@ptcwebops/ptcw-design 0.1.2 → 0.1.4

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 (52) hide show
  1. package/dist/cjs/icon-asset_5.cjs.entry.js +1 -1
  2. package/dist/cjs/interfaces-0ecd8027.js +15 -0
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/ptc-avatar.cjs.entry.js +19 -0
  5. package/dist/cjs/ptc-card.cjs.entry.js +2 -2
  6. package/dist/cjs/ptc-img.cjs.entry.js +7 -12
  7. package/dist/cjs/ptc-picture.cjs.entry.js +145 -4
  8. package/dist/cjs/ptcw-design.cjs.js +1 -1
  9. package/dist/collection/collection-manifest.json +1 -1
  10. package/dist/collection/components/ptc-avatar/ptc-avatar.css +3 -0
  11. package/dist/collection/components/ptc-avatar/ptc-avatar.js +15 -0
  12. package/dist/collection/components/ptc-card/ptc-card.css +27 -3
  13. package/dist/collection/components/ptc-card/ptc-card.js +1 -1
  14. package/dist/collection/components/ptc-img/ptc-img.js +4 -10
  15. package/dist/collection/components/ptc-para/ptc-para.css +24 -0
  16. package/dist/collection/components/ptc-para/ptc-para.js +2 -2
  17. package/dist/collection/components/ptc-picture/ptc-picture.css +29 -0
  18. package/dist/collection/components/ptc-picture/ptc-picture.js +325 -13
  19. package/dist/collection/utils/interfaces.js +6 -1
  20. package/dist/custom-elements/index.d.ts +6 -6
  21. package/dist/custom-elements/index.js +174 -67
  22. package/dist/esm/icon-asset_5.entry.js +1 -1
  23. package/dist/esm/interfaces-3cb94654.js +12 -0
  24. package/dist/esm/loader.js +1 -1
  25. package/dist/esm/ptc-avatar.entry.js +15 -0
  26. package/dist/esm/ptc-card.entry.js +2 -2
  27. package/dist/esm/ptc-img.entry.js +4 -9
  28. package/dist/esm/ptc-picture.entry.js +146 -5
  29. package/dist/esm/ptcw-design.js +1 -1
  30. package/dist/ptcw-design/{p-dddd4d6e.entry.js → p-18092cf1.entry.js} +1 -1
  31. package/dist/ptcw-design/p-240733ce.js +1 -0
  32. package/dist/ptcw-design/p-73e2418e.entry.js +1 -0
  33. package/dist/ptcw-design/p-78a47bf1.entry.js +1 -0
  34. package/dist/ptcw-design/p-b7471812.entry.js +1 -0
  35. package/dist/ptcw-design/p-f694e46a.entry.js +1 -0
  36. package/dist/ptcw-design/ptcw-design.css +1 -1
  37. package/dist/ptcw-design/ptcw-design.esm.js +1 -1
  38. package/dist/types/components/ptc-avatar/ptc-avatar.d.ts +3 -0
  39. package/dist/types/components/ptc-para/ptc-para.d.ts +1 -1
  40. package/dist/types/components/ptc-picture/ptc-picture.d.ts +60 -1
  41. package/dist/types/components.d.ts +95 -33
  42. package/dist/types/utils/interfaces.d.ts +6 -1
  43. package/package.json +1 -1
  44. package/dist/cjs/ptc-image.cjs.entry.js +0 -58
  45. package/dist/collection/components/ptc-image/ptc-image.css +0 -4
  46. package/dist/collection/components/ptc-image/ptc-image.js +0 -92
  47. package/dist/esm/ptc-image.entry.js +0 -54
  48. package/dist/ptcw-design/p-1df1006b.entry.js +0 -1
  49. package/dist/ptcw-design/p-4586b0f5.entry.js +0 -1
  50. package/dist/ptcw-design/p-56f6f900.entry.js +0 -1
  51. package/dist/ptcw-design/p-97a61538.entry.js +0 -1
  52. package/dist/types/components/ptc-image/ptc-image.d.ts +0 -18
