|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Post-build script to remove inline styles for CSP compliance |
| 5 | + * This script removes inline style attributes that violate Content Security Policy |
| 6 | + */ |
| 7 | + |
| 8 | +const fs = require('fs'); |
| 9 | +const path = require('path'); |
| 10 | + |
| 11 | +const files = [ |
| 12 | + './dist/vidstack.js', |
| 13 | + './dist/vs_js_out.js' |
| 14 | +]; |
| 15 | + |
| 16 | +console.log('Removing inline styles for CSP compliance...\n'); |
| 17 | + |
| 18 | +files.forEach(file => { |
| 19 | + const filePath = path.join(__dirname, file); |
| 20 | + |
| 21 | + if (!fs.existsSync(filePath)) { |
| 22 | + console.log(`⚠️ File not found: ${file}`); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + let content = fs.readFileSync(filePath, 'utf8'); |
| 27 | + let modified = false; |
| 28 | + |
| 29 | + // Remove pointer-events: none inline style |
| 30 | + const beforePointerEvents = content; |
| 31 | + content = content.replace( |
| 32 | + /(<media-controls-group[^>]*class="vds-controls-group"[^>]*)\s+style="pointer-events:\s*none;?"/gi, |
| 33 | + '$1' |
| 34 | + ); |
| 35 | + if (content !== beforePointerEvents) { |
| 36 | + console.log(`✓ Removed pointer-events inline style from ${file}`); |
| 37 | + modified = true; |
| 38 | + } |
| 39 | + |
| 40 | + // Remove max-width: unset inline style |
| 41 | + const beforeMaxWidth = content; |
| 42 | + content = content.replace( |
| 43 | + /(<video[^>]*)\s+style="max-width:\s*unset;?"/gi, |
| 44 | + '$1' |
| 45 | + ); |
| 46 | + if (content !== beforeMaxWidth) { |
| 47 | + console.log(`✓ Removed max-width inline style from ${file}`); |
| 48 | + modified = true; |
| 49 | + } |
| 50 | + |
| 51 | + if (modified) { |
| 52 | + fs.writeFileSync(filePath, content, 'utf8'); |
| 53 | + console.log(`✓ Updated ${file}\n`); |
| 54 | + } else { |
| 55 | + console.log(`ℹ No inline styles found in ${file}\n`); |
| 56 | + } |
| 57 | +}); |
| 58 | + |
| 59 | +console.log('Done! All inline styles removed for CSP compliance.'); |
0 commit comments