@sutton-signwriting/sgnw-components
Version:
a javascript package of web components for use with the SignWriting script.
124 lines (123 loc) • 3.98 kB
JavaScript
/*!
* The Sutton SignWriting Web Components
*/
//
import { Host, h } from "@stencil/core";
import { compose as composeStyle } from "@sutton-signwriting/core/style/style";
import { symbolSvg, signSvg } from "@sutton-signwriting/font-ttf/swu/swu";
import { cssValues } from "../../global/global";
import { ColorWatch } from "../../global/color-watch";
import { addSvgStyle } from "../../global/svg";
const BUTTON_SVG_STYLE = 'position:absolute;top:10%;bottom:10%;left:5%;right:5%;margin:auto;max-width:90%;max-height:80%;cursor:default;fill:var(--font-color)';
export class SgnwButton {
constructor() {
this.sgnw = window.sgnw;
}
connectedCallback() {
this.colorWatch = new ColorWatch(this.el, this);
if (!this.sgnw) {
let self = this;
function handleSgnw() {
self.sgnw = window.sgnw;
window.removeEventListener("sgnw", handleSgnw, false);
}
window.addEventListener('sgnw', handleSgnw, false);
}
}
disconnectedCallback() {
this.colorWatch.dispose();
}
render() {
const styleStr = composeStyle(Object.assign(cssValues(this.el), { background: "transparent", zoom: "x" }));
let svg = '';
if (this.symbol) {
svg = this.sgnw ? symbolSvg(this.symbol + styleStr) : '';
}
else if (this.sign) {
svg = this.sgnw ? signSvg(this.sign + styleStr) : '';
}
else if (this.svg) {
svg = this.svg;
}
return (h(Host, { key: '394e0749587541649b35559d4c16313957c5013d', innerHTML: addSvgStyle(svg, BUTTON_SVG_STYLE) }));
}
static get is() { return "sgnw-button"; }
static get encapsulation() { return "scoped"; }
static get originalStyleUrls() {
return {
"$": ["sgnw-button.css"]
};
}
static get styleUrls() {
return {
"$": ["sgnw-button.css"]
};
}
static get properties() {
return {
"symbol": {
"type": "string",
"mutable": true,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "SWU character for symbol"
},
"getter": false,
"setter": false,
"reflect": true,
"attribute": "symbol"
},
"sign": {
"type": "string",
"mutable": true,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "SWU string for sign"
},
"getter": false,
"setter": false,
"reflect": true,
"attribute": "sign"
},
"svg": {
"type": "string",
"mutable": true,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "SVG icon"
},
"getter": false,
"setter": false,
"reflect": true,
"attribute": "svg"
}
};
}
static get states() {
return {
"sgnw": {}
};
}
static get elementRef() { return "el"; }
}