@lancom/shared 0.0.311 → 0.0.313
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/assets/js/models/product-layers.js +1 -0
- package/assets/js/utils/fabric/wireframe.js +11 -8
- package/assets/js/utils/fabric-helper.js +6 -3
- package/components/editor/editor_layers/editor_layer_forms/editor_layer_form_text/editor-layer-form-text.vue +40 -0
- package/components/product/product_print_preview/product-print-preview.vue +45 -17
- package/components/products/product_list_product/product-list-product.vue +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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(
|
|
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
|
}
|
|
@@ -96,6 +96,30 @@
|
|
|
96
96
|
</i>
|
|
97
97
|
</div>
|
|
98
98
|
</div>
|
|
99
|
+
<div class="form-row--cols low-dense">
|
|
100
|
+
<div class="form-col col-half">
|
|
101
|
+
<label
|
|
102
|
+
for="fontSize"
|
|
103
|
+
class="form-label">
|
|
104
|
+
Letter Spacing
|
|
105
|
+
</label>
|
|
106
|
+
<i
|
|
107
|
+
class="icon-minus form-icon-left EditorLayerFormText__field-action"
|
|
108
|
+
@click="decreaseCharSpacing">
|
|
109
|
+
</i>
|
|
110
|
+
<input
|
|
111
|
+
id="charSpacing"
|
|
112
|
+
ref="charSpacing"
|
|
113
|
+
v-model.number="charSpacing"
|
|
114
|
+
name="charSpacing"
|
|
115
|
+
type="text"
|
|
116
|
+
class="form-field icon-inside-lr filled centered labelless" />
|
|
117
|
+
<i
|
|
118
|
+
class="icon-plus form-icon-right EditorLayerFormText__field-action"
|
|
119
|
+
@click="increaseCharSpacing">
|
|
120
|
+
</i>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
99
123
|
<div class="form-row--cols low-dense">
|
|
100
124
|
<div class="form-col col-half">
|
|
101
125
|
<label class="form-label EditorLayerFormText__label-with-checkbox">
|
|
@@ -197,6 +221,16 @@ export default {
|
|
|
197
221
|
this.$refs.fontSize.value = value;
|
|
198
222
|
}
|
|
199
223
|
},
|
|
224
|
+
charSpacing: {
|
|
225
|
+
get() {
|
|
226
|
+
return this.layer.charSpacing;
|
|
227
|
+
},
|
|
228
|
+
set(value) {
|
|
229
|
+
value = inRange(value, -300, 300);
|
|
230
|
+
this.$emit('set-layer-field', { field: 'charSpacing', value });
|
|
231
|
+
this.$refs.charSpacing.value = value;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
200
234
|
strokeWidth: {
|
|
201
235
|
get() {
|
|
202
236
|
return this.layer.strokeWidth;
|
|
@@ -224,6 +258,12 @@ export default {
|
|
|
224
258
|
decreaseFontSize() {
|
|
225
259
|
this.fontSize -= 1;
|
|
226
260
|
},
|
|
261
|
+
increaseCharSpacing() {
|
|
262
|
+
this.charSpacing += 1;
|
|
263
|
+
},
|
|
264
|
+
decreaseCharSpacing() {
|
|
265
|
+
this.charSpacing -= 1;
|
|
266
|
+
},
|
|
227
267
|
increaseStrokeWidth() {
|
|
228
268
|
this.strokeWidth += 1;
|
|
229
269
|
},
|
|
@@ -3,21 +3,33 @@
|
|
|
3
3
|
<canvas ref="print"></canvas>
|
|
4
4
|
<div
|
|
5
5
|
class="ProductPrintPreview__export"
|
|
6
|
-
@click="
|
|
7
|
-
Export To
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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:
|
|
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>
|