@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
101 lines (99 loc) • 3.95 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LayerThumbnail = void 0;
const lit_1 = require("lit");
const decorators_js_1 = require("lit/decorators.js");
const query_js_1 = require("lit/decorators/query.js");
const when_js_1 = require("lit/directives/when.js");
let LayerThumbnail = class LayerThumbnail extends lit_1.LitElement {
constructor() {
super(...arguments);
this.selected = false;
}
firstUpdated() {
var _a;
const { type } = this.node;
if (type === 'text') {
return;
}
this.canvas.width = 52 * window.devicePixelRatio;
this.canvas.height = 52 * window.devicePixelRatio;
const context = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.getContext('2d');
context.scale(0.2, 0.2);
if (type === 'rect') {
const { x, y, width, height, fill, stroke, strokeWidth } = this.node;
context.fillStyle = fill;
context.fillRect(x, y, width, height);
context.strokeStyle = stroke;
context.lineWidth = strokeWidth;
context.strokeRect(x, y, width, height);
}
else if (type === 'circle') {
const { cx, cy, r, fill, stroke, strokeWidth } = this.node;
context.fillStyle = fill;
context.beginPath();
context.arc(cx, cy, r, 0, 2 * Math.PI);
context.fill();
context.strokeStyle = stroke;
context.lineWidth = strokeWidth;
context.stroke();
}
else if (type === 'ellipse') {
const { cx, cy, rx, ry, fill, stroke, strokeWidth } = this.node;
context.fillStyle = fill;
context.beginPath();
context.ellipse(cx, cy, rx, ry, 0, 0, 2 * Math.PI);
context.fill();
context.strokeStyle = stroke;
context.lineWidth = strokeWidth;
context.stroke();
}
else if (type === 'path') {
const { d, fill, stroke, strokeWidth } = this.node;
context.fillStyle = fill;
context.fill(new Path2D(d));
context.strokeStyle = stroke;
context.lineWidth = strokeWidth;
context.stroke(new Path2D(d));
}
}
render() {
return (0, lit_1.html) `<sp-thumbnail size="1000" ?focused=${this.selected}>
${(0, when_js_1.when)(this.node.type === 'text', () => (0, lit_1.html) `<sp-icon-text></sp-icon-text>`, () => (0, lit_1.html) `<canvas></canvas>`)}
</sp-thumbnail>`;
}
};
exports.LayerThumbnail = LayerThumbnail;
LayerThumbnail.styles = (0, lit_1.css) `
:host {
}
canvas {
display: block;
width: 52px;
height: 52px;
box-sizing: border-box;
overflow: hidden;
}
sp-icon-text {
display: block;
}
`;
__decorate([
(0, decorators_js_1.property)()
], LayerThumbnail.prototype, "node", void 0);
__decorate([
(0, query_js_1.query)('canvas')
], LayerThumbnail.prototype, "canvas", void 0);
__decorate([
(0, decorators_js_1.property)({ type: Boolean })
], LayerThumbnail.prototype, "selected", void 0);
exports.LayerThumbnail = LayerThumbnail = __decorate([
(0, decorators_js_1.customElement)('ic-spectrum-layer-thumbnail')
], LayerThumbnail);
//# sourceMappingURL=layer-thumbnail.js.map
;