@chocbite/ts-lib-ui 1.0.4 → 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/AGENTS.md +609 -0
- package/SOURCE.md +17135 -0
- package/base/index.mjs +1 -1
- package/base/index.mjs.map +1 -1
- package/canvas/index.mjs +35 -19
- package/canvas/index.mjs.map +1 -1
- package/context-menu/index.mjs +1 -1
- package/{context-menu-Cz9rqUaM.mjs → context-menu-CA4o4fXx.mjs} +2 -2
- package/{context-menu-Cz9rqUaM.mjs.map → context-menu-CA4o4fXx.mjs.map} +1 -1
- package/form/index.mjs +2 -2
- package/keyboard/index.mjs +1 -1
- package/list/index.mjs +1 -1
- package/{list-DXkEJKjx.mjs → list-CNYJ3sm-.mjs} +4 -4
- package/list-CNYJ3sm-.mjs.map +1 -0
- package/package.json +7 -2
- package/spinner/index.mjs +1 -1
- package/state_ui/index.mjs +2 -0
- package/{state-OCzEmq3j.mjs → state_ui-Bm3TeKNL.mjs} +3 -3
- package/state_ui-Bm3TeKNL.mjs.map +1 -0
- package/test/index.d.mts +98 -0
- package/test/index.mjs +193 -0
- package/test/index.mjs.map +1 -0
- package/theme/index.mjs +1 -1
- package/{theme-CFeGnUuF.mjs → theme-ChmpRObz.mjs} +2 -2
- package/{theme-CFeGnUuF.mjs.map → theme-ChmpRObz.mjs.map} +1 -1
- package/list-DXkEJKjx.mjs.map +0 -1
- package/state/index.mjs +0 -2
- package/state-OCzEmq3j.mjs.map +0 -1
- /package/{state → state_ui}/index.d.mts +0 -0
package/base/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
|
-
import { t as state_ui } from "../
|
|
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
|
package/base/index.mjs.map
CHANGED
|
@@ -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,EAAE,QAAQ,KAAK;IACjC,MAAM,SAAS,EAAE,EAAE,CAAC;IACpB,IAAI,EAAE,EAAE,CAAC,gBAAgB;KACvB,KAAK,wBAAwB,IAAI,MAAM;KACvC,KAAK,uBAAuB,OAAO,MAAM;IAC3C,OAAO;KACL,KAAK,uBAAuB,OAAO,MAAM;KACzC,KAAK,uBAAuB,IAC1B,QACA,MAAM,KAAK,qBACb;KACA,KAAK,wBAAwB,OAAO,MAAM;IAC5C;GACF;GACA,IAAI,CAAC,KAA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;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;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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OAAO,UAAU,IACpB,kBAAkB,KAAK,WAA6B,CACtD;EACA,KAAK,OAAO,YAAY,IAAI;CAC9B;AACF"}
|
package/canvas/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
2
|
import { Base, define_element } from "../base/index.mjs";
|
|
3
|
-
import { i as theme_init_variable_root } from "../theme-
|
|
3
|
+
import { i as theme_init_variable_root } from "../theme-ChmpRObz.mjs";
|
|
4
4
|
import { $q as material_open_with_rounded, ha as material_arrow_range_rounded, r2 as material_rotate_right_rounded } from "../icons-e2J_Ojic.mjs";
|
|
5
5
|
import { BLUE, GREY } from "@chocbite/ts-lib/colors";
|
|
6
6
|
// src/canvas/shared.ts
|
|
@@ -182,11 +182,10 @@ const SNAP_GRID_FINE = 1;
|
|
|
182
182
|
/**Angle in degrees rotation snaps to, and the finer angle used while alt is held */
|
|
183
183
|
const SNAP_ANGLE = 15;
|
|
184
184
|
const SNAP_ANGLE_FINE = 5;
|
|
185
|
-
/**Rounds the value to the nearest multiple of step, a step of 0 returns the value unchanged
|
|
186
|
-
* Steps below 1 divide by the inverse, so steps like 0.1 do not give floating point errors like 0.30000000000000004 */
|
|
185
|
+
/**Rounds the value to the nearest multiple of step, a step of 0 returns the value unchanged */
|
|
187
186
|
function snap(value, step) {
|
|
188
187
|
if (step <= 0) return value;
|
|
189
|
-
return
|
|
188
|
+
return Math.round(value / step) * step;
|
|
190
189
|
}
|
|
191
190
|
/**Resize handles, x and y is the edge they move, -1 is the left or top edge, 1 the right or bottom edge, 0 none */
|
|
192
191
|
const RESIZE_HANDLES = [
|
|
@@ -297,12 +296,14 @@ var Transformer = class extends Base {
|
|
|
297
296
|
get dragging() {
|
|
298
297
|
return this.#drag !== void 0;
|
|
299
298
|
}
|
|
300
|
-
/**Sets how page units map to viewport pixels, viewport = offset + page * scale
|
|
299
|
+
/**Sets how page units map to viewport pixels, viewport = offset + page * scale
|
|
300
|
+
* During a drag the widget is moved so the grabbed point stays under the pointer */
|
|
301
301
|
view(offset_x, offset_y, scale) {
|
|
302
302
|
this.#offset_x = offset_x;
|
|
303
303
|
this.#offset_y = offset_y;
|
|
304
304
|
this.#scale = scale;
|
|
305
305
|
this.#update();
|
|
306
|
+
if (this.#drag?.last) this.#apply_drag(this.#drag, this.#drag.last);
|
|
306
307
|
}
|
|
307
308
|
#add(class_name, action, icon) {
|
|
308
309
|
const element = this.appendChild(document.createElement("div"));
|
|
@@ -329,13 +330,20 @@ var Transformer = class extends Base {
|
|
|
329
330
|
e.preventDefault();
|
|
330
331
|
e.stopPropagation();
|
|
331
332
|
const rect = this.getBoundingClientRect();
|
|
333
|
+
const center_x = rect.left + rect.width / 2;
|
|
334
|
+
const center_y = rect.top + rect.height / 2;
|
|
335
|
+
const scale = this.#scale;
|
|
336
|
+
const origin_x = center_x - this.#offset_x - (widget.x + widget.width / 2) * scale;
|
|
337
|
+
const origin_y = center_y - this.#offset_y - (widget.y + widget.height / 2) * scale;
|
|
332
338
|
this.#drag = {
|
|
333
339
|
action,
|
|
334
340
|
pointer_id: e.pointerId,
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
341
|
+
origin_x,
|
|
342
|
+
origin_y,
|
|
343
|
+
page_x: (e.clientX - origin_x - this.#offset_x) / scale,
|
|
344
|
+
page_y: (e.clientY - origin_y - this.#offset_y) / scale,
|
|
345
|
+
angle: Math.atan2(e.clientY - center_y, e.clientX - center_x),
|
|
346
|
+
last: void 0,
|
|
339
347
|
x: widget.x,
|
|
340
348
|
y: widget.y,
|
|
341
349
|
width: widget.width,
|
|
@@ -363,10 +371,22 @@ var Transformer = class extends Base {
|
|
|
363
371
|
};
|
|
364
372
|
#on_pointer_move = (e) => {
|
|
365
373
|
const drag = this.#drag;
|
|
374
|
+
if (!drag || e.pointerId !== drag.pointer_id) return;
|
|
375
|
+
drag.last = e;
|
|
376
|
+
this.#apply_drag(drag, e);
|
|
377
|
+
};
|
|
378
|
+
#on_pointer_up = (e) => {
|
|
379
|
+
if (e.pointerId === this.#drag?.pointer_id) this.#stop_drag();
|
|
380
|
+
};
|
|
381
|
+
/**Updates the widget from the pointer event and the current view */
|
|
382
|
+
#apply_drag(drag, e) {
|
|
366
383
|
const widget = this.#widget;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const
|
|
384
|
+
const scale = this.#scale;
|
|
385
|
+
if (!widget || scale <= 0) return;
|
|
386
|
+
const view_x = drag.origin_x + this.#offset_x;
|
|
387
|
+
const view_y = drag.origin_y + this.#offset_y;
|
|
388
|
+
const delta_x = (e.clientX - view_x) / scale - drag.page_x;
|
|
389
|
+
const delta_y = (e.clientY - view_y) / scale - drag.page_y;
|
|
370
390
|
const grid = e.shiftKey ? 0 : e.altKey ? SNAP_GRID_FINE : SNAP_GRID;
|
|
371
391
|
const action = drag.action;
|
|
372
392
|
switch (action.type) {
|
|
@@ -393,16 +413,12 @@ var Transformer = class extends Base {
|
|
|
393
413
|
break;
|
|
394
414
|
}
|
|
395
415
|
case "rotate": {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
widget.rotation = (snap(drag.rotation + (now - start) * 180 / Math.PI, e.shiftKey ? 0 : e.altKey ? SNAP_ANGLE_FINE : SNAP_ANGLE) % 360 + 360) % 360;
|
|
416
|
+
const now = Math.atan2(e.clientY - (view_y + (drag.y + drag.height / 2) * scale), e.clientX - (view_x + (drag.x + drag.width / 2) * scale));
|
|
417
|
+
widget.rotation = (snap(drag.rotation + (now - drag.angle) * 180 / Math.PI, e.shiftKey ? 0 : e.altKey ? SNAP_ANGLE_FINE : SNAP_ANGLE) % 360 + 360) % 360;
|
|
399
418
|
break;
|
|
400
419
|
}
|
|
401
420
|
}
|
|
402
|
-
}
|
|
403
|
-
#on_pointer_up = (e) => {
|
|
404
|
-
if (e.pointerId === this.#drag?.pointer_id) this.#stop_drag();
|
|
405
|
-
};
|
|
421
|
+
}
|
|
406
422
|
};
|
|
407
423
|
define_element(Transformer);
|
|
408
424
|
// src/canvas/viewport.ts
|
package/canvas/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/canvas/shared.ts","../../src/canvas/page.ts","../../src/canvas/widget.ts","../../src/canvas/transformer.ts","../../src/canvas/viewport.ts","../../src/canvas/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst theme_root = theme_init_variable_root(\n \"canvas\",\n \"Canvas\",\n \"Theme variables for canvas viewports and pages\",\n);\n\n// _____ ____ _ ____ _____ _____\n// / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | | | | | | | | | |__) | (___\n// | | | | | | | | | | | _ / \\___ \\\n// | |___| |__| | |___| |__| | | \\ \\ ____) |\n// \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors = theme_root.make_sub_group(\n \"colors\",\n \"Colors\",\n \"Colors used in viewports\",\n);\ncolors.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of the viewport around the page\",\n GREY[\"300\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"pageBackground\",\n \"Page Background Color\",\n \"Color of the page behind the widgets\",\n GREY[\"50\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n\n// ______ _____ _____ _______\n// | ____| __ \\_ _|__ __|\n// | |__ | | | || | | |\n// | __| | | | || | | |\n// | |____| |__| || |_ | |\n// |______|_____/_____| |_|\nconst edit = theme_root.make_sub_group(\n \"edit\",\n \"Edit\",\n \"Settings for viewports in edit mode\",\n);\nedit.make_variable(\n \"checker1\",\n \"Checkerboard First Color\",\n \"First color of the checkerboard shown behind the page in edit mode\",\n GREY[\"300\"],\n GREY[\"600\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checker2\",\n \"Checkerboard Second Color\",\n \"Second color of the checkerboard shown behind the page in edit mode\",\n GREY[\"200\"],\n GREY[\"700\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checkerSize\",\n \"Checkerboard Square Size\",\n \"Size of one square of the checkerboard shown behind the page in edit mode\",\n \"0.625rem\",\n \"0.625rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\n// _______ _____ _ _ _____ ______ ____ _____ __ __ ______ _____\n// |__ __| __ \\ /\\ | \\ | |/ ____| ____/ __ \\| __ \\| \\/ | ____| __ \\\n// | | | |__) | / \\ | \\| | (___ | |__ | | | | |__) | \\ / | |__ | |__) |\n// | | | _ / / /\\ \\ | . ` |\\___ \\| __|| | | | _ /| |\\/| | __| | _ /\n// | | | | \\ \\ / ____ \\| |\\ |____) | | | |__| | | \\ \\| | | | |____| | \\ \\\n// |_| |_| \\_\\/_/ \\_\\_| \\_|_____/|_| \\____/|_| \\_\\_| |_|______|_| \\_\\\nconst transformer = theme_root.make_sub_group(\n \"transformer\",\n \"Transformer\",\n \"Settings for the transformer used to move, resize and rotate widgets in edit mode\",\n);\ntransformer.make_variable(\n \"color\",\n \"Transformer Color\",\n \"Color of the transformer outline and handle borders\",\n BLUE[\"600\"],\n BLUE[\"300\"],\n \"Color\",\n undefined,\n);\ntransformer.make_variable(\n \"handleBackground\",\n \"Handle Background Color\",\n \"Background color of the transformer handles\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\n","import { Base, define_element } from \"#base\";\nimport \"./page.scss\";\nimport \"./shared\";\nimport type { WidgetBase } from \"./widget\";\n\n/**Page of widgets with a fixed size\n * Width and height are the size of the page in page units (px before any viewport scaling)*/\nexport class Page extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"page\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #width: number = 1920;\n #height: number = 1080;\n #widgets: readonly WidgetBase[] = [];\n\n constructor() {\n super();\n this.style.width = this.#width + \"px\";\n this.style.height = this.#height + \"px\";\n }\n\n /**Sets the width of the page */\n set width(width: number) {\n this.#width = width;\n this.style.width = width + \"px\";\n }\n /**Returns the width of the page */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the page */\n set height(height: number) {\n this.#height = height;\n this.style.height = height + \"px\";\n }\n /**Returns the height of the page */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the widgets on the page, the array order is the drawing order with the last widget on top\n * Widgets already on the page are kept in place, so they are only reconnected if their order changes */\n set widgets(widgets: readonly WidgetBase[]) {\n const keep = new Set(widgets);\n for (const widget of this.#widgets)\n if (!keep.has(widget) && widget.parentElement === this) widget.remove();\n for (let i = 0; i < widgets.length; i++) {\n const current = this.children[i];\n if (current !== widgets[i])\n this.insertBefore(widgets[i], current ?? null);\n }\n this.#widgets = widgets;\n }\n /**Returns the widgets on the page */\n get widgets(): readonly WidgetBase[] {\n return this.#widgets;\n }\n}\ndefine_element(Page);\n\nexport interface CanvasPageOptions {\n /**Width of the page in page units, defaults to 1920 */\n width?: number;\n /**Height of the page in page units, defaults to 1080 */\n height?: number;\n /**Widgets on the page, the last widget is drawn on top */\n widgets?: readonly WidgetBase[];\n}\n\n/**Creates a page of widgets with a fixed size */\nexport const canvas_page = (options?: CanvasPageOptions): Page =>\n options ? new Page().opts(options) : new Page();\n","import { Base } from \"#base\";\n\n/**Event dispatched on a widget when its position, size or rotation changes */\nexport const WIDGET_TRANSFORM_EVENT = \"widget_transform\";\n\n/**Shared class for widgets placed at a fixed position in a viewport\n * Position and size are in viewport units (px before any viewport scaling)\n * Rotation is in degrees clockwise around the center of the widget\n *\n * Width and height must always be set, they default to 0\n *\n * Widgets declare their original size, which is the size their content is laid out at\n * The content is then scaled from the original size to the width and height of the widget\n * Widgets that should not stretch, like text, return width and height as their original size\n *\n * WIDGET_TRANSFORM_EVENT is dispatched whenever position, size or rotation changes*/\nexport abstract class WidgetBase 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 \"canvas\";\n }\n\n #x: number = 0;\n #y: number = 0;\n #width: number = 0;\n #height: number = 0;\n #rotation: number = 0;\n\n constructor() {\n super();\n this.style.position = \"absolute\";\n this.style.boxSizing = \"border-box\";\n this.style.transformOrigin = \"0 0\";\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n this.#update();\n }\n\n /**Returns the width the content of the widget is laid out at, return this.width to not stretch */\n abstract get original_width(): number;\n /**Returns the height the content of the widget is laid out at, return this.height to not stretch */\n abstract get original_height(): number;\n\n /**Sets the x position of the left edge of the widget */\n set x(x: number) {\n this.#x = x;\n this.#update();\n }\n /**Returns the x position of the left edge of the widget */\n get x(): number {\n return this.#x;\n }\n\n /**Sets the y position of the top edge of the widget */\n set y(y: number) {\n this.#y = y;\n this.#update();\n }\n /**Returns the y position of the top edge of the widget */\n get y(): number {\n return this.#y;\n }\n\n /**Sets the width of the widget */\n set width(width: number) {\n this.#width = width;\n this.#update();\n }\n /**Returns the width of the widget */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the widget */\n set height(height: number) {\n this.#height = height;\n this.#update();\n }\n /**Returns the height of the widget */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the rotation of the widget in degrees, rotating clockwise around the center of the widget */\n set rotation(rotation: number) {\n this.#rotation = rotation;\n this.#update();\n }\n /**Returns the rotation of the widget in degrees */\n get rotation(): number {\n return this.#rotation;\n }\n\n #update() {\n const width = this.#width;\n const height = this.#height;\n const layout_width = this.original_width;\n const layout_height = this.original_height;\n const scale_x = layout_width > 0 ? width / layout_width : 1;\n const scale_y = layout_height > 0 ? height / layout_height : 1;\n this.style.left = this.#x + \"px\";\n this.style.top = this.#y + \"px\";\n this.style.width = layout_width + \"px\";\n this.style.height = layout_height + \"px\";\n //Scale the layout box to the widget size, then rotate around the center of the widget size\n this.style.transform = `translate(${width / 2}px, ${height / 2}px) rotate(${this.#rotation}deg) translate(${-width / 2}px, ${-height / 2}px) scale(${scale_x}, ${scale_y})`;\n this.dispatchEvent(new Event(WIDGET_TRANSFORM_EVENT));\n }\n}\n","import { Base, define_element } from \"#base\";\nimport {\n material_arrow_range_rounded,\n material_open_with_rounded,\n material_rotate_right_rounded,\n} from \"#icons\";\nimport type { SVGFunc } from \"#svg\";\nimport \"./shared\";\nimport \"./transformer.scss\";\nimport { WIDGET_TRANSFORM_EVENT, type WidgetBase } from \"./widget\";\n\n/**Smallest width and height a widget can be resized to */\nconst MIN_SIZE = 1;\n/**Grid positions and sizes snap to, and the finer grid used while alt is held */\nconst SNAP_GRID = 5;\nconst SNAP_GRID_FINE = 1;\n/**Angle in degrees rotation snaps to, and the finer angle used while alt is held */\nconst SNAP_ANGLE = 15;\nconst SNAP_ANGLE_FINE = 5;\n\n/**Rounds the value to the nearest multiple of step, a step of 0 returns the value unchanged\n * Steps below 1 divide by the inverse, so steps like 0.1 do not give floating point errors like 0.30000000000000004 */\nfunction snap(value: number, step: number): number {\n if (step <= 0) return value;\n return step < 1\n ? Math.round(value / step) / Math.round(1 / step)\n : Math.round(value / step) * step;\n}\n\n/**Resize handles, x and y is the edge they move, -1 is the left or top edge, 1 the right or bottom edge, 0 none */\nconst RESIZE_HANDLES = [\n { name: \"nw\", x: -1, y: -1 },\n { name: \"n\", x: 0, y: -1 },\n { name: \"ne\", x: 1, y: -1 },\n { name: \"e\", x: 1, y: 0 },\n { name: \"se\", x: 1, y: 1 },\n { name: \"s\", x: 0, y: 1 },\n { name: \"sw\", x: -1, y: 1 },\n { name: \"w\", x: -1, y: 0 },\n];\n\ntype Action =\n | { type: \"move\" }\n | { type: \"resize\"; x: number; y: number }\n | { type: \"rotate\" };\n\n/**State of the widget and pointer when a drag started */\ninterface Drag {\n action: Action;\n pointer_id: number;\n client_x: number;\n client_y: number;\n /**Center of the widget in client coordinates, used for rotation */\n center_x: number;\n center_y: number;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n}\n\n/**Dashed outline with handles, attached to a widget to move, resize and rotate it\n * Corner handles resize both axes and side handles one axis, keeping the opposite corner or side in place\n * The handle above the outline rotates the widget around its center\n * The center handle and the outline itself move the widget, the inside of the outline is left to the widgets below\n *\n * Position and size snap to a 5px grid and rotation to 15 degrees\n * Holding alt snaps to a 1px grid and 5 degrees instead, holding shift disables snapping\n *\n * Resize and rotate cursors follow the rotation of the widget in 45 degree steps\n *\n * The transformer is drawn in viewport pixels, so it keeps its size when the page is zoomed*/\nexport class Transformer extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"transformer\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #widget: WidgetBase | undefined;\n #offset_x: number = 0;\n #offset_y: number = 0;\n #scale: number = 1;\n #actions = new Map<Element, Action>();\n #drag: Drag | undefined;\n\n constructor() {\n super();\n this.hidden = true;\n for (const side of [\"top\", \"right\", \"bottom\", \"left\"])\n this.#add(\"side \" + side, { type: \"move\" });\n this.#add(\"line\", undefined);\n for (const handle of RESIZE_HANDLES)\n this.#add(\n \"handle \" + handle.name,\n { type: \"resize\", x: handle.x, y: handle.y },\n material_arrow_range_rounded,\n );\n this.#add(\"handle rotate\", { type: \"rotate\" }, material_rotate_right_rounded);\n //Added last so it is drawn on top of the other handles on small widgets\n this.#add(\"handle move\", { type: \"move\" }, material_open_with_rounded);\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#stop_drag();\n }\n\n /**Sets the widget the transformer is attached to, undefined hides the transformer */\n set widget(widget: WidgetBase | undefined) {\n if (this.#widget === widget) return;\n this.#stop_drag();\n this.#widget?.removeEventListener(\n WIDGET_TRANSFORM_EVENT,\n this.#on_widget_transform,\n );\n this.#widget = widget;\n widget?.addEventListener(WIDGET_TRANSFORM_EVENT, this.#on_widget_transform);\n this.#update();\n }\n /**Returns the widget the transformer is attached to */\n get widget(): WidgetBase | undefined {\n return this.#widget;\n }\n\n /**Returns whether a handle is being dragged */\n get dragging(): boolean {\n return this.#drag !== undefined;\n }\n\n /**Sets how page units map to viewport pixels, viewport = offset + page * scale */\n view(offset_x: number, offset_y: number, scale: number) {\n this.#offset_x = offset_x;\n this.#offset_y = offset_y;\n this.#scale = scale;\n this.#update();\n }\n\n #add(class_name: string, action: Action | undefined, icon?: SVGFunc) {\n const element = this.appendChild(document.createElement(\"div\"));\n element.className = class_name;\n if (icon) element.appendChild(icon());\n if (action) this.#actions.set(element, action);\n }\n\n #update() {\n const widget = this.#widget;\n this.hidden = !widget;\n if (!widget) return;\n const scale = this.#scale;\n this.style.left = this.#offset_x + widget.x * scale + \"px\";\n this.style.top = this.#offset_y + widget.y * scale + \"px\";\n this.style.width = widget.width * scale + \"px\";\n this.style.height = widget.height * scale + \"px\";\n this.style.transform = `rotate(${widget.rotation}deg)`;\n //Cursors only exist in 45 degree steps repeating every 180 degrees, the stylesheet picks the cursors from the closest step\n const half_turn = ((widget.rotation % 180) + 180) % 180;\n this.setAttribute(\"cursor-step\", String(Math.round(half_turn / 45) % 4));\n }\n\n #start(action: Action, e: PointerEvent) {\n const widget = this.#widget;\n if (!widget || this.#drag) return;\n e.preventDefault();\n e.stopPropagation();\n //The bounding box of the rotated outline is centered on the widget center\n const rect = this.getBoundingClientRect();\n this.#drag = {\n action,\n pointer_id: e.pointerId,\n client_x: e.clientX,\n client_y: e.clientY,\n center_x: rect.left + rect.width / 2,\n center_y: rect.top + rect.height / 2,\n x: widget.x,\n y: widget.y,\n width: widget.width,\n height: widget.height,\n rotation: widget.rotation,\n };\n window.addEventListener(\"pointermove\", this.#on_pointer_move);\n window.addEventListener(\"pointerup\", this.#on_pointer_up);\n window.addEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #stop_drag() {\n if (!this.#drag) return;\n this.#drag = undefined;\n window.removeEventListener(\"pointermove\", this.#on_pointer_move);\n window.removeEventListener(\"pointerup\", this.#on_pointer_up);\n window.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #on_widget_transform = () => {\n this.#update();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n const action =\n e.target instanceof Element ? this.#actions.get(e.target) : undefined;\n //Other buttons are left to the viewport, so middle mouse still pans\n if (!action || e.button !== 0) return;\n this.#start(action, e);\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n const drag = this.#drag;\n const widget = this.#widget;\n if (!drag || !widget || e.pointerId !== drag.pointer_id) return;\n //Pointer movement in page units\n const delta_x = (e.clientX - drag.client_x) / this.#scale;\n const delta_y = (e.clientY - drag.client_y) / this.#scale;\n const grid = e.shiftKey ? 0 : e.altKey ? SNAP_GRID_FINE : SNAP_GRID;\n const action = drag.action;\n switch (action.type) {\n case \"move\":\n widget.x = snap(drag.x + delta_x, grid);\n widget.y = snap(drag.y + delta_y, grid);\n break;\n case \"resize\": {\n const radians = (drag.rotation * Math.PI) / 180;\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n //Pointer movement in the unrotated frame of the widget\n const local_x = delta_x * cos + delta_y * sin;\n const local_y = delta_y * cos - delta_x * sin;\n const width = action.x\n ? Math.max(MIN_SIZE, snap(drag.width + action.x * local_x, grid))\n : drag.width;\n const height = action.y\n ? Math.max(MIN_SIZE, snap(drag.height + action.y * local_y, grid))\n : drag.height;\n //Move the center by half the size change, so the opposite corner or side stays in place\n const shift_x = (action.x * (width - drag.width)) / 2;\n const shift_y = (action.y * (height - drag.height)) / 2;\n const center_x = drag.x + drag.width / 2 + shift_x * cos - shift_y * sin;\n const center_y = drag.y + drag.height / 2 + shift_x * sin + shift_y * cos;\n widget.x = center_x - width / 2;\n widget.y = center_y - height / 2;\n widget.width = width;\n widget.height = height;\n break;\n }\n case \"rotate\": {\n const start = Math.atan2(\n drag.client_y - drag.center_y,\n drag.client_x - drag.center_x,\n );\n const now = Math.atan2(\n e.clientY - drag.center_y,\n e.clientX - drag.center_x,\n );\n const rotation = snap(\n drag.rotation + ((now - start) * 180) / Math.PI,\n e.shiftKey ? 0 : e.altKey ? SNAP_ANGLE_FINE : SNAP_ANGLE,\n );\n widget.rotation = ((rotation % 360) + 360) % 360;\n break;\n }\n }\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n if (e.pointerId === this.#drag?.pointer_id) this.#stop_drag();\n };\n}\ndefine_element(Transformer);\n","import { Base, define_element } from \"#base\";\nimport type { Page } from \"./page\";\nimport \"./shared\";\nimport { Transformer } from \"./transformer\";\nimport \"./viewport.scss\";\nimport type { WidgetBase } from \"./widget\";\n\nconst ZOOM_MIN = 0.1;\nconst ZOOM_MAX = 20;\n/**Zoom factor per wheel pixel */\nconst WHEEL_ZOOM_SPEED = 0.002;\n/**Zoom factor per wheel pixel for touchpad pinch, which reports much smaller deltas than a mouse wheel */\nconst PINCH_ZOOM_SPEED = 0.01;\n/**Screen pixels panned per wheel pixel */\nconst WHEEL_PAN_SPEED = 0.5;\n/**Pixels per line, for wheel events reported in lines */\nconst WHEEL_LINE_HEIGHT = 16;\n/**Speed multiplier for wheel zoom and pan while alt is held */\nconst WHEEL_SLOW = 0.1;\n\n/**Viewport showing a page of widgets\n * The page is scaled to fit inside the viewport element while keeping its aspect ratio, and centered\n *\n * When edit is true the page can be zoomed and panned, and a checkerboard is shown behind it\n * Wheel and touchpad two finger swipe pans, ctrl + wheel or swipe zooms toward the cursor\n * Shift + vertical wheel pans horizontally\n * Touchpad pinch zooms toward the cursor\n * Holding alt makes wheel zoom and pan 10 times slower\n * Two finger touch pinch zooms and pans, middle or right mouse drag pans\n *\n * Pressing a widget in edit mode selects it and attaches a transformer to move, resize and rotate it\n * Pressing outside any widget clears the selection*/\nexport class Viewport extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"viewport\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #background: HTMLDivElement = this.appendChild(\n document.createElement(\"div\"),\n );\n #container: HTMLDivElement = this.appendChild(document.createElement(\"div\"));\n #transformer: Transformer = this.appendChild(new Transformer());\n #page: Page | undefined;\n #page_observer = new ResizeObserver(() => {\n this.#update_view();\n });\n #scale: number = 1;\n #fit_x: number = 0;\n #fit_y: number = 0;\n #edit: boolean = false;\n #zoom: number = 1;\n #pan_x: number = 0;\n #pan_y: number = 0;\n #touches = new Map<number, { x: number; y: number }>();\n #pan_pointer_id: number | undefined;\n #pan_pointer_last = { x: 0, y: 0 };\n /**Whether the ctrl key is physically held, to tell touchpad pinch from ctrl + wheel */\n #ctrl_held: boolean = false;\n\n constructor() {\n super();\n this.#background.className = \"checkerboard\";\n this.#container.className = \"container\";\n this.attach_to_resize_observer();\n }\n\n /**Sets the page shown in the viewport */\n set page(page: Page | undefined) {\n if (this.#page === page) return;\n this.selected = undefined;\n if (this.#page) {\n this.#page_observer.unobserve(this.#page);\n if (this.#page.parentElement === this.#container) this.#page.remove();\n }\n this.#page = page;\n if (page) {\n this.#container.appendChild(page);\n this.#page_observer.observe(page);\n }\n this.#update_view();\n }\n /**Returns the page shown in the viewport */\n get page(): Page | undefined {\n return this.#page;\n }\n\n /**Sets edit mode, which enables zooming and panning and shows a checkerboard background\n * Leaving edit mode resets the view to fit the page */\n set edit(edit: boolean) {\n if (this.#edit === edit) return;\n this.#edit = edit;\n this.toggleAttribute(\"edit\", edit);\n this.#listen_keys(edit && this.isConnected);\n if (edit) {\n this.addEventListener(\"wheel\", this.#on_wheel, { passive: false });\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n this.addEventListener(\"pointermove\", this.#on_pointer_move);\n this.addEventListener(\"pointerup\", this.#on_pointer_up);\n this.addEventListener(\"pointercancel\", this.#on_pointer_up);\n this.addEventListener(\"mousedown\", this.#on_mouse_down);\n this.addEventListener(\"contextmenu\", this.#on_context_menu);\n } else {\n this.removeEventListener(\"wheel\", this.#on_wheel);\n this.removeEventListener(\"pointerdown\", this.#on_pointer_down);\n this.removeEventListener(\"pointermove\", this.#on_pointer_move);\n this.removeEventListener(\"pointerup\", this.#on_pointer_up);\n this.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n this.removeEventListener(\"mousedown\", this.#on_mouse_down);\n this.removeEventListener(\"contextmenu\", this.#on_context_menu);\n this.#touches.clear();\n this.#pan_pointer_id = undefined;\n this.selected = undefined;\n this.#zoom = 1;\n this.#pan_x = 0;\n this.#pan_y = 0;\n this.#update_view();\n }\n }\n /**Returns whether edit mode is enabled */\n get edit(): boolean {\n return this.#edit;\n }\n\n /**Sets the selected widget, which the transformer is attached to, selection is cleared when leaving edit mode */\n set selected(widget: WidgetBase | undefined) {\n this.#transformer.widget = widget;\n }\n /**Returns the selected widget */\n get selected(): WidgetBase | undefined {\n return this.#transformer.widget;\n }\n\n /**Returns the current scale from page units to screen pixels */\n get scale(): number {\n return this.#scale;\n }\n\n protected on_resize(): void {\n this.#update_view();\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n if (this.#edit) this.#listen_keys(true);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#listen_keys(false);\n }\n\n /**Adds or removes the window listeners tracking the ctrl key */\n #listen_keys(listen: boolean) {\n if (listen) {\n window.addEventListener(\"keydown\", this.#on_key);\n window.addEventListener(\"keyup\", this.#on_key);\n window.addEventListener(\"blur\", this.#on_blur);\n } else {\n window.removeEventListener(\"keydown\", this.#on_key);\n window.removeEventListener(\"keyup\", this.#on_key);\n window.removeEventListener(\"blur\", this.#on_blur);\n this.#ctrl_held = false;\n }\n }\n\n #update_view() {\n if (!this.#page) return;\n const width = this.#page.width;\n const height = this.#page.height;\n if (width <= 0 || height <= 0) return;\n const rect = this.actual_size;\n const fit = Math.min(rect.width / width, rect.height / height);\n this.#fit_x = (rect.width - width * fit) / 2;\n this.#fit_y = (rect.height - height * fit) / 2;\n this.#scale = fit * this.#zoom;\n this.#container.style.transform = `translate(${this.#fit_x + this.#pan_x}px, ${this.#fit_y + this.#pan_y}px) scale(${this.#scale})`;\n this.#transformer.view(\n this.#fit_x + this.#pan_x,\n this.#fit_y + this.#pan_y,\n this.#scale,\n );\n }\n\n /**Zooms by the factor, keeping the given point in viewport coordinates in place */\n #zoom_at(x: number, y: number, factor: number) {\n const zoom = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, this.#zoom * factor));\n const ratio = zoom / this.#zoom;\n this.#pan_x += (x - this.#fit_x - this.#pan_x) * (1 - ratio);\n this.#pan_y += (y - this.#fit_y - this.#pan_y) * (1 - ratio);\n this.#zoom = zoom;\n }\n\n /**Returns the position of the event in viewport coordinates */\n #local(e: MouseEvent): { x: number; y: number } {\n const rect = this.getBoundingClientRect();\n return { x: e.clientX - rect.left, y: e.clientY - rect.top };\n }\n\n /**Selects the widget under the pointer, or clears the selection if there is none */\n #select_at(e: PointerEvent) {\n const page = this.#page;\n let element = e.target instanceof Element ? e.target : null;\n while (element && element.parentElement !== page)\n element = element.parentElement;\n this.selected = page?.widgets.find((widget) => widget === element);\n }\n\n /**Returns center and distance of the first two touches */\n #pinch(): { x: number; y: number; distance: number } | undefined {\n if (this.#touches.size < 2) return undefined;\n const [a, b] = this.#touches.values();\n return {\n x: (a.x + b.x) / 2,\n y: (a.y + b.y) / 2,\n distance: Math.hypot(a.x - b.x, a.y - b.y),\n };\n }\n\n #on_wheel = (e: WheelEvent) => {\n e.preventDefault();\n const unit =\n e.deltaMode === WheelEvent.DOM_DELTA_LINE\n ? WHEEL_LINE_HEIGHT\n : e.deltaMode === WheelEvent.DOM_DELTA_PAGE\n ? this.actual_size.height\n : 1;\n const delta_x = e.deltaX * unit;\n const delta_y = e.deltaY * unit;\n const speed = e.altKey ? WHEEL_SLOW : 1;\n if (e.ctrlKey) {\n //Browsers report touchpad pinch as ctrl + wheel, without the ctrl key being held\n const zoom_speed = this.#ctrl_held ? WHEEL_ZOOM_SPEED : PINCH_ZOOM_SPEED;\n const point = this.#local(e);\n this.#zoom_at(point.x, point.y, Math.exp(-delta_y * zoom_speed * speed));\n } else {\n //Shift makes the vertical wheel pan horizontally, some browsers already swap the deltas themselves\n const swap = e.shiftKey && delta_x === 0;\n this.#pan_x -= (swap ? delta_y : delta_x) * speed * WHEEL_PAN_SPEED;\n this.#pan_y -= (swap ? 0 : delta_y) * speed * WHEEL_PAN_SPEED;\n }\n this.#update_view();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n if (e.pointerType === \"touch\") {\n //Only the first touch selects, so a second finger can pinch without changing the selection\n if (this.#touches.size === 0 && !this.#transformer.dragging)\n this.#select_at(e);\n this.#touches.set(e.pointerId, this.#local(e));\n this.setPointerCapture(e.pointerId);\n } else if (e.button === 0) {\n this.#select_at(e);\n } else if (e.button === 1 || e.button === 2) {\n e.preventDefault();\n this.#pan_pointer_id = e.pointerId;\n this.#pan_pointer_last = this.#local(e);\n this.setPointerCapture(e.pointerId);\n }\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n this.#ctrl_held = e.ctrlKey;\n if (this.#touches.has(e.pointerId)) {\n const before = this.#pinch();\n this.#touches.set(e.pointerId, this.#local(e));\n const after = this.#pinch();\n if (!before || !after || before.distance <= 0) return;\n this.#pan_x += after.x - before.x;\n this.#pan_y += after.y - before.y;\n this.#zoom_at(after.x, after.y, after.distance / before.distance);\n this.#update_view();\n } else if (e.pointerId === this.#pan_pointer_id) {\n const point = this.#local(e);\n this.#pan_x += point.x - this.#pan_pointer_last.x;\n this.#pan_y += point.y - this.#pan_pointer_last.y;\n this.#pan_pointer_last = point;\n this.#update_view();\n }\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n this.#touches.delete(e.pointerId);\n if (e.pointerId === this.#pan_pointer_id) this.#pan_pointer_id = undefined;\n };\n\n /**Prevents the browser autoscroll on middle mouse button */\n #on_mouse_down = (e: MouseEvent) => {\n if (e.button === 1) e.preventDefault();\n };\n\n /**Prevents the context menu, as the right mouse button pans in edit mode */\n #on_context_menu = (e: MouseEvent) => {\n e.preventDefault();\n };\n\n #on_key = (e: KeyboardEvent) => {\n this.#ctrl_held = e.ctrlKey;\n };\n\n #on_blur = () => {\n this.#ctrl_held = false;\n };\n}\ndefine_element(Viewport);\n\nexport interface CanvasViewportOptions {\n /**Page shown in the viewport */\n page?: Page;\n /**Enables zooming, panning and selecting widgets */\n edit?: boolean;\n}\n\n/**Creates a viewport showing a page of widgets */\nexport const canvas_viewport = (options?: CanvasViewportOptions): Viewport =>\n options ? new Viewport().opts(options) : new Viewport();\n","import { canvas_page, Page, type CanvasPageOptions } from \"./page\";\nimport {\n canvas_viewport,\n Viewport,\n type CanvasViewportOptions,\n} from \"./viewport\";\nimport { WIDGET_TRANSFORM_EVENT } from \"./widget\";\n\n/**Displaying and editing graphics with a fixed position and size */\nexport const canvas = {\n page: canvas_page,\n viewport: canvas_viewport,\n WIDGET_TRANSFORM_EVENT,\n};\nexport default canvas;\n\nexport type { CanvasPageOptions, CanvasViewportOptions, Page, Viewport };\n\nexport { WIDGET_TRANSFORM_EVENT, WidgetBase } from \"./widget\";\n"],"mappings":";;;;;;AAGA,MAAM,aAAa,yBACjB,UACA,UACA,gDACF;AAQA,MAAM,SAAS,WAAW,eACxB,UACA,UACA,0BACF;AACA,OAAO,cACL,cACA,oBACA,yCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,OAAO,cACL,kBACA,yBACA,wCACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AAQA,MAAM,OAAO,WAAW,eACtB,QACA,QACA,qCACF;AACA,KAAK,cACH,YACA,4BACA,sEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,YACA,6BACA,uEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,eACA,4BACA,6EACA,YACA,YACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAQA,MAAM,cAAc,WAAW,eAC7B,eACA,eACA,mFACF;AACA,YAAY,cACV,SACA,qBACA,uDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,oBACA,2BACA,+CACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;;;;ACnGA,IAAa,OAAb,cAA0B,KAAK;;CAE7B,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CAC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,KAAA;CACnE;;CAGA,kBAAkB,MAAkB;EAClC,IAAI,EAAE,WAAW,GAAG,EAAE,eAAe;CACvC;;CAGA,oBAAoB,MAAkB;EACpC,EAAE,eAAe;CACnB;CAEA,WAAW,MAAqB;EAC9B,KAAK,aAAa,EAAE;CACtB;CAEA,iBAAiB;EACf,KAAK,aAAa;CACpB;AACF;AACA,eAAe,QAAQ;;AAUvB,MAAa,mBAAmB,YAC9B,UAAU,IAAI,SAAS,CAAC,CAAC,KAAK,OAAO,IAAI,IAAI,SAAS;;;ACtTxD,MAAa,SAAS;CACpB,MAAM;CACN,UAAU;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/canvas/shared.ts","../../src/canvas/page.ts","../../src/canvas/widget.ts","../../src/canvas/transformer.ts","../../src/canvas/viewport.ts","../../src/canvas/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst theme_root = theme_init_variable_root(\n \"canvas\",\n \"Canvas\",\n \"Theme variables for canvas viewports and pages\",\n);\n\n// _____ ____ _ ____ _____ _____\n// / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | | | | | | | | | |__) | (___\n// | | | | | | | | | | | _ / \\___ \\\n// | |___| |__| | |___| |__| | | \\ \\ ____) |\n// \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors = theme_root.make_sub_group(\n \"colors\",\n \"Colors\",\n \"Colors used in viewports\",\n);\ncolors.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of the viewport around the page\",\n GREY[\"300\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"pageBackground\",\n \"Page Background Color\",\n \"Color of the page behind the widgets\",\n GREY[\"50\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n\n// ______ _____ _____ _______\n// | ____| __ \\_ _|__ __|\n// | |__ | | | || | | |\n// | __| | | | || | | |\n// | |____| |__| || |_ | |\n// |______|_____/_____| |_|\nconst edit = theme_root.make_sub_group(\n \"edit\",\n \"Edit\",\n \"Settings for viewports in edit mode\",\n);\nedit.make_variable(\n \"checker1\",\n \"Checkerboard First Color\",\n \"First color of the checkerboard shown behind the page in edit mode\",\n GREY[\"300\"],\n GREY[\"600\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checker2\",\n \"Checkerboard Second Color\",\n \"Second color of the checkerboard shown behind the page in edit mode\",\n GREY[\"200\"],\n GREY[\"700\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checkerSize\",\n \"Checkerboard Square Size\",\n \"Size of one square of the checkerboard shown behind the page in edit mode\",\n \"0.625rem\",\n \"0.625rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\n// _______ _____ _ _ _____ ______ ____ _____ __ __ ______ _____\n// |__ __| __ \\ /\\ | \\ | |/ ____| ____/ __ \\| __ \\| \\/ | ____| __ \\\n// | | | |__) | / \\ | \\| | (___ | |__ | | | | |__) | \\ / | |__ | |__) |\n// | | | _ / / /\\ \\ | . ` |\\___ \\| __|| | | | _ /| |\\/| | __| | _ /\n// | | | | \\ \\ / ____ \\| |\\ |____) | | | |__| | | \\ \\| | | | |____| | \\ \\\n// |_| |_| \\_\\/_/ \\_\\_| \\_|_____/|_| \\____/|_| \\_\\_| |_|______|_| \\_\\\nconst transformer = theme_root.make_sub_group(\n \"transformer\",\n \"Transformer\",\n \"Settings for the transformer used to move, resize and rotate widgets in edit mode\",\n);\ntransformer.make_variable(\n \"color\",\n \"Transformer Color\",\n \"Color of the transformer outline and handle borders\",\n BLUE[\"600\"],\n BLUE[\"300\"],\n \"Color\",\n undefined,\n);\ntransformer.make_variable(\n \"handleBackground\",\n \"Handle Background Color\",\n \"Background color of the transformer handles\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\n","import { Base, define_element } from \"#base\";\nimport \"./page.scss\";\nimport \"./shared\";\nimport type { WidgetBase } from \"./widget\";\n\n/**Page of widgets with a fixed size\n * Width and height are the size of the page in page units (px before any viewport scaling)*/\nexport class Page extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"page\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #width: number = 1920;\n #height: number = 1080;\n #widgets: readonly WidgetBase[] = [];\n\n constructor() {\n super();\n this.style.width = this.#width + \"px\";\n this.style.height = this.#height + \"px\";\n }\n\n /**Sets the width of the page */\n set width(width: number) {\n this.#width = width;\n this.style.width = width + \"px\";\n }\n /**Returns the width of the page */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the page */\n set height(height: number) {\n this.#height = height;\n this.style.height = height + \"px\";\n }\n /**Returns the height of the page */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the widgets on the page, the array order is the drawing order with the last widget on top\n * Widgets already on the page are kept in place, so they are only reconnected if their order changes */\n set widgets(widgets: readonly WidgetBase[]) {\n const keep = new Set(widgets);\n for (const widget of this.#widgets)\n if (!keep.has(widget) && widget.parentElement === this) widget.remove();\n for (let i = 0; i < widgets.length; i++) {\n const current = this.children[i];\n if (current !== widgets[i])\n this.insertBefore(widgets[i], current ?? null);\n }\n this.#widgets = widgets;\n }\n /**Returns the widgets on the page */\n get widgets(): readonly WidgetBase[] {\n return this.#widgets;\n }\n}\ndefine_element(Page);\n\nexport interface CanvasPageOptions {\n /**Width of the page in page units, defaults to 1920 */\n width?: number;\n /**Height of the page in page units, defaults to 1080 */\n height?: number;\n /**Widgets on the page, the last widget is drawn on top */\n widgets?: readonly WidgetBase[];\n}\n\n/**Creates a page of widgets with a fixed size */\nexport const canvas_page = (options?: CanvasPageOptions): Page =>\n options ? new Page().opts(options) : new Page();\n","import { Base } from \"#base\";\n\n/**Event dispatched on a widget when its position, size or rotation changes */\nexport const WIDGET_TRANSFORM_EVENT = \"widget_transform\";\n\n/**Shared class for widgets placed at a fixed position in a viewport\n * Position and size are in viewport units (px before any viewport scaling)\n * Rotation is in degrees clockwise around the center of the widget\n *\n * Width and height must always be set, they default to 0\n *\n * Widgets declare their original size, which is the size their content is laid out at\n * The content is then scaled from the original size to the width and height of the widget\n * Widgets that should not stretch, like text, return width and height as their original size\n *\n * WIDGET_TRANSFORM_EVENT is dispatched whenever position, size or rotation changes*/\nexport abstract class WidgetBase 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 \"canvas\";\n }\n\n #x: number = 0;\n #y: number = 0;\n #width: number = 0;\n #height: number = 0;\n #rotation: number = 0;\n\n constructor() {\n super();\n this.style.position = \"absolute\";\n this.style.boxSizing = \"border-box\";\n this.style.transformOrigin = \"0 0\";\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n this.#update();\n }\n\n /**Returns the width the content of the widget is laid out at, return this.width to not stretch */\n abstract get original_width(): number;\n /**Returns the height the content of the widget is laid out at, return this.height to not stretch */\n abstract get original_height(): number;\n\n /**Sets the x position of the left edge of the widget */\n set x(x: number) {\n this.#x = x;\n this.#update();\n }\n /**Returns the x position of the left edge of the widget */\n get x(): number {\n return this.#x;\n }\n\n /**Sets the y position of the top edge of the widget */\n set y(y: number) {\n this.#y = y;\n this.#update();\n }\n /**Returns the y position of the top edge of the widget */\n get y(): number {\n return this.#y;\n }\n\n /**Sets the width of the widget */\n set width(width: number) {\n this.#width = width;\n this.#update();\n }\n /**Returns the width of the widget */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the widget */\n set height(height: number) {\n this.#height = height;\n this.#update();\n }\n /**Returns the height of the widget */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the rotation of the widget in degrees, rotating clockwise around the center of the widget */\n set rotation(rotation: number) {\n this.#rotation = rotation;\n this.#update();\n }\n /**Returns the rotation of the widget in degrees */\n get rotation(): number {\n return this.#rotation;\n }\n\n #update() {\n const width = this.#width;\n const height = this.#height;\n const layout_width = this.original_width;\n const layout_height = this.original_height;\n const scale_x = layout_width > 0 ? width / layout_width : 1;\n const scale_y = layout_height > 0 ? height / layout_height : 1;\n this.style.left = this.#x + \"px\";\n this.style.top = this.#y + \"px\";\n this.style.width = layout_width + \"px\";\n this.style.height = layout_height + \"px\";\n //Scale the layout box to the widget size, then rotate around the center of the widget size\n this.style.transform = `translate(${width / 2}px, ${height / 2}px) rotate(${this.#rotation}deg) translate(${-width / 2}px, ${-height / 2}px) scale(${scale_x}, ${scale_y})`;\n this.dispatchEvent(new Event(WIDGET_TRANSFORM_EVENT));\n }\n}\n","import { Base, define_element } from \"#base\";\nimport {\n material_arrow_range_rounded,\n material_open_with_rounded,\n material_rotate_right_rounded,\n} from \"#icons\";\nimport type { SVGFunc } from \"#svg\";\nimport \"./shared\";\nimport \"./transformer.scss\";\nimport { WIDGET_TRANSFORM_EVENT, type WidgetBase } from \"./widget\";\n\n/**Smallest width and height a widget can be resized to */\nconst MIN_SIZE = 1;\n/**Grid positions and sizes snap to, and the finer grid used while alt is held */\nconst SNAP_GRID = 5;\nconst SNAP_GRID_FINE = 1;\n/**Angle in degrees rotation snaps to, and the finer angle used while alt is held */\nconst SNAP_ANGLE = 15;\nconst SNAP_ANGLE_FINE = 5;\n\n/**Rounds the value to the nearest multiple of step, a step of 0 returns the value unchanged */\nfunction snap(value: number, step: number): number {\n if (step <= 0) return value;\n return Math.round(value / step) * step;\n}\n\n/**Resize handles, x and y is the edge they move, -1 is the left or top edge, 1 the right or bottom edge, 0 none */\nconst RESIZE_HANDLES = [\n { name: \"nw\", x: -1, y: -1 },\n { name: \"n\", x: 0, y: -1 },\n { name: \"ne\", x: 1, y: -1 },\n { name: \"e\", x: 1, y: 0 },\n { name: \"se\", x: 1, y: 1 },\n { name: \"s\", x: 0, y: 1 },\n { name: \"sw\", x: -1, y: 1 },\n { name: \"w\", x: -1, y: 0 },\n];\n\ntype Action =\n | { type: \"move\" }\n | { type: \"resize\"; x: number; y: number }\n | { type: \"rotate\" };\n\n/**State of the widget and pointer when a drag started */\ninterface Drag {\n action: Action;\n pointer_id: number;\n /**Client position of the origin of the view, which is what offset is relative to */\n origin_x: number;\n origin_y: number;\n /**Point on the page that was pressed */\n page_x: number;\n page_y: number;\n /**Angle from the center of the widget to the point that was pressed, used for rotation */\n angle: number;\n /**Latest pointer event of the drag, undefined until the pointer has moved */\n last: PointerEvent | undefined;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n}\n\n/**Dashed outline with handles, attached to a widget to move, resize and rotate it\n * Corner handles resize both axes and side handles one axis, keeping the opposite corner or side in place\n * The handle above the outline rotates the widget around its center\n * The center handle and the outline itself move the widget, the inside of the outline is left to the widgets below\n *\n * Position and size snap to a 5px grid and rotation to 15 degrees\n * Holding alt snaps to a 1px grid and 5 degrees instead, holding shift disables snapping\n *\n * Resize and rotate cursors follow the rotation of the widget in 45 degree steps\n *\n * The transformer is drawn in viewport pixels, so it keeps its size when the page is zoomed*/\nexport class Transformer extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"transformer\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #widget: WidgetBase | undefined;\n #offset_x: number = 0;\n #offset_y: number = 0;\n #scale: number = 1;\n #actions = new Map<Element, Action>();\n #drag: Drag | undefined;\n\n constructor() {\n super();\n this.hidden = true;\n for (const side of [\"top\", \"right\", \"bottom\", \"left\"])\n this.#add(\"side \" + side, { type: \"move\" });\n this.#add(\"line\", undefined);\n for (const handle of RESIZE_HANDLES)\n this.#add(\n \"handle \" + handle.name,\n { type: \"resize\", x: handle.x, y: handle.y },\n material_arrow_range_rounded,\n );\n this.#add(\n \"handle rotate\",\n { type: \"rotate\" },\n material_rotate_right_rounded,\n );\n //Added last so it is drawn on top of the other handles on small widgets\n this.#add(\"handle move\", { type: \"move\" }, material_open_with_rounded);\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#stop_drag();\n }\n\n /**Sets the widget the transformer is attached to, undefined hides the transformer */\n set widget(widget: WidgetBase | undefined) {\n if (this.#widget === widget) return;\n this.#stop_drag();\n this.#widget?.removeEventListener(\n WIDGET_TRANSFORM_EVENT,\n this.#on_widget_transform,\n );\n this.#widget = widget;\n widget?.addEventListener(WIDGET_TRANSFORM_EVENT, this.#on_widget_transform);\n this.#update();\n }\n /**Returns the widget the transformer is attached to */\n get widget(): WidgetBase | undefined {\n return this.#widget;\n }\n\n /**Returns whether a handle is being dragged */\n get dragging(): boolean {\n return this.#drag !== undefined;\n }\n\n /**Sets how page units map to viewport pixels, viewport = offset + page * scale\n * During a drag the widget is moved so the grabbed point stays under the pointer */\n view(offset_x: number, offset_y: number, scale: number) {\n this.#offset_x = offset_x;\n this.#offset_y = offset_y;\n this.#scale = scale;\n this.#update();\n if (this.#drag?.last) this.#apply_drag(this.#drag, this.#drag.last);\n }\n\n #add(class_name: string, action: Action | undefined, icon?: SVGFunc) {\n const element = this.appendChild(document.createElement(\"div\"));\n element.className = class_name;\n if (icon) element.appendChild(icon());\n if (action) this.#actions.set(element, action);\n }\n\n #update() {\n const widget = this.#widget;\n this.hidden = !widget;\n if (!widget) return;\n const scale = this.#scale;\n this.style.left = this.#offset_x + widget.x * scale + \"px\";\n this.style.top = this.#offset_y + widget.y * scale + \"px\";\n this.style.width = widget.width * scale + \"px\";\n this.style.height = widget.height * scale + \"px\";\n this.style.transform = `rotate(${widget.rotation}deg)`;\n //Cursors only exist in 45 degree steps repeating every 180 degrees, the stylesheet picks the cursors from the closest step\n const half_turn = ((widget.rotation % 180) + 180) % 180;\n this.setAttribute(\"cursor-step\", String(Math.round(half_turn / 45) % 4));\n }\n\n #start(action: Action, e: PointerEvent) {\n const widget = this.#widget;\n if (!widget || this.#drag) return;\n e.preventDefault();\n e.stopPropagation();\n //The bounding box of the rotated outline is centered on the widget center\n const rect = this.getBoundingClientRect();\n const center_x = rect.left + rect.width / 2;\n const center_y = rect.top + rect.height / 2;\n const scale = this.#scale;\n const origin_x =\n center_x - this.#offset_x - (widget.x + widget.width / 2) * scale;\n const origin_y =\n center_y - this.#offset_y - (widget.y + widget.height / 2) * scale;\n this.#drag = {\n action,\n pointer_id: e.pointerId,\n origin_x,\n origin_y,\n page_x: (e.clientX - origin_x - this.#offset_x) / scale,\n page_y: (e.clientY - origin_y - this.#offset_y) / scale,\n angle: Math.atan2(e.clientY - center_y, e.clientX - center_x),\n last: undefined,\n x: widget.x,\n y: widget.y,\n width: widget.width,\n height: widget.height,\n rotation: widget.rotation,\n };\n window.addEventListener(\"pointermove\", this.#on_pointer_move);\n window.addEventListener(\"pointerup\", this.#on_pointer_up);\n window.addEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #stop_drag() {\n if (!this.#drag) return;\n this.#drag = undefined;\n window.removeEventListener(\"pointermove\", this.#on_pointer_move);\n window.removeEventListener(\"pointerup\", this.#on_pointer_up);\n window.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #on_widget_transform = () => {\n this.#update();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n const action =\n e.target instanceof Element ? this.#actions.get(e.target) : undefined;\n //Other buttons are left to the viewport, so middle mouse still pans\n if (!action || e.button !== 0) return;\n this.#start(action, e);\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n const drag = this.#drag;\n if (!drag || e.pointerId !== drag.pointer_id) return;\n drag.last = e;\n this.#apply_drag(drag, e);\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n if (e.pointerId === this.#drag?.pointer_id) this.#stop_drag();\n };\n\n /**Updates the widget from the pointer event and the current view */\n #apply_drag(drag: Drag, e: PointerEvent) {\n const widget = this.#widget;\n const scale = this.#scale;\n //A viewport without a size has a scale of 0, which has no page position\n if (!widget || scale <= 0) return;\n const view_x = drag.origin_x + this.#offset_x;\n const view_y = drag.origin_y + this.#offset_y;\n //Pointer movement in page units\n const delta_x = (e.clientX - view_x) / scale - drag.page_x;\n const delta_y = (e.clientY - view_y) / scale - drag.page_y;\n const grid = e.shiftKey ? 0 : e.altKey ? SNAP_GRID_FINE : SNAP_GRID;\n const action = drag.action;\n switch (action.type) {\n case \"move\":\n widget.x = snap(drag.x + delta_x, grid);\n widget.y = snap(drag.y + delta_y, grid);\n break;\n case \"resize\": {\n const radians = (drag.rotation * Math.PI) / 180;\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n //Pointer movement in the unrotated frame of the widget\n const local_x = delta_x * cos + delta_y * sin;\n const local_y = delta_y * cos - delta_x * sin;\n const width = action.x\n ? Math.max(MIN_SIZE, snap(drag.width + action.x * local_x, grid))\n : drag.width;\n const height = action.y\n ? Math.max(MIN_SIZE, snap(drag.height + action.y * local_y, grid))\n : drag.height;\n //Move the center by half the size change, so the opposite corner or side stays in place\n const shift_x = (action.x * (width - drag.width)) / 2;\n const shift_y = (action.y * (height - drag.height)) / 2;\n const center_x =\n drag.x + drag.width / 2 + shift_x * cos - shift_y * sin;\n const center_y =\n drag.y + drag.height / 2 + shift_x * sin + shift_y * cos;\n widget.x = center_x - width / 2;\n widget.y = center_y - height / 2;\n widget.width = width;\n widget.height = height;\n break;\n }\n case \"rotate\": {\n const now = Math.atan2(\n e.clientY - (view_y + (drag.y + drag.height / 2) * scale),\n e.clientX - (view_x + (drag.x + drag.width / 2) * scale),\n );\n const rotation = snap(\n drag.rotation + ((now - drag.angle) * 180) / Math.PI,\n e.shiftKey ? 0 : e.altKey ? SNAP_ANGLE_FINE : SNAP_ANGLE,\n );\n widget.rotation = ((rotation % 360) + 360) % 360;\n break;\n }\n }\n }\n}\ndefine_element(Transformer);\n","import { Base, define_element } from \"#base\";\nimport type { Page } from \"./page\";\nimport \"./shared\";\nimport { Transformer } from \"./transformer\";\nimport \"./viewport.scss\";\nimport type { WidgetBase } from \"./widget\";\n\nconst ZOOM_MIN = 0.1;\nconst ZOOM_MAX = 20;\n/**Zoom factor per wheel pixel */\nconst WHEEL_ZOOM_SPEED = 0.002;\n/**Zoom factor per wheel pixel for touchpad pinch, which reports much smaller deltas than a mouse wheel */\nconst PINCH_ZOOM_SPEED = 0.01;\n/**Screen pixels panned per wheel pixel */\nconst WHEEL_PAN_SPEED = 0.5;\n/**Pixels per line, for wheel events reported in lines */\nconst WHEEL_LINE_HEIGHT = 16;\n/**Speed multiplier for wheel zoom and pan while alt is held */\nconst WHEEL_SLOW = 0.1;\n\n/**Viewport showing a page of widgets\n * The page is scaled to fit inside the viewport element while keeping its aspect ratio, and centered\n *\n * When edit is true the page can be zoomed and panned, and a checkerboard is shown behind it\n * Wheel and touchpad two finger swipe pans, ctrl + wheel or swipe zooms toward the cursor\n * Shift + vertical wheel pans horizontally\n * Touchpad pinch zooms toward the cursor\n * Holding alt makes wheel zoom and pan 10 times slower\n * Two finger touch pinch zooms and pans, middle or right mouse drag pans\n *\n * Pressing a widget in edit mode selects it and attaches a transformer to move, resize and rotate it\n * Pressing outside any widget clears the selection*/\nexport class Viewport extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"viewport\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #background: HTMLDivElement = this.appendChild(\n document.createElement(\"div\"),\n );\n #container: HTMLDivElement = this.appendChild(document.createElement(\"div\"));\n #transformer: Transformer = this.appendChild(new Transformer());\n #page: Page | undefined;\n #page_observer = new ResizeObserver(() => {\n this.#update_view();\n });\n #scale: number = 1;\n #fit_x: number = 0;\n #fit_y: number = 0;\n #edit: boolean = false;\n #zoom: number = 1;\n #pan_x: number = 0;\n #pan_y: number = 0;\n #touches = new Map<number, { x: number; y: number }>();\n #pan_pointer_id: number | undefined;\n #pan_pointer_last = { x: 0, y: 0 };\n /**Whether the ctrl key is physically held, to tell touchpad pinch from ctrl + wheel */\n #ctrl_held: boolean = false;\n\n constructor() {\n super();\n this.#background.className = \"checkerboard\";\n this.#container.className = \"container\";\n this.attach_to_resize_observer();\n }\n\n /**Sets the page shown in the viewport */\n set page(page: Page | undefined) {\n if (this.#page === page) return;\n this.selected = undefined;\n if (this.#page) {\n this.#page_observer.unobserve(this.#page);\n if (this.#page.parentElement === this.#container) this.#page.remove();\n }\n this.#page = page;\n if (page) {\n this.#container.appendChild(page);\n this.#page_observer.observe(page);\n }\n this.#update_view();\n }\n /**Returns the page shown in the viewport */\n get page(): Page | undefined {\n return this.#page;\n }\n\n /**Sets edit mode, which enables zooming and panning and shows a checkerboard background\n * Leaving edit mode resets the view to fit the page */\n set edit(edit: boolean) {\n if (this.#edit === edit) return;\n this.#edit = edit;\n this.toggleAttribute(\"edit\", edit);\n this.#listen_keys(edit && this.isConnected);\n if (edit) {\n this.addEventListener(\"wheel\", this.#on_wheel, { passive: false });\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n this.addEventListener(\"pointermove\", this.#on_pointer_move);\n this.addEventListener(\"pointerup\", this.#on_pointer_up);\n this.addEventListener(\"pointercancel\", this.#on_pointer_up);\n this.addEventListener(\"mousedown\", this.#on_mouse_down);\n this.addEventListener(\"contextmenu\", this.#on_context_menu);\n } else {\n this.removeEventListener(\"wheel\", this.#on_wheel);\n this.removeEventListener(\"pointerdown\", this.#on_pointer_down);\n this.removeEventListener(\"pointermove\", this.#on_pointer_move);\n this.removeEventListener(\"pointerup\", this.#on_pointer_up);\n this.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n this.removeEventListener(\"mousedown\", this.#on_mouse_down);\n this.removeEventListener(\"contextmenu\", this.#on_context_menu);\n this.#touches.clear();\n this.#pan_pointer_id = undefined;\n this.selected = undefined;\n this.#zoom = 1;\n this.#pan_x = 0;\n this.#pan_y = 0;\n this.#update_view();\n }\n }\n /**Returns whether edit mode is enabled */\n get edit(): boolean {\n return this.#edit;\n }\n\n /**Sets the selected widget, which the transformer is attached to, selection is cleared when leaving edit mode */\n set selected(widget: WidgetBase | undefined) {\n this.#transformer.widget = widget;\n }\n /**Returns the selected widget */\n get selected(): WidgetBase | undefined {\n return this.#transformer.widget;\n }\n\n /**Returns the current scale from page units to screen pixels */\n get scale(): number {\n return this.#scale;\n }\n\n protected on_resize(): void {\n this.#update_view();\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n if (this.#edit) this.#listen_keys(true);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#listen_keys(false);\n }\n\n /**Adds or removes the window listeners tracking the ctrl key */\n #listen_keys(listen: boolean) {\n if (listen) {\n window.addEventListener(\"keydown\", this.#on_key);\n window.addEventListener(\"keyup\", this.#on_key);\n window.addEventListener(\"blur\", this.#on_blur);\n } else {\n window.removeEventListener(\"keydown\", this.#on_key);\n window.removeEventListener(\"keyup\", this.#on_key);\n window.removeEventListener(\"blur\", this.#on_blur);\n this.#ctrl_held = false;\n }\n }\n\n #update_view() {\n if (!this.#page) return;\n const width = this.#page.width;\n const height = this.#page.height;\n if (width <= 0 || height <= 0) return;\n const rect = this.actual_size;\n const fit = Math.min(rect.width / width, rect.height / height);\n this.#fit_x = (rect.width - width * fit) / 2;\n this.#fit_y = (rect.height - height * fit) / 2;\n this.#scale = fit * this.#zoom;\n this.#container.style.transform = `translate(${this.#fit_x + this.#pan_x}px, ${this.#fit_y + this.#pan_y}px) scale(${this.#scale})`;\n this.#transformer.view(\n this.#fit_x + this.#pan_x,\n this.#fit_y + this.#pan_y,\n this.#scale,\n );\n }\n\n /**Zooms by the factor, keeping the given point in viewport coordinates in place */\n #zoom_at(x: number, y: number, factor: number) {\n const zoom = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, this.#zoom * factor));\n const ratio = zoom / this.#zoom;\n this.#pan_x += (x - this.#fit_x - this.#pan_x) * (1 - ratio);\n this.#pan_y += (y - this.#fit_y - this.#pan_y) * (1 - ratio);\n this.#zoom = zoom;\n }\n\n /**Returns the position of the event in viewport coordinates */\n #local(e: MouseEvent): { x: number; y: number } {\n const rect = this.getBoundingClientRect();\n return { x: e.clientX - rect.left, y: e.clientY - rect.top };\n }\n\n /**Selects the widget under the pointer, or clears the selection if there is none */\n #select_at(e: PointerEvent) {\n const page = this.#page;\n let element = e.target instanceof Element ? e.target : null;\n while (element && element.parentElement !== page)\n element = element.parentElement;\n this.selected = page?.widgets.find((widget) => widget === element);\n }\n\n /**Returns center and distance of the first two touches */\n #pinch(): { x: number; y: number; distance: number } | undefined {\n if (this.#touches.size < 2) return undefined;\n const [a, b] = this.#touches.values();\n return {\n x: (a.x + b.x) / 2,\n y: (a.y + b.y) / 2,\n distance: Math.hypot(a.x - b.x, a.y - b.y),\n };\n }\n\n #on_wheel = (e: WheelEvent) => {\n e.preventDefault();\n const unit =\n e.deltaMode === WheelEvent.DOM_DELTA_LINE\n ? WHEEL_LINE_HEIGHT\n : e.deltaMode === WheelEvent.DOM_DELTA_PAGE\n ? this.actual_size.height\n : 1;\n const delta_x = e.deltaX * unit;\n const delta_y = e.deltaY * unit;\n const speed = e.altKey ? WHEEL_SLOW : 1;\n if (e.ctrlKey) {\n //Browsers report touchpad pinch as ctrl + wheel, without the ctrl key being held\n const zoom_speed = this.#ctrl_held ? WHEEL_ZOOM_SPEED : PINCH_ZOOM_SPEED;\n const point = this.#local(e);\n this.#zoom_at(point.x, point.y, Math.exp(-delta_y * zoom_speed * speed));\n } else {\n //Shift makes the vertical wheel pan horizontally, some browsers already swap the deltas themselves\n const swap = e.shiftKey && delta_x === 0;\n this.#pan_x -= (swap ? delta_y : delta_x) * speed * WHEEL_PAN_SPEED;\n this.#pan_y -= (swap ? 0 : delta_y) * speed * WHEEL_PAN_SPEED;\n }\n this.#update_view();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n if (e.pointerType === \"touch\") {\n //Only the first touch selects, so a second finger can pinch without changing the selection\n if (this.#touches.size === 0 && !this.#transformer.dragging)\n this.#select_at(e);\n this.#touches.set(e.pointerId, this.#local(e));\n this.setPointerCapture(e.pointerId);\n } else if (e.button === 0) {\n this.#select_at(e);\n } else if (e.button === 1 || e.button === 2) {\n e.preventDefault();\n this.#pan_pointer_id = e.pointerId;\n this.#pan_pointer_last = this.#local(e);\n this.setPointerCapture(e.pointerId);\n }\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n this.#ctrl_held = e.ctrlKey;\n if (this.#touches.has(e.pointerId)) {\n const before = this.#pinch();\n this.#touches.set(e.pointerId, this.#local(e));\n const after = this.#pinch();\n if (!before || !after || before.distance <= 0) return;\n this.#pan_x += after.x - before.x;\n this.#pan_y += after.y - before.y;\n this.#zoom_at(after.x, after.y, after.distance / before.distance);\n this.#update_view();\n } else if (e.pointerId === this.#pan_pointer_id) {\n const point = this.#local(e);\n this.#pan_x += point.x - this.#pan_pointer_last.x;\n this.#pan_y += point.y - this.#pan_pointer_last.y;\n this.#pan_pointer_last = point;\n this.#update_view();\n }\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n this.#touches.delete(e.pointerId);\n if (e.pointerId === this.#pan_pointer_id) this.#pan_pointer_id = undefined;\n };\n\n /**Prevents the browser autoscroll on middle mouse button */\n #on_mouse_down = (e: MouseEvent) => {\n if (e.button === 1) e.preventDefault();\n };\n\n /**Prevents the context menu, as the right mouse button pans in edit mode */\n #on_context_menu = (e: MouseEvent) => {\n e.preventDefault();\n };\n\n #on_key = (e: KeyboardEvent) => {\n this.#ctrl_held = e.ctrlKey;\n };\n\n #on_blur = () => {\n this.#ctrl_held = false;\n };\n}\ndefine_element(Viewport);\n\nexport interface CanvasViewportOptions {\n /**Page shown in the viewport */\n page?: Page;\n /**Enables zooming, panning and selecting widgets */\n edit?: boolean;\n}\n\n/**Creates a viewport showing a page of widgets */\nexport const canvas_viewport = (options?: CanvasViewportOptions): Viewport =>\n options ? new Viewport().opts(options) : new Viewport();\n","import { canvas_page, Page, type CanvasPageOptions } from \"./page\";\nimport {\n canvas_viewport,\n Viewport,\n type CanvasViewportOptions,\n} from \"./viewport\";\nimport { WIDGET_TRANSFORM_EVENT } from \"./widget\";\n\n/**Displaying and editing graphics with a fixed position and size */\nexport const canvas = {\n page: canvas_page,\n viewport: canvas_viewport,\n WIDGET_TRANSFORM_EVENT,\n};\nexport default canvas;\n\nexport type { CanvasPageOptions, CanvasViewportOptions, Page, Viewport };\n\nexport { WIDGET_TRANSFORM_EVENT, WidgetBase } from \"./widget\";\n"],"mappings":";;;;;;AAGA,MAAM,aAAa,yBACjB,UACA,UACA,gDACF;AAQA,MAAM,SAAS,WAAW,eACxB,UACA,UACA,0BACF;AACA,OAAO,cACL,cACA,oBACA,yCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,OAAO,cACL,kBACA,yBACA,wCACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AAQA,MAAM,OAAO,WAAW,eACtB,QACA,QACA,qCACF;AACA,KAAK,cACH,YACA,4BACA,sEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,YACA,6BACA,uEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,eACA,4BACA,6EACA,YACA,YACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAQA,MAAM,cAAc,WAAW,eAC7B,eACA,eACA,mFACF;AACA,YAAY,cACV,SACA,qBACA,uDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,oBACA,2BACA,+CACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;;;;ACnGA,IAAa,OAAb,cAA0B,KAAK;;CAE7B,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;CAEA,SAAiB;CACjB,UAAkB;CAClB,WAAkC,CAAC;CAEnC,cAAc;EACZ,MAAM;EACN,KAAK,MAAM,QAAQ,KAAK,SAAS;EACjC,KAAK,MAAM,SAAS,KAAK,UAAU;CACrC;;CAGA,IAAI,MAAM,OAAe;EACvB,KAAK,SAAS;EACd,KAAK,MAAM,QAAQ,QAAQ;CAC7B;;CAEA,IAAI,QAAgB;EAClB,OAAO,KAAK;CACd;;CAGA,IAAI,OAAO,QAAgB;EACzB,KAAK,UAAU;EACf,KAAK,MAAM,SAAS,SAAS;CAC/B;;CAEA,IAAI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AK,aAAa;EACpB;CACF;CAEA,kBAAkB,MAAoB;EACpC,KAAK,SAAS,OAAO,EAAE,SAAS;EAChC,IAAI,EAAE,cAAc,KAAK,iBAAiB,KAAK,kBAAkB,KAAA;CACnE;;CAGA,kBAAkB,MAAkB;EAClC,IAAI,EAAE,WAAW,GAAG,EAAE,eAAe;CACvC;;CAGA,oBAAoB,MAAkB;EACpC,EAAE,eAAe;CACnB;CAEA,WAAW,MAAqB;EAC9B,KAAK,aAAa,EAAE;CACtB;CAEA,iBAAiB;EACf,KAAK,aAAa;CACpB;AACF;AACA,eAAe,QAAQ;;AAUvB,MAAa,mBAAmB,YAC9B,UAAU,IAAI,SAAS,CAAC,CAAC,KAAK,OAAO,IAAI,IAAI,SAAS;;;ACtTxD,MAAa,SAAS;CACpB,MAAM;CACN,UAAU;CACV;AACF"}
|
package/context-menu/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
|
-
export { t as ctm, t as default } from "../context-menu-
|
|
2
|
+
export { t as ctm, t as default } from "../context-menu-CA4o4fXx.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
2
|
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
-
import { i as theme_init_variable_root } from "./theme-
|
|
3
|
+
import { i as theme_init_variable_root } from "./theme-ChmpRObz.mjs";
|
|
4
4
|
import { DOCUMENT_HANDLER } from "./document/index.mjs";
|
|
5
5
|
import { Fm as material_chevron_right_rounded, xh as material_close_rounded } from "./icons-e2J_Ojic.mjs";
|
|
6
6
|
import { Spinner } from "./spinner/index.mjs";
|
|
@@ -558,4 +558,4 @@ const ctm = {
|
|
|
558
558
|
};
|
|
559
559
|
export { ctm as t };
|
|
560
560
|
|
|
561
|
-
//# sourceMappingURL=context-menu-
|
|
561
|
+
//# sourceMappingURL=context-menu-CA4o4fXx.mjs.map
|