html2canvas-pro
Version:
Screenshots with JavaScript. Next generation!
72 lines • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Html2CanvasConfig = void 0;
exports.setDefaultConfig = setDefaultConfig;
exports.getDefaultConfig = getDefaultConfig;
/**
* Html2Canvas Configuration
*
* Manages configuration state for html2canvas rendering.
* Eliminates the need for global static variables.
*/
class Html2CanvasConfig {
constructor(options = {}) {
// Try to get window from options first, then fall back to global window
this.window = options.window || (typeof window !== 'undefined' ? window : null);
if (!this.window) {
throw new Error('Window object is required but not available');
}
this.cspNonce = options.cspNonce;
this.cache = options.cache;
}
/**
* Create configuration from an element
* Extracts window from element's owner document
*/
static fromElement(element, options = {}) {
const ownerDocument = element.ownerDocument;
if (!ownerDocument) {
throw new Error('Element is not attached to a document');
}
const defaultView = ownerDocument.defaultView;
if (!defaultView) {
throw new Error('Document is not attached to a window');
}
return new Html2CanvasConfig({
window: defaultView,
...options
});
}
/**
* Clone configuration with override options
*/
clone(options = {}) {
return new Html2CanvasConfig({
window: options.window || this.window,
cspNonce: options.cspNonce ?? this.cspNonce,
cache: options.cache ?? this.cache
});
}
}
exports.Html2CanvasConfig = Html2CanvasConfig;
/**
* Default global configuration (for backward compatibility)
* @deprecated Use Html2CanvasConfig instances instead
*/
let _defaultConfig = null;
/**
* Set default configuration
* @deprecated Pass configuration directly to html2canvas instead
*/
function setDefaultConfig(config) {
console.warn('[html2canvas-pro] setDefaultConfig is deprecated. Pass configuration to html2canvas directly.');
_defaultConfig = config;
}
/**
* Get default configuration
* @deprecated Pass configuration directly to html2canvas instead
*/
function getDefaultConfig() {
return _defaultConfig;
}
//# sourceMappingURL=config.js.map