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