@chocbite/ts-lib-ui 1.0.2 → 1.0.4

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 (58) hide show
  1. package/README.md +16 -1
  2. package/base/index.d.mts +2 -2
  3. package/base/index.mjs +69 -77
  4. package/base/index.mjs.map +1 -1
  5. package/canvas/index.d.mts +117 -60
  6. package/canvas/index.mjs +652 -584
  7. package/canvas/index.mjs.map +1 -1
  8. package/context-menu/index.d.mts +1 -1
  9. package/context-menu/index.mjs +1 -1
  10. package/{context-menu-CiNcuP-a.mjs → context-menu-Cz9rqUaM.mjs} +71 -37
  11. package/context-menu-Cz9rqUaM.mjs.map +1 -0
  12. package/document/index.mjs +3 -1
  13. package/document/index.mjs.map +1 -1
  14. package/form/index.d.mts +16 -5
  15. package/form/index.mjs +412 -153
  16. package/form/index.mjs.map +1 -1
  17. package/icons/index.d.mts +1 -1
  18. package/icons/index.mjs +1 -1
  19. package/icons-e2J_Ojic.mjs +4124 -0
  20. package/{index-BcidwqIy.d.mts → index-BDWg5GX2.d.mts} +7 -18
  21. package/{index-BND79jZp.d.mts → index-CvzH3M_5.d.mts} +16 -9
  22. package/{index-CugtUzv_.d.mts → index-DCn7acFY.d.mts} +30 -12
  23. package/{index-CB3-qP6l.d.mts → index-DhRb2iA8.d.mts} +7 -5
  24. package/keyboard/index.d.mts +1 -1
  25. package/keyboard/index.mjs +121 -50
  26. package/keyboard/index.mjs.map +1 -1
  27. package/list/index.d.mts +1 -1
  28. package/list/index.mjs +1 -1
  29. package/{list-CQDnxsLV.mjs → list-DXkEJKjx.mjs} +218 -117
  30. package/list-DXkEJKjx.mjs.map +1 -0
  31. package/package.json +7 -7
  32. package/selection/index.mjs +9 -11
  33. package/selection/index.mjs.map +1 -1
  34. package/settings/index.d.mts +23 -5
  35. package/settings/index.mjs +17 -10
  36. package/settings/index.mjs.map +1 -1
  37. package/spinner/index.d.mts +1 -1
  38. package/spinner/index.mjs +2 -2
  39. package/state/index.d.mts +36 -0
  40. package/state/index.mjs +2 -0
  41. package/state-OCzEmq3j.mjs +87 -0
  42. package/state-OCzEmq3j.mjs.map +1 -0
  43. package/style.css +423 -142
  44. package/svg/index.d.mts +1 -1
  45. package/svg/index.mjs +1 -1
  46. package/{svg-golJPaR4.mjs → svg-1bp-yIPC.mjs} +20 -17
  47. package/svg-1bp-yIPC.mjs.map +1 -0
  48. package/theme/index.d.mts +21 -2
  49. package/theme/index.mjs +1 -1
  50. package/{theme-9ib89_3b.mjs → theme-CFeGnUuF.mjs} +125 -44
  51. package/theme-CFeGnUuF.mjs.map +1 -0
  52. package/context-menu-CiNcuP-a.mjs.map +0 -1
  53. package/icons-CY4BLQ2F.mjs +0 -4123
  54. package/list-CQDnxsLV.mjs.map +0 -1
  55. package/svg-golJPaR4.mjs.map +0 -1
  56. package/theme-9ib89_3b.mjs.map +0 -1
  57. package/viewport/index.d.mts +0 -1
  58. package/viewport/index.mjs +0 -2
@@ -1 +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;AAC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ACnC,KAAK,qBAAqB;EAC1B,KAAK,kBAAkB;CACzB;CACA,IAAI,oBAA4B;EAC9B,OAAO,KAAK;CACd;;;CAIA,IAAI,kBAAkB,OAAe;EACnC,KAAK,qBAAqB;EAC1B,KAAK,kBAAkB;CACzB;CACA,IAAI,oBAA4B;EAC9B,OAAO,KAAK;CACd;CAEA,oBAAoB;EAClB,IAAI,KAAK,cAAc,GACrB,KAAK,OAAO,gBAAgB,WAAW;OAClC;GACL,MAAM,KAAK,KAAK,cAAc,KAAK;GACnC,MAAM,KAAK,KAAK,cAAc,KAAK;GACnC,KAAK,OAAO,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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/canvas/shared.ts","../../src/canvas/page.ts","../../src/canvas/widget.ts","../../src/canvas/transformer.ts","../../src/canvas/viewport.ts","../../src/canvas/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst theme_root = theme_init_variable_root(\n \"canvas\",\n \"Canvas\",\n \"Theme variables for canvas viewports and pages\",\n);\n\n// _____ ____ _ ____ _____ _____\n// / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | | | | | | | | | |__) | (___\n// | | | | | | | | | | | _ / \\___ \\\n// | |___| |__| | |___| |__| | | \\ \\ ____) |\n// \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors = theme_root.make_sub_group(\n \"colors\",\n \"Colors\",\n \"Colors used in viewports\",\n);\ncolors.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of the viewport around the page\",\n GREY[\"300\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"pageBackground\",\n \"Page Background Color\",\n \"Color of the page behind the widgets\",\n GREY[\"50\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n\n// ______ _____ _____ _______\n// | ____| __ \\_ _|__ __|\n// | |__ | | | || | | |\n// | __| | | | || | | |\n// | |____| |__| || |_ | |\n// |______|_____/_____| |_|\nconst edit = theme_root.make_sub_group(\n \"edit\",\n \"Edit\",\n \"Settings for viewports in edit mode\",\n);\nedit.make_variable(\n \"checker1\",\n \"Checkerboard First Color\",\n \"First color of the checkerboard shown behind the page in edit mode\",\n GREY[\"300\"],\n GREY[\"600\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checker2\",\n \"Checkerboard Second Color\",\n \"Second color of the checkerboard shown behind the page in edit mode\",\n GREY[\"200\"],\n GREY[\"700\"],\n \"Color\",\n undefined,\n);\nedit.make_variable(\n \"checkerSize\",\n \"Checkerboard Square Size\",\n \"Size of one square of the checkerboard shown behind the page in edit mode\",\n \"0.625rem\",\n \"0.625rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\n// _______ _____ _ _ _____ ______ ____ _____ __ __ ______ _____\n// |__ __| __ \\ /\\ | \\ | |/ ____| ____/ __ \\| __ \\| \\/ | ____| __ \\\n// | | | |__) | / \\ | \\| | (___ | |__ | | | | |__) | \\ / | |__ | |__) |\n// | | | _ / / /\\ \\ | . ` |\\___ \\| __|| | | | _ /| |\\/| | __| | _ /\n// | | | | \\ \\ / ____ \\| |\\ |____) | | | |__| | | \\ \\| | | | |____| | \\ \\\n// |_| |_| \\_\\/_/ \\_\\_| \\_|_____/|_| \\____/|_| \\_\\_| |_|______|_| \\_\\\nconst transformer = theme_root.make_sub_group(\n \"transformer\",\n \"Transformer\",\n \"Settings for the transformer used to move, resize and rotate widgets in edit mode\",\n);\ntransformer.make_variable(\n \"color\",\n \"Transformer Color\",\n \"Color of the transformer outline and handle borders\",\n BLUE[\"600\"],\n BLUE[\"300\"],\n \"Color\",\n undefined,\n);\ntransformer.make_variable(\n \"handleBackground\",\n \"Handle Background Color\",\n \"Background color of the transformer handles\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\n","import { Base, define_element } from \"#base\";\nimport \"./page.scss\";\nimport \"./shared\";\nimport type { WidgetBase } from \"./widget\";\n\n/**Page of widgets with a fixed size\n * Width and height are the size of the page in page units (px before any viewport scaling)*/\nexport class Page extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"page\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #width: number = 1920;\n #height: number = 1080;\n #widgets: readonly WidgetBase[] = [];\n\n constructor() {\n super();\n this.style.width = this.#width + \"px\";\n this.style.height = this.#height + \"px\";\n }\n\n /**Sets the width of the page */\n set width(width: number) {\n this.#width = width;\n this.style.width = width + \"px\";\n }\n /**Returns the width of the page */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the page */\n set height(height: number) {\n this.#height = height;\n this.style.height = height + \"px\";\n }\n /**Returns the height of the page */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the widgets on the page, the array order is the drawing order with the last widget on top\n * Widgets already on the page are kept in place, so they are only reconnected if their order changes */\n set widgets(widgets: readonly WidgetBase[]) {\n const keep = new Set(widgets);\n for (const widget of this.#widgets)\n if (!keep.has(widget) && widget.parentElement === this) widget.remove();\n for (let i = 0; i < widgets.length; i++) {\n const current = this.children[i];\n if (current !== widgets[i])\n this.insertBefore(widgets[i], current ?? null);\n }\n this.#widgets = widgets;\n }\n /**Returns the widgets on the page */\n get widgets(): readonly WidgetBase[] {\n return this.#widgets;\n }\n}\ndefine_element(Page);\n\nexport interface CanvasPageOptions {\n /**Width of the page in page units, defaults to 1920 */\n width?: number;\n /**Height of the page in page units, defaults to 1080 */\n height?: number;\n /**Widgets on the page, the last widget is drawn on top */\n widgets?: readonly WidgetBase[];\n}\n\n/**Creates a page of widgets with a fixed size */\nexport const canvas_page = (options?: CanvasPageOptions): Page =>\n options ? new Page().opts(options) : new Page();\n","import { Base } from \"#base\";\n\n/**Event dispatched on a widget when its position, size or rotation changes */\nexport const WIDGET_TRANSFORM_EVENT = \"widget_transform\";\n\n/**Shared class for widgets placed at a fixed position in a viewport\n * Position and size are in viewport units (px before any viewport scaling)\n * Rotation is in degrees clockwise around the center of the widget\n *\n * Width and height must always be set, they default to 0\n *\n * Widgets declare their original size, which is the size their content is laid out at\n * The content is then scaled from the original size to the width and height of the widget\n * Widgets that should not stretch, like text, return width and height as their original size\n *\n * WIDGET_TRANSFORM_EVENT is dispatched whenever position, size or rotation changes*/\nexport abstract class WidgetBase extends Base {\n /**Returns the name used to define the element, Abstract classes should return @abstract@ */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #x: number = 0;\n #y: number = 0;\n #width: number = 0;\n #height: number = 0;\n #rotation: number = 0;\n\n constructor() {\n super();\n this.style.position = \"absolute\";\n this.style.boxSizing = \"border-box\";\n this.style.transformOrigin = \"0 0\";\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n this.#update();\n }\n\n /**Returns the width the content of the widget is laid out at, return this.width to not stretch */\n abstract get original_width(): number;\n /**Returns the height the content of the widget is laid out at, return this.height to not stretch */\n abstract get original_height(): number;\n\n /**Sets the x position of the left edge of the widget */\n set x(x: number) {\n this.#x = x;\n this.#update();\n }\n /**Returns the x position of the left edge of the widget */\n get x(): number {\n return this.#x;\n }\n\n /**Sets the y position of the top edge of the widget */\n set y(y: number) {\n this.#y = y;\n this.#update();\n }\n /**Returns the y position of the top edge of the widget */\n get y(): number {\n return this.#y;\n }\n\n /**Sets the width of the widget */\n set width(width: number) {\n this.#width = width;\n this.#update();\n }\n /**Returns the width of the widget */\n get width(): number {\n return this.#width;\n }\n\n /**Sets the height of the widget */\n set height(height: number) {\n this.#height = height;\n this.#update();\n }\n /**Returns the height of the widget */\n get height(): number {\n return this.#height;\n }\n\n /**Sets the rotation of the widget in degrees, rotating clockwise around the center of the widget */\n set rotation(rotation: number) {\n this.#rotation = rotation;\n this.#update();\n }\n /**Returns the rotation of the widget in degrees */\n get rotation(): number {\n return this.#rotation;\n }\n\n #update() {\n const width = this.#width;\n const height = this.#height;\n const layout_width = this.original_width;\n const layout_height = this.original_height;\n const scale_x = layout_width > 0 ? width / layout_width : 1;\n const scale_y = layout_height > 0 ? height / layout_height : 1;\n this.style.left = this.#x + \"px\";\n this.style.top = this.#y + \"px\";\n this.style.width = layout_width + \"px\";\n this.style.height = layout_height + \"px\";\n //Scale the layout box to the widget size, then rotate around the center of the widget size\n this.style.transform = `translate(${width / 2}px, ${height / 2}px) rotate(${this.#rotation}deg) translate(${-width / 2}px, ${-height / 2}px) scale(${scale_x}, ${scale_y})`;\n this.dispatchEvent(new Event(WIDGET_TRANSFORM_EVENT));\n }\n}\n","import { Base, define_element } from \"#base\";\nimport {\n material_arrow_range_rounded,\n material_open_with_rounded,\n material_rotate_right_rounded,\n} from \"#icons\";\nimport type { SVGFunc } from \"#svg\";\nimport \"./shared\";\nimport \"./transformer.scss\";\nimport { WIDGET_TRANSFORM_EVENT, type WidgetBase } from \"./widget\";\n\n/**Smallest width and height a widget can be resized to */\nconst MIN_SIZE = 1;\n/**Grid positions and sizes snap to, and the finer grid used while alt is held */\nconst SNAP_GRID = 5;\nconst SNAP_GRID_FINE = 1;\n/**Angle in degrees rotation snaps to, and the finer angle used while alt is held */\nconst SNAP_ANGLE = 15;\nconst SNAP_ANGLE_FINE = 5;\n\n/**Rounds the value to the nearest multiple of step, a step of 0 returns the value unchanged\n * Steps below 1 divide by the inverse, so steps like 0.1 do not give floating point errors like 0.30000000000000004 */\nfunction snap(value: number, step: number): number {\n if (step <= 0) return value;\n return step < 1\n ? Math.round(value / step) / Math.round(1 / step)\n : Math.round(value / step) * step;\n}\n\n/**Resize handles, x and y is the edge they move, -1 is the left or top edge, 1 the right or bottom edge, 0 none */\nconst RESIZE_HANDLES = [\n { name: \"nw\", x: -1, y: -1 },\n { name: \"n\", x: 0, y: -1 },\n { name: \"ne\", x: 1, y: -1 },\n { name: \"e\", x: 1, y: 0 },\n { name: \"se\", x: 1, y: 1 },\n { name: \"s\", x: 0, y: 1 },\n { name: \"sw\", x: -1, y: 1 },\n { name: \"w\", x: -1, y: 0 },\n];\n\ntype Action =\n | { type: \"move\" }\n | { type: \"resize\"; x: number; y: number }\n | { type: \"rotate\" };\n\n/**State of the widget and pointer when a drag started */\ninterface Drag {\n action: Action;\n pointer_id: number;\n client_x: number;\n client_y: number;\n /**Center of the widget in client coordinates, used for rotation */\n center_x: number;\n center_y: number;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n}\n\n/**Dashed outline with handles, attached to a widget to move, resize and rotate it\n * Corner handles resize both axes and side handles one axis, keeping the opposite corner or side in place\n * The handle above the outline rotates the widget around its center\n * The center handle and the outline itself move the widget, the inside of the outline is left to the widgets below\n *\n * Position and size snap to a 5px grid and rotation to 15 degrees\n * Holding alt snaps to a 1px grid and 5 degrees instead, holding shift disables snapping\n *\n * Resize and rotate cursors follow the rotation of the widget in 45 degree steps\n *\n * The transformer is drawn in viewport pixels, so it keeps its size when the page is zoomed*/\nexport class Transformer extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"transformer\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #widget: WidgetBase | undefined;\n #offset_x: number = 0;\n #offset_y: number = 0;\n #scale: number = 1;\n #actions = new Map<Element, Action>();\n #drag: Drag | undefined;\n\n constructor() {\n super();\n this.hidden = true;\n for (const side of [\"top\", \"right\", \"bottom\", \"left\"])\n this.#add(\"side \" + side, { type: \"move\" });\n this.#add(\"line\", undefined);\n for (const handle of RESIZE_HANDLES)\n this.#add(\n \"handle \" + handle.name,\n { type: \"resize\", x: handle.x, y: handle.y },\n material_arrow_range_rounded,\n );\n this.#add(\"handle rotate\", { type: \"rotate\" }, material_rotate_right_rounded);\n //Added last so it is drawn on top of the other handles on small widgets\n this.#add(\"handle move\", { type: \"move\" }, material_open_with_rounded);\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#stop_drag();\n }\n\n /**Sets the widget the transformer is attached to, undefined hides the transformer */\n set widget(widget: WidgetBase | undefined) {\n if (this.#widget === widget) return;\n this.#stop_drag();\n this.#widget?.removeEventListener(\n WIDGET_TRANSFORM_EVENT,\n this.#on_widget_transform,\n );\n this.#widget = widget;\n widget?.addEventListener(WIDGET_TRANSFORM_EVENT, this.#on_widget_transform);\n this.#update();\n }\n /**Returns the widget the transformer is attached to */\n get widget(): WidgetBase | undefined {\n return this.#widget;\n }\n\n /**Returns whether a handle is being dragged */\n get dragging(): boolean {\n return this.#drag !== undefined;\n }\n\n /**Sets how page units map to viewport pixels, viewport = offset + page * scale */\n view(offset_x: number, offset_y: number, scale: number) {\n this.#offset_x = offset_x;\n this.#offset_y = offset_y;\n this.#scale = scale;\n this.#update();\n }\n\n #add(class_name: string, action: Action | undefined, icon?: SVGFunc) {\n const element = this.appendChild(document.createElement(\"div\"));\n element.className = class_name;\n if (icon) element.appendChild(icon());\n if (action) this.#actions.set(element, action);\n }\n\n #update() {\n const widget = this.#widget;\n this.hidden = !widget;\n if (!widget) return;\n const scale = this.#scale;\n this.style.left = this.#offset_x + widget.x * scale + \"px\";\n this.style.top = this.#offset_y + widget.y * scale + \"px\";\n this.style.width = widget.width * scale + \"px\";\n this.style.height = widget.height * scale + \"px\";\n this.style.transform = `rotate(${widget.rotation}deg)`;\n //Cursors only exist in 45 degree steps repeating every 180 degrees, the stylesheet picks the cursors from the closest step\n const half_turn = ((widget.rotation % 180) + 180) % 180;\n this.setAttribute(\"cursor-step\", String(Math.round(half_turn / 45) % 4));\n }\n\n #start(action: Action, e: PointerEvent) {\n const widget = this.#widget;\n if (!widget || this.#drag) return;\n e.preventDefault();\n e.stopPropagation();\n //The bounding box of the rotated outline is centered on the widget center\n const rect = this.getBoundingClientRect();\n this.#drag = {\n action,\n pointer_id: e.pointerId,\n client_x: e.clientX,\n client_y: e.clientY,\n center_x: rect.left + rect.width / 2,\n center_y: rect.top + rect.height / 2,\n x: widget.x,\n y: widget.y,\n width: widget.width,\n height: widget.height,\n rotation: widget.rotation,\n };\n window.addEventListener(\"pointermove\", this.#on_pointer_move);\n window.addEventListener(\"pointerup\", this.#on_pointer_up);\n window.addEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #stop_drag() {\n if (!this.#drag) return;\n this.#drag = undefined;\n window.removeEventListener(\"pointermove\", this.#on_pointer_move);\n window.removeEventListener(\"pointerup\", this.#on_pointer_up);\n window.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n }\n\n #on_widget_transform = () => {\n this.#update();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n const action =\n e.target instanceof Element ? this.#actions.get(e.target) : undefined;\n //Other buttons are left to the viewport, so middle mouse still pans\n if (!action || e.button !== 0) return;\n this.#start(action, e);\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n const drag = this.#drag;\n const widget = this.#widget;\n if (!drag || !widget || e.pointerId !== drag.pointer_id) return;\n //Pointer movement in page units\n const delta_x = (e.clientX - drag.client_x) / this.#scale;\n const delta_y = (e.clientY - drag.client_y) / this.#scale;\n const grid = e.shiftKey ? 0 : e.altKey ? SNAP_GRID_FINE : SNAP_GRID;\n const action = drag.action;\n switch (action.type) {\n case \"move\":\n widget.x = snap(drag.x + delta_x, grid);\n widget.y = snap(drag.y + delta_y, grid);\n break;\n case \"resize\": {\n const radians = (drag.rotation * Math.PI) / 180;\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n //Pointer movement in the unrotated frame of the widget\n const local_x = delta_x * cos + delta_y * sin;\n const local_y = delta_y * cos - delta_x * sin;\n const width = action.x\n ? Math.max(MIN_SIZE, snap(drag.width + action.x * local_x, grid))\n : drag.width;\n const height = action.y\n ? Math.max(MIN_SIZE, snap(drag.height + action.y * local_y, grid))\n : drag.height;\n //Move the center by half the size change, so the opposite corner or side stays in place\n const shift_x = (action.x * (width - drag.width)) / 2;\n const shift_y = (action.y * (height - drag.height)) / 2;\n const center_x = drag.x + drag.width / 2 + shift_x * cos - shift_y * sin;\n const center_y = drag.y + drag.height / 2 + shift_x * sin + shift_y * cos;\n widget.x = center_x - width / 2;\n widget.y = center_y - height / 2;\n widget.width = width;\n widget.height = height;\n break;\n }\n case \"rotate\": {\n const start = Math.atan2(\n drag.client_y - drag.center_y,\n drag.client_x - drag.center_x,\n );\n const now = Math.atan2(\n e.clientY - drag.center_y,\n e.clientX - drag.center_x,\n );\n const rotation = snap(\n drag.rotation + ((now - start) * 180) / Math.PI,\n e.shiftKey ? 0 : e.altKey ? SNAP_ANGLE_FINE : SNAP_ANGLE,\n );\n widget.rotation = ((rotation % 360) + 360) % 360;\n break;\n }\n }\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n if (e.pointerId === this.#drag?.pointer_id) this.#stop_drag();\n };\n}\ndefine_element(Transformer);\n","import { Base, define_element } from \"#base\";\nimport type { Page } from \"./page\";\nimport \"./shared\";\nimport { Transformer } from \"./transformer\";\nimport \"./viewport.scss\";\nimport type { WidgetBase } from \"./widget\";\n\nconst ZOOM_MIN = 0.1;\nconst ZOOM_MAX = 20;\n/**Zoom factor per wheel pixel */\nconst WHEEL_ZOOM_SPEED = 0.002;\n/**Zoom factor per wheel pixel for touchpad pinch, which reports much smaller deltas than a mouse wheel */\nconst PINCH_ZOOM_SPEED = 0.01;\n/**Screen pixels panned per wheel pixel */\nconst WHEEL_PAN_SPEED = 0.5;\n/**Pixels per line, for wheel events reported in lines */\nconst WHEEL_LINE_HEIGHT = 16;\n/**Speed multiplier for wheel zoom and pan while alt is held */\nconst WHEEL_SLOW = 0.1;\n\n/**Viewport showing a page of widgets\n * The page is scaled to fit inside the viewport element while keeping its aspect ratio, and centered\n *\n * When edit is true the page can be zoomed and panned, and a checkerboard is shown behind it\n * Wheel and touchpad two finger swipe pans, ctrl + wheel or swipe zooms toward the cursor\n * Shift + vertical wheel pans horizontally\n * Touchpad pinch zooms toward the cursor\n * Holding alt makes wheel zoom and pan 10 times slower\n * Two finger touch pinch zooms and pans, middle or right mouse drag pans\n *\n * Pressing a widget in edit mode selects it and attaches a transformer to move, resize and rotate it\n * Pressing outside any widget clears the selection*/\nexport class Viewport extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"viewport\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"canvas\";\n }\n\n #background: HTMLDivElement = this.appendChild(\n document.createElement(\"div\"),\n );\n #container: HTMLDivElement = this.appendChild(document.createElement(\"div\"));\n #transformer: Transformer = this.appendChild(new Transformer());\n #page: Page | undefined;\n #page_observer = new ResizeObserver(() => {\n this.#update_view();\n });\n #scale: number = 1;\n #fit_x: number = 0;\n #fit_y: number = 0;\n #edit: boolean = false;\n #zoom: number = 1;\n #pan_x: number = 0;\n #pan_y: number = 0;\n #touches = new Map<number, { x: number; y: number }>();\n #pan_pointer_id: number | undefined;\n #pan_pointer_last = { x: 0, y: 0 };\n /**Whether the ctrl key is physically held, to tell touchpad pinch from ctrl + wheel */\n #ctrl_held: boolean = false;\n\n constructor() {\n super();\n this.#background.className = \"checkerboard\";\n this.#container.className = \"container\";\n this.attach_to_resize_observer();\n }\n\n /**Sets the page shown in the viewport */\n set page(page: Page | undefined) {\n if (this.#page === page) return;\n this.selected = undefined;\n if (this.#page) {\n this.#page_observer.unobserve(this.#page);\n if (this.#page.parentElement === this.#container) this.#page.remove();\n }\n this.#page = page;\n if (page) {\n this.#container.appendChild(page);\n this.#page_observer.observe(page);\n }\n this.#update_view();\n }\n /**Returns the page shown in the viewport */\n get page(): Page | undefined {\n return this.#page;\n }\n\n /**Sets edit mode, which enables zooming and panning and shows a checkerboard background\n * Leaving edit mode resets the view to fit the page */\n set edit(edit: boolean) {\n if (this.#edit === edit) return;\n this.#edit = edit;\n this.toggleAttribute(\"edit\", edit);\n this.#listen_keys(edit && this.isConnected);\n if (edit) {\n this.addEventListener(\"wheel\", this.#on_wheel, { passive: false });\n this.addEventListener(\"pointerdown\", this.#on_pointer_down);\n this.addEventListener(\"pointermove\", this.#on_pointer_move);\n this.addEventListener(\"pointerup\", this.#on_pointer_up);\n this.addEventListener(\"pointercancel\", this.#on_pointer_up);\n this.addEventListener(\"mousedown\", this.#on_mouse_down);\n this.addEventListener(\"contextmenu\", this.#on_context_menu);\n } else {\n this.removeEventListener(\"wheel\", this.#on_wheel);\n this.removeEventListener(\"pointerdown\", this.#on_pointer_down);\n this.removeEventListener(\"pointermove\", this.#on_pointer_move);\n this.removeEventListener(\"pointerup\", this.#on_pointer_up);\n this.removeEventListener(\"pointercancel\", this.#on_pointer_up);\n this.removeEventListener(\"mousedown\", this.#on_mouse_down);\n this.removeEventListener(\"contextmenu\", this.#on_context_menu);\n this.#touches.clear();\n this.#pan_pointer_id = undefined;\n this.selected = undefined;\n this.#zoom = 1;\n this.#pan_x = 0;\n this.#pan_y = 0;\n this.#update_view();\n }\n }\n /**Returns whether edit mode is enabled */\n get edit(): boolean {\n return this.#edit;\n }\n\n /**Sets the selected widget, which the transformer is attached to, selection is cleared when leaving edit mode */\n set selected(widget: WidgetBase | undefined) {\n this.#transformer.widget = widget;\n }\n /**Returns the selected widget */\n get selected(): WidgetBase | undefined {\n return this.#transformer.widget;\n }\n\n /**Returns the current scale from page units to screen pixels */\n get scale(): number {\n return this.#scale;\n }\n\n protected on_resize(): void {\n this.#update_view();\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n if (this.#edit) this.#listen_keys(true);\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#listen_keys(false);\n }\n\n /**Adds or removes the window listeners tracking the ctrl key */\n #listen_keys(listen: boolean) {\n if (listen) {\n window.addEventListener(\"keydown\", this.#on_key);\n window.addEventListener(\"keyup\", this.#on_key);\n window.addEventListener(\"blur\", this.#on_blur);\n } else {\n window.removeEventListener(\"keydown\", this.#on_key);\n window.removeEventListener(\"keyup\", this.#on_key);\n window.removeEventListener(\"blur\", this.#on_blur);\n this.#ctrl_held = false;\n }\n }\n\n #update_view() {\n if (!this.#page) return;\n const width = this.#page.width;\n const height = this.#page.height;\n if (width <= 0 || height <= 0) return;\n const rect = this.actual_size;\n const fit = Math.min(rect.width / width, rect.height / height);\n this.#fit_x = (rect.width - width * fit) / 2;\n this.#fit_y = (rect.height - height * fit) / 2;\n this.#scale = fit * this.#zoom;\n this.#container.style.transform = `translate(${this.#fit_x + this.#pan_x}px, ${this.#fit_y + this.#pan_y}px) scale(${this.#scale})`;\n this.#transformer.view(\n this.#fit_x + this.#pan_x,\n this.#fit_y + this.#pan_y,\n this.#scale,\n );\n }\n\n /**Zooms by the factor, keeping the given point in viewport coordinates in place */\n #zoom_at(x: number, y: number, factor: number) {\n const zoom = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, this.#zoom * factor));\n const ratio = zoom / this.#zoom;\n this.#pan_x += (x - this.#fit_x - this.#pan_x) * (1 - ratio);\n this.#pan_y += (y - this.#fit_y - this.#pan_y) * (1 - ratio);\n this.#zoom = zoom;\n }\n\n /**Returns the position of the event in viewport coordinates */\n #local(e: MouseEvent): { x: number; y: number } {\n const rect = this.getBoundingClientRect();\n return { x: e.clientX - rect.left, y: e.clientY - rect.top };\n }\n\n /**Selects the widget under the pointer, or clears the selection if there is none */\n #select_at(e: PointerEvent) {\n const page = this.#page;\n let element = e.target instanceof Element ? e.target : null;\n while (element && element.parentElement !== page)\n element = element.parentElement;\n this.selected = page?.widgets.find((widget) => widget === element);\n }\n\n /**Returns center and distance of the first two touches */\n #pinch(): { x: number; y: number; distance: number } | undefined {\n if (this.#touches.size < 2) return undefined;\n const [a, b] = this.#touches.values();\n return {\n x: (a.x + b.x) / 2,\n y: (a.y + b.y) / 2,\n distance: Math.hypot(a.x - b.x, a.y - b.y),\n };\n }\n\n #on_wheel = (e: WheelEvent) => {\n e.preventDefault();\n const unit =\n e.deltaMode === WheelEvent.DOM_DELTA_LINE\n ? WHEEL_LINE_HEIGHT\n : e.deltaMode === WheelEvent.DOM_DELTA_PAGE\n ? this.actual_size.height\n : 1;\n const delta_x = e.deltaX * unit;\n const delta_y = e.deltaY * unit;\n const speed = e.altKey ? WHEEL_SLOW : 1;\n if (e.ctrlKey) {\n //Browsers report touchpad pinch as ctrl + wheel, without the ctrl key being held\n const zoom_speed = this.#ctrl_held ? WHEEL_ZOOM_SPEED : PINCH_ZOOM_SPEED;\n const point = this.#local(e);\n this.#zoom_at(point.x, point.y, Math.exp(-delta_y * zoom_speed * speed));\n } else {\n //Shift makes the vertical wheel pan horizontally, some browsers already swap the deltas themselves\n const swap = e.shiftKey && delta_x === 0;\n this.#pan_x -= (swap ? delta_y : delta_x) * speed * WHEEL_PAN_SPEED;\n this.#pan_y -= (swap ? 0 : delta_y) * speed * WHEEL_PAN_SPEED;\n }\n this.#update_view();\n };\n\n #on_pointer_down = (e: PointerEvent) => {\n if (e.pointerType === \"touch\") {\n //Only the first touch selects, so a second finger can pinch without changing the selection\n if (this.#touches.size === 0 && !this.#transformer.dragging)\n this.#select_at(e);\n this.#touches.set(e.pointerId, this.#local(e));\n this.setPointerCapture(e.pointerId);\n } else if (e.button === 0) {\n this.#select_at(e);\n } else if (e.button === 1 || e.button === 2) {\n e.preventDefault();\n this.#pan_pointer_id = e.pointerId;\n this.#pan_pointer_last = this.#local(e);\n this.setPointerCapture(e.pointerId);\n }\n };\n\n #on_pointer_move = (e: PointerEvent) => {\n this.#ctrl_held = e.ctrlKey;\n if (this.#touches.has(e.pointerId)) {\n const before = this.#pinch();\n this.#touches.set(e.pointerId, this.#local(e));\n const after = this.#pinch();\n if (!before || !after || before.distance <= 0) return;\n this.#pan_x += after.x - before.x;\n this.#pan_y += after.y - before.y;\n this.#zoom_at(after.x, after.y, after.distance / before.distance);\n this.#update_view();\n } else if (e.pointerId === this.#pan_pointer_id) {\n const point = this.#local(e);\n this.#pan_x += point.x - this.#pan_pointer_last.x;\n this.#pan_y += point.y - this.#pan_pointer_last.y;\n this.#pan_pointer_last = point;\n this.#update_view();\n }\n };\n\n #on_pointer_up = (e: PointerEvent) => {\n this.#touches.delete(e.pointerId);\n if (e.pointerId === this.#pan_pointer_id) this.#pan_pointer_id = undefined;\n };\n\n /**Prevents the browser autoscroll on middle mouse button */\n #on_mouse_down = (e: MouseEvent) => {\n if (e.button === 1) e.preventDefault();\n };\n\n /**Prevents the context menu, as the right mouse button pans in edit mode */\n #on_context_menu = (e: MouseEvent) => {\n e.preventDefault();\n };\n\n #on_key = (e: KeyboardEvent) => {\n this.#ctrl_held = e.ctrlKey;\n };\n\n #on_blur = () => {\n this.#ctrl_held = false;\n };\n}\ndefine_element(Viewport);\n\nexport interface CanvasViewportOptions {\n /**Page shown in the viewport */\n page?: Page;\n /**Enables zooming, panning and selecting widgets */\n edit?: boolean;\n}\n\n/**Creates a viewport showing a page of widgets */\nexport const canvas_viewport = (options?: CanvasViewportOptions): Viewport =>\n options ? new Viewport().opts(options) : new Viewport();\n","import { canvas_page, Page, type CanvasPageOptions } from \"./page\";\nimport {\n canvas_viewport,\n Viewport,\n type CanvasViewportOptions,\n} from \"./viewport\";\nimport { WIDGET_TRANSFORM_EVENT } from \"./widget\";\n\n/**Displaying and editing graphics with a fixed position and size */\nexport const canvas = {\n page: canvas_page,\n viewport: canvas_viewport,\n WIDGET_TRANSFORM_EVENT,\n};\nexport default canvas;\n\nexport type { CanvasPageOptions, CanvasViewportOptions, Page, Viewport };\n\nexport { WIDGET_TRANSFORM_EVENT, WidgetBase } from \"./widget\";\n"],"mappings":";;;;;;AAGA,MAAM,aAAa,yBACjB,UACA,UACA,gDACF;AAQA,MAAM,SAAS,WAAW,eACxB,UACA,UACA,0BACF;AACA,OAAO,cACL,cACA,oBACA,yCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,OAAO,cACL,kBACA,yBACA,wCACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AAQA,MAAM,OAAO,WAAW,eACtB,QACA,QACA,qCACF;AACA,KAAK,cACH,YACA,4BACA,sEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,YACA,6BACA,uEACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,KAAK,cACH,eACA,4BACA,6EACA,YACA,YACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAQA,MAAM,cAAc,WAAW,eAC7B,eACA,eACA,mFACF;AACA,YAAY,cACV,SACA,qBACA,uDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,oBACA,2BACA,+CACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;;;;ACnGA,IAAa,OAAb,cAA0B,KAAK;;CAE7B,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;CAEA,SAAiB;CACjB,UAAkB;CAClB,WAAkC,CAAC;CAEnC,cAAc;EACZ,MAAM;EACN,KAAK,MAAM,QAAQ,KAAK,SAAS;EACjC,KAAK,MAAM,SAAS,KAAK,UAAU;CACrC;;CAGA,IAAI,MAAM,OAAe;EACvB,KAAK,SAAS;EACd,KAAK,MAAM,QAAQ,QAAQ;CAC7B;;CAEA,IAAI,QAAg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AAa,mBAAmB,YAC9B,UAAU,IAAI,SAAS,CAAC,CAAC,KAAK,OAAO,IAAI,IAAI,SAAS;;;ACtTxD,MAAa,SAAS;CACpB,MAAM;CACN,UAAU;CACV;AACF"}
@@ -1,3 +1,3 @@
1
1
  import '../style.css';
2
- import { n as ContextMenu, r as ContextMenuLines, t as ctm } from "../index-CB3-qP6l.mjs";
2
+ import { n as ContextMenu, r as ContextMenuLines, t as ctm } from "../index-DhRb2iA8.mjs";
3
3
  export { type ContextMenu, type ContextMenuLines, ctm, ctm as default };
@@ -1,2 +1,2 @@
1
1
  import "../style.css";
2
- export { t as ctm, t as default } from "../context-menu-CiNcuP-a.mjs";
2
+ export { t as ctm, t as default } from "../context-menu-Cz9rqUaM.mjs";
@@ -1,8 +1,8 @@
1
1
  import "./style.css";
2
2
  import { Base, define_element } from "./base/index.mjs";
3
- import { r as theme_init_variable_root } from "./theme-9ib89_3b.mjs";
3
+ import { i as theme_init_variable_root } from "./theme-CFeGnUuF.mjs";
4
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";
5
+ import { Fm as material_chevron_right_rounded, xh as material_close_rounded } from "./icons-e2J_Ojic.mjs";
6
6
  import { Spinner } from "./spinner/index.mjs";
7
7
  import { BLUE, GREY } from "@chocbite/ts-lib/colors";
8
8
  // src/context-menu/shared.ts
@@ -22,14 +22,22 @@ var MenuLine = class extends Base {
22
22
  static element_name_space() {
23
23
  return "contextmenu";
24
24
  }
25
- /**Changes focus to the next line
25
+ /**True for lines that can not take focus, like dividers, focus moves past them*/
26
+ get skips_focus() {
27
+ return false;
28
+ }
29
+ /**Changes focus to the next line, wrapping around and skipping lines that can not take focus
26
30
  * @param direction false is next sibling, true is previous */
27
31
  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();
32
+ const parent = this.parentElement;
33
+ if (!parent) return;
34
+ let line = direction ? this.previousElementSibling : this.nextElementSibling;
35
+ for (;;) {
36
+ line ??= direction ? parent.lastElementChild : parent.firstElementChild;
37
+ if (!line || line === this) return;
38
+ if (!line.skips_focus) return line.do_focus(direction);
39
+ line = direction ? line.previousElementSibling : line.nextElementSibling;
40
+ }
33
41
  }
34
42
  };
