2023-11-24 00:35:51 +08:00
|
|
|
import { action } from "@ember/object";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { drawHeader, LOREM } from "wizard/lib/preview";
|
2023-02-14 22:20:15 +08:00
|
|
|
import WizardPreviewBaseComponent from "./wizard-preview-base";
|
2016-09-17 04:39:12 +08:00
|
|
|
|
2023-02-14 22:20:15 +08:00
|
|
|
export default WizardPreviewBaseComponent.extend({
|
|
|
|
width: 375,
|
|
|
|
height: 100,
|
2016-09-17 04:39:12 +08:00
|
|
|
image: null,
|
|
|
|
|
2023-11-24 00:35:51 +08:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.field.addListener(this.imageChanged);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.field.removeListener(this.imageChanged);
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
2016-09-17 04:39:12 +08:00
|
|
|
imageChanged() {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
images() {
|
2023-11-24 00:35:51 +08:00
|
|
|
return { image: this.field.value };
|
2016-09-17 04:39:12 +08:00
|
|
|
},
|
|
|
|
|
2020-10-06 01:40:41 +08:00
|
|
|
paint(options) {
|
|
|
|
const { ctx, colors, font, headingFont, width, height } = options;
|
2016-09-17 04:39:12 +08:00
|
|
|
const headerHeight = height / 2;
|
|
|
|
|
|
|
|
drawHeader(ctx, colors, width, headerHeight);
|
|
|
|
|
|
|
|
const image = this.image;
|
|
|
|
const headerMargin = headerHeight * 0.2;
|
|
|
|
|
|
|
|
const maxWidth = headerHeight - headerMargin * 2.0;
|
|
|
|
let imageWidth = image.width;
|
|
|
|
let ratio = 1.0;
|
|
|
|
if (imageWidth > maxWidth) {
|
|
|
|
ratio = maxWidth / imageWidth;
|
|
|
|
imageWidth = maxWidth;
|
|
|
|
}
|
|
|
|
|
2016-09-22 04:48:48 +08:00
|
|
|
this.scaleImage(
|
|
|
|
image,
|
|
|
|
headerMargin,
|
|
|
|
headerMargin,
|
|
|
|
imageWidth,
|
|
|
|
image.height * ratio
|
|
|
|
);
|
2016-09-17 04:39:12 +08:00
|
|
|
|
|
|
|
const afterLogo = headerMargin * 1.7 + imageWidth;
|
|
|
|
const fontSize = Math.round(headerHeight * 0.4);
|
2020-10-06 01:40:41 +08:00
|
|
|
|
|
|
|
ctx.font = `Bold ${fontSize}px '${headingFont}'`;
|
2016-09-17 04:39:12 +08:00
|
|
|
ctx.fillStyle = colors.primary;
|
|
|
|
const title = LOREM.substring(0, 27);
|
|
|
|
ctx.fillText(
|
|
|
|
title,
|
|
|
|
headerMargin + imageWidth,
|
|
|
|
headerHeight - fontSize * 1.1
|
|
|
|
);
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
const category = this.categories()[0];
|
2016-09-17 04:39:12 +08:00
|
|
|
const badgeSize = height / 13.0;
|
|
|
|
ctx.beginPath();
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fillStyle = category.color;
|
2016-09-17 04:39:12 +08:00
|
|
|
ctx.rect(afterLogo, headerHeight * 0.7, badgeSize, badgeSize);
|
|
|
|
ctx.fill();
|
|
|
|
|
2020-08-31 18:14:09 +08:00
|
|
|
ctx.font = `Bold ${badgeSize * 1.2}px '${font}'`;
|
2016-09-17 04:39:12 +08:00
|
|
|
ctx.fillStyle = colors.primary;
|
2016-09-22 04:09:18 +08:00
|
|
|
ctx.fillText(
|
|
|
|
category.name,
|
|
|
|
afterLogo + badgeSize * 1.5,
|
|
|
|
headerHeight * 0.7 + badgeSize * 0.9
|
|
|
|
);
|
2016-09-17 04:39:12 +08:00
|
|
|
|
|
|
|
const LINE_HEIGHT = 12;
|
2020-08-31 18:14:09 +08:00
|
|
|
ctx.font = `${LINE_HEIGHT}px '${font}'`;
|
2016-09-17 04:39:12 +08:00
|
|
|
const lines = LOREM.split("\n");
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
const line = height * 0.55 + i * (LINE_HEIGHT * 1.5);
|
|
|
|
ctx.fillText(lines[i], afterLogo, line);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|