@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
317 lines (304 loc) • 12.5 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.PenbarDrawSettings = void 0;
const lit_1 = require("lit");
const decorators_js_1 = require("lit/decorators.js");
const when_js_1 = require("lit/directives/when.js");
const context_1 = require("@lit/context");
const ecs_1 = require("@infinite-canvas-tutorial/ecs");
const context_2 = require("../context");
const localize_1 = require("@lit/localize");
let PenbarDrawSettings = class PenbarDrawSettings extends lit_1.LitElement {
handleStrokeWidthChanged(e) {
const strokeWidth = parseInt(e.target.value);
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { strokeWidth }),
});
this.api.record();
}
handleStrokeOpacityChanged(e) {
const strokeOpacity = parseFloat(e.target.value);
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { strokeOpacity }),
});
this.api.record();
}
handleStrokeColorChanged(e) {
e.stopPropagation();
const strokeColor = e.target.selected[0];
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { stroke: strokeColor }),
});
}
handleFillOpacityChanged(e) {
const fillOpacity = parseFloat(e.target.value);
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { fillOpacity }),
});
this.api.record();
}
handleFillColorChanged(e) {
e.stopPropagation();
const fillColor = e.target.selected[0];
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { fill: fillColor }),
});
}
handleRoughFillStyleChanged(e) {
e.stopPropagation();
const roughFillStyle = e.target.value;
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { roughFillStyle }),
});
this.api.record();
}
handleRoughBowingChanged(e) {
const roughBowing = parseFloat(e.target.value);
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { roughBowing }),
});
this.api.record();
}
handleRoughRoughnessChanged(e) {
const roughRoughness = parseFloat(e.target.value);
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { roughRoughness }),
});
this.api.record();
}
handleMarkerStartChanged(e) {
const markerStart = e.target.value;
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { markerStart }),
});
this.api.record();
}
handleMarkerEndChanged(e) {
const markerEnd = e.target.value;
this.api.setAppState({
[this.penbarDrawKey]: Object.assign(Object.assign({}, this.api.getAppState()[this.penbarDrawKey]), { markerEnd }),
});
this.api.record();
}
get penbarDrawKey() {
return this.pen === ecs_1.Pen.DRAW_RECT
? 'penbarDrawRect'
: this.pen === ecs_1.Pen.DRAW_ELLIPSE
? 'penbarDrawEllipse'
: this.pen === ecs_1.Pen.DRAW_LINE
? 'penbarDrawLine'
: this.pen === ecs_1.Pen.DRAW_ARROW
? 'penbarDrawArrow'
: 'penbarDrawRoughRect';
}
get penbarDraw() {
const { penbarDrawRect, penbarDrawEllipse, penbarDrawLine, penbarDrawArrow, penbarDrawRoughRect, } = this.appState;
return this.pen === ecs_1.Pen.DRAW_RECT
? penbarDrawRect
: this.pen === ecs_1.Pen.DRAW_ELLIPSE
? penbarDrawEllipse
: this.pen === ecs_1.Pen.DRAW_LINE
? penbarDrawLine
: this.pen === ecs_1.Pen.DRAW_ARROW
? penbarDrawArrow
: penbarDrawRoughRect;
}
render() {
const { theme } = this.appState;
return (0, lit_1.html) `<h4 style="margin: 0; margin-bottom: 8px;">
${(0, localize_1.msg)((0, localize_1.str) `Draw shapes settings`)}
</h4>
<div style="display: flex; flex-direction: column; gap: 4px;">
${(0, when_js_1.when)(this.pen === ecs_1.Pen.DRAW_RECT ||
this.pen === ecs_1.Pen.DRAW_ELLIPSE ||
this.pen === ecs_1.Pen.DRAW_ROUGH_RECT, () => (0, lit_1.html) `
<div>
<sp-field-label for="fill">${(0, localize_1.msg)((0, localize_1.str) `Fill`)}</sp-field-label>
<sp-swatch-group
id="fill"
selects="single"
.selected=${[this.penbarDraw.fill]}
@change=${this.handleFillColorChanged}
>
${theme.colors[theme.mode].swatches.map((color) => (0, lit_1.html) ` <sp-swatch color=${color} size="s"></sp-swatch> `)}
</sp-swatch-group>
</div>
<div class="line">
<sp-slider
label=${(0, localize_1.msg)((0, localize_1.str) `Fill opacity`)}
size="s"
max="1"
min="0"
value=${this.penbarDraw.fillOpacity}
step="0.01"
editable
@change=${this.handleFillOpacityChanged}
></sp-slider>
</div>
`)}
<div>
<sp-field-label for="stroke">${(0, localize_1.msg)((0, localize_1.str) `Stroke`)}</sp-field-label>
<sp-swatch-group
id="stroke"
selects="single"
.selected=${[this.penbarDraw.stroke]}
@change=${this.handleStrokeColorChanged}
>
${theme.colors[theme.mode].swatches.map((color) => (0, lit_1.html) ` <sp-swatch color=${color} size="s"></sp-swatch> `)}
</sp-swatch-group>
</div>
<div class="line">
<sp-slider
label=${(0, localize_1.msg)((0, localize_1.str) `Stroke width`)}
size="s"
max="20"
min="0"
value=${this.penbarDraw.strokeWidth}
step="1"
editable
format-options='{
"style": "unit",
"unit": "px"
}'
@change=${this.handleStrokeWidthChanged}
></sp-slider>
</div>
<div class="line">
<sp-slider
size="s"
label=${(0, localize_1.msg)((0, localize_1.str) `Stroke opacity`)}
max="1"
min="0"
value=${this.penbarDraw.strokeOpacity}
step="0.01"
editable
@change=${this.handleStrokeOpacityChanged}
></sp-slider>
</div>
${(0, when_js_1.when)(this.pen === ecs_1.Pen.DRAW_ARROW, () => (0, lit_1.html) `
<div class="line">
<sp-field-label for="marker-start" side-aligned="start"
>${(0, localize_1.msg)((0, localize_1.str) `Marker start`)}</sp-field-label
>
<sp-picker
style="width: 80px;"
label=${(0, localize_1.msg)((0, localize_1.str) `Marker start`)}
value=${this.penbarDraw.markerStart}
@change=${this.handleMarkerStartChanged}
id="marker-start"
>
${['none', 'line'].map((markerType) => (0, lit_1.html) `<sp-menu-item value=${markerType}
>${markerType}</sp-menu-item
>`)}
</sp-picker>
</div>
<div class="line">
<sp-field-label for="marker-end" side-aligned="start"
>${(0, localize_1.msg)((0, localize_1.str) `Marker end`)}</sp-field-label
>
<sp-picker
style="width: 80px;"
label=${(0, localize_1.msg)((0, localize_1.str) `Marker end`)}
value=${this.penbarDraw.markerEnd}
@change=${this.handleMarkerEndChanged}
id="marker-end"
>
${['none', 'line'].map((markerType) => (0, lit_1.html) `<sp-menu-item value=${markerType}
>${markerType}</sp-menu-item
>`)}
</sp-picker>
</div>
`)}
${(0, when_js_1.when)(this.pen === ecs_1.Pen.DRAW_ROUGH_RECT, () => (0, lit_1.html) `
<div>
<sp-field-label for="rough-fill-style"
>${(0, localize_1.msg)((0, localize_1.str) `Rough fill style`)}</sp-field-label
>
<sp-picker
label=${(0, localize_1.msg)((0, localize_1.str) `Rough fill style`)}
value=${this.penbarDraw.roughFillStyle}
@change=${this.handleRoughFillStyleChanged}
id="rough-fill-style"
>
<sp-menu-item value="hachure">Hachure</sp-menu-item>
<sp-menu-item value="solid">Solid</sp-menu-item>
<sp-menu-item value="zigzag">Zigzag</sp-menu-item>
<sp-menu-item value="cross-hatch">Cross hatch</sp-menu-item>
<sp-menu-item value="dots">Dots</sp-menu-item>
<sp-menu-item value="dashed">Dashed</sp-menu-item>
</sp-picker>
</div>
<div class="line">
<sp-slider
size="s"
label=${(0, localize_1.msg)((0, localize_1.str) `Bowing`)}
value=${this.penbarDraw.roughBowing}
step="0.1"
min="0"
max="10"
editable
@change=${this.handleRoughBowingChanged}
></sp-slider>
</div>
<div class="line">
<sp-slider
size="s"
label=${(0, localize_1.msg)((0, localize_1.str) `Roughness`)}
value=${this.penbarDraw.roughRoughness}
step="0.1"
min="0"
max="10"
editable
@change=${this.handleRoughRoughnessChanged}
></sp-slider>
</div>
`)}
</div> `;
}
};
exports.PenbarDrawSettings = PenbarDrawSettings;
PenbarDrawSettings.styles = (0, lit_1.css) `
.line {
display: flex;
align-items: center;
justify-content: space-between;
sp-field-label {
width: 100px;
}
sp-number-field {
width: 80px;
}
> div {
display: flex;
align-items: center;
justify-content: space-between;
}
}
sp-slider {
flex: 1;
}
.stroke-width-field {
position: relative;
top: 10px;
}
`;
__decorate([
(0, context_1.consume)({ context: context_2.appStateContext, subscribe: true })
], PenbarDrawSettings.prototype, "appState", void 0);
__decorate([
(0, context_1.consume)({ context: context_2.apiContext, subscribe: true })
], PenbarDrawSettings.prototype, "api", void 0);
__decorate([
(0, decorators_js_1.property)({ type: String })
], PenbarDrawSettings.prototype, "pen", void 0);
exports.PenbarDrawSettings = PenbarDrawSettings = __decorate([
(0, decorators_js_1.customElement)('ic-spectrum-penbar-draw-settings'),
(0, localize_1.localized)()
], PenbarDrawSettings);
//# sourceMappingURL=penbar-draw-settings.js.map