godown 3.0.0-canary.13 → 3.0.0-canary.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +1 -1
  2. package/alert.js +1 -5
  3. package/alert.js.map +1 -1
  4. package/avatar.js +1 -5
  5. package/avatar.js.map +1 -1
  6. package/breath.js +1 -5
  7. package/breath.js.map +1 -1
  8. package/button.js +1 -5
  9. package/button.js.map +1 -1
  10. package/card.js +1 -5
  11. package/card.js.map +1 -1
  12. package/carousel.js +1 -5
  13. package/carousel.js.map +1 -1
  14. package/components/alert.js +1 -174
  15. package/components/alert.js.map +1 -1
  16. package/components/avatar.js +1 -68
  17. package/components/avatar.js.map +1 -1
  18. package/components/breath.js +1 -81
  19. package/components/breath.js.map +1 -1
  20. package/components/button.js +1 -185
  21. package/components/button.js.map +1 -1
  22. package/components/card.js +1 -49
  23. package/components/card.js.map +1 -1
  24. package/components/carousel.js +1 -119
  25. package/components/carousel.js.map +1 -1
  26. package/components/details.js +1 -53
  27. package/components/details.js.map +1 -1
  28. package/components/dialog.js +1 -98
  29. package/components/dialog.js.map +1 -1
  30. package/components/divider.js +1 -35
  31. package/components/divider.js.map +1 -1
  32. package/components/dragbox.js +1 -111
  33. package/components/dragbox.js.map +1 -1
  34. package/components/flex.js +1 -63
  35. package/components/flex.js.map +1 -1
  36. package/components/form.js +1 -75
  37. package/components/form.js.map +1 -1
  38. package/components/grid.js +1 -57
  39. package/components/grid.js.map +1 -1
  40. package/components/input.js +1 -51
  41. package/components/input.js.map +1 -1
  42. package/components/layout.js +1 -58
  43. package/components/layout.js.map +1 -1
  44. package/components/link.js +1 -53
  45. package/components/link.js.map +1 -1
  46. package/components/progress.js +1 -59
  47. package/components/progress.js.map +1 -1
  48. package/components/range.d.ts +1 -0
  49. package/components/range.d.ts.map +1 -1
  50. package/components/range.js +1 -267
  51. package/components/range.js.map +1 -1
  52. package/components/rotate.js +1 -56
  53. package/components/rotate.js.map +1 -1
  54. package/components/router.js +1 -247
  55. package/components/router.js.map +1 -1
  56. package/components/select.js +1 -217
  57. package/components/select.js.map +1 -1
  58. package/components/skeleton.js +1 -55
  59. package/components/skeleton.js.map +1 -1
  60. package/components/split.js +1 -154
  61. package/components/split.js.map +1 -1
  62. package/components/switch.js +1 -93
  63. package/components/switch.js.map +1 -1
  64. package/components/text.js +1 -46
  65. package/components/text.js.map +1 -1
  66. package/components/time.js +1 -78
  67. package/components/time.js.map +1 -1
  68. package/components/tooltip.js +1 -85
  69. package/components/tooltip.js.map +1 -1
  70. package/components/typewriter.js +1 -128
  71. package/components/typewriter.js.map +1 -1
  72. package/core/global-style.js +1 -52
  73. package/core/global-style.js.map +1 -1
  74. package/core/super-anchor.js +1 -39
  75. package/core/super-anchor.js.map +1 -1
  76. package/core/super-input.js +1 -117
  77. package/core/super-input.js.map +1 -1
  78. package/core/super-openable.js +1 -37
  79. package/core/super-openable.js.map +1 -1
  80. package/custom-elements.json +1 -1
  81. package/details.js +1 -5
  82. package/details.js.map +1 -1
  83. package/dev/components/range.d.ts +1 -0
  84. package/dev/components/range.d.ts.map +1 -1
  85. package/dev/components/range.js +8 -3
  86. package/dev/components/range.js.map +1 -1
  87. package/dev/components/router.js +2 -2
  88. package/dev/components/router.js.map +1 -1
  89. package/dialog.js +1 -5
  90. package/dialog.js.map +1 -1
  91. package/divider.js +1 -5
  92. package/divider.js.map +1 -1
  93. package/dragbox.js +1 -5
  94. package/dragbox.js.map +1 -1
  95. package/flex.js +1 -5
  96. package/flex.js.map +1 -1
  97. package/form.js +1 -5
  98. package/form.js.map +1 -1
  99. package/grid.js +1 -5
  100. package/grid.js.map +1 -1
  101. package/index.js +1 -56
  102. package/index.js.map +1 -1
  103. package/input.js +1 -5
  104. package/input.js.map +1 -1
  105. package/layout.js +1 -5
  106. package/layout.js.map +1 -1
  107. package/link.js +1 -5
  108. package/link.js.map +1 -1
  109. package/package.json +1 -1
  110. package/progress.js +1 -5
  111. package/progress.js.map +1 -1
  112. package/range.js +1 -5
  113. package/range.js.map +1 -1
  114. package/rotate.js +1 -5
  115. package/rotate.js.map +1 -1
  116. package/router.js +1 -5
  117. package/router.js.map +1 -1
  118. package/select.js +1 -5
  119. package/select.js.map +1 -1
  120. package/skeleton.js +1 -5
  121. package/skeleton.js.map +1 -1
  122. package/split.js +1 -5
  123. package/split.js.map +1 -1
  124. package/src/components/range.ts +9 -3
  125. package/src/components/router.ts +2 -2
  126. package/switch.js +1 -5
  127. package/switch.js.map +1 -1
  128. package/text.js +1 -5
  129. package/text.js.map +1 -1
  130. package/time.js +1 -5
  131. package/time.js.map +1 -1
  132. package/tooltip.js +1 -5
  133. package/tooltip.js.map +1 -1
  134. package/typewriter.js +1 -5
  135. package/typewriter.js.map +1 -1
  136. package/web-types.json +1 -1
