cotomy 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Cotomy
2
2
 
3
- A lightweight framework for managing form behavior and page controllers in web applications.
4
- Ideal for SPA (Single Page Application) or traditional web apps with dynamic form operations.
3
+ > This library targets ES2020+.
4
+ > For older browsers (e.g. iOS 13 or IE), you will need a Polyfill such as `core-js`.
5
+
6
+ **Cotomy** is a lightweight framework for managing form behavior and page controllers in web applications.
7
+ It is suitable for both SPAs (Single Page Applications) and traditional web apps requiring dynamic form operations.
8
+
9
+ ⚠️ **Warning**: This project is in early development. APIs may change without notice until version 1.0.0.
5
10
 
6
- ## Installation
7
11
 
8
12
  To install Cotomy in your project, run the following command:
9
13
 
@@ -37,14 +41,12 @@ By passing HTML and CSS strings to the constructor, it is possible to generate E
37
41
  });
38
42
  ```
39
43
 
40
- ## License
44
+ - `"display HTML in character literals with color coding"` → `"syntax highlighting for embedded HTML"`
45
+ - `"generate Element designs with a limited scope"` → `"generate scoped DOM elements with associated styles"`
41
46
 
42
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
43
-
44
- ## Warning
47
+ ## License
45
48
 
46
- This project is in its early stages, and the API is still evolving.
47
- Since the version is below `1.0.0`, breaking changes may occur without prior notice.
49
+ This project is licensed under the [MIT License](LICENSE).
48
50
 
49
51
  ## Contact
50
52
 
package/dist/api.d.ts CHANGED
@@ -1,31 +1,31 @@
1
1
  import { CotomyElement } from "./view";
2
- export declare class CotomyRestApiException extends Error {
2
+ export declare class CotomyApiException extends Error {
3
3
  readonly status: number;
4
4
  readonly message: string;
5
- readonly response: CotomyRestApiResponse;
5
+ readonly response: CotomyApiResponse;
6
6
  readonly bodyText: string;
7
- constructor(status: number, message: string, response: CotomyRestApiResponse, bodyText?: string);
7
+ constructor(status: number, message: string, response: CotomyApiResponse, bodyText?: string);
8
8
  }
9
- export declare class CotomyHttpClientError extends CotomyRestApiException {
10
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
9
+ export declare class CotomyHttpClientError extends CotomyApiException {
10
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
11
11
  }
12
12
  export declare class CotomyUnauthorizedException extends CotomyHttpClientError {
13
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
13
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
14
14
  }
15
15
  export declare class CotomyForbiddenException extends CotomyHttpClientError {
16
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
16
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
17
17
  }
18
18
  export declare class CotomyNotFoundException extends CotomyHttpClientError {
19
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
19
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
20
20
  }
21
21
  export declare class CotomyConflictException extends CotomyHttpClientError {
22
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
22
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
23
23
  }
24
24
  export declare class CotomyValidationException extends CotomyHttpClientError {
25
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
25
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
26
26
  }
27
- export declare class CotomyHttpServerError extends CotomyRestApiException {
28
- constructor(status: number, message: string, response: CotomyRestApiResponse, body?: string);
27
+ export declare class CotomyHttpServerError extends CotomyApiException {
28
+ constructor(status: number, message: string, response: CotomyApiResponse, body?: string);
29
29
  }
30
30
  export declare class CotomyResponseJsonParseException extends Error {
31
31
  constructor(message?: string);
@@ -33,7 +33,7 @@ export declare class CotomyResponseJsonParseException extends Error {
33
33
  export declare class CotomyInvalidFormDataBodyException extends Error {
34
34
  constructor(message?: string);
35
35
  }
36
- export declare class CotomyRestApiResponse {
36
+ export declare class CotomyApiResponse {
37
37
  private readonly _response?;
38
38
  private _json;
39
39
  private _map;
@@ -60,9 +60,9 @@ export declare class CotomyViewRenderer {
60
60
  renderer(type: string, callback: (element: CotomyElement, value: any) => void): this;
61
61
  get initialized(): boolean;
62
62
  protected initialize(): this;
63
- applyAsync(respose: CotomyRestApiResponse): Promise<this>;
63
+ applyAsync(respose: CotomyApiResponse): Promise<this>;
64
64
  }
65
- export interface ICotomyRestApiOptions {
65
+ export interface ICotomyApiOptions {
66
66
  baseUrl?: string | null;
67
67
  headers?: Record<string, string> | null;
68
68
  credentials?: RequestCredentials | null;
@@ -78,10 +78,10 @@ export interface ICotomyRestSubmitForm {
78
78
  action: string;
79
79
  body: globalThis.FormData | Record<string, string> | any;
80
80
  }
81
- export declare class CotomyRestApi {
81
+ export declare class CotomyApi {
82
82
  private readonly _options;
83
83
  private readonly _abortController;
84
- constructor(_options?: ICotomyRestApiOptions);
84
+ constructor(_options?: ICotomyApiOptions);
85
85
  get baseUrl(): string;
86
86
  get headers(): Record<string, string>;
87
87
  get credentials(): RequestCredentials;
@@ -93,14 +93,14 @@ export declare class CotomyRestApi {
93
93
  get integrity(): string;
94
94
  get abortController(): AbortController;
95
95
  private requestAsync;
96
- getAsync(path: string, parameters?: globalThis.FormData | Record<string, string | number>): Promise<CotomyRestApiResponse>;
97
- postAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
98
- putAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
99
- patchAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
100
- deleteAsync(path: string): Promise<CotomyRestApiResponse>;
101
- headAsync(path: string): Promise<CotomyRestApiResponse>;
102
- optionsAsync(path: string): Promise<CotomyRestApiResponse>;
103
- traceAsync(path: string): Promise<CotomyRestApiResponse>;
104
- connectAsync(path: string): Promise<CotomyRestApiResponse>;
105
- submitAsync(form: ICotomyRestSubmitForm): Promise<CotomyRestApiResponse>;
96
+ getAsync(path: string, parameters?: globalThis.FormData | Record<string, string | number>): Promise<CotomyApiResponse>;
97
+ postAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyApiResponse>;
98
+ putAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyApiResponse>;
99
+ patchAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyApiResponse>;
100
+ deleteAsync(path: string): Promise<CotomyApiResponse>;
101
+ headAsync(path: string): Promise<CotomyApiResponse>;
102
+ optionsAsync(path: string): Promise<CotomyApiResponse>;
103
+ traceAsync(path: string): Promise<CotomyApiResponse>;
104
+ connectAsync(path: string): Promise<CotomyApiResponse>;
105
+ submitAsync(form: ICotomyRestSubmitForm): Promise<CotomyApiResponse>;
106
106
  }
package/dist/form.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CotomyRestApi, CotomyRestApiResponse, CotomyViewRenderer } from "./api";
1
+ import { CotomyApi, CotomyApiResponse, CotomyViewRenderer } from "./api";
2
2
  import { CotomyElement } from "./view";
3
3
  export declare class CotomyActionEvent extends Event {
4
4
  action: string;
@@ -32,22 +32,31 @@ export declare class CotomyQueryForm extends CotomyForm {
32
32
  method(): string;
33
33
  protected submitAsync(e: Event): Promise<void>;
34
34
  }
35
+ export declare class CotomyApiFailedEvent extends Event {
36
+ private _response;
37
+ constructor(_response: CotomyApiResponse, eventName?: string);
38
+ get response(): CotomyApiResponse;
39
+ }
35
40
  export declare class CotomyApiForm extends CotomyForm {
36
41
  constructor(element: HTMLElement | {
37
42
  html: string;
38
43
  css?: string | null;
39
44
  } | string);
40
- apiClient(): CotomyRestApi;
45
+ apiClient(): CotomyApi;
41
46
  actionUri(): string;
42
47
  get identifier(): string | undefined;
43
- protected setIncrementedId(response: CotomyRestApiResponse): void;
48
+ protected setIncrementedId(response: CotomyApiResponse): void;
44
49
  get identifierInputs(): CotomyElement[];
45
50
  get identifierString(): string;
46
51
  get autoIncrement(): boolean;
52
+ apiFailed(handle: ((event: CotomyApiFailedEvent) => void | Promise<void>)): this;
53
+ protected triggerApiFailedEvent(response: CotomyApiResponse): void;
54
+ submitFailed(handle: ((event: CotomyApiFailedEvent) => void | Promise<void>)): this;
55
+ protected triggerSubmitFailedEvent(response: CotomyApiResponse): void;
47
56
  method(): string;
48
- formData(): globalThis.FormData;
57
+ formData(): FormData;
49
58
  protected submitAsync(e: Event): Promise<void>;
50
- protected submitToApiAsync(formData: globalThis.FormData): Promise<CotomyRestApiResponse>;
59
+ protected submitToApiAsync(formData: FormData): Promise<CotomyApiResponse>;
51
60
  }
52
61
  export declare class CotomyFillApiForm extends CotomyApiForm {
53
62
  private _fillers;
@@ -57,10 +66,10 @@ export declare class CotomyFillApiForm extends CotomyApiForm {
57
66
  } | string);
58
67
  filler(type: string, callback: (input: CotomyElement, value: any) => void): this;
59
68
  initialize(): this;
60
- protected submitToApiAsync(formData: globalThis.FormData): Promise<CotomyRestApiResponse>;
69
+ protected submitToApiAsync(formData: globalThis.FormData): Promise<CotomyApiResponse>;
61
70
  reload(): void;
62
71
  loadActionUri(): string;
63
72
  renderer(): CotomyViewRenderer;
64
- loadAsync(): Promise<CotomyRestApiResponse>;
65
- protected fillAsync(response: CotomyRestApiResponse): Promise<void>;
73
+ loadAsync(): Promise<CotomyApiResponse>;
74
+ protected fillAsync(response: CotomyApiResponse): Promise<void>;
66
75
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { CotomyConflictException, CotomyForbiddenException, CotomyHttpClientError, CotomyHttpServerError, CotomyInvalidFormDataBodyException, CotomyNotFoundException, CotomyResponseJsonParseException, CotomyRestApi, CotomyRestApiException, CotomyRestApiResponse, CotomyUnauthorizedException, CotomyValidationException, CotomyViewRenderer } from "./api";
1
+ export { CotomyApi, CotomyApiException, CotomyApiResponse, CotomyConflictException, CotomyForbiddenException, CotomyHttpClientError, CotomyHttpServerError, CotomyInvalidFormDataBodyException, CotomyNotFoundException, CotomyResponseJsonParseException, CotomyUnauthorizedException, CotomyValidationException, CotomyViewRenderer } from "./api";
2
2
  export { CotomyDebugFeature, CotomyDebugSettings } from "./debug";
3
- export { CotomyActionEvent, CotomyApiForm, CotomyFillApiForm, CotomyForm, CotomyQueryForm } from "./form";
3
+ export { CotomyActionEvent, CotomyApiFailedEvent, CotomyApiForm, CotomyFillApiForm, CotomyForm, CotomyQueryForm } from "./form";
4
4
  export { CotomyPageController, CotomyUrl } from "./page";
5
5
  export { CotomyElement, CotomyMetaElement, CotomyWindow } from "./view";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cotomy=e():t.Cotomy=e()}(this,()=>(()=>{var t={48:t=>{var e,n="undefined"!=typeof window&&(window.crypto||window.msCrypto)||"undefined"!=typeof self&&self.crypto;if(n){var r=Math.pow(2,32)-1;e=function(){return Math.abs(n.getRandomValues(new Uint32Array(1))[0]/r)}}else e=Math.random;t.exports=e},146:(t,e,n)=>{var r=n(473),i="object"==typeof window?window:self,s=Object.keys(i).length,o=r(((navigator.mimeTypes?navigator.mimeTypes.length:0)+navigator.userAgent.length).toString(36)+s.toString(36),4);t.exports=function(){return o}},353:function(t){t.exports=function(){"use strict";var t=6e4,e=36e5,n="millisecond",r="second",i="minute",s="hour",o="day",a="week",l="month",c="quarter",u="year",h="date",d="Invalid Date",m=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,E=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},p=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},y={s:p,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+p(r,2,"0")+":"+p(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,l),s=n-i<0,o=e.clone().add(r+(s?-1:1),l);return+(-(r+(n-i)/(s?i-o:o-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:l,y:u,w:a,d:o,D:h,h:s,m:i,s:r,ms:n,Q:c}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},f="en",T={};T[f]=g;var A="$isDayjsObject",R=function(t){return t instanceof O||!(!t||!t[A])},_=function t(e,n,r){var i;if(!e)return f;if("string"==typeof e){var s=e.toLowerCase();T[s]&&(i=s),n&&(T[s]=n,i=s);var o=e.split("-");if(!i&&o.length>1)return t(o[0])}else{var a=e.name;T[a]=e,i=a}return!r&&i&&(f=i),i||!r&&f},S=function(t,e){if(R(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new O(n)},D=y;D.l=_,D.i=R,D.w=function(t,e){return S(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var O=function(){function g(t){this.$L=_(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[A]=!0}var p=g.prototype;return p.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(D.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(m);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},p.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},p.$utils=function(){return D},p.isValid=function(){return!(this.$d.toString()===d)},p.isSame=function(t,e){var n=S(t);return this.startOf(e)<=n&&n<=this.endOf(e)},p.isAfter=function(t,e){return S(t)<this.startOf(e)},p.isBefore=function(t,e){return this.endOf(e)<S(t)},p.$g=function(t,e,n){return D.u(t)?this[e]:this.set(n,t)},p.unix=function(){return Math.floor(this.valueOf()/1e3)},p.valueOf=function(){return this.$d.getTime()},p.startOf=function(t,e){var n=this,c=!!D.u(e)||e,d=D.p(t),m=function(t,e){var r=D.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return c?r:r.endOf(o)},E=function(t,e){return D.w(n.toDate()[t].apply(n.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},g=this.$W,p=this.$M,y=this.$D,f="set"+(this.$u?"UTC":"");switch(d){case u:return c?m(1,0):m(31,11);case l:return c?m(1,p):m(0,p+1);case a:var T=this.$locale().weekStart||0,A=(g<T?g+7:g)-T;return m(c?y-A:y+(6-A),p);case o:case h:return E(f+"Hours",0);case s:return E(f+"Minutes",1);case i:return E(f+"Seconds",2);case r:return E(f+"Milliseconds",3);default:return this.clone()}},p.endOf=function(t){return this.startOf(t,!1)},p.$set=function(t,e){var a,c=D.p(t),d="set"+(this.$u?"UTC":""),m=(a={},a[o]=d+"Date",a[h]=d+"Date",a[l]=d+"Month",a[u]=d+"FullYear",a[s]=d+"Hours",a[i]=d+"Minutes",a[r]=d+"Seconds",a[n]=d+"Milliseconds",a)[c],E=c===o?this.$D+(e-this.$W):e;if(c===l||c===u){var g=this.clone().set(h,1);g.$d[m](E),g.init(),this.$d=g.set(h,Math.min(this.$D,g.daysInMonth())).$d}else m&&this.$d[m](E);return this.init(),this},p.set=function(t,e){return this.clone().$set(t,e)},p.get=function(t){return this[D.p(t)]()},p.add=function(n,c){var h,d=this;n=Number(n);var m=D.p(c),E=function(t){var e=S(d);return D.w(e.date(e.date()+Math.round(t*n)),d)};if(m===l)return this.set(l,this.$M+n);if(m===u)return this.set(u,this.$y+n);if(m===o)return E(1);if(m===a)return E(7);var g=(h={},h[i]=t,h[s]=e,h[r]=1e3,h)[m]||1,p=this.$d.getTime()+n*g;return D.w(p,this)},p.subtract=function(t,e){return this.add(-1*t,e)},p.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=D.z(this),s=this.$H,o=this.$m,a=this.$M,l=n.weekdays,c=n.months,u=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},m=function(t){return D.s(s%12||12,t,"0")},g=u||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(E,function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return D.s(e.$y,4,"0");case"M":return a+1;case"MM":return D.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return D.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,l,2);case"ddd":return h(n.weekdaysShort,e.$W,l,3);case"dddd":return l[e.$W];case"H":return String(s);case"HH":return D.s(s,2,"0");case"h":return m(1);case"hh":return m(2);case"a":return g(s,o,!0);case"A":return g(s,o,!1);case"m":return String(o);case"mm":return D.s(o,2,"0");case"s":return String(e.$s);case"ss":return D.s(e.$s,2,"0");case"SSS":return D.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")})},p.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},p.diff=function(n,h,d){var m,E=this,g=D.p(h),p=S(n),y=(p.utcOffset()-this.utcOffset())*t,f=this-p,T=function(){return D.m(E,p)};switch(g){case u:m=T()/12;break;case l:m=T();break;case c:m=T()/3;break;case a:m=(f-y)/6048e5;break;case o:m=(f-y)/864e5;break;case s:m=f/e;break;case i:m=f/t;break;case r:m=f/1e3;break;default:m=f}return d?m:D.a(m)},p.daysInMonth=function(){return this.endOf(l).$D},p.$locale=function(){return T[this.$L]},p.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=_(t,e,!0);return r&&(n.$L=r),n},p.clone=function(){return D.w(this.$d,this)},p.toDate=function(){return new Date(this.valueOf())},p.toJSON=function(){return this.isValid()?this.toISOString():null},p.toISOString=function(){return this.$d.toISOString()},p.toString=function(){return this.$d.toUTCString()},g}(),v=O.prototype;return S.prototype=v,[["$ms",n],["$s",r],["$m",i],["$H",s],["$W",o],["$M",l],["$y",u],["$D",h]].forEach(function(t){v[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),S.extend=function(t,e){return t.$i||(t(e,O,S),t.$i=!0),S},S.locale=_,S.isDayjs=R,S.unix=function(t){return S(1e3*t)},S.en=T[f],S.Ls=T,S.p={},S}()},473:t=>{t.exports=function(t,e){var n="000000000"+t;return n.substr(n.length-e)}},584:(t,e,n)=>{var r=n(146),i=n(473),s=n(48),o=0,a=Math.pow(36,4);function l(){return i((s()*a|0).toString(36),4)}function c(){return o=o<a?o:0,++o-1}function u(){return"c"+(new Date).getTime().toString(36)+i(c().toString(36),4)+r()+(l()+l())}u.slug=function(){var t=(new Date).getTime().toString(36),e=c().toString(36).slice(-4),n=r().slice(0,1)+r().slice(-1),i=l().slice(-2);return t.slice(-2)+e+n+i},u.isCuid=function(t){return"string"==typeof t&&!!t.startsWith("c")},u.isSlug=function(t){if("string"!=typeof t)return!1;var e=t.length;return e>=7&&e<=10},u.fingerprint=r,t.exports=u},831:t=>{t.exports={AD:"EUR",AE:"AED",AF:"AFN",AG:"XCD",AI:"XCD",AL:"ALL",AM:"AMD",AO:"AOA",AQ:"EUR",AR:"ARS",AS:"USD",AT:"EUR",AU:"AUD",AW:"AWG",AX:"EUR",AZ:"AZN",BA:"BAM",BB:"BBD",BD:"BDT",BE:"EUR",BF:"XOF",BG:"BGN",BH:"BHD",BI:"BIF",BJ:"XOF",BL:"EUR",BM:"BMD",BN:"BND",BO:"BOB",BQ:"USD",BR:"BRL",BS:"BSD",BT:"BTN",BV:"NOK",BW:"BWP",BY:"BYN",BZ:"BZD",CA:"CAD",CC:"AUD",CD:"CDF",CF:"XAF",CG:"XAF",CH:"CHF",CI:"XOF",CK:"NZD",CL:"CLP",CM:"XAF",CN:"CNY",CO:"COP",CR:"CRC",CU:"CUP",CV:"CVE",CW:"ANG",CX:"AUD",CY:"EUR",CZ:"CZK",DE:"EUR",DJ:"DJF",DK:"DKK",DM:"XCD",DO:"DOP",DZ:"DZD",EC:"USD",EE:"EUR",EG:"EGP",EH:"MAD",ER:"ERN",ES:"EUR",ET:"ETB",FI:"EUR",FJ:"FJD",FK:"FKP",FM:"USD",FO:"DKK",FR:"EUR",GA:"XAF",GB:"GBP",GD:"XCD",GE:"GEL",GF:"EUR",GG:"GBP",GH:"GHS",GI:"GIP",GL:"DKK",GM:"GMD",GN:"GNF",GP:"EUR",GQ:"XAF",GR:"EUR",GS:"GBP",GT:"GTQ",GU:"USD",GW:"XOF",GY:"GYD",HK:"HKD",HM:"AUD",HN:"HNL",HR:"EUR",HT:"HTG",HU:"HUF",ID:"IDR",IE:"EUR",IL:"ILS",IM:"GBP",IN:"INR",IO:"USD",IQ:"IQD",IR:"IRR",IS:"ISK",IT:"EUR",JE:"GBP",JM:"JMD",JO:"JOD",JP:"JPY",KE:"KES",KG:"KGS",KH:"KHR",KI:"AUD",KM:"KMF",KN:"XCD",KP:"KPW",KR:"KRW",KW:"KWD",KY:"KYD",KZ:"KZT",LA:"LAK",LB:"LBP",LC:"XCD",LI:"CHF",LK:"LKR",LR:"LRD",LS:"LSL",LT:"EUR",LU:"EUR",LV:"EUR",LY:"LYD",MA:"MAD",MC:"EUR",MD:"MDL",ME:"EUR",MF:"EUR",MG:"MGA",MH:"USD",MK:"MKD",ML:"XOF",MM:"MMK",MN:"MNT",MO:"MOP",MP:"USD",MQ:"EUR",MR:"MRU",MS:"XCD",MT:"EUR",MU:"MUR",MV:"MVR",MW:"MWK",MX:"MXN",MY:"MYR",MZ:"MZN",NA:"NAD",NC:"XPF",NE:"XOF",NF:"AUD",NG:"NGN",NI:"NIO",NL:"EUR",NO:"NOK",NP:"NPR",NR:"AUD",NU:"NZD",NZ:"NZD",OM:"OMR",PA:"PAB",PE:"PEN",PF:"XPF",PG:"PGK",PH:"PHP",PK:"PKR",PL:"PLN",PM:"EUR",PN:"NZD",PR:"USD",PS:"ILS",PT:"EUR",PW:"USD",PY:"PYG",QA:"QAR",RE:"EUR",RO:"RON",RS:"RSD",RU:"RUB",RW:"RWF",SA:"SAR",SB:"SBD",SC:"SCR",SD:"SDG",SE:"SEK",SG:"SGD",SH:"SHP",SI:"EUR",SJ:"NOK",SK:"EUR",SL:"SLE",SM:"EUR",SN:"XOF",SO:"SOS",SR:"SRD",SS:"SSP",ST:"STN",SV:"SVC",SX:"ANG",SY:"SYP",SZ:"SZL",TC:"USD",TD:"XAF",TF:"EUR",TG:"XOF",TH:"THB",TJ:"TJS",TK:"NZD",TL:"USD",TM:"TMT",TN:"TND",TO:"TOP",TR:"TRY",TT:"TTD",TV:"AUD",TW:"TWD",TZ:"TZS",UA:"UAH",UG:"UGX",UM:"USD",US:"USD",UY:"UYU",UZ:"UZS",VA:"EUR",VC:"XCD",VE:"VED",VG:"USD",VI:"USD",VN:"VND",VU:"VUV",WF:"XPF",WS:"WST",YE:"YER",YT:"EUR",ZA:"ZAR",ZM:"ZMW",ZW:"ZWG"}},869:(t,e,n)=>{var r=n(831);e.getCurrency=function(t){var e,n,i=(e=t,n=e.split("_"),2==n.length||2==(n=e.split("-")).length?n.pop():e).toUpperCase();return i in r?r[i]:null},e.getLocales=function(t){t=t.toUpperCase();var e=[];for(var n in r)r[n]===t&&e.push(n);return e}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,n),s.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{CotomyActionEvent:()=>w,CotomyApiForm:()=>C,CotomyConflictException:()=>f,CotomyDebugFeature:()=>s,CotomyDebugSettings:()=>a,CotomyElement:()=>u,CotomyFillApiForm:()=>U,CotomyForbiddenException:()=>p,CotomyForm:()=>I,CotomyHttpClientError:()=>E,CotomyHttpServerError:()=>A,CotomyInvalidFormDataBodyException:()=>_,CotomyMetaElement:()=>h,CotomyNotFoundException:()=>y,CotomyPageController:()=>P,CotomyQueryForm:()=>b,CotomyResponseJsonParseException:()=>R,CotomyRestApi:()=>N,CotomyRestApiException:()=>m,CotomyRestApiResponse:()=>O,CotomyUnauthorizedException:()=>g,CotomyUrl:()=>L,CotomyValidationException:()=>T,CotomyViewRenderer:()=>v,CotomyWindow:()=>d});var t,e=n(353),i=n.n(e);!function(t){t[t.CONTINUE=100]="CONTINUE",t[t.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",t[t.PROCESSING=102]="PROCESSING",t[t.EARLY_HINTS=103]="EARLY_HINTS",t[t.OK=200]="OK",t[t.CREATED=201]="CREATED",t[t.ACCEPTED=202]="ACCEPTED",t[t.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",t[t.NO_CONTENT=204]="NO_CONTENT",t[t.RESET_CONTENT=205]="RESET_CONTENT",t[t.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",t[t.MULTI_STATUS=207]="MULTI_STATUS",t[t.MULTIPLE_CHOICES=300]="MULTIPLE_CHOICES",t[t.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",t[t.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",t[t.SEE_OTHER=303]="SEE_OTHER",t[t.NOT_MODIFIED=304]="NOT_MODIFIED",t[t.USE_PROXY=305]="USE_PROXY",t[t.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",t[t.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",t[t.BAD_REQUEST=400]="BAD_REQUEST",t[t.UNAUTHORIZED=401]="UNAUTHORIZED",t[t.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",t[t.FORBIDDEN=403]="FORBIDDEN",t[t.NOT_FOUND=404]="NOT_FOUND",t[t.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",t[t.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",t[t.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",t[t.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",t[t.CONFLICT=409]="CONFLICT",t[t.GONE=410]="GONE",t[t.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",t[t.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",t[t.REQUEST_TOO_LONG=413]="REQUEST_TOO_LONG",t[t.REQUEST_URI_TOO_LONG=414]="REQUEST_URI_TOO_LONG",t[t.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",t[t.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",t[t.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",t[t.IM_A_TEAPOT=418]="IM_A_TEAPOT",t[t.INSUFFICIENT_SPACE_ON_RESOURCE=419]="INSUFFICIENT_SPACE_ON_RESOURCE",t[t.METHOD_FAILURE=420]="METHOD_FAILURE",t[t.MISDIRECTED_REQUEST=421]="MISDIRECTED_REQUEST",t[t.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",t[t.LOCKED=423]="LOCKED",t[t.FAILED_DEPENDENCY=424]="FAILED_DEPENDENCY",t[t.UPGRADE_REQUIRED=426]="UPGRADE_REQUIRED",t[t.PRECONDITION_REQUIRED=428]="PRECONDITION_REQUIRED",t[t.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",t[t.REQUEST_HEADER_FIELDS_TOO_LARGE=431]="REQUEST_HEADER_FIELDS_TOO_LARGE",t[t.UNAVAILABLE_FOR_LEGAL_REASONS=451]="UNAVAILABLE_FOR_LEGAL_REASONS",t[t.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",t[t.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",t[t.BAD_GATEWAY=502]="BAD_GATEWAY",t[t.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",t[t.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",t[t.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",t[t.INSUFFICIENT_STORAGE=507]="INSUFFICIENT_STORAGE",t[t.NETWORK_AUTHENTICATION_REQUIRED=511]="NETWORK_AUTHENTICATION_REQUIRED"}(t||(t={}));var s,o=n(869);!function(t){t.Api="api",t.Fill="fill",t.Bind="bind",t.FormData="formdata",t.Html="html",t.Page="page"}(s||(s={}));class a{static isEnabled(t){const e=localStorage.getItem(this.PREFIX);return t&&"true"===localStorage.getItem(`${this.PREFIX}:${String(t)}`)||"true"===e}static enable(t){localStorage.setItem(`${this.PREFIX}:${String(t)}`,"true")}static disable(t){localStorage.setItem(`${this.PREFIX}:${String(t)}`,"false")}static enableAll(){localStorage.setItem(this.PREFIX,"true")}static disableAll(){localStorage.setItem(this.PREFIX,"false")}static clear(t){t?localStorage.removeItem(`${this.PREFIX}:${String(t)}`):localStorage.removeItem(this.PREFIX)}}a.PREFIX="cotomy:debug";var l=n(584),c=n.n(l);class u{static createHTMLElement(t){const e=(new DOMParser).parseFromString(t,"text/html");if(0===e.body.childNodes.length)throw new Error("Invalid HTML string provided.");return e.body.firstChild}static first(t,e){const n=document.querySelector(t);if(n)return new(e??u)(n)}static find(t,e){const n=document.querySelectorAll(t),r=e??u;return Array.from(n).map(t=>new r(t))}static byId(t,e){return this.first(`#${t}`,e)}static contains(t){return null!==document.querySelector(t)}static empty(t){return new(t??u)(document.createElement("div")).setAttribute("data-cotomy-empty","").setElementStyle("display","none")}constructor(t){this._parentElement=null,this._scopeId=null,t instanceof HTMLElement?this._element=t:"string"==typeof t?this._element=u.createHTMLElement(t):(this._element=u.createHTMLElement(t.html),t.css&&this.useScopedCss(t.css),a.isEnabled(s.Html)&&(console.debug(`CotomyElement {html: "${t.html}" } is created`),t.css&&console.debug(`CotomyElement {css: "${t.css}" } is applied`))),this.removed(()=>{this._element=u.createHTMLElement('<div data-cotomy-invalid style="display: none;"></div>')})}get scopeId(){return this._scopeId||(this._scopeId=`_${c()()}`,this.setAttribute(this._scopeId,"")),this._scopeId}get scopedSelector(){return`[${this.scopeId}]`}get stylable(){return!["script","style","link","meta"].includes(this.tagname)}useScopedCss(t){if(t&&this.stylable){const e=`css-${this.scopeId}`;u.find(`#${e}`).forEach(t=>t.remove());const n=document.createElement("style"),r=t.replace(/\[scope\]/g,`[${this.scopeId}]`),i=document.createTextNode(r);n.appendChild(i),n.id=e,(u.first("head")||new u({html:"<head></head>"}).prependTo(new u(document.documentElement))).append(new u(n)),this.removed(()=>{u.find(`#${e}`).forEach(t=>t.remove())})}return this}listenLayoutEvents(){return this.setAttribute(u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE,""),this}get id(){return this.attribute("id")}setId(t){return this.setAttribute("id",t),this}get element(){return this._element}get tagname(){return this.element.tagName.toLowerCase()}is(t){const e=t.split(/\s+(?![^\[]*\])|(?<=\>)\s+/);let n=this.element;for(let t=e.length-1;t>=0;t--){let r=e[t].trim(),i=!1;if(r.startsWith(">")&&(i=!0,r=r.slice(1).trim()),!n||!n.matches(r))return!1;if(i)n=n.parentElement;else if(t>0)for(;n&&!n.matches(e[t-1].trim());)n=n.parentElement}return!0}get empty(){return new Set(["input","select","textarea","img","video","audio","br","hr","iframe","embed","canvas","object","svg","source","track","col","link","meta","base"]).has(this.tagname)||this._element.hasAttribute("data-cotomy-empty")||""===this._element.innerHTML.trim()}get attached(){return document.contains(this.element)}get readonly(){return"readOnly"in this.element?this.element.readOnly:this.element.hasAttribute("readonly")}set readonly(t){"readOnly"in this.element?this.element.readOnly=t:t?this.setAttribute("readonly","readonly"):this.removeAttribute("readonly")}get value(){return"value"in this.element?this.element.value:this.attribute("data-cotomy-value")??""}set value(t){"value"in this.element?this.element.value=t:this.setAttribute("data-cotomy-value",t)}get text(){return this.element.textContent??""}set text(t){this.element.textContent=t??""}get html(){return this.element.innerHTML}set html(t){this.element.innerHTML=t}convertUtcToLocal(t="YYYY-MM-DD HH:mm",e=!0){if(this.hasClass("utc")){if(""===this.text.trim())return this;const e=/[+-]\d{2}:\d{2}$/.test(this.text),n=new Date(this.text+(e?"":"Z"));this.text=isNaN(n.getTime())?"":i()(n).format(t),this.removeClass("utc")}if("datetime-local"===this.attribute("type")){const e=/[+-]\d{2}:\d{2}$/.test(this.value),n=new Date(this.value+(e?"":"Z"));this.value=isNaN(n.getTime())?"":i()(n).format(t)}return e&&this.find(".utc").forEach(n=>{n.convertUtcToLocal(t,e)}),this}setFocus(){this.element.focus()}get visible(){if(!this.attached)return!1;if(!this.element.offsetParent&&!document.contains(this.element))return!1;const t=this.element.getBoundingClientRect();if(t.width>0&&t.height>0){const t=this.computedStyle;return"none"!==t.display&&"hidden"!==t.visibility&&"collapse"!==t.visibility}return!1}get enabled(){return!(this.element.hasAttribute("disabled")&&null!==this.element.getAttribute("disabled"))}set enabled(t){t?this.element.removeAttribute("disabled"):this.element.setAttribute("disabled","disabled")}get valid(){return!this.element.hasAttribute("data-cotomy-invalid")}remove(){this.valid&&this._element.remove()}clone(){return new u(document.createElement(this.tagname))}clean(){this.find("*").forEach(t=>t.remove())}get width(){return this.element.offsetWidth}set width(t){let e=t.toString()+"px";this.setElementStyle("width",e)}get height(){return this.element.offsetHeight}set height(t){let e=t.toString()+"px";this.setElementStyle("height",e)}get innerWidth(){return this.element.clientWidth}get innerHeight(){return this.element.clientHeight}get outerWidth(){const t=parseFloat(this.computedStyle.marginLeft)+parseFloat(this.computedStyle.marginRight);return this.element.offsetWidth+t}get outerHeight(){const t=this.computedStyle,e=parseFloat(t.marginTop)+parseFloat(t.marginBottom);return this.element.offsetHeight+e}get scrollHeight(){return this.element.scrollHeight}get scrollWidth(){return this.element.scrollWidth}get scrollTop(){return this.element.scrollTop}get position(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left}}get absolutePosition(){const t=this.element.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX}}get screenPosition(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left}}get rect(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left,width:t.width,height:t.height}}get innerRect(){const t=this.element.getBoundingClientRect(),e=this.computedStyle,n=parseFloat(e.paddingTop),r=parseFloat(e.paddingRight),i=parseFloat(e.paddingBottom),s=parseFloat(e.paddingLeft);return{top:t.top+n,left:t.left+s,width:t.width-s-r,height:t.height-n-i}}get outerRect(){const t=this.element.getBoundingClientRect(),e=this.computedStyle,n=parseFloat(e.marginTop),r=parseFloat(e.marginRight),i=parseFloat(e.marginBottom),s=parseFloat(e.marginLeft);return{top:t.top-n,left:t.left-s,width:t.width+s+r,height:t.height+n+i}}get padding(){const t=this.computedStyle;return{top:parseFloat(t.paddingTop),right:parseFloat(t.paddingRight),bottom:parseFloat(t.paddingBottom),left:parseFloat(t.paddingLeft)}}get margin(){const t=this.computedStyle;return{top:parseFloat(t.marginTop),right:parseFloat(t.marginRight),bottom:parseFloat(t.marginBottom),left:parseFloat(t.marginLeft)}}get inViewport(){const t=this.element.getBoundingClientRect();return t.top<window.innerHeight&&t.bottom>0}get isAboveViewport(){return this.element.getBoundingClientRect().bottom<0}get isBelowViewport(){return this.element.getBoundingClientRect().top>window.innerHeight}get isLeftViewport(){return this.element.getBoundingClientRect().right<0}get isRightViewport(){return this.element.getBoundingClientRect().left>window.innerWidth}hasAttribute(t){return this.element.hasAttribute(t)}attribute(t){return this.element.hasAttribute(t)?this.element.getAttribute(t):void 0}setAttribute(t,e=void 0){return this.element.setAttribute(t,e?.toString()??""),this}removeAttribute(t){this.element.removeAttribute(t)}hasClass(t){return this.element.classList.contains(t)}addClass(t){return this.element.classList.add(t),this}removeClass(t){return this.element.classList.remove(t),this}setElementStyle(t,e){return this.element.style.setProperty(t,e),this}removeElementStyle(t){return this.element.style.removeProperty(t),this}get computedStyle(){return window.getComputedStyle(this.element)}style(t){return this.computedStyle.getPropertyValue(t)}get parent(){return null==this._parentElement&&null!==this.element.parentElement&&(this._parentElement=new u(this.element.parentElement)),this._parentElement??u.empty()}get parents(){let t=[],e=this.element.parentElement;for(;null!==e;)t.push(new u(e)),e=e.parentElement;return t}hasChildren(t="*"){return null!==this.element.querySelector(t)}children(t="*",e){const n=Array.from(this.element.querySelectorAll(t)).filter(t=>t.parentElement===this.element),r=e??u;return n.filter(t=>t instanceof HTMLElement).map(t=>new r(t))}firstChild(t="*",e){return this.children(t,e).shift()??void 0}lastChild(t="*",e){return this.children(t,e).pop()??void 0}closest(t,e){const n=this.element.closest(t);if(null!==n&&n instanceof HTMLElement)return new(e??u)(n)}find(t,e){return Array.from(this.element.querySelectorAll(t)).map(t=>new(e??u)(t))}first(t="*",e){return this.find(t,e).shift()??void 0}prepend(t){return this._element.prepend(t.element),this}append(t){return this.element.append(t.element),this}appendAll(t){return t.forEach(t=>this.append(t)),this}insertBefore(t){return this.element.before(t.element),this}insertAfter(t){return this.element.after(t.element),this}appendTo(t){return t.element.append(this.element),this}prependTo(t){return t.element.prepend(this.element),this}trigger(t,e=null){return this.element.dispatchEvent(e??new Event(t)),this}on(t,e){return this.element.addEventListener(t,e),this}onChild(t,e,n){return this.element.addEventListener(t,t=>{if(t.target instanceof HTMLElement){const r=new u(t.target).closest(e);r&&n(t,r.element)}}),this}once(t,e){return this.element.addEventListener(t,e,{once:!0}),this}off(t,e){return this.element.removeEventListener(t,e),this}click(t=null){return t?this.element.addEventListener("click",async e=>await t(e)):this.trigger("click"),this}dblclick(t=null){return t?this.element.addEventListener("dblclick",async e=>await t(e)):this.trigger("dblclick"),this}mouseover(t=null){return t?this.element.addEventListener("mouseover",async e=>await t(e)):this.trigger("mouseover"),this}mouseout(t=null){return t?this.element.addEventListener("mouseout",async e=>await t(e)):this.trigger("mouseout"),this}mousedown(t=null){return t?this.element.addEventListener("mousedown",async e=>await t(e)):this.trigger("mousedown"),this}mouseup(t=null){return t?this.element.addEventListener("mouseup",async e=>await t(e)):this.trigger("mouseup"),this}mousemove(t=null){return t?this.element.addEventListener("mousemove",async e=>await t(e)):this.trigger("mousemove"),this}mouseenter(t=null){return t?this.element.addEventListener("mouseenter",async e=>await t(e)):this.trigger("mouseenter"),this}mouseleave(t=null){return t?this.element.addEventListener("mouseleave",async e=>await t(e)):this.trigger("mouseleave"),this}dragstart(t=null){return t?this.element.addEventListener("dragstart",async e=>await t(e)):this.trigger("dragstart"),this}dragend(t=null){return t?this.element.addEventListener("dragend",async e=>await t(e)):this.trigger("dragend"),this}dragover(t=null){return t?this.element.addEventListener("dragover",async e=>await t(e)):this.trigger("dragover"),this}dragenter(t=null){return t?this.element.addEventListener("dragenter",async e=>await t(e)):this.trigger("dragenter"),this}dragleave(t=null){return t?this.element.addEventListener("dragleave",async e=>await t(e)):this.trigger("dragleave"),this}drop(t=null){return t?this.element.addEventListener("drop",async e=>await t(e)):this.trigger("drop"),this}drag(t=null){return t?this.element.addEventListener("drag",async e=>await t(e)):this.trigger("drag"),this}removed(t){return this.element.addEventListener("removed",async e=>await t(e)),this}keydown(t=null){return t?this.element.addEventListener("keydown",async e=>await t(e)):this.trigger("keydown"),this}keyup(t=null){return t?this.element.addEventListener("keyup",async e=>await t(e)):this.trigger("keyup"),this}keypress(t=null){return t?this.element.addEventListener("keypress",async e=>await t(e)):this.trigger("keypress"),this}change(t=null){return t?this.element.addEventListener("change",async e=>await t(e)):this.trigger("change"),this}input(t=null){return t?this.element.addEventListener("input",async e=>await t(e)):this.trigger("input"),this}static get intersectionObserver(){return u._intersectionObserver=u._intersectionObserver??new IntersectionObserver(t=>{t.filter(t=>t.isIntersecting).forEach(t=>t.target.dispatchEvent(new Event("inview"))),t.filter(t=>!t.isIntersecting).forEach(t=>t.target.dispatchEvent(new Event("outview")))})}inview(t=null){return t?(u.intersectionObserver.observe(this.element),this.element.addEventListener("inview",async e=>await t(e))):this.trigger("inview"),this}outview(t=null){return t?(u.intersectionObserver.observe(this.element),this.element.addEventListener("outview",async e=>await t(e))):this.trigger("outview"),this}focus(t=null){return t?this.element.addEventListener("focus",async e=>await t(e)):this.trigger("focus"),this}blur(t=null){return t?this.element.addEventListener("blur",async e=>await t(e)):this.trigger("blur"),this}focusin(t=null){return t?this.element.addEventListener("focusin",async e=>await t(e)):this.trigger("focusin"),this}focusout(t=null){return t?this.element.addEventListener("focusout",async e=>await t(e)):this.trigger("focusout"),this}filedrop(t){return this.element.addEventListener("drop",async e=>{e.preventDefault();const n=e.dataTransfer;n&&n.files&&await t(Array.from(n.files))}),this}resize(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:resize",async e=>await t(e)):this.trigger("cotomy:resize"),this}scroll(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:scroll",async e=>await t(e)):this.trigger("cotomy:scroll"),this}changelayout(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:changelayout",async e=>await t(e)):this.trigger("cotomy:changelayout"),this}}u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE="data-cotomy-layout",u._intersectionObserver=null;class h extends u{static get(t){return u.first(`meta[name="${t}" i]`)??u.empty()}get content(){return this.attribute("content")??""}}class d{constructor(){this._body=u.empty(),this._mutationObserver=null,this._reloading=!1}static get instance(){return d._instance??(d._instance=new d)}get initialized(){return this._body.attached}initialize(){if(!this.initialized){if(!document.body)throw new Error("<body> element not found. DOM may not be ready.");this._body=u.first("body"),["resize","scroll","orientationchange","fullscreenchange","cotomy:ready"].forEach(t=>{window.addEventListener(t,()=>{const t=new CustomEvent("cotomy:changelayout");window.dispatchEvent(t)},{passive:!0})}),document.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()}),document.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()}),this.resize(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:resize"))})}),this.scroll(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:scroll"))})}),this.changeLayout(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:changelayout"))})}),this._mutationObserver=new MutationObserver(t=>{t.forEach(t=>{t.removedNodes.forEach(t=>{t instanceof HTMLElement&&new u(t).trigger("removed")})})}),this._mutationObserver.observe(this.body.element,{childList:!0,subtree:!0})}}get reloading(){return this._reloading}reload(){this._reloading=!0,location.reload()}get body(){return this._body}append(t){this._body.append(t)}moveNext(t,e=!1){const n=Array.from(this.body.element.querySelectorAll("input, a, select, button, textarea")).map(t=>new u(t)).filter(t=>t.width>0&&t.height>0&&t.visible&&t.enabled&&!t.hasAttribute("readonly"));let r=n.map(t=>t.element).indexOf(t.element)+(e?-1:1);r>=n.length?r=0:r<0&&(r=n.length-1),n[r]&&n[r].setFocus()}trigger(t){window.dispatchEvent(new Event(t))}load(t){window.addEventListener("load",async e=>await t(e))}ready(t){window.addEventListener("cotomy:ready",async e=>await t(e))}on(t,e){window.addEventListener(t,async t=>await e(t))}resize(t=null){t?window.addEventListener("resize",async e=>await t(e)):this.trigger("resize")}scroll(t=null){t?window.addEventListener("scroll",async e=>await t(e)):this.trigger("scroll")}changeLayout(t=null){t?window.addEventListener("cotomy:changelayout",async e=>await t(e)):this.trigger("cotomy:changelayout")}pageshow(t=null){t?window.addEventListener("pageshow",async e=>await t(e)):this.trigger("pageshow")}get scrollTop(){return window.scrollY||document.documentElement.scrollTop}get scrollLeft(){return window.scrollX||document.documentElement.scrollLeft}get width(){return window.innerWidth}get height(){return window.innerHeight}get documentWidth(){return document.documentElement.scrollWidth}get documentHeight(){return document.documentElement.scrollHeight}}d._instance=null;class m extends Error{constructor(t,e,n,r=""){super(e),this.status=t,this.message=e,this.response=n,this.bodyText=r,this.name="CotomyRestApiException"}}class E extends m{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyHttpClientError"}}class g extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyUnauthorizedException"}}class p extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyForbiddenException"}}class y extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyNotFoundException"}}class f extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyConflictException"}}class T extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyValidationException"}}class A extends m{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyHttpServerError"}}class R extends Error{constructor(t="Failed to parse JSON response."){super(t),this.name="ResponseJsonParseException"}}class _ extends Error{constructor(t="Body must be an instance of FormData."){super(t),this.name="InvalidFormDataBodyException"}}class S{}S.GET="GET",S.POST="POST",S.PUT="PUT",S.PATCH="PATCH",S.DELETE="DELETE",S.HEAD="HEAD",S.OPTIONS="OPTIONS",S.TRACE="TRACE",S.CONNECT="CONNECT";class D{static getMessage(t){return this._responseMessages[t]||`Unexpected error: ${t}`}}D._responseMessages={[t.BAD_REQUEST]:"There is an error in the input. Please check and try again.",[t.UNAUTHORIZED]:"You are not authenticated. Please log in again.",[t.FORBIDDEN]:"You do not have permission to use this feature. If necessary, please contact the administrator.",[t.NOT_FOUND]:"The specified information could not be found. It may have been deleted. Please start over or contact the administrator.",[t.METHOD_NOT_ALLOWED]:"This operation is currently prohibited on the server.",[t.NOT_ACCEPTABLE]:"The request cannot be accepted. Processing has been stopped.",[t.PROXY_AUTHENTICATION_REQUIRED]:"Proxy authentication is required for internet access.",[t.REQUEST_TIMEOUT]:"The request timed out. Please try again.",[t.CONFLICT]:"The identifier you are trying to register already exists. Please check the content and try again.",[t.PAYMENT_REQUIRED]:"Payment is required for this operation. Please check.",[t.GONE]:"The requested resource is no longer available.",[t.LENGTH_REQUIRED]:"The Content-Length header field is required for the request.",[t.PRECONDITION_FAILED]:"The request failed because the precondition was not met.",[t.UNSUPPORTED_MEDIA_TYPE]:"The requested media type is not supported.",[t.EXPECTATION_FAILED]:"The server cannot meet the Expect header of the request.",[t.MISDIRECTED_REQUEST]:"The server cannot appropriately process this request.",[t.UNPROCESSABLE_ENTITY]:"There is an error in the request content.",[t.LOCKED]:"The requested resource is locked.",[t.FAILED_DEPENDENCY]:"The request failed due to dependency on a previous failed request.",[t.UPGRADE_REQUIRED]:"A protocol upgrade is required to perform this operation.",[t.PRECONDITION_REQUIRED]:"This request requires a precondition.",[t.TOO_MANY_REQUESTS]:"Too many requests have been sent in a short time. Please wait and try again.",[t.REQUEST_HEADER_FIELDS_TOO_LARGE]:"The request headers are too large.",[t.INTERNAL_SERVER_ERROR]:"An unexpected error occurred. Please try again later.",[t.BAD_GATEWAY]:"The server is currently overloaded. Please wait and try again later.",[t.SERVICE_UNAVAILABLE]:"The service is temporarily unavailable. Please try again later.",[t.GATEWAY_TIMEOUT]:"The communication timed out. Please try again.",[t.HTTP_VERSION_NOT_SUPPORTED]:"The current communication method is not supported.",[t.NOT_IMPLEMENTED]:"The server does not support the requested functionality.",[t.INSUFFICIENT_STORAGE]:"The server has insufficient storage.",[t.NETWORK_AUTHENTICATION_REQUIRED]:"Network authentication is required.",413:"The payload of the request is too large. Please check the size.",414:"The request URI is too long.",416:"The requested range is invalid.",508:"The server detected a loop.",510:"The request does not include the required extensions."};class O{constructor(t){this._response=t,this._json=null,this._map=null}get available(){return!!this._response}get empty(){return!this._response||0===this._response.status}get ok(){return this._response?.ok??!1}get status(){return this._response?.status??0}get statusText(){return this._response?.statusText??""}get headers(){return this._response?.headers??new Headers}async textAsync(){return await(this._response?.text())||""}async blobAsync(){return await(this._response?.blob())||new Blob}async objectAsync(t={}){if(this._response&&!this._json)try{const e=await this._response.text();if(!e)return t;this._json=JSON.parse(e)}catch(t){throw new R(`Failed to parse JSON response: ${t instanceof Error?t.message:String(t)}`)}return this._json}}class v{constructor(t){this.element=t,this._locale=null,this._currency=null,this._renderers={},this._builded=!1}get locale(){return this._locale=this._locale||navigator.language||"en-US"}get currency(){return this._currency=this._currency||o.getCurrency(this.locale)||"USD"}renderer(t,e){return this._renderers[t]=e,this}get initialized(){return this._builded}initialize(){return this.initialized||(this.renderer("mail",(t,e)=>{new u(`<a href="mailto:${e}">${e}</a>`).appendTo(t)}),this.renderer("tel",(t,e)=>{new u(`<a href="tel:${e}">${e}</a>`).appendTo(t)}),this.renderer("url",(t,e)=>{new u(`<a href="${e}" target="_blank">${e}</a>`).appendTo(t)}),this.renderer("number",(t,e)=>{t.text=new Intl.NumberFormat(navigator.language||this.locale).format(e)}),this.renderer("currency",(t,e)=>{t.text=new Intl.NumberFormat(navigator.language||this.locale,{style:"currency",currency:this.currency}).format(e)}),this.renderer("utc",(t,e)=>{const n=/[+-]\d{2}:\d{2}$/.test(e)?new Date(e):new Date(`${e}Z`);if(isNaN(n.getTime()))t.text="";else{const e=t.attribute("data-cotomy-format")??"YYYY/MM/DD HH:mm";t.text=i()(n).format(e)}})),this}async applyAsync(t){if(this.initialized||this.initialize(),!t.available)throw new Error("Response is not available.");for(const[e,n]of Object.entries(await t.objectAsync()))this.element.find(`[data-cotomy-bind="${e}" i]`).forEach(t=>{a.isEnabled(s.Bind)&&console.debug(`Binding data to element [data-cotomy-bind="${e}"]:`,n);const r=t.attribute("data-cotomy-type")?.toLowerCase();r&&this._renderers[r]?this._renderers[r](t,n):t.text=String(n)});return this}}class N{constructor(t={baseUrl:null,headers:null,credentials:null,redirect:null,cache:null,referrerPolicy:null,mode:null,keepalive:!0,integrity:""}){this._options=t,this._abortController=new AbortController}get baseUrl(){return this._options.baseUrl||""}get headers(){return this._options.headers||{}}get credentials(){return this._options.credentials||"same-origin"}get redirect(){return this._options.redirect||"follow"}get cache(){return this._options.cache||"no-cache"}get referrerPolicy(){return this._options.referrerPolicy||"no-referrer"}get mode(){return this._options.mode||"cors"}get keepalive(){return this._options.keepalive||!0}get integrity(){return this._options.integrity||""}get abortController(){return this._abortController}async requestAsync(e,n,r,i,s){const o={"application/json":t=>JSON.stringify(t),"application/x-www-form-urlencoded":t=>{if(t instanceof globalThis.FormData){let e=new URLSearchParams;return t.forEach((t,n)=>{e.append(n,String(t))}),e.toString()}return new URLSearchParams(t).toString()},"multipart/form-data":t=>{if(!(t instanceof globalThis.FormData))throw new _("Body must be an instance of FormData for multipart/form-data.");return t}},a=/^[a-zA-Z]/.test(n)?n:`${(this.baseUrl||"").replace(/\/$/,"")}/${n.replace(/^\//,"")}`,l=new Headers(this.headers);l.has("Content-Type")&&"multipart/form-data"===l.get("Content-Type")&&l.delete("Content-Type");const c=l.get("Content-Type")||"multipart/form-data",u=new(s??O)(await fetch(a,{method:e,headers:l,credentials:this.credentials,body:r?o[c]?o[c](r):r:void 0,signal:i??this._abortController.signal,redirect:this.redirect,cache:this.cache,referrerPolicy:this.referrerPolicy,mode:this.mode,keepalive:this.keepalive,integrity:this.integrity}));if(u.status>=400&&u.status<600){const e=await u.textAsync().catch(()=>"No response body available"),n=u.statusText||D.getMessage(u.status)||`Unexpected error: ${u.status}`;switch(u.status){case t.BAD_REQUEST:case t.UNPROCESSABLE_ENTITY:throw new T(u.status,n,u,e);case t.UNAUTHORIZED:throw new g(u.status,n,u,e);case t.FORBIDDEN:throw new p(u.status,n,u,e);case t.NOT_FOUND:throw new y(u.status,n,u,e);case t.CONFLICT:case t.GONE:throw new f(u.status,n,u,e);default:throw u.status<500?new E(u.status,n,u,e):new A(u.status,n,u,e)}}return u}async getAsync(t,e){let n="";if(e instanceof globalThis.FormData){let t=new URLSearchParams;e.forEach((e,n)=>{t.append(n,String(e))}),n=t.toString()}else e&&(n=new URLSearchParams(Object.fromEntries(Object.entries(e).map(([t,e])=>[t,String(e)]))).toString());const r=n?`${t}?${n}`:t;return a.isEnabled(s.Api)&&console.debug(`GET request to: ${r}`),this.requestAsync(S.GET,r)}async postAsync(t,e){return a.isEnabled(s.Api)&&console.debug(`POST request to: ${t}`),this.requestAsync(S.POST,t,e)}async putAsync(t,e){return a.isEnabled(s.Api)&&console.debug(`PUT request to: ${t}`),this.requestAsync(S.PUT,t,e)}async patchAsync(t,e){return a.isEnabled(s.Api)&&console.debug(`PATCH request to: ${t}`),this.requestAsync(S.PATCH,t,e)}async deleteAsync(t){return a.isEnabled(s.Api)&&console.debug(`DELETE request to: ${t}`),this.requestAsync(S.DELETE,t)}async headAsync(t){return a.isEnabled(s.Api)&&console.debug(`HEAD request to: ${t}`),this.requestAsync(S.HEAD,t)}async optionsAsync(t){return a.isEnabled(s.Api)&&console.debug(`OPTIONS request to: ${t}`),this.requestAsync(S.OPTIONS,t)}async traceAsync(t){return a.isEnabled(s.Api)&&console.debug(`TRACE request to: ${t}`),this.requestAsync(S.TRACE,t)}async connectAsync(t){return a.isEnabled(s.Api)&&console.debug(`CONNECT request to: ${t}`),this.requestAsync(S.CONNECT,t)}async submitAsync(t){return t.method.toUpperCase()===S.GET?this.getAsync(t.action,t.body):this.requestAsync(t.method.toUpperCase(),t.action,t.body)}}class w extends Event{constructor(t){super("cotomy:action",{bubbles:!0,cancelable:!0}),this.action=t}}class I extends u{constructor(t){super(t)}get formId(){return this.hasAttribute("id")||this.setAttribute("id",this.scopeId),this.attribute("id")}method(){return this.attribute("method")??"get"}actionUri(){return this.attribute("action")??location.pathname+location.search}get autoComplete(){return"on"===this.attribute("autocomplete")}set autoComplete(t){this.setAttribute("autocomplete",t?"on":"off")}reload(){d.instance.reload()}get autoRestore(){return"false"!==this.attribute("data-cotomy-restore")}set autoRestore(t){t?this.removeAttribute("data-cotomy-restore"):this.setAttribute("data-cotomy-restore","false")}restore(){this.autoRestore&&this.reload()}get initialized(){return this.hasAttribute("data-cotomy-builded")}initialize(){return this.initialized||(this.on("submit",async t=>{await this.submitAsync(t)}),d.instance.pageshow(t=>{t.persisted&&!d.instance.reloading&&this.restore()}),this.find("button[type=button][data-cotomy-action]").forEach(t=>{t.click(()=>{this.trigger("cotomy:action",new w(t.attribute("data-cotomy-action")))})}),this.setAttribute("data-cotomy-builded")),this}submit(){this.trigger("submit")}action(t){return"string"==typeof t?this.trigger("cotomy:action",new w(t)):this.element.addEventListener("cotomy:action",async e=>{await t(e)}),this}}class b extends I{constructor(t){super(t),this.autoComplete=!0}method(){return"get"}async submitAsync(t){t.preventDefault(),t.stopPropagation();const e=this.actionUri(),n={},r=e.split("?")[1];r&&r.split("&").forEach(t=>{const[e,r]=t.split("=");e&&r&&(n[e]=decodeURIComponent(r))}),this.find("[name]").forEach(t=>{const e=t.attribute("name");if(e){const r=t.value;r?n[e]=encodeURIComponent(r):delete n[e]}});const i=Object.entries(n).map(([t,e])=>`${t}=${e}`).join("&");location.href=`${e.split("?")[0]}?${i}`}}class C extends I{constructor(t){super(t)}apiClient(){return new N}actionUri(){return`${this.attribute("action")}/${this.autoIncrement?this.attribute("data-cotomy-key")||"":this.identifierString}`}get identifier(){return this.attribute("data-cotomy-key")||void 0}setIncrementedId(t){const e=t.headers.get("Location")?.split("/").pop();this.setAttribute("data-cotomy-key",e)}get identifierInputs(){return this.find("[data-cotomy-keyindex]").sort((t,e)=>parseInt(t.attribute("data-cotomy-keyindex")??"0")-parseInt(e.attribute("data-cotomy-keyindex")??"0"))}get identifierString(){return this.identifier??this.identifierInputs.map(t=>t.value).join("/")}get autoIncrement(){return!this.identifier&&0==this.identifierInputs.length}method(){return this.autoIncrement||!this.identifierInputs.every(t=>t.readonly)?"post":"put"}formData(){const t=this.element,e=new globalThis.FormData(t);return this.find("input[type=datetime-local][name]:not([disabled])").forEach(t=>{const n=t.value;if(n){const r=new Date(n);isNaN(r.getTime())||e.set(t.attribute("name"),i()(r).format("YYYY-MM-DDTHH:mmZ"))}}),a.isEnabled(s.FormData)&&console.debug("FormData:",Array.from(e.entries())),e}async submitAsync(t){t.preventDefault(),t.stopPropagation();const e=this.formData();await this.submitToApiAsync(e)}async submitToApiAsync(e){const n=this.apiClient(),r=await n.submitAsync({method:this.method(),action:this.actionUri(),body:e});this.autoIncrement&&r.status===t.CREATED&&this.setIncrementedId(r);const i=r.headers.get("Location");return i?(location.href=i,r):r}}class U extends C{constructor(t){super(t),this._fillers={}}filler(t,e){return this._fillers[t]=e,this}initialize(){return this.initialized||(super.initialize(),this.filler("datetime-local",(t,e)=>{const n=/[+-]\d{2}:\d{2}$/.test(e)?new Date(e):new Date(`${e}Z`);isNaN(n.getTime())?t.value="":t.value=i()(n).format("YYYY-MM-DDTHH:mm")}),this.filler("checkbox",(t,e)=>{t.removeAttribute("checked"),e&&t.setAttribute("checked")}),this.filler("radio",(t,e)=>{t.removeAttribute("checked"),t.value===e&&t.setAttribute("checked")}),d.instance.ready(async()=>{await this.loadAsync()})),this}async submitToApiAsync(t){const e=await super.submitToApiAsync(t);return e.ok&&await this.fillAsync(e),e}reload(){this.loadAsync()}loadActionUri(){return this.actionUri()}renderer(){return new v(this)}async loadAsync(){if(this.autoIncrement||!this.identifierInputs.every(t=>t.value))return new O;const t=this.apiClient();try{const e=await t.getAsync(this.loadActionUri());return await this.fillAsync(e),e}catch(t){if(t instanceof y)return t.response;throw t}}async fillAsync(t){if(t.ok&&t.available){for(const[e,n]of Object.entries(await t.objectAsync()))e.endsWith("[]")||this.find(`input[name="${e}" i]:not([data-cotomy-fill="false"]):not([multiple]),\n textarea[name="${e}" i]:not([data-cotomy-fill="false"]), \n select[name="${e}" i]:not([data-cotomy-fill="false"]):not([multiple])`).forEach(t=>{a.isEnabled(s.Fill)&&console.debug(`Filling input[name="${e}"] with value:`,n);const r=t.attribute("type")?.toLowerCase();r&&this._fillers[r]?this._fillers[r](t,n):t.value=String(n||"")});await this.renderer().applyAsync(t)}this.identifierInputs.forEach(t=>t.setElementStyle("background-color","#f0f0f0")),this.identifierInputs.forEach(t=>t.setAttribute("readonly")),this.find("textarea").forEach(t=>t.input())}}class L{static location(){return new L}constructor(t=null){this._url=t??this.current()}current(){const{pathname:t,search:e}=location;return`${t}${e}`}get url(){return this._url}get path(){return this._url.split("?")[0]}get segments(){return this.path.split("/").filter(t=>t.length>0).filter(t=>t.length>0)}get query(){return this._url.split("?")[1]??""}get parameters(){const t=(this._url.split("?")[1]??"").split("&").map(t=>t.split("=")),e={};return t.forEach(([t,n])=>e[t]=n),e}redirect(){window.location.href=this.url}}class P{constructor(){this._forms={}}static set(t){if(this._instance)throw new Error("PageController is already initialized.");return this._instance=new t,d.instance.load(async()=>{a.isEnabled(s.Page)&&console.debug("CotomyPageController initialize."),d.instance.initialize(),await P._instance.initializeAsync(),d.instance.trigger("cotomy:ready")}),this._instance}static get(){if(!(this._instance instanceof P))throw new Error("PageController is not initialized. Use CotomyPageController.set() to initialize it.");return this._instance}setForm(t){return this._forms[t.formId]=t,t.removed(()=>{delete this._forms[t.formId]}),t.initialize()}getForm(t,e){const n=this._forms[t];if(n){if(e&&!(n instanceof e))throw new Error(`Form "${t}" is not instance of expected type.`);return n}}forms(){return Object.values(this._forms)}async initializeAsync(){this.body.convertUtcToLocal()}get body(){return d.instance.body}get uri(){return new L}}P._instance=null})(),r})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cotomy=e():t.Cotomy=e()}(this,()=>(()=>{var t={48:t=>{var e,n="undefined"!=typeof window&&(window.crypto||window.msCrypto)||"undefined"!=typeof self&&self.crypto;if(n){var r=Math.pow(2,32)-1;e=function(){return Math.abs(n.getRandomValues(new Uint32Array(1))[0]/r)}}else e=Math.random;t.exports=e},146:(t,e,n)=>{var r=n(473),i="object"==typeof window?window:self,s=Object.keys(i).length,o=r(((navigator.mimeTypes?navigator.mimeTypes.length:0)+navigator.userAgent.length).toString(36)+s.toString(36),4);t.exports=function(){return o}},353:function(t){t.exports=function(){"use strict";var t=6e4,e=36e5,n="millisecond",r="second",i="minute",s="hour",o="day",a="week",l="month",c="quarter",u="year",h="date",d="Invalid Date",m=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,E=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},p=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},y={s:p,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+p(r,2,"0")+":"+p(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,l),s=n-i<0,o=e.clone().add(r+(s?-1:1),l);return+(-(r+(n-i)/(s?i-o:o-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:l,y:u,w:a,d:o,D:h,h:s,m:i,s:r,ms:n,Q:c}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},f="en",T={};T[f]=g;var A="$isDayjsObject",_=function(t){return t instanceof v||!(!t||!t[A])},R=function t(e,n,r){var i;if(!e)return f;if("string"==typeof e){var s=e.toLowerCase();T[s]&&(i=s),n&&(T[s]=n,i=s);var o=e.split("-");if(!i&&o.length>1)return t(o[0])}else{var a=e.name;T[a]=e,i=a}return!r&&i&&(f=i),i||!r&&f},S=function(t,e){if(_(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new v(n)},D=y;D.l=R,D.i=_,D.w=function(t,e){return S(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var v=function(){function g(t){this.$L=R(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[A]=!0}var p=g.prototype;return p.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(D.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(m);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},p.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},p.$utils=function(){return D},p.isValid=function(){return!(this.$d.toString()===d)},p.isSame=function(t,e){var n=S(t);return this.startOf(e)<=n&&n<=this.endOf(e)},p.isAfter=function(t,e){return S(t)<this.startOf(e)},p.isBefore=function(t,e){return this.endOf(e)<S(t)},p.$g=function(t,e,n){return D.u(t)?this[e]:this.set(n,t)},p.unix=function(){return Math.floor(this.valueOf()/1e3)},p.valueOf=function(){return this.$d.getTime()},p.startOf=function(t,e){var n=this,c=!!D.u(e)||e,d=D.p(t),m=function(t,e){var r=D.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return c?r:r.endOf(o)},E=function(t,e){return D.w(n.toDate()[t].apply(n.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},g=this.$W,p=this.$M,y=this.$D,f="set"+(this.$u?"UTC":"");switch(d){case u:return c?m(1,0):m(31,11);case l:return c?m(1,p):m(0,p+1);case a:var T=this.$locale().weekStart||0,A=(g<T?g+7:g)-T;return m(c?y-A:y+(6-A),p);case o:case h:return E(f+"Hours",0);case s:return E(f+"Minutes",1);case i:return E(f+"Seconds",2);case r:return E(f+"Milliseconds",3);default:return this.clone()}},p.endOf=function(t){return this.startOf(t,!1)},p.$set=function(t,e){var a,c=D.p(t),d="set"+(this.$u?"UTC":""),m=(a={},a[o]=d+"Date",a[h]=d+"Date",a[l]=d+"Month",a[u]=d+"FullYear",a[s]=d+"Hours",a[i]=d+"Minutes",a[r]=d+"Seconds",a[n]=d+"Milliseconds",a)[c],E=c===o?this.$D+(e-this.$W):e;if(c===l||c===u){var g=this.clone().set(h,1);g.$d[m](E),g.init(),this.$d=g.set(h,Math.min(this.$D,g.daysInMonth())).$d}else m&&this.$d[m](E);return this.init(),this},p.set=function(t,e){return this.clone().$set(t,e)},p.get=function(t){return this[D.p(t)]()},p.add=function(n,c){var h,d=this;n=Number(n);var m=D.p(c),E=function(t){var e=S(d);return D.w(e.date(e.date()+Math.round(t*n)),d)};if(m===l)return this.set(l,this.$M+n);if(m===u)return this.set(u,this.$y+n);if(m===o)return E(1);if(m===a)return E(7);var g=(h={},h[i]=t,h[s]=e,h[r]=1e3,h)[m]||1,p=this.$d.getTime()+n*g;return D.w(p,this)},p.subtract=function(t,e){return this.add(-1*t,e)},p.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=D.z(this),s=this.$H,o=this.$m,a=this.$M,l=n.weekdays,c=n.months,u=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},m=function(t){return D.s(s%12||12,t,"0")},g=u||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(E,function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return D.s(e.$y,4,"0");case"M":return a+1;case"MM":return D.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return D.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,l,2);case"ddd":return h(n.weekdaysShort,e.$W,l,3);case"dddd":return l[e.$W];case"H":return String(s);case"HH":return D.s(s,2,"0");case"h":return m(1);case"hh":return m(2);case"a":return g(s,o,!0);case"A":return g(s,o,!1);case"m":return String(o);case"mm":return D.s(o,2,"0");case"s":return String(e.$s);case"ss":return D.s(e.$s,2,"0");case"SSS":return D.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")})},p.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},p.diff=function(n,h,d){var m,E=this,g=D.p(h),p=S(n),y=(p.utcOffset()-this.utcOffset())*t,f=this-p,T=function(){return D.m(E,p)};switch(g){case u:m=T()/12;break;case l:m=T();break;case c:m=T()/3;break;case a:m=(f-y)/6048e5;break;case o:m=(f-y)/864e5;break;case s:m=f/e;break;case i:m=f/t;break;case r:m=f/1e3;break;default:m=f}return d?m:D.a(m)},p.daysInMonth=function(){return this.endOf(l).$D},p.$locale=function(){return T[this.$L]},p.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=R(t,e,!0);return r&&(n.$L=r),n},p.clone=function(){return D.w(this.$d,this)},p.toDate=function(){return new Date(this.valueOf())},p.toJSON=function(){return this.isValid()?this.toISOString():null},p.toISOString=function(){return this.$d.toISOString()},p.toString=function(){return this.$d.toUTCString()},g}(),O=v.prototype;return S.prototype=O,[["$ms",n],["$s",r],["$m",i],["$H",s],["$W",o],["$M",l],["$y",u],["$D",h]].forEach(function(t){O[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),S.extend=function(t,e){return t.$i||(t(e,v,S),t.$i=!0),S},S.locale=R,S.isDayjs=_,S.unix=function(t){return S(1e3*t)},S.en=T[f],S.Ls=T,S.p={},S}()},473:t=>{t.exports=function(t,e){var n="000000000"+t;return n.substr(n.length-e)}},584:(t,e,n)=>{var r=n(146),i=n(473),s=n(48),o=0,a=Math.pow(36,4);function l(){return i((s()*a|0).toString(36),4)}function c(){return o=o<a?o:0,++o-1}function u(){return"c"+(new Date).getTime().toString(36)+i(c().toString(36),4)+r()+(l()+l())}u.slug=function(){var t=(new Date).getTime().toString(36),e=c().toString(36).slice(-4),n=r().slice(0,1)+r().slice(-1),i=l().slice(-2);return t.slice(-2)+e+n+i},u.isCuid=function(t){return"string"==typeof t&&!!t.startsWith("c")},u.isSlug=function(t){if("string"!=typeof t)return!1;var e=t.length;return e>=7&&e<=10},u.fingerprint=r,t.exports=u},831:t=>{t.exports={AD:"EUR",AE:"AED",AF:"AFN",AG:"XCD",AI:"XCD",AL:"ALL",AM:"AMD",AO:"AOA",AQ:"EUR",AR:"ARS",AS:"USD",AT:"EUR",AU:"AUD",AW:"AWG",AX:"EUR",AZ:"AZN",BA:"BAM",BB:"BBD",BD:"BDT",BE:"EUR",BF:"XOF",BG:"BGN",BH:"BHD",BI:"BIF",BJ:"XOF",BL:"EUR",BM:"BMD",BN:"BND",BO:"BOB",BQ:"USD",BR:"BRL",BS:"BSD",BT:"BTN",BV:"NOK",BW:"BWP",BY:"BYN",BZ:"BZD",CA:"CAD",CC:"AUD",CD:"CDF",CF:"XAF",CG:"XAF",CH:"CHF",CI:"XOF",CK:"NZD",CL:"CLP",CM:"XAF",CN:"CNY",CO:"COP",CR:"CRC",CU:"CUP",CV:"CVE",CW:"ANG",CX:"AUD",CY:"EUR",CZ:"CZK",DE:"EUR",DJ:"DJF",DK:"DKK",DM:"XCD",DO:"DOP",DZ:"DZD",EC:"USD",EE:"EUR",EG:"EGP",EH:"MAD",ER:"ERN",ES:"EUR",ET:"ETB",FI:"EUR",FJ:"FJD",FK:"FKP",FM:"USD",FO:"DKK",FR:"EUR",GA:"XAF",GB:"GBP",GD:"XCD",GE:"GEL",GF:"EUR",GG:"GBP",GH:"GHS",GI:"GIP",GL:"DKK",GM:"GMD",GN:"GNF",GP:"EUR",GQ:"XAF",GR:"EUR",GS:"GBP",GT:"GTQ",GU:"USD",GW:"XOF",GY:"GYD",HK:"HKD",HM:"AUD",HN:"HNL",HR:"EUR",HT:"HTG",HU:"HUF",ID:"IDR",IE:"EUR",IL:"ILS",IM:"GBP",IN:"INR",IO:"USD",IQ:"IQD",IR:"IRR",IS:"ISK",IT:"EUR",JE:"GBP",JM:"JMD",JO:"JOD",JP:"JPY",KE:"KES",KG:"KGS",KH:"KHR",KI:"AUD",KM:"KMF",KN:"XCD",KP:"KPW",KR:"KRW",KW:"KWD",KY:"KYD",KZ:"KZT",LA:"LAK",LB:"LBP",LC:"XCD",LI:"CHF",LK:"LKR",LR:"LRD",LS:"LSL",LT:"EUR",LU:"EUR",LV:"EUR",LY:"LYD",MA:"MAD",MC:"EUR",MD:"MDL",ME:"EUR",MF:"EUR",MG:"MGA",MH:"USD",MK:"MKD",ML:"XOF",MM:"MMK",MN:"MNT",MO:"MOP",MP:"USD",MQ:"EUR",MR:"MRU",MS:"XCD",MT:"EUR",MU:"MUR",MV:"MVR",MW:"MWK",MX:"MXN",MY:"MYR",MZ:"MZN",NA:"NAD",NC:"XPF",NE:"XOF",NF:"AUD",NG:"NGN",NI:"NIO",NL:"EUR",NO:"NOK",NP:"NPR",NR:"AUD",NU:"NZD",NZ:"NZD",OM:"OMR",PA:"PAB",PE:"PEN",PF:"XPF",PG:"PGK",PH:"PHP",PK:"PKR",PL:"PLN",PM:"EUR",PN:"NZD",PR:"USD",PS:"ILS",PT:"EUR",PW:"USD",PY:"PYG",QA:"QAR",RE:"EUR",RO:"RON",RS:"RSD",RU:"RUB",RW:"RWF",SA:"SAR",SB:"SBD",SC:"SCR",SD:"SDG",SE:"SEK",SG:"SGD",SH:"SHP",SI:"EUR",SJ:"NOK",SK:"EUR",SL:"SLE",SM:"EUR",SN:"XOF",SO:"SOS",SR:"SRD",SS:"SSP",ST:"STN",SV:"SVC",SX:"ANG",SY:"SYP",SZ:"SZL",TC:"USD",TD:"XAF",TF:"EUR",TG:"XOF",TH:"THB",TJ:"TJS",TK:"NZD",TL:"USD",TM:"TMT",TN:"TND",TO:"TOP",TR:"TRY",TT:"TTD",TV:"AUD",TW:"TWD",TZ:"TZS",UA:"UAH",UG:"UGX",UM:"USD",US:"USD",UY:"UYU",UZ:"UZS",VA:"EUR",VC:"XCD",VE:"VED",VG:"USD",VI:"USD",VN:"VND",VU:"VUV",WF:"XPF",WS:"WST",YE:"YER",YT:"EUR",ZA:"ZAR",ZM:"ZMW",ZW:"ZWG"}},869:(t,e,n)=>{var r=n(831);e.getCurrency=function(t){var e,n,i=(e=t,n=e.split("_"),2==n.length||2==(n=e.split("-")).length?n.pop():e).toUpperCase();return i in r?r[i]:null},e.getLocales=function(t){t=t.toUpperCase();var e=[];for(var n in r)r[n]===t&&e.push(n);return e}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,n),s.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{CotomyActionEvent:()=>I,CotomyApi:()=>w,CotomyApiException:()=>m,CotomyApiFailedEvent:()=>C,CotomyApiForm:()=>U,CotomyApiResponse:()=>v,CotomyConflictException:()=>f,CotomyDebugFeature:()=>s,CotomyDebugSettings:()=>a,CotomyElement:()=>u,CotomyFillApiForm:()=>L,CotomyForbiddenException:()=>p,CotomyForm:()=>N,CotomyHttpClientError:()=>E,CotomyHttpServerError:()=>A,CotomyInvalidFormDataBodyException:()=>R,CotomyMetaElement:()=>h,CotomyNotFoundException:()=>y,CotomyPageController:()=>M,CotomyQueryForm:()=>b,CotomyResponseJsonParseException:()=>_,CotomyUnauthorizedException:()=>g,CotomyUrl:()=>P,CotomyValidationException:()=>T,CotomyViewRenderer:()=>O,CotomyWindow:()=>d});var t,e=n(353),i=n.n(e);!function(t){t[t.CONTINUE=100]="CONTINUE",t[t.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",t[t.PROCESSING=102]="PROCESSING",t[t.EARLY_HINTS=103]="EARLY_HINTS",t[t.OK=200]="OK",t[t.CREATED=201]="CREATED",t[t.ACCEPTED=202]="ACCEPTED",t[t.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",t[t.NO_CONTENT=204]="NO_CONTENT",t[t.RESET_CONTENT=205]="RESET_CONTENT",t[t.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",t[t.MULTI_STATUS=207]="MULTI_STATUS",t[t.MULTIPLE_CHOICES=300]="MULTIPLE_CHOICES",t[t.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",t[t.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",t[t.SEE_OTHER=303]="SEE_OTHER",t[t.NOT_MODIFIED=304]="NOT_MODIFIED",t[t.USE_PROXY=305]="USE_PROXY",t[t.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",t[t.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",t[t.BAD_REQUEST=400]="BAD_REQUEST",t[t.UNAUTHORIZED=401]="UNAUTHORIZED",t[t.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",t[t.FORBIDDEN=403]="FORBIDDEN",t[t.NOT_FOUND=404]="NOT_FOUND",t[t.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",t[t.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",t[t.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",t[t.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",t[t.CONFLICT=409]="CONFLICT",t[t.GONE=410]="GONE",t[t.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",t[t.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",t[t.REQUEST_TOO_LONG=413]="REQUEST_TOO_LONG",t[t.REQUEST_URI_TOO_LONG=414]="REQUEST_URI_TOO_LONG",t[t.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",t[t.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",t[t.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",t[t.IM_A_TEAPOT=418]="IM_A_TEAPOT",t[t.INSUFFICIENT_SPACE_ON_RESOURCE=419]="INSUFFICIENT_SPACE_ON_RESOURCE",t[t.METHOD_FAILURE=420]="METHOD_FAILURE",t[t.MISDIRECTED_REQUEST=421]="MISDIRECTED_REQUEST",t[t.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",t[t.LOCKED=423]="LOCKED",t[t.FAILED_DEPENDENCY=424]="FAILED_DEPENDENCY",t[t.UPGRADE_REQUIRED=426]="UPGRADE_REQUIRED",t[t.PRECONDITION_REQUIRED=428]="PRECONDITION_REQUIRED",t[t.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",t[t.REQUEST_HEADER_FIELDS_TOO_LARGE=431]="REQUEST_HEADER_FIELDS_TOO_LARGE",t[t.UNAVAILABLE_FOR_LEGAL_REASONS=451]="UNAVAILABLE_FOR_LEGAL_REASONS",t[t.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",t[t.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",t[t.BAD_GATEWAY=502]="BAD_GATEWAY",t[t.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",t[t.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",t[t.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",t[t.INSUFFICIENT_STORAGE=507]="INSUFFICIENT_STORAGE",t[t.NETWORK_AUTHENTICATION_REQUIRED=511]="NETWORK_AUTHENTICATION_REQUIRED"}(t||(t={}));var s,o=n(869);!function(t){t.Api="api",t.Fill="fill",t.Bind="bind",t.FormData="formdata",t.Html="html",t.Page="page"}(s||(s={}));class a{static isEnabled(t){const e=localStorage.getItem(this.PREFIX);return t&&"true"===localStorage.getItem(`${this.PREFIX}:${String(t)}`)||"true"===e}static enable(t){localStorage.setItem(`${this.PREFIX}:${String(t)}`,"true")}static disable(t){localStorage.setItem(`${this.PREFIX}:${String(t)}`,"false")}static enableAll(){localStorage.setItem(this.PREFIX,"true")}static disableAll(){localStorage.setItem(this.PREFIX,"false")}static clear(t){t?localStorage.removeItem(`${this.PREFIX}:${String(t)}`):localStorage.removeItem(this.PREFIX)}}a.PREFIX="cotomy:debug";var l=n(584),c=n.n(l);class u{static createHTMLElement(t){const e=(new DOMParser).parseFromString(t,"text/html");if(0===e.body.childNodes.length)throw new Error("Invalid HTML string provided.");return e.body.firstChild}static first(t,e){const n=document.querySelector(t);if(n)return new(e??u)(n)}static find(t,e){const n=document.querySelectorAll(t),r=e??u;return Array.from(n).map(t=>new r(t))}static contains(t){return null!==document.querySelector(t)}static byId(t,e){return this.first(`#${t}`,e)}static containsById(t){return null!==document.getElementById(t)}static empty(t){return new(t??u)(document.createElement("div")).setAttribute("data-cotomy-empty","").setElementStyle("display","none")}constructor(t){this._parentElement=null,this._scopeId=null,t instanceof HTMLElement?this._element=t:"string"==typeof t?this._element=u.createHTMLElement(t):(this._element=u.createHTMLElement(t.html),t.css&&this.useScopedCss(t.css),a.isEnabled(s.Html)&&(console.debug(`CotomyElement {html: "${t.html}" } is created`),t.css&&console.debug(`CotomyElement {css: "${t.css}" } is applied`))),this.removed(()=>{this._element=u.createHTMLElement('<div data-cotomy-invalid style="display: none;"></div>')})}get scopeId(){return this._scopeId||(this._scopeId=`_${c()()}`,this.setAttribute(this._scopeId,"")),this._scopeId}get scopedSelector(){return`[${this.scopeId}]`}get stylable(){return!["script","style","link","meta"].includes(this.tagname)}useScopedCss(t){if(t&&this.stylable){const e=`css-${this.scopeId}`;u.find(`#${e}`).forEach(t=>t.remove());const n=document.createElement("style"),r=t.replace(/\[scope\]/g,`[${this.scopeId}]`),i=document.createTextNode(r);n.appendChild(i),n.id=e,(u.first("head")||new u({html:"<head></head>"}).prependTo(new u(document.documentElement))).append(new u(n)),this.removed(()=>{u.find(`#${e}`).forEach(t=>t.remove())})}return this}listenLayoutEvents(){return this.setAttribute(u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE,""),this}get id(){return this.attribute("id")}setId(t){return this.setAttribute("id",t),this}get element(){return this._element}get tagname(){return this.element.tagName.toLowerCase()}is(t){const e=t.split(/\s+(?![^\[]*\])|(?<=\>)\s+/);let n=this.element;for(let t=e.length-1;t>=0;t--){let r=e[t].trim(),i=!1;if(r.startsWith(">")&&(i=!0,r=r.slice(1).trim()),!n||!n.matches(r))return!1;if(i)n=n.parentElement;else if(t>0)for(;n&&!n.matches(e[t-1].trim());)n=n.parentElement}return!0}get empty(){return new Set(["input","select","textarea","img","video","audio","br","hr","iframe","embed","canvas","object","svg","source","track","col","link","meta","base"]).has(this.tagname)||this._element.hasAttribute("data-cotomy-empty")||""===this._element.innerHTML.trim()}get attached(){return document.contains(this.element)}get readonly(){return"readOnly"in this.element?this.element.readOnly:this.element.hasAttribute("readonly")}set readonly(t){"readOnly"in this.element?this.element.readOnly=t:t?this.setAttribute("readonly","readonly"):this.removeAttribute("readonly")}get value(){return"value"in this.element?this.element.value:this.attribute("data-cotomy-value")??""}set value(t){"value"in this.element?this.element.value=t:this.setAttribute("data-cotomy-value",t)}get text(){return this.element.textContent??""}set text(t){this.element.textContent=t??""}get html(){return this.element.innerHTML}set html(t){this.element.innerHTML=t}convertUtcToLocal(t="YYYY-MM-DD HH:mm",e=!0){if(this.hasClass("utc")){if(""===this.text.trim())return this;const e=/[+-]\d{2}:\d{2}$/.test(this.text),n=new Date(this.text+(e?"":"Z"));this.text=isNaN(n.getTime())?"":i()(n).format(t),this.removeClass("utc")}if("datetime-local"===this.attribute("type")){const e=/[+-]\d{2}:\d{2}$/.test(this.value),n=new Date(this.value+(e?"":"Z"));this.value=isNaN(n.getTime())?"":i()(n).format(t)}return e&&this.find(".utc").forEach(n=>{n.convertUtcToLocal(t,e)}),this}setFocus(){this.element.focus()}get visible(){if(!this.attached)return!1;if(!this.element.offsetParent&&!document.contains(this.element))return!1;const t=this.element.getBoundingClientRect();if(t.width>0&&t.height>0){const t=this.computedStyle;return"none"!==t.display&&"hidden"!==t.visibility&&"collapse"!==t.visibility}return!1}get enabled(){return!(this.element.hasAttribute("disabled")&&null!==this.element.getAttribute("disabled"))}set enabled(t){t?this.element.removeAttribute("disabled"):this.element.setAttribute("disabled","disabled")}get valid(){return!this.element.hasAttribute("data-cotomy-invalid")}remove(){this.valid&&this._element.remove()}clone(){return new u(document.createElement(this.tagname))}clean(){this.find("*").forEach(t=>t.remove()),this.text=""}get width(){return this.element.offsetWidth}set width(t){let e=t.toString()+"px";this.setElementStyle("width",e)}get height(){return this.element.offsetHeight}set height(t){let e=t.toString()+"px";this.setElementStyle("height",e)}get innerWidth(){return this.element.clientWidth}get innerHeight(){return this.element.clientHeight}get outerWidth(){const t=parseFloat(this.computedStyle.marginLeft)+parseFloat(this.computedStyle.marginRight);return this.element.offsetWidth+t}get outerHeight(){const t=this.computedStyle,e=parseFloat(t.marginTop)+parseFloat(t.marginBottom);return this.element.offsetHeight+e}get scrollHeight(){return this.element.scrollHeight}get scrollWidth(){return this.element.scrollWidth}get scrollTop(){return this.element.scrollTop}get position(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left}}get absolutePosition(){const t=this.element.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX}}get screenPosition(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left}}get rect(){const t=this.element.getBoundingClientRect();return{top:t.top,left:t.left,width:t.width,height:t.height}}get innerRect(){const t=this.element.getBoundingClientRect(),e=this.computedStyle,n=parseFloat(e.paddingTop),r=parseFloat(e.paddingRight),i=parseFloat(e.paddingBottom),s=parseFloat(e.paddingLeft);return{top:t.top+n,left:t.left+s,width:t.width-s-r,height:t.height-n-i}}get outerRect(){const t=this.element.getBoundingClientRect(),e=this.computedStyle,n=parseFloat(e.marginTop),r=parseFloat(e.marginRight),i=parseFloat(e.marginBottom),s=parseFloat(e.marginLeft);return{top:t.top-n,left:t.left-s,width:t.width+s+r,height:t.height+n+i}}get padding(){const t=this.computedStyle;return{top:parseFloat(t.paddingTop),right:parseFloat(t.paddingRight),bottom:parseFloat(t.paddingBottom),left:parseFloat(t.paddingLeft)}}get margin(){const t=this.computedStyle;return{top:parseFloat(t.marginTop),right:parseFloat(t.marginRight),bottom:parseFloat(t.marginBottom),left:parseFloat(t.marginLeft)}}get inViewport(){const t=this.element.getBoundingClientRect();return t.top<window.innerHeight&&t.bottom>0}get isAboveViewport(){return this.element.getBoundingClientRect().bottom<0}get isBelowViewport(){return this.element.getBoundingClientRect().top>window.innerHeight}get isLeftViewport(){return this.element.getBoundingClientRect().right<0}get isRightViewport(){return this.element.getBoundingClientRect().left>window.innerWidth}hasAttribute(t){return this.element.hasAttribute(t)}attribute(t){return this.element.hasAttribute(t)?this.element.getAttribute(t):void 0}setAttribute(t,e=void 0){return this.element.setAttribute(t,e?.toString()??""),this}removeAttribute(t){this.element.removeAttribute(t)}hasClass(t){return this.element.classList.contains(t)}addClass(t){return this.element.classList.add(t),this}removeClass(t){return this.element.classList.remove(t),this}setElementStyle(t,e){return this.element.style.setProperty(t,e),this}removeElementStyle(t){return this.element.style.removeProperty(t),this}get computedStyle(){return window.getComputedStyle(this.element)}style(t){return this.computedStyle.getPropertyValue(t)}get parent(){return null==this._parentElement&&null!==this.element.parentElement&&(this._parentElement=new u(this.element.parentElement)),this._parentElement??u.empty()}get parents(){let t=[],e=this.element.parentElement;for(;null!==e;)t.push(new u(e)),e=e.parentElement;return t}hasChildren(t="*"){return null!==this.element.querySelector(t)}children(t="*",e){const n=Array.from(this.element.querySelectorAll(t)).filter(t=>t.parentElement===this.element),r=e??u;return n.filter(t=>t instanceof HTMLElement).map(t=>new r(t))}firstChild(t="*",e){return this.children(t,e).shift()??void 0}lastChild(t="*",e){return this.children(t,e).pop()??void 0}closest(t,e){const n=this.element.closest(t);if(null!==n&&n instanceof HTMLElement)return new(e??u)(n)}find(t,e){return Array.from(this.element.querySelectorAll(t)).map(t=>new(e??u)(t))}first(t="*",e){return this.find(t,e).shift()??void 0}prepend(t){return this._element.prepend(t.element),this}append(t){return this.element.append(t.element),this}appendAll(t){return t.forEach(t=>this.append(t)),this}insertBefore(t){return this.element.before(t.element),this}insertAfter(t){return this.element.after(t.element),this}appendTo(t){return t.element.append(this.element),this}prependTo(t){return t.element.prepend(this.element),this}trigger(t,e=null){return this.element.dispatchEvent(e??new Event(t)),this}on(t,e){return this.element.addEventListener(t,e),this}onChild(t,e,n){return this.element.addEventListener(t,t=>{if(t.target instanceof HTMLElement){const r=new u(t.target).closest(e);r&&n(t,r.element)}}),this}once(t,e){return this.element.addEventListener(t,e,{once:!0}),this}off(t,e){return this.element.removeEventListener(t,e),this}click(t=null){return t?this.element.addEventListener("click",async e=>await t(e)):this.trigger("click"),this}dblclick(t=null){return t?this.element.addEventListener("dblclick",async e=>await t(e)):this.trigger("dblclick"),this}mouseover(t=null){return t?this.element.addEventListener("mouseover",async e=>await t(e)):this.trigger("mouseover"),this}mouseout(t=null){return t?this.element.addEventListener("mouseout",async e=>await t(e)):this.trigger("mouseout"),this}mousedown(t=null){return t?this.element.addEventListener("mousedown",async e=>await t(e)):this.trigger("mousedown"),this}mouseup(t=null){return t?this.element.addEventListener("mouseup",async e=>await t(e)):this.trigger("mouseup"),this}mousemove(t=null){return t?this.element.addEventListener("mousemove",async e=>await t(e)):this.trigger("mousemove"),this}mouseenter(t=null){return t?this.element.addEventListener("mouseenter",async e=>await t(e)):this.trigger("mouseenter"),this}mouseleave(t=null){return t?this.element.addEventListener("mouseleave",async e=>await t(e)):this.trigger("mouseleave"),this}dragstart(t=null){return t?this.element.addEventListener("dragstart",async e=>await t(e)):this.trigger("dragstart"),this}dragend(t=null){return t?this.element.addEventListener("dragend",async e=>await t(e)):this.trigger("dragend"),this}dragover(t=null){return t?this.element.addEventListener("dragover",async e=>await t(e)):this.trigger("dragover"),this}dragenter(t=null){return t?this.element.addEventListener("dragenter",async e=>await t(e)):this.trigger("dragenter"),this}dragleave(t=null){return t?this.element.addEventListener("dragleave",async e=>await t(e)):this.trigger("dragleave"),this}drop(t=null){return t?this.element.addEventListener("drop",async e=>await t(e)):this.trigger("drop"),this}drag(t=null){return t?this.element.addEventListener("drag",async e=>await t(e)):this.trigger("drag"),this}removed(t){return this.element.addEventListener("removed",async e=>await t(e)),this}keydown(t=null){return t?this.element.addEventListener("keydown",async e=>await t(e)):this.trigger("keydown"),this}keyup(t=null){return t?this.element.addEventListener("keyup",async e=>await t(e)):this.trigger("keyup"),this}keypress(t=null){return t?this.element.addEventListener("keypress",async e=>await t(e)):this.trigger("keypress"),this}change(t=null){return t?this.element.addEventListener("change",async e=>await t(e)):this.trigger("change"),this}input(t=null){return t?this.element.addEventListener("input",async e=>await t(e)):this.trigger("input"),this}static get intersectionObserver(){return u._intersectionObserver=u._intersectionObserver??new IntersectionObserver(t=>{t.filter(t=>t.isIntersecting).forEach(t=>t.target.dispatchEvent(new Event("inview"))),t.filter(t=>!t.isIntersecting).forEach(t=>t.target.dispatchEvent(new Event("outview")))})}inview(t=null){return t?(u.intersectionObserver.observe(this.element),this.element.addEventListener("inview",async e=>await t(e))):this.trigger("inview"),this}outview(t=null){return t?(u.intersectionObserver.observe(this.element),this.element.addEventListener("outview",async e=>await t(e))):this.trigger("outview"),this}focus(t=null){return t?this.element.addEventListener("focus",async e=>await t(e)):this.trigger("focus"),this}blur(t=null){return t?this.element.addEventListener("blur",async e=>await t(e)):this.trigger("blur"),this}focusin(t=null){return t?this.element.addEventListener("focusin",async e=>await t(e)):this.trigger("focusin"),this}focusout(t=null){return t?this.element.addEventListener("focusout",async e=>await t(e)):this.trigger("focusout"),this}filedrop(t){return this.element.addEventListener("drop",async e=>{e.preventDefault();const n=e.dataTransfer;n&&n.files&&await t(Array.from(n.files))}),this}resize(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:resize",async e=>await t(e)):this.trigger("cotomy:resize"),this}scroll(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:scroll",async e=>await t(e)):this.trigger("cotomy:scroll"),this}changelayout(t=null){return this.listenLayoutEvents(),t?this.element.addEventListener("cotomy:changelayout",async e=>await t(e)):this.trigger("cotomy:changelayout"),this}}u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE="data-cotomy-layout",u._intersectionObserver=null;class h extends u{static get(t){return u.first(`meta[name="${t}" i]`,h)??u.empty(h)}get content(){return this.attribute("content")??""}}class d{constructor(){this._body=u.empty(),this._mutationObserver=null,this._reloading=!1}static get instance(){return d._instance??(d._instance=new d)}get initialized(){return this._body.attached}initialize(){if(!this.initialized){if(!document.body)throw new Error("<body> element not found. DOM may not be ready.");this._body=u.first("body"),["resize","scroll","orientationchange","fullscreenchange","cotomy:ready"].forEach(t=>{window.addEventListener(t,()=>{const t=new CustomEvent("cotomy:changelayout");window.dispatchEvent(t)},{passive:!0})}),document.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()}),document.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()}),this.resize(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:resize"))})}),this.scroll(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:scroll"))})}),this.changeLayout(()=>{document.querySelectorAll(`[${u.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(t=>{t.dispatchEvent(new CustomEvent("cotomy:changelayout"))})}),this._mutationObserver=new MutationObserver(t=>{t.forEach(t=>{t.removedNodes.forEach(t=>{t instanceof HTMLElement&&new u(t).trigger("removed")})})}),this._mutationObserver.observe(this.body.element,{childList:!0,subtree:!0})}}get reloading(){return this._reloading}reload(){this._reloading=!0,location.reload()}get body(){return this._body}append(t){this._body.append(t)}moveNext(t,e=!1){const n=Array.from(this.body.element.querySelectorAll("input, a, select, button, textarea")).map(t=>new u(t)).filter(t=>t.width>0&&t.height>0&&t.visible&&t.enabled&&!t.hasAttribute("readonly"));let r=n.map(t=>t.element).indexOf(t.element)+(e?-1:1);r>=n.length?r=0:r<0&&(r=n.length-1),n[r]&&n[r].setFocus()}trigger(t){window.dispatchEvent(new Event(t))}load(t){window.addEventListener("load",async e=>await t(e))}ready(t){window.addEventListener("cotomy:ready",async e=>await t(e))}on(t,e){window.addEventListener(t,async t=>await e(t))}resize(t=null){t?window.addEventListener("resize",async e=>await t(e)):this.trigger("resize")}scroll(t=null){t?window.addEventListener("scroll",async e=>await t(e)):this.trigger("scroll")}changeLayout(t=null){t?window.addEventListener("cotomy:changelayout",async e=>await t(e)):this.trigger("cotomy:changelayout")}pageshow(t=null){t?window.addEventListener("pageshow",async e=>await t(e)):this.trigger("pageshow")}get scrollTop(){return window.scrollY||document.documentElement.scrollTop}get scrollLeft(){return window.scrollX||document.documentElement.scrollLeft}get width(){return window.innerWidth}get height(){return window.innerHeight}get documentWidth(){return document.documentElement.scrollWidth}get documentHeight(){return document.documentElement.scrollHeight}}d._instance=null;class m extends Error{constructor(t,e,n,r=""){super(e),this.status=t,this.message=e,this.response=n,this.bodyText=r,this.name="CotomyApiException"}}class E extends m{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyHttpClientError"}}class g extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyUnauthorizedException"}}class p extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyForbiddenException"}}class y extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyNotFoundException"}}class f extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyConflictException"}}class T extends E{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyValidationException"}}class A extends m{constructor(t,e,n,r=""){super(t,e,n,r),this.name="CotomyHttpServerError"}}class _ extends Error{constructor(t="Failed to parse JSON response."){super(t),this.name="ResponseJsonParseException"}}class R extends Error{constructor(t="Body must be an instance of FormData."){super(t),this.name="InvalidFormDataBodyException"}}class S{}S.GET="GET",S.POST="POST",S.PUT="PUT",S.PATCH="PATCH",S.DELETE="DELETE",S.HEAD="HEAD",S.OPTIONS="OPTIONS",S.TRACE="TRACE",S.CONNECT="CONNECT";class D{static getMessage(t){return this._responseMessages[t]||`Unexpected error: ${t}`}}D._responseMessages={[t.BAD_REQUEST]:"There is an error in the input. Please check and try again.",[t.UNAUTHORIZED]:"You are not authenticated. Please log in again.",[t.FORBIDDEN]:"You do not have permission to use this feature. If necessary, please contact the administrator.",[t.NOT_FOUND]:"The specified information could not be found. It may have been deleted. Please start over or contact the administrator.",[t.METHOD_NOT_ALLOWED]:"This operation is currently prohibited on the server.",[t.NOT_ACCEPTABLE]:"The request cannot be accepted. Processing has been stopped.",[t.PROXY_AUTHENTICATION_REQUIRED]:"Proxy authentication is required for internet access.",[t.REQUEST_TIMEOUT]:"The request timed out. Please try again.",[t.CONFLICT]:"The identifier you are trying to register already exists. Please check the content and try again.",[t.PAYMENT_REQUIRED]:"Payment is required for this operation. Please check.",[t.GONE]:"The requested resource is no longer available.",[t.LENGTH_REQUIRED]:"The Content-Length header field is required for the request.",[t.PRECONDITION_FAILED]:"The request failed because the precondition was not met.",[t.UNSUPPORTED_MEDIA_TYPE]:"The requested media type is not supported.",[t.EXPECTATION_FAILED]:"The server cannot meet the Expect header of the request.",[t.MISDIRECTED_REQUEST]:"The server cannot appropriately process this request.",[t.UNPROCESSABLE_ENTITY]:"There is an error in the request content.",[t.LOCKED]:"The requested resource is locked.",[t.FAILED_DEPENDENCY]:"The request failed due to dependency on a previous failed request.",[t.UPGRADE_REQUIRED]:"A protocol upgrade is required to perform this operation.",[t.PRECONDITION_REQUIRED]:"This request requires a precondition.",[t.TOO_MANY_REQUESTS]:"Too many requests have been sent in a short time. Please wait and try again.",[t.REQUEST_HEADER_FIELDS_TOO_LARGE]:"The request headers are too large.",[t.INTERNAL_SERVER_ERROR]:"An unexpected error occurred. Please try again later.",[t.BAD_GATEWAY]:"The server is currently overloaded. Please wait and try again later.",[t.SERVICE_UNAVAILABLE]:"The service is temporarily unavailable. Please try again later.",[t.GATEWAY_TIMEOUT]:"The communication timed out. Please try again.",[t.HTTP_VERSION_NOT_SUPPORTED]:"The current communication method is not supported.",[t.NOT_IMPLEMENTED]:"The server does not support the requested functionality.",[t.INSUFFICIENT_STORAGE]:"The server has insufficient storage.",[t.NETWORK_AUTHENTICATION_REQUIRED]:"Network authentication is required.",413:"The payload of the request is too large. Please check the size.",414:"The request URI is too long.",416:"The requested range is invalid.",508:"The server detected a loop.",510:"The request does not include the required extensions."};class v{constructor(t){this._response=t,this._json=null,this._map=null}get available(){return!!this._response}get empty(){return!this._response||0===this._response.status}get ok(){return this._response?.ok??!1}get status(){return this._response?.status??0}get statusText(){return this._response?.statusText??""}get headers(){return this._response?.headers??new Headers}async textAsync(){return await(this._response?.text())||""}async blobAsync(){return await(this._response?.blob())||new Blob}async objectAsync(t={}){if(this._response&&!this._json)try{const e=await this._response.text();if(!e)return t;this._json=JSON.parse(e)}catch(t){throw new _(`Failed to parse JSON response: ${t instanceof Error?t.message:String(t)}`)}return this._json}}class O{constructor(t){this.element=t,this._locale=null,this._currency=null,this._renderers={},this._builded=!1}get locale(){return this._locale=this._locale||navigator.language||"en-US"}get currency(){return this._currency=this._currency||o.getCurrency(this.locale)||"USD"}renderer(t,e){return this._renderers[t]=e,this}get initialized(){return this._builded}initialize(){return this.initialized||(this.renderer("mail",(t,e)=>{t.clean(),e&&new u(`<a href="mailto:${e}">${e}</a>`).appendTo(t)}),this.renderer("tel",(t,e)=>{t.clean(),e&&new u(`<a href="tel:${e}">${e}</a>`).appendTo(t)}),this.renderer("url",(t,e)=>{t.clean(),e&&new u(`<a href="${e}" target="_blank">${e}</a>`).appendTo(t)}),this.renderer("number",(t,e)=>{t.clean(),e&&(t.text=new Intl.NumberFormat(navigator.language||this.locale).format(e))}),this.renderer("currency",(t,e)=>{t.clean(),e&&(t.text=new Intl.NumberFormat(navigator.language||this.locale,{style:"currency",currency:this.currency}).format(e))}),this.renderer("utc",(t,e)=>{if(t.clean(),e){const n=/[+-]\d{2}:\d{2}$/.test(e)?new Date(e):new Date(`${e}Z`);if(!isNaN(n.getTime())){const e=t.attribute("data-cotomy-format")??"YYYY/MM/DD HH:mm";t.text=i()(n).format(e)}}})),this}async applyAsync(t){if(this.initialized||this.initialize(),!t.available)throw new Error("Response is not available.");for(const[e,n]of Object.entries(await t.objectAsync()))this.element.find(`[data-cotomy-bind="${e}" i]`).forEach(t=>{a.isEnabled(s.Bind)&&console.debug(`Binding data to element [data-cotomy-bind="${e}"]:`,n);const r=t.attribute("data-cotomy-bindtype")?.toLowerCase();r&&this._renderers[r]?this._renderers[r](t,n):t.text=String(n??"")});return this}}class w{constructor(t={baseUrl:null,headers:null,credentials:null,redirect:null,cache:null,referrerPolicy:null,mode:null,keepalive:!0,integrity:""}){this._options=t,this._abortController=new AbortController}get baseUrl(){return this._options.baseUrl||""}get headers(){return this._options.headers||{}}get credentials(){return this._options.credentials||"same-origin"}get redirect(){return this._options.redirect||"follow"}get cache(){return this._options.cache||"no-cache"}get referrerPolicy(){return this._options.referrerPolicy||"no-referrer"}get mode(){return this._options.mode||"cors"}get keepalive(){return this._options.keepalive||!0}get integrity(){return this._options.integrity||""}get abortController(){return this._abortController}async requestAsync(e,n,r,i,o){a.isEnabled(s.Api)&&console.debug(`API request: ${e} ${n}`,{body:r,headers:this.headers});const l={"application/json":t=>JSON.stringify(t),"application/x-www-form-urlencoded":t=>{if(t instanceof globalThis.FormData){let e=new URLSearchParams;return t.forEach((t,n)=>{e.append(n,String(t))}),e.toString()}return new URLSearchParams(t).toString()},"multipart/form-data":t=>{if(t instanceof globalThis.FormData)return t;const e=new globalThis.FormData;for(const[n,r]of Object.entries(t))e.append(n,String(r));return e}},c=/^[a-zA-Z]/.test(n)?n:`${(this.baseUrl||"").replace(/\/$/,"")}/${n.replace(/^\//,"")}`,u=new Headers(this.headers);u.has("Content-Type")&&"multipart/form-data"===u.get("Content-Type")&&u.delete("Content-Type");const h=u.get("Content-Type")||"multipart/form-data",d=new(o??v)(await fetch(c,{method:e,headers:u,credentials:this.credentials,body:r?l[h]?l[h](r):r:void 0,signal:i??this._abortController.signal,redirect:this.redirect,cache:this.cache,referrerPolicy:this.referrerPolicy,mode:this.mode,keepalive:this.keepalive,integrity:this.integrity}));if(d.status>=400&&d.status<600){const e=await d.textAsync().catch(()=>"No response body available"),n=d.statusText||D.getMessage(d.status)||`Unexpected error: ${d.status}`;switch(a.isEnabled(s.Api)&&console.error(`API request failed: ${n}`,d,e),d.status){case t.BAD_REQUEST:case t.UNPROCESSABLE_ENTITY:throw new T(d.status,n,d,e);case t.UNAUTHORIZED:throw new g(d.status,n,d,e);case t.FORBIDDEN:throw new p(d.status,n,d,e);case t.NOT_FOUND:throw new y(d.status,n,d,e);case t.CONFLICT:case t.GONE:throw new f(d.status,n,d,e);default:throw d.status<500?new E(d.status,n,d,e):new A(d.status,n,d,e)}}return d}async getAsync(t,e){let n="";if(e instanceof globalThis.FormData){let t=new URLSearchParams;e.forEach((e,n)=>{t.append(n,String(e))}),n=t.toString()}else e&&(n=new URLSearchParams(Object.fromEntries(Object.entries(e).map(([t,e])=>[t,String(e)]))).toString());const r=n?`${t}?${n}`:t;return a.isEnabled(s.Api)&&console.debug(`GET request to: ${r}`),this.requestAsync(S.GET,r)}async postAsync(t,e){return this.requestAsync(S.POST,t,e)}async putAsync(t,e){return this.requestAsync(S.PUT,t,e)}async patchAsync(t,e){return this.requestAsync(S.PATCH,t,e)}async deleteAsync(t){return this.requestAsync(S.DELETE,t)}async headAsync(t){return this.requestAsync(S.HEAD,t)}async optionsAsync(t){return this.requestAsync(S.OPTIONS,t)}async traceAsync(t){return this.requestAsync(S.TRACE,t)}async connectAsync(t){return this.requestAsync(S.CONNECT,t)}async submitAsync(t){return t.method.toUpperCase()===S.GET?this.getAsync(t.action,t.body):this.requestAsync(t.method.toUpperCase(),t.action,t.body)}}class I extends Event{constructor(t){super("cotomy:action",{bubbles:!0,cancelable:!0}),this.action=t}}class N extends u{constructor(t){super(t)}get formId(){return this.hasAttribute("id")||this.setAttribute("id",this.scopeId),this.attribute("id")}method(){return this.attribute("method")??"get"}actionUri(){return this.attribute("action")??location.pathname+location.search}get autoComplete(){return"on"===this.attribute("autocomplete")}set autoComplete(t){this.setAttribute("autocomplete",t?"on":"off")}reload(){d.instance.reload()}get autoRestore(){return"false"!==this.attribute("data-cotomy-restore")}set autoRestore(t){t?this.removeAttribute("data-cotomy-restore"):this.setAttribute("data-cotomy-restore","false")}restore(){this.autoRestore&&this.reload()}get initialized(){return this.hasAttribute("data-cotomy-builded")}initialize(){return this.initialized||(this.on("submit",async t=>{await this.submitAsync(t)}),d.instance.pageshow(t=>{t.persisted&&!d.instance.reloading&&this.restore()}),this.find("button[type=button][data-cotomy-action]").forEach(t=>{t.click(()=>{this.trigger("cotomy:action",new I(t.attribute("data-cotomy-action")))})}),this.setAttribute("data-cotomy-builded")),this}submit(){this.trigger("submit")}action(t){return"string"==typeof t?this.trigger("cotomy:action",new I(t)):this.element.addEventListener("cotomy:action",async e=>{await t(e)}),this}}class b extends N{constructor(t){super(t),this.autoComplete=!0}method(){return"get"}async submitAsync(t){t.preventDefault(),t.stopPropagation();const e=this.actionUri(),n={},r=e.split("?")[1];r&&r.split("&").forEach(t=>{const[e,r]=t.split("=");e&&r&&(n[e]=decodeURIComponent(r))}),this.find("[name]").forEach(t=>{const e=t.attribute("name");if(e){const r=t.value;r?n[e]=encodeURIComponent(r):delete n[e]}});const i=Object.entries(n).map(([t,e])=>`${t}=${e}`).join("&");location.href=`${e.split("?")[0]}?${i}`}}class C extends Event{constructor(t,e="cotomy:apifailed"){super(e,{bubbles:!0,cancelable:!0}),this._response=t}get response(){return this._response}}class U extends N{constructor(t){super(t)}apiClient(){return new w}actionUri(){return`${this.attribute("action")}/${this.autoIncrement?this.attribute("data-cotomy-key")||"":this.identifierString}`}get identifier(){return this.attribute("data-cotomy-key")||void 0}setIncrementedId(t){const e=t.headers.get("Location")?.split("/").pop();this.setAttribute("data-cotomy-key",e)}get identifierInputs(){return this.find("[data-cotomy-keyindex]").sort((t,e)=>parseInt(t.attribute("data-cotomy-keyindex")??"0")-parseInt(e.attribute("data-cotomy-keyindex")??"0"))}get identifierString(){return this.identifier??this.identifierInputs.map(t=>t.value).join("/")}get autoIncrement(){return!this.identifier&&0==this.identifierInputs.length}apiFailed(t){return this.on("cotomy:apifailed",async e=>{await t(e)}),this}triggerApiFailedEvent(t){this.trigger("cotomy:apifailed",new C(t)),a.isEnabled(s.Api)&&console.error("API request failed:",t)}submitFailed(t){return this.on("cotomy:submitfailed",async e=>{await t(e)}),this}triggerSubmitFailedEvent(t){this.trigger("cotomy:submitfailed",new C(t,"cotomy:submitfailed")),a.isEnabled(s.Api)&&console.error("Submit failed:",t)}method(){return this.autoIncrement||!this.identifierInputs.every(t=>t.readonly)?"post":"put"}formData(){const t=this.element,e=new FormData(t);return this.find("input[type=datetime-local][name]:not([disabled])").forEach(t=>{const n=t.value;if(n){const r=new Date(n);isNaN(r.getTime())||e.set(t.attribute("name"),i()(r).format("YYYY-MM-DDTHH:mmZ"))}}),a.isEnabled(s.FormData)&&console.debug("FormData:",Array.from(e.entries())),e}async submitAsync(t){t.preventDefault(),t.stopPropagation();const e=this.formData();await this.submitToApiAsync(e)}async submitToApiAsync(e){const n=this.apiClient();try{const r=await n.submitAsync({method:this.method(),action:this.actionUri(),body:e});this.autoIncrement&&r.status===t.CREATED&&this.setIncrementedId(r);const i=r.headers.get("Location");return i?(location.href=i,r):r}catch(t){throw t instanceof m&&(this.triggerApiFailedEvent(t.response),this.triggerSubmitFailedEvent(t.response)),t}}}class L extends U{constructor(t){super(t),this._fillers={}}filler(t,e){return this._fillers[t]=e,this}initialize(){return this.initialized||(super.initialize(),this.filler("datetime-local",(t,e)=>{const n=/[+-]\d{2}:\d{2}$/.test(e)?new Date(e):new Date(`${e}Z`);isNaN(n.getTime())?t.value="":t.value=i()(n).format("YYYY-MM-DDTHH:mm")}),this.filler("checkbox",(t,e)=>{t.removeAttribute("checked"),e&&t.setAttribute("checked")}),this.filler("radio",(t,e)=>{t.removeAttribute("checked"),t.value===e&&t.setAttribute("checked")}),d.instance.ready(async()=>{await this.loadAsync()})),this}async submitToApiAsync(t){const e=await super.submitToApiAsync(t);return e.ok&&await this.fillAsync(e),e}reload(){this.loadAsync()}loadActionUri(){return this.actionUri()}renderer(){return new O(this)}async loadAsync(){if(this.autoIncrement||!this.identifierInputs.every(t=>t.value))return new v;const t=this.apiClient();try{const e=await t.getAsync(this.loadActionUri());return await this.fillAsync(e),e}catch(t){if(t instanceof m&&this.triggerApiFailedEvent(t.response),t instanceof y)return t.response;throw t}}async fillAsync(t){if(t.ok&&t.available){for(const[e,n]of Object.entries(await t.objectAsync()))e.endsWith("[]")||this.find(`input[name="${e}" i]:not([data-cotomy-fill="false"]):not([multiple]),\n textarea[name="${e}" i]:not([data-cotomy-fill="false"]), \n select[name="${e}" i]:not([data-cotomy-fill="false"]):not([multiple])`).forEach(t=>{a.isEnabled(s.Fill)&&console.debug(`Filling input[name="${e}"] with value:`,n);const r=t.attribute("type")?.toLowerCase();r&&this._fillers[r]?this._fillers[r](t,n):t.value=String(n||"")});await this.renderer().applyAsync(t)}this.identifierInputs.forEach(t=>t.setElementStyle("background-color","#f0f0f0")),this.identifierInputs.forEach(t=>t.setAttribute("readonly")),this.find("textarea").forEach(t=>t.input())}}class P{static location(){return new P}constructor(t=null){this._url=t??this.current()}current(){const{pathname:t,search:e}=location;return`${t}${e}`}get url(){return this._url}get path(){return this._url.split("?")[0]}get segments(){return this.path.split("/").filter(t=>t.length>0).filter(t=>t.length>0)}get query(){return this._url.split("?")[1]??""}get parameters(){const t=(this._url.split("?")[1]??"").split("&").map(t=>t.split("=")),e={};return t.forEach(([t,n])=>e[t]=n),e}redirect(){window.location.href=this.url}}class M{constructor(){this._forms={}}static set(t){if(this._instance)throw new Error("PageController is already initialized.");return this._instance=new t,d.instance.load(async()=>{a.isEnabled(s.Page)&&console.debug("CotomyPageController initialize."),d.instance.initialize(),await M._instance.initializeAsync(),d.instance.trigger("cotomy:ready")}),this._instance}static get(){if(!(this._instance instanceof M))throw new Error("PageController is not initialized. Use CotomyPageController.set() to initialize it.");return this._instance}setForm(t){return this._forms[t.formId]=t,t.removed(()=>{delete this._forms[t.formId]}),t.initialize()}getForm(t,e){const n=this._forms[t];if(n){if(e&&!(n instanceof e))throw new Error(`Form "${t}" is not instance of expected type.`);return n}}forms(){return Object.values(this._forms)}async initializeAsync(){this.body.convertUtcToLocal()}get body(){return d.instance.body}get uri(){return new P}}M._instance=null})(),r})());
package/dist/view.d.ts CHANGED
@@ -2,8 +2,9 @@ export declare class CotomyElement {
2
2
  protected static createHTMLElement(html: string): HTMLElement;
3
3
  static first<T extends CotomyElement = CotomyElement>(selector: string, type?: new (el: HTMLElement) => T): T | undefined;
4
4
  static find<T extends CotomyElement = CotomyElement>(selector: string, type?: new (el: HTMLElement) => T): T[];
5
- static byId<T extends CotomyElement = CotomyElement>(id: string, type?: new (el: HTMLElement) => T): T | undefined;
6
5
  static contains(selector: string): boolean;
6
+ static byId<T extends CotomyElement = CotomyElement>(id: string, type?: new (el: HTMLElement) => T): T | undefined;
7
+ static containsById(id: string): boolean;
7
8
  static empty<T extends CotomyElement = CotomyElement>(type?: new (el: HTMLElement) => T): T;
8
9
  private _element;
9
10
  private _parentElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cotomy",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [