tinkiet 0.11.4 → 0.11.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/drawer/index.js CHANGED
@@ -27,7 +27,7 @@ var external_lit_ = __webpack_require__(2927);
27
27
  // EXTERNAL MODULE: external "lit/decorators.js"
28
28
  var decorators_js_ = __webpack_require__(8899);
29
29
  ;// ./tinkiet/drawer/drawer.scss
30
- /* harmony default export */ const drawer = ("*{-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-tap-highlight-color:rgba(0,0,0,0);box-sizing:border-box}:host{display:block;height:100%;width:100%;position:relative;overflow:hidden;background-color:hsl(var(--surface))}.drawer{display:grid;grid-template-columns:var(--drawer-width, 256px) 10px;grid-template-rows:auto 1fr auto;grid-template-areas:\"header swipe\" \"content swipe\" \"footer swipe\";position:absolute;top:0;bottom:0;transform:translateX(calc(-100% + 10px));transition:transform cubic-bezier(0.4, 0, 0.2, 1) var(--transition-duration-medium, 180ms);will-change:transform;touch-action:pan-y;z-index:var(--drawer-z-index, 200);background-color:hsl(var(--surface))}.drawer .drawer-header{grid-area:header}.drawer .drawer-content{grid-area:content;overflow:auto}.drawer .drawer-footer{grid-area:footer}.drawer .drawer-swipe{grid-area:swipe;background-color:rgba(0,0,0,0)}:host([right]) .drawer{right:0;transform:translateX(calc(100% + 10px))}.overlay{position:absolute;top:0;left:0;right:0;bottom:0;z-index:var(--drawer-overlay-z-index, 200);background-color:rgba(0,0,0,.5);display:none}.container{transition:padding cubic-bezier(0.4, 0, 0.2, 1) var(--transition-duration-slow, 250ms);overflow:auto;height:100%}:host([open]) .drawer{transform:none}:host([open]) .container{padding-left:var(--drawer-width, 256px)}:host([open][over]) .drawer{background-color:hsl(var(--surface-container-low));box-shadow:0px 1px 2px 0px rgba(0, 0, 0, 0.3), 0px 1px 3px 1px rgba(0, 0, 0, 0.15)}:host([open][over]) .container{padding-left:0}:host([open][over]) .overlay{display:block}@media(max-width: var(--drawer-trigger-width, 400px)){:host([open]) .container{padding-left:0}:host([open]) .overlay{display:block}}");
30
+ /* harmony default export */ const drawer = ("*{-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-tap-highlight-color:rgba(0,0,0,0);box-sizing:border-box}:host{display:block;height:100%;width:100%;position:relative;overflow:hidden;background-color:hsl(var(--surface))}.drawer{display:grid;grid-template-columns:var(--drawer-width, 256px) 10px;grid-template-rows:auto 1fr auto;grid-template-areas:\"header swipe\" \"content swipe\" \"footer swipe\";position:absolute;top:0;bottom:0;transform:translateX(calc(-100% + 10px));transition:transform cubic-bezier(0.4, 0, 0.2, 1) var(--transition-duration-medium, 180ms);will-change:transform;touch-action:pan-y;z-index:var(--drawer-z-index, 200);background-color:hsl(var(--surface))}.drawer .drawer-header{grid-area:header}.drawer .drawer-content{grid-area:content;overflow:auto;position:relative;transition:opacity var(--transition-duration-medium, 180ms) ease}.drawer .drawer-content::before,.drawer .drawer-content::after{content:\"\";position:sticky;display:block;height:14px;pointer-events:none;opacity:0;transition:opacity var(--transition-duration-medium, 180ms) ease;left:0;right:0;width:100%;z-index:1}.drawer .drawer-content::before{top:0;margin-top:-14px;background:linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0))}.drawer .drawer-content::after{bottom:0;margin-bottom:-14px;background:linear-gradient(0deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0))}.drawer .drawer-content.has-top-shadow::before{opacity:1}.drawer .drawer-content.has-bottom-shadow::after{opacity:1}.drawer .drawer-footer{grid-area:footer}.drawer .drawer-swipe{grid-area:swipe;background-color:rgba(0,0,0,0)}:host([right]) .drawer{right:0;transform:translateX(calc(100% + 10px))}.overlay{position:absolute;top:0;left:0;right:0;bottom:0;z-index:var(--drawer-overlay-z-index, 200);background-color:rgba(0,0,0,.5);display:none}.container{transition:padding cubic-bezier(0.4, 0, 0.2, 1) var(--transition-duration-slow, 250ms);overflow:auto;height:100%}:host([open]) .drawer{transform:none}:host([open]) .container{padding-left:var(--drawer-width, 256px)}:host([open][over]) .drawer{background-color:hsl(var(--surface-container-low));box-shadow:0px 1px 2px 0px rgba(0, 0, 0, 0.3), 0px 1px 3px 1px rgba(0, 0, 0, 0.15)}:host([open][over]) .container{padding-left:0}:host([open][over]) .overlay{display:block}@media(max-width: var(--drawer-trigger-width, 400px)){:host([open]) .container{padding-left:0}:host([open]) .overlay{display:block}}");
31
31
  ;// ./tinkiet/drawer/drawer.ts
32
32
  var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
33
33
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -38,46 +38,47 @@ var __decorate = (undefined && undefined.__decorate) || function (decorators, ta
38
38
 
39
39
 
40
40
 
41
-
42
41
  let TkDrawer = class TkDrawer extends external_lit_.LitElement {
43
42
  constructor() {
44
43
  super(...arguments);
45
- this._open = false;
44
+ this.open = false;
46
45
  this.over = false;
47
46
  this.right = false;
48
47
  this.swipeable = false;
48
+ this.contentScrolled = false;
49
+ this.contentHasBottomShadow = false;
49
50
  this.overMediaQueryListener = (e) => {
50
51
  e.matches ? this.setAttribute("over", "") : this.removeAttribute("over");
51
52
  };
53
+ this.handleOverlayClick = () => {
54
+ this.hide();
55
+ };
56
+ this.handleContentScroll = () => {
57
+ if (!this.$content)
58
+ return;
59
+ const { scrollTop, scrollHeight, clientHeight } = this.$content;
60
+ this.contentScrolled = scrollTop > 0;
61
+ const atBottom = Math.ceil(scrollTop + clientHeight) >= scrollHeight;
62
+ this.contentHasBottomShadow = !atBottom && scrollHeight > clientHeight;
63
+ };
52
64
  this.swipeX = 0;
53
65
  this.swipeY = 0;
54
66
  this.isHorizontalSwipe = false;
55
67
  }
56
- set open(value) {
57
- if (value === this._open)
58
- return;
59
- const oldValue = this._open;
60
- this._open = value;
61
- this.requestUpdate("open", oldValue);
62
- if (this._open)
63
- this.dispatchEvent(new Event("did-show"));
64
- if (!this._open)
65
- this.dispatchEvent(new Event("did-close"));
66
- }
67
- get open() {
68
- return this._open;
69
- }
70
68
  render() {
71
69
  return (0,external_lit_.html) `
72
70
  <div class="container">
73
71
  <slot name="drawer-container"></slot>
74
72
  </div>
75
- <div class="overlay" @click=${() => (this.open = false)}></div>
73
+ <div class="overlay" @click=${this.handleOverlayClick}></div>
76
74
  <div class="drawer" @touchstart=${this.touchStart} @touchmove=${this.touchMove} @touchend=${this.touchEnd}>
77
75
  <div class="drawer-header">
78
76
  <slot name="drawer-header"></slot>
79
77
  </div>
80
- <div class="drawer-content">
78
+ <div
79
+ class="drawer-content ${this.contentScrolled ? "has-top-shadow" : ""} ${this.contentHasBottomShadow ? "has-bottom-shadow" : ""}"
80
+ @scroll=${this.handleContentScroll}
81
+ >
81
82
  <slot name="drawer-content"></slot>
82
83
  </div>
83
84
  <div class="drawer-footer">
@@ -88,17 +89,31 @@ let TkDrawer = class TkDrawer extends external_lit_.LitElement {
88
89
 
89
90
  `;
90
91
  }
92
+ firstUpdated() {
93
+ if (this.overQuery)
94
+ this.overMediaQuery();
95
+ if (this.openQuery && window.matchMedia(this.openQuery).matches)
96
+ this.show();
97
+ this.handleContentScroll();
98
+ }
91
99
  updated(props) {
92
- if (props.has("overQuery"))
100
+ super.updated(props);
101
+ if (props.has("overQuery") && this.overQuery)
93
102
  this.overMediaQuery();
94
- if (props.has("openQuery")) {
95
- if (window.matchMedia(this.openQuery).matches)
96
- this.show();
97
- }
98
- if (props.has("open") && this.swipeable) {
99
- requestAnimationFrame(_ => {
100
- this.$drawer.removeAttribute('style');
101
- });
103
+ if (props.has("openQuery") && this.openQuery && window.matchMedia(this.openQuery).matches)
104
+ this.show();
105
+ if (props.has("open")) {
106
+ if (this.open) {
107
+ this.dispatchEvent(new CustomEvent("did-show", { bubbles: true }));
108
+ }
109
+ else if (props.get("open") === true) {
110
+ this.dispatchEvent(new CustomEvent("did-close", { bubbles: true }));
111
+ }
112
+ if (this.swipeable && this.$drawer) {
113
+ requestAnimationFrame(() => {
114
+ this.$drawer.removeAttribute("style");
115
+ });
116
+ }
102
117
  }
103
118
  }
104
119
  overMediaQuery() {
@@ -123,42 +138,43 @@ let TkDrawer = class TkDrawer extends external_lit_.LitElement {
123
138
  this.open = !this.open;
124
139
  }
125
140
  touchStart(event) {
126
- if (!this.swipeable)
141
+ if (!this.swipeable || !this.$drawer)
127
142
  return;
128
143
  this.$drawer.style.transition = "transform 0ms ease";
129
144
  this.swipeX = event.touches[0].clientX;
130
145
  this.swipeY = event.touches[0].clientY;
131
146
  }
132
147
  touchMove(event) {
133
- if (!this.swipeable)
148
+ if (!this.swipeable || !this.$drawer)
134
149
  return;
135
150
  const deltaX = event.touches[0].clientX - this.swipeX;
136
151
  const deltaY = event.touches[0].clientY - this.swipeY;
137
152
  this.isHorizontalSwipe = Math.abs(deltaX) > Math.abs(deltaY);
138
153
  if (!this.isHorizontalSwipe)
139
154
  return;
140
- var x = this.open ?
141
- deltaX > 0 ? 0 : deltaX :
142
- deltaX < 0 ? 0 : deltaX;
143
- var transformString;
144
- this.open ?
145
- transformString = "translateX(" + x + "px)" :
146
- transformString = `translateX(min(calc(-100% + 10px + ${x}px), 0px)`;
147
- requestAnimationFrame(_ => {
155
+ const x = this.open
156
+ ? deltaX > 0 ? 0 : deltaX
157
+ : deltaX < 0 ? 0 : deltaX;
158
+ const transformString = this.open
159
+ ? `translateX(${x}px)`
160
+ : `translateX(min(calc(-100% + 10px + ${x}px), 0px))`;
161
+ requestAnimationFrame(() => {
162
+ if (!this.$drawer)
163
+ return;
148
164
  this.$drawer.style.transform = transformString;
149
165
  });
150
166
  }
151
167
  touchEnd(event) {
152
- if (!this.swipeable)
168
+ if (!this.swipeable || !this.$drawer)
153
169
  return;
154
- requestAnimationFrame(_ => {
155
- this.$drawer.removeAttribute('style');
170
+ requestAnimationFrame(() => {
171
+ var _a;
172
+ (_a = this.$drawer) === null || _a === void 0 ? void 0 : _a.removeAttribute("style");
156
173
  });
157
174
  const deltaX = event.changedTouches[0].clientX - this.swipeX;
158
175
  if (this.isHorizontalSwipe && this.open)
159
176
  this.open = -50 > deltaX ? false : true;
160
177
  else if (this.isHorizontalSwipe && !this.open) {
161
- console.log("bbb", deltaX, 50 < Math.abs(deltaX) ? true : false);
162
178
  this.open = 50 < deltaX ? true : false;
163
179
  }
164
180
  this.isHorizontalSwipe = false;
@@ -174,7 +190,7 @@ TkDrawer.styles = (0,external_lit_.css) `
174
190
  `;
175
191
  __decorate([
176
192
  (0,decorators_js_.property)({ type: Boolean, reflect: true })
177
- ], TkDrawer.prototype, "open", null);
193
+ ], TkDrawer.prototype, "open", void 0);
178
194
  __decorate([
179
195
  (0,decorators_js_.property)({ type: Boolean, reflect: true })
180
196
  ], TkDrawer.prototype, "over", void 0);
@@ -193,6 +209,15 @@ __decorate([
193
209
  __decorate([
194
210
  (0,decorators_js_.query)("div.drawer")
195
211
  ], TkDrawer.prototype, "$drawer", void 0);
212
+ __decorate([
213
+ (0,decorators_js_.query)("div.drawer-content")
214
+ ], TkDrawer.prototype, "$content", void 0);
215
+ __decorate([
216
+ (0,decorators_js_.state)()
217
+ ], TkDrawer.prototype, "contentScrolled", void 0);
218
+ __decorate([
219
+ (0,decorators_js_.state)()
220
+ ], TkDrawer.prototype, "contentHasBottomShadow", void 0);
196
221
  __decorate([
197
222
  (0,decorators_js_.eventOptions)({ passive: true })
198
223
  ], TkDrawer.prototype, "touchStart", null);
@@ -217,7 +242,7 @@ var x = (y) => {
217
242
  var x = {}; __webpack_require__.d(x, y); return x
218
243
  }
219
244
  var y = (x) => (() => (x))
220
- module.exports = x({ ["customElement"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.customElement), ["eventOptions"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.eventOptions), ["property"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.property), ["query"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.query) });
245
+ module.exports = x({ ["customElement"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.customElement), ["eventOptions"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.eventOptions), ["property"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.property), ["query"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.query), ["state"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.state) });
221
246
 
222
247
  /***/ })
223
248
 
package/icon/icon.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { PropertyValues } from "lit";
1
2
  import { TkBox } from "../box";
2
3
  export declare class TkIcon extends TkBox {
3
4
  static get styles(): import("lit").CSSResult[];
@@ -6,7 +7,7 @@ export declare class TkIcon extends TkBox {
6
7
  path: string;
7
8
  private svg;
8
9
  render(): import("lit").TemplateResult<1>;
9
- updated(props: any): void;
10
+ protected updated(props: PropertyValues<TkIcon>): void;
10
11
  loadIcon(): Promise<void>;
11
12
  }
12
13
  declare global {
package/icon/index.js CHANGED
@@ -339,29 +339,43 @@ let TkIcon = class TkIcon extends box/* TkBox */.P {
339
339
  `;
340
340
  }
341
341
  updated(props) {
342
- if (props.has("name") && this.name)
342
+ if ((props.has("name") || props.has("library")) && this.name && !this.path)
343
343
  this.loadIcon();
344
344
  }
345
345
  loadIcon() {
346
346
  return __awaiter(this, void 0, void 0, function* () {
347
+ if (!this.name || this.path) {
348
+ this.svg = "";
349
+ return;
350
+ }
351
+ const name = this.name;
352
+ const library = this.library;
347
353
  const resolver = this.library
348
354
  ? document.querySelector(`tk-icons[library=${this.library}]`)
349
355
  : document.querySelector("tk-icons");
350
- if (resolver) {
351
- this.svg = yield fetch(resolver.resolve(this.name))
352
- .then(response => {
353
- return response.blob().then(blob => {
354
- return {
355
- contentType: response.headers.get("Content-Type"),
356
- raw: blob
357
- };
358
- });
359
- })
360
- .then(data => {
361
- if (data.contentType && /svg/.test(data.contentType))
362
- return data.raw.text();
363
- return "";
364
- });
356
+ if (!resolver) {
357
+ this.svg = "";
358
+ return;
359
+ }
360
+ try {
361
+ const response = yield fetch(resolver.resolve(name));
362
+ if (!response.ok) {
363
+ this.svg = "";
364
+ return;
365
+ }
366
+ const contentType = response.headers.get("Content-Type") || "";
367
+ if (!/svg/i.test(contentType)) {
368
+ this.svg = "";
369
+ return;
370
+ }
371
+ const svg = yield response.text();
372
+ // Ensure the props are still current to avoid race conditions
373
+ if (name === this.name && library === this.library && !this.path) {
374
+ this.svg = svg;
375
+ }
376
+ }
377
+ catch (_e) {
378
+ this.svg = "";
365
379
  }
366
380
  });
367
381
  }
@@ -376,7 +390,7 @@ __decorate([
376
390
  (0,decorators_js_.property)()
377
391
  ], TkIcon.prototype, "path", void 0);
378
392
  __decorate([
379
- (0,decorators_js_.property)()
393
+ (0,decorators_js_.state)()
380
394
  ], TkIcon.prototype, "svg", void 0);
381
395
  TkIcon = __decorate([
382
396
  (0,decorators_js_.customElement)("tk-icon")
@@ -393,7 +407,7 @@ var x = (y) => {
393
407
  var x = {}; __webpack_require__.d(x, y); return x
394
408
  }
395
409
  var y = (x) => (() => (x))
396
- module.exports = x({ ["customElement"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.customElement), ["property"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.property) });
410
+ module.exports = x({ ["customElement"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.customElement), ["property"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.property), ["state"]: () => (__WEBPACK_EXTERNAL_MODULE_lit_decorators_js_226d44c5__.state) });
397
411
 
398
412
  /***/ })
399
413