@ape.swap/bonds-sdk 2.0.8-seedify2 → 2.0.8
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/main.js
CHANGED
|
@@ -4,7 +4,6 @@ import { useWaitForTransactionReceipt, useChainId, useAccount, useSwitchChain, u
|
|
|
4
4
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { ConnectButton as ConnectButton$1 } from '@rainbow-me/rainbowkit';
|
|
7
|
-
import domtoimage from 'dom-to-image';
|
|
8
7
|
|
|
9
8
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
10
9
|
|
|
@@ -6295,7 +6294,7 @@ const Text$1 = /*#__PURE__*/React__default.forwardRef(function Text(props, ref)
|
|
|
6295
6294
|
* Image style variants can be defined in the theme.images object.
|
|
6296
6295
|
* @see https://theme-ui.com/components/image/
|
|
6297
6296
|
*/
|
|
6298
|
-
const Image = /*#__PURE__*/React__default.forwardRef(function Image(props, ref) {
|
|
6297
|
+
const Image$1 = /*#__PURE__*/React__default.forwardRef(function Image(props, ref) {
|
|
6299
6298
|
const __outerCss = props.__css;
|
|
6300
6299
|
return jsx$2(Box$1, {
|
|
6301
6300
|
ref: ref,
|
|
@@ -71597,8 +71596,8 @@ const remainingPercentage = (bond) => {
|
|
|
71597
71596
|
};
|
|
71598
71597
|
const getDiscountColor = (discount) => {
|
|
71599
71598
|
if (!discount)
|
|
71600
|
-
return '';
|
|
71601
|
-
return discount < 0 ? '
|
|
71599
|
+
return 'white';
|
|
71600
|
+
return discount < 0 ? '#DF4141' : '#38A611';
|
|
71602
71601
|
};
|
|
71603
71602
|
const calculateARR = (bond) => {
|
|
71604
71603
|
const discount2 = 'discount' in bond ? bond.discount : undefined;
|
|
@@ -72876,11 +72875,15 @@ const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
|
|
|
72876
72875
|
: 'BUY' })) }), jsx$2(Flex, { sx: { marginTop: '10px', justifyContent: 'center' }, children: jsx$2(Link, { href: "https://docs.ape.bond/apebond/products-and-features/zap", target: "_blank", rel: "noopener noreferrer", sx: { textDecoration: 'none' }, children: jsxs(Text, { style: { fontSize: '12px', lineHeight: '18px', fontWeight: 400, borderBottom: '1px solid' }, children: ["Learn more", '>'] }) }) })] })] }));
|
|
72877
72876
|
};
|
|
72878
72877
|
|
|
72879
|
-
const AccordionText = ({ isVisible = false }) => {
|
|
72878
|
+
const AccordionText = ({ title, body, isVisible = false }) => {
|
|
72879
|
+
const [isDropdownExpanded, setIsDropdownExpanded] = useState(false);
|
|
72880
|
+
const toggleDropdown = () => {
|
|
72881
|
+
setIsDropdownExpanded(!isDropdownExpanded);
|
|
72882
|
+
};
|
|
72880
72883
|
if (!isVisible) {
|
|
72881
72884
|
return null;
|
|
72882
72885
|
}
|
|
72883
|
-
return (jsxs(Fragment$1, { children: [jsx$2(Flex, { className: "accordion-title", children:
|
|
72886
|
+
return (jsxs(Fragment$1, { children: [jsxs(Flex, { className: "accordion-header", onClick: toggleDropdown, children: [jsx$2(Flex, { className: "accordion-title", children: title }), jsx$2(Flex, { className: "accordion-icon", children: jsx$2(Svg, { icon: "caret", direction: isDropdownExpanded ? 'down' : 'up' }) })] }), jsx$2(AnimatePresence, { children: isDropdownExpanded && (jsx$2(motion.div, { initial: { height: 0 }, animate: { height: 'fit-content' }, transition: { opacity: { duration: 0.2 } }, exit: { height: 0 }, sx: { overflow: 'hidden', width: '100%' }, children: jsx$2(Flex, { className: "accordion-body", children: body }) })) })] }));
|
|
72884
72887
|
};
|
|
72885
72888
|
|
|
72886
72889
|
const useSoulZapBondQuote = (typedValue, inputCurrency, bond, account) => {
|
|
@@ -73124,12 +73127,11 @@ const BondModalHeaderAlt = ({ bondData, onDismiss, showProjectInfoButton, }) =>
|
|
|
73124
73127
|
|
|
73125
73128
|
const BondModal = ({ onDismiss, bondAddress, bondChain, handlePurchasedBond,
|
|
73126
73129
|
// ??
|
|
73127
|
-
accordionTitle = 'What are Bonds?', accordionBody = 'Body', }) => {
|
|
73130
|
+
accordionTitle = 'What are Bonds?', accordionBody = 'Body', accordionVisible = false, }) => {
|
|
73128
73131
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
73129
73132
|
const SDKConfig = useSDKConfig();
|
|
73130
73133
|
// State
|
|
73131
73134
|
const [modalVariant, setModalVariant] = useState(SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.modalVariant);
|
|
73132
|
-
const [accordionVisible, setAccordionVisible] = useState(false);
|
|
73133
73135
|
// Hooks
|
|
73134
73136
|
const userChainId = useChainId();
|
|
73135
73137
|
const { address: account } = useAccount();
|
|
@@ -73327,15 +73329,15 @@ accordionTitle = 'What are Bonds?', accordionBody = 'Body', }) => {
|
|
|
73327
73329
|
(bondData === null || bondData === void 0 ? void 0 : bondData.soldOut) ||
|
|
73328
73330
|
!account ||
|
|
73329
73331
|
!inputValue ||
|
|
73330
|
-
parseFloat(inputValue) === 0, onClick: handleApprove, children: "enable" })) })] })] })] })) })) : (jsx$2(Fragment$1, { children: bondData && (jsxs(Flex, { className: "modal-content font-small gpt", children: [typeof window !== 'undefined' && window.location.origin === 'http://localhost:5173' && (jsxs(Text, { sx: { borderBottom: '1px solid white' }, children: ["Dev Mode - Current view: \"alt\"", jsx$2(Text, { onClick: () => setModalVariant('standard'), sx: { ml: '15px', textDecoration: 'underline', cursor: 'pointer' }, children: "Switch view" })] })), jsxs(Flex, { className: "modaltable-container", sx: { flexDirection: 'row', gap: '20px' }, children: [jsxs(Flex, { sx: { width: '500px', flexDirection: 'column' }, children: [jsx$2("img", { src: "https://placehold.co/400x200" }), jsx$2(Flex, { className: "modaltable-container description-container paragraph-spaced", sx: { marginTop: '20px' }, children: bondData === null || bondData === void 0 ? void 0 : bondData.shortDescription })] }), jsxs(Flex, { sx: { flexDirection: 'column', width: '600px' }, children: [jsxs(Flex, { sx: { alignItems: 'center' }, children: [jsx$2(Flex, { sx: { minWidth: '300px' }, children: jsxs("h2", {
|
|
73331
|
-
|
|
73332
|
+
parseFloat(inputValue) === 0, onClick: handleApprove, children: "enable" })) })] }), accordionVisible && (jsx$2(Flex, { className: "modaltable-container accordion-container", children: jsx$2(AccordionText, { title: accordionTitle, body: accordionBody, isVisible: accordionVisible }) }))] })] })) })) : (jsx$2(Fragment$1, { children: bondData && (jsxs(Flex, { className: "modal-content font-small gpt", children: [typeof window !== 'undefined' && window.location.origin === 'http://localhost:5173' && (jsxs(Text, { sx: { borderBottom: '1px solid white' }, children: ["Dev Mode - Current view: \"alt\"", jsx$2(Text, { onClick: () => setModalVariant('standard'), sx: { ml: '15px', textDecoration: 'underline', cursor: 'pointer' }, children: "Switch view" })] })), jsx$2(Flex, { className: "bondmodal-header-alt", sx: { mb: '20px' }, children: jsx$2(BondModalHeaderAlt, { bondData: bondData, onDismiss: onDismiss, showProjectInfoButton: (SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.referenceId) === 'apebond' }) }), jsxs(Flex, { className: "modaltable-container", sx: { flexDirection: 'row', gap: '20px' }, children: [jsxs(Flex, { sx: { width: '500px', flexDirection: 'column' }, children: [jsx$2("img", { src: "https://placehold.co/400x200" }), jsx$2(Flex, { className: "modaltable-container description-container paragraph-spaced", sx: { marginTop: '20px' }, children: bondData === null || bondData === void 0 ? void 0 : bondData.shortDescription })] }), jsxs(Flex, { sx: { flexDirection: 'column', width: '600px' }, children: [jsxs(Flex, { sx: { alignItems: 'center' }, children: [jsx$2(Flex, { sx: { minWidth: '300px' }, children: jsxs("h2", { sx: { margin: '0px' }, children: [bondData === null || bondData === void 0 ? void 0 : bondData.showcaseTokenName, ' ', jsx$2(Svg, { width: 20, height: 20, icon: (_k = NETWORK_ICONS === null || NETWORK_ICONS === void 0 ? void 0 : NETWORK_ICONS[bondData.chainId]) !== null && _k !== void 0 ? _k : 'question' })] }) }), jsxs(Flex, { sx: { justifyContent: 'space-between', flexGrow: 1 }, children: [jsx$2(TokenImage, { symbol: (_l = bondData.showcaseTokenName) !== null && _l !== void 0 ? _l : bondData.earnToken.symbol, size: 20 }), jsx$2("span", { children: bondData.earnToken.symbol }), " ", jsx$2("span", { children: "|" }), ' ', jsxs("span", { children: ["Market Price: $", earnTokenPrice(bondData)] })] })] }), jsxs(Flex, { sx: { flexDirection: 'column', marginTop: '20px' }, children: [jsx$2(TokenSelectorPanel, { typedValue: inputValue, setTypedValue: setInputValue, selectedToken: inputToken, handleMaxBtn: () => { var _a; return setInputValue((_a = new BigNumber$1(inputCurrencyBalance !== null && inputCurrencyBalance !== void 0 ? inputCurrencyBalance : '0')) === null || _a === void 0 ? void 0 : _a.toString()); }, handleCurrencySelect: handleCurrencySelect, chainId: bondData === null || bondData === void 0 ? void 0 : bondData.chainId, enableZap: true, bondPrincipalToken: bondData === null || bondData === void 0 ? void 0 : bondData.lpToken, tokenBalance: inputCurrencyBalance, selectedTokenPrice: inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price }), jsxs(Flex, { sx: { justifyContent: 'space-between', alignItems: 'center' }, children: [jsxs(Flex, { children: ["You will receive:", jsx$2(Flex, { sx: { marginLeft: '15px', marginRight: '5px' }, children: jsx$2(TokenImage, { symbol: (_m = bondData.showcaseTokenName) !== null && _m !== void 0 ? _m : bondData.earnToken.symbol, size: 20 }) }), (lodashExports.toNumber(inputValue) / lodashExports.toNumber(earnTokenPrice(bondData))).toFixed(0), ' ', bondData.earnToken.symbol, " + \u00A0", (youGet(bondData, inputValue) -
|
|
73333
|
+
lodashExports.toNumber(inputValue) / lodashExports.toNumber(earnTokenPrice(bondData))).toFixed(0), jsx$2("span", { className: "text-highlight", children: "\u00A0additional" })] }), jsx$2(Flex, { className: "button-container buy", sx: { justifyContent: 'end' }, children: !account ? (jsx$2(ConnectButton, {})) : userChainId !== bondData.chainId ? (jsx$2(Button, { className: "switch-button button-narrow", disabled: loadingTx || isConfirming || (bondData === null || bondData === void 0 ? void 0 : bondData.soldOut), onClick: (event) => {
|
|
73332
73334
|
event.stopPropagation();
|
|
73333
73335
|
switchChain({ chainId: bondData.chainId });
|
|
73334
|
-
}, children: `Switch to ${NETWORK_LABEL[bondData.chainId]}` })) : approvalState === ApprovalState.APPROVED ? (jsxs(Button, { className: "action-button", load: load, disabled: load || (bondData === null || bondData === void 0 ? void 0 : bondData.soldOut) || !account || !inputValue || parseFloat(inputValue) === 0, onClick: handleBothPurchases, children: ["buy",
|
|
73336
|
+
}, children: `Switch to ${NETWORK_LABEL[bondData.chainId]}` })) : approvalState === ApprovalState.APPROVED ? (jsxs(Button, { className: "action-button", load: load, disabled: load || (bondData === null || bondData === void 0 ? void 0 : bondData.soldOut) || !account || !inputValue || parseFloat(inputValue) === 0, onClick: handleBothPurchases, children: ["buy ", isZap ? 'zap' : 'normal'] })) : (jsx$2(Button, { className: "action-button", load: approvalState === ApprovalState.PENDING, disabled: approvalState === ApprovalState.PENDING ||
|
|
73335
73337
|
(bondData === null || bondData === void 0 ? void 0 : bondData.soldOut) ||
|
|
73336
73338
|
!account ||
|
|
73337
73339
|
!inputValue ||
|
|
73338
|
-
parseFloat(inputValue) === 0, onClick: handleApprove, children: "enable" })) })] }), jsx$2(Flex, { sx: { width: '100%', marginTop: '10px', marginBottom: '10px' }, children: jsx$2("hr", { className: "fading-hr" }) }), jsxs(Flex, { sx: { width: '100%' }, children: [jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["Market Price: $", formatUSDNumber((youGet(bondData, inputValue) * lodashExports.toNumber(earnTokenPrice(bondData))).toString()), jsx$2("hr", { className: "fading-hr" }), jsx$2("span", { className: "text-highlight flex-inline", children: "Our price: " }), jsxs("span", { className: "flex-inline", children: ["$", formatUSDNumber((lodashExports.toNumber(inputValue) * lodashExports.toNumber(bondData.principalTokenPrice)).toString()), ' '] }), jsxs("span", { className: "text-highlight flex-inline", children: ["(discount rate ", bondData === null || bondData === void 0 ? void 0 : bondData.discount.toFixed(2), "%)"] })] }), jsx$2(Flex, { sx: { width: '50px', alignItems: 'center', justifyContent: 'center' }, children: "vs." }), jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["If purchased from market:", ' ', (lodashExports.toNumber(inputValue) / lodashExports.toNumber(earnTokenPrice(bondData))).toFixed(0), ' ', bondData.earnToken.symbol, jsx$2("hr", { className: "fading-hr" }), jsx$2("span", { className: "text-highlight flex-inline", children: "Amount you will get:" }), ' ', youGet(bondData, inputValue).toFixed(0), ' ', jsx$2("span", { className: "flex-inline", children: bondData.earnToken.symbol })] })] })] })] })] }), jsxs(Flex, { className: "footer-details", children: [jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting start date:", ' ', new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }).format(new Date())] }), jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting end date:", ' ', new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }).format(new Date(Date.now() + vestingTime((_o = bondData === null || bondData === void 0 ? void 0 : bondData.vestingTerm) !== null && _o !== void 0 ? _o : 0).days * 86400000))] }), jsx$2(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: "Vesting type: Linear" }),
|
|
73340
|
+
parseFloat(inputValue) === 0, onClick: handleApprove, children: "enable" })) })] }), jsx$2(Flex, { sx: { width: '100%', marginTop: '10px', marginBottom: '10px' }, children: jsx$2("hr", { className: "fading-hr" }) }), jsxs(Flex, { sx: { width: '100%' }, children: [jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["Market Price: $", formatUSDNumber((youGet(bondData, inputValue) * lodashExports.toNumber(earnTokenPrice(bondData))).toString()), jsx$2("hr", { className: "fading-hr" }), jsx$2("span", { className: "text-highlight flex-inline", children: "Our price: " }), jsxs("span", { className: "flex-inline", children: ["$", formatUSDNumber((lodashExports.toNumber(inputValue) * lodashExports.toNumber(bondData.principalTokenPrice)).toString()), ' '] }), jsxs("span", { className: "text-highlight flex-inline", children: ["(discount rate ", bondData === null || bondData === void 0 ? void 0 : bondData.discount.toFixed(2), "%)"] })] }), jsx$2(Flex, { sx: { width: '50px', alignItems: 'center', justifyContent: 'center' }, children: "vs." }), jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["If purchased from market:", ' ', (lodashExports.toNumber(inputValue) / lodashExports.toNumber(earnTokenPrice(bondData))).toFixed(0), ' ', bondData.earnToken.symbol, jsx$2("hr", { className: "fading-hr" }), jsx$2("span", { className: "text-highlight flex-inline", children: "Amount you will get:" }), ' ', youGet(bondData, inputValue).toFixed(0), ' ', jsx$2("span", { className: "flex-inline", children: bondData.earnToken.symbol })] })] })] })] })] }), jsxs(Flex, { className: "footer-details", children: [jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting start date:", ' ', new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }).format(new Date())] }), jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting end date:", ' ', new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }).format(new Date(Date.now() + vestingTime((_o = bondData === null || bondData === void 0 ? void 0 : bondData.vestingTerm) !== null && _o !== void 0 ? _o : 0).days * 86400000))] }), jsx$2(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: "Vesting type: Linear" }), jsx$2(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: "What are bonds?" })] }), accordionVisible && (jsx$2(Flex, { className: "modaltable-container accordion-container", children: jsx$2(AccordionText, { title: accordionTitle, body: accordionBody, isVisible: accordionVisible }) }))] })) })) }));
|
|
73339
73341
|
};
|
|
73340
73342
|
|
|
73341
73343
|
/*
|
|
@@ -73568,7 +73570,7 @@ const BondRow = ({ bond }) => {
|
|
|
73568
73570
|
const tokens = new BigNumber$1(tokensRemaining);
|
|
73569
73571
|
return tokens.times(payoutTokenPrice);
|
|
73570
73572
|
};
|
|
73571
|
-
return (jsxs("div", { className: "bond-row", onClick: handleOpenModal, children: [jsx$2("div", { className: "token-info-container", children: jsx$2(TokenInfoAndName, { bill: bond }) }), jsxs("div", { className: "bond-info-columns", children: [jsx$2("div", { className:
|
|
73573
|
+
return (jsxs("div", { className: "bond-row", onClick: handleOpenModal, children: [jsx$2("div", { className: "token-info-container", children: jsx$2(TokenInfoAndName, { bill: bond }) }), jsxs("div", { className: "bond-info-columns", children: [jsx$2("div", { className: "discount-column", style: { color: getDiscountColor(discount) }, children: discount !== undefined ? `${discount === null || discount === void 0 ? void 0 : discount.toFixed(2)}%` : '-' }), jsx$2("div", { className: "arr-column", children: calculateARR(bond) !== undefined ? calculateARR(bond) : '-' }), jsx$2("div", { className: "terms-column", children: ((_a = vestingTime(bond === null || bond === void 0 ? void 0 : bond.vestingTerm)) === null || _a === void 0 ? void 0 : _a.days) ? `${(_b = vestingTime(bond === null || bond === void 0 ? void 0 : bond.vestingTerm)) === null || _b === void 0 ? void 0 : _b.days} D` : '-' }), jsx$2("div", { className: "tokens-remaining-column", children: jsx$2(ProgressBarWrapper$1, { title: '', value: jsx$2(ProgressBar, { value: remainingPercentage(bond) }), style: {
|
|
73572
73574
|
width: '127px',
|
|
73573
73575
|
height: '25px',
|
|
73574
73576
|
flexDirection: 'column',
|
|
@@ -73827,7 +73829,7 @@ const RecommendationCards$1 = () => {
|
|
|
73827
73829
|
color: 'grey',
|
|
73828
73830
|
fontSize: ['11px'],
|
|
73829
73831
|
fontWeight: 500,
|
|
73830
|
-
}, children: "BONDS MARKETS:" }), jsx$2(RecommendationSelector, { options: options, activeOption: activeOption, setActiveOption: setActiveOption })] }), jsx$2(Flex, { sx: { display: ['none', 'none', 'none', 'flex'] }, children: jsx$2(Image, { width: 190, height: 20, alt: "poweredBy", src: "/images/bills/powered.png", sx: {
|
|
73832
|
+
}, children: "BONDS MARKETS:" }), jsx$2(RecommendationSelector, { options: options, activeOption: activeOption, setActiveOption: setActiveOption })] }), jsx$2(Flex, { sx: { display: ['none', 'none', 'none', 'flex'] }, children: jsx$2(Image$1, { width: 190, height: 20, alt: "poweredBy", src: "/images/bills/powered.png", sx: {
|
|
73831
73833
|
width: '190px',
|
|
73832
73834
|
height: '20px',
|
|
73833
73835
|
cursor: 'pointer',
|
|
@@ -90523,6 +90525,779 @@ const ProjectViewWithProviders = (props) => {
|
|
|
90523
90525
|
return (jsx$2(Providers, { children: jsx$2(ProjectView, Object.assign({}, props)) }));
|
|
90524
90526
|
};
|
|
90525
90527
|
|
|
90528
|
+
var domToImage = {exports: {}};
|
|
90529
|
+
|
|
90530
|
+
(function (module) {
|
|
90531
|
+
(function (global) {
|
|
90532
|
+
|
|
90533
|
+
var util = newUtil();
|
|
90534
|
+
var inliner = newInliner();
|
|
90535
|
+
var fontFaces = newFontFaces();
|
|
90536
|
+
var images = newImages();
|
|
90537
|
+
|
|
90538
|
+
// Default impl options
|
|
90539
|
+
var defaultOptions = {
|
|
90540
|
+
// Default is to fail on error, no placeholder
|
|
90541
|
+
imagePlaceholder: undefined,
|
|
90542
|
+
// Default cache bust is false, it will use the cache
|
|
90543
|
+
cacheBust: false
|
|
90544
|
+
};
|
|
90545
|
+
|
|
90546
|
+
var domtoimage = {
|
|
90547
|
+
toSvg: toSvg,
|
|
90548
|
+
toPng: toPng,
|
|
90549
|
+
toJpeg: toJpeg,
|
|
90550
|
+
toBlob: toBlob,
|
|
90551
|
+
toPixelData: toPixelData,
|
|
90552
|
+
impl: {
|
|
90553
|
+
fontFaces: fontFaces,
|
|
90554
|
+
images: images,
|
|
90555
|
+
util: util,
|
|
90556
|
+
inliner: inliner,
|
|
90557
|
+
options: {}
|
|
90558
|
+
}
|
|
90559
|
+
};
|
|
90560
|
+
|
|
90561
|
+
module.exports = domtoimage;
|
|
90562
|
+
|
|
90563
|
+
|
|
90564
|
+
/**
|
|
90565
|
+
* @param {Node} node - The DOM Node object to render
|
|
90566
|
+
* @param {Object} options - Rendering options
|
|
90567
|
+
* @param {Function} options.filter - Should return true if passed node should be included in the output
|
|
90568
|
+
* (excluding node means excluding it's children as well). Not called on the root node.
|
|
90569
|
+
* @param {String} options.bgcolor - color for the background, any valid CSS color value.
|
|
90570
|
+
* @param {Number} options.width - width to be applied to node before rendering.
|
|
90571
|
+
* @param {Number} options.height - height to be applied to node before rendering.
|
|
90572
|
+
* @param {Object} options.style - an object whose properties to be copied to node's style before rendering.
|
|
90573
|
+
* @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
|
|
90574
|
+
defaults to 1.0.
|
|
90575
|
+
* @param {String} options.imagePlaceholder - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
|
|
90576
|
+
* @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
|
|
90577
|
+
* @return {Promise} - A promise that is fulfilled with a SVG image data URL
|
|
90578
|
+
* */
|
|
90579
|
+
function toSvg(node, options) {
|
|
90580
|
+
options = options || {};
|
|
90581
|
+
copyOptions(options);
|
|
90582
|
+
return Promise.resolve(node)
|
|
90583
|
+
.then(function (node) {
|
|
90584
|
+
return cloneNode(node, options.filter, true);
|
|
90585
|
+
})
|
|
90586
|
+
.then(embedFonts)
|
|
90587
|
+
.then(inlineImages)
|
|
90588
|
+
.then(applyOptions)
|
|
90589
|
+
.then(function (clone) {
|
|
90590
|
+
return makeSvgDataUri(clone,
|
|
90591
|
+
options.width || util.width(node),
|
|
90592
|
+
options.height || util.height(node)
|
|
90593
|
+
);
|
|
90594
|
+
});
|
|
90595
|
+
|
|
90596
|
+
function applyOptions(clone) {
|
|
90597
|
+
if (options.bgcolor) clone.style.backgroundColor = options.bgcolor;
|
|
90598
|
+
|
|
90599
|
+
if (options.width) clone.style.width = options.width + 'px';
|
|
90600
|
+
if (options.height) clone.style.height = options.height + 'px';
|
|
90601
|
+
|
|
90602
|
+
if (options.style)
|
|
90603
|
+
Object.keys(options.style).forEach(function (property) {
|
|
90604
|
+
clone.style[property] = options.style[property];
|
|
90605
|
+
});
|
|
90606
|
+
|
|
90607
|
+
return clone;
|
|
90608
|
+
}
|
|
90609
|
+
}
|
|
90610
|
+
|
|
90611
|
+
/**
|
|
90612
|
+
* @param {Node} node - The DOM Node object to render
|
|
90613
|
+
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
90614
|
+
* @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data.
|
|
90615
|
+
* */
|
|
90616
|
+
function toPixelData(node, options) {
|
|
90617
|
+
return draw(node, options || {})
|
|
90618
|
+
.then(function (canvas) {
|
|
90619
|
+
return canvas.getContext('2d').getImageData(
|
|
90620
|
+
0,
|
|
90621
|
+
0,
|
|
90622
|
+
util.width(node),
|
|
90623
|
+
util.height(node)
|
|
90624
|
+
).data;
|
|
90625
|
+
});
|
|
90626
|
+
}
|
|
90627
|
+
|
|
90628
|
+
/**
|
|
90629
|
+
* @param {Node} node - The DOM Node object to render
|
|
90630
|
+
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
90631
|
+
* @return {Promise} - A promise that is fulfilled with a PNG image data URL
|
|
90632
|
+
* */
|
|
90633
|
+
function toPng(node, options) {
|
|
90634
|
+
return draw(node, options || {})
|
|
90635
|
+
.then(function (canvas) {
|
|
90636
|
+
return canvas.toDataURL();
|
|
90637
|
+
});
|
|
90638
|
+
}
|
|
90639
|
+
|
|
90640
|
+
/**
|
|
90641
|
+
* @param {Node} node - The DOM Node object to render
|
|
90642
|
+
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
90643
|
+
* @return {Promise} - A promise that is fulfilled with a JPEG image data URL
|
|
90644
|
+
* */
|
|
90645
|
+
function toJpeg(node, options) {
|
|
90646
|
+
options = options || {};
|
|
90647
|
+
return draw(node, options)
|
|
90648
|
+
.then(function (canvas) {
|
|
90649
|
+
return canvas.toDataURL('image/jpeg', options.quality || 1.0);
|
|
90650
|
+
});
|
|
90651
|
+
}
|
|
90652
|
+
|
|
90653
|
+
/**
|
|
90654
|
+
* @param {Node} node - The DOM Node object to render
|
|
90655
|
+
* @param {Object} options - Rendering options, @see {@link toSvg}
|
|
90656
|
+
* @return {Promise} - A promise that is fulfilled with a PNG image blob
|
|
90657
|
+
* */
|
|
90658
|
+
function toBlob(node, options) {
|
|
90659
|
+
return draw(node, options || {})
|
|
90660
|
+
.then(util.canvasToBlob);
|
|
90661
|
+
}
|
|
90662
|
+
|
|
90663
|
+
function copyOptions(options) {
|
|
90664
|
+
// Copy options to impl options for use in impl
|
|
90665
|
+
if(typeof(options.imagePlaceholder) === 'undefined') {
|
|
90666
|
+
domtoimage.impl.options.imagePlaceholder = defaultOptions.imagePlaceholder;
|
|
90667
|
+
} else {
|
|
90668
|
+
domtoimage.impl.options.imagePlaceholder = options.imagePlaceholder;
|
|
90669
|
+
}
|
|
90670
|
+
|
|
90671
|
+
if(typeof(options.cacheBust) === 'undefined') {
|
|
90672
|
+
domtoimage.impl.options.cacheBust = defaultOptions.cacheBust;
|
|
90673
|
+
} else {
|
|
90674
|
+
domtoimage.impl.options.cacheBust = options.cacheBust;
|
|
90675
|
+
}
|
|
90676
|
+
}
|
|
90677
|
+
|
|
90678
|
+
function draw(domNode, options) {
|
|
90679
|
+
return toSvg(domNode, options)
|
|
90680
|
+
.then(util.makeImage)
|
|
90681
|
+
.then(util.delay(100))
|
|
90682
|
+
.then(function (image) {
|
|
90683
|
+
var canvas = newCanvas(domNode);
|
|
90684
|
+
canvas.getContext('2d').drawImage(image, 0, 0);
|
|
90685
|
+
return canvas;
|
|
90686
|
+
});
|
|
90687
|
+
|
|
90688
|
+
function newCanvas(domNode) {
|
|
90689
|
+
var canvas = document.createElement('canvas');
|
|
90690
|
+
canvas.width = options.width || util.width(domNode);
|
|
90691
|
+
canvas.height = options.height || util.height(domNode);
|
|
90692
|
+
|
|
90693
|
+
if (options.bgcolor) {
|
|
90694
|
+
var ctx = canvas.getContext('2d');
|
|
90695
|
+
ctx.fillStyle = options.bgcolor;
|
|
90696
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
90697
|
+
}
|
|
90698
|
+
|
|
90699
|
+
return canvas;
|
|
90700
|
+
}
|
|
90701
|
+
}
|
|
90702
|
+
|
|
90703
|
+
function cloneNode(node, filter, root) {
|
|
90704
|
+
if (!root && filter && !filter(node)) return Promise.resolve();
|
|
90705
|
+
|
|
90706
|
+
return Promise.resolve(node)
|
|
90707
|
+
.then(makeNodeCopy)
|
|
90708
|
+
.then(function (clone) {
|
|
90709
|
+
return cloneChildren(node, clone, filter);
|
|
90710
|
+
})
|
|
90711
|
+
.then(function (clone) {
|
|
90712
|
+
return processClone(node, clone);
|
|
90713
|
+
});
|
|
90714
|
+
|
|
90715
|
+
function makeNodeCopy(node) {
|
|
90716
|
+
if (node instanceof HTMLCanvasElement) return util.makeImage(node.toDataURL());
|
|
90717
|
+
return node.cloneNode(false);
|
|
90718
|
+
}
|
|
90719
|
+
|
|
90720
|
+
function cloneChildren(original, clone, filter) {
|
|
90721
|
+
var children = original.childNodes;
|
|
90722
|
+
if (children.length === 0) return Promise.resolve(clone);
|
|
90723
|
+
|
|
90724
|
+
return cloneChildrenInOrder(clone, util.asArray(children), filter)
|
|
90725
|
+
.then(function () {
|
|
90726
|
+
return clone;
|
|
90727
|
+
});
|
|
90728
|
+
|
|
90729
|
+
function cloneChildrenInOrder(parent, children, filter) {
|
|
90730
|
+
var done = Promise.resolve();
|
|
90731
|
+
children.forEach(function (child) {
|
|
90732
|
+
done = done
|
|
90733
|
+
.then(function () {
|
|
90734
|
+
return cloneNode(child, filter);
|
|
90735
|
+
})
|
|
90736
|
+
.then(function (childClone) {
|
|
90737
|
+
if (childClone) parent.appendChild(childClone);
|
|
90738
|
+
});
|
|
90739
|
+
});
|
|
90740
|
+
return done;
|
|
90741
|
+
}
|
|
90742
|
+
}
|
|
90743
|
+
|
|
90744
|
+
function processClone(original, clone) {
|
|
90745
|
+
if (!(clone instanceof Element)) return clone;
|
|
90746
|
+
|
|
90747
|
+
return Promise.resolve()
|
|
90748
|
+
.then(cloneStyle)
|
|
90749
|
+
.then(clonePseudoElements)
|
|
90750
|
+
.then(copyUserInput)
|
|
90751
|
+
.then(fixSvg)
|
|
90752
|
+
.then(function () {
|
|
90753
|
+
return clone;
|
|
90754
|
+
});
|
|
90755
|
+
|
|
90756
|
+
function cloneStyle() {
|
|
90757
|
+
copyStyle(window.getComputedStyle(original), clone.style);
|
|
90758
|
+
|
|
90759
|
+
function copyStyle(source, target) {
|
|
90760
|
+
if (source.cssText) target.cssText = source.cssText;
|
|
90761
|
+
else copyProperties(source, target);
|
|
90762
|
+
|
|
90763
|
+
function copyProperties(source, target) {
|
|
90764
|
+
util.asArray(source).forEach(function (name) {
|
|
90765
|
+
target.setProperty(
|
|
90766
|
+
name,
|
|
90767
|
+
source.getPropertyValue(name),
|
|
90768
|
+
source.getPropertyPriority(name)
|
|
90769
|
+
);
|
|
90770
|
+
});
|
|
90771
|
+
}
|
|
90772
|
+
}
|
|
90773
|
+
}
|
|
90774
|
+
|
|
90775
|
+
function clonePseudoElements() {
|
|
90776
|
+
[':before', ':after'].forEach(function (element) {
|
|
90777
|
+
clonePseudoElement(element);
|
|
90778
|
+
});
|
|
90779
|
+
|
|
90780
|
+
function clonePseudoElement(element) {
|
|
90781
|
+
var style = window.getComputedStyle(original, element);
|
|
90782
|
+
var content = style.getPropertyValue('content');
|
|
90783
|
+
|
|
90784
|
+
if (content === '' || content === 'none') return;
|
|
90785
|
+
|
|
90786
|
+
var className = util.uid();
|
|
90787
|
+
clone.className = clone.className + ' ' + className;
|
|
90788
|
+
var styleElement = document.createElement('style');
|
|
90789
|
+
styleElement.appendChild(formatPseudoElementStyle(className, element, style));
|
|
90790
|
+
clone.appendChild(styleElement);
|
|
90791
|
+
|
|
90792
|
+
function formatPseudoElementStyle(className, element, style) {
|
|
90793
|
+
var selector = '.' + className + ':' + element;
|
|
90794
|
+
var cssText = style.cssText ? formatCssText(style) : formatCssProperties(style);
|
|
90795
|
+
return document.createTextNode(selector + '{' + cssText + '}');
|
|
90796
|
+
|
|
90797
|
+
function formatCssText(style) {
|
|
90798
|
+
var content = style.getPropertyValue('content');
|
|
90799
|
+
return style.cssText + ' content: ' + content + ';';
|
|
90800
|
+
}
|
|
90801
|
+
|
|
90802
|
+
function formatCssProperties(style) {
|
|
90803
|
+
|
|
90804
|
+
return util.asArray(style)
|
|
90805
|
+
.map(formatProperty)
|
|
90806
|
+
.join('; ') + ';';
|
|
90807
|
+
|
|
90808
|
+
function formatProperty(name) {
|
|
90809
|
+
return name + ': ' +
|
|
90810
|
+
style.getPropertyValue(name) +
|
|
90811
|
+
(style.getPropertyPriority(name) ? ' !important' : '');
|
|
90812
|
+
}
|
|
90813
|
+
}
|
|
90814
|
+
}
|
|
90815
|
+
}
|
|
90816
|
+
}
|
|
90817
|
+
|
|
90818
|
+
function copyUserInput() {
|
|
90819
|
+
if (original instanceof HTMLTextAreaElement) clone.innerHTML = original.value;
|
|
90820
|
+
if (original instanceof HTMLInputElement) clone.setAttribute("value", original.value);
|
|
90821
|
+
}
|
|
90822
|
+
|
|
90823
|
+
function fixSvg() {
|
|
90824
|
+
if (!(clone instanceof SVGElement)) return;
|
|
90825
|
+
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
90826
|
+
|
|
90827
|
+
if (!(clone instanceof SVGRectElement)) return;
|
|
90828
|
+
['width', 'height'].forEach(function (attribute) {
|
|
90829
|
+
var value = clone.getAttribute(attribute);
|
|
90830
|
+
if (!value) return;
|
|
90831
|
+
|
|
90832
|
+
clone.style.setProperty(attribute, value);
|
|
90833
|
+
});
|
|
90834
|
+
}
|
|
90835
|
+
}
|
|
90836
|
+
}
|
|
90837
|
+
|
|
90838
|
+
function embedFonts(node) {
|
|
90839
|
+
return fontFaces.resolveAll()
|
|
90840
|
+
.then(function (cssText) {
|
|
90841
|
+
var styleNode = document.createElement('style');
|
|
90842
|
+
node.appendChild(styleNode);
|
|
90843
|
+
styleNode.appendChild(document.createTextNode(cssText));
|
|
90844
|
+
return node;
|
|
90845
|
+
});
|
|
90846
|
+
}
|
|
90847
|
+
|
|
90848
|
+
function inlineImages(node) {
|
|
90849
|
+
return images.inlineAll(node)
|
|
90850
|
+
.then(function () {
|
|
90851
|
+
return node;
|
|
90852
|
+
});
|
|
90853
|
+
}
|
|
90854
|
+
|
|
90855
|
+
function makeSvgDataUri(node, width, height) {
|
|
90856
|
+
return Promise.resolve(node)
|
|
90857
|
+
.then(function (node) {
|
|
90858
|
+
node.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
90859
|
+
return new XMLSerializer().serializeToString(node);
|
|
90860
|
+
})
|
|
90861
|
+
.then(util.escapeXhtml)
|
|
90862
|
+
.then(function (xhtml) {
|
|
90863
|
+
return '<foreignObject x="0" y="0" width="100%" height="100%">' + xhtml + '</foreignObject>';
|
|
90864
|
+
})
|
|
90865
|
+
.then(function (foreignObject) {
|
|
90866
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + width + '" height="' + height + '">' +
|
|
90867
|
+
foreignObject + '</svg>';
|
|
90868
|
+
})
|
|
90869
|
+
.then(function (svg) {
|
|
90870
|
+
return 'data:image/svg+xml;charset=utf-8,' + svg;
|
|
90871
|
+
});
|
|
90872
|
+
}
|
|
90873
|
+
|
|
90874
|
+
function newUtil() {
|
|
90875
|
+
return {
|
|
90876
|
+
escape: escape,
|
|
90877
|
+
parseExtension: parseExtension,
|
|
90878
|
+
mimeType: mimeType,
|
|
90879
|
+
dataAsUrl: dataAsUrl,
|
|
90880
|
+
isDataUrl: isDataUrl,
|
|
90881
|
+
canvasToBlob: canvasToBlob,
|
|
90882
|
+
resolveUrl: resolveUrl,
|
|
90883
|
+
getAndEncode: getAndEncode,
|
|
90884
|
+
uid: uid(),
|
|
90885
|
+
delay: delay,
|
|
90886
|
+
asArray: asArray,
|
|
90887
|
+
escapeXhtml: escapeXhtml,
|
|
90888
|
+
makeImage: makeImage,
|
|
90889
|
+
width: width,
|
|
90890
|
+
height: height
|
|
90891
|
+
};
|
|
90892
|
+
|
|
90893
|
+
function mimes() {
|
|
90894
|
+
/*
|
|
90895
|
+
* Only WOFF and EOT mime types for fonts are 'real'
|
|
90896
|
+
* see http://www.iana.org/assignments/media-types/media-types.xhtml
|
|
90897
|
+
*/
|
|
90898
|
+
var WOFF = 'application/font-woff';
|
|
90899
|
+
var JPEG = 'image/jpeg';
|
|
90900
|
+
|
|
90901
|
+
return {
|
|
90902
|
+
'woff': WOFF,
|
|
90903
|
+
'woff2': WOFF,
|
|
90904
|
+
'ttf': 'application/font-truetype',
|
|
90905
|
+
'eot': 'application/vnd.ms-fontobject',
|
|
90906
|
+
'png': 'image/png',
|
|
90907
|
+
'jpg': JPEG,
|
|
90908
|
+
'jpeg': JPEG,
|
|
90909
|
+
'gif': 'image/gif',
|
|
90910
|
+
'tiff': 'image/tiff',
|
|
90911
|
+
'svg': 'image/svg+xml'
|
|
90912
|
+
};
|
|
90913
|
+
}
|
|
90914
|
+
|
|
90915
|
+
function parseExtension(url) {
|
|
90916
|
+
var match = /\.([^\.\/]*?)$/g.exec(url);
|
|
90917
|
+
if (match) return match[1];
|
|
90918
|
+
else return '';
|
|
90919
|
+
}
|
|
90920
|
+
|
|
90921
|
+
function mimeType(url) {
|
|
90922
|
+
var extension = parseExtension(url).toLowerCase();
|
|
90923
|
+
return mimes()[extension] || '';
|
|
90924
|
+
}
|
|
90925
|
+
|
|
90926
|
+
function isDataUrl(url) {
|
|
90927
|
+
return url.search(/^(data:)/) !== -1;
|
|
90928
|
+
}
|
|
90929
|
+
|
|
90930
|
+
function toBlob(canvas) {
|
|
90931
|
+
return new Promise(function (resolve) {
|
|
90932
|
+
var binaryString = window.atob(canvas.toDataURL().split(',')[1]);
|
|
90933
|
+
var length = binaryString.length;
|
|
90934
|
+
var binaryArray = new Uint8Array(length);
|
|
90935
|
+
|
|
90936
|
+
for (var i = 0; i < length; i++)
|
|
90937
|
+
binaryArray[i] = binaryString.charCodeAt(i);
|
|
90938
|
+
|
|
90939
|
+
resolve(new Blob([binaryArray], {
|
|
90940
|
+
type: 'image/png'
|
|
90941
|
+
}));
|
|
90942
|
+
});
|
|
90943
|
+
}
|
|
90944
|
+
|
|
90945
|
+
function canvasToBlob(canvas) {
|
|
90946
|
+
if (canvas.toBlob)
|
|
90947
|
+
return new Promise(function (resolve) {
|
|
90948
|
+
canvas.toBlob(resolve);
|
|
90949
|
+
});
|
|
90950
|
+
|
|
90951
|
+
return toBlob(canvas);
|
|
90952
|
+
}
|
|
90953
|
+
|
|
90954
|
+
function resolveUrl(url, baseUrl) {
|
|
90955
|
+
var doc = document.implementation.createHTMLDocument();
|
|
90956
|
+
var base = doc.createElement('base');
|
|
90957
|
+
doc.head.appendChild(base);
|
|
90958
|
+
var a = doc.createElement('a');
|
|
90959
|
+
doc.body.appendChild(a);
|
|
90960
|
+
base.href = baseUrl;
|
|
90961
|
+
a.href = url;
|
|
90962
|
+
return a.href;
|
|
90963
|
+
}
|
|
90964
|
+
|
|
90965
|
+
function uid() {
|
|
90966
|
+
var index = 0;
|
|
90967
|
+
|
|
90968
|
+
return function () {
|
|
90969
|
+
return 'u' + fourRandomChars() + index++;
|
|
90970
|
+
|
|
90971
|
+
function fourRandomChars() {
|
|
90972
|
+
/* see http://stackoverflow.com/a/6248722/2519373 */
|
|
90973
|
+
return ('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4);
|
|
90974
|
+
}
|
|
90975
|
+
};
|
|
90976
|
+
}
|
|
90977
|
+
|
|
90978
|
+
function makeImage(uri) {
|
|
90979
|
+
return new Promise(function (resolve, reject) {
|
|
90980
|
+
var image = new Image();
|
|
90981
|
+
image.onload = function () {
|
|
90982
|
+
resolve(image);
|
|
90983
|
+
};
|
|
90984
|
+
image.onerror = reject;
|
|
90985
|
+
image.src = uri;
|
|
90986
|
+
});
|
|
90987
|
+
}
|
|
90988
|
+
|
|
90989
|
+
function getAndEncode(url) {
|
|
90990
|
+
var TIMEOUT = 30000;
|
|
90991
|
+
if(domtoimage.impl.options.cacheBust) {
|
|
90992
|
+
// Cache bypass so we dont have CORS issues with cached images
|
|
90993
|
+
// Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
|
|
90994
|
+
url += ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
|
|
90995
|
+
}
|
|
90996
|
+
|
|
90997
|
+
return new Promise(function (resolve) {
|
|
90998
|
+
var request = new XMLHttpRequest();
|
|
90999
|
+
|
|
91000
|
+
request.onreadystatechange = done;
|
|
91001
|
+
request.ontimeout = timeout;
|
|
91002
|
+
request.responseType = 'blob';
|
|
91003
|
+
request.timeout = TIMEOUT;
|
|
91004
|
+
request.open('GET', url, true);
|
|
91005
|
+
request.send();
|
|
91006
|
+
|
|
91007
|
+
var placeholder;
|
|
91008
|
+
if(domtoimage.impl.options.imagePlaceholder) {
|
|
91009
|
+
var split = domtoimage.impl.options.imagePlaceholder.split(/,/);
|
|
91010
|
+
if(split && split[1]) {
|
|
91011
|
+
placeholder = split[1];
|
|
91012
|
+
}
|
|
91013
|
+
}
|
|
91014
|
+
|
|
91015
|
+
function done() {
|
|
91016
|
+
if (request.readyState !== 4) return;
|
|
91017
|
+
|
|
91018
|
+
if (request.status !== 200) {
|
|
91019
|
+
if(placeholder) {
|
|
91020
|
+
resolve(placeholder);
|
|
91021
|
+
} else {
|
|
91022
|
+
fail('cannot fetch resource: ' + url + ', status: ' + request.status);
|
|
91023
|
+
}
|
|
91024
|
+
|
|
91025
|
+
return;
|
|
91026
|
+
}
|
|
91027
|
+
|
|
91028
|
+
var encoder = new FileReader();
|
|
91029
|
+
encoder.onloadend = function () {
|
|
91030
|
+
var content = encoder.result.split(/,/)[1];
|
|
91031
|
+
resolve(content);
|
|
91032
|
+
};
|
|
91033
|
+
encoder.readAsDataURL(request.response);
|
|
91034
|
+
}
|
|
91035
|
+
|
|
91036
|
+
function timeout() {
|
|
91037
|
+
if(placeholder) {
|
|
91038
|
+
resolve(placeholder);
|
|
91039
|
+
} else {
|
|
91040
|
+
fail('timeout of ' + TIMEOUT + 'ms occured while fetching resource: ' + url);
|
|
91041
|
+
}
|
|
91042
|
+
}
|
|
91043
|
+
|
|
91044
|
+
function fail(message) {
|
|
91045
|
+
console.error(message);
|
|
91046
|
+
resolve('');
|
|
91047
|
+
}
|
|
91048
|
+
});
|
|
91049
|
+
}
|
|
91050
|
+
|
|
91051
|
+
function dataAsUrl(content, type) {
|
|
91052
|
+
return 'data:' + type + ';base64,' + content;
|
|
91053
|
+
}
|
|
91054
|
+
|
|
91055
|
+
function escape(string) {
|
|
91056
|
+
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1');
|
|
91057
|
+
}
|
|
91058
|
+
|
|
91059
|
+
function delay(ms) {
|
|
91060
|
+
return function (arg) {
|
|
91061
|
+
return new Promise(function (resolve) {
|
|
91062
|
+
setTimeout(function () {
|
|
91063
|
+
resolve(arg);
|
|
91064
|
+
}, ms);
|
|
91065
|
+
});
|
|
91066
|
+
};
|
|
91067
|
+
}
|
|
91068
|
+
|
|
91069
|
+
function asArray(arrayLike) {
|
|
91070
|
+
var array = [];
|
|
91071
|
+
var length = arrayLike.length;
|
|
91072
|
+
for (var i = 0; i < length; i++) array.push(arrayLike[i]);
|
|
91073
|
+
return array;
|
|
91074
|
+
}
|
|
91075
|
+
|
|
91076
|
+
function escapeXhtml(string) {
|
|
91077
|
+
return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
|
|
91078
|
+
}
|
|
91079
|
+
|
|
91080
|
+
function width(node) {
|
|
91081
|
+
var leftBorder = px(node, 'border-left-width');
|
|
91082
|
+
var rightBorder = px(node, 'border-right-width');
|
|
91083
|
+
return node.scrollWidth + leftBorder + rightBorder;
|
|
91084
|
+
}
|
|
91085
|
+
|
|
91086
|
+
function height(node) {
|
|
91087
|
+
var topBorder = px(node, 'border-top-width');
|
|
91088
|
+
var bottomBorder = px(node, 'border-bottom-width');
|
|
91089
|
+
return node.scrollHeight + topBorder + bottomBorder;
|
|
91090
|
+
}
|
|
91091
|
+
|
|
91092
|
+
function px(node, styleProperty) {
|
|
91093
|
+
var value = window.getComputedStyle(node).getPropertyValue(styleProperty);
|
|
91094
|
+
return parseFloat(value.replace('px', ''));
|
|
91095
|
+
}
|
|
91096
|
+
}
|
|
91097
|
+
|
|
91098
|
+
function newInliner() {
|
|
91099
|
+
var URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g;
|
|
91100
|
+
|
|
91101
|
+
return {
|
|
91102
|
+
inlineAll: inlineAll,
|
|
91103
|
+
shouldProcess: shouldProcess,
|
|
91104
|
+
impl: {
|
|
91105
|
+
readUrls: readUrls,
|
|
91106
|
+
inline: inline
|
|
91107
|
+
}
|
|
91108
|
+
};
|
|
91109
|
+
|
|
91110
|
+
function shouldProcess(string) {
|
|
91111
|
+
return string.search(URL_REGEX) !== -1;
|
|
91112
|
+
}
|
|
91113
|
+
|
|
91114
|
+
function readUrls(string) {
|
|
91115
|
+
var result = [];
|
|
91116
|
+
var match;
|
|
91117
|
+
while ((match = URL_REGEX.exec(string)) !== null) {
|
|
91118
|
+
result.push(match[1]);
|
|
91119
|
+
}
|
|
91120
|
+
return result.filter(function (url) {
|
|
91121
|
+
return !util.isDataUrl(url);
|
|
91122
|
+
});
|
|
91123
|
+
}
|
|
91124
|
+
|
|
91125
|
+
function inline(string, url, baseUrl, get) {
|
|
91126
|
+
return Promise.resolve(url)
|
|
91127
|
+
.then(function (url) {
|
|
91128
|
+
return baseUrl ? util.resolveUrl(url, baseUrl) : url;
|
|
91129
|
+
})
|
|
91130
|
+
.then(get || util.getAndEncode)
|
|
91131
|
+
.then(function (data) {
|
|
91132
|
+
return util.dataAsUrl(data, util.mimeType(url));
|
|
91133
|
+
})
|
|
91134
|
+
.then(function (dataUrl) {
|
|
91135
|
+
return string.replace(urlAsRegex(url), '$1' + dataUrl + '$3');
|
|
91136
|
+
});
|
|
91137
|
+
|
|
91138
|
+
function urlAsRegex(url) {
|
|
91139
|
+
return new RegExp('(url\\([\'"]?)(' + util.escape(url) + ')([\'"]?\\))', 'g');
|
|
91140
|
+
}
|
|
91141
|
+
}
|
|
91142
|
+
|
|
91143
|
+
function inlineAll(string, baseUrl, get) {
|
|
91144
|
+
if (nothingToInline()) return Promise.resolve(string);
|
|
91145
|
+
|
|
91146
|
+
return Promise.resolve(string)
|
|
91147
|
+
.then(readUrls)
|
|
91148
|
+
.then(function (urls) {
|
|
91149
|
+
var done = Promise.resolve(string);
|
|
91150
|
+
urls.forEach(function (url) {
|
|
91151
|
+
done = done.then(function (string) {
|
|
91152
|
+
return inline(string, url, baseUrl, get);
|
|
91153
|
+
});
|
|
91154
|
+
});
|
|
91155
|
+
return done;
|
|
91156
|
+
});
|
|
91157
|
+
|
|
91158
|
+
function nothingToInline() {
|
|
91159
|
+
return !shouldProcess(string);
|
|
91160
|
+
}
|
|
91161
|
+
}
|
|
91162
|
+
}
|
|
91163
|
+
|
|
91164
|
+
function newFontFaces() {
|
|
91165
|
+
return {
|
|
91166
|
+
resolveAll: resolveAll,
|
|
91167
|
+
impl: {
|
|
91168
|
+
readAll: readAll
|
|
91169
|
+
}
|
|
91170
|
+
};
|
|
91171
|
+
|
|
91172
|
+
function resolveAll() {
|
|
91173
|
+
return readAll()
|
|
91174
|
+
.then(function (webFonts) {
|
|
91175
|
+
return Promise.all(
|
|
91176
|
+
webFonts.map(function (webFont) {
|
|
91177
|
+
return webFont.resolve();
|
|
91178
|
+
})
|
|
91179
|
+
);
|
|
91180
|
+
})
|
|
91181
|
+
.then(function (cssStrings) {
|
|
91182
|
+
return cssStrings.join('\n');
|
|
91183
|
+
});
|
|
91184
|
+
}
|
|
91185
|
+
|
|
91186
|
+
function readAll() {
|
|
91187
|
+
return Promise.resolve(util.asArray(document.styleSheets))
|
|
91188
|
+
.then(getCssRules)
|
|
91189
|
+
.then(selectWebFontRules)
|
|
91190
|
+
.then(function (rules) {
|
|
91191
|
+
return rules.map(newWebFont);
|
|
91192
|
+
});
|
|
91193
|
+
|
|
91194
|
+
function selectWebFontRules(cssRules) {
|
|
91195
|
+
return cssRules
|
|
91196
|
+
.filter(function (rule) {
|
|
91197
|
+
return rule.type === CSSRule.FONT_FACE_RULE;
|
|
91198
|
+
})
|
|
91199
|
+
.filter(function (rule) {
|
|
91200
|
+
return inliner.shouldProcess(rule.style.getPropertyValue('src'));
|
|
91201
|
+
});
|
|
91202
|
+
}
|
|
91203
|
+
|
|
91204
|
+
function getCssRules(styleSheets) {
|
|
91205
|
+
var cssRules = [];
|
|
91206
|
+
styleSheets.forEach(function (sheet) {
|
|
91207
|
+
try {
|
|
91208
|
+
util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules));
|
|
91209
|
+
} catch (e) {
|
|
91210
|
+
console.log('Error while reading CSS rules from ' + sheet.href, e.toString());
|
|
91211
|
+
}
|
|
91212
|
+
});
|
|
91213
|
+
return cssRules;
|
|
91214
|
+
}
|
|
91215
|
+
|
|
91216
|
+
function newWebFont(webFontRule) {
|
|
91217
|
+
return {
|
|
91218
|
+
resolve: function resolve() {
|
|
91219
|
+
var baseUrl = (webFontRule.parentStyleSheet || {}).href;
|
|
91220
|
+
return inliner.inlineAll(webFontRule.cssText, baseUrl);
|
|
91221
|
+
},
|
|
91222
|
+
src: function () {
|
|
91223
|
+
return webFontRule.style.getPropertyValue('src');
|
|
91224
|
+
}
|
|
91225
|
+
};
|
|
91226
|
+
}
|
|
91227
|
+
}
|
|
91228
|
+
}
|
|
91229
|
+
|
|
91230
|
+
function newImages() {
|
|
91231
|
+
return {
|
|
91232
|
+
inlineAll: inlineAll,
|
|
91233
|
+
impl: {
|
|
91234
|
+
newImage: newImage
|
|
91235
|
+
}
|
|
91236
|
+
};
|
|
91237
|
+
|
|
91238
|
+
function newImage(element) {
|
|
91239
|
+
return {
|
|
91240
|
+
inline: inline
|
|
91241
|
+
};
|
|
91242
|
+
|
|
91243
|
+
function inline(get) {
|
|
91244
|
+
if (util.isDataUrl(element.src)) return Promise.resolve();
|
|
91245
|
+
|
|
91246
|
+
return Promise.resolve(element.src)
|
|
91247
|
+
.then(get || util.getAndEncode)
|
|
91248
|
+
.then(function (data) {
|
|
91249
|
+
return util.dataAsUrl(data, util.mimeType(element.src));
|
|
91250
|
+
})
|
|
91251
|
+
.then(function (dataUrl) {
|
|
91252
|
+
return new Promise(function (resolve, reject) {
|
|
91253
|
+
element.onload = resolve;
|
|
91254
|
+
element.onerror = reject;
|
|
91255
|
+
element.src = dataUrl;
|
|
91256
|
+
});
|
|
91257
|
+
});
|
|
91258
|
+
}
|
|
91259
|
+
}
|
|
91260
|
+
|
|
91261
|
+
function inlineAll(node) {
|
|
91262
|
+
if (!(node instanceof Element)) return Promise.resolve(node);
|
|
91263
|
+
|
|
91264
|
+
return inlineBackground(node)
|
|
91265
|
+
.then(function () {
|
|
91266
|
+
if (node instanceof HTMLImageElement)
|
|
91267
|
+
return newImage(node).inline();
|
|
91268
|
+
else
|
|
91269
|
+
return Promise.all(
|
|
91270
|
+
util.asArray(node.childNodes).map(function (child) {
|
|
91271
|
+
return inlineAll(child);
|
|
91272
|
+
})
|
|
91273
|
+
);
|
|
91274
|
+
});
|
|
91275
|
+
|
|
91276
|
+
function inlineBackground(node) {
|
|
91277
|
+
var background = node.style.getPropertyValue('background');
|
|
91278
|
+
|
|
91279
|
+
if (!background) return Promise.resolve(node);
|
|
91280
|
+
|
|
91281
|
+
return inliner.inlineAll(background)
|
|
91282
|
+
.then(function (inlined) {
|
|
91283
|
+
node.style.setProperty(
|
|
91284
|
+
'background',
|
|
91285
|
+
inlined,
|
|
91286
|
+
node.style.getPropertyPriority('background')
|
|
91287
|
+
);
|
|
91288
|
+
})
|
|
91289
|
+
.then(function () {
|
|
91290
|
+
return node;
|
|
91291
|
+
});
|
|
91292
|
+
}
|
|
91293
|
+
}
|
|
91294
|
+
}
|
|
91295
|
+
})();
|
|
91296
|
+
} (domToImage));
|
|
91297
|
+
|
|
91298
|
+
var domToImageExports = domToImage.exports;
|
|
91299
|
+
var domtoimage = /*@__PURE__*/getDefaultExportFromCjs(domToImageExports);
|
|
91300
|
+
|
|
90526
91301
|
function getTemplateHTML(data) {
|
|
90527
91302
|
var _a, _b, _c;
|
|
90528
91303
|
const isProfit = data.data.payout * +data.data.payoutTokenPrice - data.data.dollarValue > 0;
|