@chocbite/ts-lib-ui 0.0.0-stage → 1.0.0
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/README.md +48 -2
- package/base/index.d.mts +3 -0
- package/base/index.mjs +521 -0
- package/base/index.mjs.map +1 -0
- package/canvas/index.d.mts +74 -0
- package/canvas/index.mjs +619 -0
- package/canvas/index.mjs.map +1 -0
- package/context-menu/index.d.mts +3 -0
- package/context-menu/index.mjs +2 -0
- package/context-menu-BbDVgMiZ.mjs +527 -0
- package/context-menu-BbDVgMiZ.mjs.map +1 -0
- package/document/index.d.mts +27 -0
- package/document/index.mjs +50 -0
- package/document/index.mjs.map +1 -0
- package/dom/index.d.mts +3 -0
- package/dom/index.mjs +8 -0
- package/dom/index.mjs.map +1 -0
- package/form/index.d.mts +747 -0
- package/form/index.mjs +2694 -0
- package/form/index.mjs.map +1 -0
- package/icons/index.d.mts +4109 -0
- package/icons/index.mjs +2 -0
- package/icons/mixins.scss +12 -0
- package/icons-CY4BLQ2F.mjs +4123 -0
- package/index-BvflC2sG.d.mts +212 -0
- package/index-CWQ5KhrP.d.mts +167 -0
- package/index-CdiJN7JF.d.mts +155 -0
- package/index-Cx6QmIC-.d.mts +120 -0
- package/keyboard/index.d.mts +85 -0
- package/keyboard/index.mjs +1499 -0
- package/keyboard/index.mjs.map +1 -0
- package/list/index.d.mts +3 -0
- package/list/index.mjs +2 -0
- package/list-CmrmWLBD.mjs +617 -0
- package/list-CmrmWLBD.mjs.map +1 -0
- package/package.json +95 -4
- package/selection/index.d.mts +16 -0
- package/selection/index.mjs +96 -0
- package/selection/index.mjs.map +1 -0
- package/settings/index.d.mts +43 -0
- package/settings/index.mjs +110 -0
- package/settings/index.mjs.map +1 -0
- package/spinner/index.d.mts +10 -0
- package/spinner/index.mjs +39 -0
- package/spinner/index.mjs.map +1 -0
- package/style.css +2994 -0
- package/svg/index.d.mts +3 -0
- package/svg/index.mjs +2 -0
- package/svg-golJPaR4.mjs +358 -0
- package/svg-golJPaR4.mjs.map +1 -0
- package/theme/index.d.mts +179 -0
- package/theme/index.mjs +2 -0
- package/theme/mixins.scss +39 -0
- package/theme-BtAXQpvm.mjs +338 -0
- package/theme-BtAXQpvm.mjs.map +1 -0
- package/viewport/index.d.mts +1 -0
- package/viewport/index.mjs +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["state"],"sources":["../../src/canvas/viewport_mover.ts","../../src/canvas/viewport.ts","../../src/canvas/viewport_element.ts","../../src/canvas/index.ts"],"sourcesContent":["import { node_clone } from \"#dom\";\nimport { material_autorenew_rounded } from \"#icons\";\nimport type { StateROS } from \"@chocbite/ts-lib/state\";\nimport { svg } from \"#svg\";\nimport { ViewportElement } from \"./viewport_element\";\nimport \"./viewport_mover.scss\";\n\nconst nw = svg.svg(32, 32, \"0 0 32 32\").cl(\"nw\").elem;\nnw.appendChild(svg.create(\"circle\").elem);\nnw.appendChild(svg.line(-8, -8, 8, 8).elem);\nnw.appendChild(svg.isosceles_triangle(-7, -7, 8, 6).rotate(-45, -7, -7).elem);\nnw.appendChild(svg.isosceles_triangle(7, 7, 8, 6).rotate(135, 7, 7).elem);\nconst ne = svg.svg(32, 32, \"0 0 32 32\").cl(\"ne\").elem;\nne.appendChild(svg.create(\"circle\").elem);\nne.appendChild(svg.line(-8, 8, 8, -8).elem);\nne.appendChild(svg.isosceles_triangle(-7, 7, 8, 6).rotate(-135, -7, 7).elem);\nne.appendChild(svg.isosceles_triangle(7, -7, 8, 6).rotate(45, 7, -7).elem);\nconst se = svg.svg(32, 32, \"0 0 32 32\").cl(\"se\").elem;\nse.appendChild(svg.create(\"circle\").elem);\nse.appendChild(svg.line(-8, -8, 8, 8).elem);\nse.appendChild(svg.isosceles_triangle(-7, -7, 8, 6).rotate(-45, -7, -7).elem);\nse.appendChild(svg.isosceles_triangle(7, 7, 8, 6).rotate(135, 7, 7).elem);\nconst sw = svg.svg(32, 32, \"0 0 32 32\").cl(\"sw\").elem;\nsw.appendChild(svg.create(\"circle\").elem);\nsw.appendChild(svg.line(-8, 8, 8, -8).elem);\nsw.appendChild(svg.isosceles_triangle(-7, 7, 8, 6).rotate(-135, -7, 7).elem);\nsw.appendChild(svg.isosceles_triangle(7, -7, 8, 6).rotate(45, 7, -7).elem);\nconst move = svg.svg(32, 32, \"0 0 32 32\").cl(\"move\").elem;\nmove.appendChild(svg.create(\"circle\").elem);\nmove.appendChild(svg.line(0, 8, 0, -8).elem);\nmove.appendChild(svg.isosceles_triangle(0, 10, 8, 6).rotate(180, 0, 10).elem);\nmove.appendChild(svg.isosceles_triangle(0, -10, 8, 6).rotate(0, 0, -10).elem);\nmove.appendChild(svg.line(-10, 0, 10, 0).elem);\nmove.appendChild(svg.isosceles_triangle(-10, 0, 8, 6).rotate(270, -10, 0).elem);\nmove.appendChild(svg.isosceles_triangle(10, 0, 8, 6).rotate(90, 10, 0).elem);\nconst rotate_sym = svg.svg(32, 32, \"0 0 32 32\").a(\"y\", \"-30\").cl(\"rotate\").elem;\nrotate_sym.appendChild(svg.create(\"circle\").elem);\nrotate_sym.appendChild(\n svg.attr(material_autorenew_rounded()).a(\"x\", \"-12\").a(\"y\", \"-12\")\n .elem,\n);\nconst rotation_center_indicator = svg\n .svg(16, 16, \"0 0 16 16\")\n .cl(\"rotation-center\").elem;\nrotation_center_indicator.appendChild(svg.create(\"circle\").elem);\nrotation_center_indicator.appendChild(svg.line(-6, 0, 6, 0).elem);\nrotation_center_indicator.appendChild(svg.line(0, -6, 0, 6).elem);\n\nconst DEG_TO_RAD = Math.PI / 180;\n\nexport class ViewportMover {\n #canvas: SVGSVGElement = svg.create(\"svg\").cl(\"viewport-mover\").elem;\n #outline = this.#canvas.appendChild(\n svg.rectangle_from_corner(-1, -1, 1, 1, 0).elem,\n );\n #nw_corner = this.#canvas.appendChild(node_clone(nw));\n #ne_corner = this.#canvas.appendChild(node_clone(ne));\n #sw_corner = this.#canvas.appendChild(node_clone(sw));\n #se_corner = this.#canvas.appendChild(node_clone(se));\n #move = this.#canvas.appendChild(node_clone(move));\n #rotate = this.#canvas.appendChild(node_clone(rotate_sym));\n #rc_indicator = this.#canvas.appendChild(\n node_clone(rotation_center_indicator),\n );\n #scale_buffer = 1;\n #grid_x_buffer = 1;\n #grid_y_buffer = 1;\n #grid_rotate_buffer = 0;\n\n constructor(\n scale: StateROS<number>,\n grid_x: StateROS<number>,\n grid_y: StateROS<number>,\n grid_rotate: StateROS<number>,\n ) {\n scale.sub((val) => {\n this.#scale_buffer = val.value;\n const s = `scale(${1 / val.value})`;\n this.#nw_corner.setAttribute(\"transform\", s);\n this.#ne_corner.setAttribute(\"transform\", s);\n this.#sw_corner.setAttribute(\"transform\", s);\n this.#se_corner.setAttribute(\"transform\", s);\n this.#move.setAttribute(\"transform\", s);\n this.#rotate.setAttribute(\"transform\", s);\n this.#rc_indicator.setAttribute(\"transform\", s);\n }, true);\n grid_x.sub((val) => {\n this.#grid_x_buffer = val.value;\n }, true);\n grid_y.sub((val) => {\n this.#grid_y_buffer = val.value;\n }, true);\n grid_rotate.sub((val) => {\n this.#grid_rotate_buffer = val.value;\n }, true);\n this.#setup_position();\n this.#setup_corner(this.#nw_corner, -1, -1);\n this.#setup_corner(this.#ne_corner, 1, -1);\n this.#setup_corner(this.#sw_corner, -1, 1);\n this.#setup_corner(this.#se_corner, 1, 1);\n this.#setup_rotation();\n }\n #update_mover_transform() {\n if (this.#rotation === 0) {\n this.#canvas.removeAttribute(\"transform\");\n } else {\n const cx = this.#position_x + this.#rotation_center_x;\n const cy = this.#position_y + this.#rotation_center_y;\n this.#canvas.setAttribute(\n \"transform\",\n `rotate(${this.#rotation} ${cx} ${cy})`,\n );\n }\n }\n\n #element?: ViewportElement;\n attach_to_element(element: ViewportElement, canvas: SVGSVGElement) {\n // Clear the old element reference first so the property setters below\n // don't propagate the new element's values back to the previous element.\n this.#element = undefined;\n this.#canvas.setAttribute(\"x\", element.position_x.toString());\n this.#canvas.setAttribute(\"y\", element.position_y.toString());\n this.width = element.width;\n this.height = element.height;\n this.position_x = element.position_x;\n this.position_y = element.position_y;\n this.#rotation = element.rotation;\n this.#rotation_center_x = element.rotation_center_x;\n this.#rotation_center_y = element.rotation_center_y;\n this.#update_rc_indicator();\n this.#element = element;\n this.#update_mover_transform();\n canvas.appendChild(this.#canvas);\n }\n\n detach_from_element() {\n this.#element = undefined;\n this.#canvas.remove();\n }\n // _____ ____ _____ _____ _______ _____ ____ _ _\n // | __ \\ / __ \\ / ____|_ _|__ __|_ _/ __ \\| \\ | |\n // | |__) | | | | (___ | | | | | || | | | \\| |\n // | ___/| | | |\\___ \\ | | | | | || | | | . ` |\n // | | | |__| |____) |_| |_ | | _| || |__| | |\\ |\n // |_| \\____/|_____/|_____| |_| |_____\\____/|_| \\_|\n #setup_position() {\n this.#move.onpointerdown = (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (!this.#element) return;\n this.#move.setPointerCapture(e.pointerId);\n const x = this.#position_x;\n const y = this.#position_y;\n const offset_x = e.offsetX;\n const offset_y = e.offsetY;\n this.#move.onpointermove = (ev) => {\n if (this.#element) {\n const pos_x = (ev.offsetX - offset_x) / this.#scale_buffer + x;\n this.position_x = ev.shiftKey\n ? pos_x\n : Math.round(pos_x / this.#grid_x_buffer) * this.#grid_x_buffer;\n const pos_y = (ev.offsetY - offset_y) / this.#scale_buffer + y;\n this.position_y = ev.shiftKey\n ? pos_y\n : Math.round(pos_y / this.#grid_y_buffer) * this.#grid_y_buffer;\n }\n };\n this.#move.onpointerup = (ev) => {\n this.#move.releasePointerCapture(ev.pointerId);\n this.#move.onpointermove = null;\n };\n };\n }\n\n #position_x = 0;\n set position_x(value: number) {\n this.#canvas.setAttribute(\"x\", String(value));\n this.#position_x = value;\n if (this.#element) this.#element.position_x = value;\n this.#update_mover_transform();\n }\n\n #position_y = 0;\n set position_y(value: number) {\n this.#canvas.setAttribute(\"y\", String(value));\n this.#position_y = value;\n if (this.#element) this.#element.position_y = value;\n this.#update_mover_transform();\n }\n\n // _____ ____ _______ _______ _____ ____ _ _\n // | __ \\ / __ \\__ __|/\\|__ __|_ _/ __ \\| \\ | |\n // | |__) | | | | | | / \\ | | | || | | | \\| |\n // | _ /| | | | | | / /\\ \\ | | | || | | | . ` |\n // | | \\ \\| |__| | | |/ ____ \\| | _| || |__| | |\\ |\n // |_| \\_\\\\____/ |_/_/ \\_\\_| |_____\\____/|_| \\_|\n #setup_rotation() {\n this.#rotate.onpointerdown = (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (!this.#element) return;\n this.#rotate.setPointerCapture(e.pointerId);\n const ctm = this.#canvas.getScreenCTM();\n if (!ctm) return;\n // Use the rotation center as the angle reference so the mover and\n // element both rotate around the same point without position shifts.\n const center = new DOMPoint(\n this.#rotation_center_x,\n this.#rotation_center_y,\n ).matrixTransform(ctm);\n const initial_angle = Math.atan2(\n e.clientY - center.y,\n e.clientX - center.x,\n );\n const initial_rotation = this.#rotation;\n this.#rotate.onpointermove = (ev) => {\n if (!this.#element) return;\n const current_angle = Math.atan2(\n ev.clientY - center.y,\n ev.clientX - center.x,\n );\n const raw_rotation =\n initial_rotation + (current_angle - initial_angle) / DEG_TO_RAD;\n this.rotation = ev.shiftKey\n ? raw_rotation\n : Math.round(raw_rotation / this.#grid_rotate_buffer) *\n this.#grid_rotate_buffer;\n };\n this.#rotate.onpointerup = (ev) => {\n this.#rotate.releasePointerCapture(ev.pointerId);\n this.#rotate.onpointermove = null;\n };\n };\n }\n #update_rc_indicator() {\n this.#rc_indicator.setAttribute(\"x\", String(this.#rotation_center_x));\n this.#rc_indicator.setAttribute(\"y\", String(this.#rotation_center_y));\n this.#rc_indicator.setAttribute(\n \"transform-origin\",\n `${this.#rotation_center_x} ${this.#rotation_center_y}`,\n );\n }\n\n #rotation = 0;\n set rotation(value: number) {\n this.#rotation = value;\n if (this.#element) this.#element.rotation = value;\n this.#update_mover_transform();\n }\n\n #rotation_center_x = 0;\n #rotation_center_y = 0;\n\n // _____ _____ ____________\n // / ____|_ _|___ / ____|\n // | (___ | | / /| |__\n // \\___ \\ | | / / | __|\n // ____) |_| |_ / /__| |____\n // |_____/|_____/_____|______|\n #setup_corner(handle: SVGSVGElement, sx: number, sy: number) {\n handle.onpointerdown = (e) => {\n e.preventDefault();\n e.stopPropagation();\n if (!this.#element) return;\n handle.setPointerCapture(e.pointerId);\n const initial_x = e.clientX;\n const initial_y = e.clientY;\n const initial_w = this.#width;\n const initial_h = this.#height;\n const initial_px = this.#position_x;\n const initial_py = this.#position_y;\n const initial_rcx = this.#rotation_center_x;\n const initial_rcy = this.#rotation_center_y;\n const rad = this.#rotation * DEG_TO_RAD;\n const cos_r = Math.cos(rad);\n const sin_r = Math.sin(rad);\n handle.onpointermove = (ev) => {\n if (!this.#element) return;\n const canvas_dx = (ev.clientX - initial_x) / this.#scale_buffer;\n const canvas_dy = (ev.clientY - initial_y) / this.#scale_buffer;\n const local_dx = cos_r * canvas_dx + sin_r * canvas_dy;\n const local_dy = -sin_r * canvas_dx + cos_r * canvas_dy;\n let new_w = Math.max(1, initial_w + sx * local_dx);\n let new_h = Math.max(1, initial_h + sy * local_dy);\n if (!ev.shiftKey) {\n new_w = Math.round(new_w);\n new_h = Math.round(new_h);\n }\n const new_rcx =\n initial_w > 0 ? initial_rcx * (new_w / initial_w) : initial_rcx;\n const new_rcy =\n initial_h > 0 ? initial_rcy * (new_h / initial_h) : initial_rcy;\n const drc_x = initial_rcx - new_rcx;\n const drc_y = initial_rcy - new_rcy;\n const delta_w = new_w - initial_w;\n const delta_h = new_h - initial_h;\n let new_px = initial_px;\n let new_py = initial_py;\n if (sx < 0) {\n new_px -= delta_w * cos_r;\n new_py -= delta_w * sin_r;\n }\n if (sy < 0) {\n new_px += delta_h * sin_r;\n new_py -= delta_h * cos_r;\n }\n // Compensate position for the rotation pivot change so the\n // anchor corner stays visually fixed on a rotated element.\n new_px += drc_x * (1 - cos_r) + drc_y * sin_r;\n new_py += -drc_x * sin_r + drc_y * (1 - cos_r);\n this.#rotation_center_x = new_rcx;\n this.#rotation_center_y = new_rcy;\n if (this.#element) {\n this.#element.rotation_center_x = new_rcx;\n this.#element.rotation_center_y = new_rcy;\n }\n this.#update_rc_indicator();\n this.width = new_w;\n this.height = new_h;\n this.position_x = new_px;\n this.position_y = new_py;\n };\n handle.onpointerup = (ev) => {\n handle.releasePointerCapture(ev.pointerId);\n handle.onpointermove = null;\n };\n };\n }\n\n #width = 0;\n set width(value: number) {\n this.#outline.setAttribute(\"width\", (value + 2).toString());\n this.#ne_corner.setAttribute(\"x\", String(value));\n this.#ne_corner.setAttribute(\"transform-origin\", `${value} 0`);\n this.#se_corner.setAttribute(\"x\", String(value));\n this.#se_corner.setAttribute(\n \"transform-origin\",\n `${value} ${this.#height}`,\n );\n this.#move.setAttribute(\"x\", String(value / 2));\n this.#move.setAttribute(\n \"transform-origin\",\n `${value / 2} ${this.#height / 2}`,\n );\n this.#rotate.setAttribute(\"x\", String(value / 2));\n this.#rotate.setAttribute(\"transform-origin\", `${value / 2} 0`);\n this.#width = value;\n if (this.#element) this.#element.width = value;\n }\n #height = 0;\n set height(value: number) {\n this.#outline.setAttribute(\"height\", (value + 2).toString());\n this.#sw_corner.setAttribute(\"y\", String(value));\n this.#sw_corner.setAttribute(\"transform-origin\", `0 ${value}`);\n this.#se_corner.setAttribute(\"y\", String(value));\n this.#se_corner.setAttribute(\"transform-origin\", `${this.#width} ${value}`);\n this.#move.setAttribute(\"y\", String(value / 2));\n this.#move.setAttribute(\n \"transform-origin\",\n `${this.#width / 2} ${value / 2}`,\n );\n this.#height = value;\n if (this.#element) this.#element.height = value;\n }\n}\n","import { Base, define_element } from \"#base\";\nimport { sync_resolve } from \"@chocbite/ts-lib/common\";\nimport { ok } from \"@chocbite/ts-lib/result\";\nimport type { State, StateInferSub } from \"@chocbite/ts-lib/state\";\nimport { state } from \"@chocbite/ts-lib/state\";\nimport { svg } from \"#svg\";\nimport \"./viewport.scss\";\nimport type { ViewportElement } from \"./viewport_element\";\nimport { ViewportMover } from \"./viewport_mover\";\n\nexport class Viewport extends Base {\n static element_name(): string {\n return \"viewport\";\n }\n static element_name_space(): string {\n return \"editor\";\n }\n\n #viewport_width: number = 0;\n #viewport_width_half: number = 0;\n #viewport_height: number = 0;\n #viewport_height_half: number = 0;\n #resize_observer = new ResizeObserver((a) => {\n this.#viewport_width = a[0].contentRect.width;\n this.#viewport_width_half = this.#viewport_width / 2;\n this.#viewport_height = a[0].contentRect.height;\n this.#viewport_height_half = this.#viewport_height / 2;\n this.#pan_coordinates(\n this.#pan_x.ok() + (a[0].contentRect.width - this.#viewport_width) / 2,\n this.#pan_y.ok() + (a[0].contentRect.height - this.#viewport_height) / 2,\n );\n this.#root.setAttribute(\n \"viewBox\",\n `0 0 ${this.#viewport_width} ${this.#viewport_height}`,\n );\n });\n #root = this.appendChild(svg.create(\"svg\").elem);\n #panner;\n #zoomer;\n\n constructor(\n canvas_width: number,\n canvas_height: number,\n infinite_canvas: boolean = false,\n ) {\n super();\n this.#resize_observer.observe(this);\n this.#canvas_width = canvas_width;\n this.#canvas_height = canvas_height;\n //Panning\n this.#panner = this.#root.appendChild(\n svg\n .create(\"svg\")\n .a(\"width\", canvas_width.toString())\n .a(\"height\", canvas_height.toString()).elem,\n );\n //Zoomer\n this.#zoomer = this.#panner.appendChild(\n svg\n .create(\"svg\")\n .a(\"x\", \"-50%\")\n .a(\"y\", \"-50%\")\n .a(\"width\", canvas_width.toString())\n .a(\"height\", canvas_height.toString()).elem,\n );\n //Background\n (infinite_canvas ? this.#root : this.#zoomer).prepend(\n svg\n .create(\"rect\")\n .attribute(\"x\", \"0\")\n .attribute(\"y\", \"0\")\n .attribute(\"width\", \"100%\")\n .attribute(\"height\", \"100%\")\n .fill(\"white\").elem,\n );\n //Canvas\n this.#canvas = this.#zoomer.appendChild(\n svg.svg(\n canvas_width,\n canvas_height,\n `0 0 ${canvas_width} ${canvas_height}`,\n ).elem,\n );\n this.#canvas_elements = this.#canvas.appendChild(svg.create(\"g\").elem);\n\n // _____ _ _ _______ ______ _____ _____ _______ _____ ____ _ _\n // |_ _| \\ | |__ __| ____| __ \\ /\\ / ____|__ __|_ _/ __ \\| \\ | |\n // | | | \\| | | | | |__ | |__) | / \\ | | | | | || | | | \\| |\n // | | | . ` | | | | __| | _ / / /\\ \\| | | | | || | | | . ` |\n // _| |_| |\\ | | | | |____| | \\ \\ / ____ \\ |____ | | _| || |__| | |\\ |\n // |_____|_| \\_| |_| |______|_| \\_\\/_/ \\_\\_____| |_| |_____\\____/|_| \\_|\n\n let count = 0;\n let mover_x = 0;\n let mover_y = 0;\n let initial_x = 0;\n let initial_y = 0;\n let initial_id = 0;\n // let second_initial_x = 0;\n // let second_initial_y = 0;\n let second_initial_id = 0;\n\n //Middle Mouse\n let double_click = 0;\n this.addEventListener(\"pointerdown\", (e) => {\n if (e.pointerType === \"mouse\" || e.pointerType === \"touch\") {\n e.preventDefault();\n e.stopPropagation();\n\n // Element selection: detect clicks on the mover or viewport elements\n const target = e.target as Element;\n if (target.closest(\".viewport-mover\")) return;\n const elementCanvas = target.closest(\".viewport-element\");\n if (elementCanvas) {\n const element = this.#elements.find(\n (el) => el.canvas === elementCanvas,\n );\n if (element) {\n this.attach_mover(element);\n return;\n }\n }\n this.#detach_mover();\n\n //Double Click Reset Position\n const now = performance.now();\n if (now - double_click < 300) {\n this.#pan_coordinates(0, 0);\n this.#zoom_coordinates(\n Math.min(\n this.#viewport_height / this.#canvas_height,\n this.#viewport_width / this.#canvas_width,\n ),\n 0,\n 0,\n );\n return;\n }\n double_click = now;\n //Dragging\n this.setPointerCapture(e.pointerId);\n if (count === 0) {\n mover_x = this.#pan_x.ok();\n mover_y = this.#pan_y.ok();\n initial_x = e.offsetX;\n initial_y = e.offsetY;\n initial_id = e.pointerId;\n } else if (count === 1) {\n // second_initial_x = e.offsetX;\n // second_initial_y = e.offsetY;\n second_initial_id = e.pointerId;\n }\n count++;\n }\n });\n this.onpointermove = (ev) => {\n if (count === 0) return;\n if (ev.pointerId === initial_id) {\n this.#pan_coordinates(\n mover_x + (ev.offsetX - initial_x) / count,\n mover_y + (ev.offsetY - initial_y) / count,\n );\n } else if (ev.pointerId === second_initial_id) {\n if (count < 2) return;\n this.#pan_coordinates(\n mover_x + (ev.offsetX - initial_x) / count,\n mover_y + (ev.offsetY - initial_y) / count,\n );\n }\n };\n this.onpointerup = (ev) => {\n if (this.hasPointerCapture(ev.pointerId)) {\n this.releasePointerCapture(ev.pointerId);\n count--;\n }\n };\n //Wheel\n this.addEventListener(\n \"wheel\",\n (e) => {\n e.preventDefault();\n e.stopPropagation();\n const move_scale = e.shiftKey\n ? e.altKey\n ? 0.01\n : 0.05\n : e.altKey\n ? 2\n : 0.5;\n if (e.ctrlKey) {\n this.#pan_coordinates(\n undefined,\n this.#pan_y.ok() - e.deltaY * move_scale,\n );\n } else {\n const scale_scale = e.shiftKey\n ? e.altKey\n ? 0.00005\n : 0.0001\n : e.altKey\n ? 0.005\n : 0.001;\n const scale = this.#zoom.ok() * (1 - e.deltaY * scale_scale);\n this.#zoom_coordinates(\n scale,\n e.offsetX - this.#viewport_width / 2,\n e.offsetY - this.#viewport_height / 2,\n );\n }\n this.#pan_coordinates(\n this.#pan_x.ok() - e.deltaX * move_scale,\n undefined,\n );\n },\n { capture: true },\n );\n // Detach mover when clicking outside the viewport\n document.addEventListener(\"pointerdown\", (e) => {\n if (!this.contains(e.target as Node)) {\n this.#detach_mover();\n }\n });\n // Detach mover when the browser window loses focus\n window.addEventListener(\"blur\", () => {\n this.#detach_mover();\n });\n }\n\n #pan_coordinates(x?: number, y?: number) {\n if (x !== undefined) {\n this.#panner.setAttribute(\n \"x\",\n (this.#viewport_width_half + x).toFixed(0),\n );\n this.#pan_x.set_ok(x);\n }\n if (y !== undefined) {\n this.#panner.setAttribute(\n \"y\",\n (this.#viewport_height_half + y).toFixed(0),\n );\n this.#pan_y.set_ok(y);\n }\n }\n\n /**Zooms coordinate aware to offset canvas position so hover position stays\n * coordinates are relative to the center */\n #zoom_coordinates(scale: number, x: number, y: number) {\n scale = Math.max(0.001, Math.min(10000, scale));\n const zoom_factor = scale / this.#zoom.ok();\n this.#pan_coordinates(\n this.#pan_x.ok() * zoom_factor + x * (1 - zoom_factor),\n this.#pan_y.ok() * zoom_factor + y * (1 - zoom_factor),\n );\n this.#zoomer.style.scale = scale.toString();\n this.#zoom.set_ok(scale);\n }\n\n // _____ _ ___ __ _____\n // / ____| /\\ | \\ | \\ \\ / /\\ / ____|\n // | | / \\ | \\| |\\ \\ / / \\ | (___\n // | | / /\\ \\ | . ` | \\ \\/ / /\\ \\ \\___ \\\n // | |____ / ____ \\| |\\ | \\ / ____ \\ ____) |\n // \\_____/_/ \\_\\_| \\_| \\/_/ \\_\\_____/\n #canvas;\n #canvas_width;\n #canvas_height;\n #canvas_elements;\n\n set canvas_width(value: number) {\n this.#canvas.setAttribute(\"width\", value.toString());\n this.#canvas.setAttribute(\"viewBox\", `0 0 ${value} ${this.#canvas_height}`);\n this.#zoomer.setAttribute(\"width\", value.toString());\n this.#canvas_width = value;\n }\n get canvas_width(): number {\n return this.#canvas_width;\n }\n set canvas_height(value: number) {\n this.#canvas.setAttribute(\"height\", value.toString());\n this.#canvas.setAttribute(\"viewBox\", `0 0 ${this.#canvas_width} ${value}`);\n this.#zoomer.setAttribute(\"height\", value.toString());\n this.#canvas_height = value;\n }\n get canvas_height(): number {\n return this.#canvas_height;\n }\n\n #pan_x = state.rosw(ok(1), (value) => {\n return sync_resolve(ok(this.#pan_coordinates(value, undefined)));\n });\n readonly pan_x = this.#pan_x.read_write;\n\n #pan_y = state.rosw(ok(1), (value) => {\n return sync_resolve(ok(this.#pan_coordinates(undefined, value)));\n });\n readonly pan_y = this.#pan_y.read_write;\n\n #zoom = state.rosw(ok(1), (value) =>\n sync_resolve(ok(this.#zoom_coordinates(value, 0, 0))),\n );\n readonly zoom = this.#zoom.read_write;\n\n // _____ _____ _____ _____\n // / ____| __ \\|_ _| __ \\\n // | | __| |__) | | | | | | |\n // | | |_ | _ / | | | | | |\n // | |__| | | \\ \\ _| |_| |__| |\n // \\_____|_| \\_\\_____|_____/\n #grid_x = state.rosw(ok(10), (value) => {\n this.#grid_x.set_ok(value);\n return sync_resolve(ok(undefined));\n });\n readonly grid_x = this.#grid_x.read_write;\n\n #grid_y = state.rosw(ok(10), (value) => {\n this.#grid_y.set_ok(value);\n return sync_resolve(ok(undefined));\n });\n readonly grid_y = this.#grid_y.read_write;\n\n #grid_rotate = state.rosw(ok(15), (value) => {\n this.#grid_rotate.set_ok(value);\n return sync_resolve(ok(undefined));\n });\n readonly grid_rotate = this.#grid_rotate.read_write;\n\n // ______ _ ______ __ __ ______ _ _ _______ _____\n // | ____| | | ____| \\/ | ____| \\ | |__ __/ ____|\n // | |__ | | | |__ | \\ / | |__ | \\| | | | | (___\n // | __| | | | __| | |\\/| | __| | . ` | | | \\___ \\\n // | |____| |____| |____| | | | |____| |\\ | | | ____) |\n // |______|______|______|_| |_|______|_| \\_| |_| |_____/\n #elements: readonly ViewportElement[] = [];\n #state_sub?: StateInferSub<State<ViewportElement[]>>;\n\n set elements(elements: ViewportElement[] | State<ViewportElement[]>) {\n if (this.#state_sub) {\n this.detach_state(this.#state_sub);\n this.#state_sub = undefined;\n }\n if (state.is.state(elements)) {\n this.#state_sub = this.attach_state(elements, (r) =>\n this.#update_rows(r.ok ? r.value : []),\n );\n } else this.#update_rows(elements);\n }\n\n #update_rows(rows: readonly ViewportElement[]) {\n this.#elements = rows;\n if (rows.length === 0) {\n this.#canvas_elements.replaceChildren();\n return;\n }\n const read = state.a.read(rows);\n for (let i = 0; i < read.length; i++) {\n const row = read[i];\n if (row.type === \"fresh\")\n this.#canvas_elements.replaceChildren(\n ...row.items.map((i) => i.canvas),\n );\n else if (row.type === \"added\") {\n const child = this.#canvas_elements.children[row.index] as\n | SVGSVGElement\n | undefined;\n const rows = row.items.map((i) => i.canvas);\n if (child) child.before(...rows);\n else this.#canvas_elements.append(...rows);\n } else if (row.type === \"removed\")\n for (let i = 0; i < row.items.length; i++)\n this.#canvas_elements.children[row.index].remove();\n else if (row.type === \"changed\")\n for (let i = 0; i < row.items.length; i++)\n this.#canvas_elements.replaceChild(\n row.items[i].canvas,\n this.#canvas_elements.children[row.index + i],\n );\n else if (row.type === \"moved\") {\n const extracted = [];\n for (let i = 0; i < row.items.length; i++) {\n const child = this.#canvas_elements.children[\n row.from_index + i\n ] as SVGSVGElement;\n if (child) extracted.push(child);\n child.remove();\n }\n const child = this.#canvas_elements.children[row.to_index] as\n | SVGSVGElement\n | undefined;\n for (let i = 0; i < extracted.length; i++) {\n if (child) child.before(extracted[i]);\n else this.#canvas_elements.append(extracted[i]);\n }\n }\n }\n }\n\n // __ __ ______ ________ _____\n // | \\/ |/ __ \\ \\ / / ____| __ \\\n // | \\ / | | | \\ \\ / /| |__ | |__) |\n // | |\\/| | | | |\\ \\/ / | __| | _ /\n // | | | | |__| | \\ / | |____| | \\ \\\n // |_| |_|\\____/ \\/ |______|_| \\_\\\n #mover?: ViewportMover;\n\n attach_mover(move: ViewportElement) {\n (this.#mover ??= new ViewportMover(\n this.#zoom,\n this.#grid_x,\n this.#grid_y,\n this.#grid_rotate,\n )).attach_to_element(move, this.#canvas);\n }\n\n #detach_mover() {\n this.#mover?.detach_from_element();\n }\n}\ndefine_element(Viewport);\n\nexport function create_viewport(\n canvas_width: number,\n canvas_height: number,\n infinite_canvas: boolean = false,\n): Viewport {\n return new Viewport(canvas_width, canvas_height, infinite_canvas);\n}\n","import { some, type Option } from \"@chocbite/ts-lib/result\";\nimport { svg } from \"#svg\";\n\nexport abstract class ViewportElement {\n protected abstract element_name(): string;\n protected abstract element_name_space(): string;\n\n /**Default width of element when created */\n abstract default_width(): number;\n /**Default height of element when created */\n abstract default_height(): number;\n /**Element optimal ratio, returns the ratio where the element has no distortion.\n * If the element can dynamically change based on ratio, return none. */\n optimal_ratio(): Option<number> {\n const w = this.default_width();\n const h = this.default_height();\n if (w === 0 || h === 0) return some(0);\n return some(w / h);\n }\n\n /**Called when the element has no optimal ratio and its dimensions change.\n * Descendants can override this to re-layout their content in the new\n * coordinate space defined by the updated viewBox. */\n protected on_resize(_width: number, _height: number): void {}\n\n readonly canvas: SVGSVGElement = svg\n .svg(\n this.default_width(),\n this.default_height(),\n `0 0 ${this.default_width()} ${this.default_height()}`,\n )\n .cl(\n \"viewport-element\",\n `${this.element_name_space()}-${this.element_name()}`,\n ).elem;\n\n constructor() {\n // When the element has an optimal ratio, set preserveAspectRatio to \"none\"\n // so that non-uniform scaling (stretching) is applied when the display\n // dimensions deviate from the optimal ratio.\n if (this.optimal_ratio().some) {\n this.canvas.setAttribute(\"preserveAspectRatio\", \"none\");\n }\n }\n\n // _____ ____ _____ _____ _______ _____ ____ _ _\n // | __ \\ / __ \\ / ____|_ _|__ __|_ _/ __ \\| \\ | |\n // | |__) | | | | (___ | | | | | || | | | \\| |\n // | ___/| | | |\\___ \\ | | | | | || | | | . ` |\n // | | | |__| |____) |_| |_ | | _| || |__| | |\\ |\n // |_| \\____/|_____/|_____| |_| |_____\\____/|_| \\_|\n #position_x = 0;\n #position_y = 0;\n\n set position_x(value: number) {\n this.#position_x = value;\n this.canvas.setAttribute(\"x\", value.toString());\n this.#update_transform();\n }\n get position_x(): number {\n return this.#position_x;\n }\n\n set position_y(value: number) {\n this.#position_y = value;\n this.canvas.setAttribute(\"y\", value.toString());\n this.#update_transform();\n }\n get position_y(): number {\n return this.#position_y;\n }\n\n // _____ ____ _______ _______ _____ ____ _ _\n // | __ \\ / __ \\__ __|/\\|__ __|_ _/ __ \\| \\ | |\n // | |__) | | | | | | / \\ | | | || | | | \\| |\n // | _ /| | | | | | / /\\ \\ | | | || | | | . ` |\n // | | \\ \\| |__| | | |/ ____ \\| | _| || |__| | |\\ |\n // |_| \\_\\\\____/ |_/_/ \\_\\_| |_____\\____/|_| \\_|\n #rotation = 0;\n #rotation_center_x = this.default_width() / 2;\n #rotation_center_y = this.default_height() / 2;\n\n set rotation(value: number) {\n this.#rotation = value;\n this.#update_transform();\n }\n get rotation(): number {\n return this.#rotation;\n }\n\n /**Rotation center x coordinate, relative to the element's display area.\n * Defaults to half of default_width (center of element). */\n set rotation_center_x(value: number) {\n this.#rotation_center_x = value;\n this.#update_transform();\n }\n get rotation_center_x(): number {\n return this.#rotation_center_x;\n }\n\n /**Rotation center y coordinate, relative to the element's display area.\n * Defaults to half of default_height (center of element). */\n set rotation_center_y(value: number) {\n this.#rotation_center_y = value;\n this.#update_transform();\n }\n get rotation_center_y(): number {\n return this.#rotation_center_y;\n }\n\n #update_transform() {\n if (this.#rotation === 0) {\n this.canvas.removeAttribute(\"transform\");\n } else {\n const cx = this.#position_x + this.#rotation_center_x;\n const cy = this.#position_y + this.#rotation_center_y;\n this.canvas.setAttribute(\n \"transform\",\n `rotate(${this.#rotation} ${cx} ${cy})`,\n );\n }\n }\n\n // _____ _____ ____________\n // / ____|_ _|___ / ____|\n // | (___ | | / /| |__\n // \\___ \\ | | / / | __|\n // ____) |_| |_ / /__| |____\n // |_____/|_____/_____|______|\n #width = this.default_width();\n #height = this.default_height();\n\n /**Display width of the element. Changing this scales the element.\n * - If the element has an optimal_ratio, the viewBox stays at default\n * dimensions and the SVG content is stretched/scaled to fill the new size.\n * - If the element has no optimal_ratio, the viewBox is updated to match\n * the new dimensions and on_resize is called. */\n set width(value: number) {\n this.#width = value;\n this.#apply_size();\n }\n get width(): number {\n return this.#width;\n }\n\n /**Display height of the element. Changing this scales the element.\n * - If the element has an optimal_ratio, the viewBox stays at default\n * dimensions and the SVG content is stretched/scaled to fill the new size.\n * - If the element has no optimal_ratio, the viewBox is updated to match\n * the new dimensions and on_resize is called. */\n set height(value: number) {\n this.#height = value;\n this.#apply_size();\n }\n get height(): number {\n return this.#height;\n }\n\n #apply_size() {\n this.canvas.setAttribute(\"width\", this.#width.toString());\n this.canvas.setAttribute(\"height\", this.#height.toString());\n\n if (this.optimal_ratio().none) {\n // No optimal ratio: update the coordinate system to match the new\n // display size and notify the descendant so it can re-layout.\n this.canvas.setAttribute(\"viewBox\", `0 0 ${this.#width} ${this.#height}`);\n this.on_resize(this.#width, this.#height);\n }\n // When an optimal ratio exists the viewBox stays at the default\n // dimensions. preserveAspectRatio=\"none\" ensures the content is\n // stretched/scaled to fill the (possibly non-uniform) display size.\n }\n}\n","import { create_viewport } from \"./viewport\";\nexport { ViewportElement } from \"./viewport_element\";\n\nexport const viewport = {\n create_viewport,\n};\n"],"mappings":";;;;;;;;;AAOA,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACjD,GAAG,YAAY,IAAI,OAAO,QAAQ,CAAC,CAAC,IAAI;AACxC,GAAG,YAAY,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI;AAC1C,GAAG,YAAY,IAAI,mBAAmB,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI;AAC5E,GAAG,YAAY,IAAI,mBAAmB,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI;AACxE,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACjD,GAAG,YAAY,IAAI,OAAO,QAAQ,CAAC,CAAC,IAAI;AACxC,GAAG,YAAY,IAAI,KAAK,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI;AAC1C,GAAG,YAAY,IAAI,mBAAmB,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI;AAC3E,GAAG,YAAY,IAAI,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,IAAI;AACzE,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,CA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O,aACV,aACA,UAAU,KAAK,UAAU,GAAG,GAAG,GAAG,GAAG,EACvC;EACF;CACF;CAQA,SAAS,KAAK,cAAc;CAC5B,UAAU,KAAK,eAAe;;;;;;CAO9B,IAAI,MAAM,OAAe;EACvB,KAAK,SAAS;EACd,KAAK,YAAY;CACnB;CACA,IAAI,QAAgB;EAClB,OAAO,KAAK;CACd;;;;;;CAOA,IAAI,OAAO,OAAe;EACxB,KAAK,UAAU;EACf,KAAK,YAAY;CACnB;CACA,IAAI,SAAiB;EACnB,OAAO,KAAK;CACd;CAEA,cAAc;EACZ,KAAK,OAAO,aAAa,SAAS,KAAK,OAAO,SAAS,CAAC;EACxD,KAAK,OAAO,aAAa,UAAU,KAAK,QAAQ,SAAS,CAAC;EAE1D,IAAI,KAAK,cAAc,CAAC,CAAC,MAAM;GAG7B,KAAK,OAAO,aAAa,WAAW,OAAO,KAAK,OAAO,GAAG,KAAK,SAAS;GACxE,KAAK,UAAU,KAAK,QAAQ,KAAK,OAAO;EAC1C;CAIF;AACF;;ACzKA,MAAa,WAAW,EACtB,gBACF"}
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
+
import { r as theme_init_variable_root } from "./theme-BtAXQpvm.mjs";
|
|
4
|
+
import { DOCUMENT_HANDLER } from "./document/index.mjs";
|
|
5
|
+
import { Fm as material_chevron_right_rounded, xh as material_close_rounded } from "./icons-CY4BLQ2F.mjs";
|
|
6
|
+
import { Spinner } from "./spinner/index.mjs";
|
|
7
|
+
import { BLUE, GREY } from "@chocbite/ts-lib/colors";
|
|
8
|
+
// src/context-menu/shared.ts
|
|
9
|
+
const variables = theme_init_variable_root("contextmenu", "Context Menu", "Right click or touch and hold context menu appearance");
|
|
10
|
+
variables.make_variable("background", "Background Color", "Color of background", GREY["50"], GREY["900"], "Color", void 0);
|
|
11
|
+
variables.make_variable("text", "Text Color", "Color of text", GREY["600"], GREY["400"], "Color", void 0);
|
|
12
|
+
variables.make_variable("hover", "Hover Color", "Background color of line when hovering over it", BLUE["200"], BLUE["900"], "Color", void 0);
|
|
13
|
+
variables.make_variable("hoverText", "Text Color", "Standard text color", GREY["900"], GREY["50"], "Color", void 0);
|
|
14
|
+
variables.make_variable("border", "Border Color", "Color of border and deviders", GREY["300"], GREY["800"], "Color", void 0);
|
|
15
|
+
// src/context-menu/line.ts
|
|
16
|
+
var MenuLine = class extends Base {
|
|
17
|
+
/**Returns the name used to define the element */
|
|
18
|
+
static element_name() {
|
|
19
|
+
return "@abstract@";
|
|
20
|
+
}
|
|
21
|
+
/**Returns the namespace override for the element*/
|
|
22
|
+
static element_name_space() {
|
|
23
|
+
return "contextmenu";
|
|
24
|
+
}
|
|
25
|
+
/**Changes focus to the next line
|
|
26
|
+
* @param direction false is next sibling, true is previous */
|
|
27
|
+
focus_next(direction) {
|
|
28
|
+
if (direction) {
|
|
29
|
+
if (this.previousElementSibling) this.previousElementSibling.do_focus(true);
|
|
30
|
+
else if (this.parentElement?.lastElementChild !== this) (this.parentElement?.lastElementChild).do_focus(true);
|
|
31
|
+
} else if (this.nextElementSibling) this.nextElementSibling.do_focus();
|
|
32
|
+
else if (this.parentElement?.firstElementChild !== this) (this.parentElement?.firstElementChild).do_focus();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// src/context-menu/devider.ts
|
|
36
|
+
var Devider = class extends MenuLine {
|
|
37
|
+
/**Returns the name used to define the element */
|
|
38
|
+
static element_name() {
|
|
39
|
+
return "devider";
|
|
40
|
+
}
|
|
41
|
+
do_focus(dir) {
|
|
42
|
+
this.focus_next(dir);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
define_element(Devider);
|
|
46
|
+
function context_devider() {
|
|
47
|
+
return new Devider();
|
|
48
|
+
}
|
|
49
|
+
// src/context-menu/container.ts
|
|
50
|
+
var Container = class extends Base {
|
|
51
|
+
#active_element_buffer;
|
|
52
|
+
/**Returns the name used to define the element */
|
|
53
|
+
static element_name() {
|
|
54
|
+
return "container";
|
|
55
|
+
}
|
|
56
|
+
/**Returns the namespace override for the element*/
|
|
57
|
+
static element_name_space() {
|
|
58
|
+
return "contextmenu";
|
|
59
|
+
}
|
|
60
|
+
constructor() {
|
|
61
|
+
super();
|
|
62
|
+
this.tabIndex = -1;
|
|
63
|
+
const preventer = (e) => {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
};
|
|
67
|
+
this.oncontextmenu = preventer;
|
|
68
|
+
this.onpointerdown = preventer;
|
|
69
|
+
this.onpointerup = preventer;
|
|
70
|
+
this.onpointercancel = preventer;
|
|
71
|
+
this.onpointerenter = preventer;
|
|
72
|
+
this.onpointerleave = preventer;
|
|
73
|
+
this.onpointermove = preventer;
|
|
74
|
+
this.onpointerout = preventer;
|
|
75
|
+
this.onpointerout = preventer;
|
|
76
|
+
this.onclick = preventer;
|
|
77
|
+
}
|
|
78
|
+
/**Attaches a menu to the container */
|
|
79
|
+
attach_menu(menu) {
|
|
80
|
+
menu.container = this;
|
|
81
|
+
this.#active_element_buffer = this.ownerDocument.activeElement;
|
|
82
|
+
this.replaceChildren(menu);
|
|
83
|
+
return menu;
|
|
84
|
+
}
|
|
85
|
+
/**Closes open context menu */
|
|
86
|
+
close_up() {
|
|
87
|
+
if (this.#active_element_buffer) {
|
|
88
|
+
this.#active_element_buffer.focus();
|
|
89
|
+
if (this.ownerDocument.activeElement !== this.#active_element_buffer) this.focus();
|
|
90
|
+
this.#active_element_buffer = void 0;
|
|
91
|
+
} else this.focus();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
define_element(Container);
|
|
95
|
+
// src/context-menu/engine.ts
|
|
96
|
+
const CONTEXT_MENY_SYMBOL = Symbol("context_menu");
|
|
97
|
+
/**Reference to document handler*/
|
|
98
|
+
let default_menu;
|
|
99
|
+
DOCUMENT_HANDLER.events.on("added", (e) => {
|
|
100
|
+
apply_to_doc(e.data);
|
|
101
|
+
});
|
|
102
|
+
DOCUMENT_HANDLER.for_documents((doc) => {
|
|
103
|
+
apply_to_doc(doc);
|
|
104
|
+
});
|
|
105
|
+
function apply_to_doc(doc) {
|
|
106
|
+
const container = new Container();
|
|
107
|
+
doc[CONTEXT_MENY_SYMBOL] = container;
|
|
108
|
+
doc.documentElement.appendChild(container);
|
|
109
|
+
if (default_menu) context_menu_attach(doc.documentElement, default_menu);
|
|
110
|
+
}
|
|
111
|
+
/**Attaches a context menu to the given element
|
|
112
|
+
* @param element the element to attach the context menu to
|
|
113
|
+
* @param lines the context menu to attach, if a function is given it will be called when the context menu is summoned
|
|
114
|
+
* @param block a function that returns true if the context menu should not be summoned, if undefined the context menu will always be summoned*/
|
|
115
|
+
function context_menu_attach(element, lines, block) {
|
|
116
|
+
if (element[CONTEXT_MENY_SYMBOL]) context_menu_detach(element);
|
|
117
|
+
const listener = (e) => {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
if (block && block()) return;
|
|
121
|
+
const lineses = typeof lines === "function" ? lines().unwrap_or(void 0) : lines;
|
|
122
|
+
if (!lineses) return;
|
|
123
|
+
context_menu_summon(lineses, element, e.clientX, e.clientY);
|
|
124
|
+
};
|
|
125
|
+
element.addEventListener("contextmenu", listener);
|
|
126
|
+
element[CONTEXT_MENY_SYMBOL] = listener;
|
|
127
|
+
}
|
|
128
|
+
/**Dettaches the context menu from the given element */
|
|
129
|
+
function context_menu_detach(element) {
|
|
130
|
+
if (element[CONTEXT_MENY_SYMBOL]) {
|
|
131
|
+
element.removeEventListener("contextmenu", element[CONTEXT_MENY_SYMBOL]);
|
|
132
|
+
delete element[CONTEXT_MENY_SYMBOL];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**Summons a context menu at a given location
|
|
136
|
+
* @param menu the context menu to summon
|
|
137
|
+
* @param element the element the context menu is referenced to, if undefined the context menu will appear in the main document
|
|
138
|
+
* @param x x position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen
|
|
139
|
+
* @param y y position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen
|
|
140
|
+
* @param dont_cover when set true */
|
|
141
|
+
function context_menu_summon(menu, element, x, y, dont_cover) {
|
|
142
|
+
const container = element ? element.ownerDocument[CONTEXT_MENY_SYMBOL] : DOCUMENT_HANDLER.main[CONTEXT_MENY_SYMBOL];
|
|
143
|
+
if (container) {
|
|
144
|
+
if (typeof x !== "number" || typeof y !== "number") {
|
|
145
|
+
if (element) {
|
|
146
|
+
const box = element.getBoundingClientRect();
|
|
147
|
+
x = box.left + box.width / 2;
|
|
148
|
+
y = box.top + box.height / 2;
|
|
149
|
+
} else {
|
|
150
|
+
x = 0;
|
|
151
|
+
y = 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
container.attach_menu(menu).set_position(x, y, dont_cover ? element : void 0);
|
|
155
|
+
} else console.error("No context menu container available");
|
|
156
|
+
}
|
|
157
|
+
/**Sets the default context menu for the page, the one used if no other context menu has been attached to the element
|
|
158
|
+
* If set to a boolean the operating system context menu is disabled and nothing will appear
|
|
159
|
+
* If set undefined the operating systems context menu will be used*/
|
|
160
|
+
function context_menu_default(lines) {
|
|
161
|
+
if (default_menu) DOCUMENT_HANDLER.for_documents((doc) => {
|
|
162
|
+
context_menu_detach(doc.documentElement);
|
|
163
|
+
});
|
|
164
|
+
if (lines) {
|
|
165
|
+
default_menu = lines;
|
|
166
|
+
DOCUMENT_HANDLER.for_documents((doc) => {
|
|
167
|
+
context_menu_attach(doc.documentElement, lines);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// src/context-menu/buffer.ts
|
|
172
|
+
var Buffer = class extends MenuLine {
|
|
173
|
+
/**Returns the name used to define the element */
|
|
174
|
+
static element_name() {
|
|
175
|
+
return "buffer";
|
|
176
|
+
}
|
|
177
|
+
constructor() {
|
|
178
|
+
super();
|
|
179
|
+
this.appendChild(new Spinner());
|
|
180
|
+
}
|
|
181
|
+
do_focus(dir) {
|
|
182
|
+
this.focus_next(dir);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
define_element(Buffer);
|
|
186
|
+
// src/context-menu/option.ts
|
|
187
|
+
var MenuOption = class extends MenuLine {
|
|
188
|
+
func;
|
|
189
|
+
/**Returns the name used to define the element */
|
|
190
|
+
static element_name() {
|
|
191
|
+
return "option";
|
|
192
|
+
}
|
|
193
|
+
constructor(text, func, icon, shortcut, checkmark) {
|
|
194
|
+
super();
|
|
195
|
+
this.func = func;
|
|
196
|
+
this.tabIndex = 0;
|
|
197
|
+
const icon_box = this.appendChild(document.createElement("div"));
|
|
198
|
+
icon_box.className = "icon";
|
|
199
|
+
if (icon) icon_box.appendChild(icon);
|
|
200
|
+
const text_box = this.appendChild(document.createElement("div"));
|
|
201
|
+
text_box.innerHTML = text;
|
|
202
|
+
text_box.className = "text";
|
|
203
|
+
const shortcut_box = this.appendChild(document.createElement("div"));
|
|
204
|
+
if (shortcut) shortcut_box.innerHTML = shortcut;
|
|
205
|
+
shortcut_box.className = "shortcut";
|
|
206
|
+
const check_mark_box = this.appendChild(document.createElement("div"));
|
|
207
|
+
if (checkmark) check_mark_box.innerHTML = "✓";
|
|
208
|
+
check_mark_box.className = "checkmark";
|
|
209
|
+
this.onclick = (e) => {
|
|
210
|
+
e.stopPropagation();
|
|
211
|
+
this.func();
|
|
212
|
+
navigator?.vibrate(25);
|
|
213
|
+
this.parentElement.close_up();
|
|
214
|
+
};
|
|
215
|
+
this.onkeydown = (e) => {
|
|
216
|
+
switch (e.code) {
|
|
217
|
+
case "Tab":
|
|
218
|
+
case "ArrowUp":
|
|
219
|
+
case "ArrowDown":
|
|
220
|
+
this.focus_next(e.shiftKey || e.code === "ArrowUp");
|
|
221
|
+
break;
|
|
222
|
+
case "Enter":
|
|
223
|
+
case "Space":
|
|
224
|
+
this.func();
|
|
225
|
+
this.parentElement.close_up();
|
|
226
|
+
break;
|
|
227
|
+
case "ArrowLeft":
|
|
228
|
+
case "Escape": return;
|
|
229
|
+
}
|
|
230
|
+
e.preventDefault();
|
|
231
|
+
e.stopPropagation();
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
do_focus() {
|
|
235
|
+
this.focus();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
define_element(MenuOption);
|
|
239
|
+
function context_line(text, func, icon, shortcut, checkmark) {
|
|
240
|
+
return new MenuOption(text, func, icon, shortcut, checkmark);
|
|
241
|
+
}
|
|
242
|
+
// src/context-menu/submenu.ts
|
|
243
|
+
var MenuSub = class extends MenuLine {
|
|
244
|
+
#menu;
|
|
245
|
+
#is_open;
|
|
246
|
+
#hover_time;
|
|
247
|
+
#block_time;
|
|
248
|
+
/**Returns the name used to define the element */
|
|
249
|
+
static element_name() {
|
|
250
|
+
return "submenu";
|
|
251
|
+
}
|
|
252
|
+
constructor(text, menu, icon) {
|
|
253
|
+
super();
|
|
254
|
+
this.#menu = menu;
|
|
255
|
+
this.tabIndex = 0;
|
|
256
|
+
const icon_box = this.appendChild(document.createElement("div"));
|
|
257
|
+
icon_box.className = "icon";
|
|
258
|
+
if (icon) icon_box.appendChild(icon);
|
|
259
|
+
const text_box = this.appendChild(document.createElement("div"));
|
|
260
|
+
text_box.innerHTML = text;
|
|
261
|
+
text_box.className = "text";
|
|
262
|
+
const shortcut_box = this.appendChild(document.createElement("div"));
|
|
263
|
+
shortcut_box.className = "shortcut";
|
|
264
|
+
const chevron_box = this.appendChild(document.createElement("div"));
|
|
265
|
+
chevron_box.appendChild(material_chevron_right_rounded());
|
|
266
|
+
chevron_box.className = "chevron";
|
|
267
|
+
this.onclick = (e) => {
|
|
268
|
+
e.stopPropagation();
|
|
269
|
+
if (!this.#block_time) {
|
|
270
|
+
navigator?.vibrate(25);
|
|
271
|
+
if (this.#is_open) this.close_down();
|
|
272
|
+
else this.open();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
this.onpointerenter = (e) => {
|
|
276
|
+
if (e.pointerType !== "touch" && !this.#is_open) this.#hover_time = window.setTimeout(() => {
|
|
277
|
+
this.open();
|
|
278
|
+
this.#block_time = window.setTimeout(() => {
|
|
279
|
+
this.#block_time = 0;
|
|
280
|
+
}, 500);
|
|
281
|
+
}, 300);
|
|
282
|
+
};
|
|
283
|
+
this.onpointerleave = () => {
|
|
284
|
+
clearTimeout(this.#hover_time);
|
|
285
|
+
};
|
|
286
|
+
this.onkeydown = (e) => {
|
|
287
|
+
switch (e.code) {
|
|
288
|
+
case "Tab":
|
|
289
|
+
case "ArrowUp":
|
|
290
|
+
case "ArrowDown":
|
|
291
|
+
this.focus_next(e.shiftKey || e.code === "ArrowUp");
|
|
292
|
+
break;
|
|
293
|
+
case "ArrowRight":
|
|
294
|
+
case "Enter":
|
|
295
|
+
case "Space":
|
|
296
|
+
this.open();
|
|
297
|
+
this.#menu.focus_next(false);
|
|
298
|
+
break;
|
|
299
|
+
case "ArrowLeft":
|
|
300
|
+
case "Escape": return;
|
|
301
|
+
}
|
|
302
|
+
e.preventDefault();
|
|
303
|
+
e.stopPropagation();
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**Opens the sub menu */
|
|
307
|
+
open() {
|
|
308
|
+
const sub = this.parentElement;
|
|
309
|
+
if (sub) sub.close_down();
|
|
310
|
+
this.parentElement.submenu = this;
|
|
311
|
+
this.appendChild(this.#menu);
|
|
312
|
+
this.#menu.set_position(0, 0, this);
|
|
313
|
+
this.#is_open = true;
|
|
314
|
+
}
|
|
315
|
+
do_focus() {
|
|
316
|
+
this.focus();
|
|
317
|
+
}
|
|
318
|
+
/**Closes menu by calling parent*/
|
|
319
|
+
close() {
|
|
320
|
+
this.focus();
|
|
321
|
+
this.parentElement.submenu = void 0;
|
|
322
|
+
this.removeChild(this.#menu);
|
|
323
|
+
this.#is_open = false;
|
|
324
|
+
}
|
|
325
|
+
/**Closes the context menu down the tree*/
|
|
326
|
+
close_down() {
|
|
327
|
+
this.#menu.close_down();
|
|
328
|
+
this.close();
|
|
329
|
+
}
|
|
330
|
+
/**Closes the context menu up the tree to the root*/
|
|
331
|
+
close_up() {
|
|
332
|
+
this.close();
|
|
333
|
+
this.parentElement.close_up();
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
define_element(MenuSub);
|
|
337
|
+
function context_sub(text, menu, icon) {
|
|
338
|
+
return new MenuSub(text, menu, icon);
|
|
339
|
+
}
|
|
340
|
+
// src/context-menu/menu.ts
|
|
341
|
+
var ContextMenu = class extends Base {
|
|
342
|
+
/**Returns the name used to define the element */
|
|
343
|
+
static element_name() {
|
|
344
|
+
return "menu";
|
|
345
|
+
}
|
|
346
|
+
/**Returns the namespace override for the element*/
|
|
347
|
+
static element_name_space() {
|
|
348
|
+
return "contextmenu";
|
|
349
|
+
}
|
|
350
|
+
container;
|
|
351
|
+
submenu;
|
|
352
|
+
#closer;
|
|
353
|
+
#x;
|
|
354
|
+
#y;
|
|
355
|
+
#element;
|
|
356
|
+
#focus_out_handler = (e) => {
|
|
357
|
+
e.preventDefault();
|
|
358
|
+
e.stopPropagation();
|
|
359
|
+
if (!e.relatedTarget || !this.contains(e.relatedTarget)) {
|
|
360
|
+
this.close_up();
|
|
361
|
+
this.close_down();
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
#window_resize_handler = () => {
|
|
365
|
+
this.set_position(this.#x, this.#y, this.#element);
|
|
366
|
+
};
|
|
367
|
+
#lines;
|
|
368
|
+
constructor(lines) {
|
|
369
|
+
super();
|
|
370
|
+
this.#lines = lines;
|
|
371
|
+
this.tabIndex = 0;
|
|
372
|
+
this.onscroll = () => {
|
|
373
|
+
this.close_down();
|
|
374
|
+
};
|
|
375
|
+
this.onkeydown = (e) => {
|
|
376
|
+
if (e.code === "Tab" || e.code === "ArrowUp" || e.code === "ArrowDown") this.focus_next(e.shiftKey || e.code === "ArrowUp");
|
|
377
|
+
else if (e.code === "ArrowLeft") {
|
|
378
|
+
const parent = this.parentElement;
|
|
379
|
+
if (!(parent instanceof Container)) {
|
|
380
|
+
parent.focus();
|
|
381
|
+
parent.close_down();
|
|
382
|
+
}
|
|
383
|
+
} else if (e.code === "Escape") this.close_up();
|
|
384
|
+
e.preventDefault();
|
|
385
|
+
e.stopPropagation();
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
connectedCallback() {
|
|
389
|
+
super.connectedCallback();
|
|
390
|
+
const lines = typeof this.#lines === "function" ? this.#lines() : this.#lines;
|
|
391
|
+
if (lines instanceof Promise) {
|
|
392
|
+
const buffer = this.appendChild(new Buffer());
|
|
393
|
+
lines.then((line) => {
|
|
394
|
+
buffer.remove();
|
|
395
|
+
this.lines = line;
|
|
396
|
+
this.set_position(this.#x, this.#y, this.#element);
|
|
397
|
+
});
|
|
398
|
+
} else this.lines = lines;
|
|
399
|
+
this.addEventListener("focusout", this.#focus_out_handler, { capture: true });
|
|
400
|
+
this.ownerDocument.defaultView?.addEventListener("resize", this.#window_resize_handler, { passive: true });
|
|
401
|
+
}
|
|
402
|
+
disconnectedCallback() {
|
|
403
|
+
super.disconnectedCallback();
|
|
404
|
+
this.ownerDocument.defaultView?.removeEventListener("resize", this.#window_resize_handler);
|
|
405
|
+
}
|
|
406
|
+
/**Sets the lines of the context menu */
|
|
407
|
+
set lines(lines) {
|
|
408
|
+
this.replaceChildren();
|
|
409
|
+
if (this.#closer) this.appendChild(this.#closer);
|
|
410
|
+
for (let i = 0; i < lines.length; i++) {
|
|
411
|
+
const line = lines[i];
|
|
412
|
+
if (line) this.appendChild(line);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**Changes focus to the next line
|
|
416
|
+
* @param direction false is first child, true is last child */
|
|
417
|
+
focus_next(direction) {
|
|
418
|
+
if (direction) this.lastChild?.do_focus();
|
|
419
|
+
else this.firstChild?.do_focus(true);
|
|
420
|
+
}
|
|
421
|
+
set closer(closer) {
|
|
422
|
+
if (closer && !this.#closer) {
|
|
423
|
+
this.classList.add("closer");
|
|
424
|
+
this.#closer = new MenuOption("Close", () => {}, material_close_rounded());
|
|
425
|
+
this.#closer.onclick = (e) => {
|
|
426
|
+
e.stopPropagation();
|
|
427
|
+
if (this.parentElement instanceof MenuSub) this.parentElement.close_down();
|
|
428
|
+
else this.close_up();
|
|
429
|
+
};
|
|
430
|
+
this.prepend(this.#closer);
|
|
431
|
+
} else if (!closer && this.#closer) {
|
|
432
|
+
this.classList.remove("closer");
|
|
433
|
+
this.#closer.remove();
|
|
434
|
+
this.#closer = void 0;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**Sets the context menu to fullscreen mode in x directino */
|
|
438
|
+
set fullscreenx(full) {
|
|
439
|
+
if (full) this.classList.add("fullscreen-x");
|
|
440
|
+
else this.classList.remove("fullscreen-x");
|
|
441
|
+
}
|
|
442
|
+
/**Sets the context menu to fullscreen mode in y direction */
|
|
443
|
+
set fullscreeny(full) {
|
|
444
|
+
if (full) this.classList.add("fullscreen-y");
|
|
445
|
+
else this.classList.remove("fullscreen-y");
|
|
446
|
+
}
|
|
447
|
+
/**Closes the context menu down the tree*/
|
|
448
|
+
close_down() {
|
|
449
|
+
if (this.submenu) this.submenu.close_down();
|
|
450
|
+
this.submenu = void 0;
|
|
451
|
+
}
|
|
452
|
+
/**Closes the context menu up the tree to the root*/
|
|
453
|
+
close_up() {
|
|
454
|
+
this.removeEventListener("focusout", this.#focus_out_handler, { capture: true });
|
|
455
|
+
this.parentElement?.close_up();
|
|
456
|
+
this.remove();
|
|
457
|
+
}
|
|
458
|
+
/**Updates the position of the menu
|
|
459
|
+
* @param x x coordinate for menu, this will be ignored if needed for contextmenu to fit
|
|
460
|
+
* @param y y coordinate for menu, this will be ignored if needed for contextmenu to fit
|
|
461
|
+
* @param element element to use instead of coordinates, the contextemenu will avoid covering the element if possible*/
|
|
462
|
+
set_position(x = 0, y = 0, element) {
|
|
463
|
+
this.#x = x;
|
|
464
|
+
this.#y = y;
|
|
465
|
+
this.#element = element;
|
|
466
|
+
const box = this.getBoundingClientRect();
|
|
467
|
+
const box_area = box.width * box.height;
|
|
468
|
+
const window = this.ownerDocument.defaultView;
|
|
469
|
+
const html_area = window.innerWidth * window.innerHeight;
|
|
470
|
+
this.closer = box_area > html_area * .5;
|
|
471
|
+
let top = NaN;
|
|
472
|
+
let bottom = NaN;
|
|
473
|
+
let left = NaN;
|
|
474
|
+
let right = NaN;
|
|
475
|
+
if (element) {
|
|
476
|
+
const sub_box = element.getBoundingClientRect();
|
|
477
|
+
if (sub_box.x + sub_box.width + box.width > window.innerWidth) {
|
|
478
|
+
x = sub_box.x;
|
|
479
|
+
if (box.width < x) right = window.innerWidth - x;
|
|
480
|
+
else right = window.innerWidth - (sub_box.x + sub_box.width);
|
|
481
|
+
} else x = sub_box.x + sub_box.width;
|
|
482
|
+
y = sub_box.y + sub_box.height;
|
|
483
|
+
if (y + box.height >= window.innerHeight) {
|
|
484
|
+
if (y >= box.height) bottom = window.innerHeight - sub_box.y;
|
|
485
|
+
else top = window.innerHeight - box.height;
|
|
486
|
+
} else top = y;
|
|
487
|
+
} else {
|
|
488
|
+
if (y + box.height >= window.innerHeight) {
|
|
489
|
+
if (y >= box.height) bottom = window.innerHeight - y;
|
|
490
|
+
else top = window.innerHeight - box.height;
|
|
491
|
+
} else top = y;
|
|
492
|
+
if (box.width >= window.innerWidth) right = 0;
|
|
493
|
+
else if (x + box.width >= window.innerWidth) {
|
|
494
|
+
if (x >= box.width) right = window.innerWidth - x;
|
|
495
|
+
else left = window.innerWidth - box.width;
|
|
496
|
+
} else left = x;
|
|
497
|
+
}
|
|
498
|
+
this.fullscreenx = box.width === window.innerWidth;
|
|
499
|
+
this.fullscreeny = box.height >= window.innerHeight;
|
|
500
|
+
this.style.top = top === top ? top + "px" : "";
|
|
501
|
+
this.style.bottom = bottom === bottom ? bottom + "px" : "";
|
|
502
|
+
this.style.left = left === left ? left + "px" : "";
|
|
503
|
+
this.style.right = right === right ? right + "px" : "";
|
|
504
|
+
this.focus();
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
define_element(ContextMenu);
|
|
508
|
+
function context_menu(lines) {
|
|
509
|
+
return new ContextMenu(lines);
|
|
510
|
+
}
|
|
511
|
+
// src/context-menu/index.ts
|
|
512
|
+
const ctm = {
|
|
513
|
+
attach: context_menu_attach,
|
|
514
|
+
default: context_menu_default,
|
|
515
|
+
detach: context_menu_detach,
|
|
516
|
+
summon: context_menu_summon,
|
|
517
|
+
has(element) {
|
|
518
|
+
return Boolean(element[CONTEXT_MENY_SYMBOL]);
|
|
519
|
+
},
|
|
520
|
+
menu: context_menu,
|
|
521
|
+
line: context_line,
|
|
522
|
+
sub: context_sub,
|
|
523
|
+
devider: context_devider
|
|
524
|
+
};
|
|
525
|
+
export { ctm as t };
|
|
526
|
+
|
|
527
|
+
//# sourceMappingURL=context-menu-BbDVgMiZ.mjs.map
|