@giphy/js-util 5.0.0 → 5.1.0-beta.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.
@@ -0,0 +1,18 @@
1
+ import { IRendition } from '@giphy/js-types';
2
+ export declare const setRenditionScaleUpMaxPixels: (pixels: number) => void;
3
+ /**
4
+ * Finds image rendition that best fits a given container preferring images
5
+ * ##### Note: all renditions are assumed to have the same aspect ratio
6
+ *
7
+ * When we have a portrait target and landscape gif, we choose a higher rendition to match
8
+ * the height of the portrait target, otherwise it's blurry (same applies for landscape to portrait)
9
+ *
10
+ * @name bestfit
11
+ * @function
12
+ * @param {Array.<Object>} renditions available image renditions each having a width and height property
13
+ * @param {Number} width
14
+ * @param {Number} height
15
+ * @param {Number} scaleUpMaxPixels the maximum pixels an asset should be scaled up
16
+ */
17
+ declare function bestfit(renditions: Array<IRendition>, width: number, height: number, scaleUpMaxPixels?: number): IRendition;
18
+ export default bestfit;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setRenditionScaleUpMaxPixels = void 0;
4
+ var log_1 = require("./log");
5
+ var closestArea = function (width, height, renditions) {
6
+ var currentBest = Infinity;
7
+ var result;
8
+ // sort the renditions so we can avoid scaling up low resolutions
9
+ renditions.forEach(function (rendition) {
10
+ var widthPercentage = rendition.width / width;
11
+ var heightPercentage = rendition.height / height;
12
+ // a width percentage of 1 is exact, 2 is double, .5 half etc
13
+ var areaPercentage = widthPercentage * heightPercentage;
14
+ // img could be bigger or smaller
15
+ var testBest = Math.abs(1 - areaPercentage); // the closer to 0 the better
16
+ if (testBest < currentBest) {
17
+ currentBest = testBest;
18
+ result = rendition;
19
+ }
20
+ });
21
+ return result;
22
+ };
23
+ var SCALE_UP_MAX_PIXELS = 50;
24
+ var setRenditionScaleUpMaxPixels = function (pixels) {
25
+ log_1.Logger.debug("@giphy/js-util set rendition selection scale up max pixels to ".concat(pixels));
26
+ SCALE_UP_MAX_PIXELS = pixels;
27
+ };
28
+ exports.setRenditionScaleUpMaxPixels = setRenditionScaleUpMaxPixels;
29
+ /**
30
+ * Finds image rendition that best fits a given container preferring images
31
+ * ##### Note: all renditions are assumed to have the same aspect ratio
32
+ *
33
+ * When we have a portrait target and landscape gif, we choose a higher rendition to match
34
+ * the height of the portrait target, otherwise it's blurry (same applies for landscape to portrait)
35
+ *
36
+ * @name bestfit
37
+ * @function
38
+ * @param {Array.<Object>} renditions available image renditions each having a width and height property
39
+ * @param {Number} width
40
+ * @param {Number} height
41
+ * @param {Number} scaleUpMaxPixels the maximum pixels an asset should be scaled up
42
+ */
43
+ function bestfit(renditions, width, height, scaleUpMaxPixels) {
44
+ if (scaleUpMaxPixels === void 0) { scaleUpMaxPixels = SCALE_UP_MAX_PIXELS; }
45
+ var largestRendition = renditions[0];
46
+ // filter out renditions that are smaller than the target width and height by scaleUpMaxPixels value
47
+ var testRenditions = renditions.filter(function (rendition) {
48
+ if (rendition.width * rendition.height > largestRendition.width * largestRendition.height) {
49
+ largestRendition = rendition;
50
+ }
51
+ return width - rendition.width <= scaleUpMaxPixels && height - rendition.height <= scaleUpMaxPixels;
52
+ });
53
+ // if all are too small, use the largest we have
54
+ if (testRenditions.length === 0) {
55
+ return largestRendition;
56
+ }
57
+ // find the closest area of the filtered renditions
58
+ return closestArea(width, height, testRenditions);
59
+ }
60
+ exports.default = bestfit;
61
+ //# sourceMappingURL=bestfit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bestfit.js","sourceRoot":"","sources":["../src/bestfit.ts"],"names":[],"mappings":";;;AACA,6BAA8B;AAE9B,IAAM,WAAW,GAAG,UAAC,KAAa,EAAE,MAAc,EAAE,UAAwB;IACxE,IAAI,WAAW,GAAG,QAAQ,CAAA;IAC1B,IAAI,MAAkB,CAAA;IACtB,iEAAiE;IACjE,UAAU,CAAC,OAAO,CAAC,UAAC,SAAqB;QACrC,IAAM,eAAe,GAAG,SAAS,CAAC,KAAK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EAAE;QAC7B,OAAO,gBAAgB,CAAA;KAC1B;IACD,mDAAmD;IACnD,OAAO,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,CAAA;AACrD,CAAC;AAED,kBAAe,OAAO,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare function mapValues(object: any, mapFn: (val: any, key: string) => any): any;
2
+ export declare function forEach(object: any, mapFn: (val: any, key: any) => void): void;
3
+ export declare function take<T>(arr: T[], count?: number): T[];
4
+ export declare function without<T>(arr: T[], values: T[]): T[];
5
+ export declare function pick<T extends object, U extends keyof T>(object: T, pick: Array<U>): Pick<T, U>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pick = exports.without = exports.take = exports.forEach = exports.mapValues = void 0;
4
+ function mapValues(object, mapFn) {
5
+ if (Array.isArray(object)) {
6
+ throw "This map is just for objects, just use array.map for arrays";
7
+ }
8
+ return Object.keys(object).reduce(function (result, key) {
9
+ result[key] = mapFn(object[key], key);
10
+ return result;
11
+ }, {});
12
+ }
13
+ exports.mapValues = mapValues;
14
+ function forEach(object, mapFn) {
15
+ if (Array.isArray(object)) {
16
+ throw "This map is just for objects, just use array.forEach for arrays";
17
+ }
18
+ return Object.keys(object).forEach(function (key) {
19
+ mapFn(object[key], key);
20
+ });
21
+ }
22
+ exports.forEach = forEach;
23
+ function take(arr, count) {
24
+ if (count === void 0) { count = 0; }
25
+ return arr.slice(0, count);
26
+ }
27
+ exports.take = take;
28
+ function without(arr, values) {
29
+ return arr.filter(function (val) { return values.indexOf(val) === -1; });
30
+ }
31
+ exports.without = without;
32
+ function pick(object, pick) {
33
+ var res = {};
34
+ pick.forEach(function (key) {
35
+ if (object[key] !== undefined) {
36
+ res[key] = object[key];
37
+ }
38
+ });
39
+ return res;
40
+ }
41
+ exports.pick = pick;
42
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.js","sourceRoot":"","s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,CAAC,UAAC,GAAM;QAChB,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC3B,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;SACzB;IACL,CAAC,CAAC,CAAA;IACF,OAAO,GAAiB,CAAA;AAC5B,CAAC;AARD,oBAQC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param el HTMLElement
3
+ * @returns calculated properties of DOMReact
4
+ */
5
+ declare const getClientRect: (el: HTMLElement) => DOMRectReadOnly;
6
+ export default getClientRect;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ /**
15
+ * @param el HTMLElement
16
+ * @returns calculated properties of DOMReact
17
+ */
18
+ var getClientRect = function (el) {
19
+ var left = 0;
20
+ var top = 0;
21
+ var width = el.offsetWidth;
22
+ var height = el.offsetHeight;
23
+ // no layout thrash
24
+ do {
25
+ left += el.offsetLeft;
26
+ top += el.offsetTop;
27
+ el = el.offsetParent;
28
+ } while (el);
29
+ var result = {
30
+ left: left,
31
+ top: top,
32
+ width: width,
33
+ height: height,
34
+ right: left + width,
35
+ bottom: top + height,
36
+ x: left,
37
+ y: top,
38
+ };
39
+ return __assign(__assign({}, result), { toJSON: function () { return JSON.stringify(result); } });
40
+ };
41
+ exports.default = getClientRect;
42
+ //# sourceMappingURL=get-client-rect-from-el.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-client-rect-from-el.js","sourceRoot":"","sources":["../src/get-client-rect-from-el.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;GAGG;AACH,IAAM,aAAa,GAAG,UAAC,EAAe;IAClC,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAA;IAC5B,IAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAA;IAC9B,mBAAmB;IACnB,GAAG;QACC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAA;QACrB,GAAG,IAAI,EAAE,CAAC,SAAS,CAAA;QACnB,EAAE,GAAG,EAAE,CAAC,YAA2B,CAAA;KACtC,QAAQ,EAAE,EAAC;IACZ,IAAM,MAAM,GAAG;QACX,IAAI,MAAA;QACJ,GAAG,KAAA;QACH,KAAK,OAAA;QACL,MAAM,QAAA;QACN,KAAK,EAAE,IAAI,GAAG,KAAK;QACnB,MAAM,EAAE,GAAG,GAAG,MAAM;QACpB,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,GAAG;KACT,CAAA;IACD,6BAAY,MAAM,KAAE,MAAM,EAAE,cAAM,OAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAtB,CAAsB,IAAE;AAC9D,CAAC,CAAA;AAED,kBAAe,aAAa,CAAA"}
@@ -0,0 +1,2 @@
1
+ declare const getPingbackId: () => string;
2
+ export default getPingbackId;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var uuid_1 = require("uuid");
4
+ var pingbackId = '';
5
+ var idLength = 16;
6
+ /* istanbul ignore next */
7
+ var noUUIDRandom = function () {
8
+ var result = '';
9
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10
+ var charactersLength = characters.length;
11
+ for (var i = 0; i < idLength; i++) {
12
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
13
+ }
14
+ return result;
15
+ };
16
+ var getPingbackId = function () {
17
+ // it exists in memory
18
+ if (!pingbackId) {
19
+ try {
20
+ // it exists in storage
21
+ pingbackId = sessionStorage.getItem('giphyPingbackId');
22
+ }
23
+ catch (_) { }
24
+ if (!pingbackId) {
25
+ // we need to create it
26
+ var hexTime = new Date().getTime().toString(16); // was told to mimic what we had
27
+ try {
28
+ // React Native doesn't support uuid without a polyfill
29
+ pingbackId = "".concat(hexTime).concat((0, uuid_1.v4)().replace(/-/g, '')).substring(0, idLength); // 16 character max
30
+ }
31
+ catch (error) {
32
+ /* istanbul ignore next */
33
+ pingbackId = noUUIDRandom();
34
+ }
35
+ try {
36
+ // save in storage
37
+ sessionStorage.setItem('giphyPingbackId', pingbackId);
38
+ }
39
+ catch (_) { }
40
+ }
41
+ }
42
+ return pingbackId;
43
+ };
44
+ exports.default = getPingbackId;
45
+ //# sourceMappingURL=get-pingback-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pingback-id.js","sourceRoot":"","sources":["../src/get-pingback-id.ts"],"names":[],"mappings":";;AAAA,6BAAiC;AACjC,IAAI,UAAU,GAAG,EAAE,CAAA;AAEnB,IAAM,QAAQ,GAAG,EAAE,CAAA;AAEnB,0BAA0B;AAC1B,IAAM,YAAY,GAAG;IACjB,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAM,UAAU,GAAG,gEAAgE,CAAA;IACnF,IAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAA;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;KAC5E;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AACD,IAAM,aAAa,GAAG;IAClB,sBAAsB;IACtB,IAAI,CAAC,UAAU,EAAE;QACb,IAAI;YACA,uBAAuB;YACvB,UAAU,GAAG,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAW,CAAA;SACnE;QAAC,OAAO,CAAC,EAAE,GAAE;QACd,IAAI,CAAC,UAAU,EAAE;YACb,uBAAuB;YACvB,IAAM,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAC,gCAAgC;YAClF,IAAI;gBACA,uDAAuD;gBACvD,UAAU,GAAG,UAAG,OAAO,SAAG,IAAA,SAAI,GAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAE,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA,CAAC,mBAAmB;aAClG;YAAC,OAAO,KAAK,EAAE;gBACZ,0BAA0B;gBAC1B,UAAU,GAAG,YAAY,EAAE,CAAA;aAC9B;YACD,IAAI;gBACA,kBAAkB;gBAClB,cAAc,CAAC,OAAO,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAA;aACxD;YAAC,OAAO,CAAC,EAAE,GAAE;SACjB;KACJ;IACD,OAAO,UAAU,CAAA;AACrB,CAAC,CAAA;AAED,kBAAe,aAAa,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { IGif, IImage, IImages, IRendition } from '@giphy/js-types';
2
+ export declare const getSpecificRendition: ({ images, is_sticker: isSticker }: IGif, renditionLabel: string, isStill?: boolean, useVideo?: boolean) => string;
3
+ interface IRenditionWithName extends IRendition {
4
+ renditionName: keyof IImages;
5
+ }
6
+ export declare const getBestVideo: (video: IGif['video'], width: number, height: number) => IImage | undefined;
7
+ export declare const getBestRendition: (images: IImages, gifWidth: number, gifHeight: number, scaleUpMaxPixels?: number) => IRenditionWithName;
8
+ type Options = {
9
+ isStill?: boolean;
10
+ useVideo?: boolean;
11
+ scaleUpMaxPixels?: number;
12
+ };
13
+ export declare const getBestRenditionUrl: ({ images, video, type }: IGif, gifWidth: number, gifHeight: number, options?: Options) => keyof IImages | '';
14
+ export declare const getGifHeight: ({ images }: IGif, gifWidth: number) => number;
15
+ export declare const getGifWidth: ({ images }: IGif, gifHeight: number) => number;
16
+ /**
17
+ * GIF Text - Alt Text: Generates alt text for
18
+ * GIF images based on username and tags.
19
+ * @prop {Gif}
20
+ * @return {String} GIF alt text.
21
+ */
22
+ export declare const getAltText: ({ alt_text, user, tags, is_sticker, title }: IGif) => string;
23
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getAltText = exports.getGifWidth = exports.getGifHeight = exports.getBestRenditionUrl = exports.getBestRendition = exports.getBestVideo = exports.getSpecificRendition = void 0;
18
+ var bestfit_1 = __importDefault(require("./bestfit"));
19
+ var collections_1 = require("./collections");
20
+ var webp_check_1 = require("./webp-check");
21
+ var getSpecificRendition = function (_a, renditionLabel, isStill, useVideo) {
22
+ var images = _a.images, isSticker = _a.is_sticker;
23
+ if (isStill === void 0) { isStill = false; }
24
+ if (useVideo === void 0) { useVideo = false; }
25
+ if (!images || !renditionLabel)
26
+ return '';
27
+ isStill = isStill && !useVideo;
28
+ // @ts-ignore come back to this
29
+ var rendition = images["".concat(renditionLabel).concat(isStill ? '_still' : '')];
30
+ if (rendition) {
31
+ if (isSticker || isStill) {
32
+ return rendition.url;
33
+ }
34
+ var webP = webp_check_1.SUPPORTS_WEBP && rendition.webp;
35
+ return useVideo ? rendition.mp4 : webP || rendition.url;
36
+ }
37
+ return '';
38
+ };
39
+ exports.getSpecificRendition = getSpecificRendition;
40
+ var getBestVideo = function (video, width, height) {
41
+ var assets = video === null || video === void 0 ? void 0 : video.assets;
42
+ if (assets) {
43
+ assets = __assign({}, assets);
44
+ // @ts-ignore we don't show source according to the existing code
45
+ delete assets.source;
46
+ var filteredAssets = Object.values(assets).sort(function (a, b) { return a.width - b.width; });
47
+ return (0, bestfit_1.default)(filteredAssets, width, height);
48
+ }
49
+ };
50
+ exports.getBestVideo = getBestVideo;
51
+ var getRenditions = function (type, images, video) {
52
+ return type === 'video' && video && video.previews && !Object.keys(images).length ? video.previews : images;
53
+ };
54
+ var getBestRendition = function (images, gifWidth, gifHeight, scaleUpMaxPixels) {
55
+ var checkRenditions = (0, collections_1.pick)(images, [
56
+ 'original',
57
+ 'fixed_width',
58
+ 'fixed_height',
59
+ 'fixed_width_small',
60
+ 'fixed_height_small',
61
+ ]);
62
+ var testImages = Object.entries(checkRenditions).map(function (_a) {
63
+ var renditionName = _a[0], val = _a[1];
64
+ return (__assign({ renditionName: renditionName }, val));
65
+ });
66
+ return (0, bestfit_1.default)(testImages, gifWidth, gifHeight, scaleUpMaxPixels);
67
+ };
68
+ exports.getBestRendition = getBestRendition;
69
+ var getBestRenditionUrl = function (_a, gifWidth, gifHeight, options) {
70
+ var images = _a.images, video = _a.video, type = _a.type;
71
+ if (options === void 0) { options = { isStill: false, useVideo: false }; }
72
+ if (!gifWidth || !gifHeight || !images)
73
+ return '';
74
+ var useVideo = options.useVideo, isStill = options.isStill, scaleUpMaxPixels = options.scaleUpMaxPixels;
75
+ var renditions = getRenditions(type, images, video);
76
+ var renditionName = (0, exports.getBestRendition)(renditions, gifWidth, gifHeight, scaleUpMaxPixels).renditionName;
77
+ // still, video, webp or gif
78
+ var key = "".concat(renditionName).concat(isStill && !useVideo ? '_still' : '');
79
+ var rendition = renditions[key];
80
+ var match = useVideo ? rendition.mp4 : webp_check_1.SUPPORTS_WEBP && rendition.webp ? rendition.webp : rendition.url;
81
+ return (match || '');
82
+ };
83
+ exports.getBestRenditionUrl = getBestRenditionUrl;
84
+ var getGifHeight = function (_a, gifWidth) {
85
+ var images = _a.images;
86
+ var fixed_width = images.fixed_width;
87
+ if (fixed_width) {
88
+ var width = fixed_width.width, height = fixed_width.height;
89
+ var aspectRatio = width / height;
90
+ return Math.round(gifWidth / aspectRatio);
91
+ }
92
+ return 0;
93
+ };
94
+ exports.getGifHeight = getGifHeight;
95
+ var getGifWidth = function (_a, gifHeight) {
96
+ var images = _a.images;
97
+ var fixed_width = images.fixed_width;
98
+ if (fixed_width) {
99
+ var width = fixed_width.width, height = fixed_width.height;
100
+ var aspectRatio = width / height;
101
+ return Math.round(gifHeight * aspectRatio);
102
+ }
103
+ return 0;
104
+ };
105
+ exports.getGifWidth = getGifWidth;
106
+ /**
107
+ * GIF Text - Alt Text: Generates alt text for
108
+ * GIF images based on username and tags.
109
+ * @prop {Gif}
110
+ * @return {String} GIF alt text.
111
+ */
112
+ var getAltText = function (_a) {
113
+ var alt_text = _a.alt_text, user = _a.user, _b = _a.tags, tags = _b === void 0 ? [] : _b, _c = _a.is_sticker, is_sticker = _c === void 0 ? false : _c, _d = _a.title, title = _d === void 0 ? '' : _d;
114
+ if (alt_text) {
115
+ return alt_text;
116
+ }
117
+ if (title) {
118
+ return title;
119
+ }
120
+ var username = (user && user.username) || '';
121
+ var filteredTags = (0, collections_1.take)((0, collections_1.without)(tags, ['transparent']), username ? 4 : 5);
122
+ return "".concat(username ? "".concat(username, " ") : "").concat(filteredTags.join(' '), " ").concat(is_sticker ? 'Sticker' : 'GIF');
123
+ };
124
+ exports.getAltText = getAltText;
125
+ //# sourceMappingURL=gif-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gif-utils.js","sourceRoot":"","sources":["../src/gif-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,sDAA+B;AAC/B,6CAAmD;AACnD,2CAA4C;AAErC,IAAM,oBAAoB,GAAG,UAChC,EAAuC,EACvC,cAAsB,EACtB,OAAe,EACf,QAAgB;QAHd,MAAM,YAAA,EAAc,SAAS,gBAA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,KAAK,GAAa,WAAW,MAAxB,EAAE,MAAM,GAAK,WAAW,OAAhB,CAAgB;QACrC,IAAM,WAAW,GAAG,KAAK,GAAG,MAAM,CAAA;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,WAAW,CAAC,CAAA;KAC7C;IACD,OAAO,CAAC,CAAA;AACZ,CAAC,CAAA;AARY,QAAA,WAAW,eAQvB;AAED;;;;;GAKG;AACI,IAAM,UAAU,GAAG,UAAC,EAAmE;QAAjE,QAAQ,cAAA,EAAE,IAAI,UAAA,EAAE,YAAS,EAAT,IAAI,mBAAG,EAAE,KAAA,EAAE,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAAE,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA;IAClF,IAAI,QAAQ,EAAE;QACV,OAAO,QAAQ,CAAA;KAClB;IACD,IAAI,KAAK,EAAE;QACP,OAAO,KAAK,CAAA;KACf;IACD,IAAM,QAAQ,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9C,IAAM,YAAY,GAAG,IAAA,kBAAI,EAAC,IAAA,qBAAO,EAAC,IAAI,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3E,OAAO,UAAG,QAAQ,CAAC,CAAC,CAAC,UAAG,QAAQ,MAAG,CAAC,CAAC,CAAC,EAAE,SAAG,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,cAAI,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAE,CAAA;AACzG,CAAC,CAAA;AAVY,QAAA,UAAU,cAUtB"}
package/dist/index.cjs CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
8
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -32,6 +34,14 @@ var __copyProps = (to, from, except, desc) => {
32
34
  }
