UNPKG

@sutton-signwriting/sgnw-components

Version:

a javascript package of web components for use with the SignWriting script.

65 lines (61 loc) 3.34 kB
/*! * The Sutton SignWriting Web Components */ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client'; import { s as swu } from './swu.js'; import { d as draggabilly } from './draggabilly.js'; const sgnwPaletteSymbolCss = "*.sc-sgnw-palette-symbol,*.sc-sgnw-palette-symbol::before,*.sc-sgnw-palette-symbol::after{box-sizing:border-box}.sc-sgnw-palette-symbol-h{--font-color:#424242;--button-color:lightgray;--button-hover:darkgray;--bg-color:#fff}[data-color-mode=\"dark\"] .sc-sgnw-palette-symbol-h,[data-theme=\"dark\"] .sc-sgnw-palette-symbol-h{--font-color:#e1e1ff;--button-color:gray;--button-hover:darkgray;--bg-color:#161625}.swu.sc-sgnw-palette-symbol{font-family:SuttonSignWritingOneD !important}.sc-sgnw-palette-symbol-h{border:1px solid var(--font-color);cursor:move;font-size:30px;color:var(--font-color);background:var(--bg-color)}.is-dragging.sc-sgnw-palette-symbol-h{border:0px;z-index:1;text-align:initial;vertical-align:top;line-height:0px;font-size:0px;background:transparent}.sc-sgnw-palette-symbol-s>svg{position:absolute;display:block;top:2.5%;bottom:2.5%;left:2.5%;right:2.5%;margin:auto;max-width:95%;max-height:95%;cursor:default}.sc-sgnw-palette-symbol-h.is-dragging.sc-sgnw-palette-symbol-s>svg{top:0;bottom:initial;left:0;right:initial;margin:0;max-width:initial;max-height:initial}.sc-sgnw-palette-symbol-s>svg g text.sym-line{fill:var(--font-color) !important}.sc-sgnw-palette-symbol-s>svg g text.sym-fill{fill:var(--bg-color) !important}"; const SgnwPaletteSymbol = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.paletteSymbolClick = createEvent(this, "paletteSymbolClick", 7); this.paletteSymbolDrop = createEvent(this, "paletteSymbolDrop", 7); this.sgnw = window.sgnw; } paletteSymbolClickHandler() { this.paletteSymbolClick.emit(this.symbol); } paletteSymbolDropHandler({}, pointer) { this.paletteSymbolDrop.emit({ encoding: "swu", symbol: this.symbol, x: pointer.pageX, y: pointer.pageY }); this.el.style.top = "0"; this.el.style.left = "0"; } connectedCallback() { if (!this.sgnw) { let self = this; function handleSgnw() { self.sgnw = window.sgnw; window.removeEventListener("sgnw", handleSgnw, false); } window.addEventListener('sgnw', handleSgnw, false); } } componentDidLoad() { this.draggie = new draggabilly(this.el); this.draggie.on('staticClick', this.paletteSymbolClickHandler.bind(this)); this.draggie.on('dragEnd', this.paletteSymbolDropHandler.bind(this)); } render() { return (h(Host, { symbol: this.symbol, innerHTML: this.sgnw ? swu.symbolSvg(this.symbol) : '' })); } get el() { return this; } static get style() { return sgnwPaletteSymbolCss; } }, [2, "sgnw-palette-symbol", { "symbol": [1537], "sgnw": [32] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["sgnw-palette-symbol"]; components.forEach(tagName => { switch (tagName) { case "sgnw-palette-symbol": if (!customElements.get(tagName)) { customElements.define(tagName, SgnwPaletteSymbol); } break; } }); } export { SgnwPaletteSymbol as S, defineCustomElement as d };