@stories-js/core
Version:
Stories web components to build stories
53 lines (48 loc) • 1.39 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
import { r as registerInstance, h, c as Host } from './index-49238f69.js';
function browserSupportsCssZoom() {
try {
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
document.implementation.createHTMLDocument('').body.style.zoom !== undefined);
}
catch (error) {
return false;
}
}
function computeZoomStyle(zoom) {
return {
zoom: zoom.toPrecision(2),
};
}
function computeTransformStyle(height, zoom) {
return {
height: (height + 50).toFixed(),
transformOrigin: 'top left',
transform: `scale(${zoom})`,
};
}
const zoomCss = ":host{display:block}";
const zoomStyle = browserSupportsCssZoom();
const Zoom = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.height = 0;
this.zoom = 1;
}
watchStateHandler(newDiv) {
this.height = newDiv.getBoundingClientRect().height;
}
render() {
const style = zoomStyle ? computeZoomStyle(this.zoom) : computeTransformStyle(this.height, this.zoom);
return (h(Host, { style: style }, h("div", { ref: (el) => this.div = el, class: "innerZoomElementWrapper" }, h("slot", null))));
}
static get watchers() { return {
"div": ["watchStateHandler"]
}; }
};
Zoom.style = zoomCss;
export { Zoom as stories_zoom };
//# sourceMappingURL=stories-zoom.entry.js.map