HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/wpforms-pdf/assets/js/builder.js
/* global wpformsPDF, wpf, WPFormsUtils */

/**
 * @param             window.wpformsPDF
 * @param             window.wpformsPDFThemes
 * @param             defaults.template
 * @param             defaults.page_background_color
 * @param             defaults.container_background_color
 * @param             defaults.text_color
 * @param             defaults.link_color
 * @param             defaults.logo_url
 * @param             defaults.logo_size
 * @param             defaults.font
 * @typedef  {Object} wpforms_builder_settings            Builder settings.
 * @property {Object} choicesjs_config                    Choices.js config.
 */

/**
 * WPForms PDF builder.
 *
 * @since 1.0.0
 */
const WPFormsPDFBuilder = window.WPFormsPDFBuilder || ( function( document, window, $ ) {
	/**
	 * Elements holder.
	 *
	 * @since 1.0.0
	 *
	 * @type {Object}
	 */
	const el = {};

	/**
	 * Public functions and properties.
	 *
	 * @since 1.0.0
	 */
	const app = {
		/**
		 * State variables (runtime).
		 *
		 * @since 1.0.0
		 *
		 * @type {Object}
		 */
		state: {
			pdfs: {},
		},
		/**
		 * Start the engine.
		 *
		 * @since 1.0.0
		 */
		init() {
			$( app.ready );
		},

		/**
		 * Start the engine.
		 *
		 * @since 1.0.0
		 */
		ready() {
			app.setup();
			app.loadModules();
		},

		/**
		 * Setup. Prepare some variables.
		 *
		 * @since 1.0.0
		 */
		setup() {
			// Cache DOM elements.
			el.$builder = $( '#wpforms-builder' );
		},

		/**
		 * Load modules.
		 *
		 * @since 1.0.0
		 */
		loadModules() {
			const modules = wpformsPDF.modules || [];

			// Import all modules dynamically.
			Promise.all( modules.map( ( module ) => import( module.path ) ) )
				.then( ( importedModules ) => {
					importedModules.forEach( ( module, index ) => {
						const moduleName = modules[ index ].name;
						app[ moduleName ] = module.default( document, window, $ );

						// Initialize module on `wpformsPDFLoaded` event.
						el.$builder.on( `wpformsPDFLoaded`, app[ moduleName ].init );
					} );

					// Trigger `wpformsPDFLoaded` event.
					WPFormsUtils.triggerEvent( el.$builder, 'wpformsPDFLoaded', [ importedModules ] );
				} )
				.catch( ( error ) => {
					wpf.debug( 'Error importing modules:', error );
				} );
		},

		/**
		 * Set state variable.
		 *
		 * @since 1.0.0
		 *
		 * @param {string}      varName Variable key.
		 * @param {string}      value   Variable value.
		 * @param {number|null} pdfId   PDF Id.
		 */
		setState( varName, value, pdfId = null ) {
			if ( pdfId ) {
				app.state.pdfs[ pdfId ] = app.state.pdfs[ pdfId ] ?? {};
				app.state.pdfs[ pdfId ][ varName ] = value;

				return;
			}

			app.state[ varName ] = value;
		},

		/**
		 * Set state variable.
		 *
		 * @since 1.0.0
		 *
		 * @param {string}      varName Variable key.
		 * @param {number|null} pdfId   PDF Id.
		 *
		 * @return {any} Variable value.
		 */
		getState( varName, pdfId = null ) {
			if ( pdfId ) {
				return app.state.pdfs[ pdfId ]?.[ varName ];
			}

			return app.state[ varName ];
		},
	};

	// Return the public facing methods.
	return app;
}( document, window, jQuery ) );

// Initialize.
WPFormsPDFBuilder.init();