From 636dad944e57cbc06bbf5a9df38aeb55e1f715db Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Sun, 27 Oct 2019 18:30:23 -0400
Subject: [PATCH] add helper for making states, inputs, outputs, and patch for
 hunks without loops

---
 LOG.md                                        |   15 +-
 hunks/adhoc/npath_to_path.js                  |   20 +
 hunks/data/logger.js                          |   50 +
 hunks/data/open_json.js                       |   58 +
 hunks/hunks.js                                |   26 +-
 hunks/image/readpng.js                        |    2 +-
 hunks/manager.js                              |    5 +
 .../cuttlefish/png-to-vector-pcbtest.json     |  253 ++
 .../{imageTest.json => png-to-vectors.json}   |   22 -
 test_files/example-npath.json                 | 2712 +++++++++++++++++
 typeset.js                                    |    5 +-
 11 files changed, 3139 insertions(+), 29 deletions(-)
 create mode 100644 hunks/adhoc/npath_to_path.js
 create mode 100644 hunks/data/logger.js
 create mode 100644 hunks/data/open_json.js
 create mode 100644 save/contexts/cuttlefish/png-to-vector-pcbtest.json
 rename save/contexts/cuttlefish/{imageTest.json => png-to-vectors.json} (92%)
 create mode 100644 test_files/example-npath.json

diff --git a/LOG.md b/LOG.md
index 354d24a..f1bc187 100644
--- a/LOG.md
+++ b/LOG.md
@@ -1,5 +1,15 @@
 # Cuttlefish Dev Log / Scratch Notes
 
+## Dev Prayers for Machine Week
+
+things that *should work* before MW
+- properly handle logging of *anything* and be able to inspect any datatype with this kind of tool (i.e. see the path...)
+- hunk API cleanup:
+ - don't have to push new outputs / inputs to the hunk manually (but cross compatible) - confusing if we make it, and it doesn't appear, wtf?
+- err path cleanup ... i.e. cover cases of new hunk writing:
+ - syntax errors (in code, on load)
+ - file naming errors 
+
 ## Dev Golf
 
 hour +/- long tasks under existing structures,
@@ -21,11 +31,14 @@ hour +/- long tasks under existing structures,
  - save systems w/ layout ??
 - menu
  - arrow keys to bump through items
