@chocbite/ts-lib-ui 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/base/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../style.css";
2
- import { t as state_ui } from "../state-OCzEmq3j.mjs";
2
+ import { t as state_ui } from "../state_ui-Bm3TeKNL.mjs";
3
3
  import { state as state$1 } from "@chocbite/ts-lib/state";
4
4
  import { some } from "@chocbite/ts-lib/result";
5
5
  // src/base/access.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["state","state"],"sources":["../../src/base/access.ts","../../src/base/intersect_observer.ts","../../src/base/base.ts","../../src/base/define_element.ts","../../src/base/base_loop.ts","../../src/base/base_svg.ts"],"sourcesContent":["import { state } from \"@chocbite/ts-lib/state\";\n\n/**Enum of possible access types for base element*/\nexport const AccessTypes = {\n Write: \"w\",\n Read: \"r\",\n None: \"n\",\n} as const;\nexport type AccessTypes = (typeof AccessTypes)[keyof typeof AccessTypes];\n\n/**List for access type*/\nexport const ACCESSTYPESINFO = state.e.list<AccessTypes>({\n [AccessTypes.Write]: {\n name: \"Write\",\n description: \"Write access to element\",\n },\n [AccessTypes.Read]: { name: \"Read\", description: \"Read access to element\" },\n [AccessTypes.None]: { name: \"None\", description: \"No access to element\" },\n});\n","import type { Base } from \"./base\";\n\nexport type BaseIntersectObserverOptions = {\n /**Deffers updating visible state for so many milliseconds, defaults to 250\n * this will also batch updates if they are constantly coming*/\n deffered_visible?: number;\n /**Deffers updating visible state for so many milliseconds, defaults to 250\n * this will also batch updates if they are constantly coming*/\n deffered_hidden?: number;\n} & IntersectionObserverInit;\n\nexport class BaseIntersectObserver extends IntersectionObserver {\n #deffered_visible_time: number;\n #deffered_visible_timeout: number | null = null;\n #deffered_visible_queue: Set<Base> = new Set();\n #deffered_hidden_time: number;\n #deffered_hidden_timeout: number | null = null;\n /**Elements with the time they hide, in order of that time as the deferral is the same for all*/\n #deffered_hidden_queue: Map<Base, number> = new Map();\n\n constructor(options: BaseIntersectObserverOptions) {\n super(\n (e) => {\n if (\n this.#deffered_hidden_time === 0 &&\n this.#deffered_visible_time === 0\n ) {\n for (let i = 0; i < e.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n (<Base>e[i].target).internal_set_visible(e[i].isIntersecting);\n }\n return;\n }\n const now = performance.now();\n for (let i = 0; i < e.length; i++) {\n const target = e[i].target as Base;\n if (e[i].isIntersecting) {\n this.#deffered_visible_queue.add(target);\n this.#deffered_hidden_queue.delete(target);\n } else {\n this.#deffered_hidden_queue.delete(target);\n this.#deffered_hidden_queue.set(\n target,\n now + this.#deffered_hidden_time,\n );\n this.#deffered_visible_queue.delete(target);\n }\n }\n if (!this.#deffered_visible_timeout && this.#deffered_visible_queue.size)\n this.#deffered_visible_timeout = window.setTimeout(() => {\n for (const element of this.#deffered_visible_queue)\n //@ts-expect-error Call of private method, is private to prevent external usage\n element.internal_set_visible(true);\n this.#deffered_visible_queue.clear();\n this.#deffered_visible_timeout = null;\n }, this.#deffered_visible_time);\n if (!this.#deffered_hidden_timeout && this.#deffered_hidden_queue.size)\n this.#hide_after(this.#deffered_hidden_time);\n },\n options,\n );\n this.#deffered_visible_time = options.deffered_visible ?? 250;\n this.#deffered_hidden_time = options.deffered_hidden ?? 250;\n }\n\n /**Hides the elements whose time has come, then waits for the next*/\n #hide_after(time: number): void {\n this.#deffered_hidden_timeout = window.setTimeout(() => {\n this.#deffered_hidden_timeout = null;\n const now = performance.now();\n for (const [element, at] of this.#deffered_hidden_queue) {\n if (at > now) return this.#hide_after(at - now);\n this.#deffered_hidden_queue.delete(element);\n //@ts-expect-error Call of private method, is private to prevent external usage\n element.internal_set_visible(false);\n }\n }, time);\n }\n\n /**Also drops the element from pending deferred updates, so it does not change visibility after it is unobserved*/\n unobserve(target: Element): void {\n super.unobserve(target);\n this.#deffered_visible_queue.delete(target as Base);\n this.#deffered_hidden_queue.delete(target as Base);\n }\n}\n","import { some, type Option } from \"@chocbite/ts-lib/result\";\nimport {\n state,\n type State,\n type StateInferSub,\n type StateREA,\n type StateROA,\n type StateSub,\n} from \"@chocbite/ts-lib/state\";\nimport { AccessTypes } from \"./access\";\nimport {\n BaseIntersectObserver,\n type BaseIntersectObserverOptions,\n} from \"./intersect_observer\";\n\n// Helpers for opts\ntype DataProps<T> = {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n [K in keyof T as T[K] extends Function ? never : K]: T[K];\n};\ntype WithStateROA<T> = {\n [K in keyof T]?: T[K] | StateROA<T[K]>;\n};\n\nconst base_resize_observer = new ResizeObserver((e) => {\n for (let i = 0; i < e.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n (<Base>e[i].target).internal_set_size_pos(e[i].contentRect);\n }\n});\n\n/**Shared class for elements to extend\n * All none abstract elements must use the define_element function to declare itself\n *\n * Elements are only created in code, with new or a factory function, HTML is not supported,\n * constructors add children and attributes, which document.createElement and the HTML parser do not allow\n *\n * All none abstracts classes must override the static method element_name to return the name of the element\n * Abstract classes should return @abstract@\n *\n * If another library defines an abstract base class, it is recommended to change the static element_name_space method to the name of the library\n * example for this library '@chocolatelibui/core' becomes 'chocolatelibui-core'\n * static element_name_space() { return 'chocolatelibui-core' }\n * This resets the nametree to the library name and prevents too long element names\n *\n * Elements have an access propery, which builds on the html inert property\n * Access has the following three states\n * write = normal interaction and look\n * read = inert attribute is added making the element uninteractable, and add opacity 0.5 to make the element look inaccessible\n * none = adds display:none to element to make it */\nexport abstract class Base extends HTMLElement {\n /**Returns the name used to define the element, Abstract classes should return @abstract@ */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"lib\";\n }\n\n #states: Map<StateSub<any>, [State<any>, boolean]> = new Map();\n\n readonly is_connected: boolean = false;\n\n /**Works when element is connected to observer, otherwise it is an alias for isConnected*/\n readonly is_visible: boolean = false;\n\n #access?: AccessTypes;\n\n #props: Map<any, StateSub<any>> = new Map();\n #attr: Map<string, StateSub<any>> = new Map();\n\n /**Runs when element is attached to document*/\n protected connectedCallback() {\n for (const [f, [s, v]] of this.#states) if (!v) s.sub(f, true);\n //Set after subscribing, so states attached by the subscribers are not subscribed twice,\n //but before visibility, so states attached from on_visible are subscribed\n //@ts-expect-error Change readonly, in same class, why is there no way to do this without ts-ignore?\n this.is_connected = true;\n if (this.#attached_int_observer) this.#attached_int_observer.observe(this);\n else this.internal_set_visible(true);\n }\n\n /**Runs when element is dettached from document*/\n protected disconnectedCallback() {\n //@ts-expect-error Change readonly, in same class\n this.is_connected = false;\n for (const [f, [s, v]] of this.#states) if (!v) s.unsub(f);\n if (this.#attached_int_observer) this.#attached_int_observer.unobserve(this);\n this.internal_set_visible(false);\n }\n\n /**Sets any attribute on the base element, to either a fixed value or a state value */\n opts(opts: WithStateROA<DataProps<this>>): this {\n for (const key in opts) {\n const opt = opts[key] as this[typeof key] | StateROA<this[typeof key]>;\n if (state.is.roa(opt)) this.attach_state_ROA_to_prop(key, opt);\n else this.detach_state_from_prop(key)[key] = opt;\n }\n return this;\n }\n\n /**Elements that can attach to a writable state can declare them in binds*/\n bind(_opts: never): this {\n return this;\n }\n\n /**Executes a function with the element as an argument and returns the element\n * Useful when declaring multiple elements in a single statement, without easy access to a scope to execute code in*/\n scope(fn: (elem: this) => void): this {\n fn(this);\n return this;\n }\n\n // ____ ____ _____ ______ _______ ________ _____\n // / __ \\| _ \\ / ____| ____| __ \\ \\ / / ____| __ \\\n // | | | | |_) | (___ | |__ | |__) \\ \\ / /| |__ | |__) |\n // | | | | _ < \\___ \\| __| | _ / \\ \\/ / | __| | _ /\n // | |__| | |_) |____) | |____| | \\ \\ \\ / | |____| | \\ \\\n // \\____/|____/|_____/|______|_| \\_\\ \\/ |______|_| \\_\\\n /**Observer for children of this element */\n #intersect_observer?: BaseIntersectObserver;\n #attached_int_observer?: BaseIntersectObserver;\n\n /**Returns an observer for the element */\n intersect_observer(\n options: BaseIntersectObserverOptions = {\n root: this,\n threshold: 0,\n deffered_hidden: 1000,\n },\n ): BaseIntersectObserver {\n return (this.#intersect_observer ??= new BaseIntersectObserver(options));\n }\n\n /**Attaches the component to an observer, which is needed for the isVisible state and event to work and for the state system to work on visible*/\n attach_to_intersect_observer(observer?: BaseIntersectObserver): this {\n if (observer) {\n if (this.is_connected) {\n if (this.#attached_int_observer)\n this.#attached_int_observer.unobserve(this);\n observer.observe(this);\n }\n this.#attached_int_observer = observer;\n } else if (this.#attached_int_observer) {\n //Without an observer a connected element counts as visible\n if (this.is_connected) {\n this.#attached_int_observer.unobserve(this);\n this.internal_set_visible(true);\n }\n this.#attached_int_observer = undefined;\n }\n return this;\n }\n\n private internal_set_visible(is: boolean) {\n if (this.is_visible !== is) {\n //@ts-expect-error Change readonly, in same class\n this.is_visible = is;\n if (is) {\n for (const [f, [s, v]] of this.#states) if (v) s.sub(f, true);\n if (this.#resize_observe) base_resize_observer.observe(this);\n } else {\n for (const [f, [s, v]] of this.#states) if (v) s.unsub(f);\n if (this.#resize_observe) base_resize_observer.unobserve(this);\n }\n this.on_visible(is);\n }\n }\n /**Overrideable function called when the element becomes visible or hidden\n * If intersection observer is not attached it is based on connectedCallback, which is less accurate*/\n protected on_visible(_is: boolean) {}\n\n #resize_observe = false;\n #actual_size?: { width: number; height: number };\n /**Returns actual size and position of the element\n * if a resize observer is attached to the element, it will return the result of that, otherwise it will return the result of getBoundingClientRect()*/\n get actual_size(): { width: number; height: number } {\n return this.#actual_size ?? this.getBoundingClientRect();\n }\n\n /**Attaches the component to the global resize observer */\n attach_to_resize_observer(): this {\n if (this.is_visible) base_resize_observer.observe(this);\n this.#resize_observe = true;\n return this;\n }\n\n /**Dettaches the component from the global resize observer */\n detach_from_resize_observer(): this {\n if (this.is_visible) base_resize_observer.unobserve(this);\n this.#resize_observe = false;\n this.#actual_size = undefined;\n return this;\n }\n\n private internal_set_size_pos(rect: DOMRectReadOnly) {\n this.#actual_size = rect;\n this.on_resize(rect);\n }\n\n /**Overrideable function called when the element is resized\n * Only triggers when a resize observer is attached to the element, otherwise it will not trigger*/\n protected on_resize(_rect: { width: number; height: number }) {}\n\n // _____ _____ ______ _____ _____\n // /\\ / ____/ ____| ____|/ ____/ ____|\n // / \\ | | | | | |__ | (___| (___\n // / /\\ \\| | | | | __| \\___ \\\\___ \\\n // / ____ \\ |___| |____| |____ ____) |___) |\n // /_/ \\_\\_____\\_____|______|_____/_____/\n /**Sets the access of the element, passing undefined is the same as passing write access*/\n set access(access: AccessTypes) {\n if (this.#access === access) return;\n this.#access = access;\n switch (access) {\n case AccessTypes.Write:\n this.inert = false;\n break;\n case AccessTypes.Read:\n this.inert = true;\n break;\n case AccessTypes.None:\n this.setAttribute(\"inert\", \"none\");\n break;\n }\n this.on_access(access);\n }\n\n /**Overrideable function called when access is changed */\n protected on_access(_access: AccessTypes) {}\n\n /**Returns the current access of the element */\n get access(): AccessTypes {\n return this.#access ?? AccessTypes.Write;\n }\n // _____ _______ _______ ______\n // / ____|__ __|/\\|__ __| ____|\n // | (___ | | / \\ | | | |__\n // \\___ \\ | | / /\\ \\ | | | __|\n // ____) | | |/ ____ \\| | | |____\n // |_____/ |_/_/ \\_\\_| |______|\n /**Attaches a state to a function, so that the function is subscribed to the state when the component is connected\n * @param visible when set true the function is only subscribed when the element is visible, this requires an observer to be attached to the element*/\n attach_state<S extends State<any>>(\n state: S,\n func: StateInferSub<S>,\n visible?: boolean,\n ): typeof func {\n if (this.#states.has(func))\n console.error(\"Function already registered with element\", func, this);\n else {\n this.#states.set(func, [state, Boolean(visible)]);\n if (visible ? this.is_visible : this.is_connected)\n state.sub(func as StateSub<any>, true);\n }\n return func;\n }\n\n /**Detaches the function from the state/component */\n detach_state(func: StateSub<any>): typeof func {\n const state = this.#states.get(func);\n if (state) {\n if (state[1] ? this.is_visible : this.is_connected) state[0].unsub(func);\n this.#states.delete(func);\n } else console.error(\"Function not registered with element\", func, this);\n return func;\n }\n\n /**Attaches a state to a function, so that the function is subscribed to the state when the component is connected\n * @param visible when set true the function is only subscribed when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_symbol<S extends State<any>>(\n symbol: symbol,\n state: S,\n func: StateInferSub<S>,\n visible?: boolean,\n ): this {\n this.detach_state_from_symbol(symbol).#props.set(\n symbol,\n this.attach_state(state, func, visible),\n );\n return this;\n }\n\n /**Detaches the function from the state/component */\n detach_state_from_symbol(symbol: symbol): this {\n const pro = this.#props.get(symbol);\n if (pro) {\n this.detach_state(pro);\n this.#props.delete(symbol);\n }\n return this;\n }\n\n // _____ _______ _______ ______ _____ _____ ____ _____\n // / ____|__ __|/\\|__ __| ____| | __ \\| __ \\ / __ \\| __ \\\n // | (___ | | / \\ | | | |__ | |__) | |__) | | | | |__) |\n // \\___ \\ | | / /\\ \\ | | | __| | ___/| _ /| | | | ___/\n // ____) | | |/ ____ \\| | | |____ | | | | \\ \\| |__| | |\n // |_____/ |_/_/ \\_\\_| |______| |_| |_| \\_\\\\____/|_|\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_ROA_to_prop<K extends keyof this>(\n prop: K,\n state: StateROA<this[K], any, any>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(state, (val) => (this[prop] = val.value), visible),\n );\n return this;\n }\n\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element\n * @param fallback the fallback value for the property when the state is not ok, if undefined the property is not updated when the state is not ok*/\n attach_state_ROA_to_prop_map<K extends keyof this, T = this[K]>(\n prop: K,\n state: StateROA<T, any, any>,\n map: (val: T) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (val) => {\n const o = map(val.value);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param map_err function called when state gives a ResultErr,\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_prop<K extends keyof this>(\n prop: K,\n state: StateREA<this[K], any, any>,\n map_err: (error: string) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? some(v.value) : map_err(v.error);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param map_err function called when state gives a ResultErr,\n * @param map function called when state gives a ResultOk,\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_prop_map<K extends keyof this, T = this[K]>(\n prop: K,\n state: StateREA<T, any, any>,\n map_err: (error: string) => Option<this[K]>,\n map: (val: T) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? map(v.value) : map_err(v.error);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Detaches the state from the property */\n detach_state_from_prop<T extends keyof this>(prop: T): this {\n const pro = this.#props.get(prop);\n if (pro) {\n this.detach_state(pro);\n this.#props.delete(prop);\n }\n return this;\n }\n\n // _____ _______ _______ ______ _______ _______ _____ _____ ____ _ _ _______ ______\n // / ____|__ __|/\\|__ __| ____| /\\|__ __|__ __| __ \\|_ _| _ \\| | | |__ __| ____|\n // | (___ | | / \\ | | | |__ / \\ | | | | | |__) | | | | |_) | | | | | | | |__\n // \\___ \\ | | / /\\ \\ | | | __| / /\\ \\ | | | | | _ / | | | _ <| | | | | | | __|\n // ____) | | |/ ____ \\| | | |____ / ____ \\| | | | | | \\ \\ _| |_| |_) | |__| | | | | |____\n // |_____/ |_/_/ \\_\\_| |______| /_/ \\_\\_| |_| |_| \\_\\_____|____/ \\____/ |_| |______|\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_ROA_to_attribute(\n qualified_name: string,\n state: StateROA<string, any, any>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (val) => this.setAttribute(qualified_name, val.value),\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element\n * @param fallback the fallback value for the attribute when the state is not ok, if undefined the attribute is not updated when the state is not ok*/\n attach_state_ROA_to_attribute_map<U>(\n qualified_name: string,\n state: StateROA<U, any, any>,\n map: (val: U) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (val) => {\n const o = map(val.value);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param map_err function called when state gives a ResultErr,\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_attribute(\n qualified_name: string,\n state: StateREA<string, any, any>,\n map_err: (error: string) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? some(v.value) : map_err(v.error);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param map_err function called when state gives a ResultErr,\n * @param map function called when state gives a ResultOk,\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_attribute_map<U>(\n qualified_name: string,\n state: StateREA<U, any, any>,\n map_err: (error: string) => Option<string>,\n map: (val: U) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? map(v.value) : map_err(v.error);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Detaches the state from the property */\n detach_state_from_attribute(qualified_name: string): this {\n const pro = this.#attr.get(qualified_name);\n if (pro) {\n this.detach_state(pro);\n this.#attr.delete(qualified_name);\n }\n return this;\n }\n}\n","const RESERVED_NAMES = new Set([\n \"annotation-xml\",\n \"color-profile\",\n \"font-face\",\n \"font-face-src\",\n \"font-face-uri\",\n \"font-face-format\",\n \"font-face-name\",\n \"missing-glyph\",\n]);\n\nconst regex =\n /^[a-z](?:[\\.0-9_a-z\\xB7\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u037D\\u037F-\\u1FFF\\u200C\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF])*-(?:[\\x2D\\.0-9_a-z\\xB7\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u037D\\u037F-\\u1FFF\\u200C\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF])*$/;\n\n/**Gives more information about whats wrong with the given element name */\nexport const validate_element_name = (name: string) => {\n if (!name) return \"Missing element name.\";\n if (/[A-Z]/.test(name))\n return \"Custom element names must not contain uppercase ASCII characters.\";\n if (!name.includes(\"-\"))\n return \"Custom element names must contain a hyphen. Example: unicorn-cake\";\n if (/^\\d/i.test(name))\n return \"Custom element names must not start with a digit.\";\n if (/^-/i.test(name))\n return \"Custom element names must not start with a hyphen.\";\n // https://html.spec.whatwg.org/multipage/scripting.html#prod-potentialcustomelementname\n if (!regex.test(name)) return \"Invalid element name.\";\n if (RESERVED_NAMES.has(name))\n return \"The supplied element name is reserved and can't be used.\\nSee: https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name\";\n return \"Unknown fault\";\n};\n\nlet base_element_global_namespace = \"\";\n\nexport const set_base_element_global_namespace = (namespace: string) => {\n base_element_global_namespace = namespace + (namespace.length ? \"-\" : \"\");\n};\n\ninterface ElementConstructor {\n element_name: () => string;\n element_name_space: () => string;\n}\n\n/**Generates the base name for a custom element */\nexport const base_element_name = (element: ElementConstructor): string => {\n const namespace = element.element_name_space();\n const check = element.element_name;\n let define_name = \"\";\n let runner = element;\n // @ts-expect-error Very dynamic stuff\n while (runner !== HTMLElement) {\n if (namespace !== runner.element_name_space()) break;\n const name = runner.element_name();\n runner = Object.getPrototypeOf(runner) as ElementConstructor;\n if (check === runner.element_name)\n throw new Error(\n \"Element uses same name as ancestor, abstract classes should return '@abstract@'\",\n );\n if (!name.length) throw new Error(\"Element doesn't define element name\");\n if (name !== \"@abstract@\") define_name = \"-\" + name + define_name;\n }\n return base_element_global_namespace + namespace + define_name;\n};\n\nexport const ELEMENT_LIST: Set<string> = new Set();\n\n/**Defines elements inheriting from the base*/\nexport const define_element = (element: ElementConstructor) => {\n const namespace = element.element_name_space();\n const check = element.element_name;\n let define_name = \"\";\n let runner = element;\n // @ts-expect-error Very dynamic stuff\n while (runner !== HTMLElement) {\n if (namespace !== runner.element_name_space()) break;\n\n const name = runner.element_name();\n runner = Object.getPrototypeOf(runner) as ElementConstructor;\n if (check === runner.element_name)\n throw new Error(\n 'Failed to define element \"' +\n namespace +\n \"-\" +\n name +\n define_name +\n '\" ' +\n \"Element uses same name as ancestor, abstract classes should return '@abstract@'\",\n );\n if (!name.length) throw new Error(\"Element doesn't define element name\");\n if (name !== \"@abstract@\") define_name = \"-\" + name + define_name;\n }\n define_name = base_element_global_namespace + namespace + define_name;\n //Checked first, browsers word the error for a name or class used twice differently\n if (customElements.get(define_name))\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" the name has already been defined, by another element or by this library being loaded twice',\n );\n //getName is missing in older browsers\n const defined_as =\n \"getName\" in customElements\n ? customElements.getName(element as unknown as CustomElementConstructor)\n : null;\n if (defined_as)\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" the class is already defined as \"' +\n defined_as +\n '\"',\n );\n try {\n // @ts-expect-error Dynamic custom element definition\n customElements.define(define_name, element);\n ELEMENT_LIST.add(define_name);\n } catch {\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" ' +\n validate_element_name(define_name),\n );\n }\n};\n","import state_ui from \"#state\";\nimport { Base } from \"./base\";\nimport { define_element } from \"./define_element\";\n\ninterface LoopOptions<T, N extends ChildNode> {\n /**Updates a node to a new value, when given nodes are reused instead of replaced*/\n change?: (element: N, new_value: T) => void;\n /**Called for every node that is removed or replaced*/\n destructor?: (element: N) => void;\n}\n\n/**Element with one child node per value of an array, follows the changes of array states*/\nexport class Loop<T, N extends ChildNode> extends Base {\n static element_name(): string {\n return \"loop\";\n }\n static element_name_space(): string {\n return \"base\";\n }\n\n #generator: (val: T) => N;\n #destructor?: (element: N) => void;\n #change?: (element: N, new_value: T) => void;\n\n constructor(generator: (val: T) => N, options?: LoopOptions<T, N>) {\n super();\n this.#generator = generator;\n this.#destructor = options?.destructor;\n this.#change = options?.change;\n }\n\n set array(array: readonly T[]) {\n state_ui.a.apply(this, array, {\n create: this.#generator,\n update: this.#change,\n destroy: this.#destructor,\n });\n }\n\n set error(err: Node) {\n this.replaceChildren(err);\n }\n}\ndefine_element(Loop);\n\nexport function base_loop<T, N extends ChildNode>(\n generator: (val: T) => N,\n options?: LoopOptions<T, N>,\n) {\n return new Loop<T, N>(generator, options);\n}\n","import { Base } from \"./base\";\nimport { base_element_name } from \"./define_element\";\n\n/**Shared svg class for elements to extend\n * See Base for more information on how to define elements, and the element lifecycle */\nexport abstract class BaseSVG extends Base {\n /**Returns the name used to define the element, Abstract classes should return @abstract@ */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"lib\";\n }\n\n protected abstract default_canvas(): SVGSVGElement;\n\n readonly canvas: SVGSVGElement = this.default_canvas();\n\n constructor() {\n super();\n this.canvas.classList.add(\n base_element_name(this.constructor as typeof BaseSVG),\n );\n this.canvas.appendChild(this);\n }\n}\n"],"mappings":";;;;;;AAGA,MAAa,cAAc;CACzB,OAAO;CACP,MAAM;CACN,MAAM;AACR;;AAIA,MAAa,kBAAkBA,QAAM,EAAE,KAAkB;EACtD,YAAY,QAAQ;EACnB,MAAM;EACN,aAAa;CACf;EACC,YAAY,OAAO;EAAE,MAAM;EAAQ,aAAa;CAAyB;EACzE,YAAY,OAAO;EAAE,MAAM;EAAQ,aAAa;CAAuB;AAC1E,CAAC;;ACPD,IAAa,wBAAb,cAA2C,qBAAqB;CAC9D;CACA,4BAA2C;CAC3C,0CAAqC,IAAI,IAAI;CAC7C;CACA,2BAA0C;;CAE1C,yCAA4C,IAAI,IAAI;CAEpD,YAAY,SAAuC;EACjD,OACG,MAAM;GACL,IACE,KAAK,0BAA0B,KAC/B,KAAK,2BAA2B,GAChC;IACA,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAE5B,EAAS,EAAE,CAAC,OAAQ,qBAAqB,EAAE,EAAE,CAAC,cAAc;IAE9D;GACF;GACA,MAAM,MAAM,YAAY,IAAI;GAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,E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,IAAI,YACF,MAAM,IAAI,MACR,gCACE,cACA,0CACA,aACA,IACJ;CACF,IAAI;EAEF,eAAe,OAAO,aAAa,OAAO;EAC1C,aAAa,IAAI,WAAW;CAC9B,QAAQ;EACN,MAAM,IAAI,MACR,gCACE,cACA,QACA,sBAAsB,WAAW,CACrC;CACF;AACF;;;AChHA,IAAa,OAAb,cAAkD,KAAK;CACrD,OAAO,eAAuB;EAC5B,OAAO;CACT;CACA,OAAO,qBAA6B;EAClC,OAAO;CACT;CAEA;CACA;CACA;CAEA,YAAY,WAA0B,SAA6B;EACjE,MAAM;EACN,KAAK,aAAa;EAClB,KAAK,cAAc,SAAS;EAC5B,KAAK,UAAU,SAAS;CAC1B;CAEA,IAAI,MAAM,OAAqB;EAC7B,SAAS,EAAE,MAAM,MAAM,OAAO;GAC5B,QAAQ,KAAK;GACb,QAAQ,KAAK;GACb,SAAS,KAAK;EAChB,CAAC;CACH;CAEA,IAAI,MAAM,KAAW;EACnB,KAAK,gBAAgB,GAAG;CAC1B;AACF;AACA,eAAe,IAAI;AAEnB,SAAgB,UACd,WACA,SACA;CACA,OAAO,IAAI,KAAW,WAAW,OAAO;AAC1C;;;;AC7CA,IAAsB,UAAtB,cAAsC,KAAK;;CAEzC,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;CAIA,SAAiC,KAAK,eAAe;CAErD,cAAc;EACZ,MAAM;EACN,KAAK,OAAO,UAAU,IACpB,kBAAkB,KAAK,WAA6B,CACtD;EACA,KAAK,OAAO,YAAY,IAAI;CAC9B;AACF"}
