浏览代码

Add files via upload

Daniele Bonini (皮夕): WebDev and DevOps by lots of Simplicity bits 3 年之前
父节点
当前提交
380840e0db
共有 9 个文件被更改,包括 1078 次插入0 次删除
  1. 5 0
      css/style.css
  2. 145 0
      drag1.html
  3. 146 0
      drag2.html
  4. 77 0
      index.html
  5. 138 0
      js/dropjs.js
  6. 1 0
      js/jquery-3.1.0.min.js
  7. 298 0
      js/serialize-javascript.js
  8. 268 0
      js/serialize.js.original_code.js
  9. 二进制
      res/obj.png

+ 5 - 0
css/style.css

@@ -0,0 +1,5 @@
+body {
+  background: #000000;
+  color: #FFFFFF;
+  font-weight:900;
+}

+ 145 - 0
drag1.html

@@ -0,0 +1,145 @@
+<!--
+
+  Copyright (c) 2016, 2024, 5 Mode's contributors
+  All rights reserved.
+  
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+      * Redistributions of source code must retain the above copyright
+        notice, this list of conditions and the following disclaimer.
+      * Redistributions in binary form must reproduce the above copyright
+        notice, this list of conditions and the following disclaimer in the
+        documentation and/or other materials provided with the distribution.
+      * Neither 5 Mode nor the names of its contributors 
+        may be used to endorse or promote products derived from this software 
+        without specific prior written permission.
+  
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ 
+-->
+
+<!DOCTYPE html>
+<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+
+  <meta name="viewport" content="width=device-width, initial-scale=1"/>
+  
+  <title>Objects do: an iconic js library!</title>
+
+  <link rel="shortcut icon" href="./favicon.ico" />
+
+  <meta name="description" content="Welcome to Objects do! Enjoy the library or contact us.."/>
+  <meta name="keywords" content="5 Mode,object"/>
+  <meta name="robots" content="index,follow"/>
+  <meta name="author" content="5 Mode"/>
+  
+  <script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
+  
+  <script src="./js/serialize-javascript.js" type="text/javascript"></script>
+  <script src="./js/dropjs.js" type="text/javascript"></script>
+    
+  <link href="./css/style.css" type="text/css" rel="stylesheet">  
+  
+  <script type="text/javascript">
+
+    function myObj() {
+      
+      const s = "Hello World!";
+      
+      // Properties
+      this.msg = s;
+      this.start = mystart;
+      
+      // Methods
+      function mystart() {
+	      alert(this.msg);
+      }
+      
+    }  
+
+    function getObj(objName) {
+      //alert("param"+objName);
+      switch (objName) {
+       case "myObj": 
+        thiss = new myObj();
+        return thiss; 
+      }
+    }
+
+  </script>    
+</head>
+
+<body style="margin-top:20px; padding-top:3%;">
+
+  <div style="width:500px;margin:auto;">
+
+<pre style="width:300px; margin:auto; background: black; color: #FFFFFF; text-align:left">
+  
+    function myObj() {
+      
+      const s = "Hello World!";
+      
+      // Properties
+      this.msg = s;
+      this.start = mystart;
+      
+      // Methods
+      function mystart() {
+        alert(this.msg);
+      }
+      
+    }    
+    
+</pre>  
+
+    <div style="float:left; text-align:center;" ondragover="onDragOver(event);" ondrop="onDrop(event);">
+      
+      <img src="./res/obj.png" style="width:300px" draggable="true" ondragstart="onDragStart(event);" onmouseover="onMouseOver();"><br><br>
+      
+      OBJECT: <input type="text" id="objName" name="objName" value="myObj">
+      
+    </div>
+
+    <div style="float:left; width: 100px; margin-left:60px;">
+      
+      <br>
+      
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" ondragover="onDragOver(event);" ondrop="onDropJSON(event);"> 
+      &nbsp;JSON&nbsp; 
+      </div>
+      
+      <br><br>
+      
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" ondragover="onDragOver(event);" ondrop="onDropJS(event);">   
+      &nbsp;Javascript&nbsp; 
+      </div>
+
+      <br><br>
+
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" ondragover="onDragOver(event);" ondrop="onDropINFO(event);"> 
+      &nbsp;Info&nbsp; 
+      </div>
+
+      <br><br>
+
+      <div style="width:fit-content; height:40px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" ondragover="onDragOver(event);" ondrop="onDropMoon(event);"> 
+      &nbsp;Inject<br>Hello Moon&nbsp; 
+      </div>
+
+      
+    </div>  
+
+  </div>
+
+
+</body>
+</html>

