UNPKG

@shockpkg/dir-projector

Version:

Package for creating Shockwave Director projectors

296 lines (261 loc) 7.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProjectorHtml = void 0; var _nodePath = require("node:path"); var _promises = require("node:fs/promises"); var _projector = require("../projector.js"); var _util = require("../util.js"); /** * ProjectorHtml object. */ class ProjectorHtml extends _projector.Projector { /** * The HTML document lang. */ lang = null; /** * The HTML document title. */ title = null; /** * HTML document background style. */ background = null; /** * HTML document color style. */ color = null; /** * Required <object> classid attribute. */ classid = 'clsid:166B1BCA-3F9C-11CF-8075-444553540000'; /** * Required <embed> type attribute. */ type = 'application/x-director'; /** * The <object> codebase attribute. */ codebase = null; /** * The <embed> codebase attribute. */ pluginspage = null; /** * Required src/movie URL (unless using custom HTML). */ src = ''; /** * Required movie width (unless using custom HTML). */ width = null; /** * Required movie height (unless using custom HTML). */ height = null; /** * The name for object, param, and embed elements. */ name = null; /** * The id for the object element. */ id = null; /** * The movie background color. */ bgcolor = null; /** * The movie stretch style (none | meet | fill | stage). */ swStretchStyle = null; /** * The stretch horizontal alignment (left | center | right). */ swStretchHAlign = null; /** * The stretch vertical alignment (top | center | bottom). */ swStretchVAlign = null; /** * A set of parameters in the form of "swVolume='false' swRestart='true'". * Boolean: swSaveEnabled. * Boolean: swVolume. * Boolean: swRestart. * Boolean: swPausePlay. * Boolean: swFastForward. * Boolean: swContextMenu. */ swRemote = null; /** * Custom parameter 1. */ sw1 = null; /** * Custom parameter 2. */ sw2 = null; /** * Custom parameter 3. */ sw3 = null; /** * Custom parameter 4. */ sw4 = null; /** * Custom parameter 5. */ sw5 = null; /** * Custom parameter 6. */ sw6 = null; /** * Custom parameter 7. */ sw7 = null; /** * Custom parameter 8. */ sw8 = null; /** * Custom parameter 9. */ sw9 = null; /** * The progress attribute (controls loading screen?). */ progress = null; /** * The logo attribute (controls loading screen?). */ logo = null; /** * The playerversion attribute (for update checking?). */ playerVersion = null; /** * Custom HTML to use instead of generated HTML. */ html = null; /** * ProjectorHtml constructor. * * @param path Output path. */ constructor(path) { super(path); } /** * @inheritdoc */ async write() { const { path } = this; await (0, _promises.mkdir)((0, _nodePath.dirname)(path), { recursive: true }); await (0, _promises.writeFile)(path, await this.getHtml()); } /** * Get HTML document code. * * @returns HTML code. */ async getHtml() { const { html } = this; if (html) { return typeof html === 'function' ? html(this) : html; } return this.getHtmlDefault(); } /** * Get the default HTML document code. * * @returns HTML code. */ getHtmlDefault() { const { lang, title, background, color, classid, type, codebase, pluginspage, src, width, height, id, name, bgcolor, swStretchStyle, swStretchHAlign, swStretchVAlign, swRemote, sw1, sw2, sw3, sw4, sw5, sw6, sw7, sw8, sw9, progress, logo, playerVersion } = this; if (!src) { throw new Error('Required property: src'); } if (width === null) { throw new Error('Required property: width'); } if (height === null) { throw new Error('Required property: height'); } const object = new Map(); object.set('classid', classid); if (codebase !== null) { object.set('codebase', codebase); } object.set('width', `${width}`); object.set('height', `${height}`); if (id !== null) { object.set('id', id); } const param = new Map(); param.set('movie', src); const embed = new Map(); embed.set('type', type); if (pluginspage !== null) { embed.set('pluginspage', pluginspage); } embed.set('width', `${width}`); embed.set('height', `${height}`); embed.set('src', src); if (name !== null) { object.set('name', name); param.set('name', name); embed.set('name', name); } for (const [k, v] of [['bgcolor', bgcolor], ['swstretchstyle', swStretchStyle], ['swstretchhalign', swStretchHAlign], ['swstretchvalign', swStretchVAlign], ['swremote', swRemote], ['sw1', sw1], ['sw2', sw2], ['sw3', sw3], ['sw4', sw4], ['sw5', sw5], ['sw6', sw6], ['sw7', sw7], ['sw8', sw8], ['sw9', sw9], ['progress', progress], ['logo', logo], ['playerversion', playerVersion]]) { if (v !== null) { param.set(k, `${v}`); embed.set(k, `${v}`); } } const hAttr = lang === null ? '' : ` lang="${(0, _util.htmlEncode)(lang, true)}"`; return ['<!DOCTYPE html>', `<html${hAttr}>`, ' <head>', ' <meta charset="UTF-8">', ' <meta http-equiv="X-UA-Compatible" content="IE=Edge">', ...(title === null ? [] : [` <title>${(0, _util.htmlEncode)(title)}</title>`]), ' <style>', ' * {', ' margin: 0;', ' padding: 0;', ' }', ' html,', ' body {', ' height: 100%;', ' }', ' body {', ...(background === null ? [] : [` background: ${(0, _util.htmlEncode)(background)};`]), ...(color === null ? [] : [` color: ${(0, _util.htmlEncode)(color)};`]), ' font-family: Verdana, Geneva, sans-serif;', ' }', ' object,', ' embed {', ' display: block;', ' outline: 0;', ' }', ' object:focus,', ' embed:focus {', ' outline: 0;', ' }', ' .main {', ' display: table;', ' height: 100%;', ' width: 100%;', ' }', ' .player {', ' display: table-cell;', ' vertical-align: middle;', ' }', ' .player object,', ' .player embed {', ' margin: 0 auto;', ' }', ' </style>', ' </head>', ' <body>', ' <div class="main">', ' <div class="player">', ' <object', ...[...object.entries()].map(([a, v]) => ` ${a}="${(0, _util.htmlEncode)(v, true)}"`), ' >', ...[...param.entries()].map(([a, v]) => ` <param name="${a}" value="${(0, _util.htmlEncode)(v, true)}">`), ' <embed', ...[...embed.entries()].map(([a, v]) => ` ${a}="${(0, _util.htmlEncode)(v, true)}"`), ' >', ' </object>', ' </div>', ' </div>', ' </body>', '</html>', ''].map(s => s.replace(/^\s+/, s => '\t'.repeat(s.length))).join('\n'); } } exports.ProjectorHtml = ProjectorHtml; //# sourceMappingURL=html.js.map