@@ -1,57 +1,2 @@
1
- import { __decorate } from 'tslib';
2
- import { godown } from '@godown/element/decorators/godown.js';
3
- import { part } from '@godown/element/decorators/part.js';
4
- import { styles } from '@godown/element/decorators/styles.js';
5
- import { htmlSlot } from '@godown/element/directives/html-slot.js';
6
- import { css, html } from 'lit';
7
- import { scopePrefix, GlobalStyle } from '../core/global-style.js';
8
-
9
- const protoName = "rotate";
10
- const cssScope = scopePrefix(protoName);
11
- /**
12
- * {@linkcode Rotate} Make child elements rotate.
13
- *
14
- * @category wrapper
15
- */
16
- let Rotate = class Rotate extends GlobalStyle {
17
- render() {
18
- return html `<div part="root"><div part="slot" @mousemove="${this._handleRotate}">${htmlSlot()}</div><i @mouseleave="${this.reset}"></i></div>`;
19
- }
20
- reset() {
21
- this._root.style.removeProperty("transform");
22
- this._root.style.removeProperty("transition");
23
- }
24
- _handleRotate(e) {
25
- const { rotateX, rotateY } = this._computeOffset(e);
26
- this._root.style.setProperty("transform", `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`);
27
- this._root.style.setProperty("transition", "0s");
28
- }
29
- /**
30
- * Compute offset.
31
- * ```
32
- * `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`
33
- * ```
34
- * @param e Mouse move event.
35
- * @returns rotateX, rotateY
36
- */
37
- _computeOffset(e) {
38
- const { left, top, width, height } = this._root.getBoundingClientRect();
39
- const { clientX, clientY } = e;
40
- const offsetX = clientX - left;
41
- const offsetY = clientY - top;
42
- const rotateX = -(offsetY - height / 2) / height / 2;
43
- const rotateY = (offsetX - width / 2) / width / 2;
44
- return { rotateX, rotateY };
45
- }
46
- };
47
- __decorate([
48
- part("root")
49
- ], Rotate.prototype, "_root", void 0);
50
- Rotate = __decorate([
51
- godown(protoName),
52
- styles(css `:host{display:block;width:-moz-fit-content;width:fit-content;transition:all .5s ease-in-out;${cssScope}--padding:.75em;${cssScope}--offset:.5em}div{position:relative;transition:inherit;transition-property:transform}i{width:100%;height:100%;position:absolute;top:0;box-sizing:content-box;padding:var(${cssScope}--offset);margin:calc(-1 * var(${cssScope}--offset))}[part=slot]{z-index:2}`)
53
- ], Rotate);
54
- var Rotate$1 = Rotate;
55
-
56
- export { Rotate$1 as default };
1
+ import{__decorate as t}from"tslib";import{godown as o}from"@godown/element/decorators/godown.js";import{part as e}from"@godown/element/decorators/part.js";import{styles as r}from"@godown/element/decorators/styles.js";import{htmlSlot as i}from"@godown/element/directives/html-slot.js";import{css as s,html as n}from"lit";import{scopePrefix as a,GlobalStyle as l}from"../core/global-style.js";const d="rotate",m=a(d);let p=class Rotate extends l{render(){return n`<div part="root"><div part="slot" @mousemove="${this._handleRotate}">${i()}</div><i @mouseleave="${this.reset}"></i></div>`}reset(){this._root.style.removeProperty("transform"),this._root.style.removeProperty("transition")}_handleRotate(t){const{rotateX:o,rotateY:e}=this._computeOffset(t);this._root.style.setProperty("transform",`rotateX(${o}rad) rotateY(${e}rad)`),this._root.style.setProperty("transition","0s")}_computeOffset(t){const{left:o,top:e,width:r,height:i}=this._root.getBoundingClientRect(),{clientX:s,clientY:n}=t;return{rotateX:-(n-e-i/2)/i/2,rotateY:(s-o-r/2)/r/2}}};t([e("root")],p.prototype,"_root",void 0),p=t([o(d),r(s`:host{display:block;width:-moz-fit-content;width:fit-content;transition:all .5s ease-in-out;${m}--padding:.75em;${m}--offset:.5em}div{position:relative;transition:inherit;transition-property:transform}i{width:100%;height:100%;position:absolute;top:0;box-sizing:content-box;padding:var(${m}--offset);margin:calc(-1 * var(${m}--offset))}[part=slot]{z-index:2}`)],p);var f=p;export{f as default};
57
2
  //# sourceMappingURL=rotate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rotate.js","sources":["../src/components/rotate.ts"],"sourcesContent":null,"names":[],"mappings":";;;;;;;;AAQA,MAAM,SAAS,GAAG,QAAQ;AAC1B,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC;AAEvC;;;;AAIE;AAKF,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,WAAW,CAAA;IAIpB,MAAM,GAAA;AACd,QAAA,OAAO,IAAI,CAAA,CACsB,8CAAA,EAAA,IAAI,CAAC,aAAa,CAAA,EAAA,EAAK,QAAQ,EAAE,CAC9C,sBAAA,EAAA,IAAI,CAAC,KAAK,cACvB;;IAGT,KAAK,GAAA;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC;;AAGrC,IAAA,aAAa,CAAC,CAAa,EAAA;AACnC,QAAA,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;AACnD,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,OAAO,CAAA,aAAA,EAAgB,OAAO,CAAA,IAAA,CAAM,CAAC;QAC1F,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC;;AAGlD;;;;;;;AAOE;AACF,IAAA,cAAc,CAAC,CAAa,EAAA;AAI1B,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE;AACvE,QAAA,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC;AAC9B,QAAA,MAAM,OAAO,GAAG,OAAO,GAAG,IAAI;AAC9B,QAAA,MAAM,OAAO,GAAG,OAAO,GAAG,GAAG;AAE7B,QAAA,MAAM,OAAO,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC;AACpD,QAAA,MAAM,OAAO,GAAG,CAAC,OAAO,GAAG,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC;AACjD,QAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE;;CAE/B;AAzCY,UAAA,CAAA;IADT,IAAI,CAAC,MAAM;AACgB,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFxB,MAAM,GAAA,UAAA,CAAA;IAJX,MAAM,CAAC,SAAS,CAAA;AAChB,IAAA,MAAM,CACL,GAAG,CAAA,CAAA,4FAAA,EAAgG,QAAQ,CAAA,gBAAA,EAAmB,QAAQ,CAAA,yKAAA,EAA4K,QAAQ,CAAA,+BAAA,EAAkC,QAAQ,CAAA,iCAAA,CAAmC;AAEnY,CAAA,EAAA,MAAM,CA2CZ;AAEA,eAAe,MAAM;;;;"}