@@ -1,44 +1,356 @@
1
- import { Component, Prop, Host, h } from '@stencil/core';
1
+ import { Component, Prop, h, Element, Listen, State, Host } from '@stencil/core';
2
+ import { ResponsivePictureVariables } from '../../utils/interfaces';
2
3
  export class PtcPicture {
3
4
  constructor() {
4
- this.lazy = 'lazy';
5
+ /**
6
+ * Image size for smallest screen
7
+ * <=767px
8
+ */
9
+ this.sizeXs = '510x340';
10
+ /**
11
+ * Image size for small screen
12
+ * >=768px and <=991px
13
+ */
14
+ this.sizeSm = '1240x496';
15
+ /**
16
+ * Image size for medium screen
17
+ * >=992px and <=1199px
18
+ */
19
+ this.sizeMd = '1366x500';
20
+ /**
21
+ * Image solution for large screen
22
+ * >=1200px
23
+ */
24
+ this.sizeLg = '1920x1080';
25
+ /**
26
+ * Image border shape
27
+ */
28
+ this.borderRadius = '';
29
+ /**
30
+ * Set height
31
+ * Width will be auto by default
32
+ */
33
+ this.height = 'auto';
34
+ /**
35
+ * Set Width
36
+ * height will be 100% by default
37
+ */
38
+ this.width = '100%';
39
+ /**
40
+ * Object Fit
41
+ * Default: cover
42
+ */
43
+ this.objectFit = 'cover';
44
+ }
45
+ WindowResize() {
46
+ this.addIntersectionObserver();
47
+ }
48
+ componentDidLoad() {
49
+ this.addIntersectionObserver();
50
+ }
51
+ componentWillUpdate() {
52
+ if (this.src !== this.oldSrc) {
53
+ this.addIntersectionObserver();
54
+ }
55
+ this.oldSrc = this.src;
56
+ }
57
+ //lazy-loading
58
+ addIntersectionObserver() {
59
+ if (!this.src) {
60
+ return;
61
+ }
62
+ if ('IntersectionObserver' in window) {
63
+ let lazyLoadImages = new IntersectionObserver(entries => {
64
+ entries.forEach(entry => {
65
+ if (entry.isIntersecting) {
66
+ const image = this.el.shadowRoot.querySelector('img');
67
+ image.src = this.setResponsiveBg();
68
+ console.log('loaded');
69
+ lazyLoadImages.unobserve(image);
70
+ }
71
+ });
72
+ });
73
+ lazyLoadImages.observe(this.el.shadowRoot.querySelector('img'));
74
+ }
75
+ else {
76
+ // fall back to setTimeout for Safari and IE
77
+ setTimeout(() => {
78
+ const image = this.el.shadowRoot.querySelector('img');
79
+ image.src = this.setResponsiveBg();
80
+ image.onload = () => {
81
+ image.removeAttribute('data-src');
82
+ console.log('loaded fallback');
83
+ };
84
+ }, 5000);
85
+ }
86
+ }
87
+ //responsive image
88
+ setResponsiveBg() {
89
+ // Define local variables
90
+ let backgrounds = (this.el.shadowRoot || document).querySelectorAll('img'), el, elData, currentBreakpoint = this.getCurrentBreakPoints();
91
+ //console.log('current breakpoint: ' + currentBreakpoint);
92
+ // Loop through all target elements
93
+ for (var i = 0, len = backgrounds.length; i < len; i++) {
94
+ // Set current variables
95
+ el = backgrounds[i];
96
+ elData = el.getAttribute('data-' + currentBreakpoint);
97
+ if (elData !== null) {
98
+ // console.log('img src= ' + elData);
99
+ return elData;
100
+ }
101
+ else {
102
+ if (typeof console == 'object') {
103
+ console.warn('Data attribute: data-' + currentBreakpoint + ' not found on element:\n\n' + el.outerHTML + '\n\n\n');
104
+ }
105
+ }
106
+ }
5
107
  }
6
108
  render() {
7
109
  const classMap = this.getCssClassMap();
8
- return (h(Host, { class: classMap },
9
- h("picture", null,
10
- h("slot", null))));
110
+ return (h(Host, null,
111
+ h("style", null, `img{width:${this.width};height:${this.height};}`),
112
+ h("img", { class: classMap, "data-xs": `${this.src}:${this.sizeXs}`, "data-sm": `${this.src}:${this.sizeSm}`, "data-md": `${this.src}:${this.sizeMd}`, "data-lg": `${this.src}:${this.sizeLg}`, alt: this.alt })));
113
+ }
114
+ getCurrentBreakPoints() {
115
+ // Define local variables
116
+ let doc = window.document, temp = doc.createElement('div'), env;
117
+ // Append test node
118
+ doc.body.appendChild(temp);
119
+ // Loop through breakpoints
120
+ for (let i = ResponsivePictureVariables.envs.length - 1; i >= 0; i--) {
121
+ env = ResponsivePictureVariables.envs[i];
122
+ // Add classes
123
+ temp.className = 'hidden-' + env;
124
+ // Found breakpoint
125
+ if (temp.offsetParent === null) {
126
+ // Remove our test node
127
+ doc.body.removeChild(temp);
128
+ console.log('remove test node');
129
+ // Return current breakpoint
130
+ return env;
131
+ }
132
+ }
133
+ // Breakpoint not found, try fallback
134
+ doc.body.removeChild(temp);
135
+ return this.getFallbackBreakpoint();
136
+ }
137
+ getFallbackBreakpoint() {
138
+ if (window.matchMedia('(min-width: 992px)').matches) {
139
+ return 'lg';
140
+ }
141
+ else if (window.matchMedia('(min-width: 768px)').matches) {
142
+ return 'md';
143
+ }
144
+ else if (window.matchMedia('(min-width: 576px)').matches) {
145
+ return 'sm';
146
+ }
147
+ else {
148
+ return 'xs';
149
+ }
11
150
  }
12
151
  getCssClassMap() {
13
152
  return {
14
- [this.lazy]: true,
153
+ [this.borderRadius]: true,
154
+ [this.objectFit]: true,
15
155
  };
16
156
  }
17
157
  static get is() { return "ptc-picture"; }
158
+ static get encapsulation() { return "shadow"; }
18
159
  static get originalStyleUrls() { return {
19
- "$": ["ptc-picture.css"]
160
+ "$": ["ptc-picture.scss"]
20
161
  }; }
21
162
  static get styleUrls() { return {
22
163
  "$": ["ptc-picture.css"]
23
164
  }; }
24
165
  static get properties() { return {
25
- "lazy": {
166
+ "src": {
167
+ "type": "string",
168
+ "mutable": false,
169
+ "complexType": {
170
+ "original": "string",
171
+ "resolved": "string",
172
+ "references": {}
173
+ },
174
+ "required": false,
175
+ "optional": false,
176
+ "docs": {
177
+ "tags": [],
178
+ "text": "Image Render Src"
179
+ },
180
+ "attribute": "src",
181
+ "reflect": false
182
+ },
183
+ "alt": {
184
+ "type": "string",
185
+ "mutable": false,
186
+ "complexType": {
187
+ "original": "string",
188
+ "resolved": "string",
189
+ "references": {}
190
+ },
191
+ "required": false,
192
+ "optional": false,
193
+ "docs": {
194
+ "tags": [],
195
+ "text": "Image alt"
196
+ },
197
+ "attribute": "alt",
198
+ "reflect": false
199
+ },
200
+ "sizeXs": {
201
+ "type": "string",
202
+ "mutable": true,
203
+ "complexType": {
204
+ "original": "string",
205
+ "resolved": "string",
206
+ "references": {}
207
+ },
208
+ "required": false,
209
+ "optional": false,
210
+ "docs": {
211
+ "tags": [],
212
+ "text": "Image size for smallest screen\n<=767px"
213
+ },
214
+ "attribute": "size-xs",
215
+ "reflect": false,
216
+ "defaultValue": "'510x340'"
217
+ },
218
+ "sizeSm": {
219
+ "type": "string",
220
+ "mutable": true,
221
+ "complexType": {
222
+ "original": "string",
223
+ "resolved": "string",
224
+ "references": {}
225
+ },
226
+ "required": false,
227
+ "optional": false,
228
+ "docs": {
229
+ "tags": [],
230
+ "text": "Image size for small screen\n>=768px and <=991px"
231
+ },
232
+ "attribute": "size-sm",
233
+ "reflect": false,
234
+ "defaultValue": "'1240x496'"
235
+ },
236
+ "sizeMd": {
237
+ "type": "string",
238
+ "mutable": true,
239
+ "complexType": {
240
+ "original": "string",
241
+ "resolved": "string",
242
+ "references": {}
243
+ },
244
+ "required": false,
245
+ "optional": false,
246
+ "docs": {
247
+ "tags": [],
248
+ "text": "Image size for medium screen\n>=992px and <=1199px"
249
+ },
250
+ "attribute": "size-md",
251
+ "reflect": false,
252
+ "defaultValue": "'1366x500'"
253
+ },
254
+ "sizeLg": {
255
+ "type": "string",
256
+ "mutable": true,
257
+ "complexType": {
258
+ "original": "string",
259
+ "resolved": "string",
260
+ "references": {}
261
+ },
262
+ "required": false,
263
+ "optional": false,
264
+ "docs": {
265
+ "tags": [],
266
+ "text": "Image solution for large screen\n>=1200px"
267
+ },
268
+ "attribute": "size-lg",
269
+ "reflect": false,
270
+ "defaultValue": "'1920x1080'"
271
+ },
272
+ "borderRadius": {
273
+ "type": "string",
274
+ "mutable": false,
275
+ "complexType": {
276
+ "original": "'radius-sm' | 'radius-md' | 'radius-lg' | ''",
277
+ "resolved": "\"\" | \"radius-lg\" | \"radius-md\" | \"radius-sm\"",
278
+ "references": {}
279
+ },
280
+ "required": false,
281
+ "optional": false,
282
+ "docs": {
283
+ "tags": [],
284
+ "text": "Image border shape"
285
+ },
286
+ "attribute": "border-radius",
287
+ "reflect": false,
288
+ "defaultValue": "''"
289
+ },
290
+ "height": {
291
+ "type": "string",
292
+ "mutable": false,
293
+ "complexType": {
294
+ "original": "string",
295
+ "resolved": "string",
296
+ "references": {}
297
+ },
298
+ "required": false,
299
+ "optional": false,
300
+ "docs": {
301
+ "tags": [],
302
+ "text": "Set height\nWidth will be auto by default"
303
+ },
304
+ "attribute": "height",
305
+ "reflect": false,
306
+ "defaultValue": "'auto'"
307
+ },
308
+ "width": {
309
+ "type": "string",
310
+ "mutable": false,
311
+ "complexType": {
312
+ "original": "string",
313
+ "resolved": "string",
314
+ "references": {}
315
+ },
316
+ "required": false,
317
+ "optional": false,
318
+ "docs": {
319
+ "tags": [],
320
+ "text": "Set Width\nheight will be 100% by default"
321
+ },
322
+ "attribute": "width",
323
+ "reflect": false,
324
+ "defaultValue": "'100%'"
325
+ },
326
+ "objectFit": {
26
327
  "type": "string",
27
328
  "mutable": false,
28
329
  "complexType": {
29
- "original": "'lazy' | 'eager'",
30
- "resolved": "\"eager\" | \"lazy\"",
330
+ "original": "'cover' | 'fill' | 'contain' | 'scale-down' | 'none' | 'initial' | 'inherit'",
331
+ "resolved": "\"contain\" | \"cover\" | \"fill\" | \"inherit\" | \"initial\" | \"none\" | \"scale-down\"",
31
332
  "references": {}
32
333
  },
33
334
  "required": false,
34
335
  "optional": false,
35
336
  "docs": {
36
337
  "tags": [],
37
- "text": ""
338
+ "text": "Object Fit\nDefault: cover"
38
339
  },
39
- "attribute": "lazy",
340
+ "attribute": "object-fit",
40
341
  "reflect": false,
41
- "defaultValue": "'lazy'"
342
+ "defaultValue": "'cover'"
42
343
  }
43
344
  }; }
345
+ static get states() { return {
346
+ "oldSrc": {}
347
+ }; }
348
+ static get elementRef() { return "el"; }
349
+ static get listeners() { return [{
350
+ "name": "resize",
351
+ "method": "WindowResize",
352
+ "target": "window",
353
+ "capture": false,
354
+ "passive": true
355
+ }]; }
44
356
  }
@@ -3,4 +3,9 @@ let ResponsiveBgVariables = {
3
3
  selector: '.ptc-img',
4
4
  interval: 250
5
5
  };
6
- export { ResponsiveBgVariables };
6
+ let ResponsivePictureVariables = {
7
+ envs: ['xs', 'sm', 'md', 'lg'],
8
+ selector: '.ptc-picture',
9
+ interval: 250
10
+ };
11
+ export { ResponsiveBgVariables, ResponsivePictureVariables };
@@ -26,6 +26,12 @@ export const PtcAnnouncement: {
26
26
  new (): PtcAnnouncement;
27
27
  };
28
28
 
29
+ interface PtcAvatar extends Components.PtcAvatar, HTMLElement {}
30
+ export const PtcAvatar: {
31
+ prototype: PtcAvatar;
32
+ new (): PtcAvatar;
33
+ };
34
+
29
35
  interface PtcButton extends Components.PtcButton, HTMLElement {}
30
36
  export const PtcButton: {
31
37
  prototype: PtcButton;
@@ -50,12 +56,6 @@ export const PtcFooter: {
50
56
  new (): PtcFooter;
51
57
  };
52
58
 
53
- interface PtcImage extends Components.PtcImage, HTMLElement {}
54
- export const PtcImage: {
55
- prototype: PtcImage;
56
- new (): PtcImage;
57
- };
58
-
59
59
  interface PtcImg extends Components.PtcImg, HTMLElement {}
60
60
  export const PtcImg: {
61
61
  prototype: PtcImg;