@chocbite/ts-lib-ui 0.0.0-stage → 1.0.1

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.
Files changed (57) hide show
  1. package/README.md +48 -2
  2. package/base/index.d.mts +3 -0
  3. package/base/index.mjs +521 -0
  4. package/base/index.mjs.map +1 -0
  5. package/canvas/index.d.mts +74 -0
  6. package/canvas/index.mjs +619 -0
  7. package/canvas/index.mjs.map +1 -0
  8. package/context-menu/index.d.mts +3 -0
  9. package/context-menu/index.mjs +2 -0
  10. package/context-menu-3OazryD0.mjs +527 -0
  11. package/context-menu-3OazryD0.mjs.map +1 -0
  12. package/document/index.d.mts +27 -0
  13. package/document/index.mjs +50 -0
  14. package/document/index.mjs.map +1 -0
  15. package/dom/index.d.mts +3 -0
  16. package/dom/index.mjs +8 -0
  17. package/dom/index.mjs.map +1 -0
  18. package/form/index.d.mts +747 -0
  19. package/form/index.mjs +2694 -0
  20. package/form/index.mjs.map +1 -0
  21. package/icons/index.d.mts +4109 -0
  22. package/icons/index.mjs +2 -0
  23. package/icons/mixins.scss +12 -0
  24. package/icons-CY4BLQ2F.mjs +4123 -0
  25. package/index-BND79jZp.d.mts +212 -0
  26. package/index-BcidwqIy.d.mts +167 -0
  27. package/index-CB3-qP6l.d.mts +120 -0
  28. package/index-CugtUzv_.d.mts +155 -0
  29. package/keyboard/index.d.mts +85 -0
  30. package/keyboard/index.mjs +1499 -0
  31. package/keyboard/index.mjs.map +1 -0
  32. package/list/index.d.mts +3 -0
  33. package/list/index.mjs +2 -0
  34. package/list-BcNSxtNm.mjs +617 -0
  35. package/list-BcNSxtNm.mjs.map +1 -0
  36. package/package.json +95 -4
  37. package/selection/index.d.mts +16 -0
  38. package/selection/index.mjs +96 -0
  39. package/selection/index.mjs.map +1 -0
  40. package/settings/index.d.mts +43 -0
  41. package/settings/index.mjs +110 -0
  42. package/settings/index.mjs.map +1 -0
  43. package/spinner/index.d.mts +10 -0
  44. package/spinner/index.mjs +39 -0
  45. package/spinner/index.mjs.map +1 -0
  46. package/style.css +2994 -0
  47. package/svg/index.d.mts +3 -0
  48. package/svg/index.mjs +2 -0
  49. package/svg-golJPaR4.mjs +358 -0
  50. package/svg-golJPaR4.mjs.map +1 -0
  51. package/theme/index.d.mts +179 -0
  52. package/theme/index.mjs +2 -0
  53. package/theme/mixins.scss +39 -0
  54. package/theme-DhIVwHQw.mjs +338 -0
  55. package/theme-DhIVwHQw.mjs.map +1 -0
  56. package/viewport/index.d.mts +1 -0
  57. package/viewport/index.mjs +2 -0
