leksy-editor 1.0.0

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/gallery.js ADDED
@@ -0,0 +1,107 @@
1
+
2
+ const giphy = {
3
+ search: async (options, search, page=1) => {
4
+ try {
5
+ const response = await fetch(`https://api.giphy.com/v1/gifs/search?api_key=${options.giphyApiKey}&q=${encodeURIComponent(search)}&limit=50&offset=${(page - 1) * 50}`)
6
+ if (response.ok) {
7
+ const { data, pagination } = await response.json()
8
+ return {
9
+ images: data.map(gif => ({ src: gif.images.fixed_height_small.url })),
10
+ totalPages: Math.ceil(pagination.total_count / 50) || 1,
11
+ }
12
+ }
13
+ return { images: [], totalPages: 1 };
14
+ } catch (error) {
15
+ console.error(error)
16
+ }
17
+ },
18
+ suggestions: async (options, page=1) => {
19
+ try {
20
+ const response = await fetch(`https://api.giphy.com/v1/gifs/trending?api_key=${options.giphyApiKey}&limit=10&offset=${(page - 1) * 10}`)
21
+ if (response.ok) {
22
+ const { data, pagination } = await response.json()
23
+
24
+ return {
25
+ images: data.map(gif => ({ src: gif.images.fixed_height_small.url })),
26
+ totalPages: Math.ceil(pagination.total_count / 10) || 1
27
+ }
28
+ }
29
+ return { images: [], totalPages: 1 }
30
+ } catch (error) {
31
+ console.error(error)
32
+ }
33
+ }
34
+ }
35
+
36
+ const pexels = {
37
+ search: async (options, search, page = 1) => {
38
+ try {
39
+ const response = await fetch(`https://api.pexels.com/v1/search?query=${encodeURIComponent(search)}&per_page=50&page=${page}`, { headers: { Authorization: options.pexelsApiKey } })
40
+ if (response.ok) {
41
+ const { photos, total_results } = await response.json()
42
+
43
+ return {
44
+ images: photos.map(photo => ({ src: photo.src.medium })),
45
+ totalPages: Math.ceil(total_results / 50) || 1
46
+ }
47
+ }
48
+ else return { images: [], totalPages: 1 }
49
+ } catch (error) {
50
+ console.error(error)
51
+ }
52
+ },
53
+ suggestions: async (options, page = 1) => {
54
+ try {
55
+ const response = await fetch(`https://api.pexels.com/v1/curated?per_page=10&page=${page}`, { headers: { Authorization: options.pexelsApiKey } })
56
+ if (response.ok) {
57
+ const { photos, total_results } = await response.json()
58
+
59
+ return {
60
+ images: photos.map(photo => ({ src: photo.src.medium })),
61
+ totalPages: Math.ceil(total_results / 10) || 1
62
+ }
63
+ }
64
+ else return { images: [], totalPages: 1 }
65
+ } catch (error) {
66
+ console.error(error)
67
+ }
68
+ }
69
+ }
70
+
71
+ const tenor = {
72
+ search: async (options, search, next="") => {
73
+ try {
74
+ const response = await fetch(`https://tenor.googleapis.com/v2/search?q=${encodeURIComponent(search)}&key=${options.tenorApiKey}&limit=50&pos=${next}`);
75
+ if (response.ok) {
76
+ const data = await response.json();
77
+ return {
78
+ images: data.results.map(gif => ({ src: gif.media_formats.webp.url })),
79
+ next:data.next
80
+ }
81
+ } else return { images: [], next: "" }
82
+ } catch (error) {
83
+ console.error(error)
84
+ }
85
+ },
86
+ suggestions: async (options, next="") => {
87
+ try {
88
+ const response = await fetch(`https://tenor.googleapis.com/v2/featured?key=${options.tenorApiKey}&limit=10&pos=${next}`);
89
+ if (response.ok) {
90
+ const data = await response.json();
91
+
92
+ return {
93
+ images: data.results.map(gif => ({ src: gif.media_formats.webp.url })),
94
+ next:data.next
95
+ }
96
+ } else return { images: [], next: "" }
97
+ } catch (error) {
98
+ console.error(error)
99
+ }
100
+ }
101
+ }
102
+
103
+ export {
104
+ giphy,
105
+ pexels,
106
+ tenor,
107
+ }