New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bili-small-game

Package Overview
Dependencies
Maintainers
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bili-small-game - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

lib/adapter.android.js

1098

lib/adapter.game.js

@@ -7,3 +7,2 @@ // This file is always executed before the App's index.js. It sets up most of

// Make 'window' the global scope

@@ -13,176 +12,438 @@ self = window = this;

(function (window) {
(function(window) {
// The 'ej' object provides some basic info and utility functions
var ej = window.ejecta = new Ejecta.GlobalUtils();
var BiliGame = BCanvas;
var BiliUtils = new BiliGame.GlobalUtils.Instance();
var BiliExt = bl_ext;
var BiliTouchInput = new BiliGame.TouchInput.Instance();
// Set up the screen properties and useragent
window.devicePixelRatio = ej.devicePixelRatio;
window.innerWidth = ej.screenWidth;
window.innerHeight = ej.screenHeight;
// Create the default screen canvas
var screenCanvas = new BiliGame.Canvas.Instance();
screenCanvas.style = {};
window.canvas = screenCanvas;
window.sharedCanvas = new BiliGame.Canvas.Instance();
sharedCanvas.style = {};
var onScreen = true;
window.__SmallApp.fileSystemManager = new BiliGame.FileSystemManager.Instance();
Object.defineProperty(window, 'orientation', {
get: function () {
return ej.orientation;
function SocketObject(id, target) {
this.id = id;
this.target = target;
return this;
}
SocketObject.prototype.close = function(options) {
try {
this.target.close(options.code || 1000);
options && options.success && typeof options.success === 'function' && options.success({ errMsg: 'close:ok' });
options && options.complete && typeof options.complete === 'function' && options.complete({ errMsg: 'close:ok' });
} catch (e) {
options && options.fail && typeof options.fail === 'function' && options.fail({ errMsg: 'close:fail' });
options && options.complete && typeof options.complete === 'function' && options.complete({ errMsg: 'close:fail' });
}
});
};
window.screen = {
availWidth: window.innerWidth,
availHeight: window.innerHeight
SocketObject.prototype.send = function(options) {
try {
this.target.send(options.data);
options && options.success && typeof options.success === 'function' && options.success({ errMsg: 'close:ok' });
options && options.complete && typeof options.complete === 'function' && options.complete({ errMsg: 'close:ok' });
} catch (e) {
options && options.fail && typeof options.fail === 'function' && options.fail({ errMsg: 'close:fail' });
options && options.complete && typeof options.complete === 'function' && options.complete({ errMsg: 'close:fail' });
}
};
var geolocation = null;
SocketObject.prototype.onClose = function(callback) {
this.target.onclose = callback;
};
window.wx = window.bl;
SocketObject.prototype.onOpen = function(callback) {
this.target.onopen = callback;
};
window.navigator = {
language: ej.language,
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN",
appVersion: "5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
platform: ej.platform,
get onLine() {
return ej.onLine;
}, // re-evaluate on each get
get geolocation() { // Lazily create geolocation instance
geolocation = geolocation || new Ejecta.Geolocation();
return geolocation;
}
SocketObject.prototype.onError = function(callback) {
this.target.onerror = callback;
};
// Create the default screen canvas
window.canvas = new Ejecta.Canvas();
window.sharedCanvas = canvas;
window.canvas.type = 'canvas';
SocketObject.prototype.onMessage = function(callback) {
this.target.onmessage = callback;
};
// The console object
window.console = {
SocketObject.uid = 0;
// We try to be sensible of how much data we want to log here. Only the first
// level of an Object or Array is parsed. All subsequent levels are ommited.
// Arrays are shortened to the first 32 entries.
// To log an Object and traverse all levels, use console.logJSON()
_arrayMaxLength: 32,
const oldWebSocket = window.WebSocket;
_toString: function (obj, deep) {
if (deep) {
return JSON.stringify(obj);
} else if (obj instanceof Array || ArrayBuffer.isView(obj)) {
var s = '',
length = Math.min(obj.length, window.console._arrayMaxLength),
omitted = obj.length - length;
for (var i = 0; i < length; i++) {
s += (i === 0 ? '' : ', ') + window.console._toStringFlat(obj[i]);
}
return '[' + s + (omitted ? ', ...' + omitted + ' more]' : ']');
var bl = (window.bl = {
createCanvas: function() {
if (onScreen) {
onScreen = false;
return screenCanvas;
} else {
var s = '',
first = true;
for (var i in obj) {
s += (first ? '' : ', ') + i + ': ' + window.console._toStringFlat(obj[i]);
first = false;
}
return '{' + s + '}';
var tmp = new BiliGame.Canvas.Instance();
tmp.style = {};
return tmp;
}
},
_toStringFlat: function (obj) {
if (typeof (obj) === 'function') {
return '[Function]';
} else if (obj instanceof Array || ArrayBuffer.isView(obj)) {
return '[Array ' + obj.length + ']';
} else {
return obj;
createImage: function() {
return new BiliGame.Image.Instance();
},
onTouchStart: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.addEventListener('touchstart', callback);
},
_log: function (level, args, deep) {
var s = level + ':';
for (var i = 0; i < args.length; i++) {
var arg = args[i];
s += ' ' + (!arg || typeof (arg) !== 'object' ?
arg :
window.console._toString(arg, deep));
offTouchStart: function(callback) {
if (!callback) {
return;
}
ej.log(s);
BiliTouchInput.removeEventListener('touchstart', callback);
},
onTouchMove: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.addEventListener('touchmove', function(touchevt) {
callback(touchevt);
});
},
offTouchMove: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.removeEventListener('touchmove', callback);
},
onTouchEnd: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.addEventListener('touchend', callback);
},
offTouchEnd: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.removeEventListener('touchend', callback);
},
onTouchCancel: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.addEventListener('touchcancel', callback);
},
offTouchCancel: function(callback) {
if (!callback) {
return;
}
BiliTouchInput.removeEventListener('touchcancel', callback);
},
connectSocket: function(options) {
var url = options.url;
var protocols = options.protocols;
var header = options.header;
var tcpNoDelay = options.tcpNoDelay;
return new SocketObject(SocketObject.uid++, new oldWebSocket(url, protocols, header, tcpNoDelay));
},
loadFont: function(e) {
return BiliUtils.loadFont(e);
},
//TODO proxy to blapi
// createInnerAudioContext : function (){
// return {};
// },
//TODO proxy to blapi
// requireModule : function (a,b,c,d) {
// return _internalBL.requireModule(a,b,c,d);
// },
//TODO proxy to blapi
// getFileSystemManager : function (){
// return _internalBL.getFileSystemManager();
// },
//TODO proxy to blapi
// getTextLineHeight : function (e){
// return _internalBL.getTextLineHeight(e);
// },
});
assert: function () {
var args = Array.prototype.slice.call(arguments);
var assertion = args.shift();
if (!assertion) {
ej.log('Assertion failed: ' + args.join(', '));
}
}
// touchEvent.touches = touchEvt.touches;
// touchEvent.targetTouches = touchEvt.targetTouches;
// touchEvent.changedTouches = touchEvt.changedTouches;
// touchEvent.type = touchEvt.type;
// touchEvent.timestamp = touchEvt.stimestamp;
//TODO proxy to blapi
window.localStorage = {};
// Timers
window.performance = {
now: function() {
return BiliExt.performanceNow();
},
};
window.console.debug = function () {
window.console._log('DEBUG', arguments);
var timeoutOld = window.setTimeout;
var setIntervalOld = window.setInterval;
var clearTimeoutOld = window.clearTimeout;
var clearIntervalOld = window.clearInterval;
var requestAnimationFrameOld = window.requestAnimationFrame;
var cancelAnimationFrameOld = window.cancelAnimationFrame;
window.setTimeout = function(cb, t) {
return timeoutOld(cb, t || 0);
};
window.console.info = function () {
window.console._log('INFO', arguments);
window.setInterval = function(cb, t) {
return setIntervalOld(cb, t || 0);
};
window.console.warn = function () {
window.console._log('WARN', arguments);
window.clearTimeout = function(id) {
return clearTimeoutOld(id);
};
window.console.error = function () {
window.console._log('ERROR', arguments);
window.clearInterval = function(id) {
return clearIntervalOld(id);
};
window.console.log = function () {
window.console._log('LOG', arguments);
window.requestAnimationFrame = function(cb, element) {
return requestAnimationFrameOld(function() {
cb(BiliExt.performanceNow());
});
};
window.console.logJSON = function () {
window.console._log('JSON', arguments, true);
window.cancelAnimationFrame = function(id) {
return cancelAnimationFrameOld(id);
};
var consoleTimers = {};
console.time = function (name) {
consoleTimers[name] = ej.performanceNow();
// Set up the screen properties and useragent
window.devicePixelRatio = BiliUtils.devicePixelRatio;
window.innerWidth = BiliUtils.screenWidth;
window.innerHeight = BiliUtils.screenHeight;
// TODO NOT IMPLEMENTED
// Object.defineProperty(window, 'orientation', {
// get: function () {
// return ej.orientation;
// }
// });
window.screen = {
availWidth: window.innerWidth,
availHeight: window.innerHeight,
};
console.timeEnd = function (name) {
var timeStart = consoleTimers[name];
if (!timeStart) {
// var geolocation = null;
window.wx = window.bl;
window.navigator = {
language: window._locale,
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN', //hard code like weixin
appVersion: '5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', //hard code like weixin
platform: '', //TODO read from getSystemInfo
get onLine() {
return BiliExt.isOnline();
}, // re-evaluate on each get
//TODO proxy to blapi
// get geolocation() { // Lazily create geolocation instance
// geolocation = geolocation || new Ejecta.Geolocation();
// return geolocation;
// }
};
// The console object
var serialize = (function() {
var isMixed = function(obj) {
return /\[object (Object)|(Array)\]/.test(Object.prototype.toString.call(obj));
};
try {
// 尝试使用Proxy
var tempProxy = new Proxy({}, {});
var handler = function(rootPath = '@') {
var self = this;
return {
get: function(target, key) {
var result = Reflect.get(target, key);
var descriptor = Object.getOwnPropertyDescriptor(target, key);
if (isMixed(result)) {
var cacheKey = Array.isArray(target) ? `${rootPath}[${key}]` : `${rootPath}.${key}`;
var filtered = self.filter(function(a) {
return a.value === result;
});
if (filtered.length) {
return `<Circular ${filtered[0].key}>`;
}
self.push({ key: cacheKey, value: result });
return new Proxy(result, handler.call(self, cacheKey));
}
if (typeof result === 'function' && descriptor.enumerable) {
return '<Function>';
}
return result;
},
};
};
return function(obj, space) {
if (isMixed(obj)) {
var caches = [{ key: '@', value: obj }];
var proxy = new Proxy(obj, handler.call(caches));
return "'" + JSON.stringify(proxy, null, space) + "'";
}
return "'" + JSON.stringify(obj, null, space) + "'";
};
} catch (e) {
console.error(e);
// 兼容方案
return function(object) {
var trap = [];
return (
"'" +
JSON.stringify(object, (key, value) => {
if (isMixed(value)) {
if (
trap.reduce((prev, curr) => {
return curr.value === value || prev;
}, false)
) {
return '<Circular>';
} else {
trap.push({ key, value });
return value;
}
} else if (typeof value === 'function') {
return '<Function>';
}
return value;
}) +
"'"
);
};
}
})();
var needSerialize = window.console.isDebug;
var consoleDebugOld = window.console.debug;
var consoleInfoOld = window.console.info;
var consoleWarnOld = window.console.warn;
var consoleErrorOld = window.console.error;
var consoleLogOld = window.console.log;
window.console.debug = function() {
if (!needSerialize) {
consoleDebugOld.apply(window.console, arguments);
return;
}
var timeElapsed = ej.performanceNow() - timeStart;
console.log(name + ": " + timeElapsed + "ms");
delete consoleTimers[name];
for (var i = 0; i < arguments.length; i++) {
try {
consoleDebugOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
// Timers
window.performance = {
now: function () {
return ej.performanceNow();
window.console.assert = function() {
if (!needSerialize) {
consoleLogOld.apply(window.console, arguments);
return;
}
for (var i = 0; i < arguments.length; i++) {
try {
consoleLogOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
window.setTimeout = function (cb, t) {
return ej.setTimeout(cb, t || 0);
window.console.log = function() {
if (!needSerialize) {
consoleLogOld.apply(window.console, arguments);
return;
}
for (var i = 0; i < arguments.length; i++) {
try {
consoleLogOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
window.setInterval = function (cb, t) {
return ej.setInterval(cb, t || 0);
window.console.info = function() {
if (!needSerialize) {
consoleInfoOld.apply(window.console, arguments);
return;
}
for (var i = 0; i < arguments.length; i++) {
try {
consoleInfoOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
window.clearTimeout = function (id) {
return ej.clearTimeout(id);
window.console.warn = function() {
if (!needSerialize) {
consoleWarnOld.apply(window.console, arguments);
return;
}
for (var i = 0; i < arguments.length; i++) {
try {
consoleWarnOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
window.clearInterval = function (id) {
return ej.clearInterval(id);
window.console.error = function() {
if (!needSerialize) {
consoleErrorOld.apply(window.console, arguments);
return;
}
for (var i = 0; i < arguments.length; i++) {
try {
consoleErrorOld(serialize(arguments[i]));
} catch (e) {
consoleErrorOld(JSON.stringify(e.message));
}
}
};
window.requestAnimationFrame = function (cb, element) {
return ej.setTimeout(function () {
cb(ej.performanceNow());
}, 16);
var consoleTimers = {};
console.time = function(name) {
consoleTimers[name] = BiliExt.performanceNow();
};
window.cancelAnimationFrame = function (id) {
return ej.clearTimeout(id);
console.timeEnd = function(name) {
var timeStart = consoleTimers[name];
if (!timeStart) {
return;
}
var timeElapsed = BiliExt.performanceNow() - timeStart;
console.log(name + ': ' + timeElapsed + 'ms');
delete consoleTimers[name];
};
// The native Image, Audio, HttpRequest and LocalStorage class mimic the real elements
window.Image = Ejecta.Image;
window.Video = Ejecta.Video;
window.XMLHttpRequest = Ejecta.HttpRequest;
window.localStorage = new Ejecta.LocalStorage();
window.WebSocket = Ejecta.WebSocket;
window.Image = BiliGame.Image.Instance;
//TODO NOT IMPLEMENTED
// window.Video = Ejecta.Video;
//TODO proxy to blapi
// window.XMLHttpRequest = Ejecta.HttpRequest;
window.Event = function (type) {
//TODO NOT IMPLEMENTED
// window.WebSocket = Ejecta.WebSocket;
window.Event = function(type) {
this.type = type;

@@ -192,28 +453,30 @@ this.cancelBubble = false;

this.target = null;
this.timestamp = ej.performanceNow();
this.timestamp = BiliExt.performanceNow();
this.initEvent = function (type, bubbles, cancelable) {
this.initEvent = function(type, bubbles, cancelable) {
this.type = type;
this.cancelBubble = bubbles;
this.cancelable = cancelable;
this.timestamp = ej.performanceNow();
this.timestamp = BiliExt.performanceNow();
};
this.preventDefault = function () {};
this.stopPropagation = function () {};
this.preventDefault = function() {};
this.stopPropagation = function() {};
};
window.location = {
href: 'index.js'
href: 'game.js',
};
window.location.reload = function () {
ejecta.load('index.js');
}
window.location.reload = function() {
//TODO
//ejecta.load('index.js');
};
window.open = function (url) {
ej.openURL(url);
window.open = function(url) {
// TODO
// ej.openURL(url);
};
// Set up a "fake" HTMLElement
HTMLElement = function (tagName) {
// Set up a 'fake' HTMLElement
HTMLElement = function(tagName) {
this.tagName = tagName.toUpperCase();

@@ -224,24 +487,25 @@ this.children = [];

HTMLElement.prototype.appendChild = function (element) {
this.children.push(element);
// TODO
// HTMLElement.prototype.appendChild = function (element) {
// this.children.push(element);
//
// // If the child is a script element, begin to load it or execute it
// if (element.tagName && element.tagName.toLowerCase() == 'script') {
// if (element.src) {
// setTimeout(function () {
// bl.include(element.src);
// if (element.onload) {
// element.onload({
// type: 'load',
// currentTarget: element
// });
// }
// }, 1);
// } else if (element.text) {
// window.eval(element.text);
// }
// }
// };
// If the child is a script element, begin to load it or execute it
if (element.tagName && element.tagName.toLowerCase() == 'script') {
if (element.src) {
ej.setTimeout(function () {
ej.include(element.src);
if (element.onload) {
element.onload({
type: 'load',
currentTarget: element
});
}
}, 1);
} else if (element.text) {
window.eval(element.text);
}
}
};
HTMLElement.prototype.insertBefore = function (newElement, existingElement) {
HTMLElement.prototype.insertBefore = function(newElement, existingElement) {
// Just append; we don't care about order here

@@ -251,4 +515,4 @@ this.appendChild(newElement);

HTMLElement.prototype.removeChild = function (node) {
for (var i = this.children.length; i--;) {
HTMLElement.prototype.removeChild = function(node) {
for (var i = this.children.length; i--; ) {
if (this.children[i] === node) {

@@ -260,3 +524,3 @@ this.children.splice(i, 1);

HTMLElement.prototype.getBoundingClientRect = function () {
HTMLElement.prototype.getBoundingClientRect = function() {
return {

@@ -266,15 +530,15 @@ top: 0,

width: window.innerWidth,
height: window.innerHeight
height: window.innerHeight,
};
};
HTMLElement.prototype.setAttribute = function (attr, value) {
HTMLElement.prototype.setAttribute = function(attr, value) {
this[attr] = value;
};
HTMLElement.prototype.getAttribute = function (attr) {
HTMLElement.prototype.getAttribute = function(attr) {
return this[attr];
};
HTMLElement.prototype.addEventListener = function (event, method) {
HTMLElement.prototype.addEventListener = function(event, method) {
if (event === 'load') {

@@ -285,3 +549,3 @@ this.onload = method;

HTMLElement.prototype.removeEventListener = function (event, method) {
HTMLElement.prototype.removeEventListener = function(event, method) {
if (event === 'load') {

@@ -294,3 +558,3 @@ this.onload = undefined;

if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
throw new TypeError('Cannot call a class as a function');
}

@@ -303,8 +567,8 @@ }

}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
return call && (typeof call === 'object' || typeof call === 'function') ? call : self;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
}

@@ -316,9 +580,9 @@ subClass.prototype = Object.create(superClass && superClass.prototype, {

writable: true,
configurable: true
}
configurable: true,
},
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : (subClass.__proto__ = superClass);
}
HTMLImageElement = function (_HTMLElement) {
HTMLImageElement = (function(_HTMLElement) {
_inherits(HTMLImageElement, _HTMLElement);

@@ -333,5 +597,5 @@

return HTMLImageElement;
}(HTMLElement);
})(HTMLElement);
HTMLCanvasElement = function (_HTMLElement) {
HTMLCanvasElement = (function(_HTMLElement) {
_inherits(HTMLCanvasElement, _HTMLElement);

@@ -346,5 +610,5 @@

return HTMLCanvasElement;
}(HTMLElement);
})(HTMLElement);
HTMLVideoElement = function (_HTMLElement) {
HTMLVideoElement = function(_HTMLElement) {
_inherits(HTMLVideoElement, _HTMLElement);

@@ -359,3 +623,3 @@

return HTMLVideoElement;
}
};

@@ -376,41 +640,49 @@ // The document object

createElement: function (name) {
createElement: function(name) {
if (name === 'canvas') {
var canvas = new Ejecta.Canvas();
canvas.type = 'canvas';
var canvas = bl.createCanvas();
return canvas;
} else if (name == 'audio') {
return new Ejecta.Audio();
} else if (name == 'video') {
return new Ejecta.Video();
} else if (name === 'img') {
return new window.Image();
} else if (name === 'input' || name === 'textarea') {
return new Ejecta.KeyInput();
}
// TODO proxy to blapi
// else if (name == 'audio') {
// return new Ejecta.Audio();
// } else if (name == 'video') {
// return new Ejecta.Video();
// }
else if (name === 'img') {
return bl.createImage();
}
// TODO NOT IMPLEMENTED
// else if (name === 'input' || name === 'textarea') {
// return new Ejecta.KeyInput();
// }
return new HTMLElement(name);
},
createElementNS: function (namespace, name) {
createElementNS: function(namespace, name) {
if (name === 'canvas') {
var canvas = new Ejecta.Canvas();
canvas.type = 'canvas';
var canvas = bl.createCanvas();
return canvas;
} else if (name == 'audio') {
return new Ejecta.Audio();
} else if (name == 'video') {
return new Ejecta.Video();
} else if (name === 'img') {
return new window.Image();
} else if (name === 'input' || name === 'textarea') {
return new Ejecta.KeyInput();
}
// TODO proxy to blapi
// else if (name == 'audio') {
// return new Ejecta.Audio();
// } else if (name == 'video') {
// return new Ejecta.Video();
// }
else if (name === 'img') {
return bl.createImage();
}
// TODO NOT IMPLEMENTED
// else if (name === 'input' || name === 'textarea') {
// return new Ejecta.KeyInput();
// }
return new HTMLElement(name);
},
createTextNode: function () {
createTextNode: function() {
return new HTMLElement('div');
},
getElementById: function (id) {
getElementById: function(id) {
if (id === 'canvas') {

@@ -422,5 +694,6 @@ return window.canvas;

getElementsByTagName: function (tagName) {
getElementsByTagName: function(tagName) {
var elements = [],
children, i;
children,
i;

@@ -445,9 +718,9 @@ tagName = tagName.toLowerCase();

createEvent: function (type) {
createEvent: function(type) {
return new window.Event(type);
},
addEventListener: function (type, callback, useCapture) {
addEventListener: function(type, callback, useCapture) {
if (type == 'DOMContentLoaded') {
ej.setTimeout(callback, 1);
window.setTimeout(callback, 1);
return;

@@ -460,3 +733,3 @@ }

// bind to this event.
if (typeof (this._eventInitializers[type]) == 'function') {
if (typeof this._eventInitializers[type] == 'function') {
this._eventInitializers[type]();

@@ -468,3 +741,3 @@ }

removeEventListener: function (type, callback) {
removeEventListener: function(type, callback) {
var listeners = this.events[type];

@@ -475,3 +748,3 @@ if (!listeners) {

for (var i = listeners.length; i--;) {
for (var i = listeners.length; i--; ) {
if (listeners[i] === callback) {

@@ -484,3 +757,3 @@ listeners.splice(i, 1);

_eventInitializers: {},
dispatchEvent: function (event) {
dispatchEvent: function(event) {
var listeners = this.events[event.type];

@@ -494,17 +767,17 @@ if (!listeners) {

}
}
},
};
window.canvas.addEventListener = window.addEventListener = function (type, callback) {
window.canvas.addEventListener = window.addEventListener = function(type, callback) {
window.document.addEventListener(type, callback);
};
window.canvas.removeEventListener = window.removeEventListener = function (type, callback) {
window.canvas.removeEventListener = window.removeEventListener = function(type, callback) {
window.document.removeEventListener(type, callback);
};
window.canvas.getBoundingClientRect = function () {
window.canvas.getBoundingClientRect = function() {
return {
top: this.offsetTop,
left: this.offsetLeft,
width: this.offsetWidth,
height: this.offsetHeight
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight,
};

@@ -515,4 +788,2 @@ };

// Touch events

@@ -536,16 +807,16 @@

timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
preventDefault: function() {},
stopPropagation: function() {},
};
var dispatchTouchEvent = function (type, all, changed, timestamp) {
touchEvent.touches = all;
touchEvent.targetTouches = all;
touchEvent.changedTouches = changed;
var dispatchTouchEvent = function(type, touchEvt) {
touchEvent.touches = touchEvt.touches;
touchEvent.targetTouches = touchEvt.touches;
touchEvent.changedTouches = touchEvt.changedTouches;
touchEvent.type = type;
touchEvent.timestamp = timestamp;
touchEvent.timestamp = touchEvt.timeStamp;
document.dispatchEvent(touchEvent);
};
eventInit.touchstart = eventInit.touchend = eventInit.touchmove = function () {
eventInit.touchstart = eventInit.touchend = eventInit.touchmove = function() {
if (touchInput) {

@@ -555,193 +826,186 @@ return;

touchInput = new Ejecta.TouchInput(window.canvas);
touchInput.ontouchstart = dispatchTouchEvent.bind(window, 'touchstart');
touchInput.ontouchend = dispatchTouchEvent.bind(window, 'touchend');
touchInput.ontouchmove = dispatchTouchEvent.bind(window, 'touchmove');
bl.onTouchStart(dispatchTouchEvent.bind(window, 'touchstart'));
bl.onTouchEnd(dispatchTouchEvent.bind(window, 'touchend'));
bl.onTouchMove(dispatchTouchEvent.bind(window, 'touchmove'));
bl.onTouchCancel(dispatchTouchEvent.bind(window, 'touchcancel'));
};
// TODO WAIT IMPLEMENT
// DeviceMotion and DeviceOrientation events
// var deviceMotion = null;
// var deviceMotionEvent = {
// type: 'devicemotion',
// target: window.canvas,
// currentTarget: window.canvas,
// interval: 16,
// acceleration: {
// x: 0,
// y: 0,
// z: 0
// },
// accelerationIncludingGravity: {
// x: 0,
// y: 0,
// z: 0
// },
// rotationRate: {
// alpha: 0,
// beta: 0,
// gamma: 0
// },
// timestamp: 0,
// preventDefault: function () {},
// stopPropagation: function () {}
// };
//
// var deviceOrientationEvent = {
// type: 'deviceorientation',
// target: window.canvas,
// currentTarget: window.canvas,
// alpha: null,
// beta: null,
// gamma: null,
// absolute: true,
// timestamp: 0,
// preventDefault: function () {},
// stopPropagation: function () {}
// };
//
// eventInit.deviceorientation = eventInit.devicemotion = function () {
// if (deviceMotion) {
// return;
// }
//
// deviceMotion = new Ejecta.DeviceMotion();
// deviceMotionEvent.interval = deviceMotion.interval;
//
// // Callback for Devices that have a Gyro
// deviceMotion.ondevicemotion = function (agx, agy, agz, ax, ay, az, rx, ry, rz, ox, oy, oz, timestamp) {
// deviceMotionEvent.accelerationIncludingGravity.x = agx;
// deviceMotionEvent.accelerationIncludingGravity.y = agy;
// deviceMotionEvent.accelerationIncludingGravity.z = agz;
//
// deviceMotionEvent.acceleration.x = ax;
// deviceMotionEvent.acceleration.y = ay;
// deviceMotionEvent.acceleration.z = az;
//
// deviceMotionEvent.rotationRate.alpha = rx;
// deviceMotionEvent.rotationRate.beta = ry;
// deviceMotionEvent.rotationRate.gamma = rz;
//
// deviceMotionEvent.timestamp = timestamp;
//
// document.dispatchEvent(deviceMotionEvent);
//
//
// deviceOrientationEvent.alpha = ox;
// deviceOrientationEvent.beta = oy;
// deviceOrientationEvent.gamma = oz;
//
// deviceOrientationEvent.timestamp = timestamp;
//
// document.dispatchEvent(deviceOrientationEvent);
// };
//
// // Callback for Devices that only have an accelerometer
// deviceMotion.onacceleration = function (agx, agy, agz, timestamp) {
// deviceMotionEvent.accelerationIncludingGravity.x = agx;
// deviceMotionEvent.accelerationIncludingGravity.y = agy;
// deviceMotionEvent.accelerationIncludingGravity.z = agz;
//
// deviceMotionEvent.acceleration = null;
// deviceMotionEvent.rotationRate = null;
//
// deviceMotionEvent.timestamp = timestamp;
//
// document.dispatchEvent(deviceMotionEvent);
// };
// };
var deviceMotion = null;
var deviceMotionEvent = {
type: 'devicemotion',
target: window.canvas,
currentTarget: window.canvas,
interval: 16,
acceleration: {
x: 0,
y: 0,
z: 0
},
accelerationIncludingGravity: {
x: 0,
y: 0,
z: 0
},
rotationRate: {
alpha: 0,
beta: 0,
gamma: 0
},
timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
};
var deviceOrientationEvent = {
type: 'deviceorientation',
target: window.canvas,
currentTarget: window.canvas,
alpha: null,
beta: null,
gamma: null,
absolute: true,
timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
};
eventInit.deviceorientation = eventInit.devicemotion = function () {
if (deviceMotion) {
return;
}
deviceMotion = new Ejecta.DeviceMotion();
deviceMotionEvent.interval = deviceMotion.interval;
// Callback for Devices that have a Gyro
deviceMotion.ondevicemotion = function (agx, agy, agz, ax, ay, az, rx, ry, rz, ox, oy, oz, timestamp) {
deviceMotionEvent.accelerationIncludingGravity.x = agx;
deviceMotionEvent.accelerationIncludingGravity.y = agy;
deviceMotionEvent.accelerationIncludingGravity.z = agz;
deviceMotionEvent.acceleration.x = ax;
deviceMotionEvent.acceleration.y = ay;
deviceMotionEvent.acceleration.z = az;
deviceMotionEvent.rotationRate.alpha = rx;
deviceMotionEvent.rotationRate.beta = ry;
deviceMotionEvent.rotationRate.gamma = rz;
deviceMotionEvent.timestamp = timestamp;
document.dispatchEvent(deviceMotionEvent);
deviceOrientationEvent.alpha = ox;
deviceOrientationEvent.beta = oy;
deviceOrientationEvent.gamma = oz;
deviceOrientationEvent.timestamp = timestamp;
document.dispatchEvent(deviceOrientationEvent);
};
// Callback for Devices that only have an accelerometer
deviceMotion.onacceleration = function (agx, agy, agz, timestamp) {
deviceMotionEvent.accelerationIncludingGravity.x = agx;
deviceMotionEvent.accelerationIncludingGravity.y = agy;
deviceMotionEvent.accelerationIncludingGravity.z = agz;
deviceMotionEvent.acceleration = null;
deviceMotionEvent.rotationRate = null;
deviceMotionEvent.timestamp = timestamp;
document.dispatchEvent(deviceMotionEvent);
};
};
// TODO WAIT IMPLEMENT
// Window events (resize/pagehide/pageshow)
// var windowEvents = null;
//
// var lifecycleEvent = {
// type: 'pagehide',
// target: window.document,
// currentTarget: window.document,
// timestamp: 0,
// preventDefault: function () {},
// stopPropagation: function () {}
// };
//
// var resizeEvent = {
// type: 'resize',
// target: window,
// currentTarget: window,
// timestamp: 0,
// preventDefault: function () {},
// stopPropagation: function () {}
// };
//
// var visibilityEvent = {
// type: 'visibilitychange',
// target: window.document,
// currentTarget: window.document,
// timestamp: 0,
// preventDefault: function () {},
// stopPropagation: function () {}
// };
//
// eventInit.visibilitychange = eventInit.pagehide = eventInit.pageshow = eventInit.resize = function () {
// if (windowEvents) {
// return;
// }
//
// windowEvents = new Ejecta.WindowEvents();
//
// windowEvents.onpagehide = function () {
// document.hidden = true;
// document.visibilityState = 'hidden';
// visibilityEvent.timestamp = ej.performanceNow();
// document.dispatchEvent(visibilityEvent);
//
// lifecycleEvent.type = 'pagehide';
// document.dispatchEvent(lifecycleEvent);
// };
//
// windowEvents.onpageshow = function () {
// document.hidden = false;
// document.visibilityState = 'visible';
// visibilityEvent.timestamp = ej.performanceNow();
// document.dispatchEvent(visibilityEvent);
//
// lifecycleEvent.type = 'pageshow';
// document.dispatchEvent(lifecycleEvent);
// };
//
// windowEvents.onresize = function () {
// window.innerWidth = ej.screenWidth;
// window.innerHeight = ej.screenHeight;
// resizeEvent.timestamp = ej.performanceNow();
// document.dispatchEvent(resizeEvent);
// };
// };
var windowEvents = null;
var lifecycleEvent = {
type: 'pagehide',
target: window.document,
currentTarget: window.document,
timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
};
var resizeEvent = {
type: 'resize',
target: window,
currentTarget: window,
timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
};
var visibilityEvent = {
type: 'visibilitychange',
target: window.document,
currentTarget: window.document,
timestamp: 0,
preventDefault: function () {},
stopPropagation: function () {}
};
eventInit.visibilitychange = eventInit.pagehide = eventInit.pageshow = eventInit.resize = function () {
if (windowEvents) {
return;
}
windowEvents = new Ejecta.WindowEvents();
windowEvents.onpagehide = function () {
document.hidden = true;
document.visibilityState = 'hidden';
visibilityEvent.timestamp = ej.performanceNow();
document.dispatchEvent(visibilityEvent);
lifecycleEvent.type = 'pagehide';
document.dispatchEvent(lifecycleEvent);
};
windowEvents.onpageshow = function () {
document.hidden = false;
document.visibilityState = 'visible';
visibilityEvent.timestamp = ej.performanceNow();
document.dispatchEvent(visibilityEvent);
lifecycleEvent.type = 'pageshow';
document.dispatchEvent(lifecycleEvent);
};
windowEvents.onresize = function () {
window.innerWidth = ej.screenWidth;
window.innerHeight = ej.screenHeight;
resizeEvent.timestamp = ej.performanceNow();
document.dispatchEvent(resizeEvent);
};
};
// TODO NOT IMPLEMENTED
// Gamepad API
var gamepadProvider = null;
var initGamepadProvider = function () {
if (gamepadProvider) {
return;
}
gamepadProvider = new Ejecta.GamepadProvider();
gamepadProvider.ongamepadconnected = gamepadProvider.ongamepaddisconnected = function (ev) {
document.dispatchEvent(ev);
};
};
navigator.getGamepads = function () {
initGamepadProvider();
return gamepadProvider.getGamepads();
};
eventInit.gamepadconnected = eventInit.gamepaddisconnected = initGamepadProvider;
// var gamepadProvider = null;
// var initGamepadProvider = function () {
// if (gamepadProvider) {
// return;
// }
// gamepadProvider = new Ejecta.GamepadProvider();
//
// gamepadProvider.ongamepadconnected = gamepadProvider.ongamepaddisconnected = function (ev) {
// document.dispatchEvent(ev);
// };
// };
//
// navigator.getGamepads = function () {
// initGamepadProvider();
// return gamepadProvider.getGamepads();
// };
//
// eventInit.gamepadconnected = eventInit.gamepaddisconnected = initGamepadProvider;
})(this);
{
"name": "bili-small-game",
"version": "1.0.11",
"version": "1.0.12",
"description": "bilibili small game",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc