@chocbite/ts-lib-ui 1.0.1 → 1.0.3

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 (56) hide show
  1. package/README.md +16 -0
  2. package/base/index.d.mts +2 -2
  3. package/base/index.mjs +69 -77
  4. package/base/index.mjs.map +1 -1
  5. package/canvas/index.d.mts +3 -1
  6. package/canvas/index.mjs +51 -53
  7. package/canvas/index.mjs.map +1 -1
  8. package/context-menu/index.d.mts +1 -1
  9. package/context-menu/index.mjs +1 -1
  10. package/{context-menu-3OazryD0.mjs → context-menu-_9dMpC-H.mjs} +71 -37
  11. package/context-menu-_9dMpC-H.mjs.map +1 -0
  12. package/document/index.mjs +3 -1
  13. package/document/index.mjs.map +1 -1
  14. package/form/index.d.mts +16 -5
  15. package/form/index.mjs +410 -151
  16. package/form/index.mjs.map +1 -1
  17. package/icons/index.d.mts +1 -1
  18. package/icons/index.mjs +1 -1
  19. package/icons-e2J_Ojic.mjs +4124 -0
  20. package/{index-BcidwqIy.d.mts → index-BDWg5GX2.d.mts} +7 -18
  21. package/{index-BND79jZp.d.mts → index-CvzH3M_5.d.mts} +16 -9
  22. package/{index-CugtUzv_.d.mts → index-CzpbJoAj.d.mts} +19 -10
  23. package/{index-CB3-qP6l.d.mts → index-DhRb2iA8.d.mts} +7 -5
  24. package/keyboard/index.d.mts +1 -1
  25. package/keyboard/index.mjs +121 -50
  26. package/keyboard/index.mjs.map +1 -1
  27. package/list/index.d.mts +1 -1
  28. package/list/index.mjs +1 -1
  29. package/{list-BcNSxtNm.mjs → list-Bkm9Ailw.mjs} +98 -110
  30. package/list-Bkm9Ailw.mjs.map +1 -0
  31. package/package.json +7 -2
  32. package/selection/index.mjs +9 -11
  33. package/selection/index.mjs.map +1 -1
  34. package/settings/index.d.mts +23 -5
  35. package/settings/index.mjs +17 -10
  36. package/settings/index.mjs.map +1 -1
  37. package/spinner/index.d.mts +1 -1
  38. package/spinner/index.mjs +2 -2
  39. package/state/index.d.mts +36 -0
  40. package/state/index.mjs +2 -0
  41. package/state-OCzEmq3j.mjs +87 -0
  42. package/state-OCzEmq3j.mjs.map +1 -0
  43. package/style.css +14 -7
  44. package/svg/index.d.mts +1 -1
  45. package/svg/index.mjs +1 -1
  46. package/{svg-golJPaR4.mjs → svg-1bp-yIPC.mjs} +20 -17
  47. package/svg-1bp-yIPC.mjs.map +1 -0
  48. package/theme/index.d.mts +21 -2
  49. package/theme/index.mjs +1 -1
  50. package/{theme-DhIVwHQw.mjs → theme-DlD5P5tY.mjs} +125 -44
  51. package/theme-DlD5P5tY.mjs.map +1 -0
  52. package/context-menu-3OazryD0.mjs.map +0 -1
  53. package/icons-CY4BLQ2F.mjs +0 -4123
  54. package/list-BcNSxtNm.mjs.map +0 -1
  55. package/svg-golJPaR4.mjs.map +0 -1
  56. package/theme-DhIVwHQw.mjs.map +0 -1
@@ -3,9 +3,6 @@ import state from "@chocbite/ts-lib/state";
3
3
  import { ok } from "@chocbite/ts-lib/result";
4
4
  // src/settings/index.ts
5
5
  let name_transformer;
6
- const settings_set_name_transform = (transform) => {
7
- name_transformer = transform;
8
- };
9
6
  const packages = localStorage["settings/packageVersions"];
10
7
  let package_versions = {};
