From a4b705c7313157f6c4e2be50b5ba055c3fc5a657 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Wed, 13 May 2020 00:24:41 +0200 Subject: [PATCH] web: Reformatted all javascript with prettier --- web/.eslintrc.json | 2 +- web/.prettierrc.json | 4 +- web/demo/package.json | 32 +++++------ web/demo/webpack.config.js | 56 +++++++++--------- web/demo/www/index.js | 72 ++++++++++++----------- web/extension/build/js/lv0.js | 46 +++++++++------ web/extension/js/index.js | 6 +- web/extension/package.json | 30 +++++----- web/extension/webpack.config.js | 50 ++++++++-------- web/js-src/load-ruffle.js | 10 ++-- web/js-src/plugin-polyfill.js | 53 +++++++++++------ web/js-src/polyfills.js | 76 ++++++++++++++----------- web/js-src/public-api.js | 78 ++++++++++++++----------- web/js-src/public-path.js | 14 +++-- web/js-src/register-element.js | 30 +++++----- web/js-src/ruffle-embed.js | 18 +++++- web/js-src/ruffle-object.js | 32 +++++++++-- web/js-src/ruffle-player.js | 59 ++++++++++++++----- web/js-src/source-api.js | 23 ++++---- web/js-src/version-range.js | 23 +++++--- web/js-src/version.js | 98 ++++++++++++++++++++++---------- web/package.json | 20 +++---- web/selfhosted/js/ruffle.js | 8 ++- web/selfhosted/package.json | 28 ++++----- web/selfhosted/webpack.config.js | 50 ++++++++-------- 25 files changed, 554 insertions(+), 364 deletions(-) diff --git a/web/.eslintrc.json b/web/.eslintrc.json index 70f2d551c..265b8279a 100644 --- a/web/.eslintrc.json +++ b/web/.eslintrc.json @@ -11,6 +11,6 @@ }, "rules": { "no-console": "off", - "no-constant-condition": ["error", {"checkLoops": false}] + "no-constant-condition": ["error", { "checkLoops": false }] } } diff --git a/web/.prettierrc.json b/web/.prettierrc.json index b6c56942f..0a02bcefd 100644 --- a/web/.prettierrc.json +++ b/web/.prettierrc.json @@ -1,3 +1,3 @@ { - "tabWidth": 4 -} \ No newline at end of file + "tabWidth": 4 +} diff --git a/web/demo/package.json b/web/demo/package.json index 208185b19..0a4782d05 100644 --- a/web/demo/package.json +++ b/web/demo/package.json @@ -1,18 +1,18 @@ { - "name": "ruffle-demo", - "version": "0.1.0", - "description": "Demo of Ruffle Flash emulator", - "scripts": { - "build": "webpack", - "serve": "webpack-dev-server" - }, - "devDependencies": { - "@wasm-tool/wasm-pack-plugin": "^1.2.0", - "clean-webpack-plugin": "^3.0.0", - "copy-webpack-plugin": "^5.1.1", - "html-webpack-plugin": "^3.2.0", - "webpack": "^4.42.0", - "webpack-cli": "^3.3.11", - "webpack-dev-server": "^3.10.3" - } + "name": "ruffle-demo", + "version": "0.1.0", + "description": "Demo of Ruffle Flash emulator", + "scripts": { + "build": "webpack", + "serve": "webpack-dev-server" + }, + "devDependencies": { + "@wasm-tool/wasm-pack-plugin": "^1.2.0", + "clean-webpack-plugin": "^3.0.0", + "copy-webpack-plugin": "^5.1.1", + "html-webpack-plugin": "^3.2.0", + "webpack": "^4.42.0", + "webpack-cli": "^3.3.11", + "webpack-dev-server": "^3.10.3" + } } diff --git a/web/demo/webpack.config.js b/web/demo/webpack.config.js index 4b7b68b80..dd6ce5ca8 100644 --- a/web/demo/webpack.config.js +++ b/web/demo/webpack.config.js @@ -1,36 +1,38 @@ /* eslint-env node */ -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); -const path = require('path'); +const path = require("path"); module.exports = (env, argv) => { - let mode = "production"; - if (argv && argv.mode) { - mode = argv.mode; - } + let mode = "production"; + if (argv && argv.mode) { + mode = argv.mode; + } - console.log(`Building ${mode}...`); + console.log(`Building ${mode}...`); - return { - entry: path.resolve(__dirname, "www/index.js"), - output: { - path: path.resolve(__dirname, "dist"), - filename: "index.js", - }, - mode: mode, - plugins: [ - new CleanWebpackPlugin(), - new CopyWebpackPlugin([{ - from: path.resolve(__dirname, "www/index.html"), - to: "index.html" - }]), - new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, ".."), - outName: "ruffle", - forceMode: mode, - }) - ] - } + return { + entry: path.resolve(__dirname, "www/index.js"), + output: { + path: path.resolve(__dirname, "dist"), + filename: "index.js", + }, + mode: mode, + plugins: [ + new CleanWebpackPlugin(), + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, "www/index.html"), + to: "index.html", + }, + ]), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".."), + outName: "ruffle", + forceMode: mode, + }), + ], + }; }; diff --git a/web/demo/www/index.js b/web/demo/www/index.js index fa2a7af6a..21ba8cf4c 100644 --- a/web/demo/www/index.js +++ b/web/demo/www/index.js @@ -1,52 +1,59 @@ import { PublicAPI } from "../../js-src/public-api"; import { SourceAPI } from "../../js-src/source-api"; -window.RufflePlayer = PublicAPI.negotiate(window.RufflePlayer, "local", new SourceAPI("local")); +window.RufflePlayer = PublicAPI.negotiate( + window.RufflePlayer, + "local", + new SourceAPI("local") +); let ruffle; let player; let jsonData; -let container = document.getElementById('main'); +let container = document.getElementById("main"); let author_container = document.getElementById("author-container"); let author = document.getElementById("author"); let sampleFileInputContainer = document.getElementById("sample-swfs-container"); let sampleFileInput = document.getElementById("sample-swfs"); let localFileInput = document.getElementById("local-file"); -window.addEventListener('DOMContentLoaded', () => { - ruffle = window.RufflePlayer.newest(); - player = ruffle.create_player(); - player.id = "player"; - container.appendChild(player); - fetch("swfs.json").then(response => { +window.addEventListener("DOMContentLoaded", () => { + ruffle = window.RufflePlayer.newest(); + player = ruffle.create_player(); + player.id = "player"; + container.appendChild(player); + fetch("swfs.json").then((response) => { if (response.ok) { - response.json().then( data => { + response.json().then((data) => { const list = document.getElementById("sample-swfs"); jsonData = data; - jsonData.swfs.forEach(item => { + jsonData.swfs.forEach((item) => { let temp = document.createElement("option"); temp.innerHTML = item.title; - temp.setAttribute("value",item.location); + temp.setAttribute("value", item.location); list.appendChild(temp); }); - document.getElementById("sample-swfs-container").style.display = "inline-block"; - let rn = Math.floor(Math.random() * Math.floor(sampleFileInput.children.length - 1)); + document.getElementById("sample-swfs-container").style.display = + "inline-block"; + let rn = Math.floor( + Math.random() * + Math.floor(sampleFileInput.children.length - 1) + ); sampleFileInput.selectedIndex = rn + 1; loadRemoteFile(jsonData.swfs[rn].location); author_container.style.display = "block"; author.innerHTML = jsonData.swfs[rn].author; author.href = jsonData.swfs[rn].authorLink; - }); - } - else { - sampleFileInputContainer.style.display = "none"; - } - }); + }); + } else { + sampleFileInputContainer.style.display = "none"; + } + }); }); -if(sampleFileInput) { - sampleFileInput.addEventListener("change",sampleFileSelected,false); +if (sampleFileInput) { + sampleFileInput.addEventListener("change", sampleFileSelected, false); } if (localFileInput) { @@ -63,18 +70,18 @@ if (window.location.search && window.location.search != "") { } function sampleFileSelected() { - let selected_value = sampleFileInput.children[sampleFileInput.selectedIndex].value; + let selected_value = + sampleFileInput.children[sampleFileInput.selectedIndex].value; let selected_index = sampleFileInput.selectedIndex - 1; //We subtract 1 here because the dropdown menu inlcudes a "None" option. - if (selected_value != "none") { + if (selected_value != "none") { author_container.style.display = "block"; author.innerHTML = jsonData.swfs[selected_index].author; author.href = jsonData.swfs[selected_index].authorLink; localFileInput.value = null; loadRemoteFile(selected_value); - } - else { - replacePlayer() + } else { + replacePlayer(); } } @@ -83,22 +90,21 @@ function localFileSelected() { author_container.style.display = "none"; author.innerHTML = ""; author.href = ""; - + let file = localFileInput.files[0]; if (file) { let fileReader = new FileReader(); fileReader.onload = () => { player.play_swf_data(fileReader.result); - } + }; fileReader.readAsArrayBuffer(file); } } function loadRemoteFile(url) { - fetch(url) - .then(response => { - response.arrayBuffer().then(data => player.play_swf_data(data)) - }); + fetch(url).then((response) => { + response.arrayBuffer().then((data) => player.play_swf_data(data)); + }); } function replacePlayer() { @@ -109,4 +115,4 @@ function replacePlayer() { author_container.style.display = "none"; author.innerHTML = ""; author.href = ""; -} \ No newline at end of file +} diff --git a/web/extension/build/js/lv0.js b/web/extension/build/js/lv0.js index 5fc0c20e7..fb1ff314a 100644 --- a/web/extension/build/js/lv0.js +++ b/web/extension/build/js/lv0.js @@ -1,41 +1,55 @@ /** * Pierce the extension sandbox by copying our code into window space. - * + * * The isolation extension content scripts get is neat, but it causes problems * based on what browser you use: - * + * * 1. On Chrome, you are explicitly banned from registering custom elements * 2. On Firefox, you can register custom elements but they can't expose any * useful API surface, and can't even see their own methods. - * + * * This code exists to pierce the extension sandbox, while maintaining: - * + * * 1. The isolation of not interfering with the page's execution environment * unintentionally. * 2. The ability to load extension resources such as .wasm files */ let page_optout = document.documentElement.hasAttribute("data-ruffle-optout"); try { - if ((!page_optout) && window.top && window.top.document && window.top.document.documentElement) { + if ( + !page_optout && + window.top && + window.top.document && + window.top.document.documentElement + ) { /* In case the opting out page uses iframes */ - page_optout = window.top.document.documentElement.hasAttribute("data-ruffle-optout"); + page_optout = window.top.document.documentElement.hasAttribute( + "data-ruffle-optout" + ); } -} -catch (e) { +} catch (e) { console.log("Unable to check top-level optout: " + e.message); } -let obfuscated_event_prefix = "rufEvent" + Math.floor(Math.random() * 100000000000); +let obfuscated_event_prefix = + "rufEvent" + Math.floor(Math.random() * 100000000000); let ext_path = ""; if (chrome && chrome.extension && chrome.extension.getURL) { - ext_path = chrome.extension.getURL("dist/ruffle.js").replace("dist/ruffle.js", ""); + ext_path = chrome.extension + .getURL("dist/ruffle.js") + .replace("dist/ruffle.js", ""); } else if (browser && browser.runtime && browser.runtime.getURL) { - ext_path = browser.runtime.getURL("dist/ruffle.js").replace("dist/ruffle.js", ""); + ext_path = browser.runtime + .getURL("dist/ruffle.js") + .replace("dist/ruffle.js", ""); } if (!(page_optout || window.RufflePlayer)) { let setup_scriptelem = document.createElement("script"); - let setup_src = "var runtime_path = \"" + - ext_path + "\";\nvar obfuscated_event_prefix = \"" + - obfuscated_event_prefix + "\";" + + let setup_src = + 'var runtime_path = "' + + ext_path + + '";\nvar obfuscated_event_prefix = "' + + obfuscated_event_prefix + + '";' + '(function(){class RuffleMimeType{constructor(a,b,c){this.type=a,this.description=b,this.suffixes=c}}class RuffleMimeTypeArray{constructor(a){this.__mimetypes=[],this.__named_mimetypes={};for(let b of a)this.install(b)}install(a){let b=this.__mimetypes.length;this.__mimetypes.push(a),this.__named_mimetypes[a.type]=a,this[a.type]=a,this[b]=a}item(a){return this.__mimetypes[a]}namedItem(a){return this.__named_mimetypes[a]}get length(){return this.__mimetypes.length}}class RufflePlugin extends RuffleMimeTypeArray{constructor(a,b,c,d){super(d),this.name=a,this.description=b,this.filename=c}install(a){a.enabledPlugin||(a.enabledPlugin=this),super.install(a)}}class RufflePluginArray{constructor(a){this.__plugins=[],this.__named_plugins={};for(let b of a)this.install(b)}install(a){let b=this.__plugins.length;this.__plugins.push(a),this.__named_plugins[a.name]=a,this[a.name]=a,this[b]=a}item(a){return this.__plugins[a]}namedItem(a){return this.__named_plugins[a]}get length(){return this.__plugins.length}}const FLASH_PLUGIN=new RufflePlugin("Shockwave Flash","Shockwave Flash 32.0 r0","ruffle.js",[new RuffleMimeType("application/futuresplash","Shockwave Flash","spl"),new RuffleMimeType("application/x-shockwave-flash","Shockwave Flash","swf"),new RuffleMimeType("application/x-shockwave-flash2-preview","Shockwave Flash","swf"),new RuffleMimeType("application/vnd.adobe.flash-movie","Shockwave Flash","swf")]);function install_plugin(a){navigator.plugins.install||Object.defineProperty(navigator,"plugins",{value:new RufflePluginArray(navigator.plugins),writable:!1}),navigator.plugins.install(a),0 { - let mode = "production"; - if (argv && argv.mode) { - mode = argv.mode; - } + let mode = "production"; + if (argv && argv.mode) { + mode = argv.mode; + } - console.log(`Building ${mode}...`); + console.log(`Building ${mode}...`); - return { - entry: path.resolve(__dirname, "js/index.js"), - output: { - path: path.resolve(__dirname, "build/dist"), - filename: "ruffle.js", - chunkFilename: "core.ruffle.js", - jsonpFunction: "RufflePlayerExtensionLoader", - }, - mode: mode, - plugins: [ - new CleanWebpackPlugin(), - new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, ".."), - outName: "ruffle", - forceMode: mode, - }) - ] - } + return { + entry: path.resolve(__dirname, "js/index.js"), + output: { + path: path.resolve(__dirname, "build/dist"), + filename: "ruffle.js", + chunkFilename: "core.ruffle.js", + jsonpFunction: "RufflePlayerExtensionLoader", + }, + mode: mode, + plugins: [ + new CleanWebpackPlugin(), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".."), + outName: "ruffle", + forceMode: mode, + }), + ], + }; }; diff --git a/web/js-src/load-ruffle.js b/web/js-src/load-ruffle.js index 2c8f79a2f..4a4d6a7c3 100644 --- a/web/js-src/load-ruffle.js +++ b/web/js-src/load-ruffle.js @@ -6,7 +6,7 @@ /** * Load ruffle from an automatically-detected location. - * + * * This function returns a new instance of Ruffle and downloads it every time. * You should not use it directly; this module will memoize the resource * download. @@ -14,7 +14,7 @@ async function fetch_ruffle() { try { //If runtime_path is defined then we are executing inside the extension - //closure. In that case, we configure our local Webpack instance + //closure. In that case, we configure our local Webpack instance __webpack_public_path__ = runtime_path + "dist/"; } catch (e) { //Checking an undefined closure variable usually throws ReferencError, @@ -23,7 +23,7 @@ async function fetch_ruffle() { throw e; } } - + //We currently assume that if we are not executing inside the extension, //then we can use webpack to get Ruffle. let ruffle_module = await import("../pkg/ruffle"); @@ -34,7 +34,7 @@ let last_loaded_ruffle = null; /** * Obtain an instance of `Ruffle`. - * + * * This function returns a promise which yields `Ruffle` asynchronously. */ export default function load_ruffle() { @@ -43,4 +43,4 @@ export default function load_ruffle() { } return last_loaded_ruffle; -} \ No newline at end of file +} diff --git a/web/js-src/plugin-polyfill.js b/web/js-src/plugin-polyfill.js index fb7fbaca9..d74dc981b 100644 --- a/web/js-src/plugin-polyfill.js +++ b/web/js-src/plugin-polyfill.js @@ -13,10 +13,10 @@ class RuffleMimeType { /** * Replacement object for `MimeTypeArray` that lets us install new fake mime * types. - * + * * Unlike plugins we can at least enumerate mime types in Firefox, so we don't * lose data. - * + * * We also expose a method called `install` which adds a new plugin. This is * used to falsify Flash detection. If the existing `navigator.mimeTypes` has an * `install` method, you should not use `RuffleMimeTypeArray` as some other @@ -34,8 +34,8 @@ class RuffleMimeTypeArray { /** * Install a MIME Type into the array. - * - * @param {MimeType | RuffleMimeType} mimetype + * + * @param {MimeType | RuffleMimeType} mimetype */ install(mimetype) { let id = this.__mimetypes.length; @@ -82,15 +82,15 @@ class RufflePlugin extends RuffleMimeTypeArray { /** * Replacement object for `PluginArray` that lets us install new fake plugins. - * + * * This object needs to wrap the native plugin array, since the user might have * actual plugins installed. Firefox doesn't let us enumerate the array, though, * which has some consequences. Namely, we can't actually perfectly wrap the * native plugin array, at least unless there's some secret "unresolved object * property name handler" that I've never known before in JS... - * + * * We can still wrap `namedItem` perfectly at least. - * + * * We also expose a method called `install` which adds a new plugin. This is * used to falsify Flash detection. If the existing `navigator.plugins` has an * `install` method, you should not use `RufflePluginArray` as some other plugin @@ -128,16 +128,37 @@ class RufflePluginArray { } } -export const FLASH_PLUGIN = new RufflePlugin("Shockwave Flash", "Shockwave Flash 32.0 r0", "ruffle.js", [ - new RuffleMimeType("application/futuresplash", "Shockwave Flash", "spl"), - new RuffleMimeType("application/x-shockwave-flash", "Shockwave Flash", "swf"), - new RuffleMimeType("application/x-shockwave-flash2-preview", "Shockwave Flash", "swf"), - new RuffleMimeType("application/vnd.adobe.flash-movie", "Shockwave Flash", "swf") -]); +export const FLASH_PLUGIN = new RufflePlugin( + "Shockwave Flash", + "Shockwave Flash 32.0 r0", + "ruffle.js", + [ + new RuffleMimeType( + "application/futuresplash", + "Shockwave Flash", + "spl" + ), + new RuffleMimeType( + "application/x-shockwave-flash", + "Shockwave Flash", + "swf" + ), + new RuffleMimeType( + "application/x-shockwave-flash2-preview", + "Shockwave Flash", + "swf" + ), + new RuffleMimeType( + "application/vnd.adobe.flash-movie", + "Shockwave Flash", + "swf" + ), + ] +); /** * Install a fake plugin such that detectors will see it in `navigator.plugins`. - * + * * This function takes care to check if the existing implementation of * `navigator.plugins` already accepts fake plugin entries. If so, it will use * that version of the plugin array. This allows the plugin polyfill to compose @@ -147,7 +168,7 @@ export function install_plugin(plugin) { if (!navigator.plugins.install) { Object.defineProperty(navigator, "plugins", { value: new RufflePluginArray(navigator.plugins), - writable: false + writable: false, }); } @@ -156,7 +177,7 @@ export function install_plugin(plugin) { if (plugin.length > 0 && !navigator.mimeTypes.install) { Object.defineProperty(navigator, "mimeTypes", { value: new RuffleMimeTypeArray(navigator.mimeTypes), - writable: false + writable: false, }); } diff --git a/web/js-src/polyfills.js b/web/js-src/polyfills.js index 52ffbe41c..9718e5dc2 100644 --- a/web/js-src/polyfills.js +++ b/web/js-src/polyfills.js @@ -1,26 +1,26 @@ import RuffleObject from "./ruffle-object"; import RuffleEmbed from "./ruffle-embed"; import { install_plugin, FLASH_PLUGIN } from "./plugin-polyfill"; -import { public_path } from "./public-path" +import { public_path } from "./public-path"; if (!window.RufflePlayer) { - window.RufflePlayer={}; + window.RufflePlayer = {}; } let top_level_ruffle_config; -let ruffle_script_src=public_path({}, "ruffle.js"); +let ruffle_script_src = public_path({}, "ruffle.js"); if (window.RufflePlayer.config) { - top_level_ruffle_config=window.RufflePlayer.config; - ruffle_script_src=public_path(window.RufflePlayer.config, "ruffle.js"); + top_level_ruffle_config = window.RufflePlayer.config; + ruffle_script_src = public_path(window.RufflePlayer.config, "ruffle.js"); } /* public_path returns the directory where the file is, * * so we need to append the filename. We don't need to * * worry about the directory not having a slash because * * public_path appends a slash. */ -ruffle_script_src+="ruffle.js"; +ruffle_script_src += "ruffle.js"; /** * Polyfill native elements with Ruffle equivalents. - * + * * This polyfill isn't fool-proof: If there's a chance site JavaScript has * access to a pre-polyfill element, then this will break horribly. We can * keep native objects out of the DOM, and thus out of JavaScript's grubby @@ -48,7 +48,10 @@ function replace_flash_instances() { } } } catch (err) { - console.error("Serious error encountered when polyfilling native Flash elements: " + err); + console.error( + "Serious error encountered when polyfilling native Flash elements: " + + err + ); } } @@ -56,18 +59,19 @@ function polyfill_static_content() { replace_flash_instances(); } - function polyfill_dynamic_content() { // Listen for changes to the DOM. If nodes are added, re-check for any Flash instances. const observer = new MutationObserver(function (mutationsList) { // If any nodes were added, re-run the polyfill to replace any new instances. - let nodesAdded = mutationsList.some(mutation => mutation.addedNodes.length > 0); + let nodesAdded = mutationsList.some( + (mutation) => mutation.addedNodes.length > 0 + ); if (nodesAdded) { replace_flash_instances(); } }); - observer.observe(document, { childList: true, subtree: true}); + observer.observe(document, { childList: true, subtree: true }); } function falsify_plugin_detection() { @@ -75,39 +79,37 @@ function falsify_plugin_detection() { } function load_ruffle_player_into_frame(event) { - let current_frame=event.currentTarget.contentWindow; + let current_frame = event.currentTarget.contentWindow; let frame_document; console.log("Event handled"); try { - frame_document=current_frame.document; + frame_document = current_frame.document; if (!frame_document) { console.log("Frame has no document."); return; } - } - catch(e) { + } catch (e) { console.log("Error Getting Frame: " + e.message); return; } - if(!current_frame.RufflePlayer) { + if (!current_frame.RufflePlayer) { /* Make sure we populate the frame's window.RufflePlayer.config */ - current_frame.RufflePlayer={}; - current_frame.RufflePlayer.config=top_level_ruffle_config; + current_frame.RufflePlayer = {}; + current_frame.RufflePlayer.config = top_level_ruffle_config; let script = frame_document.createElement("script"); - script.src=ruffle_script_src; /* Load this script(ruffle.js) into the frame */ + script.src = ruffle_script_src; /* Load this script(ruffle.js) into the frame */ frame_document.body.appendChild(script); - } - else { + } else { console.log("(i)frame already has RufflePlayer"); } polyfill_frames_common(current_frame); } function polyfill_frames_common(depth) { - let current_iframes=depth.document.getElementsByTagName("iframe"); - let current_frames=depth.document.getElementsByTagName("frame"); - for (let i=0;i mutation.addedNodes.length > 0); + let nodesAdded = mutationsList.some( + (mutation) => mutation.addedNodes.length > 0 + ); if (nodesAdded) { polyfill_frames_common(window); } @@ -141,7 +145,7 @@ function ruffle_frame_listener(mutationsList) { function polyfill_dynamic_frames() { const observer = new MutationObserver(ruffle_frame_listener); - observer.observe(document, {childList: true, subtree: true}); + observer.observe(document, { childList: true, subtree: true }); } function polyfill_frames() { @@ -155,7 +159,7 @@ let polyfills = { "static-content": polyfill_static_content, "dynamic-content": polyfill_dynamic_content, "plugin-detect": falsify_plugin_detection, - "frames": polyfill_frames + frames: polyfill_frames, }; export function polyfill(polyfill_list) { @@ -164,8 +168,12 @@ export function polyfill(polyfill_list) { continue; } - if (!Object.prototype.hasOwnProperty.call(polyfills, polyfill_list[i])) { - throw new Error("Requested nonexistent polyfill: " + polyfill_list[i]); + if ( + !Object.prototype.hasOwnProperty.call(polyfills, polyfill_list[i]) + ) { + throw new Error( + "Requested nonexistent polyfill: " + polyfill_list[i] + ); } running_polyfills.push(polyfill_list[i]); diff --git a/web/js-src/public-api.js b/web/js-src/public-api.js index f70ebf47c..433f54242 100644 --- a/web/js-src/public-api.js +++ b/web/js-src/public-api.js @@ -3,28 +3,28 @@ import { VersionRange } from "./version-range.js"; /** * Represents the Ruffle public API. - * + * * The public API exists primarily to allow multiple installs of Ruffle on a * page (e.g. an extension install and a local one) to cooperate. In an ideal * situation, all Ruffle sources on the page install themselves into a single * public API, and then the public API picks the newest version by default. - * + * * This API *is* versioned, in case we need to upgrade it. However, it must be * backwards- and forwards-compatible with all known sources. */ export class PublicAPI { /** * Construct the Ruffle public API. - * + * * Do not use this function to negotiate a public API. Instead, use * `public_api` to register your Ruffle source with an existing public API * if it exists. - * + * * Constructing a Public API will also trigger it to initialize Ruffle once * the page loads, if the API has not already been superceded. - * + * * @param {object} prev What used to be in the public API slot. - * + * * This is used to upgrade from a prior version of the public API, or from * a user-defined configuration object placed in the public API slot. */ @@ -44,7 +44,10 @@ export class PublicAPI { this.newest_name = prev.newest_name; prev.superceded(); - } else if (prev.constructor === Object && prev.config !== undefined) { + } else if ( + prev.constructor === Object && + prev.config !== undefined + ) { /// We're the first, install user configuration this.config = prev.config; } else { @@ -62,7 +65,7 @@ export class PublicAPI { /** * The version of the public API. - * + * * This allows a page with an old version of the Public API to be upgraded * to a new version of the API. The public API is intended to be changed * very infrequently, if at all, but this provides an escape mechanism for @@ -74,7 +77,7 @@ export class PublicAPI { /** * Register a given source with the Ruffle Public API. - * + * * @param {string} name The name of the source. * @param {object} api The public API object. This must conform to the shape * of `SourceAPI`. @@ -82,15 +85,16 @@ export class PublicAPI { register_source(name, api) { this.sources[name] = api; } - + /** * Determine the name of the newest registered source in the Public API. - * + * * @returns {(string|bool)} The name of the source, or `false` if no source * has yet to be registered. */ newest_source_name() { - let newest_name = false, newest_version = Version.from_semver("0.0.0"); + let newest_name = false, + newest_version = Version.from_semver("0.0.0"); for (let k in this.sources) { if (Object.prototype.hasOwnProperty.call(this.sources, k)) { @@ -107,7 +111,7 @@ export class PublicAPI { /** * Negotiate and start Ruffle. - * + * * This function reads the config parameter to determine which polyfills * should be enabled. If the configuration parameter is missing, then we * use a built-in set of defaults sufficient to fool sites with static @@ -129,16 +133,20 @@ export class PublicAPI { * we would need to have all polyfills but frames added * * to the extension's javascript because it uses the * * "all_frames" manifest property to handle frames. */ - polyfills = ["plugin-detect", "static-content", "dynamic-content"]; + polyfills = [ + "plugin-detect", + "static-content", + "dynamic-content", + ]; } - + this.sources[this.newest_name].polyfill(polyfills); } } /** * Look up the newest Ruffle source and return it's API. - * + * * @returns {SourceAPI} An instance of the Source API. */ newest() { @@ -148,10 +156,10 @@ export class PublicAPI { /** * Look up a specific Ruffle version (or any version satisfying a given set * of requirements) and return it's API. - * + * * @param {string} ver_requirement A set of semantic version requirement * strings that the player version must satisfy. - * + * * @returns {SourceAPI|null} An instance of the Source API, if one or more * sources satisfied the requirement. */ @@ -164,7 +172,7 @@ export class PublicAPI { let version = Version.from_semver(this.sources[k].version); if (requirement.satisfied_by(version)) { - valid_source = this.sources[k] + valid_source = this.sources[k]; } } } @@ -199,11 +207,11 @@ export class PublicAPI { /** * Indicates that this version of the public API has been superceded by a * newer version. - * + * * This should only be called by a newer version of the Public API. * Identical versions of the Public API should not supercede older versions * of that same API. - * + * * Unfortunately, we can't disable polyfills after-the-fact, so this * only lets you disable the init event... */ @@ -213,45 +221,51 @@ export class PublicAPI { /** * Join a source into the public API, if it doesn't already exist. - * + * * @param {*} prev_ruffle The previous iteration of the Ruffle API. - * + * * The `prev_ruffle` param lists the previous object in the RufflePlayer * slot. We perform some checks to see if this is a Ruffle public API or a * conflicting object. If this is conflicting, then a new public API will * be constructed (see the constructor information for what happens to * `prev_ruffle`). - * + * * Note that Public API upgrades are deliberately not enabled in this * version of Ruffle, since there is no Public API to upgrade from. - * + * * @param {string|undefined} source_name The name of this particular * Ruffle source. - * + * * @param {object|undefined} source_api The Ruffle source to add. - * + * * If both parameters are provided they will be used to define a new Ruffle * source to register with the public API. - * + * * @returns {object} The Ruffle Public API. */ static negotiate(prev_ruffle, source_name, source_api) { let public_api; - if (prev_ruffle !== undefined && prev_ruffle.constructor.name == PublicAPI.name) { + if ( + prev_ruffle !== undefined && + prev_ruffle.constructor.name == PublicAPI.name + ) { public_api = prev_ruffle; } else { public_api = new PublicAPI(prev_ruffle); } - + if (source_name !== undefined && source_api !== undefined) { public_api.register_source(source_name, source_api); - + // Install the faux plugin detection immediately. // This is necessary because scripts such as SWFObject check for the // Flash Player immediately when they load. // TODO: Maybe there's a better place for this. let polyfills = public_api.config.polyfills; - if (polyfills === undefined || polyfills.includes("plugin-detect")) { + if ( + polyfills === undefined || + polyfills.includes("plugin-detect") + ) { source_api.polyfill(["plugin-detect"]); } } diff --git a/web/js-src/public-path.js b/web/js-src/public-path.js index 6263e9c14..3d8f02512 100644 --- a/web/js-src/public-path.js +++ b/web/js-src/public-path.js @@ -1,10 +1,10 @@ /** * Attempt to discover the public path of the current Ruffle source. This can * be used to configure Webpack. - * + * * We have several points of configuration for how the Ruffle public path can * be determined: - * + * * 1. The public path can be specified on a per-source basis using the * RufflePlayer config, for example: * `window.RufflePlayer.config.public_paths.local = "/dist/";` @@ -13,14 +13,18 @@ * 3. If there is absolutely no configuration that yields a public path then we * return the parent path of where this script is hosted, which should be * the correct default in most cases. - * + * * @param {object} config The `window.RufflePlayer.config` object. * @param {string} source_name The name of the source. * @returns {string} The public path for the given source. */ export function public_path(config, source_name) { let public_path = ""; - if (config !== undefined && config.public_paths !== undefined && config.public_paths[source_name] !== undefined) { + if ( + config !== undefined && + config.public_paths !== undefined && + config.public_paths[source_name] !== undefined + ) { public_path = config.public_paths[source_name]; } else if (config !== undefined && config.public_path !== undefined) { public_path = config.public_path; @@ -32,7 +36,7 @@ export function public_path(config, source_name) { console.warn("Unable to get currentScript URL"); } } - + // Webpack expects the paths to end with a /. if (public_path !== "" && !public_path.endsWith("/")) { public_path += "/"; diff --git a/web/js-src/register-element.js b/web/js-src/register-element.js index 0aaf7afaf..9fd6d4bf3 100644 --- a/web/js-src/register-element.js +++ b/web/js-src/register-element.js @@ -5,13 +5,13 @@ var private_registry = {}; /** * Lookup a previously registered custom element. - * + * * @param {string} element_name The internal element name, previously used to * register the element with the private registry. - * + * * @returns {object|null} The element data in the registry, or null if there is * no such element name registered. - * + * * The returned object will have `name`, `class`, and `internal_name` * properties listing the external name, implementing class, and internal name * respectively. @@ -20,9 +20,9 @@ export function lookup_element(element_name) { let data = private_registry[element_name]; if (data !== undefined) { return { - "internal_name": element_name, - "name": data.name, - "class": data.class + internal_name: element_name, + name: data.name, + class: data.class, }; } else { return null; @@ -31,21 +31,21 @@ export function lookup_element(element_name) { /** * Register a custom element. - * + * * This function is designed to be tolerant of naming conflicts. If * registration fails, we modify the name, and try again. As a result, this * function returns the real element name to use. - * + * * Calling this function multiple times will *not* register multiple elements. * We store a private registry mapping internal element names to DOM names. * Thus, the proper way to use this function is to call it every time you are * about to work with custom element names. - * + * * @param {string} element_name The internal name of the element. * @param {function} element_class The class of the element. - * + * * You must call this function with the same class every time. - * + * * @returns {string} The actual element name. * @throws Throws an error if two different elements were registered with the * same internal name. @@ -70,9 +70,9 @@ export function register_element(element_name, element_class) { window.customElements.define(external_name, element_class); private_registry[element_name] = { - "class": element_class, - "name": external_name, - "internal_name": element_name + class: element_class, + name: external_name, + internal_name: element_name, }; return external_name; @@ -82,4 +82,4 @@ export function register_element(element_name, element_class) { } } } -} \ No newline at end of file +} diff --git a/web/js-src/ruffle-embed.js b/web/js-src/ruffle-embed.js index 5c6987650..94ad9c6ae 100644 --- a/web/js-src/ruffle-embed.js +++ b/web/js-src/ruffle-embed.js @@ -1,4 +1,11 @@ -import { FLASH_MIMETYPE, FUTURESPLASH_MIMETYPE, FLASH7_AND_8_MIMETYPE, FLASH_MOVIE_MIMETYPE, is_swf_filename, RufflePlayer } from "./ruffle-player.js"; +import { + FLASH_MIMETYPE, + FUTURESPLASH_MIMETYPE, + FLASH7_AND_8_MIMETYPE, + FLASH_MOVIE_MIMETYPE, + is_swf_filename, + RufflePlayer, +} from "./ruffle-player.js"; import { register_element } from "./register-element"; export default class RuffleEmbed extends RufflePlayer { @@ -35,9 +42,14 @@ export default class RuffleEmbed extends RufflePlayer { static is_interdictable(elem) { if (!elem.src) { - return false; + return false; } - if (elem.type === FLASH_MIMETYPE || elem.type === FUTURESPLASH_MIMETYPE || elem.type == FLASH7_AND_8_MIMETYPE || elem.type == FLASH_MOVIE_MIMETYPE) { + if ( + elem.type === FLASH_MIMETYPE || + elem.type === FUTURESPLASH_MIMETYPE || + elem.type == FLASH7_AND_8_MIMETYPE || + elem.type == FLASH_MOVIE_MIMETYPE + ) { return true; } else if (elem.type === undefined || elem.type === "") { return is_swf_filename(elem.src); diff --git a/web/js-src/ruffle-object.js b/web/js-src/ruffle-object.js index 8a0cf261b..b21752189 100644 --- a/web/js-src/ruffle-object.js +++ b/web/js-src/ruffle-object.js @@ -1,4 +1,12 @@ -import { FLASH_MIMETYPE, FUTURESPLASH_MIMETYPE, FLASH7_AND_8_MIMETYPE, FLASH_MOVIE_MIMETYPE, FLASH_ACTIVEX_CLASSID, is_swf_filename, RufflePlayer } from "./ruffle-player.js"; +import { + FLASH_MIMETYPE, + FUTURESPLASH_MIMETYPE, + FLASH7_AND_8_MIMETYPE, + FLASH_MOVIE_MIMETYPE, + FLASH_ACTIVEX_CLASSID, + is_swf_filename, + RufflePlayer, +} from "./ruffle-player.js"; import { register_element } from "./register-element"; export default class RuffleObject extends RufflePlayer { @@ -8,7 +16,7 @@ export default class RuffleObject extends RufflePlayer { connectedCallback() { super.connectedCallback(); - + this.params = RuffleObject.params_of(this); //Kick off the SWF download. @@ -31,7 +39,7 @@ export default class RuffleObject extends RufflePlayer { if (!elem.data) { let has_movie = false; let params = elem.getElementsByTagName("param"); - for (let i = 0;i < params.length;i ++) { + for (let i = 0; i < params.length; i++) { if (params[i].name == "movie" && params[i].value) { has_movie = true; } @@ -40,11 +48,23 @@ export default class RuffleObject extends RufflePlayer { return false; } } - if (elem.type === FLASH_MIMETYPE || elem.type === FUTURESPLASH_MIMETYPE || elem.type == FLASH7_AND_8_MIMETYPE || elem.type == FLASH_MOVIE_MIMETYPE) { + if ( + elem.type === FLASH_MIMETYPE || + elem.type === FUTURESPLASH_MIMETYPE || + elem.type == FLASH7_AND_8_MIMETYPE || + elem.type == FLASH_MOVIE_MIMETYPE + ) { return true; - } else if (elem.attributes && elem.attributes.classid && elem.attributes.classid.value === FLASH_ACTIVEX_CLASSID) { + } else if ( + elem.attributes && + elem.attributes.classid && + elem.attributes.classid.value === FLASH_ACTIVEX_CLASSID + ) { return true; - } else if ((elem.type === undefined || elem.type === "") && elem.attributes.classid === undefined) { + } else if ( + (elem.type === undefined || elem.type === "") && + elem.attributes.classid === undefined + ) { let params = RuffleObject.params_of(elem); if (params && params.movie) { return is_swf_filename(params.movie); diff --git a/web/js-src/ruffle-player.js b/web/js-src/ruffle-player.js index 122554fc3..935c29a92 100644 --- a/web/js-src/ruffle-player.js +++ b/web/js-src/ruffle-player.js @@ -14,14 +14,17 @@ export class RufflePlayer extends HTMLElement { constructor(...args) { let self = super(...args); - self.shadow = self.attachShadow({ mode: 'closed' }); + self.shadow = self.attachShadow({ mode: "closed" }); self.shadow.appendChild(ruffle_shadow_template.content.cloneNode(true)); self.dynamic_styles = self.shadow.getElementById("dynamic_styles"); self.container = self.shadow.getElementById("container"); self.play_button = self.shadow.getElementById("play_button"); if (self.play_button) { - self.play_button.addEventListener("click", self.play_button_clicked.bind(self)); + self.play_button.addEventListener( + "click", + self.play_button_clicked.bind(self) + ); } self.instance = null; @@ -59,16 +62,24 @@ export class RufflePlayer extends HTMLElement { } if (this.attributes.width) { - let width = RufflePlayer.html_dimension_to_css_dimension(this.attributes.width.value); + let width = RufflePlayer.html_dimension_to_css_dimension( + this.attributes.width.value + ); if (width !== null) { - this.dynamic_styles.sheet.insertRule(`:host { width: ${width}; }`); + this.dynamic_styles.sheet.insertRule( + `:host { width: ${width}; }` + ); } } if (this.attributes.height) { - let height = RufflePlayer.html_dimension_to_css_dimension(this.attributes.height.value); + let height = RufflePlayer.html_dimension_to_css_dimension( + this.attributes.height.value + ); if (height !== null) { - this.dynamic_styles.sheet.insertRule(`:host { height: ${height}; }`); + this.dynamic_styles.sheet.insertRule( + `:host { height: ${height}; }` + ); } } } @@ -76,7 +87,7 @@ export class RufflePlayer extends HTMLElement { /** * Determine if this element is the fallback content of another Ruffle * player. - * + * * This heurustic assumes Ruffle objects will never use their fallback * content. If this changes, then this code also needs to change. */ @@ -111,10 +122,19 @@ export class RufflePlayer extends HTMLElement { await this.play_swf_data(data); console.log("Playing " + url); } else { - console.error("SWF load failed: " + response.status + " " + response.statusText + " for " + url); + console.error( + "SWF load failed: " + + response.status + + " " + + response.statusText + + " for " + + url + ); } } else { - console.warn("Ignoring attempt to play a disconnected or suspended Ruffle element"); + console.warn( + "Ignoring attempt to play a disconnected or suspended Ruffle element" + ); } } catch (err) { console.error("Serious error occured loading SWF file: " + err); @@ -153,7 +173,9 @@ export class RufflePlayer extends HTMLElement { this.play_button.style.display = "block"; } } else { - console.warn("Ignoring attempt to play a disconnected or suspended Ruffle element"); + console.warn( + "Ignoring attempt to play a disconnected or suspended Ruffle element" + ); } } @@ -166,7 +188,10 @@ export class RufflePlayer extends HTMLElement { for (let attrib of elem.attributes) { if (attrib.specified) { // Issue 468: Chrome "Click to Active Flash" box stomps on title attribute - if (attrib.name === "title" && attrib.value === "Adobe Flash Player") { + if ( + attrib.name === "title" && + attrib.value === "Adobe Flash Player" + ) { continue; } @@ -174,7 +199,9 @@ export class RufflePlayer extends HTMLElement { this.setAttribute(attrib.name, attrib.value); } catch (err) { // The embed may have invalid attributes, so handle these gracefully. - console.warn(`Unable to set attribute ${attrib.name} on Ruffle instance`); + console.warn( + `Unable to set attribute ${attrib.name} on Ruffle instance` + ); } } } @@ -198,7 +225,7 @@ export class RufflePlayer extends HTMLElement { let out = match[1]; if (!match[3]) { // Unitless -- add px for CSS. - out += "px" + out += "px"; } return out; } @@ -211,5 +238,9 @@ export class RufflePlayer extends HTMLElement { * Returns whether the given filename ends in an "swf" extension. */ export function is_swf_filename(filename) { - return filename && typeof filename === "string" && filename.search(/\.swf\s*$/i) >= 0; + return ( + filename && + typeof filename === "string" && + filename.search(/\.swf\s*$/i) >= 0 + ); } diff --git a/web/js-src/source-api.js b/web/js-src/source-api.js index a590a5a3a..c46c7cb4f 100644 --- a/web/js-src/source-api.js +++ b/web/js-src/source-api.js @@ -4,7 +4,7 @@ import { RufflePlayer } from "./ruffle-player"; /** * Represents this particular version of Ruffle. - * + * * Multiple APIs can be instantiated from different sources; e.g. an "extension" * version, versus a "local" version. This expresses to the Public API * negotiator (see `PublicAPI`) what this particular version of Ruffle is and @@ -13,7 +13,7 @@ import { RufflePlayer } from "./ruffle-player"; export class SourceAPI { /** * Construct a Source API. - * + * * @param {string} source_name The name of this particular source. */ constructor(source_name) { @@ -23,32 +23,35 @@ export class SourceAPI { get version() { return "0.1.0"; } - + /** * Start up a particular set of polyfills. - * + * * Polyfills, once enabled, may not be disabled. However, this function may * be called again with a different list to enable further polyfills. - * + * * Do not run polyfills for more than one Ruffle source at a time. - * + * * @param {array} polyfills A list of polyfills. See the `polyfills` module * for a list of allowable strings. */ polyfill(polyfills) { polyfill(polyfills); } - + /** * Create a Ruffle player element using this particular version of Ruffle. - * + * * @returns {RufflePlayer} The player element. This is a DOM element that * may be inserted into the current page as you wish. */ create_player() { - let player_element_name = register_element("ruffle-player", RufflePlayer); + let player_element_name = register_element( + "ruffle-player", + RufflePlayer + ); let player = document.createElement(player_element_name); return player; } -} \ No newline at end of file +} diff --git a/web/js-src/version-range.js b/web/js-src/version-range.js index 9dba4e5ef..6933fb1f1 100644 --- a/web/js-src/version-range.js +++ b/web/js-src/version-range.js @@ -10,7 +10,7 @@ export class VersionRange { /** * Determine if a given version satisfies this range. - * + * * @param {Version} fver A version object to test against. * @return {bool} Whether or not the given version matches this range. */ @@ -22,18 +22,25 @@ export class VersionRange { let comparator = this.requirements[i][j][0]; let version = this.requirements[i][j][1]; - matches = matches && version.is_stable_or_compatible_prerelease(fver); + matches = + matches && version.is_stable_or_compatible_prerelease(fver); if (comparator === "" || comparator === "=") { matches = matches && version.is_equal(fver); } else if (comparator === ">") { matches = matches && version.has_precedence_over(fver); } else if (comparator === ">=") { - matches = matches && (version.has_precedence_over(fver) || version.is_equal(fver)); + matches = + matches && + (version.has_precedence_over(fver) || + version.is_equal(fver)); } else if (comparator === "<") { matches = matches && fver.has_precedence_over(version); } else if (comparator === "<=") { - matches = matches && (fver.has_precedence_over(version) || version.is_equal(fver)); + matches = + matches && + (fver.has_precedence_over(version) || + version.is_equal(fver)); } else if (comparator === "^") { matches = matches && version.is_compatible_with(fver); } @@ -45,7 +52,7 @@ export class VersionRange { /** * Parse a requirement string into a version range. - * + * * @param {string} requirement The version requirements, consisting of a * series of space-separated strings, each one being a semver version * optionally prefixed by a comparator (e.g. <, <=, >, >=, =, or ^), or the @@ -66,7 +73,9 @@ export class VersionRange { } else { let match = /[0-9]/.exec(components[i]); let comparator = components[i].slice(0, match.index).trim(); - let version = Version.from_semver(components[i].slice(match.index).trim()); + let version = Version.from_semver( + components[i].slice(match.index).trim() + ); requirement_set.push([comparator, version]); } @@ -79,4 +88,4 @@ export class VersionRange { return new VersionRange(requirement_set); } -} \ No newline at end of file +} diff --git a/web/js-src/version.js b/web/js-src/version.js index f561791c1..cc6f62f32 100644 --- a/web/js-src/version.js +++ b/web/js-src/version.js @@ -1,7 +1,7 @@ export class Version { /** * Construct a Version from components. - * + * * @param {number} major The major version * @param {number} minor The minor version * @param {number} patch The patch version @@ -20,10 +20,10 @@ export class Version { /** * Construct a version from a semver 2 compliant string. - * + * * This function is intended for use with semver 2 compliant strings. * Malformatted strins may still parse correctly, however. - * + * * @param {string} version_string A semver 2.0.0 compliant version string. * @return {Version} A version object. */ @@ -32,7 +32,7 @@ export class Version { pr_split = build_split[0].split("-"), version_split = pr_split[0].split("."), version = []; - + version.push(parseInt(version_split[0])); if (version_split[1] != undefined) { @@ -59,37 +59,51 @@ export class Version { version.push(undefined); } - return new Version(version[0], version[1], version[2], version[3], version[4]); + return new Version( + version[0], + version[1], + version[2], + version[3], + version[4] + ); } /** * Returns true if a given version is compatible with this one. - * + * * Compatibility is defined as having the same nonzero major version * number, or if both major versions are zero, the same nonzero minor * version number, or if both minor versions are zero, the same nonzero * patch version number. - * + * * This implements the ^ operator in npm's semver package, with the * exception of the prerelease exclusion rule. - * + * * @param {Version} fver The other version to test against * @return {bool} */ is_compatible_with(fver) { - return this.major !== 0 && this.major === fver.major || - this.major === 0 && fver.major === 0 && this.minor === fver.minor || - this.major === 0 && fver.major === 0 && this.minor === 0 && fver.minor === 0 && this.patch === fver.patch; + return ( + (this.major !== 0 && this.major === fver.major) || + (this.major === 0 && + fver.major === 0 && + this.minor === fver.minor) || + (this.major === 0 && + fver.major === 0 && + this.minor === 0 && + fver.minor === 0 && + this.patch === fver.patch) + ); } /** * Returns true if this version has precedence over (is newer than) another * version. - * + * * Precedence is defined as in the Semver 2 spec. This implements the > * operator in npm's semver package, with the exception of the prerelease * exclusion rule. - * + * * @param {Version} fver The other version to test against * @return {bool} True if this version has precedence over the other one. */ @@ -116,18 +130,38 @@ export class Version { return true; } else if (this.pr_ident !== undefined && fver.pr_ident !== undefined) { let is_numeric = /^[0-9]*$/; - for (let i = 0; i < this.pr_ident.length && i < fver.pr_ident.length; i += 1) { - if (!is_numeric.test(this.pr_ident[i]) && is_numeric.test(fver.pr_ident[i])) { + for ( + let i = 0; + i < this.pr_ident.length && i < fver.pr_ident.length; + i += 1 + ) { + if ( + !is_numeric.test(this.pr_ident[i]) && + is_numeric.test(fver.pr_ident[i]) + ) { return true; - } else if (is_numeric.test(this.pr_ident[i]) && is_numeric.test(fver.pr_ident[i])) { - if (parseInt(this.pr_ident[i]) > parseInt(fver.pr_ident[i])) { + } else if ( + is_numeric.test(this.pr_ident[i]) && + is_numeric.test(fver.pr_ident[i]) + ) { + if ( + parseInt(this.pr_ident[i]) > parseInt(fver.pr_ident[i]) + ) { return true; - } else if (parseInt(this.pr_ident[i]) < parseInt(fver.pr_ident[i])) { + } else if ( + parseInt(this.pr_ident[i]) < parseInt(fver.pr_ident[i]) + ) { return false; } - } else if (is_numeric.test(this.pr_ident[i]) && !is_numeric.test(fver.pr_ident[i])) { + } else if ( + is_numeric.test(this.pr_ident[i]) && + !is_numeric.test(fver.pr_ident[i]) + ) { return false; - } else if (!is_numeric.test(this.pr_ident[i]) && !is_numeric.test(fver.pr_ident[i])) { + } else if ( + !is_numeric.test(this.pr_ident[i]) && + !is_numeric.test(fver.pr_ident[i]) + ) { if (this.pr_ident[i] > fver.pr_ident[i]) { return true; } else if (this.pr_ident[i] < fver.pr_ident[i]) { @@ -135,7 +169,7 @@ export class Version { } } } - + return this.pr_ident.length > fver.pr_ident.length; } @@ -144,27 +178,29 @@ export class Version { /** * Tests if a given version is equivalent to this one. - * + * * Build and prerelease tags are ignored. - * + * * @param {Version} fver The other version to test against * @return {bool} True if the given version is equivalent. */ is_equal(fver) { - return this.major === fver.major && + return ( + this.major === fver.major && this.minor === fver.minor && - this.patch === fver.patch; + this.patch === fver.patch + ); } /** * Tests if a given version is stable or a compatible prerelease for this * version. - * + * * This implements the prerelease exclusion rule of NPM semver: a * prerelease version can only pass this check if the major/minor/patch * components of both versions are the same. Otherwise, the prerelease * version always fails. - * + * * @param {Version} fver The other version to test against * @return {bool} True if the given version is either stable, or a * prerelease in the same series as this one. @@ -173,9 +209,11 @@ export class Version { if (fver.pr_ident === undefined) { return true; } else { - return this.major === fver.major && + return ( + this.major === fver.major && this.minor === fver.minor && - this.patch === fver.patch; + this.patch === fver.patch + ); } } -} \ No newline at end of file +} diff --git a/web/package.json b/web/package.json index 43d17cb5b..6e2aadf80 100644 --- a/web/package.json +++ b/web/package.json @@ -1,12 +1,12 @@ { - "name": "ruffle", - "version": "0.1.0", - "description": "Root project of ruffle web", - "devDependencies": { - "babel-eslint": "^10.1.0", - "eslint": "^7.0.0", - "eslint-config-prettier": "^6.11.0", - "eslint-plugin-prettier": "^3.1.3", - "prettier": "^2.0.5" - } + "name": "ruffle", + "version": "0.1.0", + "description": "Root project of ruffle web", + "devDependencies": { + "babel-eslint": "^10.1.0", + "eslint": "^7.0.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.3", + "prettier": "^2.0.5" + } } diff --git a/web/selfhosted/js/ruffle.js b/web/selfhosted/js/ruffle.js index 5e8ff1d64..951030965 100644 --- a/web/selfhosted/js/ruffle.js +++ b/web/selfhosted/js/ruffle.js @@ -2,5 +2,9 @@ import { PublicAPI } from "../../js-src/public-api"; import { SourceAPI } from "../../js-src/source-api"; import { public_path } from "../../js-src/public-path"; -window.RufflePlayer = PublicAPI.negotiate(window.RufflePlayer, "local", new SourceAPI("local")); -__webpack_public_path__ = public_path(window.RufflePlayer.config, "local"); \ No newline at end of file +window.RufflePlayer = PublicAPI.negotiate( + window.RufflePlayer, + "local", + new SourceAPI("local") +); +__webpack_public_path__ = public_path(window.RufflePlayer.config, "local"); diff --git a/web/selfhosted/package.json b/web/selfhosted/package.json index b80245420..79008c231 100644 --- a/web/selfhosted/package.json +++ b/web/selfhosted/package.json @@ -1,16 +1,16 @@ { - "name": "ruffle-selfhosted", - "version": "0.1.0", - "description": "Put Flash back on the web with Ruffle on your own site", - "scripts": { - "build": "webpack", - "serve": "webpack-dev-server" - }, - "devDependencies": { - "@wasm-tool/wasm-pack-plugin": "^1.3.1", - "clean-webpack-plugin": "^3.0.0", - "webpack": "^4.43.0", - "webpack-cli": "^3.3.11", - "webpack-dev-server": "^3.11.0" - } + "name": "ruffle-selfhosted", + "version": "0.1.0", + "description": "Put Flash back on the web with Ruffle on your own site", + "scripts": { + "build": "webpack", + "serve": "webpack-dev-server" + }, + "devDependencies": { + "@wasm-tool/wasm-pack-plugin": "^1.3.1", + "clean-webpack-plugin": "^3.0.0", + "webpack": "^4.43.0", + "webpack-cli": "^3.3.11", + "webpack-dev-server": "^3.11.0" + } } diff --git a/web/selfhosted/webpack.config.js b/web/selfhosted/webpack.config.js index e6765cc1f..e361317e0 100644 --- a/web/selfhosted/webpack.config.js +++ b/web/selfhosted/webpack.config.js @@ -1,33 +1,33 @@ /* eslint-env node */ -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); -const path = require('path'); +const path = require("path"); module.exports = (env, argv) => { - let mode = "production"; - if (argv && argv.mode) { - mode = argv.mode; - } + let mode = "production"; + if (argv && argv.mode) { + mode = argv.mode; + } - console.log(`Building ${mode}...`); + console.log(`Building ${mode}...`); - return { - entry: path.resolve(__dirname, "js/ruffle.js"), - output: { - path: path.resolve(__dirname, "dist"), - filename: "ruffle.js", - chunkFilename: "core.ruffle.[contenthash].js", - jsonpFunction: "RufflePlayerLoader", - }, - mode: mode, - plugins: [ - new CleanWebpackPlugin(), - new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, ".."), - outName: "ruffle", - forceMode: mode, - }) - ] - } + return { + entry: path.resolve(__dirname, "js/ruffle.js"), + output: { + path: path.resolve(__dirname, "dist"), + filename: "ruffle.js", + chunkFilename: "core.ruffle.[contenthash].js", + jsonpFunction: "RufflePlayerLoader", + }, + mode: mode, + plugins: [ + new CleanWebpackPlugin(), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".."), + outName: "ruffle", + forceMode: mode, + }), + ], + }; };