修改验证方法

This commit is contained in:
Harvey Zack committed 2018-10-24 14:54:56 +08:00
1 parent 4ce05442c7
commit 8a88fb3043
9 files changed
+189 -123

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 18 KiB

+4 -22
View File
@@ -25,6 +25,10 @@
</div>
<script src="./js/artplayer.js"></script>
<script>
function Test(option) {
this.option = option;
}
var player = new Artplayer({
container: '.artplayer-app',
url: './video/one-more-time-one-more-chance.mp4',
@@ -37,7 +41,6 @@
width: 190,
height: 107
},
contextmenu: [],
highlight: [
{
time: 60,
@@ -91,27 +94,6 @@
console.log('video', event);
});
});
// Artplayer.config.mse.mediaSource.events.forEach(item => {
// player.on('mediaSource:' + item, event => {
// console.log('mediaSource', event);
// });
// });
// Artplayer.config.mse.sourceBufferList.events.forEach(item => {
// player.on('sourceBuffers:' + item, event => {
// console.log('sourceBuffers', event);
// });
// player.on('activeSourceBuffers:' + item, event => {
// console.log('activeSourceBuffers', event);
// });
// });
// Artplayer.config.mse.sourceBuffer.events.forEach(item => {
// player.on('sourceBuffer:' + item, event => {
// console.log('sourceBuffer', event);
// });
// });
</script>
</body>
+106 -67
View File
@@ -217,52 +217,6 @@
var objectSpread = _objectSpread;
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
var arrayWithHoles = _arrayWithHoles;
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
var iterableToArrayLimit = _iterableToArrayLimit;
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var nonIterableRest = _nonIterableRest;
function _slicedToArray(arr, i) {
return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
}
var slicedToArray = _slicedToArray;
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
@@ -396,18 +350,16 @@
returnValue = toConsumableArray(returnValue).concat(toConsumableArray(source));
} else if (isObject(source)) {
var _arr = Object.entries(source);
for (var key in source) {
if (source.hasOwnProperty(key)) {
var value = source[key];
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
var _arr$_i = slicedToArray(_arr[_i2], 2),
key = _arr$_i[0],
value = _arr$_i[1];
if (isObject(value) && key in returnValue) {
value = deepMerge(returnValue[key], value);
}
if (isObject(value) && Reflect.has(returnValue, key)) {
value = deepMerge(returnValue[key], value);
returnValue = objectSpread({}, returnValue, defineProperty({}, key, value));
}
returnValue = objectSpread({}, returnValue, defineProperty({}, key, value));
}
}
}
@@ -440,6 +392,51 @@
if (type === 'object') {
validOption(defaultValue, value, path.concat(key));
}
if (path.length === 1) {
if (key === 'layers') {
value.forEach(function (item, index) {
validOption({
name: '',
index: 0,
html: '',
style: {}
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'contextmenu') {
value.forEach(function (item, index) {
validOption({
name: '',
click: new Function(),
html: '',
style: {}
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'highlight') {
value.forEach(function (item, index) {
validOption({
time: 0,
text: ''
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'controls') {
value.forEach(function (item, index) {
if (item.option) {
validOption({
disable: false,
position: '',
index: 0
}, item.option, path.concat("".concat(key, "[").concat(index, "]")));
}
});
}
}
});
}
@@ -897,6 +894,52 @@
return Pip;
}();
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
var arrayWithHoles = _arrayWithHoles;
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
var iterableToArrayLimit = _iterableToArrayLimit;
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var nonIterableRest = _nonIterableRest;
function _slicedToArray(arr, i) {
return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
}
var slicedToArray = _slicedToArray;
var loading = "<svg class=\"lds-spinner\" width=\"80px\" height=\"80px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 100 100\" preserveAspectRatio=\"xMidYMid\" style=\"background: none;\"><g transform=\"rotate(0 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.9166666666666666s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(30 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.8333333333333334s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(60 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.75s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(90 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.6666666666666666s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(120 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.5833333333333334s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(150 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.5s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(180 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.4166666666666667s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(210 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.3333333333333333s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(240 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.25s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(270 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.16666666666666666s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(300 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.08333333333333333s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g><g transform=\"rotate(330 50 50)\">\n <rect x=\"47\" y=\"24\" rx=\"9.4\" ry=\"4.8\" width=\"6\" height=\"12\" fill=\"#ffffff\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"0s\" repeatCount=\"indefinite\"></animate>\n </rect>\n</g></svg>\n";
var playBig = "<svg style=\"width: 60px; height: 60px; filter: drop-shadow(0px 1px 1px black);\" version=\"1.1\" viewBox=\"0 0 24 24\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"info\"/>\n <g id=\"icons\">\n <path d=\"M20,2H4C1.8,2,0,3.8,0,6v12c0,2.2,1.8,4,4,4h16c2.2,0,4-1.8,4-4V6C24,3.8,22.2,2,20,2z M15.6,12.8L10.5,16 C9.9,16.5,9,16,9,15.2V8.8C9,8,9.9,7.5,10.5,8l5.1,3.2C16.3,11.5,16.3,12.5,15.6,12.8z\" id=\"video\"/>\n </g>\n</svg>";
@@ -1413,11 +1456,7 @@
classCallCheck(this, Controls);
this.art = art;
this.$map = {
top: [],
left: [],
right: []
};
this.$map = {};
this.init();
this.mount();
}
@@ -1477,9 +1516,7 @@
position: 'right',
index: 50
}));
this.art.option.controls.filter(function (item) {
return !item.disable;
}).forEach(function (item) {
this.art.option.controls.forEach(function (item) {
_this.add(item);
});
}
@@ -1488,7 +1525,7 @@
value: function add(control) {
var option = control.option;
if (!option.disable) {
if (option && !option.disable) {
id++;
var name = control.constructor.name.toLowerCase() || "control".concat(id);
var $control = document.createElement('div');
@@ -1496,8 +1533,8 @@
$control.setAttribute('data-control-index', String(option.index) || id);
option.$control = $control;
this.commonMethod(control);
this.$map[option.position].push($control);
control.apply(this.art);
(this.$map[option.position] || (this.$map[option.position] = [])).push($control);
control.apply && control.apply(this.art);
this[name] = control;
}
}
@@ -2093,7 +2130,9 @@
this.art = art;
this.add = this.add.bind(this);
this.art.option.layers.forEach(this.add);
this.art.option.layers.filter(function (item) {
return item.disable === false;
}).forEach(this.add);
this.init();
}
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../src/verification/player.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/pip.js","../../src/icons/index.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/index.js"],"sourcesContent":["function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction _construct(Parent, args, Class) {\n if (isNativeReflectConstruct()) {\n module.exports = _construct = Reflect.construct;\n } else {\n module.exports = _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n\n return _construct.apply(null, arguments);\n}\n\nmodule.exports = _construct;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\"./arrayWithoutHoles\");\n\nvar iterableToArray = require(\"./iterableToArray\");\n\nvar nonIterableSpread = require(\"./nonIterableSpread\");\n\nfunction _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();\n}\n\nmodule.exports = _toConsumableArray;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, Line truncated
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../src/verification/player.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/pip.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../src/icons/index.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/index.js"],"sourcesContent":["function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction _construct(Parent, args, Class) {\n if (isNativeReflectConstruct()) {\n module.exports = _construct = Reflect.construct;\n } else {\n module.exports = _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n\n return _construct.apply(null, arguments);\n}\n\nmodule.exports = _construct;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\"./arrayWithoutHoles\");\n\nvar iterableToArray = require(\"./iterableToArray\");\n\nvar nonIterableSpread = require(\"./nonIterableSpread\");\n\nfunction _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();\n}\n\nmodule.exports = _toConsumableArray;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, Line truncated
+5 -9
View File
@@ -14,11 +14,7 @@ let id = 0;
export default class Controls {
constructor(art) {
this.art = art;
this.$map = {
top: [],
left: [],
right: []
};
this.$map = {};
this.init();
this.mount();
}
@@ -84,14 +80,14 @@ export default class Controls {
index: 50
}));
this.art.option.controls.filter(item => !item.disable).forEach(item => {
this.art.option.controls.forEach(item => {
this.add(item);
});
}
add(control) {
const { option } = control;
if (!option.disable) {
if (option && !option.disable) {
id++;
const name = control.constructor.name.toLowerCase() || `control${id}`;
const $control = document.createElement('div');
@@ -99,8 +95,8 @@ export default class Controls {
$control.setAttribute('data-control-index', String(option.index) || id);
option.$control = $control;
this.commonMethod(control);
this.$map[option.position].push($control);
control.apply(this.art);
(this.$map[option.position] || (this.$map[option.position] = [])).push($control);
control.apply && control.apply(this.art);
this[name] = control;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ export default class Layers {
constructor(art) {
this.art = art;
this.add = this.add.bind(this);
this.art.option.layers.forEach(this.add);
this.art.option.layers.filter(item => item.disable === false).forEach(this.add);
this.init();
}
+7 -4
View File
@@ -69,11 +69,14 @@ export function deepMerge(...sources) {
}
returnValue = [...returnValue, ...source];
} else if (isObject(source)) {
for (let [key, value] of Object.entries(source)) {
if (isObject(value) && Reflect.has(returnValue, key)) {
value = deepMerge(returnValue[key], value);
for (const key in source) {
if (source.hasOwnProperty(key)) {
let value = source[key];
if (isObject(value) && key in returnValue) {
value = deepMerge(returnValue[key], value);
}
returnValue = { ...returnValue, [key]: value };
}
returnValue = { ...returnValue, [key]: value };
}
}
}
-18
View File
@@ -1,18 +0,0 @@
import { errorHandle } from '../utils';
export default function validControl(option) {
errorHandle(
typeof option.disable === 'boolean',
`'disable' option require 'boolean' type, but got '${typeof option.disable}'.`
);
errorHandle(
['top', 'left', 'right'].indexOf(option.position) > -1,
`'position' option require one of 'top、left、right', but got '${option.position}'.`
);
errorHandle(
typeof option.index === 'number',
`'index' option require 'number' type, but got '${typeof option.index}'.`
);
}
+65 -1
View File
@@ -6,10 +6,74 @@ export default function validOption(DEFAULTS, option, path = ['option']) {
const value = option[key];
const defaultType = getType(defaultValue);
const type = getType(value);
errorHandle(defaultType === type, `'${path.join('.')}.${key}' require '${defaultType}' type, but got '${type}'`);
errorHandle(
defaultType === type,
`'${path.join('.')}.${key}' require '${defaultType}' type, but got '${type}'`
);
if (type === 'object') {
validOption(defaultValue, value, path.concat(key));
}
if (path.length === 1) {
if (key === 'layers') {
value.forEach((item, index) => {
validOption(
{
name: '',
index: 0,
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'contextmenu') {
value.forEach((item, index) => {
validOption(
{
name: '',
click: new Function(),
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'highlight') {
value.forEach((item, index) => {
validOption(
{
time: 0,
text: ''
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'controls') {
value.forEach((item, index) => {
if (item.option) {
validOption(
{
disable: false,
position: '',
index: 0
},
item.option,
path.concat(`${key}[${index}]`)
);
}
});
}
}
});
}