@chocbite/ts-lib-ui 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/AGENTS.md +172 -3
  2. package/SOURCE.md +2161 -273
  3. package/base/index.mjs +7 -7
  4. package/base/index.mjs.map +1 -1
  5. package/canvas/index.mjs +8 -8
  6. package/canvas/index.mjs.map +1 -1
  7. package/context-menu/index.d.mts +2 -2
  8. package/context-menu/index.mjs +1 -1
  9. package/{context-menu-Bo8R6DmK.mjs → context-menu-hHRJ33Lu.mjs} +149 -111
  10. package/context-menu-hHRJ33Lu.mjs.map +1 -0
  11. package/document/index.mjs +1 -1
  12. package/document/index.mjs.map +1 -1
  13. package/dom/index.mjs +1 -1
  14. package/dom/index.mjs.map +1 -1
  15. package/form/index.d.mts +4 -3
  16. package/form/index.mjs +30 -29
  17. package/form/index.mjs.map +1 -1
  18. package/icons/index.mjs +1 -1
  19. package/{icons-e2J_Ojic.mjs → icons-B88i-7MC.mjs} +2 -2
  20. package/{index-Pr2sLv9e.d.mts → index-76zZKjTH.d.mts} +32 -16
  21. package/index-D6L_jK1x.d.mts +385 -0
  22. package/keyboard/index.mjs +12 -12
  23. package/keyboard/index.mjs.map +1 -1
  24. package/list/index.d.mts +2 -2
  25. package/list/index.mjs +1 -1
  26. package/list-Bic1UzeC.mjs +1640 -0
  27. package/list-Bic1UzeC.mjs.map +1 -0
  28. package/package.json +5 -80
  29. package/selection/index.mjs +1 -1
  30. package/selection/index.mjs.map +1 -1
  31. package/settings/index.mjs +1 -1
  32. package/settings/index.mjs.map +1 -1
  33. package/spinner/index.mjs +3 -3
  34. package/spinner/index.mjs.map +1 -1
  35. package/state_ui/index.mjs +1 -1
  36. package/{state_ui-Bm3TeKNL.mjs → state_ui-Dtm2y5RU.mjs} +3 -3
  37. package/state_ui-Dtm2y5RU.mjs.map +1 -0
  38. package/style.css +349 -63
  39. package/svg/index.mjs +1 -1
  40. package/{svg-1bp-yIPC.mjs → svg-Yz7elqnU.mjs} +16 -16
  41. package/svg-Yz7elqnU.mjs.map +1 -0
  42. package/test/index.mjs +1 -1
  43. package/test/index.mjs.map +1 -1
  44. package/theme/index.mjs +1 -1
  45. package/{theme-DgVtLDzP.mjs → theme-DilOXXDu.mjs} +9 -9
  46. package/theme-DilOXXDu.mjs.map +1 -0
  47. package/context-menu-Bo8R6DmK.mjs.map +0 -1
  48. package/index-BTUFkF9s.d.mts +0 -173
  49. package/list-DOXIQOEY.mjs +0 -715
  50. package/list-DOXIQOEY.mjs.map +0 -1
  51. package/state_ui-Bm3TeKNL.mjs.map +0 -1
  52. package/svg-1bp-yIPC.mjs.map +0 -1
  53. package/theme-DgVtLDzP.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import "./style.css";
2
2
  import { degrees_to_radians } from "@chocbite/ts-lib/math";
3
- // src/svg/attributes.ts
3
+ // svg/attributes.ts
4
4
  var SVGAttributes = class {
5
5
  constructor(elem) {
6
6
  this.#elem = elem;
@@ -98,13 +98,13 @@ var SVGAttributes = class {
98
98
  return this;
99
99
  }
100
100
  };
101
- // src/svg/shared.ts
101
+ // svg/shared.ts
102
102
  const NAME_SPACE = "http://www.w3.org/2000/svg";
103
- // src/svg/primitives/shared.ts
103
+ // svg/primitives/shared.ts
104
104
  function create_svg_element(name) {
105
105
  return new SVGAttributes(document.createElementNS(NAME_SPACE, name));
106
106
  }
107
- // src/svg/primitives/ellipse.ts
107
+ // svg/primitives/ellipse.ts
108
108
  /**This creates a svg ellipse
109
109
  * @param center_x x coordinate of center
110
110
  * @param center_y y coordinate of center
@@ -133,7 +133,7 @@ function ellipse_arc(center_x, center_y, radius_x, radius_y, start_angle, end_an
133
133
  const f_a = Math.abs(sweep) > Math.PI ? 1 : 0;
134
134
  return create_svg_element("path").a("d", `M ${point(start_radian)} ${arc} ${f_a} ${f_s} ${point(start_radian + sweep)}`);
135
135
  }
136
- // src/svg/primitives/circle.ts
136
+ // svg/primitives/circle.ts
137
137
  /**This creates a svg circle
138
138
  * @param center_x x coordinate of center
139
139
  * @param center_y y coordinate of center
@@ -154,12 +154,12 @@ function circle(center_x, center_y, radius) {
154
154
  function circle_arc(center_x, center_y, radius, start_angle, end_angle) {
155
155
  return ellipse_arc(center_x, center_y, radius, radius, start_angle, end_angle);
156
156
  }
157
- // src/svg/primitives/group.ts
157
+ // svg/primitives/group.ts
158
158
  /**This draws a triangle*/
159
159
  function group() {
160
160
  return create_svg_element("g");
161
161
  }
162
- // src/svg/primitives/line.ts
162
+ // svg/primitives/line.ts
163
163
  /**This creates a line element
164
164
  * @param start_x start point on x axis
165
165
  * @param start_y start point on y axis
@@ -168,12 +168,12 @@ function group() {
168
168
  function line(start_x, start_y, end_x, end_y) {
169
169
  return create_svg_element("line").a("x1", String(start_x)).a("y1", String(start_y)).a("x2", String(end_x)).a("y2", String(end_y));
170
170
  }
171
- // src/svg/primitives/path.ts
171
+ // svg/primitives/path.ts
172
172
  /**This creates a path element*/
173
173
  function path(path) {
174
174
  return create_svg_element("path").a("d", path);
175
175
  }
176
- // src/svg/primitives/rectangle.ts
176
+ // svg/primitives/rectangle.ts
177
177
  /**This creates a rectangle with teh center as origin
178
178
  * @param center_x x coordinate of center
179
179
  * @param center_y y coordinate of center
@@ -192,7 +192,7 @@ function rectangle_from_center(center_x, center_y, width, height, corner_radius)
192
192
  function rectangle_from_corner(start_x, start_y, width, height, corner_radius) {
193
193
  return create_svg_element("rect").a("x", String(start_x)).a("y", String(start_y)).a("width", String(width)).a("height", String(height)).a("rx", String(corner_radius));
194
194
  }
195
- // src/svg/primitives/svg.ts
195
+ // svg/primitives/svg.ts
196
196
  /** This returns an empty svg element
197
197
  * @param width width of svg
198
198
  * @param height height of svg
@@ -200,7 +200,7 @@ function rectangle_from_corner(start_x, start_y, width, height, corner_radius) {
200
200
  function svg$1(width, height, viewbox = `0 0 ${width} ${height}`) {
201
201
  return create_svg_element("svg").a("width", String(width)).a("height", String(height)).a("viewBox", String(viewbox));
202
202
  }
203
- // src/svg/util/anchorPoint.ts
203
+ // svg/util/anchorPoint.ts
204
204
  const SVGAnchorPoint = {
205
205
  bottomLeft: 0,
206
206
  middleLeft: 1,
@@ -212,7 +212,7 @@ const SVGAnchorPoint = {
212
212
  bottomCenter: 7,
213
213
  middleCenter: 8
214
214
  };
215
- // src/svg/primitives/text.ts
215
+ // svg/primitives/text.ts
216
216
  /**Creates a text nodes for an svg
217
217
  * @param x x coordinate of text
218
218
  * @param y y coordinate of text
@@ -310,7 +310,7 @@ function multi_line_text(x, y, width, height, text, size, anchor) {
310
310
  }
311
311
  return text_element;
312
312
  }
313
- // src/svg/primitives/triangle.ts
313
+ // svg/primitives/triangle.ts
314
314
  /**This draws a triangle
315
315
  * @param center_x x coordinate of center
316
316
  * @param center_y y coordinate of center
@@ -321,7 +321,7 @@ function isosceles_triangle(center_x, center_y, width, height) {
321
321
  const half_h = height / 2;
322
322
  return create_svg_element("path").a("d", "M" + (center_x - half_w) + "," + (center_y + half_h) + " " + (center_x + half_w) + "," + (center_y + half_h) + " " + center_x + "," + (center_y - half_h) + "Z");
323
323
  }
324
- // src/svg/util/angleToAnchorPoint.ts
324
+ // svg/util/angleToAnchorPoint.ts
325
325
  /**Converts an angle to an anchor point
326
326
  * @param angle angle in radians, any angle outside 0 to 2PI is wrapped around*/
327
327
  const angle_to_anchor_point = (angle) => {
@@ -337,7 +337,7 @@ const angle_to_anchor_point = (angle) => {
337
337
  else if (sec > .3490658503988659) return SVGAnchorPoint.bottomRight;
338
338
  else return SVGAnchorPoint.middleRight;
339
339
  };
340
- // src/svg/index.ts
340
+ // svg/index.ts
341
341
  const svg = {
342
342
  create: create_svg_element,
343
343
  attr: (elem) => new SVGAttributes(elem),
@@ -358,4 +358,4 @@ const svg = {
358
358
  };
359
359
  export { SVGAnchorPoint as n, svg as t };
360
360
 
361
- //# sourceMappingURL=svg-1bp-yIPC.mjs.map
361
+ //# sourceMappingURL=svg-Yz7elqnU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg-Yz7elqnU.mjs","names":["svg","svgsvg"],"sources":["../../package-ui/svg/attributes.ts","../../package-ui/svg/shared.ts","../../package-ui/svg/primitives/shared.ts","../../package-ui/svg/primitives/ellipse.ts","../../package-ui/svg/primitives/circle.ts","../../package-ui/svg/primitives/group.ts","../../package-ui/svg/primitives/line.ts","../../package-ui/svg/primitives/path.ts","../../package-ui/svg/primitives/rectangle.ts","../../package-ui/svg/primitives/svg.ts","../../package-ui/svg/util/anchorPoint.ts","../../package-ui/svg/primitives/text.ts","../../package-ui/svg/primitives/triangle.ts","../../package-ui/svg/util/angleToAnchorPoint.ts","../../package-ui/svg/index.ts"],"sourcesContent":["export class SVGAttributes<T extends SVGElement> {\n constructor(elem: T) {\n this.#elem = elem;\n }\n #elem: T;\n /**Returns the svg element */\n get elem(): T {\n this.#apply_transforms();\n return this.#elem;\n }\n\n /** Sets the stroke color of the SVG element */\n stroke(stroke: string): this {\n this.#elem.setAttribute(\"stroke\", stroke);\n return this;\n }\n /** Sets the stroke color of the SVG element */\n s(stroke: string): this {\n this.#elem.setAttribute(\"stroke\", stroke);\n return this;\n }\n\n /** Sets the fill color of the SVG element */\n fill(fill: string): this {\n this.#elem.setAttribute(\"fill\", fill);\n return this;\n }\n /** Sets the fill color of the SVG element */\n f(fill: string): this {\n this.#elem.setAttribute(\"fill\", fill);\n return this;\n }\n\n /** Sets the stroke width of the SVG element */\n stroke_width(width: number): this {\n this.#elem.setAttribute(\"stroke-width\", String(width));\n return this;\n }\n /** Sets the stroke width of the SVG element */\n sw(width: number): this {\n this.#elem.setAttribute(\"stroke-width\", String(width));\n return this;\n }\n\n /** Adds one or more class names to the SVG element */\n class_list(...class_name: string[]): this {\n this.#elem.classList.add(...class_name);\n return this;\n }\n /** Adds one or more class names to the SVG element */\n cl(...class_name: string[]): this {\n this.#elem.classList.add(...class_name);\n return this;\n }\n\n /** Sets an arbitrary attribute on the SVG element */\n attribute(name: string, value: string): this {\n this.#elem.setAttribute(name, value);\n return this;\n }\n /** Sets an arbitrary attribute on the SVG element */\n a(name: string, value: string): this {\n this.#elem.setAttribute(name, value);\n return this;\n }\n\n #transforms: string[] = [];\n #apply_transforms(): void {\n if (this.#transforms.length > 0)\n this.#elem.setAttribute(\"transform\", this.#transforms.join(\" \"));\n }\n\n /** Applies a translation transform to the SVG element */\n translate(x: number, y: number): this {\n this.#transforms.push(`translate(${x} ${y})`);\n return this;\n }\n\n /** Applies a rotation transform to the SVG element */\n rotate(angle: number, cx?: number, cy?: number): this {\n if (cx !== undefined && cy !== undefined)\n this.#transforms.push(`rotate(${angle} ${cx} ${cy})`);\n else this.#transforms.push(`rotate(${angle})`);\n return this;\n }\n\n /** Applies a scaling transform to the SVG element */\n scale(sx: number, sy?: number): this {\n if (sy !== undefined) this.#transforms.push(`scale(${sx} ${sy})`);\n else this.#transforms.push(`scale(${sx})`);\n return this;\n }\n\n /** Applies a skewX transform to the SVG element */\n skewX(angle: number): this {\n this.#transforms.push(`skewX(${angle})`);\n return this;\n }\n\n /** Applies a skewY transform to the SVG element */\n skewY(angle: number): this {\n this.#transforms.push(`skewY(${angle})`);\n return this;\n }\n\n /** Applies a custom transform to the SVG element */\n transform(transform: string): this {\n this.#transforms.push(transform);\n return this;\n }\n}\n","export const NAME_SPACE = \"http://www.w3.org/2000/svg\";\n","import { SVGAttributes } from \"../attributes\";\nimport { NAME_SPACE } from \"../shared\";\n\nexport function create_svg_element<K extends keyof SVGElementTagNameMap>(\n name: K,\n): SVGAttributes<SVGElementTagNameMap[K]> {\n return new SVGAttributes(document.createElementNS(NAME_SPACE, name));\n}\n","import { degrees_to_radians } from \"@chocbite/ts-lib/math\";\nimport { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This creates a svg ellipse\n * @param center_x x coordinate of center\n * @param center_y y coordinate of center\n * @param radius_x x radius of circle\n * @param radius_y y radius of circle*/\nexport function ellipse(\n center_x: number,\n center_y: number,\n radius_x: number,\n radius_y: number,\n): SVGAttributes<SVGEllipseElement> {\n return create_svg_element(\"ellipse\")\n .a(\"cx\", String(center_x))\n .a(\"cy\", String(center_y))\n .a(\"rx\", String(radius_x))\n .a(\"ry\", String(radius_y));\n}\n\n/**This draws parts of a circle/ellipse, the circle direction is reversed\n * @param center_x the center point on the x axis\n * @param center_y the center point on the y axis\n * @param radius_x radius in x axis\n * @param radius_y radius in y axis\n * @param start_angle start angle in degrees\n * @param end_angle end angle in degrees, a sweep of 360 degrees or more draws the whole ellipse*/\nexport function ellipse_arc(\n center_x: number,\n center_y: number,\n radius_x: number,\n radius_y: number,\n start_angle: number,\n end_angle: number,\n): SVGAttributes<SVGPathElement> {\n const start_radian = degrees_to_radians(start_angle);\n const sweep = degrees_to_radians(end_angle - start_angle);\n const point = (radian: number) =>\n `${radius_x * Math.cos(radian) + center_x} ${radius_y * Math.sin(radian) + center_y}`;\n const f_s = sweep > 0 ? 1 : 0;\n const arc = `A ${radius_x} ${radius_y} 0`;\n //An arc ending where it starts draws nothing, so the whole ellipse is two halves\n if (Math.abs(sweep) >= 2 * Math.PI) {\n const half = start_radian + (sweep > 0 ? Math.PI : -Math.PI);\n return create_svg_element(\"path\").a(\n \"d\",\n `M ${point(start_radian)} ${arc} 0 ${f_s} ${point(half)} ${arc} 0 ${f_s} ${point(start_radian)}`,\n );\n }\n const f_a = Math.abs(sweep) > Math.PI ? 1 : 0;\n return create_svg_element(\"path\").a(\n \"d\",\n `M ${point(start_radian)} ${arc} ${f_a} ${f_s} ${point(start_radian + sweep)}`,\n );\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { ellipse_arc } from \"./ellipse\";\nimport { create_svg_element } from \"./shared\";\n\n/**This creates a svg circle\n * @param center_x x coordinate of center\n * @param center_y y coordinate of center\n * @param radius radius of circle*/\nexport function circle(\n center_x: number,\n center_y: number,\n radius: number,\n): SVGAttributes<SVGCircleElement> {\n const circle = create_svg_element(\"circle\");\n circle.a(\"cx\", String(center_x));\n circle.a(\"cy\", String(center_y));\n circle.a(\"r\", String(radius));\n return circle;\n}\n\n/**This draws parts of a circle/ellipse, the circle direction is reversed\n * @param center_x the center point on the x axis\n * @param center_y the center point on the y axis\n * @param radius radius in x axis\n * @param start_angle start angle in degrees\n * @param end_angle end angle in degrees, a sweep of 360 degrees or more draws the whole circle*/\nexport function circle_arc(\n center_x: number,\n center_y: number,\n radius: number,\n start_angle: number,\n end_angle: number,\n): SVGAttributes<SVGPathElement> {\n return ellipse_arc(\n center_x,\n center_y,\n radius,\n radius,\n start_angle,\n end_angle,\n );\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This draws a triangle*/\nexport function group(): SVGAttributes<SVGGElement> {\n return create_svg_element(\"g\");\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This creates a line element\n * @param start_x start point on x axis\n * @param start_y start point on y axis\n * @param end_x end point on x axis\n * @param end_y end point on y axis*/\nexport function line(\n start_x: number,\n start_y: number,\n end_x: number,\n end_y: number,\n): SVGAttributes<SVGLineElement> {\n return create_svg_element(\"line\")\n .a(\"x1\", String(start_x))\n .a(\"y1\", String(start_y))\n .a(\"x2\", String(end_x))\n .a(\"y2\", String(end_y));\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This creates a path element*/\nexport function path(path: string): SVGAttributes<SVGPathElement> {\n return create_svg_element(\"path\").a(\"d\", path);\n}\n\n/**This creates a line with a path element\n * @param start_x start point on x axis\n * @param start_y start point on y axis\n * @param end_x end point on x axis\n * @param end_y end point on y axis*/\nexport function path_line(\n start_x: number,\n start_y: number,\n end_x: number,\n end_y: number,\n): SVGAttributes<SVGPathElement> {\n return create_svg_element(\"path\").a(\n \"d\",\n `M ${start_x} ${start_y} L ${end_x} ${end_y}`,\n );\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This creates a rectangle with teh center as origin\n * @param center_x x coordinate of center\n * @param center_y y coordinate of center\n * @param width width\n * @param height height\n * @param corner_radius radius of corner*/\nexport function rectangle_from_center(\n center_x: number,\n center_y: number,\n width: number,\n height: number,\n corner_radius: number,\n): SVGAttributes<SVGRectElement> {\n return create_svg_element(\"rect\")\n .a(\"x\", String(center_x - width / 2))\n .a(\"y\", String(center_y - height / 2))\n .a(\"width\", String(width))\n .a(\"height\", String(height))\n .a(\"rx\", String(corner_radius));\n}\n\n/**This creates a rectangle with teh center as origin\n * @param start_x x coordinate of center\n * @param start_y y coordinate of center\n * @param width width\n * @param height height\n * @param corner_radius radius of corner*/\nexport function rectangle_from_corner(\n start_x: number,\n start_y: number,\n width: number,\n height: number,\n corner_radius: number,\n): SVGAttributes<SVGRectElement> {\n return create_svg_element(\"rect\")\n .a(\"x\", String(start_x))\n .a(\"y\", String(start_y))\n .a(\"width\", String(width))\n .a(\"height\", String(height))\n .a(\"rx\", String(corner_radius));\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/** This returns an empty svg element\n * @param width width of svg\n * @param height height of svg\n * @param viewbox viewbox of svg*/\nexport function svg(\n width: number,\n height: number,\n viewbox: string = `0 0 ${width} ${height}`,\n): SVGAttributes<SVGSVGElement> {\n return create_svg_element(\"svg\")\n .a(\"width\", String(width))\n .a(\"height\", String(height))\n .a(\"viewBox\", String(viewbox));\n}\n","//Enum describing the diffrent possible anchor points\nexport const SVGAnchorPoint = {\n bottomLeft: 0,\n middleLeft: 1,\n topLeft: 2,\n topCenter: 3,\n topRight: 4,\n middleRight: 5,\n bottomRight: 6,\n bottomCenter: 7,\n middleCenter: 8,\n} as const;\nexport type SVGAnchorPoint =\n (typeof SVGAnchorPoint)[keyof typeof SVGAnchorPoint];\n","import { SVGAttributes } from \"../attributes\";\nimport { SVGAnchorPoint } from \"../util/anchorPoint\";\nimport { create_svg_element } from \"./shared\";\n\n/**Creates a text nodes for an svg\n * @param x x coordinate of text\n * @param y y coordinate of text\n * @param text text\n * @param size size of text in px\n * @param anchor anchor point of text*/\nexport function text(\n x: number,\n y: number,\n text: string,\n size: number,\n anchor: SVGAnchorPoint,\n): SVGAttributes<SVGTextElement> {\n const text_elem = create_svg_element(\"text\")\n .a(\"x\", String(x))\n .a(\"y\", String(y))\n .a(\"font-size\", String(size));\n text_elem.elem.textContent = text;\n switch (anchor) {\n case SVGAnchorPoint.bottomLeft:\n case SVGAnchorPoint.middleLeft:\n case SVGAnchorPoint.topLeft: {\n text_elem.a(\"text-anchor\", \"start\");\n break;\n }\n case SVGAnchorPoint.topCenter:\n case SVGAnchorPoint.bottomCenter:\n case SVGAnchorPoint.middleCenter: {\n text_elem.a(\"text-anchor\", \"middle\");\n break;\n }\n case SVGAnchorPoint.topRight:\n case SVGAnchorPoint.middleRight:\n case SVGAnchorPoint.bottomRight: {\n text_elem.a(\"text-anchor\", \"end\");\n break;\n }\n }\n switch (anchor) {\n case SVGAnchorPoint.bottomLeft:\n case SVGAnchorPoint.bottomRight:\n case SVGAnchorPoint.bottomCenter: {\n text_elem.a(\"dominant-baseline\", \"auto\");\n break;\n }\n case SVGAnchorPoint.middleLeft:\n case SVGAnchorPoint.middleRight:\n case SVGAnchorPoint.middleCenter: {\n text_elem.a(\"dominant-baseline\", \"central\");\n break;\n }\n case SVGAnchorPoint.topLeft:\n case SVGAnchorPoint.topCenter:\n case SVGAnchorPoint.topRight: {\n text_elem.a(\"dominant-baseline\", \"hanging\");\n break;\n }\n }\n return text_elem;\n}\n\n/**Creates a text nodes for an svg\n * @param x x coordinate of text\n * @param y y coordinate of text\n * @param width width of text\n * @param height height of text\n * @param text text\n * @param size size of text in px\n * @param anchor anchor point of */\nexport function multi_line_text(\n x: number,\n y: number,\n width: number,\n height: number,\n text: string,\n size: number,\n anchor: SVGAnchorPoint,\n): SVGAttributes<SVGForeignObjectElement> {\n const text_element = create_svg_element(\"foreignObject\");\n const text_div = text_element.elem.appendChild(document.createElement(\"div\"));\n text_element.a(\"width\", String(width));\n text_element.a(\"height\", String(height));\n text_element.a(\"x\", String(x));\n text_element.a(\"y\", String(y));\n text_div.style.fontSize = size + \"px\";\n text_div.style.width = \"100%\";\n text_div.style.height = \"100%\";\n text_div.style.display = \"flex\";\n text_div.textContent = text;\n switch (anchor) {\n case SVGAnchorPoint.bottomLeft:\n case SVGAnchorPoint.middleLeft:\n case SVGAnchorPoint.topLeft: {\n text_div.style.textAlign = \"start\";\n text_div.style.justifyContent = \"flex-start\";\n break;\n }\n case SVGAnchorPoint.topCenter:\n case SVGAnchorPoint.bottomCenter:\n case SVGAnchorPoint.middleCenter: {\n text_div.style.textAlign = \"center\";\n text_div.style.justifyContent = \"center\";\n break;\n }\n case SVGAnchorPoint.topRight:\n case SVGAnchorPoint.middleRight:\n case SVGAnchorPoint.bottomRight: {\n text_div.style.textAlign = \"end\";\n text_div.style.justifyContent = \"flex-end\";\n break;\n }\n }\n switch (anchor) {\n case SVGAnchorPoint.bottomLeft:\n case SVGAnchorPoint.bottomRight:\n case SVGAnchorPoint.bottomCenter: {\n text_div.style.alignItems = \"flex-end\";\n break;\n }\n case SVGAnchorPoint.middleLeft:\n case SVGAnchorPoint.middleRight:\n case SVGAnchorPoint.middleCenter: {\n text_div.style.alignItems = \"center\";\n break;\n }\n case SVGAnchorPoint.topLeft:\n case SVGAnchorPoint.topCenter:\n case SVGAnchorPoint.topRight: {\n text_div.style.alignItems = \"flex-start\";\n break;\n }\n }\n return text_element;\n}\n","import { SVGAttributes } from \"../attributes\";\nimport { create_svg_element } from \"./shared\";\n\n/**This draws a triangle\n * @param center_x x coordinate of center\n * @param center_y y coordinate of center\n * @param width width\n * @param height height*/\nexport function isosceles_triangle(\n center_x: number,\n center_y: number,\n width: number,\n height: number,\n): SVGAttributes<SVGPathElement> {\n const half_w = width / 2;\n const half_h = height / 2;\n return create_svg_element(\"path\").a(\n \"d\",\n \"M\" +\n (center_x - half_w) +\n \",\" +\n (center_y + half_h) +\n \" \" +\n (center_x + half_w) +\n \",\" +\n (center_y + half_h) +\n \" \" +\n center_x +\n \",\" +\n (center_y - half_h) +\n \"Z\",\n );\n}\n","import { SVGAnchorPoint } from \"./anchorPoint\";\n\n/**Converts an angle to an anchor point\n * @param angle angle in radians, any angle outside 0 to 2PI is wrapped around*/\nexport const angle_to_anchor_point = (angle: number) => {\n const full = 6.283185307179586;\n const sec = ((angle % full) + full) % full;\n if (sec > 5.93411945678072) {\n return SVGAnchorPoint.middleRight;\n } else if (sec > 4.974188368183839) {\n return SVGAnchorPoint.topRight;\n } else if (sec > 4.45058959258554) {\n return SVGAnchorPoint.topCenter;\n } else if (sec > 3.4906585039886591) {\n return SVGAnchorPoint.topLeft;\n } else if (sec > 2.792526803190927) {\n return SVGAnchorPoint.middleLeft;\n } else if (sec > 1.832595714594046) {\n return SVGAnchorPoint.bottomLeft;\n } else if (sec > 1.308996938995747) {\n return SVGAnchorPoint.bottomCenter;\n } else if (sec > 0.3490658503988659) {\n return SVGAnchorPoint.bottomRight;\n } else {\n return SVGAnchorPoint.middleRight;\n }\n};\n","import { SVGAttributes } from \"./attributes\";\nimport { circle, circle_arc } from \"./primitives/circle\";\nimport { ellipse, ellipse_arc } from \"./primitives/ellipse\";\nimport { group } from \"./primitives/group\";\nimport { line } from \"./primitives/line\";\nimport { path } from \"./primitives/path\";\nimport {\n rectangle_from_center,\n rectangle_from_corner,\n} from \"./primitives/rectangle\";\nimport { create_svg_element } from \"./primitives/shared\";\nimport { svg as svgsvg } from \"./primitives/svg\";\nimport { multi_line_text, text } from \"./primitives/text\";\nimport { isosceles_triangle } from \"./primitives/triangle\";\nimport { angle_to_anchor_point } from \"./util/angleToAnchorPoint\";\n\nexport const svg = {\n create: create_svg_element,\n attr: (elem: SVGElement) => new SVGAttributes(elem),\n //Primitives\n circle: circle,\n circle_arc: circle_arc,\n ellipse: ellipse,\n ellipse_arc: ellipse_arc,\n group: group,\n line: line,\n path: path,\n rectangle_from_center: rectangle_from_center,\n rectangle_from_corner: rectangle_from_corner,\n svg: svgsvg,\n text: text,\n multi_line_text: multi_line_text,\n isosceles_triangle: isosceles_triangle,\n //Utilities\n angle_to_anchor_point: angle_to_anchor_point,\n};\n\nexport type SVGFunc = () => SVGSVGElement;\nexport { SVGAnchorPoint } from \"./util/anchorPoint\";\n\ndeclare global {\n /**Types enum icons in @chocbite/ts-lib state as SVGFunc*/\n interface ChocbiteStateRegister {\n icon: SVGFunc;\n }\n}\n"],"mappings":";;;AAAA,IAAa,gBAAb,MAAiD;CAC/C,YAAY,MAAS;EACnB,KAAK,QAAQ;CACf;CACA;;CAEA,IAAI,OAAU;EACZ,KAAK,kBAAkB;EACvB,OAAO,KAAK;CACd;;CAGA,OAAO,QAAsB;EAC3B,KAAK,MAAM,aAAa,UAAU,MAAM;EACxC,OAAO;CACT;;CAEA,EAAE,QAAsB;EACtB,KAAK,MAAM,aAAa,UAAU,MAAM;EACxC,OAAO;CACT;;CAGA,KAAK,MAAoB;EACvB,KAAK,MAAM,aAAa,QAAQ,IAAI;EACpC,OAAO;CACT;;CAEA,EAAE,MAAoB;EACpB,KAAK,MAAM,aAAa,QAAQ,IAAI;EACpC,OAAO;CACT;;CAGA,aAAa,OAAqB;EAChC,KAAK,MAAM,aAAa,gBAAgB,OAAO,KAAK,CAAC;EACrD,OAAO;CACT;;CAEA,GAAG,OAAqB;EACtB,KAAK,MAAM,aAAa,gBAAgB,OAAO,KAAK,CAAC;EACrD,OAAO;CACT;;CAGA,WAAW,GAAG,YAA4B;EACxC,KAAK,MAAM,UAAU,IAAI,GAAG,UAAU;EACtC,OAAO;CACT;;CAEA,GAAG,GAAG,YAA4B;EAChC,KAAK,MAAM,UAAU,IAAI,GAAG,UAAU;EACtC,OAAO;CACT;;CAGA,UAAU,MAAc,OAAqB;EAC3C,KAAK,MAAM,aAAa,MAAM,KAAK;EACnC,OAAO;CACT;;CAEA,EAAE,MAAc,OAAqB;EACnC,KAAK,MAAM,aAAa,MAAM,KAAK;EACnC,OAAO;CACT;CAEA,cAAwB,CAAC;CACzB,oBAA0B;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MAAM,mBACf,OAAO,eAAe;MACjB,IAAI,MAAM,mBACf,OAAO,eAAe;MACjB,IAAI,MAAM,mBACf,OAAO,eAAe;MAEtB,OAAO,eAAe;AAE1B;;ACVA,MAAa,MAAM;CACjB,QAAQ;CACR,OAAO,SAAqB,IAAI,cAAc,IAAI;CAE1C;CACI;CACH;CACI;CACN;CACD;CACA;CACiB;CACA;CACvB,KAAKC;CACC;CACW;CACG;CAEG;AACzB"}
package/test/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import "../style.css";
2
2
  import { Base, define_element } from "../base/index.mjs";
3
3
  import { state as state$1 } from "@chocbite/ts-lib/state";
4
- // src/test/index.ts
4
+ // test/index.ts
5
5
  /**Base of the trial elements, attach_input would move to Base if the pattern is kept*/
6
6
  var TestBase = class extends Base {
7
7
  static element_name() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["state"],"sources":["../../src/test/index.ts"],"sourcesContent":["import { Base, define_element } from \"#base\";\nimport {\n state,\n type State,\n type StateROSW,\n type StateSub,\n} from \"@chocbite/ts-lib/state\";\n\n/**A fixed value or a state giving the value*/\nexport type Input<T> = T | State<T>;\n\n/**Base of the trial elements, attach_input would move to Base if the pattern is kept*/\nexport abstract class TestBase extends Base {\n static element_name() {\n return \"@abstract@\";\n }\n static element_name_space() {\n return \"test\";\n }\n\n /**Applies a fixed value right away, a state is applied while the element is connected\n * The last good value is kept when a state gives an error*/\n protected attach_input<T>(input: Input<T>, apply: (value: T) => void): void {\n if (state.is.state(input))\n this.attach_state(input, (result) => {\n if (result.ok) apply(result.value);\n });\n else apply(input);\n }\n}\n\n// ____ ______ __\n// | _ \\ / __ \\ \\ / /\n// | |_) | | | \\ V /\n// | _ <| | | |> <\n// | |_) | |__| / . \\\n// |____/ \\____/_/ \\_\\\nexport interface TestBoxOptions {\n width?: Input<number>;\n height?: Input<number>;\n label?: Input<string>;\n /**State only, nothing is subscribed when left out*/\n color?: State<string>;\n}\n\n/**Colored box, the inputs are both values and states, except color which is only a state*/\nexport class TestBox extends TestBase {\n static element_name() {\n return \"box\";\n }\n\n readonly width: Input<number>;\n readonly height: Input<number>;\n readonly label: Input<string>;\n readonly color: State<string> | undefined;\n\n #text = this.appendChild(document.createElement(\"span\"));\n\n constructor(options: TestBoxOptions = {}) {\n super();\n this.width = options.width ?? 100;\n this.height = options.height ?? 32;\n this.label = options.label ?? \"\";\n this.color = options.color;\n this.style.cssText = BOX_STYLE;\n this.attach_input(this.width, (width) => {\n this.style.width = width + \"px\";\n });\n this.attach_input(this.height, (height) => {\n this.style.height = height + \"px\";\n });\n this.attach_input(this.label, (label) => {\n this.#text.textContent = this.format_label(label);\n });\n if (this.color)\n this.attach_input(this.color, (color) => {\n this.style.background = color;\n });\n }\n\n /**Overridable, shows what happens when an input calls into a subclass*/\n protected format_label(label: string): string {\n return label;\n }\n}\ndefine_element(TestBox);\n\nconst BOX_STYLE =\n \"display:inline-flex;align-items:center;justify-content:center;gap:4px;box-sizing:border-box;overflow:hidden;background:#2980b9;color:white;font:12px sans-serif\";\n\nexport interface TestLabelBoxOptions extends TestBoxOptions {\n badge?: Input<string>;\n}\n\n/**Subclass adding its own input after super, which is safe*/\nexport class TestLabelBox extends TestBox {\n static element_name() {\n return \"labelbox\";\n }\n\n readonly badge: Input<string>;\n\n #badge = this.insertBefore(\n document.createElement(\"b\"),\n this.firstChild,\n );\n\n constructor(options: TestLabelBoxOptions = {}) {\n super(options);\n this.badge = options.badge ?? \"\";\n this.attach_input(this.badge, (badge) => {\n this.#badge.textContent = badge;\n });\n }\n}\ndefine_element(TestLabelBox);\n\nexport interface TestOverrideBoxOptions extends TestBoxOptions {\n prefix: string;\n}\n\n/**Subclass overriding a method used by an input, which throws for a fixed label,\n * as a fixed value is applied in the base constructor before #prefix exists*/\nexport class TestOverrideBox extends TestBox {\n static element_name() {\n return \"overridebox\";\n }\n\n #prefix: string;\n\n constructor(options: TestOverrideBoxOptions) {\n super(options);\n this.#prefix = options.prefix;\n }\n\n protected format_label(label: string): string {\n return this.#prefix + label;\n }\n}\ndefine_element(TestOverrideBox);\n\n// _____ _____ ____ _ _ _____\n// / ____| __ \\ / __ \\| | | | __ \\\n// | | __| |__) | | | | | | | |__) |\n// | | |_ | _ /| | | | | | | ___/\n// | |__| | | \\ \\| |__| | |__| | |\n// \\_____|_| \\_\\\\____/ \\____/|_|\nexport interface TestGroupOptions {\n /**State only, so other elements can always subscribe to it*/\n items: State<TestBox[]>;\n}\n\n/**Shows a list of boxes and hands the state of the list out to other elements*/\nexport class TestGroup extends TestBase {\n static element_name() {\n return \"group\";\n }\n\n readonly items: State<TestBox[]>;\n\n constructor(options: TestGroupOptions) {\n super();\n this.items = options.items;\n this.style.cssText = \"display:flex;flex-wrap:wrap;gap:4px\";\n this.attach_input(this.items, (items) => {\n this.replaceChildren(...items);\n });\n }\n}\ndefine_element(TestGroup);\n\nexport interface TestWatcherOptions {\n group: State<TestGroup | undefined>;\n}\n\n/**Follows the list of whichever group it is given, the nested subscription of a viewport following its page*/\nexport class TestWatcher extends TestBase {\n static element_name() {\n return \"watcher\";\n }\n\n readonly group: State<TestGroup | undefined>;\n\n #on_items: StateSub<any> | undefined;\n\n constructor(options: TestWatcherOptions) {\n super();\n this.group = options.group;\n this.style.cssText = \"font:12px monospace\";\n this.attach_input(this.group, (group) => {\n if (this.#on_items) this.detach_state(this.#on_items);\n this.#on_items = undefined;\n if (group)\n this.#on_items = this.attach_state(group.items, (items) => {\n this.textContent = items.ok\n ? `${items.value.length} items`\n : items.error;\n });\n else this.textContent = \"no group\";\n });\n }\n}\ndefine_element(TestWatcher);\n\n// _____ _ _____ _____ ______ _____\n// / ____| | |_ _| __ \\| ____| __ \\\n// | (___ | | | | | | | | |__ | |__) |\n// \\___ \\| | | | | | | | __| | _ /\n// ____) | |____ _| |_| |__| | |____| | \\ \\\n// |_____/|______|_____|_____/|______|_| \\_\\\nexport interface TestSliderOptions {\n value: StateROSW<number>;\n min?: Input<number>;\n max?: Input<number>;\n}\n\n/**Slider writing to a state, the state can be shared with any other element*/\nexport class TestSlider extends TestBase {\n static element_name() {\n return \"slider\";\n }\n\n readonly value: StateROSW<number>;\n\n #input = this.appendChild(document.createElement(\"input\"));\n\n constructor(options: TestSliderOptions) {\n super();\n this.value = options.value;\n this.#input.type = \"range\";\n //Limits first, setting the value clamps it to the current limits\n this.attach_input(options.min ?? 0, (min) => {\n this.#input.min = String(min);\n });\n this.attach_input(options.max ?? 100, (max) => {\n this.#input.max = String(max);\n });\n this.attach_input(this.value, (value) => {\n this.#input.value = String(value);\n });\n this.#input.oninput = () => {\n void this.value.write(Number(this.#input.value));\n };\n }\n}\ndefine_element(TestSlider);\n\n// _____ ______ _______ _______ ______ _____ _____\n// / ____| ____|__ __|__ __| ____| __ \\ / ____|\n// | (___ | |__ | | | | | |__ | |__) | (___\n// \\___ \\| __| | | | | | __| | _ / \\___ \\\n// ____) | |____ | | | | | |____| | \\ \\ ____) |\n// |_____/|______| |_| |_| |______|_| \\_\\_____/\n/**The box written the way elements are written today, with setters and getters, to compare against*/\nexport class TestSetterBox extends TestBase {\n static element_name() {\n return \"setterbox\";\n }\n\n #width: number = 100;\n #height: number = 32;\n #label: string = \"\";\n #text = this.appendChild(document.createElement(\"span\"));\n\n constructor() {\n super();\n this.style.cssText = BOX_STYLE;\n }\n\n set width(width: number) {\n this.#width = width;\n this.style.width = width + \"px\";\n }\n get width(): number {\n return this.#width;\n }\n\n set height(height: number) {\n this.#height = height;\n this.style.height = height + \"px\";\n }\n get height(): number {\n return this.#height;\n }\n\n set label(label: string) {\n this.#label = label;\n this.#text.textContent = label;\n }\n get label(): string {\n return this.#label;\n }\n}\ndefine_element(TestSetterBox);\n"],"mappings":";;;;;AAYA,IAAsB,WAAtB,cAAuC,KAAK;CAC1C,OAAO,eAAe;EACpB,OAAO;CACT;CACA,OAAO,qBAAqB;EAC1B,OAAO;CACT;;;CAIA,aAA0B,OAAiB,OAAiC;EAC1E,IAAIA,QAAM,GAAG,MAAM,KAAK,GACtB,K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O,MAAM,QAAQ;GAC7C,KAAK,OAAO,MAAM,OAAO,GAAG;EAC9B,CAAC;EACD,KAAK,aAAa,KAAK,QAAQ,UAAU;GACvC,KAAK,OAAO,QAAQ,OAAO,KAAK;EAClC,CAAC;EACD,KAAK,OAAO,gBAAgB;GAC1B,KAAU,MAAM,MAAM,OAAO,KAAK,OAAO,KAAK,CAAC;EACjD;CACF;AACF;AACA,eAAe,UAAU;;AASzB,IAAa,gBAAb,cAAmC,SAAS;CAC1C,OAAO,eAAe;EACpB,OAAO;CACT;CAEA,SAAiB;CACjB,UAAkB;CAClB,SAAiB;CACjB,QAAQ,KAAK,YAAY,SAAS,cAAc,MAAM,CAAC;CAEvD,cAAc;EACZ,MAAM;EACN,KAAK,MAAM,UAAU;CACvB;CAEA,IAAI,MAAM,OAAe;EACvB,KAAK,SAAS;EACd,KAAK,MAAM,QAAQ,QAAQ;CAC7B;CACA,IAAI,QAAgB;EAClB,OAAO,KAAK;CACd;CAEA,IAAI,OAAO,QAAgB;EACzB,KAAK,UAAU;EACf,KAAK,MAAM,SAAS,SAAS;CAC/B;CACA,IAAI,SAAiB;EACnB,OAAO,KAAK;CACd;CAEA,IAAI,MAAM,OAAe;EACvB,KAAK,SAAS;EACd,KAAK,MAAM,cAAc;CAC3B;CACA,IAAI,QAAgB;EAClB,OAAO,KAAK;CACd;AACF;AACA,eAAe,aAAa"}
1
+ {"version":3,"file":"index.mjs","names":["state"],"sources":["../../../package-ui/test/index.ts"],"sourcesContent":["import { Base, define_element } from \"#base\";\nimport {\n state,\n type State,\n type StateROSW,\n type StateSub,\n} from \"@chocbite/ts-lib/state\";\n\n/**A fixed value or a state giving the value*/\nexport type Input<T> = T | State<T>;\n\n/**Base of the trial elements, attach_input would move to Base if the pattern is kept*/\nexport abstract class TestBase extends Base {\n static element_name() {\n return \"@abstract@\";\n }\n static element_name_space() {\n return \"test\";\n }\n\n /**Applies a fixed value right away, a state is applied while the element is connected\n * The last good value is kept when a state gives an error*/\n protected attach_input<T>(input: Input<T>, apply: (value: T) => void): void {\n if (state.is.state(input))\n this.attach_state(input, (result) => {\n if (result.ok) apply(result.value);\n });\n else apply(input);\n }\n}\n\n// ____ ______ __\n// | _ \\ / __ \\ \\ / /\n// | |_) | | | \\ V /\n// | _ <| | | |> <\n// | |_) | |__| / . \\\n// |____/ \\____/_/ \\_\\\nexport interface TestBoxOptions {\n width?: Input<number>;\n height?: Input<number>;\n label?: Input<string>;\n /**State only, nothing is subscribed when left out*/\n color?: State<string>;\n}\n\n/**Colored box, the inputs are both values and states, except color which is only a state*/\nexport class TestBox extends TestBase {\n static element_name() {\n return \"box\";\n }\n\n readonly width: Input<number>;\n readonly height: Input<number>;\n readonly label: Input<string>;\n readonly color: State<string> | undefined;\n\n #text = this.appendChild(document.createElement(\"span\"));\n\n constructor(options: TestBoxOptions = {}) {\n super();\n this.width = options.width ?? 100;\n this.height = options.height ?? 32;\n this.label = options.label ?? \"\";\n this.color = options.color;\n this.style.cssText = BOX_STYLE;\n this.attach_input(this.width, (width) => {\n this.style.width = width + \"px\";\n });\n this.attach_input(this.height, (height) => {\n this.style.height = height + \"px\";\n });\n this.attach_input(this.label, (label) => {\n this.#text.textContent = this.format_label(label);\n });\n if (this.color)\n this.attach_input(this.color, (color) => {\n this.style.background = color;\n });\n }\n\n /**Overridable, shows what happens when an input calls into a subclass*/\n protected format_label(label: string): string {\n return label;\n }\n}\ndefine_element(TestBox);\n\nconst BOX_STYLE =\n \"display:inline-flex;align-items:center;justify-content:center;gap:4px;box-sizing:border-box;overflow:hidden;background:#2980b9;color:white;font:12px sans-serif\";\n\nexport interface TestLabelBoxOptions extends TestBoxOptions {\n badge?: Input<string>;\n}\n\n/**Subclass adding its own input after super, which is safe*/\nexport class TestLabelBox extends TestBox {\n static element_name() {\n return \"labelbox\";\n }\n\n readonly badge: Input<string>;\n\n #badge = this.insertBefore(\n document.createElement(\"b\"),\n this.firstChild,\n );\n\n constructor(options: TestLabelBoxOptions = {}) {\n super(options);\n this.badge = options.badge ?? \"\";\n this.attach_input(this.badge, (badge) => {\n this.#badge.textContent = badge;\n });\n }\n}\ndefine_element(TestLabelBox);\n\nexport interface TestOverrideBoxOptions extends TestBoxOptions {\n prefix: string;\n}\n\n/**Subclass overriding a method used by an input, which throws for a fixed label,\n * as a fixed value is applied in the base constructor before #prefix exists*/\nexport class TestOverrideBox extends TestBox {\n static element_name() {\n return \"overridebox\";\n }\n\n #prefix: string;\n\n constructor(options: TestOverrideBoxOptions) {\n super(options);\n this.#prefix = options.prefix;\n }\n\n protected format_label(label: string): string {\n return this.#prefix + label;\n }\n}\ndefine_element(TestOverrideBox);\n\n// _____ _____ ____ _ _ _____\n// / ____| __ \\ / __ \\| | | | __ \\\n// | | __| |__) | | | | | | | |__) |\n// | | |_ | _ /| | | | | | | ___/\n// | |__| | | \\ \\| |__| | |__| | |\n// \\_____|_| \\_\\\\____/ \\____/|_|\nexport interface TestGroupOptions {\n /**State only, so other elements can always subscribe to it*/\n items: State<TestBox[]>;\n}\n\n/**Shows a list of boxes and hands the state of the list out to other elements*/\nexport class TestGroup extends TestBase {\n static element_name() {\n return \"group\";\n }\n\n readonly items: State<TestBox[]>;\n\n constructor(options: TestGroupOptions) {\n super();\n this.items = options.items;\n this.style.cssText = \"display:flex;flex-wrap:wrap;gap:4px\";\n this.attach_input(this.items, (items) => {\n this.replaceChildren(...items);\n });\n }\n}\ndefine_element(TestGroup);\n\nexport interface TestWatcherOptions {\n group: State<TestGroup | undefined>;\n}\n\n/**Follows the list of whichever group it is given, the nested subscription of a viewport following its page*/\nexport class TestWatcher extends TestBase {\n static element_name() {\n return \"watcher\";\n }\n\n readonly group: State<TestGroup | undefined>;\n\n #on_items: StateSub<any> | undefined;\n\n constructor(options: TestWatcherOptions) {\n super();\n this.group = options.group;\n this.style.cssText = \"font:12px monospace\";\n this.attach_input(this.group, (group) => {\n if (this.#on_items) this.detach_state(this.#on_items);\n this.#on_items = undefined;\n if (group)\n this.#on_items = this.attach_state(group.items, (items) => {\n this.textContent = items.ok\n ? `${items.value.length} items`\n : items.error;\n });\n else this.textContent = \"no group\";\n });\n }\n}\ndefine_element(TestWatcher);\n\n// _____ _ _____ _____ ______ _____\n// / ____| | |_ _| __ \\| ____| __ \\\n// | (___ | | | | | | | | |__ | |__) |\n// \\___ \\| | | | | | | | __| | _ /\n// ____) | |____ _| |_| |__| | |____| | \\ \\\n// |_____/|______|_____|_____/|______|_| \\_\\\nexport interface TestSliderOptions {\n value: StateROSW<number>;\n min?: Input<number>;\n max?: Input<number>;\n}\n\n/**Slider writing to a state, the state can be shared with any other element*/\nexport class TestSlider extends TestBase {\n static element_name() {\n return \"slider\";\n }\n\n readonly value: StateROSW<number>;\n\n #input = this.appendChild(document.createElement(\"input\"));\n\n constructor(options: TestSliderOptions) {\n super();\n this.value = options.value;\n this.#input.type = \"range\";\n //Limits first, setting the value clamps it to the current limits\n this.attach_input(options.min ?? 0, (min) => {\n this.#input.min = String(min);\n });\n this.attach_input(options.max ?? 100, (max) => {\n this.#input.max = String(max);\n });\n this.attach_input(this.value, (value) => {\n this.#input.value = String(value);\n });\n this.#input.oninput = () => {\n void this.value.write(Number(this.#input.value));\n };\n }\n}\ndefine_element(TestSlider);\n\n// _____ ______ _______ _______ ______ _____ _____\n// / ____| ____|__ __|__ __| ____| __ \\ / ____|\n// | (___ | |__ | | | | | |__ | |__) | (___\n// \\___ \\| __| | | | | | __| | _ / \\___ \\\n// ____) | |____ | | | | | |____| | \\ \\ ____) |\n// |_____/|______| |_| |_| |______|_| \\_\\_____/\n/**The box written the way elements are written today, with setters and getters, to compare against*/\nexport class TestSetterBox extends TestBase {\n static element_name() {\n return \"setterbox\";\n }\n\n #width: number = 100;\n #height: number = 32;\n #label: string = \"\";\n #text = this.appendChild(document.createElement(\"span\"));\n\n constructor() {\n super();\n this.style.cssText = BOX_STYLE;\n }\n\n set width(width: number) {\n this.#width = width;\n this.style.width = width + \"px\";\n }\n get width(): number {\n return this.#width;\n }\n\n set height(height: number) {\n this.#height = height;\n this.style.height = height + \"px\";\n }\n get height(): number {\n return this.#height;\n }\n\n set label(label: string) {\n this.#label = label;\n this.#text.textContent = label;\n }\n get label(): string {\n return this.#label;\n }\n}\ndefine_element(TestSetterBox);\n"],"mappings":";;;;;AAYA,IAAsB,WAAtB,cAAuC,KAAK;CAC1C,OAAO,eAAe;EACpB,OAAO;CACT;CACA,OAAO,qBAAqB;EAC1B,OAAO;CACT;;;CAIA,aAA0B,OAAiB,OAAiC;EAC1E,IAAIA,QAAM,GAAG,MAAM,KAAK,GACtB,KAAK,aAAa,QAAQ,WAAW;GACnC,IAAI,OAAO,IAAI,MAAM,OAAO,KAAK;EACnC,CAAC;OACE,MAAM,KAAK;CAClB;AACF;;AAiBA,IAAa,UAAb,cAA6B,SAAS;CACpC,OAAO,eAAe;EACpB,OAAO;CACT;CAEA;CACA;CACA;CACA;CAEA,QAAQ,KAAK,YAAY,SAAS,cAAc,MAAM,CAAC;CAEvD,YAAY,UAA0B,CAAC,GAAG;EACxC,MAAM;EACN,KAAK,QAAQ,QAAQ,SAAS;EAC9B,KAAK,SAAS,QAAQ,UAAU;EAChC,KAAK,QAAQ,QAAQ,SAAS;EAC9B,KAAK,QAAQ,QAAQ;EACrB,KAAK,MAAM,UAAU;EACrB,KAAK,aAAa,KAAK,QAAQ,UAAU;GACvC,KAAK,MAAM,QAAQ,QAAQ;EAC7B,CAAC;EACD,KAAK,aAAa,KAAK,SAAS,WAAW;GACzC,KAAK,MAAM,SAAS,SAAS;EAC/B,CAAC;EACD,KAAK,aAAa,KAAK,QAAQ,UAAU;GACvC,KAAK,MAAM,cAAc,KAAK,aAAa,KAAK;EAClD,CAAC;EACD,IAAI,KAAK,OACP,KAAK,aAAa,KAAK,QAAQ,UAAU;GACvC,KAAK,MAAM,aAAa;EAC1B,CAAC;CACL;;CAGA,aAAuB,OAAuB;EAC5C,OAAO;CACT;AACF;AACA,eAAe,OAAO;AAEtB,MAAM,YACJ;;AAOF,IAAa,eAAb,cAAkC,QAAQ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1
1
  import "../style.css";
2
- export { s as ANIMATION_LEVEL, c as ANIMATION_SPEED, l as AnimationLevels, n as BUILT_IN, u as INPUT_MODE, d as InputModes, f as SCALE, p as SCROLLBAR_MODE, m as ScrollbarModes, h as THEME, r as ThemeVariableGroup, g as Themes, a as px_to_rem, o as rem_to_px, t as theme_init, i as theme_init_variable_root } from "../theme-DgVtLDzP.mjs";
2
+ export { s as ANIMATION_LEVEL, c as ANIMATION_SPEED, l as AnimationLevels, n as BUILT_IN, u as INPUT_MODE, d as InputModes, f as SCALE, p as SCROLLBAR_MODE, m as ScrollbarModes, h as THEME, r as ThemeVariableGroup, g as Themes, a as px_to_rem, o as rem_to_px, t as theme_init, i as theme_init_variable_root } from "../theme-DilOXXDu.mjs";
@@ -1,13 +1,13 @@
1
1
  import "./style.css";
2
2
  import { DOCUMENT_HANDLER } from "./document/index.mjs";
3
- import { RS as material_edit_rounded, nW as material_mouse_rounded, oR as material_light_mode_rounded, vat as material_touch_app_rounded, vv as material_dark_mode_rounded } from "./icons-e2J_Ojic.mjs";
3
+ import { RS as material_edit_rounded, nW as material_mouse_rounded, oR as material_light_mode_rounded, vat as material_touch_app_rounded, vv as material_dark_mode_rounded } from "./icons-B88i-7MC.mjs";
4
4
  import { settings_init } from "./settings/index.mjs";
5
5
  import { state as state$1 } from "@chocbite/ts-lib/state";
6
6
  import { none, ok, some } from "@chocbite/ts-lib/result";
7
7
  import { GREY } from "@chocbite/ts-lib/colors";
8
8
  // ../package.json
9
- var version = "1.0.6";
10
- // src/theme/settings.ts
9
+ var version = "1.1.1";
10
+ // theme/settings.ts
11
11
  const SETTINGS = settings_init("@chocbite/ts-lib-theme", version, "Theme/UI", "Settings for UI elements and color themes");
12
12
  /**Accepts a stored setting only when it is one of the given values, otherwise the default is used*/
13
13
  const one_of = (values) => (stored) => Object.values(values).includes(stored) ? some(stored) : none();
@@ -155,9 +155,9 @@ const PRIVATE_ANIMATION_SPEED = state$1.rosw(state$1.n.help(SETTINGS.get(ANIMATI
155
155
  }), true);
156
156
  SETTINGS.register(ANIMATION_SPEED_ID, "Animation Speed", "Setting for animation speed, changes the speed of animations in the UI", PRIVATE_ANIMATION_SPEED);
157
157
  const ANIMATION_SPEED = PRIVATE_ANIMATION_SPEED.read_write;
158
- // src/theme/shared.ts
158
+ // theme/shared.ts
159
159
  const BOTTOM_GROUPS = {};
160
- // src/theme/engine.ts
160
+ // theme/engine.ts
161
161
  var ThemeEngine = class {
162
162
  #started = false;
163
163
  /**Theme of the operating system, used for the System theme*/
@@ -315,7 +315,7 @@ ANIMATION_LEVEL.sub((val) => {
315
315
  ANIMATION_SPEED.sub((val) => {
316
316
  theme_engine.apply_animation_speed(val.value);
317
317
  });
318
- // src/theme/variables.ts
318
+ // theme/variables.ts
319
319
  /**Initialises the settings for the package
320
320
  * @param package_name use import {name} from "../package.json"
321
321
  * @param name name of group formatted for user reading
@@ -381,7 +381,7 @@ var ThemeVariableGroup = class ThemeVariableGroup {
381
381
  for (const key in this.sub_groups) this.sub_groups[key].apply_themes(style, theme);
382
382
  }
383
383
  };
384
- // src/theme/builtIn.ts
384
+ // theme/builtIn.ts
385
385
  const BUILT_IN = 0;
386
386
  const root = theme_init_variable_root("common", "Shared Variables", "Shared variables across features");
387
387
  const scroll_bar_thumb = root.make_sub_group("scrollbar", "Scrollbar", "Scrollbar variables").make_sub_group("thumb", "Thumb", "Scrollbar Thumb variables");
@@ -390,7 +390,7 @@ scroll_bar_thumb.make_variable("hoverColor", "Thumb Hover Color", "Color of the
390
390
  scroll_bar_thumb.make_variable("activeColor", "Thumb Active Color", "Color of the scrollbar thumb when pressed", GREY["500"], GREY["700"], "Color", void 0);
391
391
  root.make_sub_group("fonts", "Fonts", "Font variables").make_variable("base", "UI Base Font", "The base font for the UI", "\"Roboto\", Arial, Helvetica, sans-serif", "\"Roboto\", Arial, Helvetica, sans-serif", "Font", void 0);
392
392
  root.make_sub_group("colors", "Colors", "Color variables").make_variable("layer1", "UI Layer 1", "Color of the first layer of the UI", GREY[50], "#111111", "Color", void 0);
393
- // src/theme/init.ts
393
+ // theme/init.ts
394
394
  let initialized = false;
395
395
  /**Starts the theme, the app must call it once, nothing of the theme is applied to the page before.
396
396
  * This is the only place the operating system dark mode is read, and only when system is on*/
@@ -416,4 +416,4 @@ function theme_init(options = {}) {
416
416
  }
417
417
  export { version as _, px_to_rem as a, ANIMATION_SPEED as c, InputModes as d, SCALE as f, Themes as g, THEME as h, theme_init_variable_root as i, AnimationLevels as l, ScrollbarModes as m, BUILT_IN as n, rem_to_px as o, SCROLLBAR_MODE as p, ThemeVariableGroup as r, ANIMATION_LEVEL as s, theme_init as t, INPUT_MODE as u };
418
418
 
419
- //# sourceMappingURL=theme-DgVtLDzP.mjs.map
419
+ //# sourceMappingURL=theme-DilOXXDu.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-DilOXXDu.mjs","names":["st"],"sources":["../../package.json","../../package-ui/theme/settings.ts","../../package-ui/theme/shared.ts","../../package-ui/theme/engine.ts","../../package-ui/theme/variables.ts","../../package-ui/theme/builtIn.ts","../../package-ui/theme/init.ts"],"sourcesContent":["","import {\n material_dark_mode_rounded,\n material_edit_rounded,\n material_light_mode_rounded,\n material_mouse_rounded,\n material_touch_app_rounded,\n} from \"#icons\";\nimport { settings_init } from \"#settings\";\nimport { none, ok, some, type Option } from \"@chocbite/ts-lib/result\";\nimport { state as st } from \"@chocbite/ts-lib/state\";\nimport { version } from \"../../package.json\";\n\nconst SETTINGS = settings_init(\n \"@chocbite/ts-lib-theme\",\n version,\n \"Theme/UI\",\n \"Settings for UI elements and color themes\",\n);\n\n/**Accepts a stored setting only when it is one of the given values, otherwise the default is used*/\nconst one_of =\n <T>(values: { [key: string]: T }) =>\n (stored: unknown): Option<T> =>\n Object.values(values).includes(stored as T) ? some(stored as T) : none();\n\n/**Accepts a stored setting only when it is a number within the range, otherwise the default is used*/\nconst in_range =\n (min: number, max: number) =>\n (stored: unknown): Option<number> =>\n typeof stored === \"number\" && stored >= min && stored <= max\n ? some(stored)\n : none();\n\n// _______ _ _ ______ __ __ ______\n// |__ __| | | | ____| \\/ | ____|\n// | | | |__| | |__ | \\ / | |__\n// | | | __ | __| | |\\/| | __|\n// | | | | | | |____| | | | |____\n// |_| |_| |_|______|_| |_|______|\nexport const Themes = {\n Light: \"light\",\n Dark: \"dark\",\n /**Follows the light or dark mode of the operating system, only offered when theme_init enables system*/\n System: \"system\",\n} as const;\nexport type Themes = (typeof Themes)[keyof typeof Themes];\n/**Themes that can be applied to the page, System is resolved to one of these*/\nexport type AppliedThemes = typeof Themes.Light | typeof Themes.Dark;\n\ntype ThemeList = Parameters<typeof st.e.list<Themes>>[0];\nconst LIGHT = {\n name: \"Light\",\n description: \"Theme optimized for daylight\",\n icon: material_light_mode_rounded,\n};\nconst DARK = {\n name: \"Dark\",\n description: \"Theme optimized for night time\",\n icon: material_dark_mode_rounded,\n};\n/**Theme choices, the System choice shows the theme the operating system currently uses\n * @param system theme of the operating system, undefined when the System choice is not offered*/\nconst theme_list = (system?: AppliedThemes): ThemeList => {\n const list: Partial<ThemeList> = {\n [Themes.Light]: LIGHT,\n [Themes.Dark]: DARK,\n };\n if (system) {\n const active = system === Themes.Dark ? DARK : LIGHT;\n list[Themes.System] = {\n name: \"System (\" + active.name + \")\",\n description: \"Follows the light or dark mode of the operating system\",\n icon: active.icon,\n };\n }\n return list as ThemeList;\n};\nconst THEMES = st.ok_w(theme_list());\n\nconst THEME_ID = \"theme\";\n/**Theme the user chose, undefined when nothing has been chosen yet*/\nconst STORED_THEME = SETTINGS.get<Themes | undefined>(\n THEME_ID,\n undefined,\n one_of(Themes),\n).value;\nconst PRIVATE_THEME = st.rosw(\n st.e.help(ok(STORED_THEME ?? (Themes.Light as Themes)), { list: THEMES }),\n true,\n);\n\nexport const THEME = PRIVATE_THEME.read_write;\n\n/**Sets up the theme setting, called once by theme_init\n * @param system theme of the operating system, undefined when the System choice is not offered\n * @param default_theme theme used when the user has not chosen one*/\nexport function theme_setting_init(\n system: AppliedThemes | undefined,\n default_theme: Themes,\n) {\n if (system) THEMES.set_ok(theme_list(system));\n //Set before registering, so the default is not stored as if the user chose it\n if (STORED_THEME === undefined || (STORED_THEME === Themes.System && !system))\n PRIVATE_THEME.set_ok(default_theme);\n SETTINGS.register(\n THEME_ID,\n \"Theme\",\n \"Theme to use for the UI\",\n PRIVATE_THEME,\n );\n}\n\n/**Updates the System choice to show the theme the operating system uses*/\nexport function theme_setting_system(system: AppliedThemes) {\n THEMES.set_ok(theme_list(system));\n}\n\n// _____ _____ _ ______\n// / ____|/ ____| /\\ | | | ____|\n// | (___ | | / \\ | | | |__\n// \\___ \\| | / /\\ \\ | | | __|\n// ____) | |____ / ____ \\| |____| |____\n// |_____/ \\_____/_/ \\_\\______|______|\nconst SCALE_ID = \"scale\";\nconst PRIVATE_SCALE = st.rosw(\n st.n.help(SETTINGS.get(SCALE_ID, 100, in_range(50, 400)), {\n min: st.ok(50),\n max: st.ok(400),\n unit: st.ok(\"%\"),\n start: st.ok(0),\n step: st.ok(1),\n }),\n true,\n);\nSETTINGS.register(SCALE_ID, \"Scale\", \"UI scale\", PRIVATE_SCALE);\nexport const SCALE = PRIVATE_SCALE.read_write;\n\n// _____ _____ _____ ____ _ _ ____ _____\n// / ____|/ ____| __ \\ / __ \\| | | | | _ \\ /\\ | __ \\\n// | (___ | | | |__) | | | | | | | | |_) | / \\ | |__) |\n// \\___ \\| | | _ /| | | | | | | | _ < / /\\ \\ | _ /\n// ____) | |____| | \\ \\| |__| | |____| |____| |_) / ____ \\| | \\ \\\n// |_____/ \\_____|_| \\_\\\\____/|______|______|____/_/ \\_\\_| \\_\\\nexport const ScrollbarModes = {\n Thin: \"thin\",\n Medium: \"medium\",\n Wide: \"wide\",\n} as const;\nexport type ScrollbarModes =\n (typeof ScrollbarModes)[keyof typeof ScrollbarModes];\n\nconst SCROLLBAR_MODES = st.ok(\n st.e.list<ScrollbarModes>({\n [ScrollbarModes.Thin]: {\n name: \"Thin\",\n description: \"Thin modern scrollbar\",\n },\n [ScrollbarModes.Medium]: {\n name: \"Medium\",\n description: \"Normal scrollbar\",\n },\n [ScrollbarModes.Wide]: {\n name: \"Wide\",\n description: \"Large touch friendly scrollbar\",\n },\n }),\n);\n\nconst SCROLLBAR_ID = \"scrollbar\";\nconst PRIVATE_SCROLLBAR_MODE = st.rosw(\n st.e.help(\n SETTINGS.get(\n SCROLLBAR_ID,\n ScrollbarModes.Thin as ScrollbarModes,\n one_of(ScrollbarModes),\n ),\n { list: SCROLLBAR_MODES },\n ),\n true,\n);\nSETTINGS.register(\n \"scrollbar\",\n \"Scrollbar Mode\",\n \"Size of the scrollbar to use\",\n PRIVATE_SCROLLBAR_MODE,\n);\n\nexport const SCROLLBAR_MODE = PRIVATE_SCROLLBAR_MODE.read_write;\n\n// _____ _ _ _____ _ _ _______ __ __ ____ _____ ______\n// |_ _| \\ | | __ \\| | | |__ __| | \\/ |/ __ \\| __ \\| ____|\n// | | | \\| | |__) | | | | | | | \\ / | | | | | | | |__\n// | | | . ` | ___/| | | | | | | |\\/| | | | | | | | __|\n// _| |_| |\\ | | | |__| | | | | | | | |__| | |__| | |____\n// |_____|_| \\_|_| \\____/ |_| |_| |_|\\____/|_____/|______|\nexport const InputModes = {\n Mouse: \"mouse\",\n Pen: \"pen\",\n Touch: \"touch\",\n} as const;\nexport type InputModes = (typeof InputModes)[keyof typeof InputModes];\n\nconst INPUT_MODES = st.ok(\n st.e.list<InputModes>({\n [InputModes.Mouse]: {\n name: \"Mouse\",\n description: \"Mouse input\",\n icon: material_mouse_rounded,\n },\n [InputModes.Pen]: {\n name: \"Pen\",\n description: \"Pen input\",\n icon: material_edit_rounded,\n },\n [InputModes.Touch]: {\n name: \"Touch\",\n description: \"Touch input\",\n icon: material_touch_app_rounded,\n },\n }),\n);\n\nconst INPUT_MODE_ID = \"input_mode\";\nconst PRIVATE_INPUT_MODE = st.rosw(\n st.e.help(\n SETTINGS.get(\n INPUT_MODE_ID,\n matchMedia(\"(pointer: coarse)\").matches\n ? InputModes.Touch\n : (InputModes.Mouse as InputModes),\n one_of(InputModes),\n ),\n { list: INPUT_MODES },\n ),\n true,\n);\nSETTINGS.register(\n INPUT_MODE_ID,\n \"Input Mode\",\n \"Setting for preffered input mode, changes UI elements to be more optimized for the selected input mode\",\n PRIVATE_INPUT_MODE,\n);\n\nexport const INPUT_MODE = PRIVATE_INPUT_MODE.read_write;\n\n// _ _ _____ __ __ _______ _____ ____ _ _ _ ________ ________ _\n// /\\ | \\ | |_ _| \\/ | /\\|__ __|_ _/ __ \\| \\ | | | | | ____\\ \\ / / ____| |\n// / \\ | \\| | | | | \\ / | / \\ | | | || | | | \\| | | | | |__ \\ \\ / /| |__ | |\n// / /\\ \\ | . ` | | | | |\\/| | / /\\ \\ | | | || | | | . ` | | | | __| \\ \\/ / | __| | |\n// / ____ \\| |\\ |_| |_| | | |/ ____ \\| | _| || |__| | |\\ | | |____| |____ \\ / | |____| |____\n// /_/ \\_\\_| \\_|_____|_| |_/_/ \\_\\_| |_____\\____/|_| \\_| |______|______| \\/ |______|______|\nexport const AnimationLevels = {\n All: \"all\",\n Some: \"some\",\n None: \"none\",\n} as const;\nexport type AnimationLevels =\n (typeof AnimationLevels)[keyof typeof AnimationLevels];\n\nconst ANIMATION_LEVELS = st.ok(\n st.e.list<AnimationLevels>({\n [AnimationLevels.All]: { name: \"All\", description: \"All animations\" },\n [AnimationLevels.Some]: {\n name: \"Functional\",\n description: \"Only functional animations that improve usability\",\n },\n [AnimationLevels.None]: { name: \"None\", description: \"No animations\" },\n }),\n);\n\nconst ANIMATION_LEVEL_ID = \"animation_level\";\nconst PRIVATE_ANIMATION_LEVEL = st.rosw(\n st.e.help(\n SETTINGS.get(\n ANIMATION_LEVEL_ID,\n AnimationLevels.None as AnimationLevels,\n one_of(AnimationLevels),\n ),\n { list: ANIMATION_LEVELS },\n ),\n true,\n);\nSETTINGS.register(\n ANIMATION_LEVEL_ID,\n \"Animation Level\",\n \"Setting for animation level, changes the amount of animations used in the UI\",\n PRIVATE_ANIMATION_LEVEL,\n);\n\nexport const ANIMATION_LEVEL = PRIVATE_ANIMATION_LEVEL.read_write;\n\n// _ _ _____ __ __ _______ _____ ____ _ _ _____ _____ ______ ______ _____\n// /\\ | \\ | |_ _| \\/ | /\\|__ __|_ _/ __ \\| \\ | | / ____| __ \\| ____| ____| __ \\\n// / \\ | \\| | | | | \\ / | / \\ | | | || | | | \\| | | (___ | |__) | |__ | |__ | | | |\n// / /\\ \\ | . ` | | | | |\\/| | / /\\ \\ | | | || | | | . ` | \\___ \\| ___/| __| | __| | | | |\n// / ____ \\| |\\ |_| |_| | | |/ ____ \\| | _| || |__| | |\\ | ____) | | | |____| |____| |__| |\n// /_/ \\_\\_| \\_|_____|_| |_/_/ \\_\\_| |_____\\____/|_| \\_| |_____/|_| |______|______|_____/\nconst ANIMATION_SPEED_ID = \"animation_speed\";\nconst PRIVATE_ANIMATION_SPEED = st.rosw(\n st.n.help(SETTINGS.get(ANIMATION_SPEED_ID, 200, in_range(50, 1000)), {\n min: st.ok(50),\n max: st.ok(1000),\n unit: st.ok(\"ms\"),\n start: st.ok(0),\n step: st.ok(50),\n }),\n true,\n);\nSETTINGS.register(\n ANIMATION_SPEED_ID,\n \"Animation Speed\",\n \"Setting for animation speed, changes the speed of animations in the UI\",\n PRIVATE_ANIMATION_SPEED,\n);\n\nexport const ANIMATION_SPEED = PRIVATE_ANIMATION_SPEED.read_write;\n","import type { ThemeVariableGroup } from \"./variables\";\n\nexport const BOTTOM_GROUPS: { [key: string]: ThemeVariableGroup } = {};\n","import { DOCUMENT_HANDLER } from \"#document\";\nimport {\n ANIMATION_LEVEL,\n ANIMATION_SPEED,\n AnimationLevels,\n INPUT_MODE,\n InputModes,\n SCALE,\n SCROLLBAR_MODE,\n ScrollbarModes,\n THEME,\n Themes,\n type AppliedThemes,\n} from \"./settings\";\nimport { BOTTOM_GROUPS } from \"./shared\";\n\nclass ThemeEngine {\n #started = false;\n /**Theme of the operating system, used for the System theme*/\n #os_theme: AppliedThemes = Themes.Light;\n\n /**Starts applying the theme to all documents, called once by theme_init*/\n start() {\n this.#started = true;\n DOCUMENT_HANDLER.events.on(\"added\", (e) => {\n this.#apply_all_to_doc(e.data);\n });\n this.#for_documents((doc) => {\n this.#apply_all_to_doc(doc);\n });\n }\n\n /**Runs for every document, nothing is applied before the engine is started*/\n #for_documents(func: (doc: Document) => void) {\n if (this.#started) DOCUMENT_HANDLER.for_documents(func);\n }\n\n /**Sets the theme of the operating system, reapplying the theme when System is used*/\n set_os_theme(theme: AppliedThemes) {\n this.#os_theme = theme;\n if (THEME.ok() === Themes.System) this.apply_theme(Themes.System);\n }\n\n /**Resolves the System theme to the theme of the operating system*/\n #applied(theme: Themes): AppliedThemes {\n return theme === Themes.System ? this.#os_theme : theme;\n }\n\n /**This applies the current theme to a document*/\n #apply_all_to_doc(doc: Document) {\n this.#apply_scrollbar_to_doc(doc, SCROLLBAR_MODE.ok());\n this.#apply_theme_to_doc(doc, THEME.ok());\n this.#apply_input_to_doc(doc, INPUT_MODE.ok());\n this.#apply_scale_to_doc(doc, SCALE.ok() / 100);\n this.#apply_animation_level_to_doc(doc, ANIMATION_LEVEL.ok());\n this.#apply_animation_speed_to_doc(doc, ANIMATION_SPEED.ok());\n }\n\n /**This applies the current theme to a document*/\n apply_scrollbar(scroll: ScrollbarModes) {\n this.#for_documents((doc) => {\n this.#apply_scrollbar_to_doc(doc, scroll);\n });\n }\n #apply_scrollbar_to_doc(doc: Document, scroll: ScrollbarModes) {\n doc.documentElement.style.setProperty(\n \"--scrollbar\",\n {\n [ScrollbarModes.Thin]: \"0.6rem\",\n [ScrollbarModes.Medium]: \"1rem\",\n [ScrollbarModes.Wide]: \"2.6rem\",\n }[scroll],\n );\n }\n\n /**This applies the current theme to a document*/\n apply_animation_level(anim: AnimationLevels) {\n this.#for_documents((doc) => {\n this.#apply_animation_level_to_doc(doc, anim);\n });\n }\n #apply_animation_level_to_doc(doc: Document, anim: AnimationLevels) {\n doc.documentElement.classList.remove(\"anim-all\", \"anim-some\");\n switch (anim) {\n case AnimationLevels.All:\n doc.documentElement.classList.add(\"anim-all\");\n doc.documentElement.classList.add(\"anim-some\");\n break;\n case AnimationLevels.Some:\n doc.documentElement.classList.add(\"anim-some\");\n break;\n }\n }\n\n /**This applies the current theme to a document*/\n apply_animation_speed(speed: number) {\n this.#for_documents((doc) => {\n this.#apply_animation_speed_to_doc(doc, speed);\n });\n }\n #apply_animation_speed_to_doc(doc: Document, speed: number) {\n const style = doc.documentElement.style;\n style.setProperty(\"--animation-speed\", speed.toString() + \"ms\");\n }\n\n /**This applies the current theme to a document*/\n apply_theme(theme: Themes) {\n this.#for_documents((doc) => {\n this.#apply_theme_to_doc(doc, theme);\n });\n }\n #apply_theme_to_doc(doc: Document, theme: Themes) {\n const applied = this.#applied(theme);\n for (const key in BOTTOM_GROUPS)\n BOTTOM_GROUPS[key].apply_themes(doc.documentElement.style, applied);\n }\n\n /**This applies the current scale to a document*/\n apply_scale(scale: number) {\n this.#for_documents((doc) => {\n this.#apply_scale_to_doc(doc, scale);\n });\n }\n #apply_scale_to_doc(doc: Document, scale: number) {\n doc.documentElement.style.fontSize = scale * 16 + \"px\";\n }\n\n /**Auto Input Mode */\n apply_input(mode: InputModes) {\n this.#for_documents((doc) => {\n this.#apply_input_to_doc(doc, mode);\n });\n }\n #apply_input_to_doc(doc: Document, mode: InputModes) {\n const style = doc.documentElement.style;\n style.setProperty(\"--mouse\", \"0\");\n style.setProperty(\"--pen\", \"0\");\n style.setProperty(\"--touch\", \"0\");\n doc.documentElement.classList.remove(\"mouse\", \"pen\", \"touch\");\n switch (mode) {\n case InputModes.Mouse:\n style.setProperty(\"--mouse\", \"1\");\n doc.documentElement.classList.add(\"mouse\");\n break;\n case InputModes.Pen:\n style.setProperty(\"--pen\", \"1\");\n doc.documentElement.classList.add(\"pen\");\n break;\n case InputModes.Touch:\n style.setProperty(\"--touch\", \"1\");\n doc.documentElement.classList.add(\"touch\");\n break;\n }\n }\n\n apply_single_property(key: string, variable: { [s: string]: string }) {\n const theme_buff = this.#applied(THEME.ok());\n this.#for_documents((doc) => {\n doc.documentElement.style.setProperty(key, variable[theme_buff]);\n });\n }\n}\n\nexport const theme_engine = new ThemeEngine();\n\nTHEME.sub((val) => {\n theme_engine.apply_theme(val.value);\n});\n/**Size of a rem in pixels at the current scale, set right away from the stored scale*/\nlet scale_rem = 16;\nSCALE.sub((val) => {\n const scale_value = val.value / 100;\n scale_rem = scale_value * 16;\n theme_engine.apply_scale(scale_value);\n}, true);\n/**Converts the given rems to pixels */\nexport function rem_to_px(rem: number) {\n return rem * scale_rem;\n}\n/**Converts the given pixels to rems */\nexport function px_to_rem(px: number) {\n return px / scale_rem;\n}\nSCROLLBAR_MODE.sub((val) => {\n theme_engine.apply_scrollbar(val.value);\n});\nINPUT_MODE.sub((val) => {\n theme_engine.apply_input(val.value);\n});\nANIMATION_LEVEL.sub((val) => {\n theme_engine.apply_animation_level(val.value);\n});\nANIMATION_SPEED.sub((val) => {\n theme_engine.apply_animation_speed(val.value);\n});\n","import { theme_engine } from \"./engine\";\nimport { Themes } from \"./settings\";\nimport { BOTTOM_GROUPS } from \"./shared\";\n\n/**Initialises the settings for the package\n * @param package_name use import {name} from \"../package.json\"\n * @param name name of group formatted for user reading\n * @param description a description of what the setting group is about*/\nexport const theme_init_variable_root = (\n package_name: string,\n name: string,\n description: string\n) => {\n if (package_name.includes(\"-\"))\n throw new Error(\"Dash not permitted in package name \" + package_name);\n if (package_name in BOTTOM_GROUPS)\n throw new Error(\n \"Theme variable group already registered \" +\n package_name +\n \", by another package or by this library being loaded twice\",\n );\n BOTTOM_GROUPS[package_name] = new ThemeVariableGroup(\n package_name,\n name,\n description\n );\n return BOTTOM_GROUPS[package_name];\n};\n\n/**Group of settings should never be instantiated manually use initSettings*/\nexport class ThemeVariableGroup {\n private path_id: string;\n private variables: {\n [key: string]: {\n name: string;\n desc: string;\n vars: { [key: string]: string };\n type: keyof VariableType;\n typeParams: VariableType[keyof VariableType];\n example?: () => Element;\n };\n } = {};\n private sub_groups: { [key: string]: ThemeVariableGroup } = {};\n readonly name: string;\n readonly description: string;\n\n constructor(path: string, name: string, description: string) {\n this.path_id = path;\n this.name = name;\n this.description = description;\n }\n\n /**Makes a variable subgroup for this group\n * @param id unique identifier for this subgroup in the parent group\n * @param name name of group formatted for user reading\n * @param description a description of what the setting group is about formatted for user reading*/\n make_sub_group(id: string, name: string, description: string) {\n if (id.includes(\"-\"))\n throw new Error(\"Dash not permitted in variable id \" + id);\n if (id in this.sub_groups)\n throw new Error(\"Sub group already registered \" + id);\n return (this.sub_groups[id] = new ThemeVariableGroup(\n this.path_id + \"-\" + id,\n name,\n description\n ));\n }\n\n /**Makes a variable\n * @param id unique identifier for this variable in the group\n * @param name name of variable formatted for user reading\n * @param description a description of what the variable is about formatted for user reading\n * @param light value for light mode\n * @param dark value for dark mode\n * @param type type of variable for editing\n * @param type_params */\n make_variable<K extends keyof VariableType>(\n id: string,\n name: string,\n description: string,\n light: string,\n dark: string,\n type: K,\n type_params: VariableType[K],\n example?: () => Element\n ): string {\n if (id.includes(\"-\"))\n throw new Error(\"Dash not permitted in variable id \" + id);\n const key = \"--\" + this.path_id + \"-\" + id;\n if (key in this.variables)\n throw new Error(\"Settings already registered \" + id);\n const variable = (this.variables[key] = {\n name,\n desc: description,\n vars: { [Themes.Light]: light, [Themes.Dark]: dark },\n type,\n typeParams: type_params,\n example,\n });\n theme_engine.apply_single_property(key, variable.vars);\n return key;\n }\n\n /**Applies the groups\n * @param style unique identifier for this variable in the group\n * @param theme name of variable formatted for user reading*/\n apply_themes(style: CSSStyleDeclaration, theme: string) {\n for (const key in this.variables)\n style.setProperty(key, this.variables[key].vars[theme]);\n for (const key in this.sub_groups)\n this.sub_groups[key].apply_themes(style, theme);\n }\n}\n\n/**Defines the parameters for a variable type */\ninterface VariableType {\n /**Font variable, */\n Font: undefined;\n /**Text variable, */\n String: undefined;\n /**Color variable */\n Color: undefined;\n /**Transition type */\n TransitionType: undefined;\n /**Percent type */\n Percent: undefined;\n /**Filter type */\n Filter: undefined;\n /**Radius type */\n Radius: undefined;\n /**Time variable */\n Time: {\n /**Minimum time in milliseconds */\n min: number;\n /**Maximum time in milliseconds */\n max: number;\n };\n /**Angle variable */\n Angle: { min: number; max: number };\n /**Length variable*/\n Length: { min: number; max: number };\n /**Number variable*/\n Number: { min: number; max: number };\n /**Ratio*/\n Ratio:\n | {\n width: { min: number; max: number };\n height: { min: number; max: number };\n }\n | number;\n}\n","import { GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"./variables\";\n\nexport const BUILT_IN = 0;\n\nconst root = theme_init_variable_root(\n \"common\",\n \"Shared Variables\",\n \"Shared variables across features\",\n);\n\nconst scroll_bar = root.make_sub_group(\n \"scrollbar\",\n \"Scrollbar\",\n \"Scrollbar variables\",\n);\nconst scroll_bar_thumb = scroll_bar.make_sub_group(\n \"thumb\",\n \"Thumb\",\n \"Scrollbar Thumb variables\",\n);\nscroll_bar_thumb.make_variable(\n \"color\",\n \"Thumb Color\",\n \"Color of the scrollbar thumb in normal state\",\n GREY[\"400\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\nscroll_bar_thumb.make_variable(\n \"hoverColor\",\n \"Thumb Hover Color\",\n \"Color of the scrollbar thumb when hovered\",\n GREY[\"600\"],\n GREY[\"600\"],\n \"Color\",\n undefined,\n);\nscroll_bar_thumb.make_variable(\n \"activeColor\",\n \"Thumb Active Color\",\n \"Color of the scrollbar thumb when pressed\",\n GREY[\"500\"],\n GREY[\"700\"],\n \"Color\",\n undefined,\n);\n\nconst fonts = root.make_sub_group(\"fonts\", \"Fonts\", \"Font variables\");\nfonts.make_variable(\n \"base\",\n \"UI Base Font\",\n \"The base font for the UI\",\n '\"Roboto\", Arial, Helvetica, sans-serif',\n '\"Roboto\", Arial, Helvetica, sans-serif',\n \"Font\",\n undefined,\n);\n\n// _____ ____ _ ____ _____ _____\n// / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | | | | | | | | | |__) | (___\n// | | | | | | | | | | | _ / \\___ \\\n// | |___| |__| | |___| |__| | | \\ \\ ____) |\n// \\_____\\____/|______\\____/|_| \\_\\_____/\n\nconst colors = root.make_sub_group(\"colors\", \"Colors\", \"Color variables\");\ncolors.make_variable(\n \"layer1\",\n \"UI Layer 1\",\n \"Color of the first layer of the UI\",\n GREY[50],\n \"#111111\",\n \"Color\",\n undefined,\n);\n","import { theme_engine } from \"./engine\";\nimport {\n theme_setting_init,\n theme_setting_system,\n Themes,\n type AppliedThemes,\n} from \"./settings\";\n\nexport interface ThemeInitOptions {\n /**Offers a System theme that follows the light or dark mode of the operating system,\n * leave it off on devices without that feature*/\n system?: boolean;\n /**Theme used until the user chooses one, defaults to System when system is on, otherwise Light*/\n default?: Themes;\n}\n\nlet initialized = false;\n\n/**Starts the theme, the app must call it once, nothing of the theme is applied to the page before.\n * This is the only place the operating system dark mode is read, and only when system is on*/\nexport function theme_init(options: ThemeInitOptions = {}) {\n const default_theme =\n options.default ?? (options.system ? Themes.System : Themes.Light);\n if (default_theme === Themes.System && !options.system)\n throw new Error(\"The System theme can only be the default with system on\");\n if (initialized) throw new Error(\"theme_init has already been called\");\n initialized = true;\n let os_theme: AppliedThemes | undefined;\n if (options.system) {\n const query = window.matchMedia(\"(prefers-color-scheme: dark)\");\n const theme_of = (dark: boolean) => (dark ? Themes.Dark : Themes.Light);\n os_theme = theme_of(query.matches);\n theme_engine.set_os_theme(os_theme);\n query.addEventListener(\"change\", (e) => {\n const changed = theme_of(e.matches);\n theme_setting_system(changed);\n theme_engine.set_os_theme(changed);\n });\n }\n theme_setting_init(os_theme, default_theme);\n theme_engine.start();\n}\n"],"mappings":";;;;;;;;;;ACYA,MAAM,WAAW,cACf,0BACA,SACA,YACA,2CACF;;AAGA,MAAM,UACA,YACH,WACC,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,MAAW,IAAI,KAAK,MAAW,IAAI,KAAK;;AAG3E,MAAM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AAU,UAAU,iBAClD,CAAC,CAAC,cACL,UACA,cACA,sCACA,KAAK,KACL,WACA,SACA,KAAA,CACF;;AC5DA,IAAI,cAAc;;;AAIlB,SAAgB,WAAW,UAA4B,CAAC,GAAG;CACzD,MAAM,gBACJ,QAAQ,YAAY,QAAQ,SAAS,OAAO,SAAS,OAAO;CAC9D,IAAI,kBAAkB,OAAO,UAAU,CAAC,QAAQ,QAC9C,MAAM,IAAI,MAAM,yDAAyD;CAC3E,IAAI,aAAa,MAAM,IAAI,MAAM,oCAAoC;CACrE,cAAc;CACd,IAAI;CACJ,IAAI,QAAQ,QAAQ;EAClB,MAAM,QAAQ,OAAO,WAAW,8BAA8B;EAC9D,MAAM,YAAY,SAAmB,OAAO,OAAO,OAAO,OAAO;EACjE,WAAW,SAAS,MAAM,OAAO;EACjC,aAAa,aAAa,QAAQ;EAClC,MAAM,iBAAiB,WAAW,MAAM;GACtC,MAAM,UAAU,SAAS,EAAE,OAAO;GAClC,qBAAqB,OAAO;GAC5B,aAAa,aAAa,OAAO;EACnC,CAAC;CACH;CACA,mBAAmB,UAAU,aAAa;CAC1C,aAAa,MAAM;AACrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-menu-Bo8R6DmK.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"],"mapp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