+ 146 - 0
drag2.html

@@ -0,0 +1,146 @@
+<!--
+
+  Copyright (c) 2016, 2024, 5 Mode's contributors
+  All rights reserved.
+  
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+      * Redistributions of source code must retain the above copyright
+        notice, this list of conditions and the following disclaimer.
+      * Redistributions in binary form must reproduce the above copyright
+        notice, this list of conditions and the following disclaimer in the
+        documentation and/or other materials provided with the distribution.
+      * Neither 5 Mode nor the names of its contributors 
+        may be used to endorse or promote products derived from this software 
+        without specific prior written permission.
+  
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ 
+-->
+
+
+<!DOCTYPE html>
+<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+
+  <meta name="viewport" content="width=device-width, initial-scale=1"/>
+  
+  <title>Objects do: an iconic js library!</title>
+
+  <link rel="shortcut icon" href="./favicon.ico" />
+
+  <meta name="description" content="Welcome to Objects do! Enjoy the library or contact us.."/>
+  <meta name="keywords" content="5 Mode,object"/>
+  <meta name="robots" content="index,follow"/>
+  <meta name="author" content="5 Mode"/>
+  
+  <script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
+  
+  <script src="./js/serialize-javascript.js" type="text/javascript"></script>
+  <script src="./js/dropjs.js" type="text/javascript"></script>
+    
+  <link href="./css/style.css" type="text/css" rel="stylesheet">  
+  
+  <script type="text/javascript">
+
+    function myObj() {
+      
+      const s = "Hello World!";
+      
+      // Properties
+      this.msg = s;
+      this.start = mystart;
+      
+      // Methods
+      function mystart() {
+	      alert(this.msg);
+      }
+      
+    }  
+
+    function getObj(objName) {
+      //alert("param"+objName);
+      switch (objName) {
+       case "myObj": 
+        thiss = new myObj();
+        return thiss; 
+      }
+    }
+
+  </script>    
+</head>
+
+<body style="margin-top:20px; padding-top:3%;">
+
+  <div style="width:500px;margin:auto;">
+
+<pre style="width:300px; margin:auto; background: black; color: #FFFFFF; text-align:left">
+  
+    function myObj() {
+      
+      const s = "Hello World!";
+      
+      // Properties
+      this.msg = s;
+      this.start = mystart;
+      
+      // Methods
+      function mystart() {
+        alert(this.msg);
+      }
+      
+    }    
+    
+</pre>  
+
+    <div style="float:left; text-align:center;" ondragover="onDragOver(event);" ondrop="onDrop(event);">
+      
+      <img src="./res/obj.png" style="width:300px" draggable="true" ondragstart="onDragStart(event);" onmouseover="onMouseOver();"><br><br>
+      
+      OBJECT: <input type="text" id="objName" name="objName" value="myObj">
+      
+    </div>
+
+    <div style="float:left; width: 100px; margin-left:60px;">
+      
+      <br>
+      
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" draggable="false" ondragover="onDragOver(event);" ondrop="onDropJSON(event);"> 
+      &nbsp;JSON&nbsp; 
+      </div>
+      
+      <br><br>
+      
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" draggable="false" ondragover="onDragOver(event);" ondrop="onDropJS(event);">   
+      &nbsp;Javascript&nbsp; 
+      </div>
+
+      <br><br>
+
+      <div style="width:fit-content; height:30px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" draggable="false" ondragover="onDragOver(event);" ondrop="onDropINFO(event);"> 
+      &nbsp;Info&nbsp; 
+      </div>
+
+      <br><br>
+
+      <div style="width:fit-content; height:40px; background: orange; border: 2px solid darkorange; font-size: 16px; font-weight:900; text-align: center; padding-top: 8px;" draggable="false" ondragover="onDragOver(event);" ondrop="onDropMoon(event);"> 
+      &nbsp;Inject<br>Hello Moon&nbsp; 
+      </div>
+
+      
+    </div>  
+
+  </div>
+
+
+</body>
+</html>

+ 77 - 0
index.html

