cotomy 0.1.62 → 0.1.63

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.
@@ -0,0 +1,2898 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["Cotomy"] = factory();
8
+ else
9
+ root["Cotomy"] = factory();
10
+ })(this, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ var __webpack_modules__ = ({
13
+
14
+ /***/ 48:
15
+ /***/ ((module) => {
16
+
17
+
18
+ var getRandomValue;
19
+
20
+ var crypto = typeof window !== 'undefined' &&
21
+ (window.crypto || window.msCrypto) ||
22
+ typeof self !== 'undefined' &&
23
+ self.crypto;
24
+
25
+ if (crypto) {
26
+ var lim = Math.pow(2, 32) - 1;
27
+ getRandomValue = function () {
28
+ return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim);
29
+ };
30
+ } else {
31
+ getRandomValue = Math.random;
32
+ }
33
+
34
+ module.exports = getRandomValue;
35
+
36
+
37
+ /***/ }),
38
+
39
+ /***/ 146:
40
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
41
+
42
+ var pad = __webpack_require__(473);
43
+
44
+ var env = typeof window === 'object' ? window : self;
45
+ var globalCount = Object.keys(env).length;
46
+ var mimeTypesLength = navigator.mimeTypes ? navigator.mimeTypes.length : 0;
47
+ var clientId = pad((mimeTypesLength +
48
+ navigator.userAgent.length).toString(36) +
49
+ globalCount.toString(36), 4);
50
+
51
+ module.exports = function fingerprint () {
52
+ return clientId;
53
+ };
54
+
55
+
56
+ /***/ }),
57
+
58
+ /***/ 353:
59
+ /***/ (function(module) {
60
+
61
+ !function(t,e){ true?module.exports=e():0}(this,(function(){"use strict";var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|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,M={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])+"]"}},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+m(r,2,"0")+":"+m(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,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return+(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.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($);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()},m.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()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.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 b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
62
+
63
+ /***/ }),
64
+
65
+ /***/ 473:
66
+ /***/ ((module) => {
67
+
68
+ module.exports = function pad (num, size) {
69
+ var s = '000000000' + num;
70
+ return s.substr(s.length - size);
71
+ };
72
+
73
+
74
+ /***/ }),
75
+
76
+ /***/ 569:
77
+ /***/ (function(module) {
78
+
79
+ !function(t,e){ true?module.exports=e():0}(this,(function(){"use strict";var t={year:0,month:1,day:2,hour:3,minute:4,second:5},e={};return function(n,i,o){var r,a=function(t,n,i){void 0===i&&(i={});var o=new Date(t),r=function(t,n){void 0===n&&(n={});var i=n.timeZoneName||"short",o=t+"|"+i,r=e[o];return r||(r=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:i}),e[o]=r),r}(n,i);return r.formatToParts(o)},u=function(e,n){for(var i=a(e,n),r=[],u=0;u<i.length;u+=1){var f=i[u],s=f.type,m=f.value,c=t[s];c>=0&&(r[c]=parseInt(m,10))}var d=r[3],l=24===d?0:d,h=r[0]+"-"+r[1]+"-"+r[2]+" "+l+":"+r[4]+":"+r[5]+":000",v=+e;return(o.utc(h).valueOf()-(v-=v%1e3))/6e4},f=i.prototype;f.tz=function(t,e){void 0===t&&(t=r);var n,i=this.utcOffset(),a=this.toDate(),u=a.toLocaleString("en-US",{timeZone:t}),f=Math.round((a-new Date(u))/1e3/60),s=15*-Math.round(a.getTimezoneOffset()/15)-f;if(!Number(s))n=this.utcOffset(0,e);else if(n=o(u,{locale:this.$L}).$set("millisecond",this.$ms).utcOffset(s,!0),e){var m=n.utcOffset();n=n.add(i-m,"minute")}return n.$x.$timezone=t,n},f.offsetName=function(t){var e=this.$x.$timezone||o.tz.guess(),n=a(this.valueOf(),e,{timeZoneName:t}).find((function(t){return"timezonename"===t.type.toLowerCase()}));return n&&n.value};var s=f.startOf;f.startOf=function(t,e){if(!this.$x||!this.$x.$timezone)return s.call(this,t,e);var n=o(this.format("YYYY-MM-DD HH:mm:ss:SSS"),{locale:this.$L});return s.call(n,t,e).tz(this.$x.$timezone,!0)},o.tz=function(t,e,n){var i=n&&e,a=n||e||r,f=u(+o(),a);if("string"!=typeof t)return o(t).tz(a);var s=function(t,e,n){var i=t-60*e*1e3,o=u(i,n);if(e===o)return[i,e];var r=u(i-=60*(o-e)*1e3,n);return o===r?[i,o]:[t-60*Math.min(o,r)*1e3,Math.max(o,r)]}(o.utc(t,i).valueOf(),f,a),m=s[0],c=s[1],d=o(m).utcOffset(c);return d.$x.$timezone=a,d},o.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},o.tz.setDefault=function(t){r=t}}}));
80
+
81
+ /***/ }),
82
+
83
+ /***/ 584:
84
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
85
+
86
+ /**
87
+ * cuid.js
88
+ * Collision-resistant UID generator for browsers and node.
89
+ * Sequential for fast db lookups and recency sorting.
90
+ * Safe for element IDs and server-side lookups.
91
+ *
92
+ * Extracted from CLCTR
93
+ *
94
+ * Copyright (c) Eric Elliott 2012
95
+ * MIT License
96
+ */
97
+
98
+ var fingerprint = __webpack_require__(146);
99
+ var pad = __webpack_require__(473);
100
+ var getRandomValue = __webpack_require__(48);
101
+
102
+ var c = 0,
103
+ blockSize = 4,
104
+ base = 36,
105
+ discreteValues = Math.pow(base, blockSize);
106
+
107
+ function randomBlock () {
108
+ return pad((getRandomValue() *
109
+ discreteValues << 0)
110
+ .toString(base), blockSize);
111
+ }
112
+
113
+ function safeCounter () {
114
+ c = c < discreteValues ? c : 0;
115
+ c++; // this is not subliminal
116
+ return c - 1;
117
+ }
118
+
119
+ function cuid () {
120
+ // Starting with a lowercase letter makes
121
+ // it HTML element ID friendly.
122
+ var letter = 'c', // hard-coded allows for sequential access
123
+
124
+ // timestamp
125
+ // warning: this exposes the exact date and time
126
+ // that the uid was created.
127
+ timestamp = (new Date().getTime()).toString(base),
128
+
129
+ // Prevent same-machine collisions.
130
+ counter = pad(safeCounter().toString(base), blockSize),
131
+
132
+ // A few chars to generate distinct ids for different
133
+ // clients (so different computers are far less
134
+ // likely to generate the same id)
135
+ print = fingerprint(),
136
+
137
+ // Grab some more chars from Math.random()
138
+ random = randomBlock() + randomBlock();
139
+
140
+ return letter + timestamp + counter + print + random;
141
+ }
142
+
143
+ cuid.slug = function slug () {
144
+ var date = new Date().getTime().toString(36),
145
+ counter = safeCounter().toString(36).slice(-4),
146
+ print = fingerprint().slice(0, 1) +
147
+ fingerprint().slice(-1),
148
+ random = randomBlock().slice(-2);
149
+
150
+ return date.slice(-2) +
151
+ counter + print + random;
152
+ };
153
+
154
+ cuid.isCuid = function isCuid (stringToCheck) {
155
+ if (typeof stringToCheck !== 'string') return false;
156
+ if (stringToCheck.startsWith('c')) return true;
157
+ return false;
158
+ };
159
+
160
+ cuid.isSlug = function isSlug (stringToCheck) {
161
+ if (typeof stringToCheck !== 'string') return false;
162
+ var stringLength = stringToCheck.length;
163
+ if (stringLength >= 7 && stringLength <= 10) return true;
164
+ return false;
165
+ };
166
+
167
+ cuid.fingerprint = fingerprint;
168
+
169
+ module.exports = cuid;
170
+
171
+
172
+ /***/ }),
173
+
174
+ /***/ 826:
175
+ /***/ (function(module) {
176
+
177
+ !function(t,i){ true?module.exports=i():0}(this,(function(){"use strict";var t="minute",i=/[+-]\d\d(?::?\d\d)?/g,e=/([+-]|\d\d)/g;return function(s,f,n){var u=f.prototype;n.utc=function(t){var i={date:t,utc:!0,args:arguments};return new f(i)},u.utc=function(i){var e=n(this.toDate(),{locale:this.$L,utc:!0});return i?e.add(this.utcOffset(),t):e},u.local=function(){return n(this.toDate(),{locale:this.$L,utc:!1})};var o=u.parse;u.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),o.call(this,t)};var r=u.init;u.init=function(){if(this.$u){var t=this.$d;this.$y=t.getUTCFullYear(),this.$M=t.getUTCMonth(),this.$D=t.getUTCDate(),this.$W=t.getUTCDay(),this.$H=t.getUTCHours(),this.$m=t.getUTCMinutes(),this.$s=t.getUTCSeconds(),this.$ms=t.getUTCMilliseconds()}else r.call(this)};var a=u.utcOffset;u.utcOffset=function(s,f){var n=this.$utils().u;if(n(s))return this.$u?0:n(this.$offset)?a.call(this):this.$offset;if("string"==typeof s&&(s=function(t){void 0===t&&(t="");var s=t.match(i);if(!s)return null;var f=(""+s[0]).match(e)||["-",0,0],n=f[0],u=60*+f[1]+ +f[2];return 0===u?0:"+"===n?u:-u}(s),null===s))return this;var u=Math.abs(s)<=16?60*s:s,o=this;if(f)return o.$offset=u,o.$u=0===s,o;if(0!==s){var r=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(o=this.local().add(u+r,t)).$offset=u,o.$x.$localOffset=r}else o=this.utc();return o};var h=u.format;u.format=function(t){var i=t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,i)},u.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*t},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var l=u.toDate;u.toDate=function(t){return"s"===t&&this.$offset?n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():l.call(this)};var c=u.diff;u.diff=function(t,i,e){if(t&&this.$u===t.$u)return c.call(this,t,i,e);var s=this.local(),f=n(t).local();return c.call(s,f,i,e)}}}));
178
+
179
+ /***/ })
180
+
181
+ /******/ });
182
+ /************************************************************************/
183
+ /******/ // The module cache
184
+ /******/ var __webpack_module_cache__ = {};
185
+ /******/
186
+ /******/ // The require function
187
+ /******/ function __webpack_require__(moduleId) {
188
+ /******/ // Check if module is in cache
189
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
190
+ /******/ if (cachedModule !== undefined) {
191
+ /******/ return cachedModule.exports;
192
+ /******/ }
193
+ /******/ // Create a new module (and put it into the cache)
194
+ /******/ var module = __webpack_module_cache__[moduleId] = {
195
+ /******/ // no module.id needed
196
+ /******/ // no module.loaded needed
197
+ /******/ exports: {}
198
+ /******/ };
199
+ /******/
200
+ /******/ // Execute the module function
201
+ /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
202
+ /******/
203
+ /******/ // Return the exports of the module
204
+ /******/ return module.exports;
205
+ /******/ }
206
+ /******/
207
+ /************************************************************************/
208
+ /******/ /* webpack/runtime/compat get default export */
209
+ /******/ (() => {
210
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
211
+ /******/ __webpack_require__.n = (module) => {
212
+ /******/ var getter = module && module.__esModule ?
213
+ /******/ () => (module['default']) :
214
+ /******/ () => (module);
215
+ /******/ __webpack_require__.d(getter, { a: getter });
216
+ /******/ return getter;
217
+ /******/ };
218
+ /******/ })();
219
+ /******/
220
+ /******/ /* webpack/runtime/define property getters */
221
+ /******/ (() => {
222
+ /******/ // define getter functions for harmony exports
223
+ /******/ __webpack_require__.d = (exports, definition) => {
224
+ /******/ for(var key in definition) {
225
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
226
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
227
+ /******/ }
228
+ /******/ }
229
+ /******/ };
230
+ /******/ })();
231
+ /******/
232
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
233
+ /******/ (() => {
234
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
235
+ /******/ })();
236
+ /******/
237
+ /******/ /* webpack/runtime/make namespace object */
238
+ /******/ (() => {
239
+ /******/ // define __esModule on exports
240
+ /******/ __webpack_require__.r = (exports) => {
241
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
242
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
243
+ /******/ }
244
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
245
+ /******/ };
246
+ /******/ })();
247
+ /******/
248
+ /************************************************************************/
249
+ var __webpack_exports__ = {};
250
+ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
251
+ (() => {
252
+ "use strict";
253
+ // ESM COMPAT FLAG
254
+ __webpack_require__.r(__webpack_exports__);
255
+
256
+ // EXPORTS
257
+ __webpack_require__.d(__webpack_exports__, {
258
+ CotomyApi: () => (/* reexport */ CotomyApi),
259
+ CotomyApiException: () => (/* reexport */ CotomyApiException),
260
+ CotomyApiFailedEvent: () => (/* reexport */ CotomyApiFailedEvent),
261
+ CotomyApiForm: () => (/* reexport */ CotomyApiForm),
262
+ CotomyApiResponse: () => (/* reexport */ CotomyApiResponse),
263
+ CotomyBracketBindNameGenerator: () => (/* reexport */ CotomyBracketBindNameGenerator),
264
+ CotomyConflictException: () => (/* reexport */ CotomyConflictException),
265
+ CotomyDebugFeature: () => (/* reexport */ CotomyDebugFeature),
266
+ CotomyDebugSettings: () => (/* reexport */ CotomyDebugSettings),
267
+ CotomyDotBindNameGenerator: () => (/* reexport */ CotomyDotBindNameGenerator),
268
+ CotomyElement: () => (/* reexport */ CotomyElement),
269
+ CotomyEntityApiForm: () => (/* reexport */ CotomyEntityApiForm),
270
+ CotomyEntityFillApiForm: () => (/* reexport */ CotomyEntityFillApiForm),
271
+ CotomyForbiddenException: () => (/* reexport */ CotomyForbiddenException),
272
+ CotomyForm: () => (/* reexport */ CotomyForm),
273
+ CotomyHttpClientError: () => (/* reexport */ CotomyHttpClientError),
274
+ CotomyHttpServerError: () => (/* reexport */ CotomyHttpServerError),
275
+ CotomyInvalidFormDataBodyException: () => (/* reexport */ CotomyInvalidFormDataBodyException),
276
+ CotomyMetaElement: () => (/* reexport */ CotomyMetaElement),
277
+ CotomyNotFoundException: () => (/* reexport */ CotomyNotFoundException),
278
+ CotomyPageController: () => (/* reexport */ CotomyPageController),
279
+ CotomyQueryForm: () => (/* reexport */ CotomyQueryForm),
280
+ CotomyRequestInvalidException: () => (/* reexport */ CotomyRequestInvalidException),
281
+ CotomyResponseJsonParseException: () => (/* reexport */ CotomyResponseJsonParseException),
282
+ CotomyTooManyRequestsException: () => (/* reexport */ CotomyTooManyRequestsException),
283
+ CotomyUnauthorizedException: () => (/* reexport */ CotomyUnauthorizedException),
284
+ CotomyUrl: () => (/* reexport */ CotomyUrl),
285
+ CotomyViewRenderer: () => (/* reexport */ CotomyViewRenderer),
286
+ CotomyWindow: () => (/* reexport */ CotomyWindow)
287
+ });
288
+
289
+ // EXTERNAL MODULE: ./node_modules/dayjs/dayjs.min.js
290
+ var dayjs_min = __webpack_require__(353);
291
+ var dayjs_min_default = /*#__PURE__*/__webpack_require__.n(dayjs_min);
292
+ ;// ./node_modules/http-status-codes/build/es/status-codes.js
293
+ // Generated file. Do not edit
294
+ var StatusCodes;
295
+ (function (StatusCodes) {
296
+ /**
297
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1
298
+ *
299
+ * This interim response indicates that everything so far is OK and that the client should continue with the request or ignore it if it is already finished.
300
+ */
301
+ StatusCodes[StatusCodes["CONTINUE"] = 100] = "CONTINUE";
302
+ /**
303
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2
304
+ *
305
+ * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too.
306
+ */
307
+ StatusCodes[StatusCodes["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
308
+ /**
309
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.1
310
+ *
311
+ * This code indicates that the server has received and is processing the request, but no response is available yet.
312
+ */
313
+ StatusCodes[StatusCodes["PROCESSING"] = 102] = "PROCESSING";
314
+ /**
315
+ * Official Documentation @ https://www.rfc-editor.org/rfc/rfc8297#page-3
316
+ *
317
+ * This code indicates to the client that the server is likely to send a final response with the header fields included in the informational response.
318
+ */
319
+ StatusCodes[StatusCodes["EARLY_HINTS"] = 103] = "EARLY_HINTS";
320
+ /**
321
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1
322
+ *
323
+ * The request has succeeded. The meaning of a success varies depending on the HTTP method:
324
+ * GET: The resource has been fetched and is transmitted in the message body.
325
+ * HEAD: The entity headers are in the message body.
326
+ * POST: The resource describing the result of the action is transmitted in the message body.
327
+ * TRACE: The message body contains the request message as received by the server
328
+ */
329
+ StatusCodes[StatusCodes["OK"] = 200] = "OK";
330
+ /**
331
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2
332
+ *
333
+ * The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request.
334
+ */
335
+ StatusCodes[StatusCodes["CREATED"] = 201] = "CREATED";
336
+ /**
337
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.3
338
+ *
339
+ * The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.
340
+ */
341
+ StatusCodes[StatusCodes["ACCEPTED"] = 202] = "ACCEPTED";
342
+ /**
343
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4
344
+ *
345
+ * This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response.
346
+ */
347
+ StatusCodes[StatusCodes["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
348
+ /**
349
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5
350
+ *
351
+ * There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.
352
+ */
353
+ StatusCodes[StatusCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
354
+ /**
355
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.6
356
+ *
357
+ * This response code is sent after accomplishing request to tell user agent reset document view which sent this request.
358
+ */
359
+ StatusCodes[StatusCodes["RESET_CONTENT"] = 205] = "RESET_CONTENT";
360
+ /**
361
+ * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.1
362
+ *
363
+ * This response code is used because of range header sent by the client to separate download into multiple streams.
364
+ */
365
+ StatusCodes[StatusCodes["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
366
+ /**
367
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.2
368
+ *
369
+ * A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate.
370
+ */
371
+ StatusCodes[StatusCodes["MULTI_STATUS"] = 207] = "MULTI_STATUS";
372
+ /**
373
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.1
374
+ *
375
+ * The request has more than one possible responses. User-agent or user should choose one of them. There is no standardized way to choose one of the responses.
376
+ */
377
+ StatusCodes[StatusCodes["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
378
+ /**
379
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.2
380
+ *
381
+ * This response code means that URI of requested resource has been changed. Probably, new URI would be given in the response.
382
+ */
383
+ StatusCodes[StatusCodes["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
384
+ /**
385
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.3
386
+ *
387
+ * This response code means that URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.
388
+ */
389
+ StatusCodes[StatusCodes["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
390
+ /**
391
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.4
392
+ *
393
+ * Server sent this response to directing client to get requested resource to another URI with an GET request.
394
+ */
395
+ StatusCodes[StatusCodes["SEE_OTHER"] = 303] = "SEE_OTHER";
396
+ /**
397
+ * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1
398
+ *
399
+ * This is used for caching purposes. It is telling to client that response has not been modified. So, client can continue to use same cached version of response.
400
+ */
401
+ StatusCodes[StatusCodes["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
402
+ /**
403
+ * @deprecated
404
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.6
405
+ *
406
+ * Was defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy.
407
+ */
408
+ StatusCodes[StatusCodes["USE_PROXY"] = 305] = "USE_PROXY";
409
+ /**
410
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.7
411
+ *
412
+ * Server sent this response to directing client to get requested resource to another URI with same method that used prior request. This has the same semantic than the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.
413
+ */
414
+ StatusCodes[StatusCodes["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
415
+ /**
416
+ * Official Documentation @ https://tools.ietf.org/html/rfc7538#section-3
417
+ *
418
+ * This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.
419
+ */
420
+ StatusCodes[StatusCodes["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
421
+ /**
422
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.1
423
+ *
424
+ * This response means that server could not understand the request due to invalid syntax.
425
+ */
426
+ StatusCodes[StatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
427
+ /**
428
+ * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1
429
+ *
430
+ * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
431
+ */
432
+ StatusCodes[StatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
433
+ /**
434
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2
435
+ *
436
+ * This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems however this is not used currently.
437
+ */
438
+ StatusCodes[StatusCodes["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
439
+ /**
440
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3
441
+ *
442
+ * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server.
443
+ */
444
+ StatusCodes[StatusCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
445
+ /**
446
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.4
447
+ *
448
+ * The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web.
449
+ */
450
+ StatusCodes[StatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
451
+ /**
452
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5
453
+ *
454
+ * The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code.
455
+ */
456
+ StatusCodes[StatusCodes["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
457
+ /**
458
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.6
459
+ *
460
+ * This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent.
461
+ */
462
+ StatusCodes[StatusCodes["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
463
+ /**
464
+ * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.2
465
+ *
466
+ * This is similar to 401 but authentication is needed to be done by a proxy.
467
+ */
468
+ StatusCodes[StatusCodes["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
469
+ /**
470
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7
471
+ *
472
+ * This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message.
473
+ */
474
+ StatusCodes[StatusCodes["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
475
+ /**
476
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8
477
+ *
478
+ * This response is sent when a request conflicts with the current state of the server.
479
+ */
480
+ StatusCodes[StatusCodes["CONFLICT"] = 409] = "CONFLICT";
481
+ /**
482
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9
483
+ *
484
+ * This response would be sent when the requested content has been permenantly deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code.
485
+ */
486
+ StatusCodes[StatusCodes["GONE"] = 410] = "GONE";
487
+ /**
488
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.10
489
+ *
490
+ * The server rejected the request because the Content-Length header field is not defined and the server requires it.
491
+ */
492
+ StatusCodes[StatusCodes["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
493
+ /**
494
+ * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.2
495
+ *
496
+ * The client has indicated preconditions in its headers which the server does not meet.
497
+ */
498
+ StatusCodes[StatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
499
+ /**
500
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11
501
+ *
502
+ * Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field.
503
+ */
504
+ StatusCodes[StatusCodes["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
505
+ /**
506
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.12
507
+ *
508
+ * The URI requested by the client is longer than the server is willing to interpret.
509
+ */
510
+ StatusCodes[StatusCodes["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
511
+ /**
512
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13
513
+ *
514
+ * The media format of the requested data is not supported by the server, so the server is rejecting the request.
515
+ */
516
+ StatusCodes[StatusCodes["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
517
+ /**
518
+ * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.4
519
+ *
520
+ * The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data.
521
+ */
522
+ StatusCodes[StatusCodes["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
523
+ /**
524
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.14
525
+ *
526
+ * This response code means the expectation indicated by the Expect request header field can't be met by the server.
527
+ */
528
+ StatusCodes[StatusCodes["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
529
+ /**
530
+ * Official Documentation @ https://tools.ietf.org/html/rfc2324#section-2.3.2
531
+ *
532
+ * Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout.
533
+ */
534
+ StatusCodes[StatusCodes["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
535
+ /**
536
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6
537
+ *
538
+ * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request which received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action.
539
+ */
540
+ StatusCodes[StatusCodes["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
541
+ /**
542
+ * @deprecated
543
+ * Official Documentation @ https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt
544
+ *
545
+ * A deprecated response used by the Spring Framework when a method has failed.
546
+ */
547
+ StatusCodes[StatusCodes["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
548
+ /**
549
+ * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7540#section-9.1.2
550
+ *
551
+ * Defined in the specification of HTTP/2 to indicate that a server is not able to produce a response for the combination of scheme and authority that are included in the request URI.
552
+ */
553
+ StatusCodes[StatusCodes["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
554
+ /**
555
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3
556
+ *
557
+ * The request was well-formed but was unable to be followed due to semantic errors.
558
+ */
559
+ StatusCodes[StatusCodes["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
560
+ /**
561
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.4
562
+ *
563
+ * The resource that is being accessed is locked.
564
+ */
565
+ StatusCodes[StatusCodes["LOCKED"] = 423] = "LOCKED";
566
+ /**
567
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.5
568
+ *
569
+ * The request failed due to failure of a previous request.
570
+ */
571
+ StatusCodes[StatusCodes["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
572
+ /**
573
+ * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.15
574
+ *
575
+ * The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol.
576
+ */
577
+ StatusCodes[StatusCodes["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
578
+ /**
579
+ * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-3
580
+ *
581
+ * The origin server requires the request to be conditional. Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.
582
+ */
583
+ StatusCodes[StatusCodes["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
584
+ /**
585
+ * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4
586
+ *
587
+ * The user has sent too many requests in a given amount of time ("rate limiting").
588
+ */
589
+ StatusCodes[StatusCodes["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
590
+ /**
591
+ * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5
592
+ *
593
+ * The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields.
594
+ */
595
+ StatusCodes[StatusCodes["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
596
+ /**
597
+ * Official Documentation @ https://tools.ietf.org/html/rfc7725
598
+ *
599
+ * The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government.
600
+ */
601
+ StatusCodes[StatusCodes["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
602
+ /**
603
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.1
604
+ *
605
+ * The server encountered an unexpected condition that prevented it from fulfilling the request.
606
+ */
607
+ StatusCodes[StatusCodes["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
608
+ /**
609
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2
610
+ *
611
+ * The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.
612
+ */
613
+ StatusCodes[StatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
614
+ /**
615
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.3
616
+ *
617
+ * This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.
618
+ */
619
+ StatusCodes[StatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
620
+ /**
621
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.4
622
+ *
623
+ * The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached.
624
+ */
625
+ StatusCodes[StatusCodes["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
626
+ /**
627
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.5
628
+ *
629
+ * This error response is given when the server is acting as a gateway and cannot get a response in time.
630
+ */
631
+ StatusCodes[StatusCodes["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
632
+ /**
633
+ * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.6
634
+ *
635
+ * The HTTP version used in the request is not supported by the server.
636
+ */
637
+ StatusCodes[StatusCodes["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
638
+ /**
639
+ * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6
640
+ *
641
+ * The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
642
+ */
643
+ StatusCodes[StatusCodes["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
644
+ /**
645
+ * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-6
646
+ *
647
+ * The 511 status code indicates that the client needs to authenticate to gain network access.
648
+ */
649
+ StatusCodes[StatusCodes["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
650
+ })(StatusCodes || (StatusCodes = {}));
651
+
652
+ ;// ./src/debug.ts
653
+ var CotomyDebugFeature;
654
+ (function (CotomyDebugFeature) {
655
+ CotomyDebugFeature["Api"] = "api";
656
+ CotomyDebugFeature["Fill"] = "fill";
657
+ CotomyDebugFeature["Bind"] = "bind";
658
+ CotomyDebugFeature["FormData"] = "formdata";
659
+ CotomyDebugFeature["Html"] = "html";
660
+ CotomyDebugFeature["Page"] = "page";
661
+ CotomyDebugFeature["FormLoad"] = "formload";
662
+ })(CotomyDebugFeature || (CotomyDebugFeature = {}));
663
+ class CotomyDebugSettings {
664
+ static isEnabled(key) {
665
+ const global = localStorage.getItem(this.PREFIX);
666
+ if (key) {
667
+ const specific = localStorage.getItem(`${this.PREFIX}:${String(key)}`);
668
+ return specific === "true" || global === "true";
669
+ }
670
+ return global === "true";
671
+ }
672
+ static enable(key) {
673
+ localStorage.setItem(`${this.PREFIX}:${String(key)}`, "true");
674
+ }
675
+ static disable(key) {
676
+ localStorage.setItem(`${this.PREFIX}:${String(key)}`, "false");
677
+ }
678
+ static enableAll() {
679
+ localStorage.setItem(this.PREFIX, "true");
680
+ }
681
+ static disableAll() {
682
+ localStorage.setItem(this.PREFIX, "false");
683
+ }
684
+ static clear(key) {
685
+ if (key) {
686
+ localStorage.removeItem(`${this.PREFIX}:${String(key)}`);
687
+ }
688
+ else {
689
+ localStorage.removeItem(this.PREFIX);
690
+ }
691
+ }
692
+ }
693
+ CotomyDebugSettings.PREFIX = "cotomy:debug";
694
+
695
+ // EXTERNAL MODULE: ./node_modules/cuid/index.js
696
+ var cuid = __webpack_require__(584);
697
+ var cuid_default = /*#__PURE__*/__webpack_require__.n(cuid);
698
+ ;// ./src/view.ts
699
+
700
+
701
+ class HandlerEntry {
702
+ constructor(handle, wrapper, options) {
703
+ this.handle = handle;
704
+ this.wrapper = wrapper;
705
+ this.options = options;
706
+ }
707
+ get current() {
708
+ return this.wrapper ?? this.handle;
709
+ }
710
+ equals(entryOrHandle, optionsOrMode, wrapper, mode) {
711
+ let targetHandle;
712
+ let targetWrapper;
713
+ let targetOptions;
714
+ let compareMode = "strict";
715
+ if (entryOrHandle instanceof HandlerEntry) {
716
+ targetHandle = entryOrHandle.handle;
717
+ targetWrapper = entryOrHandle.wrapper;
718
+ targetOptions = entryOrHandle.options;
719
+ compareMode = optionsOrMode ?? "strict";
720
+ }
721
+ else {
722
+ targetHandle = entryOrHandle;
723
+ if (typeof optionsOrMode === "string") {
724
+ compareMode = optionsOrMode;
725
+ targetWrapper = wrapper;
726
+ targetOptions = undefined;
727
+ }
728
+ else {
729
+ targetOptions = optionsOrMode;
730
+ targetWrapper = wrapper;
731
+ compareMode = mode ?? "strict";
732
+ }
733
+ }
734
+ if (this.handle !== targetHandle) {
735
+ return false;
736
+ }
737
+ if (compareMode === "strict" && this.wrapper !== targetWrapper) {
738
+ return false;
739
+ }
740
+ return HandlerEntry.optionsEquals(this.options, targetOptions);
741
+ }
742
+ static optionsEquals(left, right) {
743
+ const getBoolean = (options, key) => options?.[key] ?? false;
744
+ const getSignal = (options) => options?.signal;
745
+ const leftSignal = getSignal(left);
746
+ const rightSignal = getSignal(right);
747
+ const signalsEqual = leftSignal === rightSignal;
748
+ return getBoolean(left, "capture") === getBoolean(right, "capture")
749
+ && getBoolean(left, "once") === getBoolean(right, "once")
750
+ && getBoolean(left, "passive") === getBoolean(right, "passive")
751
+ && signalsEqual;
752
+ }
753
+ }
754
+ class HandlerRegistory {
755
+ constructor(target) {
756
+ this.target = target;
757
+ this._registory = new Map();
758
+ }
759
+ ensure(event) {
760
+ return this._registory.get(event) ?? this._registory.set(event, []).get(event);
761
+ }
762
+ find(event, entry) {
763
+ return this._registory.get(event)?.find(e => e.equals(entry)) ?? undefined;
764
+ }
765
+ add(event, entry) {
766
+ if (entry.options?.once) {
767
+ this.remove(event, entry);
768
+ }
769
+ if (!this.find(event, entry)) {
770
+ this.ensure(event).push(entry);
771
+ this.target.element.addEventListener(event, entry.current, entry.options);
772
+ }
773
+ }
774
+ remove(event, entry) {
775
+ if (!entry) {
776
+ const list = this._registory.get(event);
777
+ if (!list)
778
+ return;
779
+ list.forEach(e => this.target.element.removeEventListener(event, e.current, e.options?.capture ?? false));
780
+ this._registory.delete(event);
781
+ return;
782
+ }
783
+ const list = this._registory.get(event);
784
+ if (list) {
785
+ const remaining = [];
786
+ for (const e of list) {
787
+ if (e.equals(entry, "remove")) {
788
+ this.target.element.removeEventListener(event, e.current, e.options?.capture ?? false);
789
+ }
790
+ else {
791
+ remaining.push(e);
792
+ }
793
+ }
794
+ if (remaining.length === 0) {
795
+ this._registory.delete(event);
796
+ }
797
+ else {
798
+ this._registory.set(event, remaining);
799
+ }
800
+ }
801
+ }
802
+ get empty() {
803
+ return this._registory.size === 0;
804
+ }
805
+ }
806
+ class EventRegistry {
807
+ static get instance() {
808
+ return this._instance ?? (this._instance = new EventRegistry());
809
+ }
810
+ constructor() {
811
+ this._registry = new Map();
812
+ }
813
+ map(target) {
814
+ const scopeId = target.scopeId;
815
+ let registry = this._registry.get(scopeId);
816
+ if (!registry) {
817
+ registry = new HandlerRegistory(target);
818
+ this._registry.set(scopeId, registry);
819
+ }
820
+ return registry;
821
+ }
822
+ on(event, target, entry) {
823
+ const registry = this.map(target);
824
+ registry.add(event, entry);
825
+ }
826
+ off(event, target, entry) {
827
+ const registry = this._registry.get(target.scopeId);
828
+ if (!registry)
829
+ return;
830
+ if (entry) {
831
+ registry.remove(event, entry);
832
+ }
833
+ else {
834
+ registry.remove(event);
835
+ }
836
+ if (registry.empty) {
837
+ this._registry.delete(target.scopeId);
838
+ }
839
+ }
840
+ clear(target) {
841
+ this._registry.delete(target.scopeId);
842
+ }
843
+ }
844
+ class CotomyElement {
845
+ static encodeHtml(text) {
846
+ const div = document.createElement("div");
847
+ div.textContent = text ?? "";
848
+ return div.innerHTML;
849
+ }
850
+ static createHTMLElement(html) {
851
+ const wrapperMap = {
852
+ "tr": { prefix: "<table><tbody>", suffix: "</tbody></table>" },
853
+ "td": { prefix: "<table><tbody><tr>", suffix: "</tr></tbody></table>" },
854
+ "th": { prefix: "<table><tbody><tr>", suffix: "</tr></tbody></table>" },
855
+ "thead": { prefix: "<table>", suffix: "</table>" },
856
+ "tbody": { prefix: "<table>", suffix: "</table>" },
857
+ "tfoot": { prefix: "<table>", suffix: "</table>" },
858
+ "caption": { prefix: "<table>", suffix: "</table>" },
859
+ "colgroup": { prefix: "<table>", suffix: "</table>" },
860
+ "col": { prefix: "<table><colgroup>", suffix: "</colgroup></table>" },
861
+ "option": { prefix: "<select>", suffix: "</select>" },
862
+ "optgroup": { prefix: "<select>", suffix: "</select>" },
863
+ "legend": { prefix: "<fieldset>", suffix: "</fieldset>" },
864
+ "li": { prefix: "<ul>", suffix: "</ul>" }
865
+ };
866
+ const match = html.match(/<\s*([a-z0-9]+)/i);
867
+ if (!match) {
868
+ throw new Error(`Invalid HTML: cannot extract tag from "${html}"`);
869
+ }
870
+ const tag = match[1].toLowerCase();
871
+ const wrap = wrapperMap[tag];
872
+ const wrappedHtml = wrap ? `${wrap.prefix}${html}${wrap.suffix}` : html;
873
+ const parser = new DOMParser();
874
+ const doc = parser.parseFromString(wrappedHtml, "text/html");
875
+ const errors = doc.querySelector("parsererror");
876
+ if (errors) {
877
+ throw new Error(`HTML parsing failed for tag <${tag}>: "${html}"`);
878
+ }
879
+ if (doc.body.children.length !== 1) {
880
+ throw new Error(`CotomyElement requires a single root element, but got ${doc.body.children.length}.`);
881
+ }
882
+ const element = doc.body.querySelector(tag);
883
+ if (!element) {
884
+ throw new Error(`Parsed but <${tag}> element not found: "${html}"`);
885
+ }
886
+ return element;
887
+ }
888
+ static first(selector, type) {
889
+ const element = document.querySelector(selector);
890
+ if (!element)
891
+ return undefined;
892
+ const ctor = (type ?? CotomyElement);
893
+ return new ctor(element);
894
+ }
895
+ static find(selector, type) {
896
+ const elements = document.querySelectorAll(selector);
897
+ const ctor = (type ?? CotomyElement);
898
+ return Array.from(elements).map(e => new ctor(e));
899
+ }
900
+ static contains(selector) {
901
+ return document.querySelector(selector) !== null;
902
+ }
903
+ static byId(id, type) {
904
+ return this.first(`#${id}`, type);
905
+ }
906
+ static containsById(id) {
907
+ return document.getElementById(id) !== null;
908
+ }
909
+ static empty(type) {
910
+ const ctor = (type ?? CotomyElement);
911
+ return new ctor(document.createElement("div")).attribute("data-cotomy-empty", "").style("display", "none");
912
+ }
913
+ constructor(element) {
914
+ this._parentElement = null;
915
+ this._scopeId = null;
916
+ if (element instanceof HTMLElement) {
917
+ this._element = element;
918
+ }
919
+ else if (typeof element === "string") {
920
+ this._element = CotomyElement.createHTMLElement(element);
921
+ }
922
+ else {
923
+ this._element = CotomyElement.createHTMLElement("html" in element ? element.html : `<${element.tagname}></${element.tagname}>`);
924
+ if ("tagname" in element && element.text) {
925
+ this._element.textContent = element.text;
926
+ }
927
+ if (element.css) {
928
+ this.useScopedCss(element.css);
929
+ }
930
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Html)) {
931
+ if ("html" in element) {
932
+ console.debug(`CotomyElement {html: "${element.html}" } is created`);
933
+ }
934
+ if ("tagname" in element) {
935
+ console.debug(`CotomyElement {tagname: "${element.tagname}", text: "${element.text ?? ""}"} is created`);
936
+ }
937
+ if (element.css) {
938
+ console.debug(`CotomyElement {css: "${element.css}" } is applied`);
939
+ }
940
+ }
941
+ }
942
+ this.removed(() => {
943
+ this._element = CotomyElement.createHTMLElement(`<div data-cotomy-invalidated style="display: none;"></div>`);
944
+ EventRegistry.instance.clear(this);
945
+ });
946
+ }
947
+ get scopeId() {
948
+ if (!this._scopeId) {
949
+ this._scopeId = `__cotomy_scope__${cuid_default()()}`;
950
+ this.attribute(this._scopeId, "");
951
+ }
952
+ return this._scopeId;
953
+ }
954
+ get scopedSelector() {
955
+ return `[${this.scopeId}]`;
956
+ }
957
+ get stylable() {
958
+ return !["script", "style", "link", "meta"].includes(this.tagname);
959
+ }
960
+ get scopedCssElementId() {
961
+ return `css-${this.scopeId}`;
962
+ }
963
+ useScopedCss(css) {
964
+ if (css && this.stylable) {
965
+ const cssid = this.scopedCssElementId;
966
+ CotomyElement.find(`#${cssid}`).forEach(e => e.remove());
967
+ const element = document.createElement("style");
968
+ const writeCss = css.replace(/\[scope\]/g, `[${this.scopeId}]`);
969
+ const node = document.createTextNode(writeCss);
970
+ element.appendChild(node);
971
+ element.id = cssid;
972
+ const head = CotomyElement.first("head")
973
+ || new CotomyElement({ html: `<head></head>` }).prependTo(new CotomyElement(document.documentElement));
974
+ head.append(new CotomyElement(element));
975
+ this.removed(() => {
976
+ CotomyElement.find(`#${cssid}`).forEach(e => e.remove());
977
+ });
978
+ }
979
+ return this;
980
+ }
981
+ listenLayoutEvents() {
982
+ this.attribute(CotomyElement.LISTEN_LAYOUT_EVENTS_ATTRIBUTE, "");
983
+ return this;
984
+ }
985
+ get id() {
986
+ return this.attribute("id");
987
+ }
988
+ generateId(prefix = "__cotomy_elem__") {
989
+ if (!this.id) {
990
+ this.attribute("id", `${prefix}${cuid_default()()}`);
991
+ }
992
+ return this;
993
+ }
994
+ get element() {
995
+ return this._element;
996
+ }
997
+ get tagname() {
998
+ return this.element.tagName.toLowerCase();
999
+ }
1000
+ is(selector) {
1001
+ const selectors = selector.split(/\s+(?![^\[]*\])|(?<=\>)\s+/);
1002
+ let element = this.element;
1003
+ for (let i = selectors.length - 1; i >= 0; i--) {
1004
+ let subSelector = selectors[i].trim();
1005
+ let directChild = false;
1006
+ if (subSelector.startsWith(">")) {
1007
+ directChild = true;
1008
+ subSelector = subSelector.slice(1).trim();
1009
+ }
1010
+ if (!element || !element.matches(subSelector)) {
1011
+ return false;
1012
+ }
1013
+ if (directChild) {
1014
+ element = element.parentElement;
1015
+ }
1016
+ else {
1017
+ if (i > 0) {
1018
+ while (element && !element.matches(selectors[i - 1].trim())) {
1019
+ element = element.parentElement;
1020
+ }
1021
+ }
1022
+ }
1023
+ }
1024
+ return true;
1025
+ }
1026
+ get empty() {
1027
+ const nonEmptyTags = new Set([
1028
+ "input", "select", "textarea", "img", "video", "audio", "br", "hr",
1029
+ "iframe", "embed", "canvas", "object", "svg", "source", "track", "col",
1030
+ "link", "meta", "base"
1031
+ ]);
1032
+ return nonEmptyTags.has(this.tagname)
1033
+ || this._element.hasAttribute("data-cotomy-empty")
1034
+ || this._element.innerHTML.trim() === "";
1035
+ }
1036
+ get attached() {
1037
+ return document.contains(this.element);
1038
+ }
1039
+ get readonly() {
1040
+ if ("readOnly" in this.element) {
1041
+ return this.element.readOnly;
1042
+ }
1043
+ else {
1044
+ return this.element.hasAttribute("readonly");
1045
+ }
1046
+ }
1047
+ set readonly(readonly) {
1048
+ if ("readOnly" in this.element) {
1049
+ this.element.readOnly = readonly;
1050
+ }
1051
+ else {
1052
+ if (readonly) {
1053
+ this.attribute("readonly", "readonly");
1054
+ }
1055
+ else {
1056
+ this.attribute("readonly", null);
1057
+ }
1058
+ }
1059
+ }
1060
+ get value() {
1061
+ if ("value" in this.element) {
1062
+ return this.element.value;
1063
+ }
1064
+ else {
1065
+ return this.attribute("data-cotomy-value") ?? "";
1066
+ }
1067
+ }
1068
+ set value(val) {
1069
+ if ("value" in this.element) {
1070
+ this.element.value = val;
1071
+ }
1072
+ else {
1073
+ this.attribute("data-cotomy-value", val);
1074
+ }
1075
+ }
1076
+ get text() {
1077
+ return this.element.textContent ?? "";
1078
+ }
1079
+ set text(text) {
1080
+ this.element.textContent = text ?? "";
1081
+ }
1082
+ get html() {
1083
+ return this.element.innerHTML;
1084
+ }
1085
+ set html(html) {
1086
+ this.element.innerHTML = html;
1087
+ }
1088
+ setFocus() {
1089
+ this.element.focus();
1090
+ }
1091
+ get visible() {
1092
+ if (!this.attached) {
1093
+ return false;
1094
+ }
1095
+ if (!this.element.offsetParent && !document.contains(this.element)) {
1096
+ return false;
1097
+ }
1098
+ const rect = this.element.getBoundingClientRect();
1099
+ if (rect.width > 0 && rect.height > 0) {
1100
+ const style = this.getComputedStyle();
1101
+ return style.display !== "none" && style.visibility !== "hidden" && style.visibility !== "collapse";
1102
+ }
1103
+ return false;
1104
+ }
1105
+ get enabled() {
1106
+ return !(this.element.hasAttribute("disabled") && this.element.getAttribute("disabled") !== null);
1107
+ }
1108
+ set enabled(value) {
1109
+ if (value) {
1110
+ this.element.removeAttribute("disabled");
1111
+ }
1112
+ else {
1113
+ this.element.setAttribute("disabled", "disabled");
1114
+ }
1115
+ }
1116
+ get invalidated() {
1117
+ return this.element.hasAttribute("data-cotomy-invalidated");
1118
+ }
1119
+ remove() {
1120
+ if (!this.invalidated) {
1121
+ this._element.remove();
1122
+ }
1123
+ }
1124
+ clear() {
1125
+ this.find("*").forEach(e => e.remove());
1126
+ this.text = "";
1127
+ return this;
1128
+ }
1129
+ get width() {
1130
+ return this.element.offsetWidth;
1131
+ }
1132
+ set width(width) {
1133
+ let w = width.toString() + "px";
1134
+ this.style("width", w);
1135
+ }
1136
+ get height() {
1137
+ return this.element.offsetHeight;
1138
+ }
1139
+ set height(height) {
1140
+ let h = height.toString() + "px";
1141
+ this.style("height", h);
1142
+ }
1143
+ get innerWidth() {
1144
+ return this.element.clientWidth;
1145
+ }
1146
+ get innerHeight() {
1147
+ return this.element.clientHeight;
1148
+ }
1149
+ get outerWidth() {
1150
+ const style = this.getComputedStyle();
1151
+ const margin = parseFloat(style.marginLeft) + parseFloat(style.marginRight);
1152
+ return this.element.offsetWidth + margin;
1153
+ }
1154
+ get outerHeight() {
1155
+ const style = this.getComputedStyle();
1156
+ const margin = parseFloat(style.marginTop) + parseFloat(style.marginBottom);
1157
+ return this.element.offsetHeight + margin;
1158
+ }
1159
+ get scrollHeight() {
1160
+ return this.element.scrollHeight;
1161
+ }
1162
+ get scrollWidth() {
1163
+ return this.element.scrollWidth;
1164
+ }
1165
+ get scrollTop() {
1166
+ return this.element.scrollTop;
1167
+ }
1168
+ get position() {
1169
+ const rect = this.element.getBoundingClientRect();
1170
+ return { top: rect.top, left: rect.left };
1171
+ }
1172
+ get absolutePosition() {
1173
+ const rect = this.element.getBoundingClientRect();
1174
+ return { top: rect.top + window.scrollY, left: rect.left + window.scrollX };
1175
+ }
1176
+ get screenPosition() {
1177
+ const rect = this.element.getBoundingClientRect();
1178
+ return { top: rect.top, left: rect.left };
1179
+ }
1180
+ get rect() {
1181
+ const rect = this.element.getBoundingClientRect();
1182
+ return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
1183
+ }
1184
+ get innerRect() {
1185
+ const rect = this.element.getBoundingClientRect();
1186
+ const style = this.getComputedStyle();
1187
+ const padding = {
1188
+ top: parseFloat(style.paddingTop),
1189
+ right: parseFloat(style.paddingRight),
1190
+ bottom: parseFloat(style.paddingBottom),
1191
+ left: parseFloat(style.paddingLeft)
1192
+ };
1193
+ return {
1194
+ top: rect.top + padding.top,
1195
+ left: rect.left + padding.left,
1196
+ width: rect.width - padding.left - padding.right,
1197
+ height: rect.height - padding.top - padding.bottom
1198
+ };
1199
+ }
1200
+ get outerRect() {
1201
+ const rect = this.element.getBoundingClientRect();
1202
+ const style = this.getComputedStyle();
1203
+ const margin = {
1204
+ top: parseFloat(style.marginTop),
1205
+ right: parseFloat(style.marginRight),
1206
+ bottom: parseFloat(style.marginBottom),
1207
+ left: parseFloat(style.marginLeft)
1208
+ };
1209
+ return {
1210
+ top: rect.top - margin.top,
1211
+ left: rect.left - margin.left,
1212
+ width: rect.width + margin.left + margin.right,
1213
+ height: rect.height + margin.top + margin.bottom
1214
+ };
1215
+ }
1216
+ get padding() {
1217
+ const style = this.getComputedStyle();
1218
+ return {
1219
+ top: parseFloat(style.paddingTop),
1220
+ right: parseFloat(style.paddingRight),
1221
+ bottom: parseFloat(style.paddingBottom),
1222
+ left: parseFloat(style.paddingLeft)
1223
+ };
1224
+ }
1225
+ get margin() {
1226
+ const style = this.getComputedStyle();
1227
+ return {
1228
+ top: parseFloat(style.marginTop),
1229
+ right: parseFloat(style.marginRight),
1230
+ bottom: parseFloat(style.marginBottom),
1231
+ left: parseFloat(style.marginLeft)
1232
+ };
1233
+ }
1234
+ get inViewport() {
1235
+ const rect = this.element.getBoundingClientRect();
1236
+ return rect.top < window.innerHeight && rect.bottom > 0;
1237
+ }
1238
+ get isAboveViewport() {
1239
+ return this.element.getBoundingClientRect().bottom < 0;
1240
+ }
1241
+ get isBelowViewport() {
1242
+ return this.element.getBoundingClientRect().top > window.innerHeight;
1243
+ }
1244
+ get isLeftViewport() {
1245
+ return this.element.getBoundingClientRect().right < 0;
1246
+ }
1247
+ get isRightViewport() {
1248
+ return this.element.getBoundingClientRect().left > window.innerWidth;
1249
+ }
1250
+ hasAttribute(name) {
1251
+ return this.element.hasAttribute(name);
1252
+ }
1253
+ attribute(name, value) {
1254
+ if (arguments.length === 1) {
1255
+ return this.element.hasAttribute(name) ? this.element.getAttribute(name) : undefined;
1256
+ }
1257
+ else if (value === null) {
1258
+ this.element.removeAttribute(name);
1259
+ return this;
1260
+ }
1261
+ else {
1262
+ this.element.setAttribute(name, value?.toString() ?? "");
1263
+ return this;
1264
+ }
1265
+ }
1266
+ hasClass(name) {
1267
+ return this.element.classList.contains(name);
1268
+ }
1269
+ addClass(name) {
1270
+ this.element.classList.add(name);
1271
+ return this;
1272
+ }
1273
+ removeClass(name) {
1274
+ this.element.classList.remove(name);
1275
+ return this;
1276
+ }
1277
+ toggleClass(name, force) {
1278
+ this.element.classList.toggle(name, force);
1279
+ return this;
1280
+ }
1281
+ style(name, value) {
1282
+ if (arguments.length === 1) {
1283
+ return this.element.style.getPropertyValue(name);
1284
+ }
1285
+ else if (value == null) {
1286
+ this.element.style.removeProperty(name);
1287
+ return this;
1288
+ }
1289
+ else {
1290
+ this.element.style.setProperty(name, value);
1291
+ return this;
1292
+ }
1293
+ }
1294
+ getComputedStyle() {
1295
+ return window.getComputedStyle(this.element);
1296
+ }
1297
+ computedStyle(name) {
1298
+ return window.getComputedStyle(this.element).getPropertyValue(name);
1299
+ }
1300
+ get parent() {
1301
+ if (this._parentElement == null && this.element.parentElement !== null) {
1302
+ this._parentElement = new CotomyElement(this.element.parentElement);
1303
+ }
1304
+ return this._parentElement ?? CotomyElement.empty();
1305
+ }
1306
+ get parents() {
1307
+ let parents = [];
1308
+ let currentElement = this.element.parentElement;
1309
+ while (currentElement !== null) {
1310
+ parents.push(new CotomyElement(currentElement));
1311
+ currentElement = currentElement.parentElement;
1312
+ }
1313
+ return parents;
1314
+ }
1315
+ hasChildren(selector = "*") {
1316
+ return this.element.querySelector(selector) !== null;
1317
+ }
1318
+ children(selector = "*", type) {
1319
+ const children = Array.from(this.element.querySelectorAll(selector));
1320
+ const directChildren = children.filter(child => child.parentElement === this.element);
1321
+ const ctor = (type ?? CotomyElement);
1322
+ return directChildren.filter((e) => e instanceof HTMLElement).map(e => new ctor(e));
1323
+ }
1324
+ firstChild(selector = "*", type) {
1325
+ const elements = this.children(selector, type);
1326
+ return elements.shift() ?? undefined;
1327
+ }
1328
+ lastChild(selector = "*", type) {
1329
+ const elements = this.children(selector, type);
1330
+ return elements.pop() ?? undefined;
1331
+ }
1332
+ closest(selector, type) {
1333
+ const closestElement = this.element.closest(selector);
1334
+ if (closestElement !== null && closestElement instanceof HTMLElement) {
1335
+ const ctor = (type ?? CotomyElement);
1336
+ return new ctor(closestElement);
1337
+ }
1338
+ else {
1339
+ return undefined;
1340
+ }
1341
+ }
1342
+ find(selector, type) {
1343
+ const elements = Array.from(this.element.querySelectorAll(selector));
1344
+ return elements.map(e => new (type ?? CotomyElement)(e));
1345
+ }
1346
+ first(selector = "*", type) {
1347
+ const elements = this.find(selector, type);
1348
+ return elements.shift() ?? undefined;
1349
+ }
1350
+ contains(selector) {
1351
+ return this.find(selector).length > 0;
1352
+ }
1353
+ prepend(prepend) {
1354
+ this._element.prepend(prepend.element);
1355
+ return this;
1356
+ }
1357
+ append(target) {
1358
+ this.element.append(target.element);
1359
+ return this;
1360
+ }
1361
+ appendAll(targets) {
1362
+ targets.forEach(e => this.append(e));
1363
+ return this;
1364
+ }
1365
+ insertBefore(append) {
1366
+ this.element.before(append.element);
1367
+ return this;
1368
+ }
1369
+ insertAfter(append) {
1370
+ this.element.after(append.element);
1371
+ return this;
1372
+ }
1373
+ appendTo(target) {
1374
+ target.element.append(this.element);
1375
+ return this;
1376
+ }
1377
+ prependTo(target) {
1378
+ target.element.prepend(this.element);
1379
+ return this;
1380
+ }
1381
+ trigger(event, e) {
1382
+ this.element.dispatchEvent(e ?? new Event(event));
1383
+ return this;
1384
+ }
1385
+ on(event, handle, options) {
1386
+ const entry = new HandlerEntry(handle, undefined, options);
1387
+ EventRegistry.instance.on(event, this, entry);
1388
+ return this;
1389
+ }
1390
+ onChild(event, selector, handle, options) {
1391
+ const delegate = (e) => {
1392
+ const target = e.target;
1393
+ if (target && target.closest(selector)) {
1394
+ return handle(e);
1395
+ }
1396
+ };
1397
+ const entry = new HandlerEntry(handle, delegate, options);
1398
+ EventRegistry.instance.on(event, this, entry);
1399
+ return this;
1400
+ }
1401
+ once(event, handle, options) {
1402
+ const mergedOptions = { ...(options ?? {}), once: true };
1403
+ const entry = new HandlerEntry(handle, undefined, mergedOptions);
1404
+ this.off(event, handle, mergedOptions);
1405
+ EventRegistry.instance.on(event, this, entry);
1406
+ return this;
1407
+ }
1408
+ off(event, handle, options) {
1409
+ if (handle) {
1410
+ const entry = new HandlerEntry(handle, undefined, options);
1411
+ EventRegistry.instance.off(event, this, entry);
1412
+ }
1413
+ else {
1414
+ EventRegistry.instance.off(event, this);
1415
+ }
1416
+ return this;
1417
+ }
1418
+ click(handle) {
1419
+ if (handle) {
1420
+ this.element.addEventListener("click", async (e) => await handle(e));
1421
+ }
1422
+ else {
1423
+ this.trigger("click");
1424
+ }
1425
+ return this;
1426
+ }
1427
+ dblclick(handle) {
1428
+ if (handle) {
1429
+ this.element.addEventListener("dblclick", async (e) => await handle(e));
1430
+ }
1431
+ else {
1432
+ this.trigger("dblclick");
1433
+ }
1434
+ return this;
1435
+ }
1436
+ mouseover(handle) {
1437
+ if (handle) {
1438
+ this.element.addEventListener("mouseover", async (e) => await handle(e));
1439
+ }
1440
+ else {
1441
+ this.trigger("mouseover");
1442
+ }
1443
+ return this;
1444
+ }
1445
+ mouseout(handle) {
1446
+ if (handle) {
1447
+ this.element.addEventListener("mouseout", async (e) => await handle(e));
1448
+ }
1449
+ else {
1450
+ this.trigger("mouseout");
1451
+ }
1452
+ return this;
1453
+ }
1454
+ mousedown(handle) {
1455
+ if (handle) {
1456
+ this.element.addEventListener("mousedown", async (e) => await handle(e));
1457
+ }
1458
+ else {
1459
+ this.trigger("mousedown");
1460
+ }
1461
+ return this;
1462
+ }
1463
+ mouseup(handle) {
1464
+ if (handle) {
1465
+ this.element.addEventListener("mouseup", async (e) => await handle(e));
1466
+ }
1467
+ else {
1468
+ this.trigger("mouseup");
1469
+ }
1470
+ return this;
1471
+ }
1472
+ mousemove(handle) {
1473
+ if (handle) {
1474
+ this.element.addEventListener("mousemove", async (e) => await handle(e));
1475
+ }
1476
+ else {
1477
+ this.trigger("mousemove");
1478
+ }
1479
+ return this;
1480
+ }
1481
+ mouseenter(handle) {
1482
+ if (handle) {
1483
+ this.element.addEventListener("mouseenter", async (e) => await handle(e));
1484
+ }
1485
+ else {
1486
+ this.trigger("mouseenter");
1487
+ }
1488
+ return this;
1489
+ }
1490
+ mouseleave(handle) {
1491
+ if (handle) {
1492
+ this.element.addEventListener("mouseleave", async (e) => await handle(e));
1493
+ }
1494
+ else {
1495
+ this.trigger("mouseleave");
1496
+ }
1497
+ return this;
1498
+ }
1499
+ dragstart(handle) {
1500
+ if (handle) {
1501
+ this.element.addEventListener("dragstart", async (e) => await handle(e));
1502
+ }
1503
+ else {
1504
+ this.trigger("dragstart");
1505
+ }
1506
+ return this;
1507
+ }
1508
+ dragend(handle) {
1509
+ if (handle) {
1510
+ this.element.addEventListener("dragend", async (e) => await handle(e));
1511
+ }
1512
+ else {
1513
+ this.trigger("dragend");
1514
+ }
1515
+ return this;
1516
+ }
1517
+ dragover(handle) {
1518
+ if (handle) {
1519
+ this.element.addEventListener("dragover", async (e) => await handle(e));
1520
+ }
1521
+ else {
1522
+ this.trigger("dragover");
1523
+ }
1524
+ return this;
1525
+ }
1526
+ dragenter(handle) {
1527
+ if (handle) {
1528
+ this.element.addEventListener("dragenter", async (e) => await handle(e));
1529
+ }
1530
+ else {
1531
+ this.trigger("dragenter");
1532
+ }
1533
+ return this;
1534
+ }
1535
+ dragleave(handle) {
1536
+ if (handle) {
1537
+ this.element.addEventListener("dragleave", async (e) => await handle(e));
1538
+ }
1539
+ else {
1540
+ this.trigger("dragleave");
1541
+ }
1542
+ return this;
1543
+ }
1544
+ drop(handle) {
1545
+ if (handle) {
1546
+ this.element.addEventListener("drop", async (e) => await handle(e));
1547
+ }
1548
+ else {
1549
+ this.trigger("drop");
1550
+ }
1551
+ return this;
1552
+ }
1553
+ drag(handle) {
1554
+ if (handle) {
1555
+ this.element.addEventListener("drag", async (e) => await handle(e));
1556
+ }
1557
+ else {
1558
+ this.trigger("drag");
1559
+ }
1560
+ return this;
1561
+ }
1562
+ removed(handle) {
1563
+ this.element.addEventListener("removed", async (e) => await handle(e));
1564
+ return this;
1565
+ }
1566
+ keydown(handle) {
1567
+ if (handle) {
1568
+ this.element.addEventListener("keydown", async (e) => await handle(e));
1569
+ }
1570
+ else {
1571
+ this.trigger("keydown");
1572
+ }
1573
+ return this;
1574
+ }
1575
+ keyup(handle) {
1576
+ if (handle) {
1577
+ this.element.addEventListener("keyup", async (e) => await handle(e));
1578
+ }
1579
+ else {
1580
+ this.trigger("keyup");
1581
+ }
1582
+ return this;
1583
+ }
1584
+ keypress(handle) {
1585
+ if (handle) {
1586
+ this.element.addEventListener("keypress", async (e) => await handle(e));
1587
+ }
1588
+ else {
1589
+ this.trigger("keypress");
1590
+ }
1591
+ return this;
1592
+ }
1593
+ change(handle) {
1594
+ if (handle) {
1595
+ this.element.addEventListener("change", async (e) => await handle(e));
1596
+ }
1597
+ else {
1598
+ this.trigger("change");
1599
+ }
1600
+ return this;
1601
+ }
1602
+ input(handle) {
1603
+ if (handle) {
1604
+ this.element.addEventListener("input", async (e) => await handle(e));
1605
+ }
1606
+ else {
1607
+ this.trigger("input");
1608
+ }
1609
+ return this;
1610
+ }
1611
+ static get intersectionObserver() {
1612
+ return CotomyElement._intersectionObserver = CotomyElement._intersectionObserver
1613
+ ?? new IntersectionObserver(entries => {
1614
+ entries.filter(entry => entry.isIntersecting).forEach(entry => entry.target.dispatchEvent(new Event("inview")));
1615
+ entries.filter(entry => !entry.isIntersecting).forEach(entry => entry.target.dispatchEvent(new Event("outview")));
1616
+ });
1617
+ }
1618
+ inview(handle) {
1619
+ if (handle) {
1620
+ CotomyElement.intersectionObserver.observe(this.element);
1621
+ this.element.addEventListener("inview", async (e) => await handle(e));
1622
+ }
1623
+ else {
1624
+ this.trigger("inview");
1625
+ }
1626
+ return this;
1627
+ }
1628
+ outview(handle) {
1629
+ if (handle) {
1630
+ CotomyElement.intersectionObserver.observe(this.element);
1631
+ this.element.addEventListener("outview", async (e) => await handle(e));
1632
+ }
1633
+ else {
1634
+ this.trigger("outview");
1635
+ }
1636
+ return this;
1637
+ }
1638
+ focus(handle) {
1639
+ if (handle) {
1640
+ this.element.addEventListener("focus", async (e) => await handle(e));
1641
+ }
1642
+ else {
1643
+ this.trigger("focus");
1644
+ }
1645
+ return this;
1646
+ }
1647
+ blur(handle) {
1648
+ if (handle) {
1649
+ this.element.addEventListener("blur", async (e) => await handle(e));
1650
+ }
1651
+ else {
1652
+ this.trigger("blur");
1653
+ }
1654
+ return this;
1655
+ }
1656
+ focusin(handle) {
1657
+ if (handle) {
1658
+ this.element.addEventListener("focusin", async (e) => await handle(e));
1659
+ }
1660
+ else {
1661
+ this.trigger("focusin");
1662
+ }
1663
+ return this;
1664
+ }
1665
+ focusout(handle) {
1666
+ if (handle) {
1667
+ this.element.addEventListener("focusout", async (e) => await handle(e));
1668
+ }
1669
+ else {
1670
+ this.trigger("focusout");
1671
+ }
1672
+ return this;
1673
+ }
1674
+ filedrop(handle) {
1675
+ this.element.addEventListener("drop", async (e) => {
1676
+ e.preventDefault();
1677
+ const dt = e.dataTransfer;
1678
+ if (dt && dt.files) {
1679
+ await handle(Array.from(dt.files));
1680
+ }
1681
+ });
1682
+ return this;
1683
+ }
1684
+ resize(handle) {
1685
+ this.listenLayoutEvents();
1686
+ if (handle) {
1687
+ this.element.addEventListener("cotomy:resize", async (e) => await handle(e));
1688
+ }
1689
+ else {
1690
+ this.trigger("cotomy:resize");
1691
+ }
1692
+ return this;
1693
+ }
1694
+ scroll(handle) {
1695
+ this.listenLayoutEvents();
1696
+ if (handle) {
1697
+ this.element.addEventListener("cotomy:scroll", async (e) => await handle(e));
1698
+ }
1699
+ else {
1700
+ this.trigger("cotomy:scroll");
1701
+ }
1702
+ return this;
1703
+ }
1704
+ changelayout(handle) {
1705
+ this.listenLayoutEvents();
1706
+ if (handle) {
1707
+ this.element.addEventListener("cotomy:changelayout", async (e) => await handle(e));
1708
+ }
1709
+ else {
1710
+ this.trigger("cotomy:changelayout");
1711
+ }
1712
+ return this;
1713
+ }
1714
+ }
1715
+ CotomyElement.LISTEN_LAYOUT_EVENTS_ATTRIBUTE = "data-cotomy-layout";
1716
+ CotomyElement._intersectionObserver = null;
1717
+ class CotomyMetaElement extends CotomyElement {
1718
+ static get(name) {
1719
+ return CotomyElement.first(`meta[name="${name}" i]`, CotomyMetaElement)
1720
+ ?? CotomyElement.empty(CotomyMetaElement);
1721
+ }
1722
+ get content() {
1723
+ return this.attribute("content") ?? "";
1724
+ }
1725
+ }
1726
+ class CotomyWindow {
1727
+ constructor() {
1728
+ this._body = CotomyElement.empty();
1729
+ this._mutationObserver = null;
1730
+ this._reloading = false;
1731
+ this._eventHandlers = {};
1732
+ }
1733
+ static get instance() {
1734
+ return CotomyWindow._instance ?? (CotomyWindow._instance = new CotomyWindow());
1735
+ }
1736
+ get initialized() {
1737
+ return this._body.attached;
1738
+ }
1739
+ initialize() {
1740
+ if (!this.initialized) {
1741
+ if (!document.body) {
1742
+ throw new Error("<body> element not found. DOM may not be ready.");
1743
+ }
1744
+ this._body = CotomyElement.first("body");
1745
+ const changeLayoutEvents = ["resize", "scroll", "orientationchange", "fullscreenchange", "cotomy:ready"];
1746
+ changeLayoutEvents.forEach(e => {
1747
+ window.addEventListener(e, () => {
1748
+ const changeLayoutEvent = new CustomEvent("cotomy:changelayout");
1749
+ window.dispatchEvent(changeLayoutEvent);
1750
+ }, { passive: true });
1751
+ });
1752
+ document.addEventListener("dragover", e => {
1753
+ e.stopPropagation();
1754
+ e.preventDefault();
1755
+ });
1756
+ this.resize(() => {
1757
+ document.querySelectorAll(`[${CotomyElement.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(e => {
1758
+ e.dispatchEvent(new CustomEvent("cotomy:resize"));
1759
+ });
1760
+ });
1761
+ this.scroll(() => {
1762
+ document.querySelectorAll(`[${CotomyElement.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(e => {
1763
+ e.dispatchEvent(new CustomEvent("cotomy:scroll"));
1764
+ });
1765
+ });
1766
+ this.changeLayout(() => {
1767
+ document.querySelectorAll(`[${CotomyElement.LISTEN_LAYOUT_EVENTS_ATTRIBUTE}]`).forEach(e => {
1768
+ e.dispatchEvent(new CustomEvent("cotomy:changelayout"));
1769
+ });
1770
+ });
1771
+ this._mutationObserver = new MutationObserver(mutations => {
1772
+ mutations.forEach(mutation => {
1773
+ mutation.removedNodes.forEach(node => {
1774
+ if (node instanceof HTMLElement) {
1775
+ const element = new CotomyElement(node);
1776
+ element.trigger("removed");
1777
+ }
1778
+ });
1779
+ });
1780
+ });
1781
+ this._mutationObserver.observe(this.body.element, { childList: true, subtree: true });
1782
+ }
1783
+ }
1784
+ get reloading() {
1785
+ return this._reloading;
1786
+ }
1787
+ reload() {
1788
+ this._reloading = true;
1789
+ location.reload();
1790
+ }
1791
+ get body() {
1792
+ return this._body;
1793
+ }
1794
+ append(e) {
1795
+ this._body.append(e);
1796
+ }
1797
+ moveNext(focused, shift = false) {
1798
+ const selector = "input, a, select, button, textarea";
1799
+ const focusableElements = Array.from(this.body.element.querySelectorAll(selector))
1800
+ .map(e => new CotomyElement(e))
1801
+ .filter(e => e.width > 0 && e.height > 0 && e.visible && e.enabled && !e.hasAttribute("readonly"));
1802
+ const focusedIndex = focusableElements.map(e => e.element).indexOf(focused.element);
1803
+ let nextIndex = focusedIndex + (shift ? -1 : 1);
1804
+ if (nextIndex >= focusableElements.length) {
1805
+ nextIndex = 0;
1806
+ }
1807
+ else if (nextIndex < 0) {
1808
+ nextIndex = focusableElements.length - 1;
1809
+ }
1810
+ if (focusableElements[nextIndex]) {
1811
+ focusableElements[nextIndex].setFocus();
1812
+ }
1813
+ }
1814
+ trigger(event) {
1815
+ window.dispatchEvent(new Event(event));
1816
+ }
1817
+ on(event, handle) {
1818
+ if (!this._eventHandlers[event])
1819
+ this._eventHandlers[event] = [];
1820
+ this._eventHandlers[event].push(handle);
1821
+ window.addEventListener(event, handle);
1822
+ }
1823
+ off(event, handle) {
1824
+ if (handle) {
1825
+ window.removeEventListener(event, handle);
1826
+ this._eventHandlers[event] = this._eventHandlers[event]?.filter(h => h !== handle) ?? [];
1827
+ }
1828
+ else {
1829
+ for (const h of this._eventHandlers[event] ?? []) {
1830
+ window.removeEventListener(event, h);
1831
+ }
1832
+ delete this._eventHandlers[event];
1833
+ }
1834
+ }
1835
+ handlers(event) {
1836
+ return this._eventHandlers[event] ?? [];
1837
+ }
1838
+ load(handle) {
1839
+ this.on("load", handle);
1840
+ }
1841
+ ready(handle) {
1842
+ this.on("cotomy:ready", handle);
1843
+ }
1844
+ resize(handle) {
1845
+ if (handle) {
1846
+ this.on("resize", handle);
1847
+ }
1848
+ else {
1849
+ this.trigger("resize");
1850
+ }
1851
+ }
1852
+ scroll(handle) {
1853
+ if (handle) {
1854
+ this.on("scroll", handle);
1855
+ }
1856
+ else {
1857
+ this.trigger("scroll");
1858
+ }
1859
+ }
1860
+ changeLayout(handle) {
1861
+ if (handle) {
1862
+ this.on("cotomy:changelayout", handle);
1863
+ }
1864
+ else {
1865
+ this.trigger("cotomy:changelayout");
1866
+ }
1867
+ }
1868
+ pageshow(handle) {
1869
+ if (handle) {
1870
+ this.on("pageshow", handle);
1871
+ }
1872
+ else {
1873
+ this.trigger("pageshow");
1874
+ }
1875
+ }
1876
+ get scrollTop() {
1877
+ return window.scrollY || document.documentElement.scrollTop;
1878
+ }
1879
+ get scrollLeft() {
1880
+ return window.scrollX || document.documentElement.scrollLeft;
1881
+ }
1882
+ get width() {
1883
+ return window.innerWidth;
1884
+ }
1885
+ get height() {
1886
+ return window.innerHeight;
1887
+ }
1888
+ get documentWidth() {
1889
+ return document.documentElement.scrollWidth;
1890
+ }
1891
+ get documentHeight() {
1892
+ return document.documentElement.scrollHeight;
1893
+ }
1894
+ }
1895
+ CotomyWindow._instance = null;
1896
+
1897
+ ;// ./src/api.ts
1898
+
1899
+
1900
+
1901
+
1902
+ class CotomyApiException extends Error {
1903
+ constructor(status, message, response, bodyText = "") {
1904
+ super(message);
1905
+ this.status = status;
1906
+ this.message = message;
1907
+ this.response = response;
1908
+ this.bodyText = bodyText;
1909
+ this.name = "CotomyApiException";
1910
+ }
1911
+ }
1912
+ class CotomyHttpClientError extends CotomyApiException {
1913
+ constructor(status, message, response, body = "") {
1914
+ super(status, message, response, body);
1915
+ this.name = "CotomyHttpClientError";
1916
+ }
1917
+ }
1918
+ class CotomyUnauthorizedException extends CotomyHttpClientError {
1919
+ constructor(status, message, response, body = "") {
1920
+ super(status, message, response, body);
1921
+ this.name = "CotomyUnauthorizedException";
1922
+ }
1923
+ }
1924
+ class CotomyForbiddenException extends CotomyHttpClientError {
1925
+ constructor(status, message, response, body = "") {
1926
+ super(status, message, response, body);
1927
+ this.name = "CotomyForbiddenException";
1928
+ }
1929
+ }
1930
+ class CotomyNotFoundException extends CotomyHttpClientError {
1931
+ constructor(status, message, response, body = "") {
1932
+ super(status, message, response, body);
1933
+ this.name = "CotomyNotFoundException";
1934
+ }
1935
+ }
1936
+ class CotomyConflictException extends CotomyHttpClientError {
1937
+ constructor(status, message, response, body = "") {
1938
+ super(status, message, response, body);
1939
+ this.name = "CotomyConflictException";
1940
+ }
1941
+ }
1942
+ class CotomyRequestInvalidException extends CotomyHttpClientError {
1943
+ constructor(status, message, response, body = "") {
1944
+ super(status, message, response, body);
1945
+ this.name = "CotomyRequestInvalidException";
1946
+ }
1947
+ }
1948
+ class CotomyTooManyRequestsException extends CotomyHttpClientError {
1949
+ constructor(status, message, response, body = "") {
1950
+ super(status, message, response, body);
1951
+ this.name = "CotomyTooManyRequestsException";
1952
+ }
1953
+ }
1954
+ class CotomyHttpServerError extends CotomyApiException {
1955
+ constructor(status, message, response, body = "") {
1956
+ super(status, message, response, body);
1957
+ this.name = "CotomyHttpServerError";
1958
+ }
1959
+ }
1960
+ class CotomyResponseJsonParseException extends Error {
1961
+ constructor(message = "Failed to parse JSON response.") {
1962
+ super(message);
1963
+ this.name = "CotomyResponseJsonParseException";
1964
+ }
1965
+ }
1966
+ class CotomyInvalidFormDataBodyException extends Error {
1967
+ constructor(message = "Body must be an instance of FormData.") {
1968
+ super(message);
1969
+ this.name = "CotomyInvalidFormDataBodyException";
1970
+ }
1971
+ }
1972
+ class Methods {
1973
+ }
1974
+ Methods.GET = 'GET';
1975
+ Methods.POST = 'POST';
1976
+ Methods.PUT = 'PUT';
1977
+ Methods.PATCH = 'PATCH';
1978
+ Methods.DELETE = 'DELETE';
1979
+ Methods.HEAD = 'HEAD';
1980
+ Methods.OPTIONS = 'OPTIONS';
1981
+ Methods.TRACE = 'TRACE';
1982
+ Methods.CONNECT = 'CONNECT';
1983
+ class ResponseMessages {
1984
+ static getMessage(status) {
1985
+ return this._responseMessages[status] || `Unexpected error: ${status}`;
1986
+ }
1987
+ }
1988
+ ResponseMessages._responseMessages = {
1989
+ [StatusCodes.BAD_REQUEST]: "There is an error in the input. Please check and try again.",
1990
+ [StatusCodes.UNAUTHORIZED]: "You are not authenticated. Please log in again.",
1991
+ [StatusCodes.FORBIDDEN]: "You do not have permission to use this feature. If necessary, please contact the administrator.",
1992
+ [StatusCodes.NOT_FOUND]: "The specified information could not be found. It may have been deleted. Please start over or contact the administrator.",
1993
+ [StatusCodes.METHOD_NOT_ALLOWED]: "This operation is currently prohibited on the server.",
1994
+ [StatusCodes.NOT_ACCEPTABLE]: "The request cannot be accepted. Processing has been stopped.",
1995
+ [StatusCodes.PROXY_AUTHENTICATION_REQUIRED]: "Proxy authentication is required for internet access.",
1996
+ [StatusCodes.REQUEST_TIMEOUT]: "The request timed out. Please try again.",
1997
+ [StatusCodes.CONFLICT]: "The identifier you are trying to register already exists. Please check the content and try again.",
1998
+ [StatusCodes.PAYMENT_REQUIRED]: "Payment is required for this operation. Please check.",
1999
+ [StatusCodes.GONE]: "The requested resource is no longer available.",
2000
+ [StatusCodes.LENGTH_REQUIRED]: "The Content-Length header field is required for the request.",
2001
+ [StatusCodes.PRECONDITION_FAILED]: "The request failed because the precondition was not met.",
2002
+ [StatusCodes.UNSUPPORTED_MEDIA_TYPE]: "The requested media type is not supported.",
2003
+ [StatusCodes.EXPECTATION_FAILED]: "The server cannot meet the Expect header of the request.",
2004
+ [StatusCodes.MISDIRECTED_REQUEST]: "The server cannot appropriately process this request.",
2005
+ [StatusCodes.UNPROCESSABLE_ENTITY]: "There is an error in the request content.",
2006
+ [StatusCodes.LOCKED]: "The requested resource is locked.",
2007
+ [StatusCodes.FAILED_DEPENDENCY]: "The request failed due to dependency on a previous failed request.",
2008
+ [StatusCodes.UPGRADE_REQUIRED]: "A protocol upgrade is required to perform this operation.",
2009
+ [StatusCodes.PRECONDITION_REQUIRED]: "This request requires a precondition.",
2010
+ [StatusCodes.TOO_MANY_REQUESTS]: "Too many requests have been sent in a short time. Please wait and try again.",
2011
+ [StatusCodes.REQUEST_HEADER_FIELDS_TOO_LARGE]: "The request headers are too large.",
2012
+ [StatusCodes.INTERNAL_SERVER_ERROR]: "An unexpected error occurred. Please try again later.",
2013
+ [StatusCodes.BAD_GATEWAY]: "The server is currently overloaded. Please wait and try again later.",
2014
+ [StatusCodes.SERVICE_UNAVAILABLE]: "The service is temporarily unavailable. Please try again later.",
2015
+ [StatusCodes.GATEWAY_TIMEOUT]: "The communication timed out. Please try again.",
2016
+ [StatusCodes.HTTP_VERSION_NOT_SUPPORTED]: "The current communication method is not supported.",
2017
+ [StatusCodes.NOT_IMPLEMENTED]: "The server does not support the requested functionality.",
2018
+ [StatusCodes.INSUFFICIENT_STORAGE]: "The server has insufficient storage.",
2019
+ [StatusCodes.NETWORK_AUTHENTICATION_REQUIRED]: "Network authentication is required.",
2020
+ 413: "The payload of the request is too large. Please check the size.",
2021
+ 414: "The request URI is too long.",
2022
+ 416: "The requested range is invalid.",
2023
+ 508: "The server detected a loop.",
2024
+ 510: "The request does not include the required extensions.",
2025
+ };
2026
+ class CotomyApiResponse {
2027
+ constructor(_response) {
2028
+ this._response = _response;
2029
+ this._object = null;
2030
+ this._text = null;
2031
+ }
2032
+ get available() {
2033
+ return !!this._response;
2034
+ }
2035
+ get empty() {
2036
+ return !this._response || this._response.status === 0;
2037
+ }
2038
+ get ok() {
2039
+ return this._response?.ok ?? false;
2040
+ }
2041
+ get status() {
2042
+ return this._response?.status ?? 0;
2043
+ }
2044
+ get statusText() {
2045
+ return this._response?.statusText ?? '';
2046
+ }
2047
+ get headers() {
2048
+ return this._response?.headers ?? new Headers();
2049
+ }
2050
+ async textAsync() {
2051
+ if (!this._response)
2052
+ return "";
2053
+ return this._text ?? (this._text = await this._response?.text());
2054
+ }
2055
+ async _ensureJsonParsedAsync(defaultValue) {
2056
+ if (this._response && this._object === null) {
2057
+ try {
2058
+ const text = await this.textAsync();
2059
+ if (!text) {
2060
+ this._object = defaultValue;
2061
+ }
2062
+ else {
2063
+ this._object = JSON.parse(text);
2064
+ }
2065
+ }
2066
+ catch (error) {
2067
+ throw new CotomyResponseJsonParseException(`Failed to parse JSON response: ${error instanceof Error ? error.message : String(error)}`);
2068
+ }
2069
+ }
2070
+ return this._object ?? defaultValue;
2071
+ }
2072
+ async objectAsync(defaultValue = {}) {
2073
+ return await this._ensureJsonParsedAsync(defaultValue);
2074
+ }
2075
+ async arrayAsync(defaultValue = []) {
2076
+ const parsed = await this._ensureJsonParsedAsync(defaultValue);
2077
+ return Array.isArray(parsed) ? parsed : defaultValue;
2078
+ }
2079
+ }
2080
+ class CotomyBracketBindNameGenerator {
2081
+ create(name, parent) {
2082
+ return parent ? `${parent}[${name}]` : name;
2083
+ }
2084
+ }
2085
+ class CotomyDotBindNameGenerator {
2086
+ create(name, parent) {
2087
+ return parent ? `${parent}.${name}` : name;
2088
+ }
2089
+ }
2090
+ class CotomyViewRenderer {
2091
+ constructor(element, bindNameGenerator) {
2092
+ this.element = element;
2093
+ this.bindNameGenerator = bindNameGenerator;
2094
+ this._renderers = {};
2095
+ this._builded = false;
2096
+ }
2097
+ get locale() {
2098
+ const languages = (navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language]).filter(Boolean);
2099
+ let locale = this.element.attribute("data-cotomy-locale")
2100
+ || this.element.closest("[data-cotomy-locale]")?.attribute("data-cotomy-locale")
2101
+ || languages[0]
2102
+ || 'en-US';
2103
+ return locale.includes("-") ? locale.split("-")[0] : locale;
2104
+ }
2105
+ renderer(type, callback) {
2106
+ this._renderers[type] = callback;
2107
+ return this;
2108
+ }
2109
+ get initialized() {
2110
+ return this._builded;
2111
+ }
2112
+ initialize() {
2113
+ if (!this.initialized) {
2114
+ this.renderer("mail", (element, value) => {
2115
+ if (value) {
2116
+ new CotomyElement(`<a href="mailto:${value}">${value}</a>`).appendTo(element);
2117
+ }
2118
+ });
2119
+ this.renderer("tel", (element, value) => {
2120
+ if (value) {
2121
+ new CotomyElement(`<a href="tel:${value}">${value}</a>`).appendTo(element);
2122
+ }
2123
+ });
2124
+ this.renderer("url", (element, value) => {
2125
+ if (value) {
2126
+ new CotomyElement(`<a href="${value}" target="_blank">${value}</a>`).appendTo(element);
2127
+ }
2128
+ });
2129
+ this.renderer("number", (element, value) => {
2130
+ if (value !== undefined && value !== null) {
2131
+ const currency = element.attribute("data-cotomy-currency")
2132
+ || element.closest("[data-cotomy-currency]")?.attribute("data-cotomy-currency");
2133
+ element.text = currency
2134
+ ? new Intl.NumberFormat(this.locale, { style: "currency", currency: currency }).format(value)
2135
+ : new Intl.NumberFormat(this.locale).format(value);
2136
+ }
2137
+ });
2138
+ this.renderer("utc", (element, value) => {
2139
+ if (value) {
2140
+ const hasOffset = /[+-]\d{2}:\d{2}$/.test(value);
2141
+ const date = hasOffset ? new Date(value) : new Date(`${value}Z`);
2142
+ if (!isNaN(date.getTime())) {
2143
+ const format = element.attribute("data-cotomy-format") ?? "YYYY/MM/DD HH:mm";
2144
+ element.text = dayjs_min_default()(date).format(format);
2145
+ }
2146
+ }
2147
+ });
2148
+ this._builded = true;
2149
+ }
2150
+ return this;
2151
+ }
2152
+ async applyObjectAsync(target, propertyName = undefined) {
2153
+ if (!propertyName) {
2154
+ this.element.find("[data-cotomy-bind]").forEach(e => e.clear());
2155
+ }
2156
+ for (const [key, value] of Object.entries(await target)) {
2157
+ const pname = this.bindNameGenerator.create(key, propertyName);
2158
+ if (Array.isArray(value))
2159
+ continue;
2160
+ if (value && typeof value === "object") {
2161
+ await this.applyObjectAsync(value, pname);
2162
+ continue;
2163
+ }
2164
+ this.element.find(`[data-cotomy-bind="${pname}" i]`).forEach(element => {
2165
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Bind)) {
2166
+ console.debug(`Binding data to element [data-cotomy-bind="${pname}"]:`, value);
2167
+ }
2168
+ const type = element.attribute("data-cotomy-bindtype")?.toLowerCase();
2169
+ if (type && this._renderers[type]) {
2170
+ this._renderers[type](element, value);
2171
+ }
2172
+ else {
2173
+ element.text = String(value ?? "");
2174
+ }
2175
+ });
2176
+ }
2177
+ }
2178
+ async applyAsync(respose) {
2179
+ if (!this.initialized) {
2180
+ this.initialize();
2181
+ }
2182
+ if (!respose.available) {
2183
+ throw new Error("Response is not available.");
2184
+ }
2185
+ await this.applyObjectAsync(await respose.objectAsync());
2186
+ return this;
2187
+ }
2188
+ }
2189
+ class CotomyApi {
2190
+ constructor(_options = {
2191
+ baseUrl: null, headers: null, credentials: null, redirect: null,
2192
+ cache: null, referrerPolicy: null, mode: null, keepalive: true,
2193
+ integrity: '',
2194
+ }) {
2195
+ this._options = _options;
2196
+ this._abortController = new AbortController();
2197
+ }
2198
+ get baseUrl() {
2199
+ return this._options.baseUrl || '';
2200
+ }
2201
+ get headers() {
2202
+ return this._options.headers || {};
2203
+ }
2204
+ get credentials() {
2205
+ return this._options.credentials || 'same-origin';
2206
+ }
2207
+ get redirect() {
2208
+ return this._options.redirect || 'follow';
2209
+ }
2210
+ get cache() {
2211
+ return this._options.cache || 'no-cache';
2212
+ }
2213
+ get referrerPolicy() {
2214
+ return this._options.referrerPolicy || 'no-referrer';
2215
+ }
2216
+ get mode() {
2217
+ return this._options.mode || 'cors';
2218
+ }
2219
+ get keepalive() {
2220
+ return this._options.keepalive || true;
2221
+ }
2222
+ get integrity() {
2223
+ return this._options.integrity || '';
2224
+ }
2225
+ get abortController() {
2226
+ return this._abortController;
2227
+ }
2228
+ async requestAsync(method, path, body, signal, responseType) {
2229
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2230
+ console.debug(`API request: ${method} ${path}`, { body, headers: this.headers });
2231
+ }
2232
+ const bodyTransformers = {
2233
+ "application/json": (body) => JSON.stringify(body),
2234
+ "application/x-www-form-urlencoded": (body) => {
2235
+ if (body instanceof globalThis.FormData) {
2236
+ let params = new URLSearchParams();
2237
+ body.forEach((value, key) => {
2238
+ params.append(key, String(value));
2239
+ });
2240
+ return params.toString();
2241
+ }
2242
+ else {
2243
+ return new URLSearchParams(body).toString();
2244
+ }
2245
+ },
2246
+ "multipart/form-data": (body) => {
2247
+ if (body instanceof globalThis.FormData) {
2248
+ return body;
2249
+ }
2250
+ const formData = new globalThis.FormData();
2251
+ for (const [key, value] of Object.entries(body)) {
2252
+ formData.append(key, String(value));
2253
+ }
2254
+ return formData;
2255
+ }
2256
+ };
2257
+ const url = /^[a-zA-Z]/.test(path) ? path
2258
+ : `${(this.baseUrl || '').replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
2259
+ const headers = new Headers(this.headers);
2260
+ if (headers.has('Content-Type') && headers.get("Content-Type") === "multipart/form-data") {
2261
+ headers.delete('Content-Type');
2262
+ }
2263
+ const ct = headers.get('Content-Type') || "multipart/form-data";
2264
+ if (ct === 'multipart/form-data' && body && !(body instanceof globalThis.FormData)) {
2265
+ if (typeof body !== 'object' || Array.isArray(body)) {
2266
+ throw new CotomyInvalidFormDataBodyException('Body must be FormData or a plain object when using multipart/form-data.');
2267
+ }
2268
+ }
2269
+ const responseClass = responseType ?? CotomyApiResponse;
2270
+ const response = new responseClass(await fetch(url, {
2271
+ method,
2272
+ headers,
2273
+ credentials: this.credentials,
2274
+ body: body ? (bodyTransformers[ct] ? bodyTransformers[ct](body) : body) : undefined,
2275
+ signal: signal ?? this._abortController.signal,
2276
+ redirect: this.redirect,
2277
+ cache: this.cache,
2278
+ referrerPolicy: this.referrerPolicy,
2279
+ mode: this.mode,
2280
+ keepalive: this.keepalive,
2281
+ integrity: this.integrity,
2282
+ }));
2283
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2284
+ console.debug(`response body: ${response.status} ${response.statusText}`, await response.textAsync());
2285
+ }
2286
+ if (response.status >= 400 && response.status < 600) {
2287
+ const errorBody = await response.textAsync().catch(() => 'No response body available');
2288
+ const errorMessage = response.statusText || ResponseMessages.getMessage(response.status) || `Unexpected error: ${response.status}`;
2289
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2290
+ console.error(`API request failed: ${errorMessage}`, response, errorBody);
2291
+ }
2292
+ switch (response.status) {
2293
+ case StatusCodes.BAD_REQUEST:
2294
+ case StatusCodes.UNPROCESSABLE_ENTITY:
2295
+ throw new CotomyRequestInvalidException(response.status, errorMessage, response, errorBody);
2296
+ case StatusCodes.UNAUTHORIZED:
2297
+ throw new CotomyUnauthorizedException(response.status, errorMessage, response, errorBody);
2298
+ case StatusCodes.FORBIDDEN:
2299
+ throw new CotomyForbiddenException(response.status, errorMessage, response, errorBody);
2300
+ case StatusCodes.NOT_FOUND:
2301
+ throw new CotomyNotFoundException(response.status, errorMessage, response, errorBody);
2302
+ case StatusCodes.CONFLICT:
2303
+ case StatusCodes.GONE:
2304
+ throw new CotomyConflictException(response.status, errorMessage, response, errorBody);
2305
+ case StatusCodes.TOO_MANY_REQUESTS:
2306
+ throw new CotomyTooManyRequestsException(response.status, errorMessage, response, errorBody);
2307
+ default:
2308
+ if (response.status < 500) {
2309
+ throw new CotomyHttpClientError(response.status, errorMessage, response, errorBody);
2310
+ }
2311
+ else {
2312
+ throw new CotomyHttpServerError(response.status, errorMessage, response, errorBody);
2313
+ }
2314
+ }
2315
+ }
2316
+ return response;
2317
+ }
2318
+ async getAsync(path, parameters) {
2319
+ let queryString = '';
2320
+ if (parameters instanceof globalThis.FormData) {
2321
+ let params = new URLSearchParams();
2322
+ parameters.forEach((value, key) => {
2323
+ params.append(key, String(value));
2324
+ });
2325
+ queryString = params.toString();
2326
+ }
2327
+ else if (parameters) {
2328
+ queryString = new URLSearchParams(Object.fromEntries(Object.entries(parameters).map(([key, value]) => [key, String(value)]))).toString();
2329
+ }
2330
+ const fullUrl = queryString ? `${path}?${queryString}` : path;
2331
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2332
+ console.debug(`GET request to: ${fullUrl}`);
2333
+ }
2334
+ return this.requestAsync(Methods.GET, fullUrl);
2335
+ }
2336
+ async postAsync(path, body) {
2337
+ return this.requestAsync(Methods.POST, path, body);
2338
+ }
2339
+ async putAsync(path, body) {
2340
+ return this.requestAsync(Methods.PUT, path, body);
2341
+ }
2342
+ async patchAsync(path, body) {
2343
+ return this.requestAsync(Methods.PATCH, path, body);
2344
+ }
2345
+ async deleteAsync(path) {
2346
+ return this.requestAsync(Methods.DELETE, path);
2347
+ }
2348
+ async headAsync(path) {
2349
+ return this.requestAsync(Methods.HEAD, path);
2350
+ }
2351
+ async optionsAsync(path) {
2352
+ return this.requestAsync(Methods.OPTIONS, path);
2353
+ }
2354
+ async traceAsync(path) {
2355
+ return this.requestAsync(Methods.TRACE, path);
2356
+ }
2357
+ async connectAsync(path) {
2358
+ return this.requestAsync(Methods.CONNECT, path);
2359
+ }
2360
+ async submitAsync(form) {
2361
+ return form.method.toUpperCase() === Methods.GET ? this.getAsync(form.action, form.body)
2362
+ : this.requestAsync(form.method.toUpperCase(), form.action, form.body);
2363
+ }
2364
+ }
2365
+
2366
+ ;// ./src/form.ts
2367
+
2368
+
2369
+
2370
+
2371
+
2372
+ class CotomyForm extends CotomyElement {
2373
+ generateId(prefix = "__cotomy_form__") {
2374
+ return super.generateId(prefix);
2375
+ }
2376
+ method() {
2377
+ return this.attribute("method") ?? "get";
2378
+ }
2379
+ actionUrl() {
2380
+ return this.attribute("action") ?? location.pathname + location.search;
2381
+ }
2382
+ async reloadAsync() {
2383
+ CotomyWindow.instance.reload();
2384
+ }
2385
+ get autoReload() {
2386
+ return this.attribute("data-cotomy-autoreload") !== "false";
2387
+ }
2388
+ set autoReload(value) {
2389
+ if (value) {
2390
+ this.attribute("data-cotomy-autoreload", null);
2391
+ }
2392
+ else {
2393
+ this.attribute("data-cotomy-autoreload", "false");
2394
+ }
2395
+ }
2396
+ get initialized() {
2397
+ return this.hasAttribute("data-cotomy-initialized");
2398
+ }
2399
+ initialize() {
2400
+ if (!this.initialized) {
2401
+ this.on("submit", async (e) => {
2402
+ e.preventDefault();
2403
+ e.stopPropagation();
2404
+ await this.submitAsync();
2405
+ });
2406
+ this.attribute("data-cotomy-initialized", "");
2407
+ }
2408
+ return this;
2409
+ }
2410
+ }
2411
+ class CotomyQueryForm extends CotomyForm {
2412
+ method() {
2413
+ return "get";
2414
+ }
2415
+ async submitAsync() {
2416
+ const url = this.actionUrl();
2417
+ const queryParams = {};
2418
+ const queryString = url.split("?")[1];
2419
+ if (queryString) {
2420
+ queryString.split("&").forEach(param => {
2421
+ const [key, value] = param.split("=");
2422
+ if (key && value) {
2423
+ queryParams[key] = decodeURIComponent(value);
2424
+ }
2425
+ });
2426
+ }
2427
+ this.find("[name]").forEach(input => {
2428
+ const name = input.attribute("name");
2429
+ if (name) {
2430
+ const value = input.value;
2431
+ if (value) {
2432
+ queryParams[name] = encodeURIComponent(value);
2433
+ }
2434
+ else {
2435
+ delete queryParams[name];
2436
+ }
2437
+ }
2438
+ });
2439
+ const newQueryString = Object.entries(queryParams)
2440
+ .map(([key, value]) => `${key}=${value}`)
2441
+ .join("&");
2442
+ location.href = `${url.split("?")[0]}?${newQueryString}`;
2443
+ }
2444
+ }
2445
+ class CotomyApiFailedEvent extends Event {
2446
+ constructor(_response, eventName = "cotomy:apifailed") {
2447
+ super(eventName, { bubbles: true, cancelable: true });
2448
+ this._response = _response;
2449
+ }
2450
+ get response() {
2451
+ return this._response;
2452
+ }
2453
+ }
2454
+ class CotomyApiForm extends CotomyForm {
2455
+ apiClient() {
2456
+ return new CotomyApi();
2457
+ }
2458
+ actionUrl() {
2459
+ return this.attribute("action");
2460
+ }
2461
+ apiFailed(handle) {
2462
+ this.on("cotomy:apifailed", async (e) => {
2463
+ await handle(e);
2464
+ });
2465
+ return this;
2466
+ }
2467
+ triggerApiFailedEvent(response) {
2468
+ this.trigger("cotomy:apifailed", new CotomyApiFailedEvent(response));
2469
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2470
+ console.error("API request failed:", response);
2471
+ }
2472
+ }
2473
+ submitFailed(handle) {
2474
+ this.on("cotomy:submitfailed", async (e) => {
2475
+ await handle(e);
2476
+ });
2477
+ return this;
2478
+ }
2479
+ triggerSubmitFailedEvent(response) {
2480
+ this.trigger("cotomy:submitfailed", new CotomyApiFailedEvent(response, "cotomy:submitfailed"));
2481
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Api)) {
2482
+ console.error("Submit failed:", response);
2483
+ }
2484
+ }
2485
+ method() {
2486
+ return this.attribute("method") ?? "post";
2487
+ }
2488
+ formData() {
2489
+ const formElement = this.element;
2490
+ const formData = new FormData(formElement);
2491
+ this.find("input[type=datetime-local][name]:not([disabled])").forEach(input => {
2492
+ const localDateTime = input.value;
2493
+ if (localDateTime) {
2494
+ const date = new Date(localDateTime);
2495
+ if (!isNaN(date.getTime())) {
2496
+ formData.set(input.attribute("name"), dayjs_min_default()(date).format("YYYY-MM-DDTHH:mmZ"));
2497
+ }
2498
+ }
2499
+ });
2500
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.FormData)) {
2501
+ console.debug("FormData:", Array.from(formData.entries()));
2502
+ }
2503
+ return formData;
2504
+ }
2505
+ ;
2506
+ async submitAsync() {
2507
+ const formData = this.formData();
2508
+ await this.submitToApiAsync(formData);
2509
+ }
2510
+ async submitToApiAsync(formData) {
2511
+ const api = this.apiClient();
2512
+ try {
2513
+ const response = await api.submitAsync({
2514
+ method: this.method(),
2515
+ action: this.actionUrl(),
2516
+ body: formData,
2517
+ });
2518
+ return response;
2519
+ }
2520
+ catch (error) {
2521
+ if (error instanceof CotomyApiException) {
2522
+ this.triggerApiFailedEvent(error.response);
2523
+ this.triggerSubmitFailedEvent(error.response);
2524
+ }
2525
+ throw error;
2526
+ }
2527
+ }
2528
+ }
2529
+ class CotomyEntityApiForm extends CotomyApiForm {
2530
+ actionUrl() {
2531
+ const base = this.attribute("action");
2532
+ const keys = this.externalKey ? [this.externalKey] : this.pathKeyInputs.map(e => encodeURIComponent(e.value));
2533
+ return `${base}/${keys.join("/")}`;
2534
+ }
2535
+ method() {
2536
+ if (this.hasAttribute("method") && this.attribute("method") !== "") {
2537
+ return this.attribute("method");
2538
+ }
2539
+ if (this.externalKey)
2540
+ return "put";
2541
+ if (this.pathKeyInputs.length > 0 && this.pathKeyInputs.every(e => e.readonly))
2542
+ return "put";
2543
+ if (this.keyInputs.length > 0 && this.keyInputs.every(e => e.readonly))
2544
+ return "put";
2545
+ return "post";
2546
+ }
2547
+ get externalKey() {
2548
+ return this.attribute("data-cotomy-key") || undefined;
2549
+ }
2550
+ setExternalKey(response) {
2551
+ if (this.requiresExternalKey && response.status === StatusCodes.CREATED) {
2552
+ if (this.hasExternalKey) {
2553
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.FormLoad)) {
2554
+ console.warn("External key already exists, but server responded with 201 Created. Possible duplicate POST.");
2555
+ }
2556
+ return;
2557
+ }
2558
+ const location = response.headers.get("Location");
2559
+ if (!location)
2560
+ return;
2561
+ const normalize = (url) => {
2562
+ const s = url.replace(/[?#].*$/, "");
2563
+ return s.endsWith("/") ? s.slice(0, -1) : s;
2564
+ };
2565
+ const toPath = (u) => {
2566
+ try {
2567
+ return new URL(u, location).pathname;
2568
+ }
2569
+ catch {
2570
+ return u;
2571
+ }
2572
+ };
2573
+ const baseAction = normalize(toPath(this.attribute("action")));
2574
+ const locPath = normalize(toPath(location));
2575
+ const actionParts = baseAction.split("/");
2576
+ const locationParts = locPath.split("/");
2577
+ const isPrefix = locationParts.length >= actionParts.length && actionParts.every((p, i) => p === locationParts[i]);
2578
+ if (!isPrefix) {
2579
+ throw new Error(`Location path does not start with action path. action="${baseAction}", location="${locPath}"`);
2580
+ }
2581
+ const addedParts = locationParts.slice(actionParts.length).filter(Boolean);
2582
+ if (addedParts.length === 1 && addedParts[0]) {
2583
+ this.attribute("data-cotomy-key", addedParts[0]);
2584
+ }
2585
+ else {
2586
+ const msg = `Location does not contain a single external key segment.
2587
+ action="${baseAction}", location="${locPath}", added=["${addedParts.join('","')}"]`;
2588
+ throw new Error(msg);
2589
+ }
2590
+ }
2591
+ }
2592
+ get requiresExternalKey() {
2593
+ return this.attribute("data-cotomy-identify") !== "false" && this.keyInputs.length == 0 && this.pathKeyInputs.length == 0;
2594
+ }
2595
+ get hasExternalKey() {
2596
+ return !!this.externalKey;
2597
+ }
2598
+ get pathKeyInputs() {
2599
+ return this.find("[data-cotomy-keyindex]").sort((a, b) => {
2600
+ const aIndex = parseInt(a.attribute("data-cotomy-keyindex") ?? "0");
2601
+ const bIndex = parseInt(b.attribute("data-cotomy-keyindex") ?? "0");
2602
+ return aIndex - bIndex;
2603
+ });
2604
+ }
2605
+ get keyInputs() {
2606
+ return this.contains("[data-cotomy-key]") ? this.find("[data-cotomy-key]").sort((a, b) => {
2607
+ const aIndex = parseInt(a.attribute("data-cotomy-key") ?? "0");
2608
+ const bIndex = parseInt(b.attribute("data-cotomy-key") ?? "0");
2609
+ return aIndex - bIndex;
2610
+ }) : this.find("[name][data-cotomy-key]");
2611
+ }
2612
+ get usePathKey() {
2613
+ const use = this.pathKeyInputs.length > 0 || this.requiresExternalKey;
2614
+ if (use && this.hasExternalKey && CotomyDebugSettings.isEnabled(CotomyDebugFeature.FormLoad)) {
2615
+ console.warn("Both externalKey and pathKeyInputs are present. Using externalKey and ignoring pathKeyInputs.");
2616
+ }
2617
+ return use;
2618
+ }
2619
+ get pathKeyString() {
2620
+ return this.externalKey || this.pathKeyInputs.map(e => e.value).join("/");
2621
+ }
2622
+ async submitToApiAsync(formData) {
2623
+ const response = await super.submitToApiAsync(formData);
2624
+ if (this.requiresExternalKey && response.status === StatusCodes.CREATED) {
2625
+ this.setExternalKey(response);
2626
+ }
2627
+ return response;
2628
+ }
2629
+ }
2630
+ class CotomyEntityFillApiForm extends CotomyEntityApiForm {
2631
+ constructor() {
2632
+ super(...arguments);
2633
+ this._fillers = {};
2634
+ }
2635
+ filler(type, func) {
2636
+ this._fillers[type] = func;
2637
+ return this;
2638
+ }
2639
+ initialize() {
2640
+ if (!this.initialized) {
2641
+ super.initialize();
2642
+ this.filler("datetime-local", (input, value) => {
2643
+ const hasOffset = /[+-]\d{2}:\d{2}$/.test(value);
2644
+ const date = hasOffset ? new Date(value) : new Date(`${value}Z`);
2645
+ if (!isNaN(date.getTime())) {
2646
+ input.value = dayjs_min_default()(date).format("YYYY-MM-DDTHH:mm");
2647
+ }
2648
+ else {
2649
+ input.value = "";
2650
+ }
2651
+ });
2652
+ this.filler("checkbox", (input, value) => {
2653
+ input.attribute("checked", null);
2654
+ if (value) {
2655
+ input.attribute("checked", "");
2656
+ }
2657
+ });
2658
+ this.filler("radio", (input, value) => {
2659
+ input.attribute("checked", null);
2660
+ if (input.value === value) {
2661
+ input.attribute("checked", "");
2662
+ }
2663
+ });
2664
+ CotomyWindow.instance.ready(async () => {
2665
+ await this.loadAsync();
2666
+ });
2667
+ }
2668
+ return this;
2669
+ }
2670
+ async submitToApiAsync(formData) {
2671
+ const response = await super.submitToApiAsync(formData);
2672
+ if (response.ok) {
2673
+ await this.fillAsync(response);
2674
+ }
2675
+ return response;
2676
+ }
2677
+ async reloadAsync() {
2678
+ await this.loadAsync();
2679
+ }
2680
+ loadActionUrl() {
2681
+ return this.actionUrl();
2682
+ }
2683
+ bindNameGenerator() {
2684
+ return new CotomyBracketBindNameGenerator();
2685
+ }
2686
+ renderer() {
2687
+ return new CotomyViewRenderer(this, this.bindNameGenerator());
2688
+ }
2689
+ async loadAsync() {
2690
+ const hasPathKeys = this.pathKeyInputs.length > 0 && this.pathKeyInputs.every(e => !!e.value);
2691
+ const hasKeyInputs = this.keyInputs.length > 0 && this.keyInputs.every(e => !!e.value);
2692
+ if (!this.hasExternalKey && !hasPathKeys && !hasKeyInputs) {
2693
+ return new CotomyApiResponse();
2694
+ }
2695
+ const api = this.apiClient();
2696
+ try {
2697
+ const response = await api.getAsync(this.loadActionUrl());
2698
+ await this.fillAsync(response);
2699
+ return response;
2700
+ }
2701
+ catch (error) {
2702
+ if (error instanceof CotomyApiException) {
2703
+ this.triggerApiFailedEvent(error.response);
2704
+ }
2705
+ if (error instanceof CotomyNotFoundException) {
2706
+ return error.response;
2707
+ }
2708
+ throw error;
2709
+ }
2710
+ }
2711
+ async fillObjectAsync(bindNameGenerator, target, propertyName = undefined) {
2712
+ for (const [key, value] of Object.entries(target)) {
2713
+ if (key.endsWith('[]')) {
2714
+ continue;
2715
+ }
2716
+ const pname = bindNameGenerator.create(key, propertyName);
2717
+ if (Array.isArray(value))
2718
+ continue;
2719
+ if (value && typeof value === "object") {
2720
+ await this.fillObjectAsync(bindNameGenerator, value, pname);
2721
+ continue;
2722
+ }
2723
+ this.find(`input[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple]),
2724
+ textarea[name="${pname}" i]:not([data-cotomy-fill="false"]),
2725
+ select[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple])`).forEach(input => {
2726
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Fill)) {
2727
+ console.debug(`Filling input[name="${pname}"] with value:`, value);
2728
+ }
2729
+ const type = input.attribute("type")?.toLowerCase();
2730
+ if (type && this._fillers[type]) {
2731
+ this._fillers[type](input, value);
2732
+ }
2733
+ else {
2734
+ input.value = String(value || "");
2735
+ }
2736
+ });
2737
+ }
2738
+ }
2739
+ async fillAsync(response) {
2740
+ if (response.ok && response.available) {
2741
+ await this.fillObjectAsync(this.bindNameGenerator(), await response.objectAsync());
2742
+ await this.renderer().applyAsync(response);
2743
+ }
2744
+ this.pathKeyInputs.forEach(e => e.readonly = true);
2745
+ this.keyInputs.forEach(e => e.readonly = true);
2746
+ this.find("textarea").forEach(e => e.input());
2747
+ }
2748
+ }
2749
+
2750
+ // EXTERNAL MODULE: ./node_modules/dayjs/plugin/timezone.js
2751
+ var timezone = __webpack_require__(569);
2752
+ var timezone_default = /*#__PURE__*/__webpack_require__.n(timezone);
2753
+ // EXTERNAL MODULE: ./node_modules/dayjs/plugin/utc.js
2754
+ var utc = __webpack_require__(826);
2755
+ var utc_default = /*#__PURE__*/__webpack_require__.n(utc);
2756
+ ;// ./src/page.ts
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+ dayjs_min_default().extend((utc_default()));
2763
+ dayjs_min_default().extend((timezone_default()));
2764
+ class CotomyUrl {
2765
+ static location() {
2766
+ return new CotomyUrl();
2767
+ }
2768
+ constructor(url = null) {
2769
+ this._url = new URL(url ?? (location.pathname + location.search), location.origin);
2770
+ }
2771
+ get url() {
2772
+ return this._url.pathname + this._url.search;
2773
+ }
2774
+ get path() {
2775
+ return this._url.pathname;
2776
+ }
2777
+ get segments() {
2778
+ return this._url.pathname.split("/").filter(s => s.length > 0);
2779
+ }
2780
+ get query() {
2781
+ return this._url.search.replace(/^\?/, "");
2782
+ }
2783
+ get parameters() {
2784
+ const dict = {};
2785
+ this._url.searchParams.forEach((value, key) => { dict[key] = value; });
2786
+ return dict;
2787
+ }
2788
+ redirect() {
2789
+ window.location.href = this.url;
2790
+ }
2791
+ }
2792
+ class CotomyPageController {
2793
+ constructor() {
2794
+ this._forms = {};
2795
+ }
2796
+ static set(type) {
2797
+ if (this._instance) {
2798
+ throw new Error("PageController is already initialized.");
2799
+ }
2800
+ this._instance = new type();
2801
+ CotomyWindow.instance.load(async () => {
2802
+ if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Page)) {
2803
+ console.debug("CotomyPageController initialize.");
2804
+ }
2805
+ CotomyWindow.instance.initialize();
2806
+ await CotomyPageController._instance.initializeAsync();
2807
+ CotomyWindow.instance.trigger("cotomy:ready");
2808
+ });
2809
+ return this._instance;
2810
+ }
2811
+ static get() {
2812
+ if (!(this._instance instanceof CotomyPageController)) {
2813
+ throw new Error("PageController is not initialized. Use CotomyPageController.set() to initialize it.");
2814
+ }
2815
+ return this._instance;
2816
+ }
2817
+ setForm(form) {
2818
+ if (!form.id) {
2819
+ form.generateId();
2820
+ }
2821
+ this._forms[form.id] = form;
2822
+ form.removed(() => {
2823
+ delete this._forms[form.id];
2824
+ });
2825
+ return form.initialize();
2826
+ }
2827
+ getForm(id, type) {
2828
+ const form = this._forms[id];
2829
+ if (!form)
2830
+ return undefined;
2831
+ if (type && !(form instanceof type)) {
2832
+ throw new Error(`Form "${id}" is not instance of expected type.`);
2833
+ }
2834
+ return form;
2835
+ }
2836
+ forms() {
2837
+ return Object.values(this._forms);
2838
+ }
2839
+ async restoreAsync() {
2840
+ for (const f of this.forms()) {
2841
+ if (CotomyWindow.instance.reloading) {
2842
+ break;
2843
+ }
2844
+ if (f.autoReload) {
2845
+ await f.reloadAsync();
2846
+ }
2847
+ }
2848
+ }
2849
+ isValidUtcDateString(value) {
2850
+ return dayjs_min_default()(value).isValid() && (value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value));
2851
+ }
2852
+ initializeDateTimeElements() {
2853
+ CotomyWindow.instance.body.find("[data-cotomy-datetime]:not([data-cotomy-formatted])").forEach(e => {
2854
+ if (dayjs_min_default()(e.text).isValid()) {
2855
+ const timezone = e.attribute("data-cotomy-timezone")
2856
+ || e.closest("[data-cotomy-timezone]")?.attribute("data-cotomy-timezone");
2857
+ const format = e.attribute("data-cotomy-format") ?? "YYYY-MM-DD HH:mm";
2858
+ const lt = this.isValidUtcDateString(e.text) ? dayjs_min_default()(e.text) : dayjs_min_default()(`${dayjs_min_default()(e.text).format("YYYY-MM-DDTHH:mm:ss")}Z`);
2859
+ const dt = e.attribute("data-cotomy-datetime") === "local" ? lt : lt.utc();
2860
+ e.text = (timezone && timezone.trim() !== "") ? dt.tz(timezone).format(format) : dt.format(format);
2861
+ e.attribute("data-cotomy-formatted", "");
2862
+ }
2863
+ });
2864
+ }
2865
+ async initializeAsync() {
2866
+ this.initializeDateTimeElements();
2867
+ CotomyWindow.instance.pageshow(async (e) => {
2868
+ if (e.persisted) {
2869
+ await this.restoreAsync();
2870
+ if (CotomyWindow.instance.reloading) {
2871
+ e.stopImmediatePropagation();
2872
+ }
2873
+ }
2874
+ });
2875
+ }
2876
+ get body() {
2877
+ return CotomyWindow.instance.body;
2878
+ }
2879
+ get url() {
2880
+ return new CotomyUrl();
2881
+ }
2882
+ }
2883
+ CotomyPageController._instance = null;
2884
+
2885
+ ;// ./src/index.ts
2886
+
2887
+
2888
+
2889
+
2890
+
2891
+
2892
+ })();
2893
+
2894
+ /******/ return __webpack_exports__;
2895
+ /******/ })()
2896
+ ;
2897
+ });
2898
+ //# sourceMappingURL=cotomy.js.map