1
+ {"version":3,"file":"index.mjs","names":["state","state"],"sources":["../../src/base/access.ts","../../src/base/intersect_observer.ts","../../src/base/base.ts","../../src/base/define_element.ts","../../src/base/base_loop.ts","../../src/base/base_svg.ts"],"sourcesContent":["import { state } from \"@chocbite/ts-lib/state\";\n\n/**Enum of possible access types for base element*/\nexport const AccessTypes = {\n Write: \"w\",\n Read: \"r\",\n None: \"n\",\n} as const;\nexport type AccessTypes = (typeof AccessTypes)[keyof typeof AccessTypes];\n\n/**List for access type*/\nexport const ACCESSTYPESINFO = state.e.list<AccessTypes>({\n [AccessTypes.Write]: {\n name: \"Write\",\n description: \"Write access to element\",\n },\n [AccessTypes.Read]: { name: \"Read\", description: \"Read access to element\" },\n [AccessTypes.None]: { name: \"None\", description: \"No access to element\" },\n});\n","import type { Base } from \"./base\";\n\nexport type BaseIntersectObserverOptions = {\n /**Deffers updating visible state for so many milliseconds, defaults to 250\n * this will also batch updates if they are constantly coming*/\n deffered_visible?: number;\n /**Deffers updating visible state for so many milliseconds, defaults to 250\n * this will also batch updates if they are constantly coming*/\n deffered_hidden?: number;\n} & IntersectionObserverInit;\n\nexport class BaseIntersectObserver extends IntersectionObserver {\n #deffered_visible_time: number;\n #deffered_visible_timeout: number | null = null;\n #deffered_visible_queue: Set<Base> = new Set();\n #deffered_hidden_time: number;\n #deffered_hidden_timeout: number | null = null;\n /**Elements with the time they hide, in order of that time as the deferral is the same for all*/\n #deffered_hidden_queue: Map<Base, number> = new Map();\n\n constructor(options: BaseIntersectObserverOptions) {\n super(\n (e) => {\n if (\n this.#deffered_hidden_time === 0 &&\n this.#deffered_visible_time === 0\n ) {\n for (let i = 0; i < e.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n (<Base>e[i].target).internal_set_visible(e[i].isIntersecting);\n }\n return;\n }\n const now = performance.now();\n for (let i = 0; i < e.length; i++) {\n const target = e[i].target as Base;\n if (e[i].isIntersecting) {\n this.#deffered_visible_queue.add(target);\n this.#deffered_hidden_queue.delete(target);\n } else {\n this.#deffered_hidden_queue.delete(target);\n this.#deffered_hidden_queue.set(\n target,\n now + this.#deffered_hidden_time,\n );\n this.#deffered_visible_queue.delete(target);\n }\n }\n if (!this.#deffered_visible_timeout && this.#deffered_visible_queue.size)\n this.#deffered_visible_timeout = window.setTimeout(() => {\n for (const element of this.#deffered_visible_queue)\n //@ts-expect-error Call of private method, is private to prevent external usage\n element.internal_set_visible(true);\n this.#deffered_visible_queue.clear();\n this.#deffered_visible_timeout = null;\n }, this.#deffered_visible_time);\n if (!this.#deffered_hidden_timeout && this.#deffered_hidden_queue.size)\n this.#hide_after(this.#deffered_hidden_time);\n },\n options,\n );\n this.#deffered_visible_time = options.deffered_visible ?? 250;\n this.#deffered_hidden_time = options.deffered_hidden ?? 250;\n }\n\n /**Hides the elements whose time has come, then waits for the next*/\n #hide_after(time: number): void {\n this.#deffered_hidden_timeout = window.setTimeout(() => {\n this.#deffered_hidden_timeout = null;\n const now = performance.now();\n for (const [element, at] of this.#deffered_hidden_queue) {\n if (at > now) return this.#hide_after(at - now);\n this.#deffered_hidden_queue.delete(element);\n //@ts-expect-error Call of private method, is private to prevent external usage\n element.internal_set_visible(false);\n }\n }, time);\n }\n\n /**Also drops the element from pending deferred updates, so it does not change visibility after it is unobserved*/\n unobserve(target: Element): void {\n super.unobserve(target);\n this.#deffered_visible_queue.delete(target as Base);\n this.#deffered_hidden_queue.delete(target as Base);\n }\n}\n","import { some, type Option } from \"@chocbite/ts-lib/result\";\nimport {\n state,\n type State,\n type StateInferSub,\n type StateREA,\n type StateROA,\n type StateSub,\n} from \"@chocbite/ts-lib/state\";\nimport { AccessTypes } from \"./access\";\nimport {\n BaseIntersectObserver,\n type BaseIntersectObserverOptions,\n} from \"./intersect_observer\";\n\n// Helpers for opts\ntype DataProps<T> = {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n [K in keyof T as T[K] extends Function ? never : K]: T[K];\n};\ntype WithStateROA<T> = {\n [K in keyof T]?: T[K] | StateROA<T[K]>;\n};\n\nconst base_resize_observer = new ResizeObserver((e) => {\n for (let i = 0; i < e.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n (<Base>e[i].target).internal_set_size_pos(e[i].contentRect);\n }\n});\n\n/**Shared class for elements to extend\n * All none abstract elements must use the define_element function to declare itself\n *\n * Elements are only created in code, with new or a factory function, HTML is not supported,\n * constructors add children and attributes, which document.createElement and the HTML parser do not allow\n *\n * All none abstracts classes must override the static method element_name to return the name of the element\n * Abstract classes should return @abstract@\n *\n * If another library defines an abstract base class, it is recommended to change the static element_name_space method to the name of the library\n * example for this library '@chocolatelibui/core' becomes 'chocolatelibui-core'\n * static element_name_space() { return 'chocolatelibui-core' }\n * This resets the nametree to the library name and prevents too long element names\n *\n * Elements have an access propery, which builds on the html inert property\n * Access has the following three states\n * write = normal interaction and look\n * read = inert attribute is added making the element uninteractable, and add opacity 0.5 to make the element look inaccessible\n * none = adds display:none to element to make it */\nexport abstract class Base extends HTMLElement {\n /**Returns the name used to define the element, Abstract classes should return @abstract@ */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"lib\";\n }\n\n #states: Map<StateSub<any>, [State<any>, boolean]> = new Map();\n\n readonly is_connected: boolean = false;\n\n /**Works when element is connected to observer, otherwise it is an alias for isConnected*/\n readonly is_visible: boolean = false;\n\n #access?: AccessTypes;\n\n #props: Map<any, StateSub<any>> = new Map();\n #attr: Map<string, StateSub<any>> = new Map();\n\n /**Runs when element is attached to document*/\n protected connectedCallback() {\n for (const [f, [s, v]] of this.#states) if (!v) s.sub(f, true);\n //Set after subscribing, so states attached by the subscribers are not subscribed twice,\n //but before visibility, so states attached from on_visible are subscribed\n //@ts-expect-error Change readonly, in same class, why is there no way to do this without ts-ignore?\n this.is_connected = true;\n if (this.#attached_int_observer) this.#attached_int_observer.observe(this);\n else this.internal_set_visible(true);\n }\n\n /**Runs when element is dettached from document*/\n protected disconnectedCallback() {\n //@ts-expect-error Change readonly, in same class\n this.is_connected = false;\n for (const [f, [s, v]] of this.#states) if (!v) s.unsub(f);\n if (this.#attached_int_observer) this.#attached_int_observer.unobserve(this);\n this.internal_set_visible(false);\n }\n\n /**Sets any attribute on the base element, to either a fixed value or a state value */\n opts(opts: WithStateROA<DataProps<this>>): this {\n for (const key in opts) {\n const opt = opts[key] as this[typeof key] | StateROA<this[typeof key]>;\n if (state.is.roa(opt)) this.attach_state_ROA_to_prop(key, opt);\n else this.detach_state_from_prop(key)[key] = opt;\n }\n return this;\n }\n\n /**Elements that can attach to a writable state can declare them in binds*/\n bind(_opts: never): this {\n return this;\n }\n\n /**Executes a function with the element as an argument and returns the element\n * Useful when declaring multiple elements in a single statement, without easy access to a scope to execute code in*/\n scope(fn: (elem: this) => void): this {\n fn(this);\n return this;\n }\n\n // ____ ____ _____ ______ _______ ________ _____\n // / __ \\| _ \\ / ____| ____| __ \\ \\ / / ____| __ \\\n // | | | | |_) | (___ | |__ | |__) \\ \\ / /| |__ | |__) |\n // | | | | _ < \\___ \\| __| | _ / \\ \\/ / | __| | _ /\n // | |__| | |_) |____) | |____| | \\ \\ \\ / | |____| | \\ \\\n // \\____/|____/|_____/|______|_| \\_\\ \\/ |______|_| \\_\\\n /**Observer for children of this element */\n #intersect_observer?: BaseIntersectObserver;\n #attached_int_observer?: BaseIntersectObserver;\n\n /**Returns an observer for the element */\n intersect_observer(\n options: BaseIntersectObserverOptions = {\n root: this,\n threshold: 0,\n deffered_hidden: 1000,\n },\n ): BaseIntersectObserver {\n return (this.#intersect_observer ??= new BaseIntersectObserver(options));\n }\n\n /**Attaches the component to an observer, which is needed for the isVisible state and event to work and for the state system to work on visible*/\n attach_to_intersect_observer(observer?: BaseIntersectObserver): this {\n if (observer) {\n if (this.is_connected) {\n if (this.#attached_int_observer)\n this.#attached_int_observer.unobserve(this);\n observer.observe(this);\n }\n this.#attached_int_observer = observer;\n } else if (this.#attached_int_observer) {\n //Without an observer a connected element counts as visible\n if (this.is_connected) {\n this.#attached_int_observer.unobserve(this);\n this.internal_set_visible(true);\n }\n this.#attached_int_observer = undefined;\n }\n return this;\n }\n\n private internal_set_visible(is: boolean) {\n if (this.is_visible !== is) {\n //@ts-expect-error Change readonly, in same class\n this.is_visible = is;\n if (is) {\n for (const [f, [s, v]] of this.#states) if (v) s.sub(f, true);\n if (this.#resize_observe) base_resize_observer.observe(this);\n } else {\n for (const [f, [s, v]] of this.#states) if (v) s.unsub(f);\n if (this.#resize_observe) base_resize_observer.unobserve(this);\n }\n this.on_visible(is);\n }\n }\n /**Overrideable function called when the element becomes visible or hidden\n * If intersection observer is not attached it is based on connectedCallback, which is less accurate*/\n protected on_visible(_is: boolean) {}\n\n #resize_observe = false;\n #actual_size?: { width: number; height: number };\n /**Returns actual size and position of the element\n * if a resize observer is attached to the element, it will return the result of that, otherwise it will return the result of getBoundingClientRect()*/\n get actual_size(): { width: number; height: number } {\n return this.#actual_size ?? this.getBoundingClientRect();\n }\n\n /**Attaches the component to the global resize observer */\n attach_to_resize_observer(): this {\n if (this.is_visible) base_resize_observer.observe(this);\n this.#resize_observe = true;\n return this;\n }\n\n /**Dettaches the component from the global resize observer */\n detach_from_resize_observer(): this {\n if (this.is_visible) base_resize_observer.unobserve(this);\n this.#resize_observe = false;\n this.#actual_size = undefined;\n return this;\n }\n\n private internal_set_size_pos(rect: DOMRectReadOnly) {\n this.#actual_size = rect;\n this.on_resize(rect);\n }\n\n /**Overrideable function called when the element is resized\n * Only triggers when a resize observer is attached to the element, otherwise it will not trigger*/\n protected on_resize(_rect: { width: number; height: number }) {}\n\n // _____ _____ ______ _____ _____\n // /\\ / ____/ ____| ____|/ ____/ ____|\n // / \\ | | | | | |__ | (___| (___\n // / /\\ \\| | | | | __| \\___ \\\\___ \\\n // / ____ \\ |___| |____| |____ ____) |___) |\n // /_/ \\_\\_____\\_____|______|_____/_____/\n /**Sets the access of the element, passing undefined is the same as passing write access*/\n set access(access: AccessTypes) {\n if (this.#access === access) return;\n this.#access = access;\n switch (access) {\n case AccessTypes.Write:\n this.inert = false;\n break;\n case AccessTypes.Read:\n this.inert = true;\n break;\n case AccessTypes.None:\n this.setAttribute(\"inert\", \"none\");\n break;\n }\n this.on_access(access);\n }\n\n /**Overrideable function called when access is changed */\n protected on_access(_access: AccessTypes) {}\n\n /**Returns the current access of the element */\n get access(): AccessTypes {\n return this.#access ?? AccessTypes.Write;\n }\n // _____ _______ _______ ______\n // / ____|__ __|/\\|__ __| ____|\n // | (___ | | / \\ | | | |__\n // \\___ \\ | | / /\\ \\ | | | __|\n // ____) | | |/ ____ \\| | | |____\n // |_____/ |_/_/ \\_\\_| |______|\n /**Attaches a state to a function, so that the function is subscribed to the state when the component is connected\n * @param visible when set true the function is only subscribed when the element is visible, this requires an observer to be attached to the element*/\n attach_state<S extends State<any>>(\n state: S,\n func: StateInferSub<S>,\n visible?: boolean,\n ): typeof func {\n if (this.#states.has(func))\n console.error(\"Function already registered with element\", func, this);\n else {\n this.#states.set(func, [state, Boolean(visible)]);\n if (visible ? this.is_visible : this.is_connected)\n state.sub(func as StateSub<any>, true);\n }\n return func;\n }\n\n /**Detaches the function from the state/component */\n detach_state(func: StateSub<any>): typeof func {\n const state = this.#states.get(func);\n if (state) {\n if (state[1] ? this.is_visible : this.is_connected) state[0].unsub(func);\n this.#states.delete(func);\n } else console.error(\"Function not registered with element\", func, this);\n return func;\n }\n\n /**Attaches a state to a function, so that the function is subscribed to the state when the component is connected\n * @param visible when set true the function is only subscribed when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_symbol<S extends State<any>>(\n symbol: symbol,\n state: S,\n func: StateInferSub<S>,\n visible?: boolean,\n ): this {\n this.detach_state_from_symbol(symbol).#props.set(\n symbol,\n this.attach_state(state, func, visible),\n );\n return this;\n }\n\n /**Detaches the function from the state/component */\n detach_state_from_symbol(symbol: symbol): this {\n const pro = this.#props.get(symbol);\n if (pro) {\n this.detach_state(pro);\n this.#props.delete(symbol);\n }\n return this;\n }\n\n // _____ _______ _______ ______ _____ _____ ____ _____\n // / ____|__ __|/\\|__ __| ____| | __ \\| __ \\ / __ \\| __ \\\n // | (___ | | / \\ | | | |__ | |__) | |__) | | | | |__) |\n // \\___ \\ | | / /\\ \\ | | | __| | ___/| _ /| | | | ___/\n // ____) | | |/ ____ \\| | | |____ | | | | \\ \\| |__| | |\n // |_____/ |_/_/ \\_\\_| |______| |_| |_| \\_\\\\____/|_|\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_ROA_to_prop<K extends keyof this>(\n prop: K,\n state: StateROA<this[K], any, any>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(state, (val) => (this[prop] = val.value), visible),\n );\n return this;\n }\n\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element\n * @param fallback the fallback value for the property when the state is not ok, if undefined the property is not updated when the state is not ok*/\n attach_state_ROA_to_prop_map<K extends keyof this, T = this[K]>(\n prop: K,\n state: StateROA<T, any, any>,\n map: (val: T) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (val) => {\n const o = map(val.value);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param map_err function called when state gives a ResultErr,\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_prop<K extends keyof this>(\n prop: K,\n state: StateREA<this[K], any, any>,\n map_err: (error: string) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? some(v.value) : map_err(v.error);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n /**Attaches a state to a property, so that the property is updated when the state changes\n * @param prop the property to attach the state to\n * @param state the state to attach to the property\n * @param map_err function called when state gives a ResultErr,\n * @param map function called when state gives a ResultOk,\n * @param visible when set true the property is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_prop_map<K extends keyof this, T = this[K]>(\n prop: K,\n state: StateREA<T, any, any>,\n map_err: (error: string) => Option<this[K]>,\n map: (val: T) => Option<this[K]>,\n visible?: boolean,\n ): this {\n this.detach_state_from_prop(prop).#props.set(\n prop,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? map(v.value) : map_err(v.error);\n if (o.some) this[prop] = o.value;\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Detaches the state from the property */\n detach_state_from_prop<T extends keyof this>(prop: T): this {\n const pro = this.#props.get(prop);\n if (pro) {\n this.detach_state(pro);\n this.#props.delete(prop);\n }\n return this;\n }\n\n // _____ _______ _______ ______ _______ _______ _____ _____ ____ _ _ _______ ______\n // / ____|__ __|/\\|__ __| ____| /\\|__ __|__ __| __ \\|_ _| _ \\| | | |__ __| ____|\n // | (___ | | / \\ | | | |__ / \\ | | | | | |__) | | | | |_) | | | | | | | |__\n // \\___ \\ | | / /\\ \\ | | | __| / /\\ \\ | | | | | _ / | | | _ <| | | | | | | __|\n // ____) | | |/ ____ \\| | | |____ / ____ \\| | | | | | \\ \\ _| |_| |_) | |__| | | | | |____\n // |_____/ |_/_/ \\_\\_| |______| /_/ \\_\\_| |_| |_| \\_\\_____|____/ \\____/ |_| |______|\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_ROA_to_attribute(\n qualified_name: string,\n state: StateROA<string, any, any>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (val) => this.setAttribute(qualified_name, val.value),\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element\n * @param fallback the fallback value for the attribute when the state is not ok, if undefined the attribute is not updated when the state is not ok*/\n attach_state_ROA_to_attribute_map<U>(\n qualified_name: string,\n state: StateROA<U, any, any>,\n map: (val: U) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (val) => {\n const o = map(val.value);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param map_err function called when state gives a ResultErr,\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_attribute(\n qualified_name: string,\n state: StateREA<string, any, any>,\n map_err: (error: string) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? some(v.value) : map_err(v.error);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Attaches a state to an element attribute, so that the attribute is updated when the state changes\n * @param qualified_name the qualified name of the attribute to attach the state to\n * @param state the state to attach to the attribute\n * @param map_err function called when state gives a ResultErr,\n * @param map function called when state gives a ResultOk,\n * @param visible when set true the attribute is only updated when the element is visible, this requires an observer to be attached to the element*/\n attach_state_to_attribute_map<U>(\n qualified_name: string,\n state: StateREA<U, any, any>,\n map_err: (error: string) => Option<string>,\n map: (val: U) => Option<string>,\n visible?: boolean,\n ): this {\n this.detach_state_from_attribute(qualified_name).#attr.set(\n qualified_name,\n this.attach_state(\n state,\n (v) => {\n const o = v.ok ? map(v.value) : map_err(v.error);\n if (o.some) this.setAttribute(qualified_name, o.value);\n },\n visible,\n ),\n );\n return this;\n }\n\n /**Detaches the state from the property */\n detach_state_from_attribute(qualified_name: string): this {\n const pro = this.#attr.get(qualified_name);\n if (pro) {\n this.detach_state(pro);\n this.#attr.delete(qualified_name);\n }\n return this;\n }\n}\n","const RESERVED_NAMES = new Set([\n \"annotation-xml\",\n \"color-profile\",\n \"font-face\",\n \"font-face-src\",\n \"font-face-uri\",\n \"font-face-format\",\n \"font-face-name\",\n \"missing-glyph\",\n]);\n\nconst regex =\n /^[a-z](?:[\\.0-9_a-z\\xB7\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u037D\\u037F-\\u1FFF\\u200C\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF])*-(?:[\\x2D\\.0-9_a-z\\xB7\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u037D\\u037F-\\u1FFF\\u200C\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF])*$/;\n\n/**Gives more information about whats wrong with the given element name */\nexport const validate_element_name = (name: string) => {\n if (!name) return \"Missing element name.\";\n if (/[A-Z]/.test(name))\n return \"Custom element names must not contain uppercase ASCII characters.\";\n if (!name.includes(\"-\"))\n return \"Custom element names must contain a hyphen. Example: unicorn-cake\";\n if (/^\\d/i.test(name))\n return \"Custom element names must not start with a digit.\";\n if (/^-/i.test(name))\n return \"Custom element names must not start with a hyphen.\";\n // https://html.spec.whatwg.org/multipage/scripting.html#prod-potentialcustomelementname\n if (!regex.test(name)) return \"Invalid element name.\";\n if (RESERVED_NAMES.has(name))\n return \"The supplied element name is reserved and can't be used.\\nSee: https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name\";\n return \"Unknown fault\";\n};\n\nlet base_element_global_namespace = \"\";\n\nexport const set_base_element_global_namespace = (namespace: string) => {\n base_element_global_namespace = namespace + (namespace.length ? \"-\" : \"\");\n};\n\ninterface ElementConstructor {\n element_name: () => string;\n element_name_space: () => string;\n}\n\n/**Generates the base name for a custom element */\nexport const base_element_name = (element: ElementConstructor): string => {\n const namespace = element.element_name_space();\n const check = element.element_name;\n let define_name = \"\";\n let runner = element;\n // @ts-expect-error Very dynamic stuff\n while (runner !== HTMLElement) {\n if (namespace !== runner.element_name_space()) break;\n const name = runner.element_name();\n runner = Object.getPrototypeOf(runner) as ElementConstructor;\n if (check === runner.element_name)\n throw new Error(\n \"Element uses same name as ancestor, abstract classes should return '@abstract@'\",\n );\n if (!name.length) throw new Error(\"Element doesn't define element name\");\n if (name !== \"@abstract@\") define_name = \"-\" + name + define_name;\n }\n return base_element_global_namespace + namespace + define_name;\n};\n\nexport const ELEMENT_LIST: Set<string> = new Set();\n\n/**Defines elements inheriting from the base*/\nexport const define_element = (element: ElementConstructor) => {\n const namespace = element.element_name_space();\n const check = element.element_name;\n let define_name = \"\";\n let runner = element;\n // @ts-expect-error Very dynamic stuff\n while (runner !== HTMLElement) {\n if (namespace !== runner.element_name_space()) break;\n\n const name = runner.element_name();\n runner = Object.getPrototypeOf(runner) as ElementConstructor;\n if (check === runner.element_name)\n throw new Error(\n 'Failed to define element \"' +\n namespace +\n \"-\" +\n name +\n define_name +\n '\" ' +\n \"Element uses same name as ancestor, abstract classes should return '@abstract@'\",\n );\n if (!name.length) throw new Error(\"Element doesn't define element name\");\n if (name !== \"@abstract@\") define_name = \"-\" + name + define_name;\n }\n define_name = base_element_global_namespace + namespace + define_name;\n //Checked first, browsers word the error for a name or class used twice differently\n if (customElements.get(define_name))\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" the name has already been defined, by another element or by this library being loaded twice',\n );\n //getName is missing in older browsers\n const defined_as =\n \"getName\" in customElements\n ? customElements.getName(element as unknown as CustomElementConstructor)\n : null;\n if (defined_as)\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" the class is already defined as \"' +\n defined_as +\n '\"',\n );\n try {\n // @ts-expect-error Dynamic custom element definition\n customElements.define(define_name, element);\n ELEMENT_LIST.add(define_name);\n } catch {\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" ' +\n validate_element_name(define_name),\n );\n }\n};\n","import state_ui from \"../state_ui\";\nimport { Base } from \"./base\";\nimport { define_element } from \"./define_element\";\n\ninterface LoopOptions<T, N extends ChildNode> {\n /**Updates a node to a new value, when given nodes are reused instead of replaced*/\n change?: (element: N, new_value: T) => void;\n /**Called for every node that is removed or replaced*/\n destructor?: (element: N) => void;\n}\n\n/**Element with one child node per value of an array, follows the changes of array states*/\nexport class Loop<T, N extends ChildNode> extends Base {\n static element_name(): string {\n return \"loop\";\n }\n static element_name_space(): string {\n return \"base\";\n }\n\n #generator: (val: T) => N;\n #destructor?: (element: N) => void;\n #change?: (element: N, new_value: T) => void;\n\n constructor(generator: (val: T) => N, options?: LoopOptions<T, N>) {\n super();\n this.#generator = generator;\n this.#destructor = options?.destructor;\n this.#change = options?.change;\n }\n\n set array(array: readonly T[]) {\n state_ui.a.apply(this, array, {\n create: this.#generator,\n update: this.#change,\n destroy: this.#destructor,\n });\n }\n\n set error(err: Node) {\n this.replaceChildren(err);\n }\n}\ndefine_element(Loop);\n\nexport function base_loop<T, N extends ChildNode>(\n generator: (val: T) => N,\n options?: LoopOptions<T, N>,\n) {\n return new Loop<T, N>(generator, options);\n}\n","import { Base } from \"./base\";\nimport { base_element_name } from \"./define_element\";\n\n/**Shared svg class for elements to extend\n * See Base for more information on how to define elements, and the element lifecycle */\nexport abstract class BaseSVG extends Base {\n /**Returns the name used to define the element, Abstract classes should return @abstract@ */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"lib\";\n }\n\n protected abstract default_canvas(): SVGSVGElement;\n\n readonly canvas: SVGSVGElement = this.default_canvas();\n\n constructor() {\n super();\n this.canvas.classList.add(\n base_element_name(this.constructor as typeof BaseSVG),\n );\n this.canvas.appendChild(this);\n }\n}\n"],"mappings":";;;;;;AAGA,MAAa,cAAc;CACzB,OAAO;CAC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,KAAW;EACnB,KAAK,gBAAgB,GAAG;CAC1B;AACF;AACA,eAAe,IAAI;AAEnB,SAAgB,UACd,WACA,SACA;CACA,OAAO,IAAI,KAAW,WAAW,OAAO;AAC1C;;;;AC7CA,IAAsB,UAAtB,cAAsC,KAAK;;CAEzC,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;CAIA,SAAiC,KAAK,eAAe;CAErD,cAAc;EACZ,MAAM;EACN,KAAK,OAAO,UAAU,IACpB,kBAAkB,KAAK,WAA6B,CACtD;EACA,KAAK,OAAO,YAAY,IAAI;CAC9B;AACF"}
@@ -1,76 +1,131 @@
1
1
  import '../style.css';
2
2
  import { l as Base } from "../index-CvzH3M_5.mjs";
3
- import { State } from "@chocbite/ts-lib/state";
4
- import { Option } from "@chocbite/ts-lib/result";
5
- export declare abstract class ViewportElement {
3
+ /**Event dispatched on a widget when its position, size or rotation changes */
4
+ export declare const WIDGET_TRANSFORM_EVENT = "widget_transform";
5
+ /**Shared class for widgets placed at a fixed position in a viewport
6
+ * Position and size are in viewport units (px before any viewport scaling)
7
+ * Rotation is in degrees clockwise around the center of the widget
8
+ *
9
+ * Width and height must always be set, they default to 0
10
+ *
11
+ * Widgets declare their original size, which is the size their content is laid out at
12
+ * The content is then scaled from the original size to the width and height of the widget
13
+ * Widgets that should not stretch, like text, return width and height as their original size
14
+ *
15
+ * WIDGET_TRANSFORM_EVENT is dispatched whenever position, size or rotation changes*/
16
+ export declare abstract class WidgetBase extends Base {
6
17
  #private;
7
- protected abstract element_name(): string;
8
- protected abstract element_name_space(): string;
9
- /**Default width of element when created */
10
- abstract default_width(): number;
11
- /**Default height of element when created */
12
- abstract default_height(): number;
13
- /**Element optimal ratio, returns the ratio where the element has no distortion.
14
- * If the element can dynamically change based on ratio, return none. */
15
- optimal_ratio(): Option<number>;
16
- /**Called when the element has no optimal ratio and its dimensions change.
17
- * Descendants can override this to re-layout their content in the new
18
- * coordinate space defined by the updated viewBox. */
19
- protected on_resize(_width: number, _height: number): void;
20
- readonly canvas: SVGSVGElement;
18
+ /**Returns the name used to define the element, Abstract classes should return @abstract@ */
19
+ static element_name(): string;
20
+ /**Returns the namespace override for the element*/
21
+ static element_name_space(): string;
21
22
  constructor();
22
- set position_x(value: number);
23
- get position_x(): number;
24
- set position_y(value: number);
25
- get position_y(): number;
26
- set rotation(value: number);
23
+ protected connectedCallback(): void;
24
+ /**Returns the width the content of the widget is laid out at, return this.width to not stretch */
25
+ abstract get original_width(): number;
26
+ /**Returns the height the content of the widget is laid out at, return this.height to not stretch */
27
+ abstract get original_height(): number;
28
+ /**Sets the x position of the left edge of the widget */
29
+ set x(x: number);
30
+ /**Returns the x position of the left edge of the widget */
31
+ get x(): number;
32
+ /**Sets the y position of the top edge of the widget */
33
+ set y(y: number);
34
+ /**Returns the y position of the top edge of the widget */
35
+ get y(): number;
36
+ /**Sets the width of the widget */
37
+ set width(width: number);
38
+ /**Returns the width of the widget */
39
+ get width(): number;
40
+ /**Sets the height of the widget */
41
+ set height(height: number);
42
+ /**Returns the height of the widget */
43
+ get height(): number;
44
+ /**Sets the rotation of the widget in degrees, rotating clockwise around the center of the widget */
45
+ set rotation(rotation: number);
46
+ /**Returns the rotation of the widget in degrees */
27
47
  get rotation(): number;
28
- /**Rotation center x coordinate, relative to the element's display area.
29
- * Defaults to half of default_width (center of element). */
30
- set rotation_center_x(value: number);
31
- get rotation_center_x(): number;
32
- /**Rotation center y coordinate, relative to the element's display area.
33
- * Defaults to half of default_height (center of element). */
34
- set rotation_center_y(value: number);
35
- get rotation_center_y(): number;
36
- /**Display width of the element. Changing this scales the element.
37
- * - If the element has an optimal_ratio, the viewBox stays at default
38
- * dimensions and the SVG content is stretched/scaled to fill the new size.
39
- * - If the element has no optimal_ratio, the viewBox is updated to match
40
- * the new dimensions and on_resize is called. */
41
- set width(value: number);
48
+ }
49
+ /**Page of widgets with a fixed size
50
+ * Width and height are the size of the page in page units (px before any viewport scaling)*/
51
+ declare class Page extends Base {
52
+ #private;
53
+ /**Returns the name used to define the element */
54
+ static element_name(): string;
55
+ /**Returns the namespace override for the element*/
56
+ static element_name_space(): string;
57
+ constructor();
58
+ /**Sets the width of the page */
59
+ set width(width: number);
60
+ /**Returns the width of the page */
42
61
  get width(): number;
43
- /**Display height of the element. Changing this scales the element.
44
- * - If the element has an optimal_ratio, the viewBox stays at default
45
- * dimensions and the SVG content is stretched/scaled to fill the new size.
46
- * - If the element has no optimal_ratio, the viewBox is updated to match
47
- * the new dimensions and on_resize is called. */
48
- set height(value: number);
62
+ /**Sets the height of the page */
63
+ set height(height: number);
64
+ /**Returns the height of the page */
49
65
  get height(): number;
66
+ /**Sets the widgets on the page, the array order is the drawing order with the last widget on top
67
+ * Widgets already on the page are kept in place, so they are only reconnected if their order changes */
68
+ set widgets(widgets: readonly WidgetBase[]);
69
+ /**Returns the widgets on the page */
70
+ get widgets(): readonly WidgetBase[];
50
71
  }
72
+ interface CanvasPageOptions {
73
+ /**Width of the page in page units, defaults to 1920 */
74
+ width?: number;
75
+ /**Height of the page in page units, defaults to 1080 */
76
+ height?: number;
77
+ /**Widgets on the page, the last widget is drawn on top */
78
+ widgets?: readonly WidgetBase[];
79
+ }
80
+ /**Viewport showing a page of widgets
81
+ * The page is scaled to fit inside the viewport element while keeping its aspect ratio, and centered
82
+ *
83
+ * When edit is true the page can be zoomed and panned, and a checkerboard is shown behind it
84
+ * Wheel and touchpad two finger swipe pans, ctrl + wheel or swipe zooms toward the cursor
85
+ * Shift + vertical wheel pans horizontally
86
+ * Touchpad pinch zooms toward the cursor
87
+ * Holding alt makes wheel zoom and pan 10 times slower
88
+ * Two finger touch pinch zooms and pans, middle or right mouse drag pans
89
+ *
90
+ * Pressing a widget in edit mode selects it and attaches a transformer to move, resize and rotate it
91
+ * Pressing outside any widget clears the selection*/
51
92
  declare class Viewport extends Base {
52
93
  #private;
94
+ /**Returns the name used to define the element */
53
95
  static element_name(): string;
96
+ /**Returns the namespace override for the element*/
54
97
  static element_name_space(): string;
98
+ constructor();
99
+ /**Sets the page shown in the viewport */
100
+ set page(page: Page | undefined);
101
+ /**Returns the page shown in the viewport */
102
+ get page(): Page | undefined;
103
+ /**Sets edit mode, which enables zooming and panning and shows a checkerboard background
104
+ * Leaving edit mode resets the view to fit the page */
105
+ set edit(edit: boolean);
106
+ /**Returns whether edit mode is enabled */
107
+ get edit(): boolean;
108
+ /**Sets the selected widget, which the transformer is attached to, selection is cleared when leaving edit mode */
109
+ set selected(widget: WidgetBase | undefined);
110
+ /**Returns the selected widget */
111
+ get selected(): WidgetBase | undefined;
112
+ /**Returns the current scale from page units to screen pixels */
113
+ get scale(): number;
114
+ protected on_resize(): void;
55
115
  protected connectedCallback(): void;
56
116
  protected disconnectedCallback(): void;
57
- constructor(canvas_width: number, canvas_height: number, infinite_canvas?: boolean);
58
- set canvas_width(value: number);
59
- get canvas_width(): number;
60
- set canvas_height(value: number);
61
- get canvas_height(): number;
62
- readonly pan_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
63
- readonly pan_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
64
- readonly zoom: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
65
- readonly grid_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
66
- readonly grid_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
67
- readonly grid_rotate: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
68
- set elements(elements: ViewportElement[] | State<ViewportElement[]>);
69
- attach_mover(move: ViewportElement): void;
70
117
  }
71
- declare function create_viewport(canvas_width: number, canvas_height: number, infinite_canvas?: boolean): Viewport;
72
- export declare const viewport: {
73
- create_viewport: typeof create_viewport;
118
+ interface CanvasViewportOptions {
119
+ /**Page shown in the viewport */
120
+ page?: Page;
121
+ /**Enables zooming, panning and selecting widgets */
122
+ edit?: boolean;
123
+ }
124
+ /**Displaying and editing graphics with a fixed position and size */
125
+ export declare const canvas: {
126
+ page: (options?: CanvasPageOptions) => Page;
127
+ viewport: (options?: CanvasViewportOptions) => Viewport;
128
+ WIDGET_TRANSFORM_EVENT: string;
74
129
  };
75
- export {};
130
+ export { type CanvasPageOptions, type CanvasViewportOptions, type Page, type Viewport, canvas as default };
76
131
  //# sourceMappingURL=index.d.mts.map