Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
新增暗黑模式
  • Loading branch information
TheWindRises-2 authored Jul 31, 2022
1 parent 8913216 commit 79ae6d1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 93 deletions.
119 changes: 39 additions & 80 deletions coco-message.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"use strict";

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

!function (global, factory) {
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = global || self, global.cocoMessage = factory());
}(void 0, function () {
"use strict";

if (typeof window === "undefined") {
return;
}

var msgWrapper = c({
className: "coco-msg-stage"
});
Expand All @@ -36,18 +34,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
} else if (_typeof(children) == "object" && children.tagName) {
el.appendChild(children);
} else if (children) {
var _iterator = _createForOfIteratorHelper(children),
_step;

try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var child = _step.value;
el.appendChild(child);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
for (var i = 0; i < children.length; i++) {
var child = children[i];
el.appendChild(child);
}
}

Expand Down Expand Up @@ -138,31 +127,26 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
};

function initConfig(obj, type) {
var args = Object.assign({}, initArgs);

var _iterator2 = _createForOfIteratorHelper(obj),
_step2;

try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var it = _step2.value;

if (it !== undefined) {
if (typeof it == "string" || _typeof(it) == "object") {
args.msg = it;
} else if (typeof it == "boolean") {
args.showClose = it;
} else if (typeof it == "function") {
args.onClose = it;
} else if (typeof it == "number") {
args.duration = it;
}
var args = {};

for (var key in initArgs) {
args[key] = initArgs[key];
}

for (var i = 0; i < obj.length; i++) {
var it = obj[i];

if (it !== undefined) {
if (typeof it == "string" || _typeof(it) == "object") {
args.msg = it;
} else if (typeof it == "boolean") {
args.showClose = it;
} else if (typeof it == "function") {
args.onClose = it;
} else if (typeof it == "number") {
args.duration = it;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}

args.type = type;
Expand All @@ -179,7 +163,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
var iconObj = getIconObj();

if (type == "loading") {
msg = msg === "" ? "正在加载" : msg;
msg = msg === "" ? "正在加载,请稍后" : msg;
closable = showClose;
duration = 0;
}
Expand All @@ -202,9 +186,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
}, getMsgRight(closable))])]);
var anm = el.querySelector(".coco-msg__circle");

if (anm) {
if (anm && type !== "loading") {
css(anm, {
animation: "coco-msg_".concat(type, " ").concat(duration, "ms linear")
animation: "coco-msg__circle ".concat(duration, "ms linear")
});

if ("onanimationend" in window) {
Expand Down Expand Up @@ -263,21 +247,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
if (!el) return;
var has = false;

var _iterator3 = _createForOfIteratorHelper(msgWrapper.children),
_step3;

try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var it = _step3.value;

if (it === el) {
has = true;
}
for (var i = 0; i < msgWrapper.children.length; i++) {
if (msgWrapper.children[i] === el) {
has = true;
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}

has && removeChild(el);
Expand All @@ -304,22 +277,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
}

function _destroyAll() {
var _iterator4 = _createForOfIteratorHelper(msgWrapper.children),
_step4;

try {
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
var it = _step4.value;
closeMsg(it);
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
for (var i = 0; i < msgWrapper.children.length; i++) {
var element = msgWrapper.children[i];
closeMsg(element);
}
}

window.addEventListener('DOMContentLoaded', function () {
window.addEventListener("DOMContentLoaded", function () {
insertCssInHead();
});

Expand All @@ -329,16 +293,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
if (doc && doc.head) {
var head = doc.head;

var _css = doc.createElement('style');
var _css = doc.createElement("style");

var cssStr = "\n[class|=coco],[class|=coco]::after,[class|=coco]::before{box-sizing:border-box;outline:0}.coco-msg-progress{width:13px;height:13px}.coco-msg__circle{stroke-width:2;stroke-linecap:square;fill:none;transform:rotate(-90deg);transform-origin:center}.coco-msg-stage:hover .coco-msg__circle{-webkit-animation-play-state:paused!important;animation-play-state:paused!important}.coco-msg__background{stroke-width:2;fill:none}.coco-msg-stage{position:fixed;top:20px;left:50%;width:auto;transform:translate(-50%,0);z-index:3000}.coco-msg-wrapper{position:relative;left:50%;transform:translate(-50%,0);transform:translate3d(-50%,0,0);transition:height .3s ease,padding .3s ease;padding:6px 0;will-change:transform,opacity}.coco-msg{padding:13px 14px 13px 18px;border-radius:2px;position:relative;left:50%;transform:translate(-50%,0);transform:translate3d(-50%,0,0);display:flex;align-items:center;color:#5b6161;background-color:#fff;box-shadow:1px 4px 16px rgba(5,32,44,.08)}.coco-msg-content,.coco-msg-icon,.coco-msg-wait{display:inline-block}.coco-msg-icon{position:relative;width:13px;height:13px;border-radius:100%;display:flex;justify-content:center;align-items:center}.coco-msg-icon svg{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:11px;height:11px}.coco-msg-wait{width:20px;height:20px;position:relative;fill:#4eb127}.coco-msg-wait svg{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.coco-msg-close{width:14px;height:14px}.coco-msg-content{margin:0 10px;min-width:150px;text-align:left;font-size:14px;font-weight:500;font-family:-apple-system,Microsoft Yahei,sans-serif}.coco-msg.info .coco-msg-icon{background-color:#428ae9}.coco-msg.success .coco-msg-icon{background-color:#4ebb23}.coco-msg.warning .coco-msg-icon{background-color:#f1b306}.coco-msg.error .coco-msg-icon{background-color:#f34b51}.coco-msg_loading{flex-shrink:0;width:20px;height:20px;position:relative}.coco-msg-circular{-webkit-animation:coco-msg-rotate 2s linear infinite both;animation:coco-msg-rotate 2s linear infinite both;transform-origin:center center;height:18px!important;width:18px!important}.coco-msg-path{stroke-dasharray:1,200;stroke-dashoffset:0;stroke:#428ae9;-webkit-animation:coco-msg-dash 1.5s ease-in-out infinite;animation:coco-msg-dash 1.5s ease-in-out infinite;stroke-linecap:round}@-webkit-keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@-webkit-keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}@keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}.coco-msg .coco-msg-wait{fill:#969696}.coco-msg-pointer{cursor:pointer}@-webkit-keyframes coco-msg_info{0%{stroke:#428ae9}to{stroke:#428ae9;stroke-dasharray:0 100}}@keyframes coco-msg_info{0%{stroke:#428ae9}to{stroke:#428ae9;stroke-dasharray:0 100}}@-webkit-keyframes coco-msg_success{0%{stroke:#4eb127}to{stroke:#4eb127;stroke-dasharray:0 100}}@keyframes coco-msg_success{0%{stroke:#4eb127}to{stroke:#4eb127;stroke-dasharray:0 100}}@-webkit-keyframes coco-msg_warning{0%{stroke:#fcbc0b}to{stroke:#fcbc0b;stroke-dasharray:0 100}}@keyframes coco-msg_warning{0%{stroke:#fcbc0b}to{stroke:#fcbc0b;stroke-dasharray:0 100}}@-webkit-keyframes coco-msg_error{0%{stroke:#eb262d}to{stroke:#eb262d;stroke-dasharray:0 100}}@keyframes coco-msg_error{0%{stroke:#eb262d}to{stroke:#eb262d;stroke-dasharray:0 100}}.coco-msg-fade-in{-webkit-animation:coco-msg-fade .2s ease-out both;animation:coco-msg-fade .2s ease-out both}.coco-msg-fade-out{animation:coco-msg-fade .3s linear reverse both}@-webkit-keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,0);transform:translate3d(-50%,-80%,0)}to{opacity:1;transform:translate(-50%,0);transform:translate3d(-50%,0,0)}}@keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,0);transform:translate3d(-50%,-80%,0)}to{opacity:1;transform:translate(-50%,0);transform:translate3d(-50%,0,0)}}\n ";
var cssStr = "[class|=coco],[class|=coco]::after,[class|=coco]::before{box-sizing:border-box;outline:0}.coco-msg-progress{width:14px;height:14px}.coco-msg__circle{stroke-width:2;stroke-linecap:square;fill:none;transform:rotate(-90deg);transform-origin:center}.coco-msg-stage:hover .coco-msg__circle{-webkit-animation-play-state:paused!important;animation-play-state:paused!important}.coco-msg__background{stroke-width:2;fill:none}.coco-msg-stage{position:fixed;top:20px;left:50%;width:auto;transform:translate(-50%,0);z-index:3000;padding-top:constant(safe-area-inset-top);padding-top:env(safe-area-inset-top)}.coco-msg-wrapper{position:relative;left:50%;transform:translate(-50%,0);transition:height .35s ease-out,padding .35s ease-out;padding:8px 0;will-change:transform,opacity}.coco-msg-content,.coco-msg-icon,.coco-msg-wait{display:inline-block}.coco-msg-icon{position:relative;width:16px;height:16px;border-radius:100%;display:flex;justify-content:center;align-items:center;opacity:.87654321}.coco-msg-icon svg{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:12px;height:12px;box-sizing:content-box}.coco-msg-wait{width:20px;height:20px;position:relative}.coco-msg-wait svg{position:absolute;top:50%;right:-4px;transform:translate(0,-50%);fill:currentColor}.coco-msg-close{width:14px;height:14px}.coco-msg-content{margin:0 10px;min-width:180px;text-align:left;font-size:14px;font-weight:400}.coco-msg.error .coco-msg-icon,.coco-msg.info .coco-msg-icon,.coco-msg.success .coco-msg-icon,.coco-msg.warning .coco-msg-icon{background-color:currentColor}.coco-msg{padding:10px 20px;border-radius:10px;border-radius:2px;position:relative;left:50%;transform:translate(-50%,0);display:flex;align-items:center}.coco-msg.info,.coco-msg.loading{background-color:#f7f8fa;color:#4e5969;box-shadow:0 0 0 1px rgba(192,192,192,.2)}.coco-msg.success{background-color:#e8ffea;color:#129a37;box-shadow:0 0 0 1px rgba(213,235,215,.2)}.coco-msg.warning{background-color:#fffce8;color:#cc9213;box-shadow:0 0 0 1px rgba(214,201,152,.2)}.coco-msg.error{color:#f53f3f;background-color:#fff0ec;box-shadow:0 0 0 1px rgba(238,189,189,.2)}.coco-msg.info .coco-msg-icon path,.coco-msg.loading .coco-msg-icon path{fill:#f7f8fa}.coco-msg.success .coco-msg-icon path{fill:#e8ffea}.coco-msg.warning .coco-msg-icon path{fill:#fffce8}.coco-msg.error .coco-msg-icon path{fill:#ffece8}.dark .coco-msg.info,.dark .coco-msg.loading{background-color:#2e2e30;color:#dfdfdf}.dark .coco-msg.success{background-color:#004d1c;color:#50d266}.dark .coco-msg.warning{background-color:#4d3800;color:#f7c034}.dark .coco-msg.error{background-color:#4d000a;color:#f98d86}.dark .coco-msg{box-shadow:0 0 1px 0 rgba(55,55,55,.3)!important}.dark .coco-msg.info .coco-msg-icon path,.dark .coco-msg.loading .coco-msg-icon path{fill:#2e2e30}.dark .coco-msg.success .coco-msg-icon path{fill:#004d1c}.dark .coco-msg.warning .coco-msg-icon path{fill:#4d3800}.dark .coco-msg.error .coco-msg-icon path{fill:#4d000a}.coco-msg.loading .coco-msg-icon{background-color:transparent}@keyframes coco-msg__circle{0%{stroke:#b3b9b9;stroke:currentColor}to{stroke:#b3b9b9;stroke:currentColor;stroke-dasharray:0 100}}.coco-msg_loading{flex-shrink:0;width:20px;height:20px;position:relative}.coco-msg-circular{-webkit-animation:coco-msg-rotate 2s linear infinite both;animation:coco-msg-rotate 2s linear infinite both;transform-origin:center center;height:18px!important;width:18px!important}.coco-msg-path{stroke-dasharray:1,200;stroke-dashoffset:0;stroke:currentColor;-webkit-animation:coco-msg-dash 1.5s ease-in-out infinite;animation:coco-msg-dash 1.5s ease-in-out infinite;stroke-linecap:round}@-webkit-keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@keyframes coco-msg-rotate{100%{transform:translate(-50%,-50%) rotate(360deg)}}@-webkit-keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}@keyframes coco-msg-dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}.coco-msg-pointer{cursor:pointer}.coco-msg-fade-in{-webkit-animation:coco-msg-fade .22s ease-out both;animation:coco-msg-fade .22s ease-out both}.coco-msg-fade-out{animation:coco-msg-fade .22s linear reverse both}@-webkit-keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,-80%)}to{opacity:1;transform:translate(-50%,0)}}@keyframes coco-msg-fade{0%{opacity:0;transform:translate(-50%,-80%)}to{opacity:1;transform:translate(-50%,0)}}";
_css.innerHTML = cssStr;

if (head.children.length) {
head.insertBefore(_css, head.children[0]);
} else {
head.appendChild(_css);
}
head.appendChild(_css);
}
}

Expand Down
Loading

0 comments on commit 79ae6d1

Please sign in to comment.