@everymatrix/general-stories 0.0.1

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 (49) hide show
  1. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  2. package/dist/cjs/general-stories-34fcd4f4.js +290 -0
  3. package/dist/cjs/general-stories.cjs.entry.js +10 -0
  4. package/dist/cjs/general-stories.cjs.js +25 -0
  5. package/dist/cjs/index-839683a3.js +1317 -0
  6. package/dist/cjs/index.cjs.js +10 -0
  7. package/dist/cjs/loader.cjs.js +15 -0
  8. package/dist/collection/collection-manifest.json +12 -0
  9. package/dist/collection/components/general-stories/general-stories.css +124 -0
  10. package/dist/collection/components/general-stories/general-stories.js +379 -0
  11. package/dist/collection/components/general-stories/general-stories.types.js +1 -0
  12. package/dist/collection/components/general-stories/index.js +1 -0
  13. package/dist/collection/index.js +1 -0
  14. package/dist/collection/utils/locale.utils.js +54 -0
  15. package/dist/collection/utils/utils.js +30 -0
  16. package/dist/esm/app-globals-0f993ce5.js +3 -0
  17. package/dist/esm/general-stories-0e155a93.js +288 -0
  18. package/dist/esm/general-stories.entry.js +2 -0
  19. package/dist/esm/general-stories.js +20 -0
  20. package/dist/esm/index-1b3a1a31.js +1291 -0
  21. package/dist/esm/index.js +2 -0
  22. package/dist/esm/loader.js +11 -0
  23. package/dist/general-stories/general-stories.esm.js +1 -0
  24. package/dist/general-stories/index.esm.js +1 -0
  25. package/dist/general-stories/p-30c1a94b.js +2 -0
  26. package/dist/general-stories/p-5d17c3bf.js +1 -0
  27. package/dist/general-stories/p-9adad3b4.entry.js +1 -0
  28. package/dist/general-stories/p-e1255160.js +1 -0
  29. package/dist/index.cjs.js +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/stencil.config.dev.js +17 -0
  32. package/dist/stencil.config.js +17 -0
  33. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/general-stories/.stencil/packages/stencil/general-stories/stencil.config.d.ts +2 -0
  34. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/general-stories/.stencil/packages/stencil/general-stories/stencil.config.dev.d.ts +2 -0
  35. package/dist/types/components/general-stories/general-stories.d.ts +68 -0
  36. package/dist/types/components/general-stories/general-stories.types.d.ts +11 -0
  37. package/dist/types/components/general-stories/index.d.ts +1 -0
  38. package/dist/types/components.d.ts +93 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/stencil-public-runtime.d.ts +1674 -0
  41. package/dist/types/utils/locale.utils.d.ts +2 -0
  42. package/dist/types/utils/utils.d.ts +3 -0
  43. package/loader/cdn.js +1 -0
  44. package/loader/index.cjs.js +1 -0
  45. package/loader/index.d.ts +24 -0
  46. package/loader/index.es2017.js +1 -0
  47. package/loader/index.js +2 -0
  48. package/loader/package.json +11 -0
  49. package/package.json +26 -0
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const globalScripts = () => {};
4
+
5
+ exports.globalScripts = globalScripts;
@@ -0,0 +1,290 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index-839683a3.js');
4
+
5
+ const getDevice = () => {
6
+ let userAgent = window.navigator.userAgent;
7
+ if (userAgent.toLowerCase().match(/android/i)) {
8
+ return 'Android';
9
+ }
10
+ if (userAgent.toLowerCase().match(/iphone/i)) {
11
+ return 'iPhone';
12
+ }
13
+ if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
14
+ return 'iPad';
15
+ }
16
+ return 'PC';
17
+ };
18
+ const getDevicePlatform = () => {
19
+ const device = getDevice();
20
+ if (device) {
21
+ if (device === 'PC') {
22
+ return 'dk';
23
+ }
24
+ else if (device === 'iPad' || device === 'iPhone') {
25
+ return 'mtWeb';
26
+ }
27
+ else {
28
+ return 'mtWeb';
29
+ }
30
+ }
31
+ };
32
+
33
+ const DEFAULT_LANGUAGE = 'en';
34
+ const TRANSLATIONS = {
35
+ en: {
36
+ error: 'Error',
37
+ generalStoriesLoading: 'Loading, please wait ...',
38
+ loadMore: 'Load More',
39
+ },
40
+ hu: {
41
+ error: 'Hiba',
42
+ generalStoriesLoading: 'Betöltés, kérjük várjon ...',
43
+ loadMore: 'Továbbiak betöltése',
44
+ },
45
+ ro: {
46
+ error: 'Eroare',
47
+ generalStoriesLoading: 'Se încarcă, vă rugăm așteptați ...',
48
+ loadMore: 'Încarcă mai multe',
49
+ },
50
+ fr: {
51
+ error: 'Erreur',
52
+ generalStoriesLoading: 'Chargement, veuillez patienter ...',
53
+ loadMore: 'Charger plus',
54
+ },
55
+ ar: {
56
+ error: 'خطأ',
57
+ generalStoriesLoading: 'جار التحميل، يرجى الانتظار ...',
58
+ loadMore: 'تحميل المزيد',
59
+ },
60
+ hr: {
61
+ error: 'Greška',
62
+ generalStoriesLoading: 'Učitavanje, molimo pričekajte ...',
63
+ loadMore: 'Učitaj više',
64
+ }
65
+ };
66
+ const getTranslations = (url) => {
67
+ return new Promise((resolve) => {
68
+ fetch(url)
69
+ .then((res) => res.json())
70
+ .then((data) => {
71
+ Object.keys(data).forEach((lang) => {
72
+ if (!TRANSLATIONS[lang]) {
73
+ TRANSLATIONS[lang] = {};
74
+ }
75
+ for (let key in data[lang]) {
76
+ TRANSLATIONS[lang][key] = data[lang][key];
77
+ }
78
+ });
79
+ resolve(true);
80
+ });
81
+ });
82
+ };
83
+ const translate = (key, customLang) => {
84
+ const lang = customLang;
85
+ return TRANSLATIONS[(lang !== undefined) && (lang in TRANSLATIONS) ? lang : DEFAULT_LANGUAGE][key];
86
+ };
87
+
88
+ const generalStoriesCss = ".ImageContainer{display:flex;flex-direction:row;background-color:var(--emw--color-background, #0E1511);overflow:auto}.StoryThumbnailContainer{margin:5px;position:relative;display:inline-block;border-radius:50%}.StoryThumbnailContainer.Highlighted::before{content:\"\";position:absolute;border-radius:50%;background:linear-gradient(to bottom, var(--emw--color-primary, #22B04E), var(--emw--color-secondary, #E1A749));top:-3px;left:-3px;width:111%;height:103%}.StoryThumbnailContainer.Viewed::before{content:\"\";position:absolute;border-radius:50%;height:50px;width:50px;background:var(--emw--color-grey-150, #828282);top:-3px;left:-3px;width:111%;height:103%}.StoryThumbnailImage{height:50px;width:50px;border-radius:50%;position:relative;z-index:1}.StoryThumbnailImage.Highlighted,.StoryThumbnailImage.Viewed{border:2px solid var(--emw--color-white, #ffffff)}.FullScreenHeader{position:fixed;background:linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));top:0px;width:100%;display:flex;flex-direction:column;padding:10px 0;z-index:5;height:30px}.FullScreenHeader .CloseStoryButton{position:absolute;right:0;width:20px;margin-right:20px;margin-top:8px;z-index:50}.FullScreenHeader .ProgressBarContainer{width:90%;height:2px;position:relative;top:0;background-color:var(--emw--color-grey-150, #828282);border-radius:10px;overflow:hidden;margin:0 auto}.FullScreenHeader .ProgressBarContainer .ProgressBar{height:100%;background:var(--emw--color-white, #ffffff);width:0%;transition:width 0.1s linear}.FullScreenStory{position:fixed;width:100vw;height:100vh;background-color:var(--emw--color-grey-400, #24211f);display:flex;align-items:center;justify-content:center;overflow:hidden;z-index:300}.FullScreenStory video{height:100vh;width:100vw}.FullScreenStory img{width:100%;height:100%;object-fit:contain}.FullScreenStory .LoadMoreButtonBackground{width:100vw;height:15%;background:linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));position:absolute;bottom:0;display:flex;justify-content:center}.FullScreenStory .LoadMoreButtonBackground .LoadMoreButton{width:auto;font-size:var(--emw--font-size-small, 14px);font-family:inherit;background-color:var(--emw--color-grey-50, #F9F8F8);box-shadow:0px 0px 7px 1px var(--emw--color-grey-400, #24211f);color:var(--emw--color-black, #000000);border-radius:50px;position:absolute;bottom:15px;padding:10px 20px}";
89
+ const GeneralStoriesStyle0 = generalStoriesCss;
90
+
91
+ const GeneralStories = class {
92
+ constructor(hostRef) {
93
+ index.registerInstance(this, hostRef);
94
+ this.hasErrors = false;
95
+ this.isLoading = true;
96
+ this.isSwipe = false;
97
+ this.getStories = () => {
98
+ let url = new URL(`${this.cmsEndpoint}/${this.language}/stories`);
99
+ url.searchParams.append('env', this.cmsEnv);
100
+ url.searchParams.append('device', getDevicePlatform());
101
+ url.searchParams.append('language', this.language);
102
+ return new Promise((resolve, reject) => {
103
+ this.isLoading = true;
104
+ fetch(url.href)
105
+ .then((res) => res.json())
106
+ .then((data) => {
107
+ this.stories = data;
108
+ this.stories.forEach((story) => {
109
+ story.viewed = false;
110
+ });
111
+ this.isLoading = false;
112
+ resolve(true);
113
+ }).catch((err) => {
114
+ console.log(err);
115
+ this.isLoading = false;
116
+ this.hasErrors = true;
117
+ reject(err);
118
+ });
119
+ });
120
+ };
121
+ this.setClientStyling = () => {
122
+ let sheet = document.createElement('style');
123
+ sheet.innerHTML = this.clientStyling;
124
+ this.stylingContainer.prepend(sheet);
125
+ };
126
+ this.setClientStylingURL = () => {
127
+ let url = new URL(this.clientStylingUrl);
128
+ let cssFile = document.createElement('style');
129
+ fetch(url.href)
130
+ .then((res) => res.text())
131
+ .then((data) => {
132
+ cssFile.innerHTML = data;
133
+ setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
134
+ })
135
+ .catch((err) => {
136
+ console.log('error ', err);
137
+ });
138
+ };
139
+ this.navigateToExternalStoryLink = () => {
140
+ window.postMessage({ type: 'OpenStoryLink', url: this.currentStory.storyUrl }, window.location.href);
141
+ };
142
+ this.openFullScreenStory = (id) => {
143
+ this.currentStoryId = id;
144
+ this.currentStory = this.stories.find((story) => story.id === id);
145
+ this.markStoryAsViewed(id);
146
+ this.startProgress();
147
+ };
148
+ this.closeFullScreenView = () => {
149
+ this.markStoryAsViewed(this.currentStoryId.toString());
150
+ this.currentStoryId = null;
151
+ this.progress = 0;
152
+ clearInterval(this.intervalId);
153
+ };
154
+ this.markStoryAsViewed = (storyId) => {
155
+ const storyIndex = this.stories.findIndex(story => story.id === storyId);
156
+ if (storyIndex > -1) {
157
+ const [viewedStory] = this.stories.splice(storyIndex, 1);
158
+ viewedStory.viewed = true;
159
+ this.stories = [...this.stories, viewedStory];
160
+ }
161
+ };
162
+ this.changeStory = (story, direction) => {
163
+ const newStoryIndex = direction === 'next' ? Number(story.index) + 1 : Number(story.index) - 1;
164
+ if (newStoryIndex > this.stories.length - 1 || newStoryIndex < 0) {
165
+ this.markStoryAsViewed(story.index);
166
+ this.closeFullScreenView();
167
+ }
168
+ else {
169
+ const newStory = this.stories.find((story) => story.index === newStoryIndex);
170
+ this.currentStory = newStory;
171
+ this.currentStoryId = newStory.id;
172
+ this.progress = 0;
173
+ this.markStoryAsViewed(newStory.id);
174
+ }
175
+ };
176
+ this.startProgress = () => {
177
+ const interval = 100;
178
+ const step = (100 / (this.progressBarDuration * 1000)) * interval;
179
+ this.intervalId = setInterval(() => {
180
+ if (this.progress >= 100) {
181
+ clearInterval(this.intervalId);
182
+ }
183
+ else {
184
+ this.progress += step;
185
+ }
186
+ }, interval);
187
+ };
188
+ this.Thumbnail = ({ props }) => {
189
+ const open = () => this.openFullScreenStory(props.id);
190
+ return (index.h("div", { class: `StoryThumbnailContainer ${props.viewed ? 'Viewed' : 'Highlighted'}`, onTouchStart: open }, index.h("img", { class: `StoryThumbnailImage ${props.viewed ? 'Viewed' : 'Highlighted'}`, src: props.icon, alt: "story-icon" })));
191
+ };
192
+ this.cmsEndpoint = undefined;
193
+ this.language = 'en';
194
+ this.cmsEnv = 'stage';
195
+ this.clientStyling = '';
196
+ this.clientStylingUrl = '';
197
+ this.translationUrl = '';
198
+ this.progressBarDuration = 10;
199
+ this.currentStory = undefined;
200
+ this.currentStoryId = null;
201
+ this.progress = 0;
202
+ this.touchPosStart = undefined;
203
+ this.touchPosEnd = undefined;
204
+ }
205
+ handleStylingUpdate() {
206
+ if (this.clientStyling)
207
+ this.setClientStyling();
208
+ if (this.clientStylingUrl)
209
+ this.setClientStylingURL();
210
+ }
211
+ handleNewTranslations() {
212
+ this.isLoading = true;
213
+ getTranslations(this.translationUrl).then(() => {
214
+ this.isLoading = false;
215
+ });
216
+ }
217
+ handleTimeEnds(newValue) {
218
+ if (newValue >= 100) {
219
+ this.changeStory(this.currentStory, 'next');
220
+ }
221
+ }
222
+ async componentWillLoad() {
223
+ if (this.cmsEndpoint && this.language) {
224
+ await this.getStories();
225
+ }
226
+ if (this.translationUrl.length > 2) {
227
+ await getTranslations(this.translationUrl);
228
+ }
229
+ }
230
+ onTouchStart(e) {
231
+ this.touchPosStart = { clientX: e.touches[0].clientX, clientY: e.touches[0].clientY };
232
+ }
233
+ onTouchMove(e) {
234
+ this.touchPosEnd = { clientX: e.touches[0].clientX, clientY: e.touches[0].clientY };
235
+ const diffX = this.touchPosEnd.clientX - this.touchPosStart.clientX;
236
+ if (Math.abs(diffX) > 50) {
237
+ this.isSwipe = true;
238
+ }
239
+ }
240
+ onTouchEnd(e) {
241
+ if (this.isSwipe) {
242
+ this.touchPosEnd = { clientX: e.changedTouches[0].clientX, clientY: e.changedTouches[0].clientY };
243
+ const diffX = this.touchPosEnd.clientX - this.touchPosStart.clientX;
244
+ if (diffX > 0) {
245
+ this.changeStory(this.currentStory, 'previous');
246
+ }
247
+ else {
248
+ this.changeStory(this.currentStory, 'next');
249
+ }
250
+ }
251
+ else {
252
+ const screen = window.innerWidth;
253
+ if (e.changedTouches[0].clientX > screen / 2) {
254
+ this.changeStory(this.currentStory, 'next');
255
+ }
256
+ else {
257
+ this.changeStory(this.currentStory, 'previous');
258
+ }
259
+ }
260
+ }
261
+ render() {
262
+ if (this.hasErrors) {
263
+ return (index.h("div", { class: "GeneralStoriesError" }, index.h("div", { class: "Title" }, translate('error', this.language))));
264
+ }
265
+ if (this.isLoading) {
266
+ return (index.h("div", { class: "GeneralStoriesLoading" }, index.h("div", { class: "Title" }, translate('generalStoriesLoading', this.language))));
267
+ }
268
+ if (!this.isLoading) {
269
+ return (index.h("div", { ref: el => this.stylingContainer = el }, this.currentStoryId ?
270
+ index.h("div", { class: "FullScreenStory" }, index.h("div", { class: "FullScreenHeader" }, index.h("div", { class: "ProgressBarContainer" }, index.h("div", { class: "ProgressBar", style: { width: `${this.progress}%` } })), index.h("div", { id: "close", class: "CloseStoryButton", onTouchStart: this.closeFullScreenView }, index.h("svg", { fill: "none", stroke: "#ffffff", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, index.h("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M6 18L18 6M6 6l12 12" })))), this.currentStory.type === 'video' ?
271
+ index.h("video", { autoPlay: true }, index.h("source", { src: this.currentStory.url, type: "video/mp4" }))
272
+ :
273
+ index.h("img", { src: this.currentStory.url, alt: "story-image" }), this.currentStory.storyUrl &&
274
+ index.h("div", { class: "LoadMoreButtonBackground" }, index.h("button", { onTouchStart: this.navigateToExternalStoryLink, class: "LoadMoreButton" }, translate('loadMore', this.language))))
275
+ :
276
+ index.h("div", { class: "ImageContainer" }, this.stories.map((story) => {
277
+ return index.h(this.Thumbnail, { props: story });
278
+ }))));
279
+ }
280
+ }
281
+ static get watchers() { return {
282
+ "clientStyling": ["handleStylingUpdate"],
283
+ "clientStylingUrl": ["handleStylingUpdate"],
284
+ "translationUrl": ["handleNewTranslations"],
285
+ "progress": ["handleTimeEnds"]
286
+ }; }
287
+ };
288
+ GeneralStories.style = GeneralStoriesStyle0;
289
+
290
+ exports.GeneralStories = GeneralStories;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const generalStories = require('./general-stories-34fcd4f4.js');
6
+ require('./index-839683a3.js');
7
+
8
+
9
+
10
+ exports.general_stories = generalStories.GeneralStories;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-839683a3.js');
6
+ const appGlobals = require('./app-globals-3a1e7e63.js');
7
+
8
+ /*
9
+ Stencil Client Patch Browser v4.20.0 | MIT Licensed | https://stenciljs.com
10
+ */
11
+ var patchBrowser = () => {
12
+ const importMeta = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('general-stories.cjs.js', document.baseURI).href));
13
+ const opts = {};
14
+ if (importMeta !== "") {
15
+ opts.resourcesUrl = new URL(".", importMeta).href;
16
+ }
17
+ return index.promiseResolve(opts);
18
+ };
19
+
20
+ patchBrowser().then(async (options) => {
21
+ await appGlobals.globalScripts();
22
+ return index.bootstrapLazy([["general-stories.cjs",[[1,"general-stories",{"cmsEndpoint":[513,"cms-endpoint"],"language":[513],"cmsEnv":[513,"cms-env"],"clientStyling":[513,"client-styling"],"clientStylingUrl":[513,"client-styling-url"],"translationUrl":[513,"translation-url"],"progressBarDuration":[514,"progress-bar-duration"],"currentStory":[32],"currentStoryId":[32],"progress":[32],"touchPosStart":[32],"touchPosEnd":[32]},[[1,"touchstart","onTouchStart"],[1,"touchmove","onTouchMove"],[1,"touchend","onTouchEnd"]],{"clientStyling":["handleStylingUpdate"],"clientStylingUrl":["handleStylingUpdate"],"translationUrl":["handleNewTranslations"],"progress":["handleTimeEnds"]}]]]], options);
23
+ });
24
+
25
+ exports.setNonce = index.setNonce;