35
43
  // src/context-menu/devider.ts
@@ -38,6 +46,9 @@ var Devider = class extends MenuLine {
38
46
  static element_name() {
39
47
  return "devider";
40
48
  }
49
+ get skips_focus() {
50
+ return true;
51
+ }
41
52
  do_focus(dir) {
42
53
  this.focus_next(dir);
43
54
  }
@@ -49,6 +60,7 @@ function context_devider() {
49
60
  // src/context-menu/container.ts
50
61
  var Container = class extends Base {
51
62
  #active_element_buffer;
63
+ #replacing = false;
52
64
  /**Returns the name used to define the element */
53
65
  static element_name() {
54
66
  return "container";
@@ -78,12 +90,19 @@ var Container = class extends Base {
78
90
  /**Attaches a menu to the container */
79
91
  attach_menu(menu) {
80
92
  menu.container = this;
81
- this.#active_element_buffer = this.ownerDocument.activeElement;
93
+ const old = this.firstElementChild;
94
+ if (old) {
95
+ this.#replacing = true;
96
+ old.close_down();
97
+ old.close_up();
98
+ this.#replacing = false;
99
+ } else this.#active_element_buffer = this.ownerDocument.activeElement;
82
100
  this.replaceChildren(menu);
83
101
  return menu;
84
102
  }
85
103
  /**Closes open context menu */
86
104
  close_up() {
105
+ if (this.#replacing) return;
87
106
  if (this.#active_element_buffer) {
88
107
  this.#active_element_buffer.focus();
89
108
  if (this.ownerDocument.activeElement !== this.#active_element_buffer) this.focus();
@@ -94,8 +113,10 @@ var Container = class extends Base {
94
113
  define_element(Container);
95
114
  // src/context-menu/engine.ts
96
115
  const CONTEXT_MENY_SYMBOL = Symbol("context_menu");
97
- /**Reference to document handler*/
116
+ /**Default context menu, false blocks the operating system context menu, undefined leaves it*/
98
117
  let default_menu;
118
+ /**Blocks the operating system context menu when the default is false*/
119
+ const block_os_menu = (e) => e.preventDefault();
99
120
  DOCUMENT_HANDLER.events.on("added", (e) => {
100
121
  apply_to_doc(e.data);
101
122
  });
@@ -106,7 +127,15 @@ function apply_to_doc(doc) {
106
127
  const container = new Container();
107
128
  doc[CONTEXT_MENY_SYMBOL] = container;
108
129
  doc.documentElement.appendChild(container);
109
- if (default_menu) context_menu_attach(doc.documentElement, default_menu);
130
+ apply_default_to_doc(doc);
131
+ }
132
+ /**Applies the current default context menu to a document*/
133
+ function apply_default_to_doc(doc) {
134
+ const root = doc.documentElement;
135
+ context_menu_detach(root);
136
+ root.removeEventListener("contextmenu", block_os_menu);
137
+ if (default_menu) context_menu_attach(root, default_menu);
138
+ else if (default_menu === false) root.addEventListener("contextmenu", block_os_menu);
110
139
  }
111
140
  /**Attaches a context menu to the given element
112
141
  * @param element the element to attach the context menu to
@@ -155,18 +184,11 @@ function context_menu_summon(menu, element, x, y, dont_cover) {
155
184
  } else console.error("No context menu container available");
156
185
  }
157
186
  /**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
187
+ * If set to false the operating system context menu is disabled and nothing will appear
159
188
  * If set undefined the operating systems context menu will be used*/
160
189
  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
- }
190
+ default_menu = lines;
191
+ DOCUMENT_HANDLER.for_documents(apply_default_to_doc);
170
192
  }
171
193
  // src/context-menu/buffer.ts
172
194
  var Buffer = class extends MenuLine {
@@ -178,6 +200,9 @@ var Buffer = class extends MenuLine {
178
200
  super();
179
201
  this.appendChild(new Spinner());
180
202
  }
203
+ get skips_focus() {
204
+ return true;
205
+ }
181
206
  do_focus(dir) {
182
207
  this.focus_next(dir);
183
208
  }
@@ -198,18 +223,18 @@ var MenuOption = class extends MenuLine {
198
223
  icon_box.className = "icon";
199
224
  if (icon) icon_box.appendChild(icon);
200
225
  const text_box = this.appendChild(document.createElement("div"));
201
- text_box.innerHTML = text;
226
+ text_box.textContent = text;
202
227
  text_box.className = "text";
203
228
  const shortcut_box = this.appendChild(document.createElement("div"));
204
- if (shortcut) shortcut_box.innerHTML = shortcut;
229
+ if (shortcut) shortcut_box.textContent = shortcut;
205
230
  shortcut_box.className = "shortcut";
206
231
  const check_mark_box = this.appendChild(document.createElement("div"));
207
- if (checkmark) check_mark_box.innerHTML = "✓";
232
+ if (checkmark) check_mark_box.textContent = "✓";
208
233
  check_mark_box.className = "checkmark";
209
234
  this.onclick = (e) => {
210
235
  e.stopPropagation();
211
236
  this.func();
212
- navigator?.vibrate(25);
237
+ navigator.vibrate?.(25);
213
238
  this.parentElement.close_up();
214
239
  };
215
240
  this.onkeydown = (e) => {
@@ -257,7 +282,7 @@ var MenuSub = class extends MenuLine {
257
282
  icon_box.className = "icon";
258
283
  if (icon) icon_box.appendChild(icon);
259
284
  const text_box = this.appendChild(document.createElement("div"));
260
- text_box.innerHTML = text;
285
+ text_box.textContent = text;
261
286
  text_box.className = "text";
262
287
  const shortcut_box = this.appendChild(document.createElement("div"));
263
288
  shortcut_box.className = "shortcut";
@@ -267,7 +292,7 @@ var MenuSub = class extends MenuLine {
267
292
  this.onclick = (e) => {
268
293
  e.stopPropagation();
269
294
  if (!this.#block_time) {
270
- navigator?.vibrate(25);
295
+ navigator.vibrate?.(25);
271
296
  if (this.#is_open) this.close_down();
272
297
  else this.open();
273
298
  }
@@ -353,6 +378,8 @@ var ContextMenu = class extends Base {
353
378
  #x;
354
379
  #y;
355
380
  #element;
381
+ /**Spinner shown while promised lines load, cleared when the menu closes*/
382
+ #loading;
356
383
  #focus_out_handler = (e) => {
357
384
  e.preventDefault();
358
385
  e.stopPropagation();
@@ -388,19 +415,27 @@ var ContextMenu = class extends Base {
388
415
  connectedCallback() {
389
416
  super.connectedCallback();
390
417
  const lines = typeof this.#lines === "function" ? this.#lines() : this.#lines;
418
+ this.#loading?.remove();
391
419
  if (lines instanceof Promise) {
392
- const buffer = this.appendChild(new Buffer());
420
+ const buffer = this.#loading = this.appendChild(new Buffer());
393
421
  lines.then((line) => {
422
+ if (this.#loading !== buffer) return;
423
+ this.#loading = void 0;
394
424
  buffer.remove();
395
425
  this.lines = line;
396
426
  this.set_position(this.#x, this.#y, this.#element);
397
427
  });
398
- } else this.lines = lines;
428
+ } else {
429
+ this.#loading = void 0;
430
+ this.lines = lines;
431
+ }
399
432
  this.addEventListener("focusout", this.#focus_out_handler, { capture: true });
400
433
  this.ownerDocument.defaultView?.addEventListener("resize", this.#window_resize_handler, { passive: true });
401
434
  }
402
435
  disconnectedCallback() {
403
436
  super.disconnectedCallback();
437
+ this.#loading?.remove();
438
+ this.#loading = void 0;
404
439
  this.ownerDocument.defaultView?.removeEventListener("resize", this.#window_resize_handler);
405
440
  }
406
441
  /**Sets the lines of the context menu */
@@ -415,8 +450,8 @@ var ContextMenu = class extends Base {
415
450
  /**Changes focus to the next line
416
451
  * @param direction false is first child, true is last child */
417
452
  focus_next(direction) {
418
- if (direction) this.lastChild?.do_focus();
419
- else this.firstChild?.do_focus(true);
453
+ if (direction) this.lastChild?.do_focus(true);
454
+ else this.firstChild?.do_focus(false);
420
455
  }
421
456
  set closer(closer) {
422
457
  if (closer && !this.#closer) {
@@ -478,12 +513,11 @@ var ContextMenu = class extends Base {
478
513
  x = sub_box.x;
479
514
  if (box.width < x) right = window.innerWidth - x;
480
515
  else right = window.innerWidth - (sub_box.x + sub_box.width);
481
- } else x = sub_box.x + sub_box.width;
516
+ } else left = sub_box.x + sub_box.width;
482
517
  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;
518
+ if (y + box.height < window.innerHeight) top = y;
519
+ else if (sub_box.y >= box.height) bottom = window.innerHeight - sub_box.y;
520
+ else top = Math.max(0, window.innerHeight - box.height);
487
521
  } else {
488
522
  if (y + box.height >= window.innerHeight) {
489
523
  if (y >= box.height) bottom = window.innerHeight - y;
@@ -524,4 +558,4 @@ const ctm = {
524
558
  };
525
559
  export { ctm as t };
526
560
 
527
- //# sourceMappingURL=context-menu-CiNcuP-a.mjs.map
561
+ //# sourceMappingURL=context-menu-Cz9rqUaM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-menu-Cz9rqUaM.mjs","names":[],"sources":["../src/context-menu/shared.ts","../src/context-menu/line.ts","../src/context-menu/devider.ts","../src/context-menu/container.ts","../src/context-menu/engine.ts","../src/context-menu/buffer.ts","../src/context-menu/option.ts","../src/context-menu/submenu.ts","../src/context-menu/menu.ts","../src/context-menu/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst variables = theme_init_variable_root(\n \"contextmenu\",\n \"Context Menu\",\n \"Right click or touch and hold context menu appearance\",\n);\nvariables.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of background\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"text\",\n \"Text Color\",\n \"Color of text\",\n GREY[\"600\"],\n GREY[\"400\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hover\",\n \"Hover Color\",\n \"Background color of line when hovering over it\",\n BLUE[\"200\"],\n BLUE[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hoverText\",\n \"Text Color\",\n \"Standard text color\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"border\",\n \"Border Color\",\n \"Color of border and deviders\",\n GREY[\"300\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n","import { Base } from \"#base\";\nimport \"./option.scss\";\nimport \"./shared\";\n\nexport interface ContextMenuLine {}\n\nexport abstract class MenuLine extends Base implements ContextMenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n abstract do_focus(dir?: boolean): void;\n\n /**True for lines that can not take focus, like dividers, focus moves past them*/\n get skips_focus() {\n return false;\n }\n\n /**Changes focus to the next line, wrapping around and skipping lines that can not take focus\n * @param direction false is next sibling, true is previous */\n focus_next(direction?: boolean) {\n const parent = this.parentElement;\n if (!parent) return;\n let line = direction\n ? this.previousElementSibling\n : this.nextElementSibling;\n for (;;) {\n line ??= direction ? parent.lastElementChild : parent.firstElementChild;\n //Back at the start, there is no other line to focus\n if (!line || line === this) return;\n if (!(line as MenuLine).skips_focus)\n return (line as MenuLine).do_focus(direction);\n line = direction ? line.previousElementSibling : line.nextElementSibling;\n }\n }\n}\n","import { define_element } from \"#base\";\nimport \"./devider.scss\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\n\nexport interface ContextMenuDevider extends ContextMenuLine {}\n\nexport class Devider extends MenuLine implements ContextMenuDevider {\n /**Returns the name used to define the element */\n static element_name() {\n return \"devider\";\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir?: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Devider);\n\nexport function context_devider(): ContextMenuDevider {\n return new Devider();\n}\n","import { Base, define_element } from \"#base\";\nimport \"./container.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport class Container extends Base {\n #active_element_buffer: HTMLOrSVGElement | null | undefined;\n #replacing = false;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"container\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n constructor() {\n super();\n this.tabIndex = -1;\n const preventer = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n };\n this.oncontextmenu = preventer;\n this.onpointerdown = preventer;\n this.onpointerup = preventer;\n this.onpointercancel = preventer;\n this.onpointerenter = preventer;\n this.onpointerleave = preventer;\n this.onpointermove = preventer;\n this.onpointerout = preventer;\n this.onpointerout = preventer;\n this.onclick = preventer;\n }\n\n /**Attaches a menu to the container */\n attach_menu(menu: ContextMenu) {\n menu.container = this;\n const old = this.firstElementChild as ContextMenu | null;\n if (old) {\n //Closed before replacing, the browser closes it from a focusout while it is being removed otherwise,\n //focus still returns to the element from before the old menu\n this.#replacing = true;\n old.close_down();\n old.close_up();\n this.#replacing = false;\n } else\n this.#active_element_buffer = this.ownerDocument\n .activeElement as HTMLOrSVGElement | null;\n this.replaceChildren(menu);\n return menu;\n }\n\n /**Closes open context menu */\n close_up() {\n if (this.#replacing) return;\n if (this.#active_element_buffer) {\n this.#active_element_buffer.focus();\n if (\n (this.ownerDocument.activeElement as any) !==\n this.#active_element_buffer\n ) {\n this.focus();\n }\n this.#active_element_buffer = undefined;\n } else {\n this.focus();\n }\n }\n}\ndefine_element(Container);\n","import { DOCUMENT_HANDLER } from \"#document\";\nimport type { Option } from \"@chocbite/ts-lib/result\";\nimport { Container } from \"./container\";\nimport \"./engine.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport const CONTEXT_MENY_SYMBOL = Symbol(\"context_menu\");\n\ndeclare global {\n interface Document {\n [CONTEXT_MENY_SYMBOL]: Container | undefined;\n }\n interface Element {\n [CONTEXT_MENY_SYMBOL]: EventListenerOrEventListenerObject | undefined;\n }\n}\n\n/**Default context menu, false blocks the operating system context menu, undefined leaves it*/\nlet default_menu: ContextMenu | (() => Option<ContextMenu>) | false | undefined;\n\n/**Blocks the operating system context menu when the default is false*/\nconst block_os_menu = (e: Event) => e.preventDefault();\n\nDOCUMENT_HANDLER.events.on(\"added\", (e) => {\n apply_to_doc(e.data);\n});\nDOCUMENT_HANDLER.for_documents((doc) => {\n apply_to_doc(doc);\n});\n\nfunction apply_to_doc(doc: Document) {\n const container = new Container();\n doc[CONTEXT_MENY_SYMBOL] = container;\n doc.documentElement.appendChild(container);\n apply_default_to_doc(doc);\n}\n\n/**Applies the current default context menu to a document*/\nfunction apply_default_to_doc(doc: Document) {\n const root = doc.documentElement;\n context_menu_detach(root);\n root.removeEventListener(\"contextmenu\", block_os_menu);\n if (default_menu) context_menu_attach(root, default_menu);\n else if (default_menu === false)\n root.addEventListener(\"contextmenu\", block_os_menu);\n}\n\n/**Attaches a context menu to the given element\n * @param element the element to attach the context menu to\n * @param lines the context menu to attach, if a function is given it will be called when the context menu is summoned\n * @param block a function that returns true if the context menu should not be summoned, if undefined the context menu will always be summoned*/\nexport function context_menu_attach(\n element: Element,\n lines: ContextMenu | (() => Option<ContextMenu>),\n block?: () => boolean,\n) {\n if (element[CONTEXT_MENY_SYMBOL]) context_menu_detach(element);\n const listener = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n if (block && block()) return;\n const lineses =\n typeof lines === \"function\" ? lines().unwrap_or(undefined) : lines;\n if (!lineses) return;\n context_menu_summon(\n lineses,\n element,\n (e as MouseEvent).clientX,\n (e as MouseEvent).clientY,\n );\n };\n element.addEventListener(\"contextmenu\", listener);\n element[CONTEXT_MENY_SYMBOL] = listener;\n}\n\n/**Dettaches the context menu from the given element */\nexport function context_menu_detach(element: Element) {\n if (element[CONTEXT_MENY_SYMBOL]) {\n element.removeEventListener(\"contextmenu\", element[CONTEXT_MENY_SYMBOL]);\n delete element[CONTEXT_MENY_SYMBOL];\n }\n}\n\n/**Summons a context menu at a given location\n * @param menu the context menu to summon\n * @param element the element the context menu is referenced to, if undefined the context menu will appear in the main document\n * @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\n * @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\n * @param dont_cover when set true */\nexport function context_menu_summon(\n menu: ContextMenu,\n element?: Element,\n x?: number,\n y?: number,\n dont_cover?: boolean,\n) {\n const container = element\n ? element.ownerDocument[CONTEXT_MENY_SYMBOL]\n : DOCUMENT_HANDLER.main[CONTEXT_MENY_SYMBOL];\n if (container) {\n if (typeof x !== \"number\" || typeof y !== \"number\") {\n if (element) {\n const box = element.getBoundingClientRect();\n x = box.left + box.width / 2;\n y = box.top + box.height / 2;\n } else {\n x = 0;\n y = 0;\n }\n }\n container\n .attach_menu(menu)\n .set_position(x, y, dont_cover ? element : undefined);\n } else console.error(\"No context menu container available\");\n}\n\n/**Sets the default context menu for the page, the one used if no other context menu has been attached to the element\n * If set to false the operating system context menu is disabled and nothing will appear\n * If set undefined the operating systems context menu will be used*/\nexport function context_menu_default(\n lines: ContextMenu | (() => Option<ContextMenu>) | false | undefined,\n) {\n default_menu = lines;\n DOCUMENT_HANDLER.for_documents(apply_default_to_doc);\n}\n","import { define_element } from \"#base\";\nimport { Spinner } from \"#spinner\";\nimport \"./buffer.scss\";\nimport { MenuLine } from \"./line\";\n\nexport class Buffer extends MenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"buffer\";\n }\n\n constructor() {\n super();\n this.appendChild(new Spinner());\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Buffer);\n","import { define_element } from \"#base\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./option.scss\";\n\nexport interface ContextMenuOption extends ContextMenuLine {}\n\nexport class MenuOption extends MenuLine implements ContextMenuOption {\n readonly func: () => void;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"option\";\n }\n\n constructor(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n ) {\n super();\n this.func = func;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n if (shortcut) shortcut_box.textContent = shortcut;\n shortcut_box.className = \"shortcut\";\n const check_mark_box = this.appendChild(document.createElement(\"div\"));\n if (checkmark) check_mark_box.textContent = \"✓\";\n check_mark_box.className = \"checkmark\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n this.func();\n navigator.vibrate?.(25);\n (this.parentElement as ContextMenu).close_up();\n };\n\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"Enter\":\n case \"Space\":\n this.func();\n (this.parentElement as ContextMenu).close_up();\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n do_focus(): void {\n this.focus();\n }\n}\ndefine_element(MenuOption);\n\nexport function context_line(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n): ContextMenuOption {\n return new MenuOption(text, func, icon, shortcut, checkmark);\n}\n","import { define_element } from \"#base\";\nimport { material_chevron_right_rounded } from \"#icons\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./submenu.scss\";\n\nexport interface ContextMenuSub extends ContextMenuLine {}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\nexport class MenuSub extends MenuLine implements ContextMenuSub {\n #menu: ContextMenu;\n #is_open?: boolean;\n #hover_time?: number;\n #block_time?: number;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"submenu\";\n }\n\n constructor(text: string, menu: ContextMenu, icon?: SVGSVGElement) {\n super();\n this.#menu = menu;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n shortcut_box.className = \"shortcut\";\n const chevron_box = this.appendChild(document.createElement(\"div\"));\n chevron_box.appendChild(material_chevron_right_rounded());\n chevron_box.className = \"chevron\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n if (!this.#block_time) {\n navigator.vibrate?.(25);\n if (this.#is_open) {\n this.close_down();\n } else {\n this.open();\n }\n }\n };\n\n this.onpointerenter = (e) => {\n if (e.pointerType !== \"touch\" && !this.#is_open) {\n this.#hover_time = window.setTimeout(() => {\n this.open();\n this.#block_time = window.setTimeout(() => {\n this.#block_time = 0;\n }, 500);\n }, 300);\n }\n };\n this.onpointerleave = () => {\n clearTimeout(this.#hover_time);\n };\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"ArrowRight\":\n case \"Enter\":\n case \"Space\":\n this.open();\n this.#menu.focus_next(false);\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n /**Opens the sub menu */\n open() {\n const sub = this.parentElement as Mutable<ContextMenu>;\n if (sub) sub.close_down();\n (this.parentElement as Mutable<ContextMenu>).submenu = this;\n this.appendChild(this.#menu);\n this.#menu.set_position(0, 0, this);\n this.#is_open = true;\n }\n\n do_focus(): void {\n this.focus();\n }\n\n /**Closes menu by calling parent*/\n close() {\n this.focus();\n (this.parentElement as Mutable<ContextMenu>).submenu = undefined;\n this.removeChild(this.#menu);\n this.#is_open = false;\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n this.#menu.close_down();\n this.close();\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.close();\n (this.parentElement as ContextMenu).close_up();\n }\n}\ndefine_element(MenuSub);\n\nexport function context_sub(\n text: string,\n menu: ContextMenu,\n icon?: SVGSVGElement,\n): ContextMenuSub {\n return new MenuSub(text, menu, icon);\n}\n","import { Base, define_element } from \"#base\";\nimport { material_close_rounded } from \"#icons\";\nimport { Buffer } from \"./buffer\";\nimport { Container } from \"./container\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport \"./menu.scss\";\nimport { MenuOption } from \"./option\";\nimport \"./shared\";\nimport { MenuSub } from \"./submenu\";\n\nexport type ContextMenuLines = ContextMenuLine[];\n\nexport class ContextMenu extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"menu\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n container: Container | undefined;\n readonly submenu: MenuSub | undefined;\n #closer: MenuOption | undefined;\n #x: number | undefined;\n #y: number | undefined;\n #element: Element | undefined;\n /**Spinner shown while promised lines load, cleared when the menu closes*/\n #loading: Buffer | undefined;\n #focus_out_handler = (e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n if (!e.relatedTarget || !this.contains(e.relatedTarget as Node)) {\n this.close_up();\n this.close_down();\n }\n };\n #window_resize_handler = () => {\n this.set_position(this.#x, this.#y, this.#element);\n };\n\n #lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>);\n\n constructor(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>),\n ) {\n super();\n this.#lines = lines;\n this.tabIndex = 0;\n this.onscroll = () => {\n this.close_down();\n };\n this.onkeydown = (e) => {\n if (e.code === \"Tab\" || e.code === \"ArrowUp\" || e.code === \"ArrowDown\")\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n else if (e.code === \"ArrowLeft\") {\n const parent = this.parentElement as MenuSub | Container;\n if (!(parent instanceof Container)) {\n parent.focus();\n parent.close_down();\n }\n } else if (e.code === \"Escape\") this.close_up();\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n const lines =\n typeof this.#lines === \"function\" ? this.#lines() : this.#lines;\n this.#loading?.remove();\n if (lines instanceof Promise) {\n const buffer = (this.#loading = this.appendChild(new Buffer()));\n lines.then((line) => {\n //Closed or opened again before the lines arrived\n if (this.#loading !== buffer) return;\n this.#loading = undefined;\n buffer.remove();\n this.lines = line;\n this.set_position(this.#x, this.#y, this.#element);\n });\n } else {\n this.#loading = undefined;\n this.lines = lines;\n }\n this.addEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n this.ownerDocument.defaultView?.addEventListener(\n \"resize\",\n this.#window_resize_handler,\n { passive: true },\n );\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n //Lines arriving after the menu closed are not shown\n this.#loading?.remove();\n this.#loading = undefined;\n this.ownerDocument.defaultView?.removeEventListener(\n \"resize\",\n this.#window_resize_handler,\n );\n }\n\n /**Sets the lines of the context menu */\n set lines(lines: (ContextMenuLine | undefined)[]) {\n this.replaceChildren();\n if (this.#closer) this.appendChild(this.#closer);\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line) this.appendChild(line as MenuLine);\n }\n }\n\n /**Changes focus to the next line\n * @param direction false is first child, true is last child */\n focus_next(direction: boolean) {\n //The direction is passed on, so a divider skips to the line after it, toward the middle\n if (direction) (this.lastChild as MenuLine)?.do_focus(true);\n else (this.firstChild as MenuLine)?.do_focus(false);\n }\n\n set closer(closer: boolean) {\n if (closer && !this.#closer) {\n this.classList.add(\"closer\");\n this.#closer = new MenuOption(\n \"Close\",\n () => {},\n material_close_rounded(),\n );\n this.#closer.onclick = (e) => {\n e.stopPropagation();\n if (this.parentElement instanceof MenuSub) {\n this.parentElement.close_down();\n } else {\n this.close_up();\n }\n };\n this.prepend(this.#closer);\n } else if (!closer && this.#closer) {\n this.classList.remove(\"closer\");\n this.#closer.remove();\n this.#closer = undefined;\n }\n }\n\n /**Sets the context menu to fullscreen mode in x directino */\n set fullscreenx(full: boolean) {\n if (full) this.classList.add(\"fullscreen-x\");\n else this.classList.remove(\"fullscreen-x\");\n }\n\n /**Sets the context menu to fullscreen mode in y direction */\n set fullscreeny(full: boolean) {\n if (full) this.classList.add(\"fullscreen-y\");\n else this.classList.remove(\"fullscreen-y\");\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n if (this.submenu) this.submenu.close_down();\n //@ts-expect-error Writing to readonly property, from inside class itself\n this.submenu = undefined;\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.removeEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n (this.parentElement as Container)?.close_up();\n this.remove();\n }\n\n /**Updates the position of the menu\n * @param x x coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param y y coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param element element to use instead of coordinates, the contextemenu will avoid covering the element if possible*/\n set_position(x: number = 0, y: number = 0, element?: Element) {\n this.#x = x;\n this.#y = y;\n this.#element = element;\n const box = this.getBoundingClientRect();\n const box_area = box.width * box.height;\n const window = this.ownerDocument.defaultView!;\n const html_area = window.innerWidth * window.innerHeight;\n this.closer = box_area > html_area * 0.5;\n let top = NaN;\n let bottom = NaN;\n let left = NaN;\n let right = NaN;\n if (element) {\n const sub_box = element.getBoundingClientRect();\n\n if (sub_box.x + sub_box.width + box.width > window.innerWidth) {\n x = sub_box.x;\n if (box.width < x) right = window.innerWidth - x;\n else right = window.innerWidth - (sub_box.x + sub_box.width);\n } else left = sub_box.x + sub_box.width;\n\n y = sub_box.y + sub_box.height;\n\n //Below the element, else above it, else as low as the window allows\n if (y + box.height < window.innerHeight) top = y;\n else if (sub_box.y >= box.height) bottom = window.innerHeight - sub_box.y;\n else top = Math.max(0, window.innerHeight - box.height);\n } else {\n if (y + box.height >= window.innerHeight) {\n if (y >= box.height) bottom = window.innerHeight - y;\n else top = window.innerHeight - box.height;\n } else top = y;\n\n if (box.width >= window.innerWidth) {\n right = 0;\n } else if (x + box.width >= window.innerWidth) {\n if (x >= box.width) right = window.innerWidth - x;\n else left = window.innerWidth - box.width;\n } else left = x;\n }\n this.fullscreenx = box.width === window.innerWidth;\n this.fullscreeny = box.height >= window.innerHeight;\n\n this.style.top = top === top ? top + \"px\" : \"\";\n this.style.bottom = bottom === bottom ? bottom + \"px\" : \"\";\n this.style.left = left === left ? left + \"px\" : \"\";\n this.style.right = right === right ? right + \"px\" : \"\";\n this.focus();\n }\n}\ndefine_element(ContextMenu);\n\nexport function context_menu(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() => (ContextMenuLine | undefined)[])\n | (() => Promise<(ContextMenuLine | undefined)[]>),\n): ContextMenu {\n return new ContextMenu(lines);\n}\n","import { context_devider } from \"./devider\";\nimport {\n context_menu_attach,\n context_menu_default,\n context_menu_detach,\n context_menu_summon,\n CONTEXT_MENY_SYMBOL,\n} from \"./engine\";\nimport { context_menu } from \"./menu\";\nimport { context_line } from \"./option\";\nimport { context_sub } from \"./submenu\";\n\nexport const ctm = {\n attach: context_menu_attach,\n default: context_menu_default,\n detach: context_menu_detach,\n summon: context_menu_summon,\n has(element: Element) {\n return Boolean(element[CONTEXT_MENY_SYMBOL]);\n },\n menu: context_menu,\n line: context_line,\n sub: context_sub,\n devider: context_devider,\n};\nexport default ctm;\n\nexport type { ContextMenu, ContextMenuLines } from \"./menu\";\n"],"mappings":";;;;;;;;AAGA,MAAM,YAAY,yBAChB,eACA,gBACA,uDACF;AACA,UAAU,cACR,cACA,oBACA,uBACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,QACA,cACA,iBACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,SACA,eACA,kDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,aACA,cACA,uBACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA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head_elements.length; i++) switch (head_elements[i].nodeName) {
33
- case "LINK": break;
33
+ case "LINK":
34
+ if (head_elements[i].rel === "stylesheet") document.head.appendChild(head_elements[i].cloneNode(true));
35
+ break;
34
36
  case "STYLE": document.head.appendChild(head_elements[i].cloneNode(true));
35
37
  }
36
38
  }