11
8
  try {
@@ -13,6 +10,17 @@ try {
13
10
  } catch (_e) {}
14
11
  let store_package_versions_timeout;
15
12
  const BOTTOM_GROUPS = {};
13
+ /**Renames the settings groups of every package, the group name is the start of every stored key,
14
+ * so an app can keep the library names, like @chocbite/ts-lib-theme, out of the local storage.
15
+ *
16
+ * Groups are made and read their stored values when their module is imported, so this must be called
17
+ * in a module imported before any other module of @chocbite/ts-lib-ui
18
+ * @param transform gets the package name of a group and returns the name to store it under*/
19
+ const settings_set_name_transform = (transform) => {
20
+ const existing = Object.keys(BOTTOM_GROUPS);
21
+ if (existing.length) console.error("settings_set_name_transform must be called before any settings group is made, call it in a module imported before any other module of @chocbite/ts-lib-ui, these groups already use their name: " + existing.join(", "));
22
+ name_transformer = transform;
23
+ };
16
24
  /**Initialises the settings for the package
17
25
  * @param package_name use import {name} from ("../package.json")
18
26
  * @param package_version use import {version} from ("../package.json")
@@ -21,6 +29,7 @@ const BOTTOM_GROUPS = {};
21
29
  * @param description a description of what the setting group is about*/
22
30
  const settings_init = (package_name, package_version, name, description) => {
23
31
  if (name_transformer) package_name = name_transformer(package_name);
32
+ if (package_name in BOTTOM_GROUPS) throw new Error("Settings group already registered " + package_name + ", by another package or by this library being loaded twice");
24
33
  let changed;
25
34
  if (package_versions[package_name] !== package_version) {
26
35
  changed = package_versions[package_name];
@@ -47,6 +56,8 @@ var SettingsGroup = class SettingsGroup {
47
56
  path_id;
48
57
  settings = {};
49
58
  sub_groups = {};
59
+ /**Ids already migrated for the version change, a migration runs once per id*/
60
+ #migrated = /* @__PURE__ */ new Set();
50
61
  version_changed;
51
62
  name;
52
63
  description;
@@ -73,8 +84,9 @@ var SettingsGroup = class SettingsGroup {
73
84
  const saved = localStorage.getItem(this.path_id + "/" + id);
74
85
  if (saved === null) return ok(fallback);
75
86
  try {
76
- if (this.version_changed && version_changed) {
87
+ if (this.version_changed && version_changed && !this.#migrated.has(id)) {
77
88
  const changed_value = version_changed(saved, this.version_changed);
89
+ this.#migrated.add(id);
78
90
  localStorage.setItem(this.path_id + "/" + id, JSON.stringify(changed_value));
79
91
  return ok(changed_value);
80
92
  }
@@ -86,16 +98,11 @@ var SettingsGroup = class SettingsGroup {
86
98
  }
87
99
  /**Sets value of setting, that has not been registered to a state
88
100
  * @param id unique identifier for this setting in the parent group
89
- * @param value value to set*/
101
+ * @param value value to set, must be a value JSON can store*/
90
102
  set(id, value) {
91
103
  if (id in this.settings) throw new Error("Settings is registered " + this.path_id + "/" + id);
92
104
  localStorage[this.path_id + "/" + id] = JSON.stringify(value);
93
105
  }
94
- /**Registers a state to a setting
95
- * @param id unique identifier for this setting in the parent group
96
- * @param name name of setting formatted for user reading
97
- * @param description a description of what the setting is about formatted for user reading
98
- * @param state state object representing the setting's value */
99
106
  register(id, name, description, state$2, transform) {
100
107
  if (id in this.settings) throw new Error("Settings already registered " + this.path_id + "/" + id);
101
108
  this.settings[id] = new Setting(state$2, name, description);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["state"],"sources":["../../src/settings/index.ts"],"sourcesContent":["import { ok, type Option, type ResultOk } from \"@chocbite/ts-lib/result\";\nimport st, { type StateROAW } from \"@chocbite/ts-lib/state\";\n\nlet name_transformer: ((name: string) => string) | undefined;\nexport const settings_set_name_transform = (\n transform: (name: string) => string,\n) => {\n name_transformer = transform;\n};\n\nconst packages = localStorage[\"settings/packageVersions\"] as string | undefined;\nlet package_versions: { [key: string]: string } = {};\ntry {\n package_versions = packages\n ? (JSON.parse(packages) as { [key: string]: string })\n : {};\n} catch (_e) {}\nlet store_package_versions_timeout: number | undefined;\nconst BOTTOM_GROUPS: { [key: string]: SettingsGroup } = {};\n\n/**Initialises the settings for the package\n * @param package_name use import {name} from (\"../package.json\")\n * @param package_version use import {version} from (\"../package.json\")\n * @param versionChanged function to call when the version of the package changed\n * @param name name of group formatted for user reading\n * @param description a description of what the setting group is about*/\nexport const settings_init = (\n package_name: string,\n package_version: string,\n name: string,\n description: string,\n) => {\n if (name_transformer) package_name = name_transformer(package_name);\n let changed: string | undefined;\n if (package_versions[package_name] !== package_version) {\n changed = package_versions[package_name];\n package_versions[package_name] = package_version;\n if (store_package_versions_timeout)\n clearTimeout(store_package_versions_timeout);\n store_package_versions_timeout = window.setTimeout(() => {\n localStorage[\"settings/packageVersions\"] =\n JSON.stringify(package_versions);\n }, 1000);\n }\n return (BOTTOM_GROUPS[package_name] = new SettingsGroup(\n package_name,\n name,\n description,\n changed ? changed : undefined,\n ));\n};\n\nclass Setting {\n readonly state: StateROAW<any>;\n readonly name: string;\n readonly description: string;\n constructor(state: StateROAW<any>, name: string, description: string) {\n this.state = state;\n this.name = name;\n this.description = description;\n }\n}\n\n/**Group of settings should never be instantiated manually use initSettings*/\nexport class SettingsGroup {\n private path_id: string;\n private settings: { [key: string]: Setting } = {};\n private sub_groups: { [key: string]: SettingsGroup } = {};\n readonly version_changed: string | undefined;\n readonly name: string;\n readonly description: string;\n\n constructor(\n path: string,\n name: string,\n description: string,\n version_changed?: string,\n ) {\n this.version_changed = version_changed;\n this.path_id = path;\n this.name = name;\n this.description = description;\n }\n\n /**Makes a settings 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 in this.sub_groups)\n throw new Error(\"Sub group already registered \" + id);\n return (this.sub_groups[id] = new SettingsGroup(\n this.path_id + \"/\" + id,\n name,\n description,\n this.version_changed,\n ));\n }\n\n /**Gets value of setting or fallbacks to default\n * @param id unique identifier for this setting in the parent group\n * @param fallback value to use if no setting is stored\n * @param check function to check if the stored value is valid, if not the fallback will be used\n * @param version_changed function called when the version of the package changed to migrate old value to new formats */\n get<T>(\n id: string,\n fallback: T,\n check?: (parsed: unknown) => Option<T>,\n version_changed?: (existing: string, oldVersion: string) => T,\n ): ResultOk<T> {\n const saved = localStorage.getItem(this.path_id + \"/\" + id);\n if (saved === null) return ok(fallback);\n try {\n if (this.version_changed && version_changed) {\n const changed_value = version_changed(saved, this.version_changed);\n localStorage.setItem(\n this.path_id + \"/\" + id,\n JSON.stringify(changed_value),\n );\n return ok(changed_value);\n }\n if (check) return ok(check(JSON.parse(saved)).unwrap_or(fallback));\n return ok(JSON.parse(saved) as T);\n } catch (e) {\n return ok(fallback);\n }\n }\n\n /**Sets value of setting, that has not been registered to a state\n * @param id unique identifier for this setting in the parent group\n * @param value value to set*/\n set(id: string, value: any) {\n if (id in this.settings)\n throw new Error(\"Settings is registered \" + this.path_id + \"/\" + id);\n localStorage[this.path_id + \"/\" + id] = JSON.stringify(value);\n }\n\n /**Registers a state to a setting\n * @param id unique identifier for this setting in the parent group\n * @param name name of setting formatted for user reading\n * @param description a description of what the setting is about formatted for user reading\n * @param state state object representing the setting's value */\n register<READ, S extends StateROAW<READ>>(\n id: string,\n name: string,\n description: string,\n state: S,\n transform?: (state: S) => PromiseLike<string>,\n ): S {\n if (id in this.settings)\n throw new Error(\"Settings already registered \" + this.path_id + \"/\" + id);\n this.settings[id] = new Setting(state, name, description);\n st.v.viewer(state, async () => {\n localStorage[this.path_id + \"/\" + id] = await (transform\n ? transform(state)\n : state.to_json());\n });\n return state;\n }\n}\n"],"mappings":";;;;AAGA,IAAI;AACJ,MAAa,+BACX,cACG;CACH,mBAAmB;AACrB;AAEA,MAAM,WAAW,aAAa;AAC9B,IAAI,mBAA8C,CAAC;AACnD,IAAI;CACF,mBAAmB,WACd,KAAK,MAAM,QAAQ,IACpB,CAAC;AACP,SAAS,IAAI,CAAC;AACd,IAAI;AACJ,MAAM,gBAAkD,CAAC;;;;;;;AAQzD,MAAa,iBACX,cACA,iBACA,MACA,gBACG;CACH,IAAI,kBAAkB,eAAe,iBAAiB,YAAY;CAClE,IAAI;CACJ,IAAI,iBAAiB,kBAAkB,iBAAiB;EACtD,UAAU,iBAAiB;EAC3B,iBAAiB,gBAAgB;EACjC,IAAI,gCACF,aAAa,8BAA8B;EAC7C,iCAAiC,OAAO,iBAAiB;GACvD,aAAa,8BACX,KAAK,UAAU,gBAAgB;EACnC,GAAG,GAAI;CACT;CACA,OAAQ,cAAc,gBAAgB,IAAI,cACxC,cACA,MACA,aACA,UAAU,UAAU,KAAA,CACtB;AACF;AAEA,IAAM,UAAN,MAAc;CACZ;CACA;CACA;CACA,YAAY,OAAuB,MAAc,aAAqB;EACpE,KAAK,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,cAAc;CACrB;AACF;;AAGA,IAAa,gBAAb,MAAa,cAAc;CACzB;CACA,WAA+C,CAAC;CAChD,aAAuD,CAAC;CACxD;CACA;CACA;CAEA,YACE,MACA,MACA,aACA,iBACA;EACA,KAAK,kBAAkB;EACvB,KAAK,UAAU;EACf,KAAK,OAAO;EACZ,KAAK,cAAc;CACrB;;;;;CAMA,e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src/settings/index.ts"],"sourcesContent":["import { ok, type Option, type ResultOk } from \"@chocbite/ts-lib/result\";\nimport st, {\n type StateJsonCompatible,\n type StateROAW,\n} from \"@chocbite/ts-lib/state\";\n\nlet name_transformer: ((name: string) => string) | undefined;\n\nconst packages = localStorage[\"settings/packageVersions\"] as string | undefined;\nlet package_versions: { [key: string]: string } = {};\ntry {\n package_versions = packages\n ? (JSON.parse(packages) as { [key: string]: string })\n : {};\n} catch (_e) {}\nlet store_package_versions_timeout: number | undefined;\nconst BOTTOM_GROUPS: { [key: string]: SettingsGroup } = {};\n\n/**Renames the settings groups of every package, the group name is the start of every stored key,\n * so an app can keep the library names, like @chocbite/ts-lib-theme, out of the local storage.\n *\n * Groups are made and read their stored values when their module is imported, so this must be called\n * in a module imported before any other module of @chocbite/ts-lib-ui\n * @param transform gets the package name of a group and returns the name to store it under*/\nexport const settings_set_name_transform = (\n transform: (name: string) => string,\n) => {\n const existing = Object.keys(BOTTOM_GROUPS);\n if (existing.length)\n console.error(\n \"settings_set_name_transform must be called before any settings group is made, call it in a module imported before any other module of @chocbite/ts-lib-ui, these groups already use their name: \" +\n existing.join(\", \"),\n );\n name_transformer = transform;\n};\n\n/**Initialises the settings for the package\n * @param package_name use import {name} from (\"../package.json\")\n * @param package_version use import {version} from (\"../package.json\")\n * @param versionChanged function to call when the version of the package changed\n * @param name name of group formatted for user reading\n * @param description a description of what the setting group is about*/\nexport const settings_init = (\n package_name: string,\n package_version: string,\n name: string,\n description: string,\n) => {\n if (name_transformer) package_name = name_transformer(package_name);\n if (package_name in BOTTOM_GROUPS)\n throw new Error(\n \"Settings group already registered \" +\n package_name +\n \", by another package or by this library being loaded twice\",\n );\n let changed: string | undefined;\n if (package_versions[package_name] !== package_version) {\n changed = package_versions[package_name];\n package_versions[package_name] = package_version;\n if (store_package_versions_timeout)\n clearTimeout(store_package_versions_timeout);\n store_package_versions_timeout = window.setTimeout(() => {\n localStorage[\"settings/packageVersions\"] =\n JSON.stringify(package_versions);\n }, 1000);\n }\n return (BOTTOM_GROUPS[package_name] = new SettingsGroup(\n package_name,\n name,\n description,\n changed ? changed : undefined,\n ));\n};\n\n/**Values JSON can store, Map, Set, Date, class instances, functions and undefined are not accepted*/\nexport type SettingsJson =\n | string\n | number\n | boolean\n | null\n | readonly SettingsJson[]\n | { readonly [key: string]: SettingsJson | undefined };\n\nclass Setting {\n readonly state: StateROAW<any>;\n readonly name: string;\n readonly description: string;\n constructor(state: StateROAW<any>, name: string, description: string) {\n this.state = state;\n this.name = name;\n this.description = description;\n }\n}\n\n/**Group of settings should never be instantiated manually use initSettings*/\nexport class SettingsGroup {\n private path_id: string;\n private settings: { [key: string]: Setting } = {};\n private sub_groups: { [key: string]: SettingsGroup } = {};\n /**Ids already migrated for the version change, a migration runs once per id*/\n #migrated = new Set<string>();\n readonly version_changed: string | undefined;\n readonly name: string;\n readonly description: string;\n\n constructor(\n path: string,\n name: string,\n description: string,\n version_changed?: string,\n ) {\n this.version_changed = version_changed;\n this.path_id = path;\n this.name = name;\n this.description = description;\n }\n\n /**Makes a settings 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 in this.sub_groups)\n throw new Error(\"Sub group already registered \" + id);\n return (this.sub_groups[id] = new SettingsGroup(\n this.path_id + \"/\" + id,\n name,\n description,\n this.version_changed,\n ));\n }\n\n /**Gets value of setting or fallbacks to default\n * @param id unique identifier for this setting in the parent group\n * @param fallback value to use if no setting is stored\n * @param check function to check if the stored value is valid, if not the fallback will be used\n * @param version_changed function called when the version of the package changed to migrate old value to new formats */\n get<T>(\n id: string,\n fallback: T,\n check?: (parsed: unknown) => Option<T>,\n version_changed?: (existing: string, oldVersion: string) => T,\n ): ResultOk<T> {\n const saved = localStorage.getItem(this.path_id + \"/\" + id);\n if (saved === null) return ok(fallback);\n try {\n if (this.version_changed && version_changed && !this.#migrated.has(id)) {\n const changed_value = version_changed(saved, this.version_changed);\n this.#migrated.add(id);\n localStorage.setItem(\n this.path_id + \"/\" + id,\n JSON.stringify(changed_value),\n );\n return ok(changed_value);\n }\n if (check) return ok(check(JSON.parse(saved)).unwrap_or(fallback));\n return ok(JSON.parse(saved) as T);\n } catch (e) {\n return ok(fallback);\n }\n }\n\n /**Sets value of setting, that has not been registered to a state\n * @param id unique identifier for this setting in the parent group\n * @param value value to set, must be a value JSON can store*/\n set(id: string, value: SettingsJson) {\n if (id in this.settings)\n throw new Error(\"Settings is registered \" + this.path_id + \"/\" + id);\n localStorage[this.path_id + \"/\" + id] = JSON.stringify(value);\n }\n\n /**Registers a state to a setting, the value is stored as JSON so its type must be JSON compatible\n * @param id unique identifier for this setting in the parent group\n * @param name name of setting formatted for user reading\n * @param description a description of what the setting is about formatted for user reading\n * @param state state object representing the setting's value */\n register<READ, S extends StateROAW<READ>>(\n id: string,\n name: string,\n description: string,\n state: S & (StateJsonCompatible<S> extends true ? unknown : never),\n ): S;\n /**Registers a state to a setting, with a transform to store values JSON can not represent\n * @param id unique identifier for this setting in the parent group\n * @param name name of setting formatted for user reading\n * @param description a description of what the setting is about formatted for user reading\n * @param state state object representing the setting's value\n * @param transform converts the state value to the stored string */\n register<READ, S extends StateROAW<READ>>(\n id: string,\n name: string,\n description: string,\n state: S,\n transform: (state: S) => PromiseLike<string>,\n ): S;\n register<READ, S extends StateROAW<READ>>(\n id: string,\n name: string,\n description: string,\n state: S,\n transform?: (state: S) => PromiseLike<string>,\n ): S {\n if (id in this.settings)\n throw new Error(\"Settings already registered \" + this.path_id + \"/\" + id);\n this.settings[id] = new Setting(state, name, description);\n st.v.viewer(state, async () => {\n localStorage[this.path_id + \"/\" + id] = await (transform\n ? transform(state)\n : state.to_json());\n });\n return state;\n }\n}\n"],"mappings":";;;;AAMA,IAAI;AAEJ,MAAM,WAAW,aAAa;AAC9B,IAAI,mBAA8C,CAAC;AACnD,IAAI;CACF,mBAAmB,WACd,KAAK,MAAM,QAAQ,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CAOA,IACE,IACA,UACA,OACA,iBACa;EACb,MAAM,QAAQ,aAAa,QAAQ,KAAK,UAAU,MAAM,EAAE;EAC1D,IAAI,UAAU,MAAM,OAAO,GAAG,QAAQ;EACtC,IAAI;GACF,IAAI,KAAK,mBAAmB,mBAAmB,CAAC,KAAK,UAAU,IAAI,EAAE,GAAG;IACtE,MAAM,gBAAgB,gBAAgB,OAAO,KAAK,eAAe;IACjE,KAAK,UAAU,IAAI,EAAE;IACrB,aAAa,QACX,KAAK,UAAU,MAAM,IACrB,KAAK,UAAU,aAAa,CAC9B;IACA,OAAO,GAAG,aAAa;GACzB;GACA,IAAI,OAAO,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC,UAAU,QAAQ,CAAC;GACjE,OAAO,GAAG,KAAK,MAAM,KAAK,CAAM;EAClC,SAAS,GAAG;GACV,OAAO,GAAG,QAAQ;EACpB;CACF;;;;CAKA,IAAI,IAAY,OAAqB;EACnC,IAAI,MAAM,KAAK,UACb,MAAM,IAAI,MAAM,4BAA4B,KAAK,UAAU,MAAM,EAAE;EACrE,aAAa,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,KAAK;CAC9D;CA0BA,SACE,IACA,MACA,aACA,SACA,WACG;EACH,IAAI,MAAM,KAAK,UACb,MAAM,IAAI,MAAM,iCAAiC,KAAK,UAAU,MAAM,EAAE;EAC1E,KAAK,SAAS,MAAM,IAAI,QAAQA,SAAO,MAAM,WAAW;EACxD,MAAG,EAAE,OAAOA,SAAO,YAAY;GAC7B,aAAa,KAAK,UAAU,MAAM,MAAM,OAAO,YAC3C,UAAUA,OAAK,IACfA,QAAM,QAAQ;EACpB,CAAC;EACD,OAAOA;CACT;AACF"}
@@ -1,5 +1,5 @@
1
1
  import '../style.css';
2
- import { u as Base } from "../index-BND79jZp.mjs";
2
+ import { l as Base } from "../index-CvzH3M_5.mjs";
3
3
  export declare class Spinner extends Base {
4
4
  /**Returns the name used to define the element */
5
5
  static element_name(): string;
package/spinner/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import "../style.css";
2
2
  import { Base, define_element } from "../base/index.mjs";
3
- import { t as svg } from "../svg-golJPaR4.mjs";
4
- import { r as theme_init_variable_root } from "../theme-DhIVwHQw.mjs";
3
+ import { t as svg } from "../svg-1bp-yIPC.mjs";
4
+ import { i as theme_init_variable_root } from "../theme-DlD5P5tY.mjs";
5
5
  import { GREY } from "@chocbite/ts-lib/colors";
6
6
  // src/spinner/index.ts
7
7
  theme_init_variable_root("spinners", "Spinner", "Spinner used as a placeholder for data with and unknown arrival time").make_variable("color", "Dot color", "Color of dots in spinner", GREY["700"], GREY["300"], "Color", void 0);
@@ -0,0 +1,36 @@
1
+ import '../style.css';
2
+ /**How the nodes for the values of an array are made, updated and removed*/
3
+ interface StateUIArrayApplyHandlers<T, N extends ChildNode> {
4
+ /**Gives the node for a value*/
5
+ create: (value: T) => N;
6
+ /**Updates a node to a new value, when given nodes are reused, otherwise nodes of changed values are replaced*/
7
+ update?: (node: N, value: T) => void;
8
+ /**Called for every node that is removed or replaced*/
9
+ destroy?: (node: N) => void;
10
+ }
11
+ /**Applies an array to the child nodes of a parent, one node per value.
12
+ * Arrays from array states carry what changed, so only the changed nodes are touched,
13
+ * a plain array is applied as a whole, reusing existing nodes when update is given.
14
+ * @param parent node holding the nodes for the array, it must contain nothing else
15
+ * @param array new value of the array
16
+ * @param handlers make, update and remove the nodes*/
17
+ declare function apply<T, N extends ChildNode>(parent: ParentNode, array: readonly T[], handlers: StateUIArrayApplyHandlers<T, N>): void;
18
+ /**Array states shown in the document*/
19
+ declare const ARRAY_UI: {
20
+ /**Applies an array to the child nodes of a parent, one node per value.
21
+ * Arrays from array states carry what changed, so only the changed nodes are touched,
22
+ * a plain array is applied as a whole, reusing existing nodes when update is given.
23
+ * @param parent node holding the nodes for the array, it must contain nothing else
24
+ * @param array new value of the array
25
+ * @param handlers make, update and remove the nodes*/
26
+ apply: typeof apply;
27
+ };
28
+ /**Shows states of @chocbite/ts-lib/state in the document*/
29
+ export declare const state_ui: {
30
+ /**Array states, applies arrays to child nodes*/
31
+ a: typeof ARRAY_UI;
32
+ /**Array states, applies arrays to child nodes*/
33
+ array: typeof ARRAY_UI;
34
+ };
35
+ export { type StateUIArrayApplyHandlers, state_ui as default };
36
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,2 @@
1
+ import "../style.css";
2
+ export { t as default, t as state_ui } from "../state-OCzEmq3j.mjs";
@@ -0,0 +1,87 @@
1
+ import "./style.css";
2
+ import state from "@chocbite/ts-lib/state";
3
+ // src/state/array.ts
4
+ /**Applies an array to the child nodes of a parent, one node per value.
5
+ * Arrays from array states carry what changed, so only the changed nodes are touched,
6
+ * a plain array is applied as a whole, reusing existing nodes when update is given.
7
+ * @param parent node holding the nodes for the array, it must contain nothing else
8
+ * @param array new value of the array
9
+ * @param handlers make, update and remove the nodes*/
10
+ function apply(parent, array, handlers) {
11
+ const { create, update, destroy } = handlers;
12
+ const nodes = parent.childNodes;
13
+ const remove = (node) => {
14
+ destroy?.(node);
15
+ node.remove();
16
+ };
17
+ for (const change of state.a.read(array)) switch (change.type) {
18
+ case "fresh":
19
+ if (update) {
20
+ const reused = Math.min(nodes.length, change.items.length);
21
+ for (let i = 0; i < reused; i++) update(nodes[i], change.items[i]);
22
+ while (nodes.length > change.items.length) remove(nodes[nodes.length - 1]);
23
+ parent.append(...change.items.slice(reused).map((v) => create(v)));
24
+ } else {
25
+ if (destroy) for (const node of [...nodes]) destroy(node);
26
+ parent.replaceChildren(...change.items.map((v) => create(v)));
27
+ }
28
+ break;
29
+ case "added": {
30
+ const created = change.items.map((v) => create(v));
31
+ const next = nodes[change.index];
32
+ if (next) next.before(...created);
33
+ else parent.append(...created);
34
+ break;
35
+ }
36
+ case "removed":
37
+ for (let i = 0; i < change.items.length; i++) {
38
+ const node = nodes[change.index];
39
+ if (node) remove(node);
40
+ }
41
+ break;
42
+ case "changed":
43
+ for (let i = 0; i < change.items.length; i++) {
44
+ const node = nodes[change.index + i];
45
+ if (!node) continue;
46
+ if (update) update(node, change.items[i]);
47
+ else {
48
+ destroy?.(node);
49
+ node.replaceWith(create(change.items[i]));
50
+ }
51
+ }
52
+ break;
53
+ case "moved": {
54
+ const moved = [];
55
+ for (let i = 0; i < change.items.length; i++) {
56
+ const node = nodes[change.from_index];
57
+ if (!node) break;
58
+ moved.push(node);
59
+ node.remove();
60
+ }
61
+ const next = nodes[change.to_index];
62
+ if (next) next.before(...moved);
63
+ else parent.append(...moved);
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ /**Array states shown in the document*/
69
+ const ARRAY_UI = {
70
+ /**Applies an array to the child nodes of a parent, one node per value.
71
+ * Arrays from array states carry what changed, so only the changed nodes are touched,
72
+ * a plain array is applied as a whole, reusing existing nodes when update is given.
73
+ * @param parent node holding the nodes for the array, it must contain nothing else
74
+ * @param array new value of the array
75
+ * @param handlers make, update and remove the nodes*/
76
+ apply };
77
+ // src/state/index.ts
78
+ /**Shows states of @chocbite/ts-lib/state in the document*/
79
+ const state_ui = {
80
+ /**Array states, applies arrays to child nodes*/
81
+ a: ARRAY_UI,
82
+ /**Array states, applies arrays to child nodes*/
83
+ array: ARRAY_UI
84
+ };
85
+ export { state_ui as t };
86
+
87
+ //# sourceMappingURL=state-OCzEmq3j.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-OCzEmq3j.mjs","names":[],"sources":["../src/state/array.ts","../src/state/index.ts"],"sourcesContent":["import state from \"@chocbite/ts-lib/state\";\n\n/**How the nodes for the values of an array are made, updated and removed*/\nexport interface StateUIArrayApplyHandlers<T, N extends ChildNode> {\n /**Gives the node for a value*/\n create: (value: T) => N;\n /**Updates a node to a new value, when given nodes are reused, otherwise nodes of changed values are replaced*/\n update?: (node: N, value: T) => void;\n /**Called for every node that is removed or replaced*/\n destroy?: (node: N) => void;\n}\n\n/**Applies an array to the child nodes of a parent, one node per value.\n * Arrays from array states carry what changed, so only the changed nodes are touched,\n * a plain array is applied as a whole, reusing existing nodes when update is given.\n * @param parent node holding the nodes for the array, it must contain nothing else\n * @param array new value of the array\n * @param handlers make, update and remove the nodes*/\nfunction apply<T, N extends ChildNode>(\n parent: ParentNode,\n array: readonly T[],\n handlers: StateUIArrayApplyHandlers<T, N>,\n): void {\n const { create, update, destroy } = handlers;\n //Live list, it follows every change made below\n const nodes = parent.childNodes as NodeListOf<N>;\n const remove = (node: N) => {\n destroy?.(node);\n node.remove();\n };\n for (const change of state.a.read(array)) {\n switch (change.type) {\n case \"fresh\": {\n if (update) {\n const reused = Math.min(nodes.length, change.items.length);\n for (let i = 0; i < reused; i++) update(nodes[i], change.items[i]);\n while (nodes.length > change.items.length)\n remove(nodes[nodes.length - 1]);\n parent.append(...change.items.slice(reused).map((v) => create(v)));\n } else {\n if (destroy) for (const node of [...nodes]) destroy(node);\n parent.replaceChildren(...change.items.map((v) => create(v)));\n }\n break;\n }\n case \"added\": {\n const created = change.items.map((v) => create(v));\n const next = nodes[change.index];\n if (next) next.before(...created);\n else parent.append(...created);\n break;\n }\n case \"removed\":\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.index];\n if (node) remove(node);\n }\n break;\n case \"changed\":\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.index + i];\n if (!node) continue;\n if (update) update(node, change.items[i]);\n else {\n destroy?.(node);\n node.replaceWith(create(change.items[i]));\n }\n }\n break;\n case \"moved\": {\n const moved: N[] = [];\n //Every removal moves the next node to from_index\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.from_index];\n if (!node) break;\n moved.push(node);\n node.remove();\n }\n const next = nodes[change.to_index];\n if (next) next.before(...moved);\n else parent.append(...moved);\n break;\n }\n }\n }\n}\n\n/**Array states shown in the document*/\nexport const ARRAY_UI = {\n /**Applies an array to the child nodes of a parent, one node per value.\n * Arrays from array states carry what changed, so only the changed nodes are touched,\n * a plain array is applied as a whole, reusing existing nodes when update is given.\n * @param parent node holding the nodes for the array, it must contain nothing else\n * @param array new value of the array\n * @param handlers make, update and remove the nodes*/\n apply,\n};\n","import { ARRAY_UI } from \"./array\";\n\n/**Shows states of @chocbite/ts-lib/state in the document*/\nexport const state_ui = {\n //The \"as typeof\" casts make the declaration output reference the helper objects instead of inlining\n //their types, inlining would drop the doc comments on their members\n /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\n /**Array states, applies arrays to child nodes*/\n a: ARRAY_UI as typeof ARRAY_UI,\n /**Array states, applies arrays to child nodes*/\n array: ARRAY_UI as typeof ARRAY_UI,\n /* eslint-enable @typescript-eslint/no-unnecessary-type-assertion */\n};\nexport default state_ui;\n\nexport type { StateUIArrayApplyHandlers } from \"./array\";\n"],"mappings":";;;;;;;;;AAkBA,SAAS,MACP,QACA,OACA,UACM;CACN,MAAM,EAAE,QAAQ,QAAQ,YAAY;CAEpC,MAAM,QAAQ,OAAO;CACrB,MAAM,UAAU,SAAY;EAC1B,UAAU,IAAI;EACd,KAAK,OAAO;CACd;CACA,KAAK,MAAM,UAAU,MAAM,EAAE,KAAK,KAAK,GACrC,QAAQ,OAAO,MAAf;EACE,KAAK;GACH,IAAI,QAAQ;IACV,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,OAAO,MAAM,MAAM;IACzD,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,OAAO,MAAM,IAAI,OAAO,MAAM,EAAE;IACjE,OAAO,MAAM,SAAS,OAAO,MAAM,QACjC,OAAO,MAAM,MAAM,SAAS,EAAE;IAChC,OAAO,OAAO,GAAG,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC;GACnE,OAAO;IACL,IAAI,SAAS,KAAK,MAAM,QAAQ,CAAC,GAAG,KAAK,GAAG,QAAQ,IAAI;IACxD,OAAO,gBAAgB,GAAG,OAAO,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC;GAC9D;GACA;EAEF,KAAK,SAAS;GACZ,MAAM,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC;GACjD,MAAM,OAAO,MAAM,OAAO;GAC1B,IAAI,MAAM,KAAK,OAAO,GAAG,OAAO;QAC3B,OAAO,OAAO,GAAG,OAAO;GAC7B;EACF;EACA,KAAK;GACH,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,MAAM,QAAQ,KAAK;IAC5C,MAAM,OAAO,MAAM,OAAO;IAC1B,IAAI,MAAM,OAAO,IAAI;GACvB;GACA;EACF,KAAK;GACH,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,MAAM,QAAQ,KAAK;IAC5C,MAAM,OAAO,MAAM,OAAO,QAAQ;IAClC,IAAI,CAAC,MAAM;IACX,IAAI,QAAQ,OAAO,MAAM,OAAO,MAAM,EAAE;SACnC;KACH,UAAU,IAAI;KACd,KAAK,YAAY,OAAO,OAAO,MAAM,EAAE,CAAC;IAC1C;GACF;GACA;EACF,KAAK,SAAS;GACZ,MAAM,QAAa,CAAC;GAEpB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,MAAM,QAAQ,KAAK;IAC5C,MAAM,OAAO,MAAM,OAAO;IAC1B,IAAI,CAAC,MAAM;IACX,MAAM,KAAK,IAAI;IACf,KAAK,OAAO;GACd;GACA,MAAM,OAAO,MAAM,OAAO;GAC1B,IAAI,MAAM,KAAK,OAAO,GAAG,KAAK;QACzB,OAAO,OAAO,GAAG,KAAK;GAC3B;EACF;CACF;AAEJ;;AAGA,MAAa,WAAW;;;;;;;AAOtB,MACF;;;AC7FA,MAAa,WAAW;;CAKtB,GAAG;;CAEH,OAAO;AAET"}
package/style.css CHANGED
@@ -1086,6 +1086,7 @@ form-stepper {
1086
1086
  cursor: ew-resize;
1087
1087
  outline: none;
1088
1088
  touch-action: pan-y;
1089
+ position: relative;
1089
1090
  }
1090
1091
  .touch form-stepper {
1091
1092
  min-width: 14rem;
@@ -1687,9 +1688,9 @@ form-datetimeinput > svg {
1687
1688
  width: auto;
1688
1689
  height: calc(var(--form-size-height) / 1.3);
1689
1690
  }
1690
- form-datetimeinput > input[type=date] ~ svg[icon=material_action_calendar_month_rounded],
1691
- form-datetimeinput > input[type=time] ~ svg[icon=material_action_schedule_rounded],
1692
- form-datetimeinput > input[type=datetime-local] ~ svg[icon=material_action_calendar_month_rounded] {
1691
+ form-datetimeinput > input[type=date] ~ svg[icon=material_calendar_month_rounded],
1692
+ form-datetimeinput > input[type=time] ~ svg[icon=material_schedule_rounded],
1693
+ form-datetimeinput > input[type=datetime-local] ~ svg[icon=material_calendar_month_rounded] {
1693
1694
  display: block;
1694
1695
  }
1695
1696
  form-ipinput {
@@ -1926,8 +1927,8 @@ form-textmultiline > textarea {
1926
1927
  box-sizing: border-box;
1927
1928
  outline: none;
1928
1929
  width: 100%;
1929
- min-height: var(--form-size-height)-0.2rem;
1930
- height: var(--form-size-height)-0.2rem;
1930
+ min-height: calc(var(--form-size-height) - 0.2rem);
1931
+ height: calc(var(--form-size-height) - 0.2rem);
1931
1932
  border-radius: 0.4rem;
1932
1933
  }
1933
1934
  .touch form-textmultiline > textarea {
@@ -2264,7 +2265,7 @@ spinner-spinner > svg {
2264
2265
  max-width: 100%;
2265
2266
  }
2266
2267
  spinner-spinner > svg > circle {
2267
- fill: var(--\@chocolatelibui\/spinners\/color);
2268
+ fill: var(--spinners-color);
2268
2269
  animation: spinner 1.2s calc((var(--i) - 12) * 0.1s) infinite;
2269
2270
  }
2270
2271
  spinner-spinner > svg > circle:nth-child(1) {
@@ -2720,6 +2721,12 @@ list-addrow > span:hover {
2720
2721
  list-addrow > span:active {
2721
2722
  box-shadow: 0 0rem 0.2rem 0rem var(--list-colors-border-header);
2722
2723
  }
2724
+ list-addrow > span svg {
2725
+ fill: var(--list-colors-icon-add_icon);
2726
+ height: 1.2em;
2727
+ width: auto;
2728
+ margin-right: 0.3rem;
2729
+ }
2723
2730
  list-keyfield {
2724
2731
  --list-row-size: var(--list-size-row_min);
2725
2732
  }
@@ -2889,7 +2896,7 @@ list-container > div > list-headerrow > * {
2889
2896
  position: sticky;
2890
2897
  border-bottom: 1px solid var(--list-colors-border-header);
2891
2898
  background-color: var(--list-colors-background-row_even);
2892
- z-index: 1;
2899
+ z-index: 999;
2893
2900
  }
2894
2901
  list-container > div > list-headerrow > *:first-child {
2895
2902
  left: 0;
package/svg/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import '../style.css';
2
- import { n as svg, r as SVGAnchorPoint, t as SVGFunc } from "../index-BcidwqIy.mjs";
2
+ import { n as svg, r as SVGAnchorPoint, t as SVGFunc } from "../index-BDWg5GX2.mjs";
3
3
  export { SVGAnchorPoint, SVGFunc, svg };
package/svg/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import "../style.css";
2
- export { n as SVGAnchorPoint, t as svg } from "../svg-golJPaR4.mjs";
2
+ export { n as SVGAnchorPoint, t as svg } from "../svg-1bp-yIPC.mjs";
@@ -118,18 +118,20 @@ function ellipse(center_x, center_y, radius_x, radius_y) {
118
118
  * @param center_y the center point on the y axis
119
119
  * @param radius_x radius in x axis
120
120
  * @param radius_y radius in y axis
121
- * @param start_angle start angle in radians
122
- * @param end_angle end anglein radians*/
121
+ * @param start_angle start angle in degrees
122
+ * @param end_angle end angle in degrees, a sweep of 360 degrees or more draws the whole ellipse*/
123
123
  function ellipse_arc(center_x, center_y, radius_x, radius_y, start_angle, end_angle) {
124
124
  const start_radian = degrees_to_radians(start_angle);
125
- end_angle = degrees_to_radians(end_angle - start_angle);
126
- const s_x = radius_x * Math.cos(start_radian) + center_x;
127
- const s_y = radius_y * Math.sin(start_radian) + center_y;
128
- const e_x = radius_x * Math.cos(start_radian + end_angle) + center_x;
129
- const e_y = radius_y * Math.sin(start_radian + end_angle) + center_y;
130
- const f_a = end_angle > Math.PI ? 1 : 0;
131
- const f_s = end_angle > 0 ? 1 : 0;
132
- return create_svg_element("path").a("d", `M ${s_x} ${s_y} A ${radius_x} ${radius_y} 0 ${f_a} ${f_s} ${e_x} ${e_y}`);
125
+ const sweep = degrees_to_radians(end_angle - start_angle);
126
+ const point = (radian) => `${radius_x * Math.cos(radian) + center_x} ${radius_y * Math.sin(radian) + center_y}`;
127
+ const f_s = sweep > 0 ? 1 : 0;
128
+ const arc = `A ${radius_x} ${radius_y} 0`;
129
+ if (Math.abs(sweep) >= 2 * Math.PI) {
130
+ const half = start_radian + (sweep > 0 ? Math.PI : -Math.PI);
131
+ return create_svg_element("path").a("d", `M ${point(start_radian)} ${arc} 0 ${f_s} ${point(half)} ${arc} 0 ${f_s} ${point(start_radian)}`);
132
+ }
133
+ const f_a = Math.abs(sweep) > Math.PI ? 1 : 0;
134
+ return create_svg_element("path").a("d", `M ${point(start_radian)} ${arc} ${f_a} ${f_s} ${point(start_radian + sweep)}`);
133
135
  }
134
136
  // src/svg/primitives/circle.ts
135
137
  /**This creates a svg circle
@@ -147,8 +149,8 @@ function circle(center_x, center_y, radius) {
147
149
  * @param center_x the center point on the x axis
148
150
  * @param center_y the center point on the y axis
149
151
  * @param radius radius in x axis
150
- * @param start_angle start angle in radians
151
- * @param end_angle end anglein radians*/
152
+ * @param start_angle start angle in degrees
153
+ * @param end_angle end angle in degrees, a sweep of 360 degrees or more draws the whole circle*/
152
154
  function circle_arc(center_x, center_y, radius, start_angle, end_angle) {
153
155
  return ellipse_arc(center_x, center_y, radius, radius, start_angle, end_angle);
154
156
  }
@@ -219,7 +221,7 @@ const SVGAnchorPoint = {
219
221
  * @param anchor anchor point of text*/
220
222
  function text(x, y, text, size, anchor) {
221
223
  const text_elem = create_svg_element("text").a("x", String(x)).a("y", String(y)).a("font-size", String(size));
222
- text_elem.elem.innerHTML = text;
224
+ text_elem.elem.textContent = text;
223
225
  switch (anchor) {
224
226
  case SVGAnchorPoint.bottomLeft:
225
227
  case SVGAnchorPoint.middleLeft:
@@ -271,7 +273,7 @@ function multi_line_text(x, y, width, height, text, size, anchor) {
271
273
  text_div.style.width = "100%";
272
274
  text_div.style.height = "100%";
273
275
  text_div.style.display = "flex";
274
- text_div.innerHTML = text;
276
+ text_div.textContent = text;
275
277
  switch (anchor) {
276
278
  case SVGAnchorPoint.bottomLeft:
277
279
  case SVGAnchorPoint.middleLeft:
@@ -321,9 +323,10 @@ function isosceles_triangle(center_x, center_y, width, height) {
321
323
  }
322
324
  // src/svg/util/angleToAnchorPoint.ts
323
325
  /**Converts an angle to an anchor point
324
- * @param angle angle in radians*/
326
+ * @param angle angle in radians, any angle outside 0 to 2PI is wrapped around*/
325
327
  const angle_to_anchor_point = (angle) => {
326
- const sec = angle >= 0 ? angle % 6.283185307179586 : -(angle % 6.283185307179586);
328
+ const full = 6.283185307179586;
329
+ const sec = (angle % full + full) % full;
327
330
  if (sec > 5.93411945678072) return SVGAnchorPoint.middleRight;
328
331
  else if (sec > 4.974188368183839) return SVGAnchorPoint.topRight;
329
332
  else if (sec > 4.45058959258554) return SVGAnchorPoint.topCenter;
@@ -355,4 +358,4 @@ const svg = {
355
358
  };
356
359
  export { SVGAnchorPoint as n, svg as t };
357
360
 
358
- //# sourceMappingURL=svg-golJPaR4.mjs.map
361
+ //# sourceMappingURL=svg-1bp-yIPC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg-1bp-yIPC.mjs","names":["svg","svgsvg"],"sources":["../src/svg/attributes.ts","../src/svg/shared.ts","../src/svg/primitives/shared.ts","../src/svg/primitives/ellipse.ts","../src/svg/primitives/circle.ts","../src/svg/primitives/group.ts","../src/svg/primitives/line.ts","../src/svg/primitives/path.ts","../src/svg/primitives/rectangle.ts","../src/svg/primitives/svg.ts","../src/svg/util/anchorPoint.ts","../src/svg/primitives/text.ts","../src/svg/primitives/triangle.ts","../src/svg/util/angleToAnchorPoint.ts","../src/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;;CAE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K,eAAe;EACpB,KAAK,eAAe,UAClB,SAAS,MAAM,aAAa;CAGhC;CACA,OAAO;AACT;;;;;;;ACjIA,SAAgB,mBACd,UACA,UACA,OACA,QAC+B;CAC/B,MAAM,SAAS,QAAQ;CACvB,MAAM,SAAS,SAAS;CACxB,OAAO,mBAAmB,MAAM,CAAC,CAAC,EAChC,KACA,OACG,WAAW,UACZ,OACC,WAAW,UACZ,OACC,WAAW,UACZ,OACC,WAAW,UACZ,MACA,WACA,OACC,WAAW,UACZ,GACJ;AACF;;;;AC5BA,MAAa,yBAAyB,UAAkB;CACtD,MAAM,OAAO;CACb,MAAM,OAAQ,QAAQ,OAAQ,QAAQ;CACtC,IAAI,MAAM,kBACR,OAAO,eAAe;MACjB,IAAI,MAAM,mBACf,OAAO,eAAe;MACjB,IAAI,MAAM,kBACf,OAAO,eAAe;MACjB,IAAI,MAAM,mBACf,OAAO,eAAe;MACjB,IAAI,MAAM,mBACf,OAAO,eAAe;MACjB,IAAI,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/theme/index.d.mts CHANGED
@@ -1,11 +1,15 @@
1
1
  import '../style.css';
2
- import { t as SVGFunc } from "../index-BcidwqIy.mjs";
2
+ import { t as SVGFunc } from "../index-BDWg5GX2.mjs";
3
3
  export declare const BUILT_IN = 0;
4
4
  export declare const Themes: {
5
5
  readonly Light: "light";
6
6
  readonly Dark: "dark";
7
+ /**Follows the light or dark mode of the operating system, only offered when theme_init enables system*/
8
+ readonly System: "system";
7
9
  };
8
10
  export type Themes = (typeof Themes)[keyof typeof Themes];
11
+ /**Themes that can be applied to the page, System is resolved to one of these*/
12
+ type AppliedThemes = typeof Themes.Light | typeof Themes.Dark;
9
13
  export declare const THEME: import("@chocbite/ts-lib/state").StateROSW<Themes, import("@chocbite/ts-lib/result").OptionSome<import("@chocbite/ts-lib/state").StateEnumRelated<{
10
14
  light: {
11
15
  name: string;
@@ -17,6 +21,11 @@ export declare const THEME: import("@chocbite/ts-lib/state").StateROSW<Themes, i
17
21
  description?: string;
18
22
  icon?: SVGFunc;
19
23
  };
24
+ system: {
25
+ name: string;
26
+ description?: string;
27
+ icon?: SVGFunc;
28
+ };
20
29
  }>>, Themes>;
21
30
  export declare const SCALE: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionSome<import("@chocbite/ts-lib/state").StateNumberRelated>, number>;
22
31
  export declare const ScrollbarModes: {
@@ -93,6 +102,16 @@ export declare const ANIMATION_SPEED: import("@chocbite/ts-lib/state").StateROSW
93
102
  export declare function rem_to_px(rem: number): number;
94
103
  /**Converts the given pixels to rems */
95
104
  export declare function px_to_rem(px: number): number;
105
+ interface ThemeInitOptions {
106
+ /**Offers a System theme that follows the light or dark mode of the operating system,
107
+ * leave it off on devices without that feature*/
108
+ system?: boolean;
109
+ /**Theme used until the user chooses one, defaults to System when system is on, otherwise Light*/
110
+ default?: Themes;
111
+ }
112
+ /**Starts the theme, the app must call it once, nothing of the theme is applied to the page before.
113
+ * This is the only place the operating system dark mode is read, and only when system is on*/
114
+ export declare function theme_init(options?: ThemeInitOptions): void;
96
115
  /**Initialises the settings for the package
97
116
  * @param package_name use import {name} from "../package.json"
98
117
  * @param name name of group formatted for user reading
@@ -175,5 +194,5 @@ interface VariableType {
175
194
  };
176
195
  } | number;
177
196
  }
178
- export {};
197
+ export type { AppliedThemes, ThemeInitOptions };
179
198
  //# sourceMappingURL=index.d.mts.map
package/theme/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import "../style.css";
2
- export { o as ANIMATION_LEVEL, s as ANIMATION_SPEED, c as AnimationLevels, t as BUILT_IN, l as INPUT_MODE, u as InputModes, d as SCALE, f as SCROLLBAR_MODE, p as ScrollbarModes, m as THEME, n as ThemeVariableGroup, h as Themes, i as px_to_rem, a as rem_to_px, r as theme_init_variable_root } from "../theme-DhIVwHQw.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-DlD5P5tY.mjs";