@@ -0,0 +1,77 @@
+
+<!--
+
+  Copyright (c) 2016, 2024, 5 Mode's contributors
+  All rights reserved.
+  
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+      * Redistributions of source code must retain the above copyright
+        notice, this list of conditions and the following disclaimer.
+      * Redistributions in binary form must reproduce the above copyright
+        notice, this list of conditions and the following disclaimer in the
+        documentation and/or other materials provided with the distribution.
+      * Neither 5 Mode nor the names of its contributors 
+        may be used to endorse or promote products derived from this software 
+        without specific prior written permission.
+  
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ 
+-->
+
+<!DOCTYPE html>
+<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+
+  <meta name="viewport" content="width=device-width, initial-scale=1"/>
+  
+  <title>Dropjs: the iconic js library!</title>
+
+  <link rel="shortcut icon" href="./favicon.ico" />
+
+  <meta name="description" content="Welcome to Dropjs! Enjoy the library or contact us.."/>
+  <meta name="keywords" content="5 Mode,object"/>
+  <meta name="robots" content="index,follow"/>
+  <meta name="author" content="5 Mode"/>
+  
+  <script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
+    
+  <link href="./css/style.css" type="text/css" rel="stylesheet"> 
+
+  <script>
+    function openPages() {
+      window.open("drag1.html","_blank");
+      window.open("drag2.html","_blank"); 
+    }  
+  </script>  
+
+</head>  
+
+<body style="background:#FFFFFF; margin-top:20px; padding-top:5%; font-size:25px;">
+
+<div style="width:300px;margin:auto;">
+
+Dragjs enhance the web possibilities given<br>
+by the the JSON serialization and OOP through<br>
+iconic rappresentation.<br><br>
+
+Open the Dropjs page<br>two times and try the<br>
+drag and drop feature from<br> one to the others:<br><br>
+
+<input type="button" id="butOpenPages" onclick="openPages()" value="Open the required pages">
+
+</div>
+
+</body>
+</html>
+
+  

+ 138 - 0
js/dropjs.js

@@ -0,0 +1,138 @@
+/**
+ *
+ *  Copyright (c) 2016, 2024, 5 Mode's contributors
+ *  All rights reserved.
+ *  
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *      * Redistributions of source code must retain the above copyright
+ *        notice, this list of conditions and the following disclaimer.
+ *      * Redistributions in binary form must reproduce the above copyright
+ *        notice, this list of conditions and the following disclaimer in the
+ *        documentation and/or other materials provided with the distribution.
+ *      * Neither 5 Mode nor the names of its contributors 
+ *        may be used to endorse or promote products derived from this software 
+ *        without specific prior written permission.
+ *  
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ **/
+
+function onDragStart(e) {
+  //e.preventDefault();
+  objName = document.getElementById("objName").value;
+  //alert(objName);
+  jsonData = serialize( getObj(objName) );
+  //alert(jsonData);
+  e.dataTransfer.setData('text/plain', jsonData);
+  document.body.style.cursor="move";
+}
+  
+function onDragOver(e) {
+  e.preventDefault();
+  const id = e.dataTransfer.getData('text/plain');
+  document.body.style.cursor="pointer";     
+}  
+
+function onDragOverOff(e) {
+  e.preventDefault();
+  document.body.style.cursor="not-allowed";     
+}  
+  
+function onDrop(e) {
+  e.preventDefault();
+  mys=e.dataTransfer.getData('text/plain');
+  //alert(mys);
+  var newObj = deserialize(mys);
+  newObj.start();
+  document.body.style.cursor="normal";
+}
+
+function onDropMoon(e) {
+  e.preventDefault();
+  mys=e.dataTransfer.getData('text/plain');
+  mys=mys.substr(0,mys.length-1) + ",\"startMoon\":function mystartMoon() { alert(\"Hello Moon!\"); }}";
+  //alert(mys);
+  var newObj = deserialize(mys);
+  newObj.startMoon();
+  document.body.style.cursor="normal";
+}
+
+
+function onDropJSON(e) {
+  e.preventDefault();
+  mys=e.dataTransfer.getData('text/plain');
+  alert(mys);
+  document.body.style.cursor="normal";
+}
+
+function countMatches(matches) {
+  i=0;
+  for (const match of matches) { 
+    i++;
+  }
+  return i;
+}  
+
+function onDropINFO(e) {
+  const regexp1 = /\:function/g;
+  const regexp2 = /\:/g;
+  e.preventDefault();
+  mys=e.dataTransfer.getData('text/plain');
+  res1a = mys.matchAll(regexp1);
+  res2a = mys.matchAll(regexp2);
+  totFunctions = countMatches(res1a);
+  totEntities = countMatches(res2a);
+  res = "";
+  res += "\ntotal properties: " + (totEntities - totFunctions);
+  res += "\ntotal functions: " + totFunctions;
+  alert(res);
+  document.body.style.cursor="normal";
+}
+
+function onDropJS(e) {
+  const regexp1 = /\"(.+)\"\:\"(.+)\"[,|}]/g;
+  const regexp2 = /\"(.+)\"\:(function.+{.+})[,|}]/g;
+  e.preventDefault();
+  mys=e.dataTransfer.getData('text/plain');
+  mys=mys.replaceAll("\n","");
+  mys=mys.replaceAll(",",",\n");
+  mys=mys.replaceAll("  "," ");
+  res1a = mys.matchAll(regexp1);
+  res2a = mys.matchAll(regexp2);
+  res = "OBJECT\t[";
+  i=0;
+  for (const match of res1a) { 
+    res += "\n\tvar " + match[1] + " = '" + match[2] + "'";
+    i++;
+  }
+  i=0;
+  for (const match of res2a) { 
+    res += "\n\tvar " + match[1] + " = " + match[2] + ";";
+    i++;
+  }
+  res += "\n\];";
+  alert(res);
+  document.body.style.cursor="normal";
+}
+
+
+function onDropOff(e) {
+  e.preventDefault();
+  document.body.style.cursor="not-allowed";
+  e.stopPropagation();
+}
+
+function onMouseOver() {
+  document.body.style.cursor="pointer";     
+}
+      

