cant load ${
pkg.tagName
}
${
message || '?'
}
`;
}
};
@customElement('pie-print')
export class PiePrint extends LitElement {
static styles = css`
:host {
display: block;
border: solid 1px gray;
padding: 16px;
max-width: 800px;
}
`;
constructor() {
super();
this._resolve = defaultResolve;
this._loadResolutions = defaultLoadResolution;
this._missingElement = defaultMissingElement;
}
set missingElement(c: any) {
this._missingElement = c;
}
get missingElement() {
return this._missingElement;
}
// no shadow dom
createRenderRoot() {
return this;
}
private _resolve: ResolverFn;
private _loadResolutions: LoadResolutionFn;
private _missingElement: MissingElFn;
private mathRenderingModuleUrlImported = false;
private _applyData(item: Item) {
item.models.forEach((m) => {
const el: any = this.querySelector(`${m.element}[id="${m.id}"]`);
if (!el) {
throw new Error(`missing el: ${m.element}[id="${m.id}"]`);
}
// set el mode from role to prevent breakages
el.options = {...this.config.options, mode: this.config.options?.role};
el.model = m;
});
}
public set resolve(fn: ResolverFn) {
this._resolve = fn;
}
private _config: Config = {item: {markup: '', elements: {}, models: []}};
private _resolutions: PkgResolution[] = [];
private _printItem: Item = {markup: '', elements: {}, models: []};
private _floatItem: Item = {markup: '', elements: {}, models: []};
@property({type: Object})
get config(): Config {
return this._config;
}
/**
* TODO: I'm not sure if this is the best path, as it may be nice to
* provide some ui feedback when setting up the resolutions etc.
* Will get us over the hump for now.
*/
set config(value: Config) {
const oldValue = this._config;
this._config = value;
Promise.all(
Object.entries(this.config.item.elements).map(([tagName, pkg]) => {
console.log('tagName:', tagName, 'pkg', pkg);
return this._resolve(tagName, pkg).then((res) => {
if (!res.printTagName) {
res.printTagName = `${res.tagName}-${hashCode(res.url)}`;
}
return res;
});
})
).then((resolutions) => {
this._resolutions = resolutions;
const pif = printItemAndFloaters(this._config.item, this._resolutions);
this._printItem = pif.item;
this._floatItem = mkItem(
pif.floaters,
this._resolutions,
pif.item.elements
);
this.requestUpdate('config', oldValue);
});
}
private renderMath() {
setTimeout(() => {
if ((window as any).renderMath) {
(window as any).renderMath([this]);
}
}, 50);
}
connectedCallback() {
super.connectedCallback();
this.renderMath();
}
async updated(changedProperties: Map