@lancom/shared 0.0.311 → 0.0.312

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.
@@ -3,7 +3,7 @@ import { fabric } from 'fabric';
3
3
 
4
4
  const sizes = [];
5
5
 
6
- export const buildWireframe = ({ width, height, editor, print, printSize }) => {
6
+ export const buildWireframe = ({ width, height, editor, print, printSize, hiddenFrame }) => {
7
7
  const layers = editor.getObjects();
8
8
  const printAreaSize = printSize || print?.printSize || { width: 1, height: 1};
9
9
  const group = new fabric.Group(layers);
@@ -133,11 +133,14 @@ export const buildWireframe = ({ width, height, editor, print, printSize }) => {
133
133
  horizontalSize.set({
134
134
  left: horizontalSize.left - horizontalSize.width / 2
135
135
  });
136
- editor.add(verticalLine);
137
- editor.add(horizontallLine);
138
- editor.add(verticalArrow);
139
- editor.add(horizontalArrow);
140
- editor.add(verticalSize);
141
- editor.add(horizontalSize);
142
- editor.add(bounding);
136
+ console.log('hiddenFrame: ', hiddenFrame);
137
+ if (!hiddenFrame) {
138
+ editor.add(verticalLine);
139
+ editor.add(horizontallLine);
140
+ editor.add(verticalArrow);
141
+ editor.add(horizontalArrow);
142
+ editor.add(verticalSize);
143
+ editor.add(horizontalSize);
144
+ editor.add(bounding);
145
+ }
143
146
  };
@@ -219,8 +219,8 @@ export default class FabricHelper {
219
219
  });
220
220
  }
221
221
 
222
- buildWireframe({ width, height, print, printSize }) {
223
- buildWireframe({ width, height, editor: this.editor, print, printSize });
222
+ buildWireframe({ width, height, print, printSize, hiddenFrame }) {
223
+ buildWireframe({ width, height, editor: this.editor, print, printSize, hiddenFrame });
224
224
  }
225
225
 
226
226
  checkBoundingIntersection(object) {
@@ -362,7 +362,10 @@ export default class FabricHelper {
362
362
  }
363
363
 
364
364
  getLayersAsImage() {
365
- const data = this.editor.toDataURL('png');
365
+ const data = this.editor.toDataURL({
366
+ format: 'png',
367
+ multiplier: this.editor.width < 500 ? 2 : 1
368
+ });
366
369
  this.editor.renderAll();
367
370
  return data;
368
371
  }
@@ -3,21 +3,33 @@
3
3
  <canvas ref="print"></canvas>
4
4
  <div
5
5
  class="ProductPrintPreview__export"
6
- @click="exportPrintToSVG">
7
- Export To SVG
6
+ @click="exportPrintToPNG">
7
+ Export To PNG
8
+ </div>
9
+ <div
10
+ class="ProductPrintPreview__frame"
11
+ @click="hiddenFrame = !hiddenFrame">
12
+ {{ hiddenFrame ? 'Show' : 'Hide'}} Frame
8
13
  </div>
9
14
  </div>
10
15
  </template>
11
16
 
12
17
  <script>
13
- import { exportPrintToSVG } from '@lancom/shared/assets/js/utils/export-print-to-svg';
18
+ import FileSaver from 'file-saver';
14
19
  import FabricHelper from '@lancom/shared/assets/js/utils/fabric-helper';
15
20
 
16
21
  export default {
17
22
  name: 'ProductPrintPreview',
23
+ watch: {
24
+ hiddenFrame() {
25
+ this.fabricHelper.clear();
26
+ this.draw();
27
+ }
28
+ },
18
29
  data() {
19
30
  return {
20
31
  fabricHelper: null,
32
+ hiddenFrame: true,
21
33
  size: {
22
34
  width: 540,
23
35
  height: 540
@@ -46,23 +58,27 @@ export default {
46
58
  return layers;
47
59
  }
48
60
  },
49
- async mounted() {
50
- console.log('print: ', this.print);
61
+ mounted() {
51
62
  this.fabricHelper = new FabricHelper({
52
63
  editor: this.$refs.print,
53
64
  size: this.size
54
65
  });
55
- await this.drawLayers();
56
- this.fabricHelper.buildWireframe({
57
- ...this.size,
58
- // area: product.printAreas[this.sideId],
59
- printSize: this.printSize,
60
- product: this.product
61
- });
66
+ this.draw();
62
67
  },
63
68
  methods: {
69
+ async draw() {
70
+ await this.drawLayers();
71
+ this.fabricHelper.buildWireframe({
72
+ ...this.size,
73
+ // area: product.printAreas[this.sideId],
74
+ printSize: this.printSize,
75
+ product: this.product,
76
+ hiddenFrame: this.hiddenFrame
77
+ });
78
+ },
64
79
  drawLayers() {
65
- return this.layers.reduce(async (promise, layer) => {
80
+ const layers = JSON.parse(JSON.stringify(this.layers));
81
+ return layers.reduce(async (promise, layer) => {
66
82
  await promise;
67
83
  return new Promise(resolve => {
68
84
  this.fabricHelper.createObject({ layer }).then(obj => {
@@ -71,8 +87,15 @@ export default {
71
87
  });
72
88
  }, Promise.resolve());
73
89
  },
74
- exportPrintToSVG() {
75
- exportPrintToSVG(this.layers, this.printSize);
90
+ async exportPrintToPNG() {
91
+ const data = this.fabricHelper.editor.toDataURL({
92
+ format: 'png',
93
+ multiplier: 3
94
+ });
95
+ const response = await fetch(data);
96
+ const blob = await response.blob();
97
+ const file = new Blob([blob], {type: 'image/png'});
98
+ FileSaver.saveAs(file, `Print-${Date.now()}.png`);
76
99
  }
77
100
  }
78
101
  };
@@ -89,15 +112,20 @@ export default {
89
112
  // border: 2px solid blue;
90
113
  }
91
114
  }
92
- &__export {
115
+ &__export,
116
+ &__frame {
93
117
  position: absolute;
94
118
  top: 50px;
95
119
  right: 50px;
96
120
  display: inline-block;
97
- padding: 10px;
121
+ padding: 6px;
122
+ font-size: 13px;
98
123
  cursor: pointer;
99
124
  background: rgb(110, 217, 246);
100
125
  z-index: 99;
101
126
  }
127
+ &__frame {
128
+ top: 90px;
129
+ }
102
130
  }
103
131
  </style>
@@ -57,7 +57,7 @@
57
57
  <div
58
58
  v-if="noMinimum"
59
59
  class="ProductListProduct__tag-item ProductListProduct__tag-item--qty">
60
- <span>No Mimimums</span>
60
+ <span>No Minimums</span>
61
61
  </div>
62
62
  <div
63
63
  v-if="!noMinimum && product.minimumPrintOrderQuantity > 0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancom/shared",
3
- "version": "0.0.311",
3
+ "version": "0.0.312",
4
4
  "description": "lancom common scripts",
5
5
  "author": "e.tokovenko <e.tokovenko@gmail.com>",
6
6
  "repository": {