文件差异内容过多而无法显示
+ 1 - 0
js/jquery-3.1.0.min.js


+ 298 - 0
js/serialize-javascript.js

@@ -0,0 +1,298 @@
+/*
+Copyright (c) 2014, Yahoo! Inc. All rights reserved.
+Copyright (c) 2021, 5 Mode, requirements, installation and code changes.
+Copyrights licensed under the New BSD License.
+See the accompanying LICENSE file for terms.
+ver. 6.0.0
+*/
+
+'use strict';
+
+// upd - 5 Mode
+//var randomBytes = require('randombytes');
+// ---
+
+// Generate an internal UID to make the regexp pattern harder to guess.
+var UID_LENGTH          = 16;
+var UID                 = generateUID();
+var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
+
+var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
+var IS_PURE_FUNCTION = /function.*?\(/;
+var IS_ARROW_FUNCTION = /.*?=>.*?/;
+var UNSAFE_CHARS_REGEXP   = /[<>\/\u2028\u2029]/g;
+
+var RESERVED_SYMBOLS = ['*', 'async'];
+
+// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
+// Unicode char counterparts which are safe to use in JavaScript strings.
+var ESCAPED_CHARS = {
+    '<'     : '\\u003C',
+    '>'     : '\\u003E',
+    '/'     : '\\u002F',
+    '\u2028': '\\u2028',
+    '\u2029': '\\u2029'
+};
+
+function escapeUnsafeChars(unsafeChar) {
+    return ESCAPED_CHARS[unsafeChar];
+}
+
+// upd - 5 Mode
+function rnd(min, max) {
+  var ress = "";
+  var resa = [];
+  min = Math.ceil(min);
+  max = Math.floor(max);
+  //return Math.floor(Math.random() * (max - min +1)) + min;
+  ress = (Math.floor(Math.random() * (max - min +1)) + min) + "";
+  for (var i=0;i<UID_LENGTH;i++) {
+    resa[i] = ress.substr(i,1);
+  }  
+  return resa;
+}
+// ---
+
+function generateUID() {
+    // upd - 5 Mode
+    //var bytes = randomBytes(UID_LENGTH);
+    var bytes = rnd(1000000000000000, 9999999999999999);
+    // ---
+    var result = '';
+    for(var i=0; i<UID_LENGTH; ++i) {
+        result += bytes[i].toString(16);
+    }
+    return result;
+}
+
+function deleteFunctions(obj){
+    var functionKeys = [];
+    for (var key in obj) {
+        if (typeof obj[key] === "function") {
+            functionKeys.push(key);
+        }
+    }
+    for (var i = 0; i < functionKeys.length; i++) {
+        delete obj[functionKeys[i]];
+    }
+}
+
+// upd - 5 Mode
+//module.exports = function serialize(obj, options) {
+// ---  
+function serialize(obj, options) {
+
+    options || (options = {});
+
+    // Backwards-compatibility for `space` as the second argument.
+    if (typeof options === 'number' || typeof options === 'string') {
+        options = {space: options};
+    }
+
+    var functions = [];
+    var regexps   = [];
+    var dates     = [];
+    var maps      = [];
+    var sets      = [];
+    var arrays    = [];
+    var undefs    = [];
+    var infinities= [];
+    var bigInts = [];
+    var urls = [];
+
+    // Returns placeholders for functions and regexps (identified by index)
+    // which are later replaced by their string representation.
+    function replacer(key, value) {
+
+        // For nested function
+        if(options.ignoreFunction){
+            deleteFunctions(value);
+        }
+
+        if (!value && value !== undefined) {
+            return value;
+        }
+
+        // If the value is an object w/ a toJSON method, toJSON is called before
+        // the replacer runs, so we use this[key] to get the non-toJSONed value.
+        var origValue = this[key];
+        var type = typeof origValue;
+
+        if (type === 'object') {
+            if(origValue instanceof RegExp) {
+                return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Date) {
+                return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Map) {
+                return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Set) {
+                return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Array) {
+                var isSparse = origValue.filter(function(){return true}).length !== origValue.length;
+                if (isSparse) {
+                    return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
+                }
+            }
+
+            if(origValue instanceof URL) {
+                return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
+            }
+        }
+
+        if (type === 'function') {
+            return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'undefined') {
+            return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
+            return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'bigint') {
+            return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
+        }
+
+        return value;
+    }
+
+    function serializeFunc(fn) {
+      var serializedFn = fn.toString();
+      if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {
+          throw new TypeError('Serializing native function: ' + fn.name);
+      }
+
+      // pure functions, example: {key: function() {}}
+      if(IS_PURE_FUNCTION.test(serializedFn)) {
+          return serializedFn;
+      }
+
+      // arrow functions, example: arg1 => arg1+5
+      if(IS_ARROW_FUNCTION.test(serializedFn)) {
+          return serializedFn;
+      }
+
+      var argsStartsAt = serializedFn.indexOf('(');
+      var def = serializedFn.substr(0, argsStartsAt)
+        .trim()
+        .split(' ')
+        .filter(function(val) { return val.length > 0 });
+
+      var nonReservedSymbols = def.filter(function(val) {
+        return RESERVED_SYMBOLS.indexOf(val) === -1
+      });
+
+      // enhanced literal objects, example: {key() {}}
+      if(nonReservedSymbols.length > 0) {
+          return (def.indexOf('async') > -1 ? 'async ' : '') + 'function'
+            + (def.join('').indexOf('*') > -1 ? '*' : '')
+            + serializedFn.substr(argsStartsAt);
+      }
+
+      // arrow functions
+      return serializedFn;
+    }
+
+    // Check if the parameter is function
+    if (options.ignoreFunction && typeof obj === "function") {
+        obj = undefined;
+    }
+    // Protects against `JSON.stringify()` returning `undefined`, by serializing
+    // to the literal string: "undefined".
+    if (obj === undefined) {
+        return String(obj);
+    }
+
+    var str;
+
+    // Creates a JSON string representation of the value.
+    // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
+    if (options.isJSON && !options.space) {
+        str = JSON.stringify(obj);
+    } else {
+        str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
+    }
+
+    // Protects against `JSON.stringify()` returning `undefined`, by serializing
+    // to the literal string: "undefined".
+    if (typeof str !== 'string') {
+        return String(str);
+    }
+
+    // Replace unsafe HTML and invalid JavaScript line terminator chars with
+    // their safe Unicode char counterpart. This _must_ happen before the
+    // regexps and functions are serialized and added back to the string.
+    if (options.unsafe !== true) {
+        str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
+    }
+
+    if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) {
+        return str;
+    }
+
+    // Replaces all occurrences of function, regexp, date, map and set placeholders in the
+    // JSON string with their string representations. If the original value can
+    // not be found, then `undefined` is used.
+    return str.replace(PLACE_HOLDER_REGEXP, function (match, backSlash, type, valueIndex) {
+        // The placeholder may not be preceded by a backslash. This is to prevent
+        // replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
+        // invalid JS.
+        if (backSlash) {
+            return match;
+        }
+
+        if (type === 'D') {
+            return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
+        }
+
+        if (type === 'R') {
+            return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
+        }
+
+        if (type === 'M') {
+            return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
+        }
+
+        if (type === 'S') {
+            return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
+        }
+
+        if (type === 'A') {
+            return "Array.prototype.slice.call(" + serialize(Object.assign({ length: arrays[valueIndex].length }, arrays[valueIndex]), options) + ")";
+        }
+
+        if (type === 'U') {
+            return 'undefined'
+        }
+
+        if (type === 'I') {
+            return infinities[valueIndex];
+        }
+
+        if (type === 'B') {
+            return "BigInt(\"" + bigInts[valueIndex] + "\")";
+        }
+
+        if (type === 'L') {
+            return "new URL(\"" + urls[valueIndex].toString() + "\")"; 
+        }
+
+        var fn = functions[valueIndex];
+
+        return serializeFunc(fn);
+    });
+}
+
+function deserialize(serializedJavascript){
+  return eval('(' + serializedJavascript + ')');
+}

