@sutton-signwriting/sgnw-components
Version:
a javascript package of web components for use with the SignWriting script.
84 lines (78 loc) • 3.49 kB
JavaScript
/*!
* The Sutton SignWriting Web Components
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
const _commonjsHelpers = require('./_commonjsHelpers-9aed4453.js');
const swu = require('./swu-58a6fbe8.js');
const style = require('./style-49616a98.js');
const global = require('./global-8a256890.js');
const sgnwVpCss = ":host{writing-mode:vertical-lr;border-left:1px solid blue;border-right:1px solid blue;height:100%}:host svg{display:block}:host span.outside{font-size:0%;line-height:0%;border-left:1px solid blue;vertical-align:top}:host span.middle{vertical-align:bottom}:host span.inside{border-left:1px dashed red}sgnw-sign,sgnw-symbol{writing-mode:horizontal-tb;display:inline-block;vertical-align:middle;box-sizing:content-box}";
const SgnwVp = class {
constructor(hostRef) {
_commonjsHelpers.registerInstance(this, hostRef);
this.sgnw = window.sgnw;
this.items = [];
}
parseText(newValue) {
this.items = swu.swu.parse.text(newValue).map(val => {
let i = swu.swu.info(val);
i['text'] = val;
return i;
});
}
connectedCallback() {
if (!this.vp) {
this.vp = this.el.innerHTML;
}
else {
this.parseText(this.vp);
}
if (!this.sgnw) {
let self = this;
function handleSgnw() {
self.sgnw = window.sgnw;
window.removeEventListener("sgnw", handleSgnw, false);
}
window.addEventListener('sgnw', handleSgnw, false);
}
}
render() {
const values = global.cssValues(this.el);
const styling = style.style.compose({
colorize: this.colorize,
detail: values.detail
});
const offset = 150;
return (_commonjsHelpers.h(_commonjsHelpers.Host, { vp: this.vp }, _commonjsHelpers.h("span", { class: "outside" }, _commonjsHelpers.h("span", { class: "middle" }, _commonjsHelpers.h("span", { class: "inside" }, this.items.map((item) => {
let zoom, pad, width, height, right, padding;
if (item['segment'] == 'sign') {
zoom = values.zoom * item['zoom'];
pad = item['padding'] * zoom;
width = item['width'] * zoom + pad * 2;
height = item['height'] * zoom + pad * 2;
right = (1000 - (item["minX"] * 2) - item['width']) * zoom - (offset * values.zoom * item['lane']);
padding = Math.max(0, (20 * zoom) - pad);
return _commonjsHelpers.h("sgnw-sign", { styling: styling, style: { "font-size": (values.zoom * 30) + "px", "width": width + "px", "height": height + "px", "margin-right": ((right > 0) ? right : 0) + "px", "border-left": ((right < 0) ? (-right) : 0) + "px solid transparent", "padding": padding + "px" } }, item['text']);
}
else if (item['segment'] == 'symbol') {
zoom = values.zoom * item['zoom'];
pad = item['padding'] * zoom;
width = item['width'] * zoom + pad * 2;
height = item['height'] * zoom + pad * 2;
padding = Math.max(0, (20 * zoom) - pad);
return _commonjsHelpers.h("sgnw-symbol", { styling: styling, style: { "font-size": (values.zoom * 30) + "px", "width": width + "px", "height": height + "px", "padding-bottom": padding + "px" } }, item['text']);
}
else {
console.log("other");
return _commonjsHelpers.h("div", null, item['text']);
}
}))))));
}
get el() { return _commonjsHelpers.getElement(this); }
static get watchers() { return {
"vp": ["parseText"]
}; }
};
SgnwVp.style = sgnwVpCss;
exports.sgnw_vp = SgnwVp;