33
35
  return to;
34
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
+ ));
35
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
46
 
37
47
  // src/index.ts
@@ -43,6 +53,7 @@ __export(src_exports, {
43
53
  appendGiphySDKRequestParam: () => appendGiphySDKRequestParam,
44
54
  bestfit: () => bestfit_default,
45
55
  checkIfWebP: () => checkIfWebP,
56
+ constructMoatData: () => constructMoatData,
46
57
  forEach: () => forEach,
47
58
  getAltText: () => getAltText,
48
59
  getBestRendition: () => getBestRendition,
@@ -54,6 +65,7 @@ __export(src_exports, {
54
65
  getGiphySDKRequestHeaders: () => getGiphySDKRequestHeaders,
55
66
  getPingbackId: () => get_pingback_id_default,
56
67
  getSpecificRendition: () => getSpecificRendition,
68
+ injectTrackingPixel: () => tracking_pixel_default,
57
69
  mapValues: () => mapValues,
58
70
  pick: () => pick,
59
71
  setRenditionScaleUpMaxPixels: () => setRenditionScaleUpMaxPixels,
@@ -166,6 +178,32 @@ function pick(object, pick2) {
166
178
  return res;
167
179
  }
168
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
+
169
207
  // src/get-client-rect-from-el.ts
170
208
  var getClientRect = (el) => {
171
209
  let left = 0;
@@ -338,6 +376,22 @@ var appendGiphySDKRequestParam = (key, value) => {
338
376
  var _a;
339
377
  return (_a = getGiphySDKRequestHeaders()) == null ? void 0 : _a.set(key, value);
340
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;
341
395
  // Annotate the CommonJS export names for ESM import in node:
342
396
  0 && (module.exports = {
343
397
  LogLevel,
@@ -346,6 +400,7 @@ var appendGiphySDKRequestParam = (key, value) => {
346
400
  appendGiphySDKRequestParam,
347
401
  bestfit,
348
402
  checkIfWebP,
403
+ constructMoatData,
349
404
  forEach,
350
405
  getAltText,
351
406
  getBestRendition,
@@ -357,6 +412,7 @@ var appendGiphySDKRequestParam = (key, value) => {
357
412
  getGiphySDKRequestHeaders,
358
413
  getPingbackId,
359
414
  getSpecificRendition,
415
+ injectTrackingPixel,
360
416
  mapValues,
361
417
  pick,
362
418
  setRenditionScaleUpMaxPixels,
@@ -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
@@ -23,6 +23,27 @@ declare function take<T>(arr: T[], count?: number): T[];
23
23
  declare function without<T>(arr: T[], values: T[]): T[];
24
24
  declare function pick<T extends object, U extends keyof T>(object: T, pick: Array<U>): Pick<T, U>;
25
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
+
26
47
  /**
27
48
  * @param el HTMLElement
28
49
  * @returns calculated properties of DOMReact
@@ -74,6 +95,8 @@ declare const getGiphySDKRequestHeaders: () => Headers | undefined;
74
95
  declare const appendGiphySDKRequestHeader: (key: GiphySDKRequestHeader, value: string) => void | undefined;
75
96
  declare const appendGiphySDKRequestParam: (key: GiphySDKRequestHeader, value: string) => void | undefined;
76
97
 
98
+ declare const injectTrackingPixel: (tags?: string[]) => void;
99
+
77
100
  declare const checkIfWebP: Promise<unknown>;
78
101
 
79
- export { LogLevel, Logger, appendGiphySDKRequestHeader, appendGiphySDKRequestParam, bestfit, checkIfWebP, forEach, getAltText, getBestRendition, getBestRenditionUrl, getBestVideo, getClientRect, getGifHeight, getGifWidth, getGiphySDKRequestHeaders, getPingbackId, getSpecificRendition, mapValues, pick, setRenditionScaleUpMaxPixels, take, without };
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.js CHANGED
@@ -122,6 +122,32 @@ function pick(object, pick2) {
122
122
  return res;
123
123
  }
124
124
 
125
+ // src/construct-moat-data.ts
126
+ var constructMoatData = ({ tdata }) => {
127
+ var _a;
128
+ const [moatTrackerData] = ((_a = tdata == null ? void 0 : tdata.web) == null ? void 0 : _a.filter((tracker) => tracker.vendor === "Moat")) || [];
129
+ if (moatTrackerData == null ? void 0 : moatTrackerData.verificationParameters) {
130
+ const {
131
+ moatClientLevel1 = "_ADVERTISER_",
132
+ moatClientLevel2 = "_CAMPAIGN_",
133
+ moatClientLevel3 = "_LINE_ITEM_",
134
+ moatClientLevel4 = "_CREATIVE_",
135
+ moatClientSlicer1 = "_SITE_",
136
+ moatClientSlicer2 = "_PLACEMENT_",
137
+ zMoatPosition = "_POSITION_"
138
+ } = moatTrackerData.verificationParameters;
139
+ return {
140
+ moatClientLevel1,
141
+ moatClientLevel2,
142
+ moatClientLevel3,
143
+ moatClientLevel4,
144
+ moatClientSlicer1,
145
+ moatClientSlicer2,
146
+ zMoatPosition
147
+ };
148
+ }
149
+ };
150
+
125
151
  // src/get-client-rect-from-el.ts
126
152
  var getClientRect = (el) => {
127
153
  let left = 0;
@@ -294,6 +320,22 @@ var appendGiphySDKRequestParam = (key, value) => {
294
320
  var _a;
295
321
  return (_a = getGiphySDKRequestHeaders()) == null ? void 0 : _a.set(key, value);
296
322
  };
323
+
324
+ // src/tracking-pixel.ts
325
+ import DOMPurify from "dompurify";
326
+ var injectTrackingPixel = (tags = []) => {
327
+ tags.forEach((tag) => {
328
+ var _a;
329
+ const el = document.createElement("html");
330
+ tag = tag.replace("%%CACHEBUSTER%%", Date.now().toString());
331
+ el.innerHTML = DOMPurify.sanitize(tag);
332
+ const pixel = el.querySelector("img");
333
+ if (pixel) {
334
+ (_a = document == null ? void 0 : document.querySelector("head")) == null ? void 0 : _a.appendChild(pixel);
335
+ }
336
+ });
337
+ };
338
+ var tracking_pixel_default = injectTrackingPixel;
297
339
  export {
298
340
  LogLevel,
299
341
  Logger,
@@ -301,6 +343,7 @@ export {
301
343
  appendGiphySDKRequestParam,
302
344
  bestfit_default as bestfit,
303
345
  checkIfWebP,
346
+ constructMoatData,
304
347
  forEach,
305
348
  getAltText,
306
349
  getBestRendition,
@@ -312,6 +355,7 @@ export {
312
355
  getGiphySDKRequestHeaders,
313
356
  get_pingback_id_default as getPingbackId,
314
357
  getSpecificRendition,
358
+ tracking_pixel_default as injectTrackingPixel,
315
359
  mapValues,
316
360
  pick,
317
361
  setRenditionScaleUpMaxPixels,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,qCAA4E;AAAnE,mHAAA,OAAO,OAAW;AAAE,uHAAA,4BAA4B,OAAA;AACzD,gDAA6B;AAC7B,qEAAoE;AAA3D,yIAAA,OAAO,OAAiB;AACjC,qDAA4D;AAAnD,iIAAA,OAAO,OAAiB;AACjC,yCAQoB;AAPhB,uGAAA,UAAU,OAAA;AACV,6GAAA,gBAAgB,OAAA;AAChB,gHAAA,mBAAmB,OAAA;AACnB,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,wGAAA,WAAW,OAAA;AACX,iHAAA,oBAAoB,OAAA;AAExB,wCAAqB;AACrB,gDAA6B;AAC7B,2CAA0C;AAAjC,yGAAA,WAAW,OAAA"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3
6
+ }
7
+ export declare const Logger: {
8
+ ENABLED: boolean;
9
+ LEVEL: number;
10
+ PREFIX: string;
11
+ debug: (...msg: any) => void;
12
+ info: (...msg: any) => void;
13
+ warn: (...msg: any) => void;
14
+ error: (...msg: any) => void;
15
+ };
package/dist/log.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Logger = exports.LogLevel = void 0;
13
+ /* istanbul ignore next */
14
+ var LogLevel;
15
+ (function (LogLevel) {
16
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
17
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
18
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
19
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
20
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
21
+ /* istanbul ignore next */
22
+ exports.Logger = {
23
+ ENABLED: typeof window !== 'undefined' &&
24
+ typeof location !== 'undefined' &&
25
+ location.search.indexOf('giphy-debug') !== -1,
26
+ LEVEL: 0,
27
+ PREFIX: 'GiphyJS',
28
+ debug: function () {
29
+ var msg = [];
30
+ for (var _i = 0; _i < arguments.length; _i++) {
31
+ msg[_i] = arguments[_i];
32
+ }
33
+ if (exports.Logger.ENABLED && exports.Logger.LEVEL <= LogLevel.DEBUG) {
34
+ console.debug.apply(console, __spreadArray([exports.Logger.PREFIX], msg, false)); // eslint-disable-line no-console
35
+ }
36
+ },
37
+ info: function () {
38
+ var msg = [];
39
+ for (var _i = 0; _i < arguments.length; _i++) {
40
+ msg[_i] = arguments[_i];
41
+ }
42
+ if (exports.Logger.ENABLED && exports.Logger.LEVEL <= LogLevel.INFO) {
43
+ console.info.apply(console, __spreadArray([exports.Logger.PREFIX], msg, false)); // eslint-disable-line no-console
44
+ }
45
+ },
46
+ warn: function () {
47
+ var msg = [];
48
+ for (var _i = 0; _i < arguments.length; _i++) {
49
+ msg[_i] = arguments[_i];
50
+ }
51
+ if (exports.Logger.ENABLED && exports.Logger.LEVEL <= LogLevel.WARN) {
52
+ console.warn.apply(console, __spreadArray([exports.Logger.PREFIX], msg, false)); // eslint-disable-line no-console
53
+ }
54
+ },
55
+ error: function () {
56
+ var msg = [];
57
+ for (var _i = 0; _i < arguments.length; _i++) {
58
+ msg[_i] = arguments[_i];
59
+ }
60
+ if (exports.Logger.ENABLED && exports.Logger.LEVEL <= LogLevel.ERROR) {
61
+ console.error.apply(console, __spreadArray([exports.Logger.PREFIX], msg, false)); // eslint-disable-line no-console
62
+ }
63
+ },
64
+ };
65
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0BAA0B;AAC1B,IAAY,QAKX;AALD,WAAY,QAAQ;IAChB,yCAAS,CAAA;IACT,uCAAQ,CAAA;IACR,uCAAQ,CAAA;IACR,yCAAS,CAAA;AACb,CAAC,EALW,QAAQ,GAAR,gBAAQ,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AC,KAAK,EAAE;YAClD,OAAO,CAAC,KAAK,OAAb,OAAO,iBAAO,cAAM,CAAC,MAAM,GAAK,GAAG,UAAC,CAAC,iCAAiC;SACzE;IACL,CAAC;CACJ,CAAA"}
@@ -0,0 +1,5 @@
1
+ type GiphySDKRequestHeader = 'X-GIPHY-SDK-NAME' | 'X-GIPHY-SDK-VERSION' | 'X-GIPHY-SDK-PLATFORM';
2
+ export declare const getGiphySDKRequestHeaders: () => Headers | undefined;
3
+ export declare const appendGiphySDKRequestHeader: (key: GiphySDKRequestHeader, value: string) => void | undefined;
4
+ export declare const appendGiphySDKRequestParam: (key: GiphySDKRequestHeader, value: string) => void | undefined;
5
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendGiphySDKRequestParam = exports.appendGiphySDKRequestHeader = exports.getGiphySDKRequestHeaders = void 0;
4
+ var gl = ((typeof window !== 'undefined' ? window : global) || {});
5
+ // define _GIPHY_SDK_HEADERS_ if they don't exist
6
+ gl._GIPHY_SDK_HEADERS_ =
7
+ gl._GIPHY_SDK_HEADERS_ ||
8
+ (gl.Headers
9
+ ? new gl.Headers({
10
+ 'X-GIPHY-SDK-PLATFORM': 'web',
11
+ })
12
+ : undefined);
13
+ var getGiphySDKRequestHeaders = function () { return gl._GIPHY_SDK_HEADERS_; };
14
+ exports.getGiphySDKRequestHeaders = getGiphySDKRequestHeaders;
15
+ var appendGiphySDKRequestHeader = function (key, value) { var _a; return (_a = (0, exports.getGiphySDKRequestHeaders)()) === null || _a === void 0 ? void 0 : _a.set(key, value); };
16
+ exports.appendGiphySDKRequestHeader = appendGiphySDKRequestHeader;
17
+ var appendGiphySDKRequestParam = function (key, value) { var _a; return (_a = (0, exports.getGiphySDKRequestHeaders)()) === null || _a === void 0 ? void 0 : _a.set(key, value); };
18
+ exports.appendGiphySDKRequestParam = appendGiphySDKRequestParam;
19
+ //# sourceMappingURL=sdk-headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-headers.js","sourceRoot":"","sources":["../src/sdk-headers.ts"],"names":[],"mappings":";;;AACA,IAAM,EAAE,GAAG,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAQ,CAAA;AAC3E,iDAAiD;AACjD,EAAE,CAAC,mBAAmB;IAClB,EAAE,CAAC,mBAAmB;QACtB,CAAC,EAAE,CAAC,OAAO;YACP,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC;gBACX,sBAAsB,EAAE,KAAK;aAChC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC,CAAA;AAEb,IAAM,yBAAyB,GAAG,cAA2B,OAAA,EAAE,CAAC,mBAAmB,EAAtB,CAAsB,CAAA;AAA7E,QAAA,yBAAyB,6BAAoD;AAEnF,IAAM,2BAA2B,GAAG,UAAC,GAA0B,EAAE,KAAa,YACjF,OAAA,MAAA,IAAA,iCAAyB,GAAE,0CAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA,EAAA,CAAA;AADnC,QAAA,2BAA2B,+BACQ;AAEzC,IAAM,0BAA0B,GAAG,UAAC,GAA0B,EAAE,KAAa,YAChF,OAAA,MAAA,IAAA,iCAAyB,GAAE,0CAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA,EAAA,CAAA;AADnC,QAAA,0BAA0B,8BACS"}
@@ -0,0 +1,2 @@
1
+ export declare let SUPPORTS_WEBP: null | boolean;
2
+ export declare const checkIfWebP: Promise<unknown>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIfWebP = exports.SUPPORTS_WEBP = void 0;
4
+ exports.SUPPORTS_WEBP = null;
5
+ /* istanbul ignore next */
6
+ exports.checkIfWebP = new Promise(function (resolve) {
7
+ if (typeof Image === 'undefined') {
8
+ resolve(false);
9
+ }
10
+ var webp = new Image();
11
+ webp.onload = function () {
12
+ exports.SUPPORTS_WEBP = true;
13
+ resolve(exports.SUPPORTS_WEBP);
14
+ };
15
+ webp.onerror = function () {
16
+ exports.SUPPORTS_WEBP = false;
17
+ resolve(exports.SUPPORTS_WEBP);
18
+ };
19
+ webp.src =
20
+ 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
21
+ });
22
+ //# sourceMappingURL=webp-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webp-check.js","sourceRoot":"","sources":["../src/webp-check.ts"],"names":[],"mappings":";;;AAAW,QAAA,aAAa,GAAmB,IAAI,CAAA;AAC/C,0BAA0B;AACb,QAAA,WAAW,GAAG,IAAI,OAAO,CAAC,UAAA,OAAO;IAC1C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAC9B,OAAO,CAAC,KAAK,CAAC,CAAA;KACjB;IACD,IAAM,IAAI,GAAG,IAAI,KAAK,EAAE,CAAA;IACxB,IAAI,CAAC,MAAM,GAAG;QACV,qBAAa,GAAG,IAAI,CAAA;QACpB,OAAO,CAAC,qBAAa,CAAC,CAAA;IAC1B,CAAC,CAAA;IACD,IAAI,CAAC,OAAO,GAAG;QACX,qBAAa,GAAG,KAAK,CAAA;QACrB,OAAO,CAAC,qBAAa,CAAC,CAAA;IAC1B,CAAC,CAAA;IACD,IAAI,CAAC,GAAG;QACJ,iHAAiH,CAAA;AACzH,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "test:watch": "run -T jest --config ./jestconfig.js --watchAll"
10
10
  },
11
11
  "name": "@giphy/js-util",
12
- "version": "5.0.0",
12
+ "version": "5.1.0-beta.1",
13
13
  "description": "Shared giphy js utils",
14
14
  "homepage": "https://github.com/Giphy/giphy-js/tree/master/packages/util",
15
15
  "main": "dist/index.cjs",
@@ -34,8 +34,8 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@giphy/js-types": "*",
38
- "dompurify": "^2.2.2",
37
+ "@giphy/js-types": "5.1.0-beta.1",
38
+ "dompurify": "3.1.0",
39
39
  "uuid": "^9.0.0"
40
40
  },
41
41
  "devDependencies": {
@@ -0,0 +1,44 @@
1
+ type MoatData = {
2
+ moatClientLevel1: string
3
+ moatClientLevel2: string
4
+ moatClientLevel3: string
5
+ moatClientLevel4: string
6
+ moatClientSlicer1: string
7
+ moatClientSlicer2: string
8
+ zMoatPosition: string
9
+ zMoatSession?: string
10
+ }
11
+
12
+ type Tracker = {
13
+ vendor: string
14
+ verificationParameters: any
15
+ }
16
+
17
+ type TData = {
18
+ web?: Tracker[]
19
+ }
20
+
21
+ export const constructMoatData = ({ tdata }: { tdata: TData }): MoatData | undefined => {
22
+ const [moatTrackerData] = tdata?.web?.filter((tracker) => tracker.vendor === 'Moat') || []
23
+ if (moatTrackerData?.verificationParameters) {
24
+ const {
25
+ moatClientLevel1 = '_ADVERTISER_',
26
+ moatClientLevel2 = '_CAMPAIGN_',
27
+ moatClientLevel3 = '_LINE_ITEM_',
28
+ moatClientLevel4 = '_CREATIVE_',
29
+ moatClientSlicer1 = '_SITE_',
30
+ moatClientSlicer2 = '_PLACEMENT_',
31
+ zMoatPosition = '_POSITION_',
32
+ } = moatTrackerData.verificationParameters
33
+
34
+ return {
35
+ moatClientLevel1,
36
+ moatClientLevel2,
37
+ moatClientLevel3,
38
+ moatClientLevel4,
39
+ moatClientSlicer1,
40
+ moatClientSlicer2,
41
+ zMoatPosition,
42
+ }
43
+ }
44
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as bestfit, setRenditionScaleUpMaxPixels } from './bestfit'
2
2
  export * from './collections'
3
+ export * from './construct-moat-data'
3
4
  export { default as getClientRect } from './get-client-rect-from-el'
4
5
  export { default as getPingbackId } from './get-pingback-id'
5
6
  export {
@@ -13,4 +14,5 @@ export {
13
14
  } from './gif-utils'
14
15
  export * from './log'
15
16
  export * from './sdk-headers'
17
+ export { default as injectTrackingPixel } from './tracking-pixel'
16
18
  export { checkIfWebP } from './webp-check'
@@ -0,0 +1,15 @@
1
+ import DOMPurify from 'dompurify'
2
+
3
+ const injectTrackingPixel = (tags: string[] = []) => {
4
+ tags.forEach((tag) => {
5
+ const el = document.createElement('html')
6
+ tag = tag.replace('%%CACHEBUSTER%%', Date.now().toString())
7
+ el.innerHTML = DOMPurify.sanitize(tag)
8
+ const pixel = el.querySelector('img')
9
+ if (pixel) {
10
+ document?.querySelector('head')?.appendChild(pixel)
11
+ }
12
+ })
13
+ }
14
+
15
+ export default injectTrackingPixel