1
+ {"version":3,"file":"rotate.js","sources":["../src/components/rotate.ts"],"sourcesContent":null,"names":["protoName","cssScope","scopePrefix","Rotate","GlobalStyle","render","html","this","_handleRotate","htmlSlot","reset","_root","style","removeProperty","e","rotateX","rotateY","_computeOffset","setProperty","left","top","width","height","getBoundingClientRect","clientX","clientY","__decorate","part","prototype","godown","styles","css","Rotate$1"],"mappings":"uYAQA,MAAMA,EAAY,SACZC,EAAWC,EAAYF,GAW7B,IAAMG,EAAN,MAAMA,eAAeC,EAIT,MAAAC,GACR,OAAOC,CAAI,iDACsBC,KAAKC,kBAAkBC,4BACpCF,KAAKG,oBAI3B,KAAAA,GACEH,KAAKI,MAAMC,MAAMC,eAAe,aAChCN,KAAKI,MAAMC,MAAMC,eAAe,cAGxB,aAAAL,CAAcM,GACtB,MAAMC,QAAEA,EAAOC,QAAEA,GAAYT,KAAKU,eAAeH,GACjDP,KAAKI,MAAMC,MAAMM,YAAY,YAAa,WAAWH,iBAAuBC,SAC5ET,KAAKI,MAAMC,MAAMM,YAAY,aAAc,MAW7C,cAAAD,CAAeH,GAIb,MAAMK,KAAEA,EAAIC,IAAEA,EAAGC,MAAEA,EAAKC,OAAEA,GAAWf,KAAKI,MAAMY,yBAC1CC,QAAEA,EAAOC,QAAEA,GAAYX,EAM7B,MAAO,CAAEC,UAJOU,EAAUL,EAEEE,EAAS,GAAKA,EAAS,EAEjCN,SALFQ,EAAUL,EAICE,EAAQ,GAAKA,EAAQ,KAtCxCK,EAAA,CADTC,EAAK,SACsBxB,EAAAyB,UAAA,aAAA,GAFxBzB,EAAMuB,EAAA,CAJXG,EAAO7B,GACP8B,EACCC,CAAG,+FAAgG9B,oBAA2BA,6KAAoLA,mCAA0CA,uCAExVE,GA6CN,IAAA6B,EAAe7B"}
@@ -1,248 +1,2 @@
1
- import { __decorate } from 'tslib';
2
- import { godown } from '@godown/element/decorators/godown.js';
3
- import { styles } from '@godown/element/decorators/styles.js';
4
- import { htmlSlot } from '@godown/element/directives/html-slot.js';
5
- import { RouteTree } from '@godown/element/tools/route-tree.js';
6
- import { css } from 'lit';
7
- import { state, property } from 'lit/decorators.js';
8
- import { GlobalStyle } from '../core/global-style.js';
9
-
10
- var Router_1;
11
- const protoName = "router";
12
- /**
13
- * {@linkcode Router} has basic routing control.
14
- *
15
- * To switch routes, use `router-link component`.
16
- *
17
- * It has two methods to collect routes.
18
- *
19
- * 1. From field `routes`, an array, each elements require "path" and "component".
20
- * 2. From child elements, which have the slot attribute for matching routes.
21
- *
22
- * If only the method 1 is used, set `type` to `"field"`.
23
- *
24
- * If only the method 2 is used, set `type` to `"slotted"`.
25
- *
26
- * `type` defaults to `"united"`, which will try method 1, then method 2.
27
- *
28
- * If no routes are matched, the default value (no named slot) will be rendered.
29
- *
30
- * @slot - Display slot when there is no match.
31
- * @slot * - Matching slot will be displayed.
32
- * @category navigation
33
- */
34
- let Router = Router_1 = class Router extends GlobalStyle {
35
- constructor() {
36
- super(...arguments);
37
- this.__fieldRouteTree = new RouteTree();
38
- this.__slottedRouteTree = new RouteTree();
39
- this.__cacheRecord = new Map();
40
- /**
41
- * Render result.
42
- */
43
- this.component = null;
44
- /**
45
- * Dynamic parameters record.
46
- */
47
- this.params = {};
48
- /**
49
- * Current pathname (equals to location.pathname).
50
- */
51
- this.pathname = "";
52
- /**
53
- * Path prefix.
54
- */
55
- this.baseURL = "";
56
- /**
57
- * Rendered content when there is no match.
58
- */
59
- this.default = htmlSlot();
60
- /**
61
- * The type of routing sources.
62
- *
63
- * If field, it won't collect the slot attribute of the child elements.
64
- *
65
- * This property should not be changed after the rendering is complete.
66
- */
67
- this.type = "united";
68
- /**
69
- * Cache accessed records.
70
- *
71
- * Emptied at each re-collection.
72
- */
73
- this.cache = false;
74
- /**
75
- * Callback function when the route changes.
76
- */
77
- this.routeChangeCallback = null;
78
- this.handlePopstate = this.events.add(window, "popstate", () => {
79
- this.pathname = location.pathname;
80
- });
81
- }
82
- set routes(value) {
83
- this.__routes = value;
84
- this.collectFieldRoutes(value);
85
- }
86
- get routes() {
87
- return this.__routes;
88
- }
89
- clear() {
90
- this.__cacheRecord.clear();
91
- }
92
- render() {
93
- this.params = {};
94
- if (this.cache) {
95
- const cached = this.__cacheRecord.get(this.pathname);
96
- if (cached) {
97
- Object.assign(this, cached);
98
- return this.component;
99
- }
100
- }
101
- switch (this.type) {
102
- case "field":
103
- this.component = this.fieldComponent();
104
- break;
105
- case "slotted":
106
- this.component = this.slottedComponent();
107
- break;
108
- default:
109
- this.component = this.fieldComponent() ?? this.slottedComponent();
110
- }
111
- return this.component ?? this.default ?? null;
112
- }
113
- connectedCallback() {
114
- super.connectedCallback();
115
- Router_1.routerInstances.add(this);
116
- this.pathname ??= location.pathname;
117
- if (this.type !== "field") {
118
- const mutationObserver = new MutationObserver(this.collectSlottedRoutes);
119
- mutationObserver.observe(this, {
120
- attributeFilter: ["slot"],
121
- attributes: true,
122
- subtree: true,
123
- });
124
- this.collectSlottedRoutes();
125
- }
126
- }
127
- disconnectedCallback() {
128
- super.disconnectedCallback();
129
- Router_1.routerInstances.delete(this);
130
- }
131
- useRouter() {
132
- return {
133
- pathname: this.pathname,
134
- params: this.params,
135
- path: this.path,
136
- component: this.component,
137
- };
138
- }
139
- updated(changedProperties) {
140
- const shouldDispatch = changedProperties.has("pathname") || changedProperties.has("path");
141
- if (shouldDispatch) {
142
- const ur = this.useRouter();
143
- const noRecord = !this.__cacheRecord.has(this.pathname);
144
- if (noRecord) {
145
- this.__cacheRecord.set(this.pathname, ur);
146
- }
147
- this.routeChangeCallback?.(ur, noRecord);
148
- this.dispatchEvent(new CustomEvent("change", { detail: ur }));
149
- }
150
- }
151
- /**
152
- * Get component from {@linkcode routes} by query.
153
- */
154
- fieldComponent(query) {
155
- query ||= this.__fieldRouteTree.search(RouteTree.split(this.pathname)).pattern || null;
156
- this.path = query;
157
- if (!query) {
158
- return null;
159
- }
160
- this.params = this.parseParams(this.path, this.pathname);
161
- const route = this.routes.find((r) => r.path === query);
162
- if (!route) {
163
- return null;
164
- }
165
- return route.component;
166
- }
167
- /**
168
- * Get component from slotted elements by query.
169
- */
170
- slottedComponent(usedRouteTemplate) {
171
- const slottedPaths = this._slottedNames;
172
- usedRouteTemplate ||= this.__slottedRouteTree.search(RouteTree.split(this.pathname)).pattern || null;
173
- this.path = usedRouteTemplate;
174
- if (!usedRouteTemplate) {
175
- return null;
176
- }
177
- this.path = slottedPaths.find((s) => s === usedRouteTemplate);
178
- if (!this.path) {
179
- return null;
180
- }
181
- this.params = this.parseParams(usedRouteTemplate, this.pathname);
182
- return htmlSlot(this.path);
183
- }
184
- /**
185
- * Reset the route tree, clear cache, collect routes from child elements.
186
- */
187
- collectSlottedRoutes() {
188
- this.__slottedRouteTree = new RouteTree();
189
- this.clear();
190
- this._slottedNames.forEach(slotName => {
191
- this.__slottedRouteTree.insert(slotName);
192
- });
193
- }
194
- /**
195
- * Reset the route tree, clear cache, collect routes from value.
196
- */
197
- collectFieldRoutes(value) {
198
- this.__fieldRouteTree = new RouteTree();
199
- this.clear();
200
- value.forEach(({ path }) => {
201
- this.__fieldRouteTree.insert(path);
202
- });
203
- }
204
- parseParams(routeTemplate, path = this.pathname) {
205
- return RouteTree.parseParams(path, routeTemplate);
206
- }
207
- static updateAll() {
208
- this.routerInstances.forEach((i) => {
209
- i.handlePopstate();
210
- });
211
- }
212
- };
213
- Router.routerInstances = new Set();
214
- __decorate([
215
- state()
216
- ], Router.prototype, "component", void 0);
217
- __decorate([
218
- state()
219
- ], Router.prototype, "params", void 0);
220
- __decorate([
221
- state()
222
- ], Router.prototype, "path", void 0);
223
- __decorate([
224
- property()
225
- ], Router.prototype, "pathname", void 0);
226
- __decorate([
227
- property()
228
- ], Router.prototype, "baseURL", void 0);
229
- __decorate([
230
- state()
231
- ], Router.prototype, "default", void 0);
232
- __decorate([
233
- property()
234
- ], Router.prototype, "type", void 0);
235
- __decorate([
236
- property({ type: Boolean })
237
- ], Router.prototype, "cache", void 0);
238
- __decorate([
239
- state()
240
- ], Router.prototype, "routes", null);
241
- Router = Router_1 = __decorate([
242
- godown(protoName),
243
- styles(css `:host{display:contents}`)
244
- ], Router);
245
- var Router$1 = Router;
246
-
247
- export { Router$1 as default };
1
+ import{__decorate as t}from"tslib";import{godown as e}from"@godown/element/decorators/godown.js";import{styles as s}from"@godown/element/decorators/styles.js";import{htmlSlot as o}from"@godown/element/directives/html-slot.js";import{RouteTree as a}from"@godown/element/tools/route-tree.js";import{css as i}from"lit";import{state as h,property as r}from"lit/decorators.js";import{GlobalStyle as n}from"../core/global-style.js";var l;let p=l=class Router extends n{constructor(){super(...arguments),this.__fieldRouteTree=new a,this.__slottedRouteTree=new a,this.__cacheRecord=new Map,this.component=null,this.params={},this.pathname="",this.baseURL="",this.default=o(),this.type="united",this.cache=!1,this.routeChangeCallback=null,this.handlePopstate=this.events.add(window,"popstate",(()=>{this.pathname=location.pathname}))}set routes(t){this.__routes=t,this.collectFieldRoutes(t)}get routes(){return this.__routes}clear(){this.__cacheRecord.clear()}render(){if(this.params={},this.cache){const t=this.__cacheRecord.get(this.pathname);if(t)return Object.assign(this,t),this.component}switch(this.type){case"field":this.component=this.fieldComponent();break;case"slotted":this.component=this.slottedComponent();break;default:this.component=this.fieldComponent()??this.slottedComponent()}return this.component??this.default??null}connectedCallback(){if(super.connectedCallback(),l.routerInstances.add(this),this.pathname??=location.pathname,"field"!==this.type){new MutationObserver(this.collectSlottedRoutes).observe(this,{attributeFilter:["slot"],attributes:!0,subtree:!0}),this.collectSlottedRoutes()}}disconnectedCallback(){super.disconnectedCallback(),l.routerInstances.delete(this)}useRouter(){return{pathname:this.pathname,params:this.params,path:this.path,component:this.component}}updated(t){if(t.has("pathname")||t.has("path")){const t=this.useRouter(),e=!this.__cacheRecord.has(this.pathname);e&&this.__cacheRecord.set(this.pathname,t),this.routeChangeCallback?.(t,e),this.dispatchEvent(new CustomEvent("change",{detail:t}))}}fieldComponent(t){if(t||=this.__fieldRouteTree.search(a.split(this.pathname))?.pattern||null,this.path=t,!t)return null;this.params=this.parseParams(this.path,this.pathname);const e=this.routes.find((e=>e.path===t));return e?e.component:null}slottedComponent(t){const e=this._slottedNames;return t||=this.__slottedRouteTree.search(a.split(this.pathname))?.pattern||null,this.path=t,t?(this.path=e.find((e=>e===t)),this.path?(this.params=this.parseParams(t,this.pathname),o(this.path)):null):null}collectSlottedRoutes(){this.__slottedRouteTree=new a,this.clear(),this._slottedNames.forEach((t=>{this.__slottedRouteTree.insert(t)}))}collectFieldRoutes(t){this.__fieldRouteTree=new a,this.clear(),t.forEach((({path:t})=>{this.__fieldRouteTree.insert(t)}))}parseParams(t,e=this.pathname){return a.parseParams(e,t)}static updateAll(){this.routerInstances.forEach((t=>{t.handlePopstate()}))}};p.routerInstances=new Set,t([h()],p.prototype,"component",void 0),t([h()],p.prototype,"params",void 0),t([h()],p.prototype,"path",void 0),t([r()],p.prototype,"pathname",void 0),t([r()],p.prototype,"baseURL",void 0),t([h()],p.prototype,"default",void 0),t([r()],p.prototype,"type",void 0),t([r({type:Boolean})],p.prototype,"cache",void 0),t([h()],p.prototype,"routes",null),p=l=t([e("router"),s(i`:host{display:contents}`)],p);var c=p;export{c as default};
248
2
  //# sourceMappingURL=router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sources":["../src/components/router.ts"],"sourcesContent":null,"names":[],"mappings":";;;;;;;;;;AASA,MAAM,SAAS,GAAG,QAAQ;AAE1B;;;;;;;;;;;;;;;;;;;;;AAqBE;AAGF,IAAM,MAAM,GAAA,QAAA,GAAZ,MAAM,MAAO,SAAQ,WAAW,CAAA;AAAhC,IAAA,WAAA,GAAA;;AAGU,QAAA,IAAA,CAAA,gBAAgB,GAAc,IAAI,SAAS,EAAE;AAC7C,QAAA,IAAA,CAAA,kBAAkB,GAAc,IAAI,SAAS,EAAE;AAC/C,QAAA,IAAA,CAAA,aAAa,GAAG,IAAI,GAAG,EAA6C;AAS5E;;AAEE;QAEF,IAAS,CAAA,SAAA,GAA6B,IAAI;AAE1C;;AAEE;QAEF,IAAM,CAAA,MAAA,GAA2B,EAAE;AAQnC;;AAEE;QAEF,IAAQ,CAAA,QAAA,GAAG,EAAE;AAEb;;AAEE;QAEF,IAAO,CAAA,OAAA,GAAG,EAAE;AAEZ;;AAEE;QAEF,IAAO,CAAA,OAAA,GAAmB,QAAQ,EAAE;AAEpC;;;;;;AAME;QAEF,IAAI,CAAA,IAAA,GAAmC,QAAQ;AAE/C;;;;AAIE;QAEF,IAAK,CAAA,KAAA,GAAG,KAAK;AA4Eb;;AAEE;QACF,IAA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,EAAA,QAAA,EAAA,KAAA,CAAA,CAAA;AAMnC,UAAA,CAAA;AADC,IAAA,KAAK;AACM,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAMZ,UAAA,CAAA;AADC,IAAA,QAAQ;AACI,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA;AAMb,UAAA,CAAA;AADC,IAAA,QAAQ;AACG,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAMZ,UAAA,CAAA;AADC,IAAA,KAAK;AAC8B,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAUpC,UAAA,CAAA;AADC,IAAA,QAAQ;AACsC,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAQ/C,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;AACd,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAGb,UAAA,CAAA;AADC,IAAA,KAAK;AAIN,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,QAAA,EAAA,IAAA,CAAA;AAxEI,MAAM,GAAA,QAAA,GAAA,UAAA,CAAA;IAFX,MAAM,CAAC,SAAS,CAAA;AAChB,IAAA,MAAM,CAAC,GAAG,CAAA,CAAA,uBAAA,CAAyB;AAC9B,CAAA,EAAA,MAAM,CA+OZ;AAEA,eAAe,MAAM;;;;"}