+ 268 - 0
js/serialize.js.original_code.js

@@ -0,0 +1,268 @@
+/*
+Copyright (c) 2014, Yahoo! Inc. All rights reserved.
+Copyrights licensed under the New BSD License.
+See the accompanying LICENSE file for terms.
+*/
+
+'use strict';
+
+var randomBytes = require('randombytes');
+
+// Generate an internal UID to make the regexp pattern harder to guess.
+var UID_LENGTH          = 16;
+var UID                 = generateUID();
+var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
+
+var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
+var IS_PURE_FUNCTION = /function.*?\(/;
+var IS_ARROW_FUNCTION = /.*?=>.*?/;
+var UNSAFE_CHARS_REGEXP   = /[<>\/\u2028\u2029]/g;
+
+var RESERVED_SYMBOLS = ['*', 'async'];
+
+// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
+// Unicode char counterparts which are safe to use in JavaScript strings.
+var ESCAPED_CHARS = {
+    '<'     : '\\u003C',
+    '>'     : '\\u003E',
+    '/'     : '\\u002F',
+    '\u2028': '\\u2028',
+    '\u2029': '\\u2029'
+};
+
+function escapeUnsafeChars(unsafeChar) {
+    return ESCAPED_CHARS[unsafeChar];
+}
+
+function generateUID() {
+    var bytes = randomBytes(UID_LENGTH);
+    var result = '';
+    for(var i=0; i<UID_LENGTH; ++i) {
+        result += bytes[i].toString(16);
+    }
+    return result;
+}
+
+function deleteFunctions(obj){
+    var functionKeys = [];
+    for (var key in obj) {
+        if (typeof obj[key] === "function") {
+            functionKeys.push(key);
+        }
+    }
+    for (var i = 0; i < functionKeys.length; i++) {
+        delete obj[functionKeys[i]];
+    }
+}
+
+module.exports = function serialize(obj, options) {
+    options || (options = {});
+
+    // Backwards-compatibility for `space` as the second argument.
+    if (typeof options === 'number' || typeof options === 'string') {
+        options = {space: options};
+    }
+
+    var functions = [];
+    var regexps   = [];
+    var dates     = [];
+    var maps      = [];
+    var sets      = [];
+    var arrays    = [];
+    var undefs    = [];
+    var infinities= [];
+    var bigInts = [];
+    var urls = [];
+
+    // Returns placeholders for functions and regexps (identified by index)
+    // which are later replaced by their string representation.
+    function replacer(key, value) {
+
+        // For nested function
+        if(options.ignoreFunction){
+            deleteFunctions(value);
+        }
+
+        if (!value && value !== undefined) {
+            return value;
+        }
+
+        // If the value is an object w/ a toJSON method, toJSON is called before
+        // the replacer runs, so we use this[key] to get the non-toJSONed value.
+        var origValue = this[key];
+        var type = typeof origValue;
+
+        if (type === 'object') {
+            if(origValue instanceof RegExp) {
+                return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Date) {
+                return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Map) {
+                return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Set) {
+                return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
+            }
+
+            if(origValue instanceof Array) {
+                var isSparse = origValue.filter(function(){return true}).length !== origValue.length;
+                if (isSparse) {
+                    return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
+                }
+            }
+
+            if(origValue instanceof URL) {
+                return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
+            }
+        }
+
+        if (type === 'function') {
+            return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'undefined') {
+            return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
+            return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
+        }
+
+        if (type === 'bigint') {
+            return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
+        }
+
+        return value;
+    }
+
+    function serializeFunc(fn) {
+      var serializedFn = fn.toString();
+      if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {
+          throw new TypeError('Serializing native function: ' + fn.name);
+      }
+
+      // pure functions, example: {key: function() {}}
+      if(IS_PURE_FUNCTION.test(serializedFn)) {
+          return serializedFn;
+      }
+
+      // arrow functions, example: arg1 => arg1+5
+      if(IS_ARROW_FUNCTION.test(serializedFn)) {
+          return serializedFn;
+      }
+
+      var argsStartsAt = serializedFn.indexOf('(');
+      var def = serializedFn.substr(0, argsStartsAt)
+        .trim()
+        .split(' ')
+        .filter(function(val) { return val.length > 0 });
+
+      var nonReservedSymbols = def.filter(function(val) {
+        return RESERVED_SYMBOLS.indexOf(val) === -1
+      });
+
+      // enhanced literal objects, example: {key() {}}
+      if(nonReservedSymbols.length > 0) {
+          return (def.indexOf('async') > -1 ? 'async ' : '') + 'function'
+            + (def.join('').indexOf('*') > -1 ? '*' : '')
+            + serializedFn.substr(argsStartsAt);
+      }
+
+      // arrow functions
+      return serializedFn;
+    }
+
+    // Check if the parameter is function
+    if (options.ignoreFunction && typeof obj === "function") {
+        obj = undefined;
+    }
+    // Protects against `JSON.stringify()` returning `undefined`, by serializing
+    // to the literal string: "undefined".
+    if (obj === undefined) {
+        return String(obj);
+    }
+
+    var str;
+
+    // Creates a JSON string representation of the value.
+    // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
+    if (options.isJSON && !options.space) {
+        str = JSON.stringify(obj);
+    } else {
+        str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
+    }
+
+    // Protects against `JSON.stringify()` returning `undefined`, by serializing
+    // to the literal string: "undefined".
+    if (typeof str !== 'string') {
+        return String(str);
+    }
+
+    // Replace unsafe HTML and invalid JavaScript line terminator chars with
+    // their safe Unicode char counterpart. This _must_ happen before the
+    // regexps and functions are serialized and added back to the string.
+    if (options.unsafe !== true) {
+        str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
+    }
+
+    if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) {
+        return str;
+    }
+
+    // Replaces all occurrences of function, regexp, date, map and set placeholders in the
+    // JSON string with their string representations. If the original value can
+    // not be found, then `undefined` is used.
+    return str.replace(PLACE_HOLDER_REGEXP, function (match, backSlash, type, valueIndex) {
+        // The placeholder may not be preceded by a backslash. This is to prevent
+        // replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
+        // invalid JS.
+        if (backSlash) {
+            return match;
+        }
+
+        if (type === 'D') {
+            return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
+        }
+
+        if (type === 'R') {
+            return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
+        }
+
+        if (type === 'M') {
+            return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
+        }
+
+        if (type === 'S') {
+            return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
+        }
+
+        if (type === 'A') {
+            return "Array.prototype.slice.call(" + serialize(Object.assign({ length: arrays[valueIndex].length }, arrays[valueIndex]), options) + ")";
+        }
+
+        if (type === 'U') {
+            return 'undefined'
+        }
+
+        if (type === 'I') {
+            return infinities[valueIndex];
+        }
+
+        if (type === 'B') {
+            return "BigInt(\"" + bigInts[valueIndex] + "\")";
+        }
+
+        if (type === 'L') {
+            return "new URL(\"" + urls[valueIndex].toString() + "\")"; 
+        }
+
+        var fn = functions[valueIndex];
+
+        return serializeFunc(fn);
+    });
+}

二进制
res/obj.png


部分文件因为文件数量过多而无法显示