/** * @upsetjs/bundle * https://github.com/upsetjs/upsetjs * * Copyright (c) 2021 Samuel Gratzl */ import { render as renderPreact, h, hydrate as hydratePreact } from 'preact'; import UpSetElement, { UpSetPropsG, VennDiagramPropsG, KarnaughMapPropsG, UpSetFullPropsG, VennDiagramFullPropsG, KarnaughMapFullPropsG, UpSetProps as UpSetReactProps, VennDiagramProps as VennDiagramReactProps, KarnaughMapProps as KarnaughMapReactProps, fillDefaults as fillDefaultsImpl, fillVennDiagramDefaults as fillVennDiagramDefaultsImpl, fillKarnaughMapDefaults as fillKarnaughMapDefaultsImpl, exportSVG as exportSVGImpl, downloadUrl as downloadUrlImpl, toUpSetJSDump as toUpSetJSDumpImpl, toUpSetJSStaticDump as toUpSetJSStaticDumpImpl, IUpSetDump, IUpSetStaticDump, IUpSetJSDump, IUpSetJSStaticDump, UpSetMultiStyle, VennDiagram as VennDiagramElement, VennDiagramMultiStyle, KarnaughMap as KarnaughMapElement, KarnaughMapMultiStyle, UpSetJSSkeletonProps as UpSetJSSkeletonPropsImpl, VennDiagramSkeleton, KarnaughMapSkeleton, UpSetJSSkeleton, } from '@upsetjs/react'; import type { UpSetReactElement, UpSetReactElementComponentChildren } from './react'; export * from './addons'; export * from '@upsetjs/model'; export { propValidators, IUpSetJSDump, IUpSetJSStaticDump, UpSetJSDumpProps, UpSetThemeProps, UpSetThemes, UpSetStyleProps, UpSetFontSizes, VennDiagramFontSizes, KarnaughMapFontSizes, UpSetLayoutProps, VennDiagramLayoutProps, KarnaughMapLayoutProps, UpSetSelectionProps, VennDiagramThemeProps, KarnaughMapThemeProps, UpSetStyleClassNames, UpSetExportOptions, createVennJSAdapter, getDefaultTheme, UpSetAddonHandlerInfo, UpSetAddonHandlerInfos, } from '@upsetjs/react'; export * from './react'; export interface UpSetJSSkeletonProps { background?: string; color?: string; secondaryColor?: string; // any other property will be forwarded to the SVG element [key: string]: any; } export type UpSetProps = UpSetPropsG; export type UpSetFullProps = UpSetFullPropsG; export type VennDiagramProps = VennDiagramPropsG; export type VennDiagramFullProps = VennDiagramFullPropsG; export type KarnaughMapProps = KarnaughMapPropsG; export type KarnaughMapFullProps = KarnaughMapFullPropsG; /** * helper methods to fill up partial UpSet.js properties with their default values */ export function fillDefaults(props: UpSetProps): UpSetFullProps { const p: UpSetReactProps = props as UpSetProps & { style: any; styles: UpSetMultiStyle }; return fillDefaultsImpl(p) as UpSetFullProps; } /** * helper methods to fill up partial UpSet.js properties with their default values */ export function fillVennDiagramDefaults(props: VennDiagramProps): VennDiagramFullProps { const p: VennDiagramReactProps = props as VennDiagramProps & { style: any; styles: VennDiagramMultiStyle }; return fillVennDiagramDefaultsImpl(p) as VennDiagramFullProps; } /** * helper methods to fill up partial UpSet.js properties with their default values */ export function fillKarnaughMapDefaults(props: KarnaughMapProps): KarnaughMapFullProps { const p: KarnaughMapReactProps = props as KarnaughMapProps & { style: any; styles: KarnaughMapMultiStyle }; return fillKarnaughMapDefaultsImpl(p) as KarnaughMapFullProps; } /** * renders the UpSetJS component * @param node the DOM node to render the component into * @param props the properties of the component */ export function render(node: HTMLElement, props: UpSetProps) { const p: UpSetReactProps = props as UpSetProps & { style: any; styles: UpSetMultiStyle }; renderPreact(h(UpSetElement as any, p), node); } /** * renders the UpSetJS component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderUpSet(node: HTMLElement, props: UpSetProps) { const p: UpSetReactProps = props as UpSetProps & { style: any; styles: UpSetMultiStyle }; renderPreact(h(UpSetElement as any, p), node); } /** * renders the VennDiagram component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderVennDiagram(node: HTMLElement, props: VennDiagramProps) { const p: VennDiagramReactProps = props as VennDiagramProps & { style: any; styles: VennDiagramMultiStyle }; renderPreact(h(VennDiagramElement as any, p), node); } /** * renders the KarnaughMap component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderKarnaughMap(node: HTMLElement, props: KarnaughMapProps) { const p: KarnaughMapReactProps = props as KarnaughMapProps & { style: any; styles: KarnaughMapMultiStyle }; renderPreact(h(KarnaughMapElement as any, p), node); } /** * renders the UpSetJS skeleton component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; renderPreact(h(UpSetJSSkeleton as any, p), node); } /** * renders the VennDiagram skeleton component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderVennDiagramSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; renderPreact(h(VennDiagramSkeleton as any, p), node); } /** * renders the KarnaughMap skeleton component * @param node the DOM node to render the component into * @param props the properties of the component */ export function renderKarnaughMapSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; renderPreact(h(KarnaughMapSkeleton as any, p), node); } /** * hydrates the UpSetJS component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrate(node: HTMLElement, props: UpSetProps) { const p: UpSetReactProps = props as UpSetProps & { style: any; styles: UpSetMultiStyle }; hydratePreact(h(UpSetElement as any, p), node); } /** * hydrates the VennDiagram component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrateVennDiagram(node: HTMLElement, props: VennDiagramProps) { const p: VennDiagramReactProps = props as VennDiagramProps & { style: any; styles: VennDiagramMultiStyle }; hydratePreact(h(VennDiagramElement as any, p), node); } /** * hydrates the KarnaughMap component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrateKarnaughMap(node: HTMLElement, props: KarnaughMapProps) { const p: KarnaughMapReactProps = props as KarnaughMapProps & { style: any; styles: KarnaughMapMultiStyle }; hydratePreact(h(KarnaughMapElement as any, p), node); } /** * hydrates the UpSetJS Skeleton component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrateSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; hydratePreact(h(UpSetJSSkeleton as any, p), node); } /** * hydrates the VennDiagram Skeleton component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrateVennDiagramSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; hydratePreact(h(VennDiagramSkeleton as any, p), node); } /** * hydrates the KarnaughMap Skeleton component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export function hydrateKarnaughMapSkeleton(node: HTMLElement, props: UpSetJSSkeletonProps) { const p: UpSetJSSkeletonPropsImpl = props; hydratePreact(h(KarnaughMapSkeleton as any, p), node); } /** * hydrates the UpSetJS component when applied on a server rendered version * @param node the DOM node to render the component into * @param props the properties of the component */ export const hydrateUpSet = hydrate; /** * helper method to export an download an SVG image * @param node the SVG element to download * @param options additional options */ export function exportSVG( node: SVGSVGElement, options: { type?: 'png' | 'svg'; title?: string; toRemove?: string } ): Promise { return exportSVGImpl(node, options); } /** * helper method to download a given url in the browser * @param url the url to download * @param title the desired file name * @param doc the root document */ export function downloadUrl(url: string, title: string, doc: Document) { downloadUrlImpl(url, title, doc); } export function toUpSetJSDump( dump: IUpSetDump, elements: readonly (number | string | any)[], props: Partial>, author?: string, mode?: 'upset' | 'venn' | 'kmap' ): IUpSetJSDump { return toUpSetJSDumpImpl( dump, elements, props as Partial & { style: any; styles: UpSetMultiStyle }>, author, mode ); } export function toUpSetJSStaticDump( dump: IUpSetStaticDump, props: Partial>, author?: string, mode?: 'upset' | 'venn' | 'kmap' ): IUpSetJSStaticDump { return toUpSetJSStaticDumpImpl( dump, props as Partial & { style: any; styles: UpSetMultiStyle }>, author, mode ); } export function createElement( type: string, props: Record | null, ...children: UpSetReactElementComponentChildren[] ): UpSetReactElement { return h(type, props, ...children); }