diff --git a/.gitignore b/.gitignore index c3a119dc..63079ba6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ yarn.lock .esm-cache .sessionStorage .localStorage +lib/meta \ No newline at end of file diff --git a/lib/meta.js b/lib/meta.js index c9fa3f9b..4b412a5c 100644 --- a/lib/meta.js +++ b/lib/meta.js @@ -1,5 +1,18 @@ ;(function(){ + function USE(arg, req){ + return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){ + arg(mod = {exports: {}}); + USE[R(path)] = mod.exports; + } + function R(p){ + return p.split('/').slice(-1).toString().replace('.js',''); + } + } + +/* UNBUILD */ +;USE(function(module){ var noop = function(){}, u; + $.fn.or = function(s){ return this.length ? this : $(s||'body') }; var m = window.meta = {edit:[]}; var k = m.key = {}; k.meta = {17:17, 91:17, 93:17, 224:17}; @@ -34,7 +47,7 @@ } m.flip = function(tmp){ var board = $('#meta .meta-menu'); - ((tmp === false) || (!tmp && board.is(':visible')))? + ((tmp === false) || (!tmp && board.is(':visible')))? board.addClass('meta-none') : board.removeClass('meta-none'); } @@ -89,7 +102,7 @@ m.ask = function(help, cb){ var $ul = $('#meta .meta-menu ul').empty(); var $put = $('').attr('id', 'meta-ask').attr('placeholder', help); - var $form = $('
').append($put).on('submit', function(eve){ + var $form = $('').append($put).on('submit', function(eve){ eve.preventDefault(); cb($put.val()); $li.remove(); @@ -112,27 +125,6 @@ .or($(document.elementFromPoint(meta.tap.x, meta.tap.y))); return on; } - $(window).on('blur', k.wipe).on('focus', k.wipe); - $(document).on('mousedown mousemove mouseup', function(eve){ - m.tap.eve = eve; - m.tap.x = eve.pageX||0; - m.tap.y = eve.pageY||0; - m.tap.on = $(eve.target); - }).on('mousedown touchstart', function(eve){ - var tmp = m.tap.edit; - if(!tmp || !tmp.on){ return } - tmp.on(eve); - m.tap.edit = null; - }); - $(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true }); - $(document).on('click', '#meta .meta-menu li', function(eve){ - if(m.tap.stun){ return m.tap.stun = false } - if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return } - eve.tap = true; - k.down(eve); - k.up(eve); - }); - $(document).on('keydown', k.down).on('keyup', k.up); meta.edit = function(edit){ var tmp = edit.combow = []; $.each(edit.combo || (edit.combo = []), function(i,k){ @@ -144,8 +136,9 @@ edit.combow = edit.combow.join(','); m.list(meta.edit); } - $.fn.or = function(s){ return this.length ? this : $(s||'body') }; - ;(function(){try{ +})(USE, './metaCore'); + + ;USE(function(module){try{ /* UI */ if(meta.css){ return } var $m = $('
').attr('id', 'meta'); @@ -235,8 +228,9 @@ tag.innerHTML = tmp; document.body.appendChild(tag); } - }catch(e){}}()); - ;(function(){ + }catch(e){}})(USE, './metaUI'); + + ;USE(function(module){ // include basic text editing by default. var monotype = window.monotype || function(){console.log("monotype needed")}; var m = meta; @@ -256,7 +250,6 @@ return ((tmp = window.getSelection) && tmp().toString()) || ((tmp = document.selection) && tmp.createRange().text) || ''; } - $(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on); m.text.editor = function(opt, as){ var tmp; if(!opt){ return } opt = (typeof opt == 'string')? {edit: opt} : opt.tag? opt : {tag: opt}; @@ -379,5 +372,32 @@ on: function(eve){ meta.text.editor('fontSize', 7) }, up: function(){} }); - }()); + })(USE, './metaText'); + + + ;USE(function(module){ + $(window).on('blur', k.wipe).on('focus', k.wipe); + $(document).on('mousedown mousemove mouseup', function(eve){ + m.tap.eve = eve; + m.tap.x = eve.pageX||0; + m.tap.y = eve.pageY||0; + m.tap.on = $(eve.target); + }).on('mousedown touchstart', function(eve){ + var tmp = m.tap.edit; + if(!tmp || !tmp.on){ return } + tmp.on(eve); + m.tap.edit = null; + }); + $(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true }); + $(document).on('click', '#meta .meta-menu li', function(eve){ + if(m.tap.stun){ return m.tap.stun = false } + if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return } + eve.tap = true; + k.down(eve); + k.up(eve); + }); + $(document).on('keydown', k.down).on('keyup', k.up); + $(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on); + })(USE, './metaEvents'); + }()); \ No newline at end of file diff --git a/package.json b/package.json index 53f7ba31..91333807 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "e2e": "mocha e2e/distributed.js", "docker": "hooks/build", "minify": "uglifyjs gun.js -o gun.min.js -c -m", - "unbuild": "node lib/unbuild.js & npm run minify" + "unbuild": "node lib/unbuild.js & npm run minify", + "unbuildMeta": "node lib/unbuild.js lib/meta" }, "repository": { "type": "git",