@giphy/js-util
Advanced tools
Comparing version 1.0.5 to 1.0.6
import { IGif, IRendition } from '@giphy/js-types'; | ||
import { IImages } from '@giphy/js-types/dist/gif'; | ||
export declare const checkIfWebP: () => Promise<{}>; | ||
export declare const getSpecificRendition: ({ images, is_sticker: isSticker }: IGif, renditionLabel: string, isStill?: boolean, useVideo?: boolean) => string; | ||
@@ -11,2 +10,3 @@ interface IRenditionWithName extends IRendition { | ||
export declare const getGifHeight: ({ images }: IGif, gifWidth: number) => number; | ||
export declare const getGifWidth: ({ images }: IGif, gifHeight: number) => number; | ||
/** | ||
@@ -13,0 +13,0 @@ * GIF Text - Alt Text: Generates alt text for |
@@ -19,21 +19,3 @@ "use strict"; | ||
var bestfit_1 = __importDefault(require("./bestfit")); | ||
var SUPPORTS_WEBP = null; | ||
exports.checkIfWebP = function () { | ||
return new Promise(function (resolve) { | ||
if (SUPPORTS_WEBP !== null) { | ||
return resolve(); | ||
} | ||
var webp = new Image(); | ||
webp.onload = function () { | ||
SUPPORTS_WEBP = true; | ||
resolve(); | ||
}; | ||
webp.onerror = function () { | ||
SUPPORTS_WEBP = false; | ||
resolve(); | ||
}; | ||
webp.src = | ||
'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA'; | ||
}); | ||
}; | ||
var webp_check_1 = require("./webp-check"); | ||
exports.getSpecificRendition = function (_a, renditionLabel, isStill, useVideo) { | ||
@@ -45,2 +27,3 @@ var images = _a.images, isSticker = _a.is_sticker; | ||
return ''; | ||
isStill = isStill && !useVideo; | ||
// @ts-ignore come back to this | ||
@@ -52,3 +35,3 @@ var rendition = images["" + renditionLabel + (isStill ? '_still' : '')]; | ||
} | ||
var webP = SUPPORTS_WEBP && rendition.webp; | ||
var webP = webp_check_1.SUPPORTS_WEBP && rendition.webp; | ||
return useVideo ? rendition.mp4 : webP || rendition.url; | ||
@@ -79,5 +62,6 @@ } | ||
var renditionName = exports.getBestRendition(images, gifWidth, gifHeight).renditionName; | ||
var key = "" + renditionName + (isStill && !useVideo ? '_still' : ''); | ||
// @ts-ignore come back to this | ||
var rendition = images["" + renditionName + (isStill ? '_still' : '')]; | ||
var match = useVideo ? rendition.mp4 : SUPPORTS_WEBP && rendition.webp ? rendition.webp : rendition.url; | ||
var rendition = images[key]; | ||
var match = useVideo ? rendition.mp4 : webp_check_1.SUPPORTS_WEBP && rendition.webp ? rendition.webp : rendition.url; | ||
return match || ''; | ||
@@ -95,2 +79,12 @@ }; | ||
}; | ||
exports.getGifWidth = function (_a, gifHeight) { | ||
var images = _a.images; | ||
var fixed_width = images.fixed_width; | ||
if (fixed_width) { | ||
var width = fixed_width.width, height = fixed_width.height; | ||
var aspectRatio = width / height; | ||
return Math.round(gifHeight * aspectRatio); | ||
} | ||
return 0; | ||
}; | ||
/** | ||
@@ -109,4 +103,4 @@ * GIF Text - Alt Text: Generates alt text for | ||
var filteredTags = collections_1.take(collections_1.without(tags, ['transparent']), username ? 4 : 5); | ||
return username + " " + filteredTags.join(' ') + " " + (is_sticker ? 'Sticker' : 'GIF'); | ||
return "" + (username ? username + " " : "") + filteredTags.join(' ') + " " + (is_sticker ? 'Sticker' : 'GIF'); | ||
}; | ||
//# sourceMappingURL=gif-utils.js.map |
@@ -1,4 +0,5 @@ | ||
export { checkIfWebP, getAltText, getBestRenditionUrl, getBestRendition, getGifHeight, getSpecificRendition, } from './gif-utils'; | ||
export { getAltText, getBestRenditionUrl, getBestRendition, getGifHeight, getSpecificRendition, getGifWidth, } from './gif-utils'; | ||
export { checkIfWebP } from './webp-check'; | ||
export { default as bestfit } from './bestfit'; | ||
export { default as getClientRect } from './get-client-rect-from-el'; | ||
export * from './collections'; |
@@ -7,3 +7,2 @@ "use strict"; | ||
var gif_utils_1 = require("./gif-utils"); | ||
exports.checkIfWebP = gif_utils_1.checkIfWebP; | ||
exports.getAltText = gif_utils_1.getAltText; | ||
@@ -14,2 +13,5 @@ exports.getBestRenditionUrl = gif_utils_1.getBestRenditionUrl; | ||
exports.getSpecificRendition = gif_utils_1.getSpecificRendition; | ||
exports.getGifWidth = gif_utils_1.getGifWidth; | ||
var webp_check_1 = require("./webp-check"); | ||
exports.checkIfWebP = webp_check_1.checkIfWebP; | ||
var bestfit_1 = require("./bestfit"); | ||
@@ -16,0 +18,0 @@ exports.bestfit = bestfit_1.default; |
@@ -6,3 +6,3 @@ { | ||
"prepublish": "npm run clean && tsc", | ||
"refresh": "tsc", | ||
"build": "tsc", | ||
"test": "jest --config ./jestconfig.js", | ||
@@ -12,3 +12,3 @@ "test:watch": "jest --config ./jestconfig.js --watchAll" | ||
"name": "@giphy/js-util", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "dist/index.js", | ||
@@ -21,3 +21,3 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@giphy/js-types": "^1.0.5" | ||
"@giphy/js-types": "^1.0.6" | ||
}, | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "f05648f2d7571d864513dbc041447e328e163738" | ||
"gitHead": "28535e55d485cb4cc4a22cc2b829791e5c0c1c32" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21680
20
304
Updated@giphy/js-types@^1.0.6