@wistia/wistia-player-react
Version:
An embeddable wistia-player web component and React wrapper to add responsive, lightweight, and SEO-friendly videos to your site.
96 lines (89 loc) • 3.29 kB
JavaScript
// ../../node_modules/@wistia/type-guards/dist/index.mjs
var FALSY_VALUES = [false, 0, -0, 0n, "", null, void 0, Number.NaN];
var isNull = (value) => value === null;
var isUndefined = (value) => value === void 0;
var isNil = (value) => isNull(value) || isUndefined(value);
var isNotNil = (value) => !isNil(value);
var isString = (value) => typeof value === "string";
var isNumber = (value) => typeof value === "number";
var isFunction = (value) => isNotNil(value) && typeof value === "function";
var isBoolean = (value) => isNotNil(value) && typeof value === "boolean";
// src/utils/getMergedEmbedOption.ts
var isValidEmbedOption = (value) => {
return isNumber(value) || isString(value) || isBoolean(value);
};
var getMergedEmbedOption = (mediaId, optionKey, optionValue) => {
let finalEmbedOption = optionValue;
if (typeof window === "undefined") {
return finalEmbedOption;
}
if (isNotNil(window.wistiaOptions?._all) && isNotNil(window.wistiaOptions._all[optionKey]) && isValidEmbedOption(window.wistiaOptions._all[optionKey])) {
finalEmbedOption = window.wistiaOptions._all[optionKey];
}
if (isNotNil(window.wistiaOptions?.[mediaId]) && isNotNil(window.wistiaOptions[mediaId]) && isValidEmbedOption(window.wistiaOptions[mediaId][optionKey])) {
finalEmbedOption = window.wistiaOptions[mediaId][optionKey];
}
return finalEmbedOption;
};
// src/utils/camelCaseToKebabCase.ts
var camelCaseToKebabCase = (str) => {
return str.replace(
/[A-Z]+(?![a-z])|[A-Z]/g,
(letter, idx) => (idx !== 0 ? "-" : "") + letter.toLowerCase()
);
};
// src/utils/swatch.ts
var getSwatchMetaData = async (url) => {
const swatch = new Image();
swatch.src = url;
await swatch.decode();
return swatch;
};
var swatchUrl = (mediaId, embedHost) => `https://${embedHost}/embed/medias/${mediaId}/swatch`;
var getSwatchAspectRatio = async (mediaId, embedHost = "fast.wistia.com") => {
const swatchImg = await getSwatchMetaData(swatchUrl(mediaId, embedHost));
const { naturalHeight, naturalWidth } = swatchImg;
return naturalWidth / naturalHeight;
};
var wistiaPlayerStyleBlock = ({
mediaId,
embedHost = "fast.wistia.com",
aspect = 1.7,
shouldLoadSwatch = true,
roundedPlayer = 0
}) => {
const CSSProperties = {
background: shouldLoadSwatch ? `center / contain no-repeat url(${swatchUrl(mediaId, embedHost)})` : void 0,
borderRadius: `${roundedPlayer}px`,
display: "block",
filter: "blur(5px)",
paddingTop: `${100 / aspect}%`
};
return `
wistia-player[media-id='${mediaId}']:not(:defined) {
${Object.entries(CSSProperties).map(([key, value]) => `${camelCaseToKebabCase(key)}: ${value};`).join("\r\n")}
}
wistia-player[media-id='${mediaId}']:state(--initializing) {
${Object.entries(CSSProperties).map(([key, value]) => `${camelCaseToKebabCase(key)}: ${value};`).join("\r\n")}
}
`;
};
export {
isString,
isFunction,
isValidEmbedOption,
getMergedEmbedOption,
camelCaseToKebabCase,
getSwatchAspectRatio,
wistiaPlayerStyleBlock
};
/*! Bundled license information:
@wistia/type-guards/dist/index.mjs:
(*
* @license @wistia/type-guards v0.9.1
*
* Copyright (c) 2023-2025, Wistia, Inc. and its affiliates.
*
* This source code is unlicensed, all rights reserved.
*)
*/