@giphy/js-util 4.4.2 → 5.1.0-beta.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/dist/index.cjs ADDED
@@ -0,0 +1,421 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/index.ts
48
+ var src_exports = {};
49
+ __export(src_exports, {
50
+ LogLevel: () => LogLevel,
51
+ Logger: () => Logger,
52
+ appendGiphySDKRequestHeader: () => appendGiphySDKRequestHeader,
53
+ appendGiphySDKRequestParam: () => appendGiphySDKRequestParam,
54
+ bestfit: () => bestfit_default,
55
+ checkIfWebP: () => checkIfWebP,
56
+ constructMoatData: () => constructMoatData,
57
+ forEach: () => forEach,
58
+ getAltText: () => getAltText,
59
+ getBestRendition: () => getBestRendition,
60
+ getBestRenditionUrl: () => getBestRenditionUrl,
61
+ getBestVideo: () => getBestVideo,
62
+ getClientRect: () => get_client_rect_from_el_default,
63
+ getGifHeight: () => getGifHeight,
64
+ getGifWidth: () => getGifWidth,
65
+ getGiphySDKRequestHeaders: () => getGiphySDKRequestHeaders,
66
+ getPingbackId: () => get_pingback_id_default,
67
+ getSpecificRendition: () => getSpecificRendition,
68
+ injectTrackingPixel: () => tracking_pixel_default,
69
+ mapValues: () => mapValues,
70
+ pick: () => pick,
71
+ setRenditionScaleUpMaxPixels: () => setRenditionScaleUpMaxPixels,
72
+ take: () => take,
73
+ without: () => without
74
+ });
75
+ module.exports = __toCommonJS(src_exports);
76
+
77
+ // src/log.ts
78
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
79
+ LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
80
+ LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
81
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
82
+ LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
83
+ return LogLevel2;
84
+ })(LogLevel || {});
85
+ var Logger = {
86
+ ENABLED: typeof window !== "undefined" && typeof location !== "undefined" && location.search.indexOf("giphy-debug") !== -1,
87
+ LEVEL: 0,
88
+ PREFIX: "GiphyJS",
89
+ debug: (...msg) => {
90
+ if (Logger.ENABLED && Logger.LEVEL <= 0 /* DEBUG */) {
91
+ console.debug(Logger.PREFIX, ...msg);
92
+ }
93
+ },
94
+ info: (...msg) => {
95
+ if (Logger.ENABLED && Logger.LEVEL <= 1 /* INFO */) {
96
+ console.info(Logger.PREFIX, ...msg);
97
+ }
98
+ },
99
+ warn: (...msg) => {
100
+ if (Logger.ENABLED && Logger.LEVEL <= 2 /* WARN */) {
101
+ console.warn(Logger.PREFIX, ...msg);
102
+ }
103
+ },
104
+ error: (...msg) => {
105
+ if (Logger.ENABLED && Logger.LEVEL <= 3 /* ERROR */) {
106
+ console.error(Logger.PREFIX, ...msg);
107
+ }
108
+ }
109
+ };
110
+
111
+ // src/bestfit.ts
112
+ var closestArea = (width, height, renditions) => {
113
+ let currentBest = Infinity;
114
+ let result;
115
+ renditions.forEach((rendition) => {
116
+ const widthPercentage = rendition.width / width;
117
+ const heightPercentage = rendition.height / height;
118
+ const areaPercentage = widthPercentage * heightPercentage;
119
+ const testBest = Math.abs(1 - areaPercentage);
120
+ if (testBest < currentBest) {
121
+ currentBest = testBest;
122
+ result = rendition;
123
+ }
124
+ });
125
+ return result;
126
+ };
127
+ var SCALE_UP_MAX_PIXELS = 50;
128
+ var setRenditionScaleUpMaxPixels = (pixels) => {
129
+ Logger.debug(`@giphy/js-util set rendition selection scale up max pixels to ${pixels}`);
130
+ SCALE_UP_MAX_PIXELS = pixels;
131
+ };
132
+ function bestfit(renditions, width, height, scaleUpMaxPixels = SCALE_UP_MAX_PIXELS) {
133
+ let [largestRendition] = renditions;
134
+ const testRenditions = renditions.filter((rendition) => {
135
+ if (rendition.width * rendition.height > largestRendition.width * largestRendition.height) {
136
+ largestRendition = rendition;
137
+ }
138
+ return width - rendition.width <= scaleUpMaxPixels && height - rendition.height <= scaleUpMaxPixels;
139
+ });
140
+ if (testRenditions.length === 0) {
141
+ return largestRendition;
142
+ }
143
+ return closestArea(width, height, testRenditions);
144
+ }
145
+ var bestfit_default = bestfit;
146
+
147
+ // src/collections.ts
148
+ function mapValues(object, mapFn) {
149
+ if (Array.isArray(object)) {
150
+ throw `This map is just for objects, just use array.map for arrays`;
151
+ }
152
+ return Object.keys(object).reduce((result, key) => {
153
+ result[key] = mapFn(object[key], key);
154
+ return result;
155
+ }, {});
156
+ }
157
+ function forEach(object, mapFn) {
158
+ if (Array.isArray(object)) {
159
+ throw `This map is just for objects, just use array.forEach for arrays`;
160
+ }
161
+ return Object.keys(object).forEach((key) => {
162
+ mapFn(object[key], key);
163
+ });
164
+ }
165
+ function take(arr, count = 0) {
166
+ return arr.slice(0, count);
167
+ }
168
+ function without(arr, values) {
169
+ return arr.filter((val) => values.indexOf(val) === -1);
170
+ }
171
+ function pick(object, pick2) {
172
+ const res = {};
173
+ pick2.forEach((key) => {
174
+ if (object[key] !== void 0) {
175
+ res[key] = object[key];
176
+ }
177
+ });
178
+ return res;
179
+ }
180
+
181
+ // src/construct-moat-data.ts
182
+ var constructMoatData = ({ tdata }) => {
183
+ var _a;
184
+ const [moatTrackerData] = ((_a = tdata == null ? void 0 : tdata.web) == null ? void 0 : _a.filter((tracker) => tracker.vendor === "Moat")) || [];
185
+ if (moatTrackerData == null ? void 0 : moatTrackerData.verificationParameters) {
186
+ const {
187
+ moatClientLevel1 = "_ADVERTISER_",
188
+ moatClientLevel2 = "_CAMPAIGN_",
189
+ moatClientLevel3 = "_LINE_ITEM_",
190
+ moatClientLevel4 = "_CREATIVE_",
191
+ moatClientSlicer1 = "_SITE_",
192
+ moatClientSlicer2 = "_PLACEMENT_",
193
+ zMoatPosition = "_POSITION_"
194
+ } = moatTrackerData.verificationParameters;
195
+ return {
196
+ moatClientLevel1,
197
+ moatClientLevel2,
198
+ moatClientLevel3,
199
+ moatClientLevel4,
200
+ moatClientSlicer1,
201
+ moatClientSlicer2,
202
+ zMoatPosition
203
+ };
204
+ }
205
+ };
206
+
207
+ // src/get-client-rect-from-el.ts
208
+ var getClientRect = (el) => {
209
+ let left = 0;
210
+ let top = 0;
211
+ const width = el.offsetWidth;
212
+ const height = el.offsetHeight;
213
+ do {
214
+ left += el.offsetLeft;
215
+ top += el.offsetTop;
216
+ el = el.offsetParent;
217
+ } while (el);
218
+ const result = {
219
+ left,
220
+ top,
221
+ width,
222
+ height,
223
+ right: left + width,
224
+ bottom: top + height,
225
+ x: left,
226
+ y: top
227
+ };
228
+ return __spreadProps(__spreadValues({}, result), { toJSON: () => JSON.stringify(result) });
229
+ };
230
+ var get_client_rect_from_el_default = getClientRect;
231
+
232
+ // src/get-pingback-id.ts
233
+ var import_uuid = require("uuid");
234
+ var pingbackId = "";
235
+ var idLength = 16;
236
+ var noUUIDRandom = () => {
237
+ let result = "";
238
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
239
+ const charactersLength = characters.length;
240
+ for (let i = 0; i < idLength; i++) {
241
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
242
+ }
243
+ return result;
244
+ };
245
+ var getPingbackId = () => {
246
+ if (!pingbackId) {
247
+ try {
248
+ pingbackId = sessionStorage.getItem("giphyPingbackId");
249
+ } catch (_) {
250
+ }
251
+ if (!pingbackId) {
252
+ const hexTime = (/* @__PURE__ */ new Date()).getTime().toString(16);
253
+ try {
254
+ pingbackId = `${hexTime}${(0, import_uuid.v4)().replace(/-/g, "")}`.substring(0, idLength);
255
+ } catch (error) {
256
+ pingbackId = noUUIDRandom();
257
+ }
258
+ try {
259
+ sessionStorage.setItem("giphyPingbackId", pingbackId);
260
+ } catch (_) {
261
+ }
262
+ }
263
+ }
264
+ return pingbackId;
265
+ };
266
+ var get_pingback_id_default = getPingbackId;
267
+
268
+ // src/webp-check.ts
269
+ var SUPPORTS_WEBP = null;
270
+ var checkIfWebP = new Promise((resolve) => {
271
+ if (typeof Image === "undefined") {
272
+ resolve(false);
273
+ }
274
+ const webp = new Image();
275
+ webp.onload = () => {
276
+ SUPPORTS_WEBP = true;
277
+ resolve(SUPPORTS_WEBP);
278
+ };
279
+ webp.onerror = () => {
280
+ SUPPORTS_WEBP = false;
281
+ resolve(SUPPORTS_WEBP);
282
+ };
283
+ webp.src = "data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA";
284
+ });
285
+
286
+ // src/gif-utils.ts
287
+ var getSpecificRendition = ({ images, is_sticker: isSticker }, renditionLabel, isStill = false, useVideo = false) => {
288
+ if (!images || !renditionLabel)
289
+ return "";
290
+ isStill = isStill && !useVideo;
291
+ const rendition = images[`${renditionLabel}${isStill ? "_still" : ""}`];
292
+ if (rendition) {
293
+ if (isSticker || isStill) {
294
+ return rendition.url;
295
+ }
296
+ const webP = SUPPORTS_WEBP && rendition.webp;
297
+ return useVideo ? rendition.mp4 : webP || rendition.url;
298
+ }
299
+ return "";
300
+ };
301
+ var getBestVideo = (video, width, height) => {
302
+ let assets = video == null ? void 0 : video.assets;
303
+ if (assets) {
304
+ assets = __spreadValues({}, assets);
305
+ delete assets.source;
306
+ const filteredAssets = Object.values(assets).sort((a, b) => a.width - b.width);
307
+ return bestfit_default(filteredAssets, width, height);
308
+ }
309
+ };
310
+ var getRenditions = (type, images, video) => type === "video" && video && video.previews && !Object.keys(images).length ? video.previews : images;
311
+ var getBestRendition = (images, gifWidth, gifHeight, scaleUpMaxPixels) => {
312
+ const checkRenditions = pick(images, [
313
+ "original",
314
+ "fixed_width",
315
+ "fixed_height",
316
+ "fixed_width_small",
317
+ "fixed_height_small"
318
+ ]);
319
+ const testImages = Object.entries(checkRenditions).map(([renditionName, val]) => __spreadValues({
320
+ renditionName
321
+ }, val));
322
+ return bestfit_default(testImages, gifWidth, gifHeight, scaleUpMaxPixels);
323
+ };
324
+ var getBestRenditionUrl = ({ images, video, type }, gifWidth, gifHeight, options = { isStill: false, useVideo: false }) => {
325
+ if (!gifWidth || !gifHeight || !images)
326
+ return "";
327
+ const { useVideo, isStill, scaleUpMaxPixels } = options;
328
+ const renditions = getRenditions(type, images, video);
329
+ const { renditionName } = getBestRendition(renditions, gifWidth, gifHeight, scaleUpMaxPixels);
330
+ const key = `${renditionName}${isStill && !useVideo ? "_still" : ""}`;
331
+ const rendition = renditions[key];
332
+ const match = useVideo ? rendition.mp4 : SUPPORTS_WEBP && rendition.webp ? rendition.webp : rendition.url;
333
+ return match || "";
334
+ };
335
+ var getGifHeight = ({ images }, gifWidth) => {
336
+ const { fixed_width } = images;
337
+ if (fixed_width) {
338
+ const { width, height } = fixed_width;
339
+ const aspectRatio = width / height;
340
+ return Math.round(gifWidth / aspectRatio);
341
+ }
342
+ return 0;
343
+ };
344
+ var getGifWidth = ({ images }, gifHeight) => {
345
+ const { fixed_width } = images;
346
+ if (fixed_width) {
347
+ const { width, height } = fixed_width;
348
+ const aspectRatio = width / height;
349
+ return Math.round(gifHeight * aspectRatio);
350
+ }
351
+ return 0;
352
+ };
353
+ var getAltText = ({ alt_text, user, tags = [], is_sticker = false, title = "" }) => {
354
+ if (alt_text) {
355
+ return alt_text;
356
+ }
357
+ if (title) {
358
+ return title;
359
+ }
360
+ const username = user && user.username || "";
361
+ const filteredTags = take(without(tags, ["transparent"]), username ? 4 : 5);
362
+ return `${username ? `${username} ` : ``}${filteredTags.join(" ")} ${is_sticker ? "Sticker" : "GIF"}`;
363
+ };
364
+
365
+ // src/sdk-headers.ts
366
+ var gl = (typeof window !== "undefined" ? window : global) || {};
367
+ gl._GIPHY_SDK_HEADERS_ = gl._GIPHY_SDK_HEADERS_ || (gl.Headers ? new gl.Headers({
368
+ "X-GIPHY-SDK-PLATFORM": "web"
369
+ }) : void 0);
370
+ var getGiphySDKRequestHeaders = () => gl._GIPHY_SDK_HEADERS_;
371
+ var appendGiphySDKRequestHeader = (key, value) => {
372
+ var _a;
373
+ return (_a = getGiphySDKRequestHeaders()) == null ? void 0 : _a.set(key, value);
374
+ };
375
+ var appendGiphySDKRequestParam = (key, value) => {
376
+ var _a;
377
+ return (_a = getGiphySDKRequestHeaders()) == null ? void 0 : _a.set(key, value);
378
+ };
379
+
380
+ // src/tracking-pixel.ts
381
+ var import_dompurify = __toESM(require("dompurify"), 1);
382
+ var injectTrackingPixel = (tags = []) => {
383
+ tags.forEach((tag) => {
384
+ var _a;
385
+ const el = document.createElement("html");
386
+ tag = tag.replace("%%CACHEBUSTER%%", Date.now().toString());
387
+ el.innerHTML = import_dompurify.default.sanitize(tag);
388
+ const pixel = el.querySelector("img");
389
+ if (pixel) {
390
+ (_a = document == null ? void 0 : document.querySelector("head")) == null ? void 0 : _a.appendChild(pixel);
391
+ }
392
+ });
393
+ };
394
+ var tracking_pixel_default = injectTrackingPixel;
395
+ // Annotate the CommonJS export names for ESM import in node:
396
+ 0 && (module.exports = {
397
+ LogLevel,
398
+ Logger,
399
+ appendGiphySDKRequestHeader,
400
+ appendGiphySDKRequestParam,
401
+ bestfit,
402
+ checkIfWebP,
403
+ constructMoatData,
404
+ forEach,
405
+ getAltText,
406
+ getBestRendition,
407
+ getBestRenditionUrl,
408
+ getBestVideo,
409
+ getClientRect,
410
+ getGifHeight,
411
+ getGifWidth,
412
+ getGiphySDKRequestHeaders,
413
+ getPingbackId,
414
+ getSpecificRendition,
415
+ injectTrackingPixel,
416
+ mapValues,
417
+ pick,
418
+ setRenditionScaleUpMaxPixels,
419
+ take,
420
+ without
421
+ });
@@ -0,0 +1,102 @@
1
+ import { IRendition, IGif, IImage, IImages } from '@giphy/js-types';
2
+
3
+ declare const setRenditionScaleUpMaxPixels: (pixels: number) => void;
4
+ /**
5
+ * Finds image rendition that best fits a given container preferring images
6
+ * ##### Note: all renditions are assumed to have the same aspect ratio
7
+ *
8
+ * When we have a portrait target and landscape gif, we choose a higher rendition to match
9
+ * the height of the portrait target, otherwise it's blurry (same applies for landscape to portrait)
10
+ *
11
+ * @name bestfit
12
+ * @function
13
+ * @param {Array.<Object>} renditions available image renditions each having a width and height property
14
+ * @param {Number} width
15
+ * @param {Number} height
16
+ * @param {Number} scaleUpMaxPixels the maximum pixels an asset should be scaled up
17
+ */
18
+ declare function bestfit(renditions: Array<IRendition>, width: number, height: number, scaleUpMaxPixels?: number): IRendition;
19
+
20
+ declare function mapValues(object: any, mapFn: (val: any, key: string) => any): any;
21
+ declare function forEach(object: any, mapFn: (val: any, key: any) => void): void;
22
+ declare function take<T>(arr: T[], count?: number): T[];
23
+ declare function without<T>(arr: T[], values: T[]): T[];
24
+ declare function pick<T extends object, U extends keyof T>(object: T, pick: Array<U>): Pick<T, U>;
25
+
26
+ type MoatData = {
27
+ moatClientLevel1: string;
28
+ moatClientLevel2: string;
29
+ moatClientLevel3: string;
30
+ moatClientLevel4: string;
31
+ moatClientSlicer1: string;
32
+ moatClientSlicer2: string;
33
+ zMoatPosition: string;
34
+ zMoatSession?: string;
35
+ };
36
+ type Tracker = {
37
+ vendor: string;
38
+ verificationParameters: any;
39
+ };
40
+ type TData = {
41
+ web?: Tracker[];
42
+ };
43
+ declare const constructMoatData: ({ tdata }: {
44
+ tdata: TData;
45
+ }) => MoatData | undefined;
46
+
47
+ /**
48
+ * @param el HTMLElement
49
+ * @returns calculated properties of DOMReact
50
+ */
51
+ declare const getClientRect: (el: HTMLElement) => DOMRectReadOnly;
52
+
53
+ declare const getPingbackId: () => string;
54
+
55
+ declare const getSpecificRendition: ({ images, is_sticker: isSticker }: IGif, renditionLabel: string, isStill?: boolean, useVideo?: boolean) => string;
56
+ interface IRenditionWithName extends IRendition {
57
+ renditionName: keyof IImages;
58
+ }
59
+ declare const getBestVideo: (video: IGif['video'], width: number, height: number) => IImage | undefined;
60
+ declare const getBestRendition: (images: IImages, gifWidth: number, gifHeight: number, scaleUpMaxPixels?: number) => IRenditionWithName;
61
+ type Options = {
62
+ isStill?: boolean;
63
+ useVideo?: boolean;
64
+ scaleUpMaxPixels?: number;
65
+ };
66
+ declare const getBestRenditionUrl: ({ images, video, type }: IGif, gifWidth: number, gifHeight: number, options?: Options) => keyof IImages | '';
67
+ declare const getGifHeight: ({ images }: IGif, gifWidth: number) => number;
68
+ declare const getGifWidth: ({ images }: IGif, gifHeight: number) => number;
69
+ /**
70
+ * GIF Text - Alt Text: Generates alt text for
71
+ * GIF images based on username and tags.
72
+ * @prop {Gif}
73
+ * @return {String} GIF alt text.
74
+ */
75
+ declare const getAltText: ({ alt_text, user, tags, is_sticker, title }: IGif) => string;
76
+
77
+ declare enum LogLevel {
78
+ DEBUG = 0,
79
+ INFO = 1,
80
+ WARN = 2,
81
+ ERROR = 3
82
+ }
83
+ declare const Logger: {
84
+ ENABLED: boolean;
85
+ LEVEL: number;
86
+ PREFIX: string;
87
+ debug: (...msg: any) => void;
88
+ info: (...msg: any) => void;
89
+ warn: (...msg: any) => void;
90
+ error: (...msg: any) => void;
91
+ };
92
+
93
+ type GiphySDKRequestHeader = 'X-GIPHY-SDK-NAME' | 'X-GIPHY-SDK-VERSION' | 'X-GIPHY-SDK-PLATFORM';
94
+ declare const getGiphySDKRequestHeaders: () => Headers | undefined;
95
+ declare const appendGiphySDKRequestHeader: (key: GiphySDKRequestHeader, value: string) => void | undefined;
96
+ declare const appendGiphySDKRequestParam: (key: GiphySDKRequestHeader, value: string) => void | undefined;
97
+
98
+ declare const injectTrackingPixel: (tags?: string[]) => void;
99
+
100
+ declare const checkIfWebP: Promise<unknown>;
101
+
102
+ export { LogLevel, Logger, appendGiphySDKRequestHeader, appendGiphySDKRequestParam, bestfit, checkIfWebP, constructMoatData, forEach, getAltText, getBestRendition, getBestRenditionUrl, getBestVideo, getClientRect, getGifHeight, getGifWidth, getGiphySDKRequestHeaders, getPingbackId, getSpecificRendition, injectTrackingPixel, mapValues, pick, setRenditionScaleUpMaxPixels, take, without };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,102 @@
1
- export { default as bestfit, setRenditionScaleUpMaxPixels } from './bestfit';
2
- export * from './collections';
3
- export { default as getClientRect } from './get-client-rect-from-el';
4
- export { default as getPingbackId } from './get-pingback-id';
5
- export { getAltText, getBestRendition, getBestRenditionUrl, getBestVideo, getGifHeight, getGifWidth, getSpecificRendition, } from './gif-utils';
6
- export * from './log';
7
- export * from './sdk-headers';
8
- export { checkIfWebP } from './webp-check';
1
+ import { IRendition, IGif, IImage, IImages } from '@giphy/js-types';
2
+
3
+ declare const setRenditionScaleUpMaxPixels: (pixels: number) => void;
4
+ /**
5
+ * Finds image rendition that best fits a given container preferring images
6
+ * ##### Note: all renditions are assumed to have the same aspect ratio
7
+ *
8
+ * When we have a portrait target and landscape gif, we choose a higher rendition to match
9
+ * the height of the portrait target, otherwise it's blurry (same applies for landscape to portrait)
10
+ *
11
+ * @name bestfit
12
+ * @function
13
+ * @param {Array.<Object>} renditions available image renditions each having a width and height property
14
+ * @param {Number} width
15
+ * @param {Number} height
16
+ * @param {Number} scaleUpMaxPixels the maximum pixels an asset should be scaled up
17
+ */
18
+ declare function bestfit(renditions: Array<IRendition>, width: number, height: number, scaleUpMaxPixels?: number): IRendition;
19
+
20
+ declare function mapValues(object: any, mapFn: (val: any, key: string) => any): any;
21
+ declare function forEach(object: any, mapFn: (val: any, key: any) => void): void;
22
+ declare function take<T>(arr: T[], count?: number): T[];
23
+ declare function without<T>(arr: T[], values: T[]): T[];
24
+ declare function pick<T extends object, U extends keyof T>(object: T, pick: Array<U>): Pick<T, U>;
25
+
26
+ type MoatData = {
27
+ moatClientLevel1: string;
28
+ moatClientLevel2: string;
29
+ moatClientLevel3: string;
30
+ moatClientLevel4: string;
31
+ moatClientSlicer1: string;
32
+ moatClientSlicer2: string;
33
+ zMoatPosition: string;
34
+ zMoatSession?: string;
35
+ };
36
+ type Tracker = {
37
+ vendor: string;
38
+ verificationParameters: any;
39
+ };
40
+ type TData = {
41
+ web?: Tracker[];
42
+ };
43
+ declare const constructMoatData: ({ tdata }: {
44
+ tdata: TData;
45
+ }) => MoatData | undefined;
46
+
47
+ /**
48
+ * @param el HTMLElement
49
+ * @returns calculated properties of DOMReact
50
+ */
51
+ declare const getClientRect: (el: HTMLElement) => DOMRectReadOnly;
52
+
53
+ declare const getPingbackId: () => string;
54
+
55
+ declare const getSpecificRendition: ({ images, is_sticker: isSticker }: IGif, renditionLabel: string, isStill?: boolean, useVideo?: boolean) => string;
56
+ interface IRenditionWithName extends IRendition {
57
+ renditionName: keyof IImages;
58
+ }
59
+ declare const getBestVideo: (video: IGif['video'], width: number, height: number) => IImage | undefined;
60
+ declare const getBestRendition: (images: IImages, gifWidth: number, gifHeight: number, scaleUpMaxPixels?: number) => IRenditionWithName;
61
+ type Options = {
62
+ isStill?: boolean;
63
+ useVideo?: boolean;
64
+ scaleUpMaxPixels?: number;
65
+ };
66
+ declare const getBestRenditionUrl: ({ images, video, type }: IGif, gifWidth: number, gifHeight: number, options?: Options) => keyof IImages | '';
67
+ declare const getGifHeight: ({ images }: IGif, gifWidth: number) => number;
68
+ declare const getGifWidth: ({ images }: IGif, gifHeight: number) => number;
69
+ /**
70
+ * GIF Text - Alt Text: Generates alt text for
71
+ * GIF images based on username and tags.
72
+ * @prop {Gif}
73
+ * @return {String} GIF alt text.
74
+ */
75
+ declare const getAltText: ({ alt_text, user, tags, is_sticker, title }: IGif) => string;
76
+
77
+ declare enum LogLevel {
78
+ DEBUG = 0,
79
+ INFO = 1,
80
+ WARN = 2,
81
+ ERROR = 3
82
+ }
83
+ declare const Logger: {
84
+ ENABLED: boolean;
85
+ LEVEL: number;
86
+ PREFIX: string;
87
+ debug: (...msg: any) => void;
88
+ info: (...msg: any) => void;
89
+ warn: (...msg: any) => void;
90
+ error: (...msg: any) => void;
91
+ };
92
+
93
+ type GiphySDKRequestHeader = 'X-GIPHY-SDK-NAME' | 'X-GIPHY-SDK-VERSION' | 'X-GIPHY-SDK-PLATFORM';
94
+ declare const getGiphySDKRequestHeaders: () => Headers | undefined;
95
+ declare const appendGiphySDKRequestHeader: (key: GiphySDKRequestHeader, value: string) => void | undefined;
96
+ declare const appendGiphySDKRequestParam: (key: GiphySDKRequestHeader, value: string) => void | undefined;
97
+
98
+ declare const injectTrackingPixel: (tags?: string[]) => void;
99
+
100
+ declare const checkIfWebP: Promise<unknown>;
101
+
102
+ export { LogLevel, Logger, appendGiphySDKRequestHeader, appendGiphySDKRequestParam, bestfit, checkIfWebP, constructMoatData, forEach, getAltText, getBestRendition, getBestRenditionUrl, getBestVideo, getClientRect, getGifHeight, getGifWidth, getGiphySDKRequestHeaders, getPingbackId, getSpecificRendition, injectTrackingPixel, mapValues, pick, setRenditionScaleUpMaxPixels, take, without };