@@ -0,0 +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\n * this will also batch updates if they are constantly coming*/\n deffered_visible?: number;\n /**Deffers updating visible state for so many milliseconds\n * this will also batch updates if they are constantly coming*/\n deffered_hidden?: number;\n} & IntersectionObserverInit;\n\nconst V2 = \"delay\" in new IntersectionObserver(() => {});\nexport class BaseIntersectObserver extends IntersectionObserver {\n #deffered_visible_time: number;\n #deffered_visible_timeout: number | null = null;\n #deffered_visible_queue: Base[] = [];\n #deffered_hidden_time: number;\n #deffered_hidden_timeout: number | null = null;\n #deffered_hidden_queue: Base[] = [];\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 for (let i = 0; i < e.length; i++) {\n if (e[i].isIntersecting) {\n this.#deffered_visible_queue.push(e[i].target as Base);\n const index = this.#deffered_hidden_queue.indexOf(\n e[i].target as Base,\n );\n if (index !== -1) this.#deffered_hidden_queue.splice(index, 1);\n } else {\n this.#deffered_hidden_queue.push(e[i].target as Base);\n const index = this.#deffered_visible_queue.indexOf(\n e[i].target as Base,\n );\n if (index !== -1) this.#deffered_visible_queue.splice(index, 1);\n }\n }\n if (!this.#deffered_visible_timeout) {\n this.#deffered_visible_timeout = window.setTimeout(() => {\n for (let i = 0; i < this.#deffered_visible_queue.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n this.#deffered_visible_queue[i].internal_set_visible(true);\n }\n this.#deffered_visible_queue = [];\n this.#deffered_visible_timeout = null;\n }, this.#deffered_visible_time);\n }\n if (!this.#deffered_hidden_timeout) {\n this.#deffered_hidden_timeout = window.setTimeout(() => {\n for (let i = 0; i < this.#deffered_hidden_queue.length; i++) {\n //@ts-expect-error Call of private method, is private to prevent external usage\n this.#deffered_hidden_queue[i].internal_set_visible(false);\n }\n this.#deffered_hidden_queue = [];\n this.#deffered_hidden_timeout = null;\n }, this.#deffered_hidden_time);\n }\n },\n V2 && options.deffered_visible === options.deffered_hidden\n ? ({ delay: options.deffered_visible, ...options } as object)\n : options,\n );\n if (V2 && options.deffered_visible === options.deffered_hidden) {\n this.#deffered_visible_time = 0;\n this.#deffered_hidden_time = 0;\n } else {\n this.#deffered_visible_time = options.deffered_visible ?? 250;\n this.#deffered_hidden_time = options.deffered_hidden ?? 250;\n }\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 * 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 if (this.#attached_int_observer) this.#attached_int_observer.observe(this);\n else this.internal_set_visible(true);\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 }\n\n /**Runs when element is dettached from document*/\n protected disconnectedCallback() {\n for (const [f, [s, v]] of this.#states) if (!v) s.unsub(f);\n if (this.#attached_int_observer) {\n this.#attached_int_observer.unobserve(this);\n this.internal_set_visible(false);\n }\n //@ts-expect-error Change readonly, in same class\n this.is_connected = 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[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 if (this.is_connected) this.#attached_int_observer.unobserve(this);\n if (!this.is_visible) this.internal_set_visible(true);\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) this.detach_state(pro);\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 try {\n // @ts-expect-error Dynamic custom element definition\n customElements.define(define_name, element);\n ELEMENT_LIST.add(define_name);\n } catch (e) {\n if (\n e instanceof Error &&\n e.message.includes(\"has already been used with this registry\")\n ) {\n throw e;\n } else {\n throw new Error(\n 'Failed to define element \"' +\n define_name +\n '\" ' +\n validate_element_name(define_name),\n );\n }\n }\n};\n","import state from \"@chocbite/ts-lib/state\";\nimport { Base } from \"./base\";\nimport { define_element } from \"./define_element\";\n\ninterface LoopOptions<T, N extends Node> {\n change?: (element: N, new_value: T) => void;\n destructor?: (element: N) => void;\n}\n\nexport class Loop<T, N extends Node> 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 const read = state.a.read(array);\n for (let i = 0; i < read.length; i++) {\n const element = read[i];\n if (element.type === \"fresh\")\n this.replaceChildren(...array.map(this.#generator));\n else if (element.type === \"added\") {\n const child_nodes = this.childNodes;\n if (element.index === child_nodes.length)\n this.append(...array.slice(element.index).map(this.#generator));\n else {\n for (let i = element.items.length; i > 0; i--) {\n this.insertBefore(\n this.#generator(element.items[i - 1]),\n child_nodes[element.index],\n );\n }\n }\n } else if (element.type === \"removed\")\n for (let i = 0; i < element.items.length; i++) {\n this.#destructor?.(this.childNodes[element.index] as unknown as N);\n this.childNodes[element.index].remove();\n }\n else if (element.type === \"changed\")\n for (let i = 0; i < element.items.length; i++)\n if (this.#change)\n this.#change(\n this.childNodes[i + element.index] as unknown as N,\n element.items[i],\n );\n else {\n this.#destructor?.(\n this.childNodes[i + element.index] as unknown as N,\n );\n this.childNodes[i + element.index].replaceWith(\n this.#generator(element.items[i]),\n );\n }\n else if (element.type === \"moved\") {\n const extracted_nodes: Node[] = [];\n for (let i = 0; i < element.items.length; i++) {\n const node = this.childNodes[element.from_index + i];\n extracted_nodes.push(node);\n node.remove();\n }\n for (let i = 0; i < element.items.length; i++) {\n const node = extracted_nodes[i];\n if (element.to_index + i === this.childNodes.length)\n this.append(node);\n else this.insertBefore(node, this.childNodes[element.to_index + i]);\n }\n }\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 Node>(\n generator: (val: T) => N,\n options?: LoopOptions<T, N>,\n) {\n return new Loop<T, N>(generator, options);\n}\n\nexport function base_loop_state() {}\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,MAAM,KAAK,WAAW,IAAI,2BAA2B,CAAC,CAAC;AACvD,IAAa,wBAAb,cAA2C,qBAAqB;CAC9D;CACA,4BAA2C;CAC3C,0BAAkC,CAAC;CACnC;CACA,2BAA0C;CAC1C,y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,IACpB,kBAAkB,KAAK,WAA6B,CACtD;EACA,KAAK,OAAO,YAAY,IAAI;CAC9B;AACF"}
@@ -0,0 +1,74 @@
1
+ import '../style.css';
2
+ import { u as Base } from "../index-BND79jZp.mjs";
3
+ import { State } from "@chocbite/ts-lib/state";
4
+ import { Option } from "@chocbite/ts-lib/result";
5
+ export declare abstract class ViewportElement {
6
+ #private;
7
+ protected abstract element_name(): string;
8
+ protected abstract element_name_space(): string;
9
+ /**Default width of element when created */
10
+ abstract default_width(): number;
11
+ /**Default height of element when created */
12
+ abstract default_height(): number;
13
+ /**Element optimal ratio, returns the ratio where the element has no distortion.
14
+ * If the element can dynamically change based on ratio, return none. */
15
+ optimal_ratio(): Option<number>;
16
+ /**Called when the element has no optimal ratio and its dimensions change.
17
+ * Descendants can override this to re-layout their content in the new
18
+ * coordinate space defined by the updated viewBox. */
19
+ protected on_resize(_width: number, _height: number): void;
20
+ readonly canvas: SVGSVGElement;
21
+ constructor();
22
+ set position_x(value: number);
23
+ get position_x(): number;
24
+ set position_y(value: number);
25
+ get position_y(): number;
26
+ set rotation(value: number);
27
+ get rotation(): number;
28
+ /**Rotation center x coordinate, relative to the element's display area.
29
+ * Defaults to half of default_width (center of element). */
30
+ set rotation_center_x(value: number);
31
+ get rotation_center_x(): number;
32
+ /**Rotation center y coordinate, relative to the element's display area.
33
+ * Defaults to half of default_height (center of element). */
34
+ set rotation_center_y(value: number);
35
+ get rotation_center_y(): number;
36
+ /**Display width of the element. Changing this scales the element.
37
+ * - If the element has an optimal_ratio, the viewBox stays at default
38
+ * dimensions and the SVG content is stretched/scaled to fill the new size.
39
+ * - If the element has no optimal_ratio, the viewBox is updated to match
40
+ * the new dimensions and on_resize is called. */
41
+ set width(value: number);
42
+ get width(): number;
43
+ /**Display height of the element. Changing this scales the element.
44
+ * - If the element has an optimal_ratio, the viewBox stays at default
45
+ * dimensions and the SVG content is stretched/scaled to fill the new size.
46
+ * - If the element has no optimal_ratio, the viewBox is updated to match
47
+ * the new dimensions and on_resize is called. */
48
+ set height(value: number);
49
+ get height(): number;
50
+ }
51
+ declare class Viewport extends Base {
52
+ #private;
53
+ static element_name(): string;
54
+ static element_name_space(): string;
55
+ constructor(canvas_width: number, canvas_height: number, infinite_canvas?: boolean);
56
+ set canvas_width(value: number);
57
+ get canvas_width(): number;
58
+ set canvas_height(value: number);
59
+ get canvas_height(): number;
60
+ readonly pan_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
61
+ readonly pan_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
62
+ readonly zoom: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
63
+ readonly grid_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
64
+ readonly grid_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
65
+ readonly grid_rotate: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
66
+ set elements(elements: ViewportElement[] | State<ViewportElement[]>);
67
+ attach_mover(move: ViewportElement): void;
68
+ }
69
+ declare function create_viewport(canvas_width: number, canvas_height: number, infinite_canvas?: boolean): Viewport;
70
+ export declare const viewport: {
71
+ create_viewport: typeof create_viewport;
72
+ };
73
+ export {};
74
+ //# sourceMappingURL=index.d.mts.map