### Configure Presentation Timer Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/notes/notes.html Initializes a timer and clock display that updates every second. It calculates elapsed time from the start and formats the output for the speaker interface. ```javascript function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ); function _updateTimer() { var diff = new Date().getTime() - start.getTime(); /* ... calculation logic ... */ } setInterval( _updateTimer, 1000 ); } ``` -------------------------------- ### Define PHP Function Syntax Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/markdown/example.html A simple PHP function example demonstrating array initialization. This snippet is used to show syntax highlighting capabilities within the presentation. ```php public function foo() { $foo = array( 'bar' => 'bar' ); } ``` -------------------------------- ### Initialize Presentation Sync and UI Components Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/notes-server/notes.html Sets up socket connections, initializes iframes for current and upcoming slides, and configures event listeners for keyboard inputs and state changes. It ensures the speaker view remains synchronized with the main presentation. ```javascript (function() { var notes, notesValue, currentState, currentSlide, upcomingSlide, connected = false; var socket = io.connect( window.location.origin ), socketId = '{{socketId}}'; socket.on( 'statechanged', function( data ) { if( data.socketId !== socketId ) { return; } if( connected === false ) { connected = true; setupKeyboard(); setupNotes(); setupTimer(); } handleStateMessage( data ); } ); setupIframes(); window.addEventListener( 'message', function( event ) { var data = JSON.parse( event.data ); if( data && data.namespace === 'reveal' ) { if( /ready/.test( data.eventName ) ) { socket.emit( 'new-subscriber', { socketId: socketId } ); } } if( data && data.namespace === 'reveal' ) { if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) { socket.emit( 'statechanged-speaker', { state: data.state } ); } } } ); })(); ``` -------------------------------- ### PPTX Conversion Entry Point - JavaScript Source: https://context7.com/g21589/pptx2html/llms.txt The `processPPTX` function initiates the conversion of a PPTX file to HTML. It's designed to be run within a Web Worker, receiving the file data as an ArrayBuffer from the main thread. The process involves parsing the ZIP archive, content types, themes, and then iterating through each slide. ```javascript var worker = new Worker('./js/worker.js'); var reader = new FileReader(); reader.onload = function(e) { worker.postMessage({ "type": "processPPTX", "data": e.target.result // ArrayBuffer of the PPTX file }); }; reader.readAsArrayBuffer(pptxFile); // Inside worker.js: // var zip = new JSZip(data); // var filesInfo = getContentTypes(zip); // var slideSize = getSlideSize(zip); // themeContent = loadTheme(zip); // For each slide: processSingleSlide(zip, filename, i, slideSize); ``` -------------------------------- ### Initialize Reveal.js Configuration Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/markdown/example.html The JavaScript configuration object for Reveal.js. It defines global presentation settings and loads necessary dependencies like Markdown parsers and syntax highlighters. ```javascript Reveal.initialize({ controls: true, progress: true, history: true, center: true, dependencies: [ { src: '../../lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: '../highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: '../notes/notes.js' } ] }); ``` -------------------------------- ### Initialize Reveal.js Speaker Notes Messaging Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/notes/notes.html Sets up an event listener to handle cross-window messages using the postMessage API. It coordinates connections and state updates between the presentation and the notes interface. ```javascript window.addEventListener( 'message', function( event ) { var data = JSON.parse( event.data ); if( data && data.namespace === 'reveal-notes' ) { if( data.type === 'connect' ) { handleConnectMessage( data ); } else if( data.type === 'state' ) { handleStateMessage( data ); } } } ); ``` -------------------------------- ### JavaScript for Loading and Initializing Reveal.js Presentation Source: https://github.com/g21589/pptx2html/blob/master/reveal/demo.html This JavaScript code snippet handles the loading and decompression of presentation slides from local storage and initializes the Reveal.js framework. It checks for browser support for Web Storage, decompresses slide data using LZString, and configures Reveal.js with specified dimensions, controls, and a highlight.js dependency. ```javascript if (localStorage) { document.getElementById("target").innerHTML = LZString.decompressFromUTF16(localStorage.getItem("slides")); } else { alert("Browser don't support Web Storage!"); } Reveal.initialize({ width: +localStorage.getItem("slideWidth"), height: +localStorage.getItem("slideHeight"), controls: true, progress: true, history: true, center: true, transition: 'convex', dependencies: [ { src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector('pre code'); }, callback: function() { hljs.initHighlightingOnLoad(); } } ] }); ``` -------------------------------- ### XML Parsing and Simplification Source: https://github.com/g21589/pptx2html/blob/master/test/xmlTest.html This snippet demonstrates parsing an XML string and then simplifying the parsed structure. It utilizes functions like tXml and simplefy. The output is then stringified for display. Performance is measured using performance.now(). ```JavaScript var a = performance.now(); var output2 = simplefy(tXml(xml)); var b = performance.now(); document.getElementById("output1").innerHTML = JSON.stringify(tXml(xml)); document.getElementById("output2").innerHTML = JSON.stringify(output2); document.getElementById("rt").innerHTML = 'It took ' + (b - a) + ' ms.'; ``` -------------------------------- ### Implement Speaker Timer and Clock Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/notes-server/notes.html Creates a live timer and clock display for the speaker interface. It calculates elapsed time since initialization and updates the DOM elements every second. ```javascript function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } setInterval( _updateTimer, 1000 ); } ``` -------------------------------- ### Initialize Web Worker for PPTX Processing Source: https://context7.com/g21589/pptx2html/llms.txt Handles file input via FileReader and initializes a Web Worker to process PPTX files asynchronously. It listens for various message types from the worker to update the UI, including progress, slide content, and metadata. ```javascript $(document).ready(function() { if (window.Worker) { var $result = $("#result"); var isDone = false; $("#uploadBtn").on("change", function(evt) { isDone = false; $result.html(""); var fileName = evt.target.files[0]; var reader = new FileReader(); reader.onload = function(e) { var worker = new Worker('./js/worker.js'); worker.addEventListener('message', function(e) { var msg = e.data; switch(msg.type) { case "progress-update": $("#load-progress").text(msg.data.toFixed(2) + "%").css("width", msg.data.toFixed(2) + "%"); break; case "slide": $result.append(msg.data); break; case "pptx-thumb": $("#pptx-thumb").attr("src", "data:image/jpeg;base64," + msg.data); break; case "slideSize": localStorage.setItem("slideWidth", msg.data.width); localStorage.setItem("slideHeight", msg.data.height); break; case "globalCSS": $result.append(""); break; case "ExecutionTime": $("#info_block").html("Execution Time: " + msg.data + " (ms)"); isDone = true; worker.postMessage({ "type": "getMsgQueue" }); break; case "processMsgQueue": processMsgQueue(msg.data); break; } }); worker.postMessage({ "type": "processPPTX", "data": e.target.result }); }; reader.readAsArrayBuffer(fileName); }); } }); ``` -------------------------------- ### Export PPTX to Reveal.js Presentation Source: https://context7.com/g21589/pptx2html/llms.txt Provides functionality to store converted slides in localStorage for immediate viewing or to download them as a standalone HTML file configured for Reveal.js. ```javascript $("#to-reveal-btn").click(function() { if (localStorage) { localStorage.setItem("slides", LZString.compressToUTF16($result.html())); window.open("./reveal/demo.html", "_blank"); } }); $("#download-reveal-btn").click(function() { if (!isDone) { return; } $.get("css/pptx2html.css", function(cssText) { var revealConfig = ""; var headHtml = ""; var bodyHtml = "
"; var html = revealConfig + headHtml + bodyHtml; var blob = new Blob([html], { type: "text/html;charset=utf-8" }); saveAs(blob, "slides.html"); }); }); ``` -------------------------------- ### Process and Embed Images with processPicNode (JavaScript) Source: https://context7.com/g21589/pptx2html/llms.txt The `processPicNode` function extracts images from a PPTX file, converts them to base64 data URIs, and generates an HTML `div` element for inline display. It determines image type, extracts data from a ZIP archive, and applies positioning and sizing styles. Dependencies include `extractFileExtension`, `getPosition`, `getSize`, and `base64ArrayBuffer`. ```javascript function processPicNode(node, warpObj) { var order = node["attrs"]["order"]; // Get image reference from relationships var rid = node["p:blipFill"]["a:blip"]["attrs"]["r:embed"]; var imgName = warpObj["slideResObj"][rid]["target"]; var imgFileExt = extractFileExtension(imgName).toLowerCase(); // Extract image from ZIP as ArrayBuffer var zip = warpObj["zip"]; var imgArrayBuffer = zip.file(imgName).asArrayBuffer(); // Determine MIME type var mimeType = ""; switch (imgFileExt) { case "jpg": case "jpeg": mimeType = "image/jpeg"; break; case "png": mimeType = "image/png"; break; case "gif": mimeType = "image/gif"; break; } // Get position and size var xfrmNode = node["p:spPr"]["a:xfrm"]; // Return HTML with base64 image return "|
```
--------------------------------
### Individual Slide Processing - JavaScript
Source: https://context7.com/g21589/pptx2html/llms.txt
The `processSingleSlide` function handles the conversion of a single PPTX slide into an HTML `
// Slide Title
//
// ";
text += genBuChar(pNode); // Bullet character if present
if (rNode.constructor === Array) {
// Multiple text runs with different formatting
for (var j = 0; j < rNode.length; j++) {
text += genSpanElement(rNode[j], ...);
}
} else {
text += genSpanElement(rNode, ...);
}
text += " ";
}
}
return text;
}
```
--------------------------------
### Generate Chart from PowerPoint Data (JavaScript)
Source: https://context7.com/g21589/pptx2html/llms.txt
The genChart function extracts chart data from embedded Excel files within PowerPoint presentations. It creates placeholder divs and prepares data structures for rendering interactive D3.js/NVD3 charts. Dependencies include helper functions like getTextByPathList, getPosition, getSize, readXmlFile, and extractChartData, along with a global MsgQueue and chartID counter.
```javascript
function genChart(node, warpObj) {
var order = node["attrs"]["order"];
var xfrmNode = getTextByPathList(node, ["p:xfrm"]);
// Create chart container div
var result = "";
// Get chart data from embedded file
var rid = node["a:graphic"]["a:graphicData"]["c:chart"]["attrs"]["r:id"];
var refName = warpObj["slideResObj"][rid]["target"];
var content = readXmlFile(warpObj["zip"], refName);
var plotArea = getTextByPathList(content, ["c:chartSpace", "c:chart", "c:plotArea"]);
// Determine chart type and extract data
var chartData;
for (var key in plotArea) {
switch (key) {
case "c:lineChart":
chartData = {
"type": "createChart",
"data": {
"chartID": "chart" + chartID,
"chartType": "lineChart",
"chartData": extractChartData(plotArea[key]["c:ser"])
}
};
break;
case "c:barChart":
chartData = { ... "chartType": "barChart", ... };
break;
case "c:pieChart":
chartData = { ... "chartType": "pieChart", ... };
break;
case "c:scatterChart":
chartData = { ... "chartType": "scatterChart", ... };
break;
}
}
// Queue chart for rendering
MsgQueue.push(chartData);
chartID++;
return result;
}
// Chart is rendered in main thread using NVD3:
// d3.select("#chart0")
// .append("svg")
// .datum(data)
// .call(nv.models.barChart());
```
--------------------------------
### Debounce Function Calls in JavaScript
Source: https://github.com/g21589/pptx2html/blob/master/reveal/plugin/notes/notes.html
Limits the rate at which a function can be called. It ensures that a function is only executed after a specified delay has passed since the last invocation. This is commonly used for event handlers like window resizing or input field changes to improve performance.
```javascript
function debounce( fn, ms ) {
var lastTime = 0,
timeout;
return function() {
var args = arguments;
var context = this;
clearTimeout( timeout );
var timeSinceLastCall = Date.now() - lastTime;
if( timeSinceLastCall > ms ) {
fn.apply( context, args );
lastTime = Date.now();
} else {
timeout = setTimeout( function() {
fn.apply( context, args );
lastTime = Date.now();
}, ms - timeSinceLastCall );
}
}
}
``` |