1
+ {"version":3,"file":"router.js","sources":["../src/components/router.ts"],"sourcesContent":null,"names":["Router","Router_1","GlobalStyle","constructor","this","__fieldRouteTree","RouteTree","__slottedRouteTree","__cacheRecord","Map","component","params","pathname","baseURL","default","htmlSlot","type","cache","routeChangeCallback","handlePopstate","events","add","window","location","routes","value","__routes","collectFieldRoutes","clear","render","cached","get","Object","assign","fieldComponent","slottedComponent","connectedCallback","super","routerInstances","MutationObserver","collectSlottedRoutes","observe","attributeFilter","attributes","subtree","disconnectedCallback","delete","useRouter","path","updated","changedProperties","has","ur","noRecord","set","dispatchEvent","CustomEvent","detail","query","search","split","pattern","parseParams","route","find","r","usedRouteTemplate","slottedPaths","_slottedNames","s","forEach","slotName","insert","routeTemplate","updateAll","i","Set","__decorate","state","prototype","property","Boolean","godown","styles","css","Router$1"],"mappings":"gbAmCA,IAAMA,EAAMC,EAAZ,MAAMD,eAAeE,EAArB,WAAAC,uBAGUC,KAAAC,iBAA8B,IAAIC,EAClCF,KAAAG,mBAAgC,IAAID,EACpCF,KAAAI,cAAgB,IAAIC,IAa5BL,KAASM,UAA6B,KAMtCN,KAAMO,OAA2B,CAAE,EAYnCP,KAAQQ,SAAG,GAMXR,KAAOS,QAAG,GAMVT,KAAOU,QAAmBC,IAU1BX,KAAIY,KAAmC,SAQvCZ,KAAKa,OAAG,EA+ERb,KAAmBc,oBAKU,KAsF7Bd,KAAAe,eAAiBf,KAAKgB,OAAOC,IAAIC,OAAQ,YAAY,KACnDlB,KAAKQ,SAAWW,SAASX,QAAQ,IAxKnC,UAAIY,CAAOC,GACTrB,KAAKsB,SAAWD,EAChBrB,KAAKuB,mBAAmBF,GAG1B,UAAID,GAIF,OAAOpB,KAAKsB,SAGd,KAAAE,GACExB,KAAKI,cAAcoB,QAGX,MAAAC,GAER,GADAzB,KAAKO,OAAS,CAAE,EACZP,KAAKa,MAAO,CACd,MAAMa,EAAS1B,KAAKI,cAAcuB,IAAI3B,KAAKQ,UAC3C,GAAIkB,EAEF,OADAE,OAAOC,OAAO7B,KAAM0B,GACb1B,KAAKM,UAGhB,OAAQN,KAAKY,MACX,IAAK,QACHZ,KAAKM,UAAYN,KAAK8B,iBACtB,MACF,IAAK,UACH9B,KAAKM,UAAYN,KAAK+B,mBACtB,MACF,QACE/B,KAAKM,UAAYN,KAAK8B,kBAAoB9B,KAAK+B,mBA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}
@@ -1,218 +1,2 @@
1
- import { __decorate } from 'tslib';
2
- import { godown } from '@godown/element/decorators/godown.js';
3
- import { part } from '@godown/element/decorators/part.js';
4
- import { styles } from '@godown/element/decorators/styles.js';
5
- import { attr } from '@godown/element/directives/attr.js';
6
- import { htmlSlot } from '@godown/element/directives/html-slot.js';
7
- import svgCaretDown from '@godown/f7-icon/icons/chevron-down.js';
8
- import { css, html, nothing } from 'lit';
9
- import { property, state } from 'lit/decorators.js';
10
- import { ifDefined } from 'lit/directives/if-defined.js';
11
- import Input from './input.js';
12
-
13
- function contain(a, b) {
14
- return a && b && a.toLowerCase().includes(b.toLowerCase());
15
- }
16
- function betweenAt(i, s, c) {
17
- const start = s.slice(0, i).lastIndexOf(c) + 1 || 0;
18
- const end = s.indexOf(c, i) || s.length;
19
- return s.slice(start, end);
20
- }
21
- function updateChecked(element, operation) {
22
- if (element) {
23
- const name = "checked";
24
- if (operation) {
25
- element.setAttribute(name, "");
26
- }
27
- else {
28
- element.removeAttribute(name);
29
- }
30
- }
31
- }
32
- const protoName = "select";
33
- /**
34
- * {@linkcode Select} is similar to `<select>`.
35
- *
36
- * Elements with the value attribute/property can be used as options.
37
- *
38
- * The checked attribute will be added to the selected element.
39
- *
40
- * Multi-selected state looks the same as single-selected.
41
- *
42
- * Input will filter the element.
43
- *
44
- * @slot - Options.
45
- * @category input
46
- */
47
- let Select = class Select extends Input {
48
- constructor() {
49
- super(...arguments);
50
- this.multiple = false;
51
- this.visible = false;
52
- this.autoDirection = "bottom";
53
- this._store = [];
54
- }
55
- render() {
56
- return html `<div part="root" ${attr({
57
- ...this.observedRecord,
58
- direction: this.direction || this.autoDirection,
59
- })} class="input-field">${[
60
- this._renderPrefix(),
61
- html `<input part="input" dir="${ifDefined(this.dir)}" id="${this.makeId}" .value="${this.text}" type="${this.type}" placeholder="${this.placeholder || nothing}" ?autofocus="${this.autofocus}" autocapitalize="${this.autocapitalize || nothing}" autocomplete="${this.autocomplete || nothing}" ?disabled="${this.disabled}" @focus="${this._handleFocus}" @input="${this._handleInput}">`,
62
- html `<label for="${this.makeId}" part="suffix"><i part="icon">${svgCaretDown()}</i></label>`,
63
- html `<label for="${this.makeId}" part="content">${htmlSlot()}</label>`,
64
- ]}</div>`;
65
- }
66
- _handleFocus() {
67
- if (!this.direction) {
68
- const { top, bottom } = this.getBoundingClientRect();
69
- if (window.innerHeight - bottom < this._content.clientHeight && top > this._content.clientHeight) {
70
- this.autoDirection = "top";
71
- }
72
- else {
73
- this.autoDirection = "bottom";
74
- }
75
- }
76
- this.visible = true;
77
- }
78
- firstUpdated() {
79
- this.events.add(this._content, "click", (e) => {
80
- e.preventDefault();
81
- e.stopPropagation();
82
- const { target } = e;
83
- const value = this.optionValue(target);
84
- if (value) {
85
- const operation = this.select(value, target.textContent);
86
- if (!this.multiple) {
87
- updateChecked(this.lastChecked, 0);
88
- }
89
- updateChecked(target, operation);
90
- this.lastChecked = target;
91
- }
92
- this._input.focus();
93
- });
94
- this.events.add(document, "click", (e) => {
95
- // e.preventDefault();
96
- e.stopPropagation();
97
- const composed1 = e.composedPath()[0];
98
- if (composed1 && !this.shadowRoot.contains(composed1)) {
99
- this.blur();
100
- }
101
- });
102
- }
103
- _connectedInit() {
104
- if (!this.value) {
105
- const checked = [...this.querySelectorAll("[checked]")];
106
- const list = this.multiple
107
- ? checked
108
- : checked.length
109
- ? [this.lastChecked = checked[0]]
110
- : [];
111
- list.forEach((element) => {
112
- const operation = this.select(this.optionValue(element), element.textContent);
113
- updateChecked(element, operation);
114
- });
115
- this.default = this.value;
116
- this.defaultText = this.text;
117
- this.defaultChecked = checked;
118
- }
119
- if (!this.text) {
120
- this.text = "";
121
- }
122
- }
123
- reset() {
124
- this.value = this.default;
125
- this.text = this.defaultText;
126
- this.querySelectorAll("[checked]").forEach(element => updateChecked(element, 0));
127
- this.defaultChecked.forEach(element => updateChecked(element, 1));
128
- }
129
- select(value, text) {
130
- text ||= value;
131
- let operation = 0;
132
- if (this.multiple) {
133
- const i = this._store.findIndex(s => s.value === value);
134
- if (i > -1) {
135
- this._store.splice(i, 1);
136
- }
137
- else {
138
- this._store.push({ value, text });
139
- operation = 1;
140
- }
141
- this.value = this._store.map(s => s.value);
142
- this.text = this._store.map(s => s.text).join(", ");
143
- }
144
- else {
145
- if (this.value === value) {
146
- this.value = "";
147
- this.text = "";
148
- }
149
- else {
150
- this.value = value;
151
- this.text = text;
152
- operation = 1;
153
- }
154
- }
155
- this.dispatchEvent(new CustomEvent("change", { detail: this.namevalue() }));
156
- this.filter();
157
- return operation;
158
- }
159
- filter(query) {
160
- query = query?.trim();
161
- [...this.children].forEach((element) => {
162
- this.filterCallback(element, !query
163
- || contain(this.optionValue(element), query)
164
- || contain(element.textContent, query), query);
165
- });
166
- }
167
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
168
- filterCallback(element, match, query) {
169
- element.style.display = match ? "" : "none";
170
- }
171
- _handleInput(e) {
172
- e.stopPropagation();
173
- if (this.compositing) {
174
- return;
175
- }
176
- const s = this._input.value;
177
- this.filter(this.multiple ? betweenAt(this._input.selectionStart, s, ",") : s);
178
- this.dispatchEvent(new CustomEvent("input", { detail: this.namevalue() }));
179
- }
180
- focus(options) {
181
- this._input.focus(options);
182
- this.visible = true;
183
- }
184
- blur() {
185
- this._input.blur();
186
- this.visible = false;
187
- super.blur();
188
- }
189
- optionValue(option) {
190
- return option.value || option.getAttribute("value") || "";
191
- }
192
- };
193
- __decorate([
194
- property()
195
- ], Select.prototype, "text", void 0);
196
- __decorate([
197
- part("content")
198
- ], Select.prototype, "_content", void 0);
199
- __decorate([
200
- property()
201
- ], Select.prototype, "direction", void 0);
202
- __decorate([
203
- property({ type: Boolean })
204
- ], Select.prototype, "multiple", void 0);
205
- __decorate([
206
- property({ type: Boolean })
207
- ], Select.prototype, "visible", void 0);
208
- __decorate([
209
- state()
210
- ], Select.prototype, "autoDirection", void 0);
211
- Select = __decorate([
212
- godown(protoName),
213
- styles(css `[part=input]{text-overflow:ellipsis}[part=content]{position:absolute;width:100%;visibility:hidden}[direction=bottom] [part=content]{top:100%}[direction=top] [part=content]{bottom:100%}[visible] [part=content]{visibility:visible}`)
214
- ], Select);
215
- var Select$1 = Select;
216
-
217
- export { Select$1 as default };
1
+ import{__decorate as t}from"tslib";import{godown as e}from"@godown/element/decorators/godown.js";import{part as i}from"@godown/element/decorators/part.js";import{styles as o}from"@godown/element/decorators/styles.js";import{attr as s}from"@godown/element/directives/attr.js";import{htmlSlot as n}from"@godown/element/directives/html-slot.js";import l from"@godown/f7-icon/icons/chevron-down.js";import{css as r,html as h,nothing as a}from"lit";import{property as c,state as u}from"lit/decorators.js";import{ifDefined as d}from"lit/directives/if-defined.js";import p from"./input.js";function f(t,e){return t&&e&&t.toLowerCase().includes(e.toLowerCase())}function m(t,e){if(t){const i="checked";e?t.setAttribute(i,""):t.removeAttribute(i)}}let v=class Select extends p{constructor(){super(...arguments),this.multiple=!1,this.visible=!1,this.autoDirection="bottom",this._store=[]}render(){return h`<div part="root" ${s({...this.observedRecord,direction:this.direction||this.autoDirection})} class="input-field">${[this._renderPrefix(),h`<input part="input" dir="${d(this.dir)}" id="${this.makeId}" .value="${this.text}" type="${this.type}" placeholder="${this.placeholder||a}" ?autofocus="${this.autofocus}" autocapitalize="${this.autocapitalize||a}" autocomplete="${this.autocomplete||a}" ?disabled="${this.disabled}" @focus="${this._handleFocus}" @input="${this._handleInput}">`,h`<label for="${this.makeId}" part="suffix"><i part="icon">${l()}</i></label>`,h`<label for="${this.makeId}" part="content">${n()}</label>`]}</div>`}_handleFocus(){if(!this.direction){const{top:t,bottom:e}=this.getBoundingClientRect();window.innerHeight-e<this._content.clientHeight&&t>this._content.clientHeight?this.autoDirection="top":this.autoDirection="bottom"}this.visible=!0}firstUpdated(){this.events.add(this._content,"click",(t=>{t.preventDefault(),t.stopPropagation();const{target:e}=t,i=this.optionValue(e);if(i){const t=this.select(i,e.textContent);this.multiple||m(this.lastChecked,0),m(e,t),this.lastChecked=e}this._input.focus()})),this.events.add(document,"click",(t=>{t.stopPropagation();const e=t.composedPath()[0];e&&!this.shadowRoot.contains(e)&&this.blur()}))}_connectedInit(){if(!this.value){const t=[...this.querySelectorAll("[checked]")];(this.multiple?t:t.length?[this.lastChecked=t[0]]:[]).forEach((t=>{m(t,this.select(this.optionValue(t),t.textContent))})),this.default=this.value,this.defaultText=this.text,this.defaultChecked=t}this.text||(this.text="")}reset(){this.value=this.default,this.text=this.defaultText,this.querySelectorAll("[checked]").forEach((t=>m(t,0))),this.defaultChecked.forEach((t=>m(t,1)))}select(t,e){e||=t;let i=0;if(this.multiple){const o=this._store.findIndex((e=>e.value===t));o>-1?this._store.splice(o,1):(this._store.push({value:t,text:e}),i=1),this.value=this._store.map((t=>t.value)),this.text=this._store.map((t=>t.text)).join(", ")}else this.value===t?(this.value="",this.text=""):(this.value=t,this.text=e,i=1);return this.dispatchEvent(new CustomEvent("change",{detail:this.namevalue()})),this.filter(),i}filter(t){t=t?.trim(),[...this.children].forEach((e=>{this.filterCallback(e,!t||f(this.optionValue(e),t)||f(e.textContent,t),t)}))}filterCallback(t,e,i){t.style.display=e?"":"none"}_handleInput(t){if(t.stopPropagation(),this.compositing)return;const e=this._input.value;this.filter(this.multiple?function(t,e,i){const o=e.slice(0,t).lastIndexOf(i)+1||0,s=e.indexOf(i,t)||e.length;return e.slice(o,s)}(this._input.selectionStart,e,","):e),this.dispatchEvent(new CustomEvent("input",{detail:this.namevalue()}))}focus(t){this._input.focus(t),this.visible=!0}blur(){this._input.blur(),this.visible=!1,super.blur()}optionValue(t){return t.value||t.getAttribute("value")||""}};t([c()],v.prototype,"text",void 0),t([i("content")],v.prototype,"_content",void 0),t([c()],v.prototype,"direction",void 0),t([c({type:Boolean})],v.prototype,"multiple",void 0),t([c({type:Boolean})],v.prototype,"visible",void 0),t([u()],v.prototype,"autoDirection",void 0),v=t([e("select"),o(r`[part=input]{text-overflow:ellipsis}[part=content]{position:absolute;width:100%;visibility:hidden}[direction=bottom] [part=content]{top:100%}[direction=top] [part=content]{bottom:100%}[visible] [part=content]{visibility:visible}`)],v);var b=v;export{b as default};
218
2
  //# sourceMappingURL=select.js.map