From 717d8dc7d9caffcee2a6ac287d0311d5442e2b8b Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 2 May 2020 08:02:18 +0200 Subject: [PATCH] shave some bytes --- scripts/deps-docker/Dockerfile | 20 +- scripts/deps-docker/codemirror.patch | 277 +++++++++++++++++++++++++++ 2 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 scripts/deps-docker/codemirror.patch diff --git a/scripts/deps-docker/Dockerfile b/scripts/deps-docker/Dockerfile index b3f532d0..a9e9bd9f 100644 --- a/scripts/deps-docker/Dockerfile +++ b/scripts/deps-docker/Dockerfile @@ -6,6 +6,7 @@ ENV ver_asmcrypto=2821dd1dedd1196c378f5854037dda5c869313f3 \ ver_marked=1.0.0 \ ver_ogvjs=1.6.1 \ ver_mde=2.10.1 \ + ver_codemirror=5.53.2 \ ver_fontawesome=5.13.0 \ ver_zopfli=1.0.3 @@ -16,6 +17,7 @@ RUN apk add cmake make g++ git bash npm patch wget tar pigz brotli gzip unzi && wget https://github.com/asmcrypto/asmcrypto.js/archive/$ver_asmcrypto.tar.gz -O asmcrypto.tgz \ && wget https://github.com/markedjs/marked/archive/v$ver_marked.tar.gz -O marked.tgz \ && wget https://github.com/Ionaru/easy-markdown-editor/archive/$ver_mde.tar.gz -O mde.tgz \ + && wget https://github.com/codemirror/CodeMirror/archive/$ver_codemirror.tar.gz -O codemirror.tgz \ && wget https://github.com/FortAwesome/Font-Awesome/releases/download/$ver_fontawesome/fontawesome-free-$ver_fontawesome-web.zip -O fontawesome.zip \ && wget https://github.com/google/zopfli/archive/zopfli-$ver_zopfli.tar.gz -O zopfli.tgz \ && unzip ogvjs.zip \ @@ -26,6 +28,9 @@ RUN apk add cmake make g++ git bash npm patch wget tar pigz brotli gzip unzi && cd marked-$ver_marked \ && npm install \ && npm i grunt uglify-js -g ) \ + && (tar -xf codemirror.tgz \ + && cd CodeMirror-$ver_codemirror \ + && npm install ) \ && (tar -xf mde.tgz \ && cd easy-markdown-editor* \ && npm install \ @@ -105,12 +110,22 @@ RUN cd marked-$ver_marked \ # && npm run test \ -# build easymde (TODO man this thing is big) +# build codemirror +COPY codemirror.patch /z/ +RUN cd CodeMirror-$ver_codemirror \ + && patch -p1 < /z/codemirror.patch \ + && sed -ri '/^var urlRE = /d' mode/gfm/gfm.js \ + && npm run build \ + && ln -s $(pwd) /z/nodepkgs/codemirror + + +# build easymde COPY easymde.patch /z/ RUN cd easy-markdown-editor-$ver_mde \ && patch -p1 < /z/easymde.patch \ && sed -ri 's`https://registry.npmjs.org/marked/-/marked-0.8.2.tgz`file:/z/nodepkgs/marked`' package-lock.json \ && sed -ri 's`("marked": ")[^"]+`\1file:/z/nodepkgs/marked`' ./package.json \ + && sed -ri 's`("codemirror": ")[^"]+`\1file:/z/nodepkgs/codemirror`' ./package.json \ && npm install COPY easymde-ln.patch /z/ @@ -211,6 +226,9 @@ RUN cd /z/dist \ # easymde: # 91836 orig # 88635 no spellcheck +# 88392 no urlRE +# 85651 less bidi +# 82855 less mode meta # d=/home/ed/dev/copyparty/scripts/deps-docker/; tar -cf ../x . && ssh root@$bip "cd $d && tar -xv >&2 && make >&2 && tar -cC ../../copyparty/web deps" <../x | (cd ../../copyparty/web/; cat > the.tgz; tar -xvf the.tgz) diff --git a/scripts/deps-docker/codemirror.patch b/scripts/deps-docker/codemirror.patch new file mode 100644 index 00000000..11ab684e --- /dev/null +++ b/scripts/deps-docker/codemirror.patch @@ -0,0 +1,277 @@ +diff -NarU2 CodeMirror-orig/mode/gfm/gfm.js CodeMirror-edit/mode/gfm/gfm.js +--- CodeMirror-orig/mode/gfm/gfm.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/mode/gfm/gfm.js 2020-05-02 02:13:32.142131800 +0200 +@@ -97,5 +97,5 @@ + } + } +- if (stream.match(urlRE) && ++ /*if (stream.match(urlRE) && + stream.string.slice(stream.start - 2, stream.start) != "](" && + (stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) { +@@ -106,5 +106,5 @@ + state.combineTokens = true; + return "link"; +- } ++ }*/ + stream.next(); + return null; +diff -NarU2 CodeMirror-orig/mode/meta.js CodeMirror-edit/mode/meta.js +--- CodeMirror-orig/mode/meta.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/mode/meta.js 2020-05-02 03:56:58.852408400 +0200 +@@ -13,4 +13,5 @@ + + CodeMirror.modeInfo = [ ++ /* + {name: "APL", mime: "text/apl", mode: "apl", ext: ["dyalog", "apl"]}, + {name: "PGP", mimes: ["application/pgp", "application/pgp-encrypted", "application/pgp-keys", "application/pgp-signature"], mode: "asciiarmor", ext: ["asc", "pgp", "sig"]}, +@@ -56,5 +57,7 @@ + {name: "Gas", mime: "text/x-gas", mode: "gas", ext: ["s"]}, + {name: "Gherkin", mime: "text/x-feature", mode: "gherkin", ext: ["feature"]}, ++ */ + {name: "GitHub Flavored Markdown", mime: "text/x-gfm", mode: "gfm", file: /^(readme|contributing|history).md$/i}, ++ /* + {name: "Go", mime: "text/x-go", mode: "go", ext: ["go"]}, + {name: "Groovy", mime: "text/x-groovy", mode: "groovy", ext: ["groovy", "gradle"], file: /^Jenkinsfile$/}, +@@ -65,5 +68,7 @@ + {name: "HXML", mime: "text/x-hxml", mode: "haxe", ext: ["hxml"]}, + {name: "ASP.NET", mime: "application/x-aspx", mode: "htmlembedded", ext: ["aspx"], alias: ["asp", "aspx"]}, ++ */ + {name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm", "handlebars", "hbs"], alias: ["xhtml"]}, ++ /* + {name: "HTTP", mime: "message/http", mode: "http"}, + {name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]}, +@@ -82,5 +87,7 @@ + {name: "LiveScript", mime: "text/x-livescript", mode: "livescript", ext: ["ls"], alias: ["ls"]}, + {name: "Lua", mime: "text/x-lua", mode: "lua", ext: ["lua"]}, ++ */ + {name: "Markdown", mime: "text/x-markdown", mode: "markdown", ext: ["markdown", "md", "mkd"]}, ++ /* + {name: "mIRC", mime: "text/mirc", mode: "mirc"}, + {name: "MariaDB SQL", mime: "text/x-mariadb", mode: "sql"}, +@@ -163,5 +170,7 @@ + {name: "VHDL", mime: "text/x-vhdl", mode: "vhdl", ext: ["vhd", "vhdl"]}, + {name: "Vue.js Component", mimes: ["script/x-vue", "text/x-vue"], mode: "vue", ext: ["vue"]}, ++ */ + {name: "XML", mimes: ["application/xml", "text/xml"], mode: "xml", ext: ["xml", "xsl", "xsd", "svg"], alias: ["rss", "wsdl", "xsd"]}, ++ /* + {name: "XQuery", mime: "application/xquery", mode: "xquery", ext: ["xy", "xquery"]}, + {name: "Yacas", mime: "text/x-yacas", mode: "yacas", ext: ["ys"]}, +@@ -171,4 +180,5 @@ + {name: "xu", mime: "text/x-xu", mode: "mscgen", ext: ["xu"]}, + {name: "msgenny", mime: "text/x-msgenny", mode: "mscgen", ext: ["msgenny"]} ++ */ + ]; + // Ensure all modes have a mime property for backwards compatibility +diff -NarU2 CodeMirror-orig/src/display/selection.js CodeMirror-edit/src/display/selection.js +--- CodeMirror-orig/src/display/selection.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/display/selection.js 2020-05-02 03:27:30.144662800 +0200 +@@ -83,29 +83,21 @@ + let order = getOrder(lineObj, doc.direction) + iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, (from, to, dir, i) => { +- let ltr = dir == "ltr" +- let fromPos = coords(from, ltr ? "left" : "right") +- let toPos = coords(to - 1, ltr ? "right" : "left") ++ let fromPos = coords(from, "left") ++ let toPos = coords(to - 1, "right") + + let openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen + let first = i == 0, last = !order || i == order.length - 1 + if (toPos.top - fromPos.top <= 3) { // Single line +- let openLeft = (docLTR ? openStart : openEnd) && first +- let openRight = (docLTR ? openEnd : openStart) && last +- let left = openLeft ? leftSide : (ltr ? fromPos : toPos).left +- let right = openRight ? rightSide : (ltr ? toPos : fromPos).right ++ let openLeft = openStart && first ++ let openRight = openEnd && last ++ let left = openLeft ? leftSide : fromPos.left ++ let right = openRight ? rightSide : toPos.right + add(left, fromPos.top, right - left, fromPos.bottom) + } else { // Multiple lines + let topLeft, topRight, botLeft, botRight +- if (ltr) { +- topLeft = docLTR && openStart && first ? leftSide : fromPos.left +- topRight = docLTR ? rightSide : wrapX(from, dir, "before") +- botLeft = docLTR ? leftSide : wrapX(to, dir, "after") +- botRight = docLTR && openEnd && last ? rightSide : toPos.right +- } else { +- topLeft = !docLTR ? leftSide : wrapX(from, dir, "before") +- topRight = !docLTR && openStart && first ? rightSide : fromPos.right +- botLeft = !docLTR && openEnd && last ? leftSide : toPos.left +- botRight = !docLTR ? rightSide : wrapX(to, dir, "after") +- } ++ topLeft = openStart && first ? leftSide : fromPos.left ++ topRight = rightSide ++ botLeft = leftSide ++ botRight = openEnd && last ? rightSide : toPos.right + add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom) + if (fromPos.bottom < toPos.top) add(leftSide, fromPos.bottom, null, toPos.top) +diff -NarU2 CodeMirror-orig/src/input/ContentEditableInput.js CodeMirror-edit/src/input/ContentEditableInput.js +--- CodeMirror-orig/src/input/ContentEditableInput.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/input/ContentEditableInput.js 2020-05-02 03:33:05.707995500 +0200 +@@ -391,4 +391,5 @@ + let info = mapFromLineView(view, line, pos.line) + ++ /* + let order = getOrder(line, cm.doc.direction), side = "left" + if (order) { +@@ -396,4 +397,5 @@ + side = partPos % 2 ? "right" : "left" + } ++ */ + let result = nodeAndOffsetInLineMap(info.map, pos.ch, side) + result.offset = result.collapse == "right" ? result.end : result.start +diff -NarU2 CodeMirror-orig/src/input/movement.js CodeMirror-edit/src/input/movement.js +--- CodeMirror-orig/src/input/movement.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/input/movement.js 2020-05-02 03:31:19.710773500 +0200 +@@ -15,4 +15,5 @@ + + export function endOfLine(visually, cm, lineObj, lineNo, dir) { ++ /* + if (visually) { + if (cm.doc.direction == "rtl") dir = -dir +@@ -39,8 +40,11 @@ + } + } ++ */ + return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after") + } + + export function moveVisually(cm, line, start, dir) { ++ return moveLogically(line, start, dir) ++ /* + let bidi = getOrder(line, cm.doc.direction) + if (!bidi) return moveLogically(line, start, dir) +@@ -109,3 +113,4 @@ + // Case 4: Nowhere to move + return null ++ */ + } +diff -NarU2 CodeMirror-orig/src/line/line_data.js CodeMirror-edit/src/line/line_data.js +--- CodeMirror-orig/src/line/line_data.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/line/line_data.js 2020-05-02 03:17:02.785065000 +0200 +@@ -79,6 +79,6 @@ + // Optionally wire in some hacks into the token-rendering + // algorithm, to deal with browser quirks. +- if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) +- builder.addToken = buildTokenBadBidi(builder.addToken, order) ++ //if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) ++ // builder.addToken = buildTokenBadBidi(builder.addToken, order) + builder.map = [] + let allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line) +diff -NarU2 CodeMirror-orig/src/measurement/position_measurement.js CodeMirror-edit/src/measurement/position_measurement.js +--- CodeMirror-orig/src/measurement/position_measurement.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/measurement/position_measurement.js 2020-05-02 03:35:20.674159600 +0200 +@@ -380,5 +380,6 @@ + sticky = "after" + } +- if (!order) return get(sticky == "before" ? ch - 1 : ch, sticky == "before") ++ /*if (!order)*/ return get(sticky == "before" ? ch - 1 : ch, sticky == "before") ++ /* + + function getBidi(ch, partPos, invert) { +@@ -391,4 +392,5 @@ + if (other != null) val.other = getBidi(ch, other, sticky != "before") + return val ++ */ + } + +@@ -468,4 +470,5 @@ + let begin = 0, end = lineObj.text.length, ltr = true + ++ /* + let order = getOrder(lineObj, cm.doc.direction) + // If the line isn't plain left-to-right text, first figure out +@@ -482,4 +485,5 @@ + end = ltr ? part.to : part.from - 1 + } ++ */ + + // A binary search to find the first character whose bounding box +@@ -526,4 +530,5 @@ + } + ++/* + function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) { + // Bidi parts are sorted left-to-right, and in a non-line-wrapping +@@ -580,4 +585,5 @@ + return part + } ++*/ + + let measureText +diff -NarU2 CodeMirror-orig/src/util/bidi.js CodeMirror-edit/src/util/bidi.js +--- CodeMirror-orig/src/util/bidi.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/util/bidi.js 2020-05-02 03:12:44.418649800 +0200 +@@ -4,5 +4,5 @@ + + export function iterateBidiSections(order, from, to, f) { +- if (!order) return f(from, to, "ltr", 0) ++ /*if (!order)*/ return f(from, to, "ltr", 0) /* + let found = false + for (let i = 0; i < order.length; ++i) { +@@ -14,4 +14,5 @@ + } + if (!found) f(from, to, "ltr") ++*/ + } + +@@ -32,5 +33,7 @@ + } + } +- return found != null ? found : bidiOther ++ var ret = found != null ? found : bidiOther ++ console.log("getBidiPartAt(%s,%s,%s) => [%s]", order, ch, sticky, ret) ++ return ret + } + +@@ -55,4 +58,7 @@ + // N (ON): Other Neutrals + ++let bidiOrdering = (function() { return function(str, direction) { return false; }})(); ++/* ++ + // Returns null if characters are ordered as they appear + // (left-to-right), or an array of sections ({from, to, level} +@@ -81,5 +87,5 @@ + } + +- return function(str, direction) { ++ var fun = function(str, direction) { + let outerType = direction == "ltr" ? "L" : "R" + +@@ -204,12 +210,16 @@ + return direction == "rtl" ? order.reverse() : order + } +-})() + ++ return function(str, direction) { ++ var ret = fun(str, direction); ++ console.log("bidiOrdering inner ([%s], %s) => [%s]", str, direction, ret); ++ return ret; ++ } ++})() ++*/ + // Get the bidi ordering for the given line (and cache it). Returns + // false for lines that are fully left-to-right, and an array of + // BidiSpan objects otherwise. + export function getOrder(line, direction) { +- let order = line.order +- if (order == null) order = line.order = bidiOrdering(line.text, direction) +- return order ++ return false; + } +diff -NarU2 CodeMirror-orig/src/util/feature_detection.js CodeMirror-edit/src/util/feature_detection.js +--- CodeMirror-orig/src/util/feature_detection.js 2020-04-21 12:47:20.000000000 +0200 ++++ CodeMirror-edit/src/util/feature_detection.js 2020-05-02 03:16:21.085621400 +0200 +@@ -25,4 +25,5 @@ + } + ++/* + // Feature-detect IE's crummy client rect reporting for bidi text + let badBidiRects +@@ -36,4 +37,5 @@ + return badBidiRects = (r1.right - r0.right < 3) + } ++*/ + + // See if "".split is the broken IE version, if so, provide an