web: Reformatted all javascript with prettier

This commit is contained in:
Nathan Adams 2020-05-13 00:24:41 +02:00 committed by Mike Welsh
parent 56e467b557
commit a4b705c731
25 changed files with 554 additions and 364 deletions

View File

@ -11,6 +11,6 @@
},
"rules": {
"no-console": "off",
"no-constant-condition": ["error", {"checkLoops": false}]
"no-constant-condition": ["error", { "checkLoops": false }]
}
}

View File

@ -1,3 +1,3 @@
{
"tabWidth": 4
"tabWidth": 4
}

View File

@ -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"
}
}

View File

@ -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,
}),
],
};
};

View File

@ -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,7 +70,8 @@ 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") {
author_container.style.display = "block";
@ -72,9 +80,8 @@ function sampleFileSelected() {
localFileInput.value = null;
loadRemoteFile(selected_value);
}
else {
replacePlayer()
} else {
replacePlayer();
}
}
@ -89,16 +96,15 @@ function localFileSelected() {
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() {

View File

@ -16,26 +16,40 @@
*/
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<a.length&&!navigator.mimeTypes.install&&Object.defineProperty(navigator,"mimeTypes",{value:new RuffleMimeTypeArray(navigator.mimeTypes),writable:!1});for(var b=0;b<a.length;b+=1)navigator.mimeTypes.install(a[b])}install_plugin(FLASH_PLUGIN);})();';
let scriptelem = document.createElement("script");
setup_scriptelem.innerHTML = setup_src;
@ -45,8 +59,8 @@ if (!(page_optout || window.RufflePlayer)) {
(document.head || document.documentElement).appendChild(setup_scriptelem);
window.RufflePlayer = {};
window.RufflePlayer.config = {
"public_path": ext_path + "dist/",
"polyfills": ["static-content", "dynamic-content"]
public_path: ext_path + "dist/",
polyfills: ["static-content", "dynamic-content"],
/* We only want "static-content" & "dynamic-content" because we *
* inject the plugin polyfill above & use all_frames in *
* manifest.json for (i)frames. */

View File

@ -1,4 +1,8 @@
import { PublicAPI } from "../../js-src/public-api";
import { SourceAPI } from "../../js-src/source-api";
window.RufflePlayer = PublicAPI.negotiate(window.RufflePlayer, "extension", new SourceAPI());
window.RufflePlayer = PublicAPI.negotiate(
window.RufflePlayer,
"extension",
new SourceAPI()
);

View File

@ -1,17 +1,17 @@
{
"name": "ruffle-extension",
"version": "0.1.0",
"description": "Extension packaging for 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.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
}
"name": "ruffle-extension",
"version": "0.1.0",
"description": "Extension packaging for 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.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
}
}

View File

@ -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/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,
}),
],
};
};

View File

@ -128,12 +128,33 @@ 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`.
@ -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,
});
}

View File

@ -1,22 +1,22 @@
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.
@ -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<current_iframes.length;i++) {
let current_frame=current_iframes[i];
let current_iframes = depth.document.getElementsByTagName("iframe");
let current_frames = depth.document.getElementsByTagName("frame");
for (let i = 0; i < current_iframes.length; i++) {
let current_frame = current_iframes[i];
/* Apperently, using addEventListener attatches the event *
* to the dummy document, which is overwritten when the *
* iframe is loaded, so we do this. It can only works if *
@ -117,12 +119,12 @@ function polyfill_frames_common(depth) {
* of depth.frames to get the iframes at the depth. *
* Also, this way we should be able to handle frame *
* frame navigation, which is good. */
current_frame.onload=load_ruffle_player_into_frame;
current_frame.onload = load_ruffle_player_into_frame;
polyfill_frames_common(current_frame.contentWindow);
}
for (let i=0;i<current_frames.length;i++) {
let current_frame=current_frames[i];
current_frame.onload=load_ruffle_player_into_frame;
for (let i = 0; i < current_frames.length; i++) {
let current_frame = current_frames[i];
current_frame.onload = load_ruffle_player_into_frame;
polyfill_frames_common(current_frame.contentWindow);
}
}
@ -133,7 +135,9 @@ function polyfill_static_frames() {
function ruffle_frame_listener(mutationsList) {
/* Basically the same as the listener for dynamic embeds. */
let nodesAdded = mutationsList.some(mutation => 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]);

View File

@ -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 {
@ -90,7 +93,8 @@ export class PublicAPI {
* 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)) {
@ -129,7 +133,11 @@ 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);
@ -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];
}
}
}
@ -237,7 +245,10 @@ export class PublicAPI {
*/
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);
@ -251,7 +262,10 @@ export class PublicAPI {
// 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"]);
}
}

View File

@ -20,7 +20,11 @@
*/
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;

View File

@ -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;
@ -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;

View File

@ -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);

View File

@ -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 {
@ -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);

View File

@ -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}; }`
);
}
}
}
@ -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
);
}

View File

@ -46,7 +46,10 @@ export class SourceAPI {
* 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;

View File

@ -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);
}
@ -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]);
}

View File

@ -59,7 +59,13 @@ 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]
);
}
/**
@ -77,9 +83,17 @@ export class Version {
* @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)
);
}
/**
@ -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]) {
@ -151,9 +185,11 @@ export class Version {
* @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
);
}
/**
@ -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
);
}
}
}

View File

@ -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"
}
}

View File

@ -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"));
window.RufflePlayer = PublicAPI.negotiate(
window.RufflePlayer,
"local",
new SourceAPI("local")
);
__webpack_public_path__ = public_path(window.RufflePlayer.config, "local");

View File

@ -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"
}
}

View File

@ -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,
}),
],
};
};