+- import
+ - lit-html, emojis don't load when developing offline: store them somewhere.
+ - lit-html just writes html strings into the dom? probably easy to rm
 ```
 
 ## Examples
 
-Build a looping structure that replaces / stands in for traditional 'for/while' type structures. Recursing through offsets for the path is the currently pertinent example. Again this is a kind of polymorphic issue / etc. Want to write one kind of recursor, often need some secondary trigger / flowcontrol gate item that is of-the-appropriate-type. 
+Build a looping structure that replaces / stands in for traditional 'for/while' type structures. Recursing through offsets for the path is the currently pertinent example. Again this is a kind of polymorphic issue / etc. Want to write one kind of recursor, often need some secondary trigger / flowcontrol gate item that is of-the-appropriate-type.
 
 ## Aspirational Dev
 
diff --git a/hunks/adhoc/npath_to_path.js b/hunks/adhoc/npath_to_path.js
new file mode 100644
index 0000000..8774940
--- /dev/null
+++ b/hunks/adhoc/npath_to_path.js
@@ -0,0 +1,20 @@
+/*
+
+add z-moves for implicit z-moves from neil's path rep
+
+*/
+
+import {
+  Hunkify,
+  Input,
+  Output,
+  State
+} from '../hunks.js'
+
+export default function NPZ2PZ(){
+  Hunkify(this)
+
+  let outPath = this.output('reference', 'path')
+  let inPath = this.input('reference', 'path')
+  let zUp = this.state('number', 'clearance', 10)
+}
diff --git a/hunks/data/logger.js b/hunks/data/logger.js
new file mode 100644
index 0000000..c1e6f3a
--- /dev/null
+++ b/hunks/data/logger.js
@@ -0,0 +1,50 @@
+/*
+
+debugger ! log anything !
+
+*/
+
+import { Hunkify, Input, Output, State } from '../hunks.js'
+
+export default function ReferenceLogger() {
+  Hunkify(this)
+
+  // hmm...
+  let tolog = new Input('reference', 'tolog', this)
+  this.inputs.push(tolog)
+
+  let prefix = new State('string', 'prefix', 'LOG:')
+  let logToConsole = new State('boolean', 'console', true)
+  this.states.push(prefix, logToConsole)
+
+  this.dom = {}
+
+  this.init = () => {
+    this.dom = $('<div>').get(0)
+  }
+
+  this.onload = () => {
+    //error here
+    let text = $('<div>').addClass('txt').append('- >').get(0)
+    $(this.dom).append(text)
+  }
+
+  this.loop = () => {
+    // this will be called once every round turn
+    // typically we check flow control first
+    if (tolog.io()) {
+      // an input is occupied, and the exit path is empty
+      let raw = tolog.get()
+      let stringRep
+      if (Array.isArray(raw)) {
+        stringRep = raw.join(', ')
+      } else if (typeof raw === "boolean") {
+        stringRep = raw.toString()
+      }
+      $(this.dom).children('.txt').html(stringRep)
+      if (logToConsole.value === true) {
+        console.log(this.ind, prefix.value, raw)
+      }
+    }
+  }
+}
diff --git a/hunks/data/open_json.js b/hunks/data/open_json.js
new file mode 100644
index 0000000..0c5ca06
--- /dev/null
+++ b/hunks/data/open_json.js
@@ -0,0 +1,58 @@
+/*
+
+open csv, setup outputs for fields (?)
+
+*/
+
+import {
+  Hunkify,
+  Input,
+  Output,
+  State
+} from '../hunks.js'
+
+
+export default function OpenJSON() {
+  Hunkify(this)
+
+  let outRef = new Output('reference', 'data', this)
+  this.outputs.push(outRef)
+
+  let refUpdated = false
+  let theRef = {}
+  let bumpState = new State('boolean', 'release', false)
+  this.states.push(bumpState)
+  bumpState.onChange = (value) => {
+    refUpdated = true
+  }
+
+  let readJSON = (file) => {
+    let reader = new FileReader()
+    reader.onload = (evt) => {
+      theRef = JSON.parse(evt.target.result)
+      // that's it,
+      refUpdated = true
+    }
+    reader.readAsText(file)
+  }
+
+  this.init = () => {
+    this.dom = $('<div>').get(0)
+  }
+
+  this.onload = () => {
+    let btn = $('<input type="file" accept=".json">').get(0)
+    $(btn).on('change', (evt) => {
+      readJSON(evt.target.files[0])
+    })
+    $(this.dom).append(btn)
+  }
+
+  this.loop = () => {
+    if(refUpdated && !outRef.io()){
+      outRef.put(theRef)
+      refUpdated = false
+    }
+  }
+
+}
diff --git a/hunks/hunks.js b/hunks/hunks.js
index b8f2e09..d03de2e 100644
--- a/hunks/hunks.js
+++ b/hunks/hunks.js
@@ -31,6 +31,24 @@ function Hunkify(hunk) {
   hunk.outputs = new Array()
   hunk.states = new Array()
 
+  hunk.input = (type, name) => {
+    let ip = new Input(type, name, hunk)
+    hunk.inputs.push(ip)
+    return ip
+  }
+
+  hunk.output = (type, name) => {
+    let op = new Output(type, name, hunk)
+    hunk.outputs.push(op)
+    return op
+  }
+
+  hunk.state = (type, name, dfault) => {
+    let st = new State(type, name, dfault)
+    hunk.states.push(st)
+    return st
+  }
+
   // top-secret backdoor
   hunk.mgr = {}
 }
@@ -75,7 +93,7 @@ function Output(type, name, parent, linktype) {
   // and copy-out (same on the other side, we are potentially passing to many downstream, need a different copy for each)
   // typing ... odd ?
   this.put = (data) => {
-    if(!this.io()){
+    if (!this.io()) {
       this.ref = data
       this.data = this.phy.copy[this.type](data)
       this.setIo()
@@ -181,10 +199,10 @@ function Input(type, name, parent, linktype) {
     // we want to (roughly) round robin these, so we pick up from where we last pulled,
     var i = this.lastGet
     // find the next occupied conn: do iterations max. of total length of connections,
-    for(var u = 0; u < this.connections.length; u ++){
+    for (var u = 0; u < this.connections.length; u++) {
       // increment, wrap
-      i ++
-      if(i >= this.connections.length) i = 0
+      i++
+      if (i >= this.connections.length) i = 0
       // do work,
       if (this.connections[i].io) {
         let wire = this.connections[i]
diff --git a/hunks/image/readpng.js b/hunks/image/readpng.js
index ee7559d..bdab6a7 100644
--- a/hunks/image/readpng.js
+++ b/hunks/image/readpng.js
@@ -23,7 +23,7 @@ export default function UploadPNG() {
   // as a hack, we can use boolean state variables as a button: they have handy callbacks...
   const trig = new State("boolean", "release", false);
   this.states.push(trig);
-  trig.onChange = value => {
+  trig.onChange = (value) => {
     // I'll set this flag so that we will release image info on the next loop
     // if any is available,
     imageUpdated = true;
diff --git a/hunks/manager.js b/hunks/manager.js
index 10543fb..fcbdb26 100644
--- a/hunks/manager.js
+++ b/hunks/manager.js
@@ -252,6 +252,11 @@ function Manager() {
       }
     }
 
+    // if no loop function exists, write the empty case:
+    if(!hunk.loop){
+      hunk.loop = () => {}
+    }
+
     // if the hunk has a dom, and we have a view, add it ...
     if (hunk.dom !== null && hunk.dom !== undefined) {
       // this is only allowed in the tlview, and we manage that...
diff --git a/save/contexts/cuttlefish/png-to-vector-pcbtest.json b/save/contexts/cuttlefish/png-to-vector-pcbtest.json
new file mode 100644
index 0000000..ab5cff8
--- /dev/null
+++ b/save/contexts/cuttlefish/png-to-vector-pcbtest.json
@@ -0,0 +1,253 @@
+{
+  "interpreterName": "cuttlefish",
+  "interpreterVersion": "v0.1",
+  "hunks": [
+    {
+      "type": "manager",
+      "name": "nrol",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "1",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "view",
+      "name": "tlview",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "0",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "image/thresholdrgba",
+      "name": "image/thresholdrgba_3",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "image",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "5",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ],
+      "states": [
+        {
+          "name": "threshold",
+          "type": "number",
+          "value": "0.5"
+        }
+      ]
+    },
+    {
+      "type": "image/readpng",
+      "name": "image/readpng_3",
+      "outputs": [
+        {
+          "name": "image",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "2",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ],
+      "states": [
+        {
+          "name": "release",
+          "type": "boolean",
+          "value": "false"
+        }
+      ]
+    },
+    {
+      "type": "image/displayimagedata",
+      "name": "image/displayimagedata_4",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ]
+    },
+    {
+      "type": "image/distanceTransform",
+      "name": "image/distanceTransform_6",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "image",
+          "type": "Float32Array",
+          "connections": [
+            {
+              "inHunkIndex": "7",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "image/edgeDetect",
+      "name": "image/edgeDetect_7",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "image",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "8",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "image/offset",
+      "name": "image/offset_8",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "Float32Array"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "image",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "6",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ],
+      "states": [
+        {
+          "name": "offset",
+          "type": "number",
+          "value": "0.1"
+        },
+        {
+          "name": "width",
+          "type": "number",
+          "value": "1854"
+        },
+        {
+          "name": "height",
+          "type": "number",
+          "value": "1917"
+        }
+      ]
+    },
+    {
+      "type": "image/orientEdges",
+      "name": "image/orientEdges_9",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "image",
+          "type": "ImageData",
+          "connections": [
+            {
+              "inHunkIndex": "10",
+              "inHunkInput": "0"
+            },
+            {
+              "inHunkIndex": "4",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "image/renderVectors",
+      "name": "image/renderVectors_11",
+      "inputs": [
+        {
+          "name": "Vectors",
+          "type": "array"
+        }
+      ]
+    },
+    {
+      "type": "image/vectorize",
+      "name": "image/vectorize_11",
+      "inputs": [
+        {
+          "name": "image",
+          "type": "ImageData"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "Vectors",
+          "type": "array",
+          "connections": [
+            {
+              "inHunkIndex": "9",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/save/contexts/cuttlefish/imageTest.json b/save/contexts/cuttlefish/png-to-vectors.json
similarity index 92%
rename from save/contexts/cuttlefish/imageTest.json
rename to save/contexts/cuttlefish/png-to-vectors.json
index c8d45c5..75cc45c 100644
--- a/save/contexts/cuttlefish/imageTest.json
+++ b/save/contexts/cuttlefish/png-to-vectors.json
@@ -248,28 +248,6 @@
           ]
         }
       ]
-    },
-    {
-      "type": "data/logger",
-      "name": "data/logger_12",
-      "inputs": [
-        {
-          "name": "tolog",
-          "type": "any"
-        }
-      ],
-      "states": [
-        {
-          "name": "prefix",
-          "type": "string",
-          "value": "LOG:"
-        },
-        {
-          "name": "console",
-          "type": "boolean",
-          "value": "true"
-        }
-      ]
     }
   ]
 }
\ No newline at end of file
diff --git a/test_files/example-npath.json b/test_files/example-npath.json
new file mode 100644
index 0000000..572f104
--- /dev/null
+++ b/test_files/example-npath.json
@@ -0,0 +1,2712 @@
+[
+  [
+    [
+      63,
+      63
+    ],
+    [
+      1791,
+      63
+    ],
+    [
+      1791,
+      1854
+    ],
+    [
+      63,
+      1854
+    ],
+    [
+      63,
+      63
+    ]
+  ],
+  [
+    [
+      172,
+      135
+    ],
+    [
+      172,
+      195
+    ],
+    [
+      201,
+      195
+    ],
+    [
+      201,
+      249
+    ],
+    [
+      169,
+      249
+    ],
+    [
+      169,
+      335
+    ],
+    [
+      201,
+      335
+    ],
+    [
+      201,
+      405
+    ],
+    [
+      204,
+      405
+    ],
+    [
+      204,
+      411
+    ],
+    [
+      253,
+      411
+    ],
+    [
+      253,
+      382
+    ],
+    [
+      218,
+      382
+    ],
+    [
+      218,
+      335
+    ],
+    [
+      250,
+      335
+    ],
+    [
+      250,
+      249
+    ],
+    [
+      218,
+      249
+    ],
+    [
+      218,
+      195
+    ],
+    [
+      222,
+      195
+    ],
+    [
+      222,
+      135
+    ],
+    [
+      172,
+      135
+    ]
+  ],
+  [
+    [
+      366,
+      97
+    ],
+    [
+      366,
+      135
+    ],
+    [
+      350,
+      135
+    ],
+    [
+      350,
+      195
+    ],
+    [
+      400,
+      195
+    ],
+    [
+      400,
+      135
+    ],
+    [
+      383,
+      135
+    ],
+    [
+      383,
+      114
+    ],
+    [
+      683,
+      114
+    ],
+    [
+      683,
+      182
+    ],
+    [
+      661,
+      182
+    ],
+    [
+      661,
+      308
+    ],
+    [
+      723,
+      308
+    ],
+    [
+      723,
+      182
+    ],
+    [
+      700,
+      182
+    ],
+    [
+      700,
+      114
+    ],
+    [
+      1329,
+      114
+    ],
+    [
+      1329,
+      182
+    ],
+    [
+      1306,
+      182
+    ],
+    [
+      1306,
+      308
+    ],
+    [
+      1368,
+      308
+    ],
+    [
+      1368,
+      182
+    ],
+    [
+      1346,
+      182
+    ],
+    [
+      1346,
+      114
+    ],
+    [
+      1740,
+      114
+    ],
+    [
+      1740,
+      1024
+    ],
+    [
+      1672,
+      1024
+    ],
+    [
+      1672,
+      1001
+    ],
+    [
+      1546,
+      1001
+    ],
+    [
+      1546,
+      1063
+    ],
+    [
+      1672,
+      1063
+    ],
+    [
+      1672,
+      1041
+    ],
+    [
+      1740,
+      1041
+    ],
+    [
+      1740,
+      1791
+    ],
+    [
+      1033,
+      1791
+    ],
+    [
+      1033,
+      1722
+    ],
+    [
+      1056,
+      1722
+    ],
+    [
+      1056,
+      1596
+    ],
+    [
+      994,
+      1596
+    ],
+    [
+      994,
+      1722
+    ],
+    [
+      1017,
+      1722
+    ],
+    [
+      1017,
+      1807
+    ],
+    [
+      1757,
+      1807
+    ],
+    [
+      1757,
+      97
+    ],
+    [
+      366,
+      97
+    ]
+  ],
+  [
+    [
+      436,
+      135
+    ],
+    [
+      436,
+      284
+    ],
+    [
+      402,
+      284
+    ],
+    [
+      402,
+      249
+    ],
+    [
+      322,
+      249
+    ],
+    [
+      322,
+      335
+    ],
+    [
+      402,
+      335
+    ],
+    [
+      402,
+      300
+    ],
+    [
+      436,
+      300
+    ],
+    [
+      436,
+      436
+    ],
+    [
+      368,
+      436
+    ],
+    [
+      368,
+      430
+    ],
+    [
+      318,
+      430
+    ],
+    [
+      318,
+      459
+    ],
+    [
+      368,
+      459
+    ],
+    [
+      368,
+      453
+    ],
+    [
+      436,
+      453
+    ],
+    [
+      436,
+      588
+    ],
+    [
+      402,
+      588
+    ],
+    [
+      402,
+      554
+    ],
+    [
+      322,
+      554
+    ],
+    [
+      322,
+      588
+    ],
+    [
+      309,
+      588
+    ],
+    [
+      309,
+      1096
+    ],
+    [
+      270,
+      1096
+    ],
+    [
+      270,
+      1073
+    ],
+    [
+      144,
+      1073
+    ],
+    [
+      144,
+      1136
+    ],
+    [
+      270,
+      1136
+    ],
+    [
+      270,
+      1113
+    ],
+    [
+      309,
+      1113
+    ],
+    [
+      309,
+      1176
+    ],
+    [
+      618,
+      1176
+    ],
+    [
+      618,
+      1100
+    ],
+    [
+      704,
+      1100
+    ],
+    [
+      704,
+      1084
+    ],
+    [
+      601,
+      1084
+    ],
+    [
+      601,
+      1160
+    ],
+    [
+      326,
+      1160
+    ],
+    [
+      326,
+      639
+    ],
+    [
+      402,
+      639
+    ],
+    [
+      402,
+      605
+    ],
+    [
+      453,
+      605
+    ],
+    [
+      453,
+      152
+    ],
+    [
+      620,
+      152
+    ],
+    [
+      620,
+      364
+    ],
+    [
+      683,
+      364
+    ],
+    [
+      683,
+      454
+    ],
+    [
+      661,
+      454
+    ],
+    [
+      661,
+      580
+    ],
+    [
+      723,
+      580
+    ],
+    [
+      723,
+      454
+    ],
+    [
+      700,
+      454
+    ],
+    [
+      700,
+      364
+    ],
+    [
+      764,
+      364
+    ],
+    [
+      764,
+      152
+    ],
+    [
+      1265,
+      152
+    ],
+    [
+      1265,
+      389
+    ],
+    [
+      1329,
+      389
+    ],
+    [
+      1329,
+      454
+    ],
+    [
+      1306,
+      454
+    ],
+    [
+      1306,
+      580
+    ],
+    [
+      1368,
+      580
+    ],
+    [
+      1368,
+      454
+    ],
+    [
+      1346,
+      454
+    ],
+    [
+      1346,
+      389
+    ],
+    [
+      1409,
+      389
+    ],
+    [
+      1409,
+      152
+    ],
+    [
+      1702,
+      152
+    ],
+    [
+      1702,
+      804
+    ],
+    [
+      1227,
+      804
+    ],
+    [
+      1227,
+      844
+    ],
+    [
+      1099,
+      844
+    ],
+    [
+      1099,
+      861
+    ],
+    [
+      1244,
+      861
+    ],
+    [
+      1244,
+      821
+    ],
+    [
+      1702,
+      821
+    ],
+    [
+      1702,
+      960
+    ],
+    [
+      1490,
+      960
+    ],
+    [
+      1490,
+      1024
+    ],
+    [
+      1400,
+      1024
+    ],
+    [
+      1400,
+      1001
+    ],
+    [
+      1274,
+      1001
+    ],
+    [
+      1274,
+      1063
+    ],
+    [
+      1400,
+      1063
+    ],
+    [
+      1400,
+      1041
+    ],
+    [
+      1490,
+      1041
+    ],
+    [
+      1490,
+      1104
+    ],
+    [
+      1702,
+      1104
+    ],
+    [
+      1702,
+      1623
+    ],
+    [
+      1579,
+      1623
+    ],
+    [
+      1579,
+      1559
+    ],
+    [
+      1494,
+      1559
+    ],
+    [
+      1494,
+      1640
+    ],
+    [
+      1702,
+      1640
+    ],
+    [
+      1702,
+      1752
+    ],
+    [
+      1097,
+      1752
+    ],
+    [
+      1097,
+      1540
+    ],
+    [
+      1033,
+      1540
+    ],
+    [
+      1033,
+      1451
+    ],
+    [
+      1056,
+      1451
+    ],
+    [
+      1056,
+      1325
+    ],
+    [
+      994,
+      1325
+    ],
+    [
+      994,
+      1451
+    ],
+    [
+      1017,
+      1451
+    ],
+    [
+      1017,
+      1540
+    ],
+    [
+      953,
+      1540
+    ],
+    [
+      953,
+      1752
+    ],
+    [
+      605,
+      1752
+    ],
+    [
+      605,
+      1640
+    ],
+    [
+      640,
+      1640
+    ],
+    [
+      640,
+      1559
+    ],
+    [
+      554,
+      1559
+    ],
+    [
+      554,
+      1591
+    ],
+    [
+      250,
+      1591
+    ],
+    [
+      250,
+      1479
+    ],
+    [
+      279,
+      1479
+    ],
+    [
+      279,
+      1378
+    ],
+    [
+      250,
+      1378
+    ],
+    [
+      250,
+      1338
+    ],
+    [
+      330,
+      1338
+    ],
+    [
+      330,
+      1252
+    ],
+    [
+      249,
+      1252
+    ],
+    [
+      249,
+      1287
+    ],
+    [
+      233,
+      1287
+    ],
+    [
+      233,
+      1378
+    ],
+    [
+      204,
+      1378
+    ],
+    [
+      204,
+      1479
+    ],
+    [
+      233,
+      1479
+    ],
+    [
+      233,
+      1608
+    ],
+    [
+      554,
+      1608
+    ],
+    [
+      554,
+      1640
+    ],
+    [
+      588,
+      1640
+    ],
+    [
+      588,
+      1769
+    ],
+    [
+      970,
+      1769
+    ],
+    [
+      970,
+      1557
+    ],
+    [
+      1080,
+      1557
+    ],
+    [
+      1080,
+      1769
+    ],
+    [
+      1719,
+      1769
+    ],
+    [
+      1719,
+      1087
+    ],
+    [
+      1507,
+      1087
+    ],
+    [
+      1507,
+      977
+    ],
+    [
+      1719,
+      977
+    ],
+    [
+      1719,
+      135
+    ],
+    [
+      1392,
+      135
+    ],
+    [
+      1392,
+      372
+    ],
+    [
+      1282,
+      372
+    ],
+    [
+      1282,
+      135
+    ],
+    [
+      747,
+      135
+    ],
+    [
+      747,
+      347
+    ],
+    [
+      637,
+      347
+    ],
+    [
+      637,
+      135
+    ],
+    [
+      436,
+      135
+    ]
+  ],
+  [
+    [
+      534,
+      182
+    ],
+    [
+      534,
+      308
+    ],
+    [
+      556,
+      308
+    ],
+    [
+      556,
+      415
+    ],
+    [
+      620,
+      415
+    ],
+    [
+      620,
+      652
+    ],
+    [
+      793,
+      652
+    ],
+    [
+      793,
+      924
+    ],
+    [
+      642,
+      924
+    ],
+    [
+      642,
+      941
+    ],
+    [
+      810,
+      941
+    ],
+    [
+      810,
+      635
+    ],
+    [
+      637,
+      635
+    ],
+    [
+      637,
+      398
+    ],
+    [
+      573,
+      398
+    ],
+    [
+      573,
+      308
+    ],
+    [
+      596,
+      308
+    ],
+    [
+      596,
+      182
+    ],
+    [
+      534,
+      182
+    ]
+  ],
+  [
+    [
+      788,
+      182
+    ],
+    [
+      788,
+      308
+    ],
+    [
+      850,
+      308
+    ],
+    [
+      850,
+      253
+    ],
+    [
+      873,
+      253
+    ],
+    [
+      873,
+      1004
+    ],
+    [
+      642,
+      1004
+    ],
+    [
+      642,
+      1021
+    ],
+    [
+      890,
+      1021
+    ],
+    [
+      890,
+      237
+    ],
+    [
+      850,
+      237
+    ],
+    [
+      850,
+      182
+    ],
+    [
+      788,
+      182
+    ]
+  ],
+  [
+    [
+      788,
+      454
+    ],
+    [
+      788,
+      580
+    ],
+    [
+      792,
+      580
+    ],
+    [
+      792,
+      582
+    ],
+    [
+      796,
+      586
+    ],
+    [
+      798,
+      588
+    ],
+    [
+      807,
+      594
+    ],
+    [
+      809,
+      594
+    ],
+    [
+      817,
+      596
+    ],
+    [
+      825,
+      596
+    ],
+    [
+      833,
+      593
+    ],
+    [
+      833,
+      964
+    ],
+    [
+      642,
+      964
+    ],
+    [
+      642,
+      981
+    ],
+    [
+      850,
+      981
+    ],
+    [
+      850,
+      454
+    ],
+    [
+      788,
+      454
+    ]
+  ],
+  [
+    [
+      534,
+      454
+    ],
+    [
+      534,
+      580
+    ],
+    [
+      556,
+      580
+    ],
+    [
+      556,
+      690
+    ],
+    [
+      753,
+      690
+    ],
+    [
+      753,
+      884
+    ],
+    [
+      642,
+      884
+    ],
+    [
+      642,
+      901
+    ],
+    [
+      770,
+      901
+    ],
+    [
+      770,
+      673
+    ],
+    [
+      573,
+      673
+    ],
+    [
+      573,
+      580
+    ],
+    [
+      596,
+      580
+    ],
+    [
+      596,
+      454
+    ],
+    [
+      534,
+      454
+    ]
+  ],
+  [
+    [
+      354,
+      681
+    ],
+    [
+      354,
+      766
+    ],
+    [
+      360,
+      766
+    ],
+    [
+      360,
+      1113
+    ],
+    [
+      416,
+      1113
+    ],
+    [
+      416,
+      1136
+    ],
+    [
+      542,
+      1136
+    ],
+    [
+      542,
+      1073
+    ],
+    [
+      416,
+      1073
+    ],
+    [
+      416,
+      1096
+    ],
+    [
+      377,
+      1096
+    ],
+    [
+      377,
+      766
+    ],
+    [
+      434,
+      766
+    ],
+    [
+      434,
+      732
+    ],
+    [
+      665,
+      732
+    ],
+    [
+      665,
+      804
+    ],
+    [
+      642,
+      804
+    ],
+    [
+      642,
+      821
+    ],
+    [
+      704,
+      821
+    ],
+    [
+      704,
+      804
+    ],
+    [
+      681,
+      804
+    ],
+    [
+      681,
+      715
+    ],
+    [
+      434,
+      715
+    ],
+    [
+      434,
+      681
+    ],
+    [
+      354,
+      681
+    ]
+  ],
+  [
+    [
+      416,
+      819
+    ],
+    [
+      416,
+      882
+    ],
+    [
+      546,
+      882
+    ],
+    [
+      559,
+      877
+    ],
+    [
+      568,
+      868
+    ],
+    [
+      572,
+      861
+    ],
+    [
+      704,
+      861
+    ],
+    [
+      704,
+      844
+    ],
+    [
+      573,
+      844
+    ],
+    [
+      568,
+      833
+    ],
+    [
+      560,
+      825
+    ],
+    [
+      551,
+      821
+    ],
+    [
+      539,
+      819
+    ],
+    [
+      416,
+      819
+    ]
+  ],
+  [
+    [
+      416,
+      946
+    ],
+    [
+      416,
+      1009
+    ],
+    [
+      542,
+      1009
+    ],
+    [
+      542,
+      946
+    ],
+    [
+      416,
+      946
+    ]
+  ],
+  [
+    [
+      601,
+      1044
+    ],
+    [
+      601,
+      1061
+    ],
+    [
+      704,
+      1061
+    ],
+    [
+      704,
+      1044
+    ],
+    [
+      601,
+      1044
+    ]
+  ],
+  [
+    [
+      793,
+      1149
+    ],
+    [
+      793,
+      1236
+    ],
+    [
+      436,
+      1236
+    ],
+    [
+      436,
+      1378
+    ],
+    [
+      407,
+      1378
+    ],
+    [
+      407,
+      1479
+    ],
+    [
+      482,
+      1479
+    ],
+    [
+      482,
+      1378
+    ],
+    [
+      453,
+      1378
+    ],
+    [
+      453,
+      1253
+    ],
+    [
+      810,
+      1253
+    ],
+    [
+      810,
+      1149
+    ],
+    [
+      793,
+      1149
+    ]
+  ],
+  [
+    [
+      833,
+      1149
+    ],
+    [
+      833,
+      1274
+    ],
+    [
+      715,
+      1274
+    ],
+    [
+      715,
+      1407
+    ],
+    [
+      681,
+      1407
+    ],
+    [
+      681,
+      1487
+    ],
+    [
+      766,
+      1487
+    ],
+    [
+      766,
+      1407
+    ],
+    [
+      732,
+      1407
+    ],
+    [
+      732,
+      1291
+    ],
+    [
+      850,
+      1291
+    ],
+    [
+      850,
+      1149
+    ],
+    [
+      833,
+      1149
+    ]
+  ],
+  [
+    [
+      873,
+      1149
+    ],
+    [
+      873,
+      1253
+    ],
+    [
+      890,
+      1253
+    ],
+    [
+      890,
+      1149
+    ],
+    [
+      873,
+      1149
+    ]
+  ],
+  [
+    [
+      913,
+      1149
+    ],
+    [
+      913,
+      1311
+    ],
+    [
+      910,
+      1311
+    ],
+    [
+      904,
+      1309
+    ],
+    [
+      902,
+      1309
+    ],
+    [
+      894,
+      1308
+    ],
+    [
+      883,
+      1312
+    ],
+    [
+      873,
+      1321
+    ],
+    [
+      870,
+      1325
+    ],
+    [
+      867,
+      1325
+    ],
+    [
+      867,
+      1451
+    ],
+    [
+      929,
+      1451
+    ],
+    [
+      929,
+      1396
+    ],
+    [
+      930,
+      1149
+    ],
+    [
+      913,
+      1149
+    ]
+  ],
+  [
+    [
+      953,
+      1149
+    ],
+    [
+      953,
+      1490
+    ],
+    [
+      890,
+      1490
+    ],
+    [
+      890,
+      1596
+    ],
+    [
+      867,
+      1596
+    ],
+    [
+      867,
+      1722
+    ],
+    [
+      929,
+      1722
+    ],
+    [
+      929,
+      1596
+    ],
+    [
+      906,
+      1596
+    ],
+    [
+      906,
+      1506
+    ],
+    [
+      970,
+      1506
+    ],
+    [
+      970,
+      1149
+    ],
+    [
+      953,
+      1149
+    ]
+  ],
+  [
+    [
+      993,
+      1149
+    ],
+    [
+      993,
+      1256
+    ],
+    [
+      1080,
+      1256
+    ],
+    [
+      1080,
+      1506
+    ],
+    [
+      1144,
+      1506
+    ],
+    [
+      1144,
+      1596
+    ],
+    [
+      1121,
+      1596
+    ],
+    [
+      1121,
+      1722
+    ],
+    [
+      1183,
+      1722
+    ],
+    [
+      1183,
+      1640
+    ],
+    [
+      1452,
+      1640
+    ],
+    [
+      1452,
+      1559
+    ],
+    [
+      1367,
+      1559
+    ],
+    [
+      1367,
+      1623
+    ],
+    [
+      1183,
+      1623
+    ],
+    [
+      1183,
+      1596
+    ],
+    [
+      1160,
+      1596
+    ],
+    [
+      1160,
+      1490
+    ],
+    [
+      1097,
+      1490
+    ],
+    [
+      1097,
+      1240
+    ],
+    [
+      1010,
+      1240
+    ],
+    [
+      1010,
+      1149
+    ],
+    [
+      993,
+      1149
+    ]
+  ],
+  [
+    [
+      1033,
+      1149
+    ],
+    [
+      1033,
+      1214
+    ],
+    [
+      1144,
+      1214
+    ],
+    [
+      1144,
+      1325
+    ],
+    [
+      1121,
+      1325
+    ],
+    [
+      1121,
+      1451
+    ],
+    [
+      1183,
+      1451
+    ],
+    [
+      1183,
+      1325
+    ],
+    [
+      1160,
+      1325
+    ],
+    [
+      1160,
+      1198
+    ],
+    [
+      1050,
+      1198
+    ],
+    [
+      1050,
+      1149
+    ],
+    [
+      1033,
+      1149
+    ]
+  ],
+  [
+    [
+      1099,
+      1084
+    ],
+    [
+      1099,
+      1100
+    ],
+    [
+      1189,
+      1100
+    ],
+    [
+      1189,
+      1167
+    ],
+    [
+      1259,
+      1167
+    ],
+    [
+      1259,
+      1169
+    ],
+    [
+      1265,
+      1179
+    ],
+    [
+      1268,
+      1182
+    ],
+    [
+      1274,
+      1187
+    ],
+    [
+      1274,
+      1190
+    ],
+    [
+      1400,
+      1190
+    ],
+    [
+      1400,
+      1128
+    ],
+    [
+      1274,
+      1128
+    ],
+    [
+      1274,
+      1132
+    ],
+    [
+      1267,
+      1137
+    ],
+    [
+      1260,
+      1147
+    ],
+    [
+      1260,
+      1149
+    ],
+    [
+      1258,
+      1151
+    ],
+    [
+      1206,
+      1151
+    ],
+    [
+      1206,
+      1084
+    ],
+    [
+      1099,
+      1084
+    ]
+  ],
+  [
+    [
+      1099,
+      1044
+    ],
+    [
+      1099,
+      1061
+    ],
+    [
+      1227,
+      1061
+    ],
+    [
+      1227,
+      1104
+    ],
+    [
+      1439,
+      1104
+    ],
+    [
+      1439,
+      1167
+    ],
+    [
+      1546,
+      1167
+    ],
+    [
+      1546,
+      1190
+    ],
+    [
+      1672,
+      1190
+    ],
+    [
+      1672,
+      1128
+    ],
+    [
+      1546,
+      1128
+    ],
+    [
+      1546,
+      1151
+    ],
+    [
+      1456,
+      1151
+    ],
+    [
+      1456,
+      1087
+    ],
+    [
+      1244,
+      1087
+    ],
+    [
+      1244,
+      1044
+    ],
+    [
+      1099,
+      1044
+    ]
+  ],
+  [
+    [
+      1058,
+      924
+    ],
+    [
+      1058,
+      941
+    ],
+    [
+      1161,
+      941
+    ],
+    [
+      1161,
+      924
+    ],
+    [
+      1058,
+      924
+    ]
+  ],
+  [
+    [
+      1058,
+      884
+    ],
+    [
+      1058,
+      901
+    ],
+    [
+      1161,
+      901
+    ],
+    [
+      1161,
+      884
+    ],
+    [
+      1058,
+      884
+    ]
+  ],
+  [
+    [
+      1274,
+      874
+    ],
+    [
+      1274,
+      897
+    ],
+    [
+      1189,
+      897
+    ],
+    [
+      1189,
+      964
+    ],
+    [
+      1099,
+      964
+    ],
+    [
+      1099,
+      981
+    ],
+    [
+      1206,
+      981
+    ],
+    [
+      1206,
+      914
+    ],
+    [
+      1274,
+      914
+    ],
+    [
+      1274,
+      936
+    ],
+    [
+      1400,
+      936
+    ],
+    [
+      1400,
+      874
+    ],
+    [
+      1274,
+      874
+    ]
+  ],
+  [
+    [
+      1546,
+      874
+    ],
+    [
+      1546,
+      897
+    ],
+    [
+      1439,
+      897
+    ],
+    [
+      1439,
+      960
+    ],
+    [
+      1227,
+      960
+    ],
+    [
+      1227,
+      1004
+    ],
+    [
+      1099,
+      1004
+    ],
+    [
+      1099,
+      1021
+    ],
+    [
+      1244,
+      1021
+    ],
+    [
+      1244,
+      977
+    ],
+    [
+      1456,
+      977
+    ],
+    [
+      1456,
+      914
+    ],
+    [
+      1546,
+      914
+    ],
+    [
+      1546,
+      936
+    ],
+    [
+      1672,
+      936
+    ],
+    [
+      1672,
+      874
+    ],
+    [
+      1546,
+      874
+    ]
+  ],
+  [
+    [
+      1433,
+      454
+    ],
+    [
+      1433,
+      580
+    ],
+    [
+      1437,
+      580
+    ],
+    [
+      1445,
+      590
+    ],
+    [
+      1447,
+      590
+    ],
+    [
+      1449,
+      592
+    ],
+    [
+      1456,
+      596
+    ],
+    [
+      1456,
+      639
+    ],
+    [
+      993,
+      639
+    ],
+    [
+      993,
+      755
+    ],
+    [
+      1010,
+      755
+    ],
+    [
+      1010,
+      656
+    ],
+    [
+      1473,
+      656
+    ],
+    [
+      1473,
+      595
+    ],
+    [
+      1484,
+      589
+    ],
+    [
+      1492,
+      580
+    ],
+    [
+      1495,
+      580
+    ],
+    [
+      1495,
+      454
+    ],
+    [
+      1433,
+      454
+    ]
+  ],
+  [
+    [
+      1179,
+      454
+    ],
+    [
+      1179,
+      508
+    ],
+    [
+      953,
+      508
+    ],
+    [
+      953,
+      755
+    ],
+    [
+      970,
+      755
+    ],
+    [
+      970,
+      525
+    ],
+    [
+      1179,
+      525
+    ],
+    [
+      1179,
+      580
+    ],
+    [
+      1241,
+      580
+    ],
+    [
+      1241,
+      454
+    ],
+    [
+      1179,
+      454
+    ]
+  ],
+  [
+    [
+      1179,
+      182
+    ],
+    [
+      1179,
+      237
+    ],
+    [
+      913,
+      237
+    ],
+    [
+      913,
+      755
+    ],
+    [
+      930,
+      755
+    ],
+    [
+      930,
+      253
+    ],
+    [
+      1179,
+      253
+    ],
+    [
+      1179,
+      308
+    ],
+    [
+      1241,
+      308
+    ],
+    [
+      1241,
+      182
+    ],
+    [
+      1179,
+      182
+    ]
+  ],
+  [
+    [
+      1433,
+      182
+    ],
+    [
+      1433,
+      308
+    ],
+    [
+      1495,
+      308
+    ],
+    [
+      1495,
+      253
+    ],
+    [
+      1519,
+      253
+    ],
+    [
+      1519,
+      715
+    ],
+    [
+      1050,
+      715
+    ],
+    [
+      1050,
+      692
+    ],
+    [
+      1033,
+      692
+    ],
+    [
+      1033,
+      755
+    ],
+    [
+      1050,
+      755
+    ],
+    [
+      1050,
+      732
+    ],
+    [
+      1536,
+      732
+    ],
+    [
+      1536,
+      237
+    ],
+    [
+      1495,
+      237
+    ],
+    [
+      1495,
+      182
+    ],
+    [
+      1433,
+      182
+    ]
+  ],
+  [
+    [
+      1367,
+      1407
+    ],
+    [
+      1367,
+      1487
+    ],
+    [
+      1452,
+      1487
+    ],
+    [
+      1452,
+      1456
+    ],
+    [
+      1494,
+      1456
+    ],
+    [
+      1494,
+      1487
+    ],
+    [
+      1579,
+      1487
+    ],
+    [
+      1579,
+      1407
+    ],
+    [
+      1494,
+      1407
+    ],
+    [
+      1494,
+      1439
+    ],
+    [
+      1452,
+      1439
+    ],
+    [
+      1452,
+      1407
+    ],
+    [
+      1367,
+      1407
+    ]
+  ],
+  [
+    [
+      554,
+      1407
+    ],
+    [
+      554,
+      1487
+    ],
+    [
+      588,
+      1487
+    ],
+    [
+      588,
+      1532
+    ],
+    [
+      715,
+      1532
+    ],
+    [
+      715,
+      1559
+    ],
+    [
+      681,
+      1559
+    ],
+    [
+      681,
+      1640
+    ],
+    [
+      766,
+      1640
+    ],
+    [
+      766,
+      1559
+    ],
+    [
+      732,
+      1559
+    ],
+    [
+      732,
+      1515
+    ],
+    [
+      605,
+      1515
+    ],
+    [
+      605,
+      1487
+    ],
+    [
+      640,
+      1487
+    ],
+    [
+      640,
+      1407
+    ],
+    [
+      554,
+      1407
+    ]
+  ],
+  [
+    [
+      407,
+      1695
+    ],
+    [
+      407,
+      1796
+    ],
+    [
+      482,
+      1796
+    ],
+    [
+      482,
+      1695
+    ],
+    [
+      407,
+      1695
+    ]
+  ],
+  [
+    [
+      204,
+      1695
+    ],
+    [
+      204,
+      1796
+    ],
+    [
+      279,
+      1796
+    ],
+    [
+      279,
+      1695
+    ],
+    [
+      204,
+      1695
+    ]
+  ],
+  [
+    [
+      144,
+      946
+    ],
+    [
+      144,
+      1009
+    ],
+    [
+      270,
+      1009
+    ],
+    [
+      270,
+      946
+    ],
+    [
+      144,
+      946
+    ]
+  ],
+  [
+    [
+      204,
+      477
+    ],
+    [
+      204,
+      484
+    ],
+    [
+      201,
+      484
+    ],
+    [
+      201,
+      554
+    ],
+    [
+      169,
+      554
+    ],
+    [
+      169,
+      639
+    ],
+    [
+      233,
+      639
+    ],
+    [
+      233,
+      681
+    ],
+    [
+      201,
+      681
+    ],
+    [
+      201,
+      766
+    ],
+    [
+      233,
+      766
+    ],
+    [
+      233,
+      819
+    ],
+    [
+      144,
+      819
+    ],
+    [
+      144,
+      842
+    ],
+    [
+      97,
+      842
+    ],
+    [
+      97,
+      1338
+    ],
+    [
+      177,
+      1338
+    ],
+    [
+      177,
+      1252
+    ],
+    [
+      114,
+      1252
+    ],
+    [
+      114,
+      1214
+    ],
+    [
+      770,
+      1214
+    ],
+    [
+      770,
+      1100
+    ],
+    [
+      970,
+      1100
+    ],
+    [
+      970,
+      821
+    ],
+    [
+      1161,
+      821
+    ],
+    [
+      1161,
+      804
+    ],
+    [
+      953,
+      804
+    ],
+    [
+      953,
+      1084
+    ],
+    [
+      753,
+      1084
+    ],
+    [
+      753,
+      1198
+    ],
+    [
+      114,
+      1198
+    ],
+    [
+      114,
+      859
+    ],
+    [
+      144,
+      859
+    ],
+    [
+      144,
+      882
+    ],
+    [
+      270,
+      882
+    ],
+    [
+      270,
+      819
+    ],
+    [
+      250,
+      819
+    ],
+    [
+      250,
+      766
+    ],
+    [
+      281,
+      766
+    ],
+    [
+      281,
+      681
+    ],
+    [
+      250,
+      681
+    ],
+    [
+      250,
+      554
+    ],
+    [
+      218,
+      554
+    ],
+    [
+      218,
+      507
+    ],
+    [
+      253,
+      507
+    ],
+    [
+      253,
+      477
+    ],
+    [
+      204,
+      477
+    ]
+  ]
+]
\ No newline at end of file
diff --git a/typeset.js b/typeset.js
index 3c174cf..036129b 100644
--- a/typeset.js
+++ b/typeset.js
@@ -512,7 +512,10 @@ const TSET = [
   {
     name: 'array',
     copy: {
-      array: (arr) => [...arr]
+      array: (arr) => [...arr],
+      reference: (arr) => {
+        return arr 
+      }
     }
   }
   // etc
-- 
GitLab