@muze-nl/simplystore 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +8 -0
- package/.github/workflows/docker-build.yml +45 -0
- package/.gitignore~ +1 -0
- package/Dockerfile +60 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/data.jsontag +20 -0
- package/design/access-management.md +25 -0
- package/design/acid.md +31 -0
- package/design/commands.md +25 -0
- package/design/identity.md +71 -0
- package/design/immutability.md +26 -0
- package/design/jsontag-selector.md +365 -0
- package/design/multitasking.md +13 -0
- package/design/thoughts.md +32 -0
- package/docs/docker.md +129 -0
- package/package.json +29 -0
- package/package.json~ +29 -0
- package/src/run.mjs +3 -0
- package/src/server.mjs +323 -0
- package/src/triplestore.mjs +182 -0
- package/www/assets/css/style.css +2296 -0
- package/www/assets/feather-sprite.svg +1 -0
- package/www/assets/img/simplystore-narrow-white.svg +138 -0
- package/www/assets/img/simplystore-narrow.svg +138 -0
- package/www/assets/img/simplystore-white.svg +153 -0
- package/www/assets/img/simplystore.svg +153 -0
- package/www/codemirror/AUTHORS +979 -0
- package/www/codemirror/CHANGELOG.md +2208 -0
- package/www/codemirror/CONTRIBUTING.md +92 -0
- package/www/codemirror/LICENSE +21 -0
- package/www/codemirror/README.md +47 -0
- package/www/codemirror/addon/comment/comment.js +211 -0
- package/www/codemirror/addon/comment/continuecomment.js +114 -0
- package/www/codemirror/addon/dialog/dialog.css +32 -0
- package/www/codemirror/addon/dialog/dialog.js +163 -0
- package/www/codemirror/addon/display/autorefresh.js +47 -0
- package/www/codemirror/addon/display/fullscreen.css +6 -0
- package/www/codemirror/addon/display/fullscreen.js +41 -0
- package/www/codemirror/addon/display/panel.js +133 -0
- package/www/codemirror/addon/display/placeholder.js +78 -0
- package/www/codemirror/addon/display/rulers.js +51 -0
- package/www/codemirror/addon/edit/closebrackets.js +201 -0
- package/www/codemirror/addon/edit/closetag.js +185 -0
- package/www/codemirror/addon/edit/continuelist.js +101 -0
- package/www/codemirror/addon/edit/matchbrackets.js +160 -0
- package/www/codemirror/addon/edit/matchtags.js +66 -0
- package/www/codemirror/addon/edit/trailingspace.js +27 -0
- package/www/codemirror/addon/fold/brace-fold.js +119 -0
- package/www/codemirror/addon/fold/comment-fold.js +59 -0
- package/www/codemirror/addon/fold/foldcode.js +159 -0
- package/www/codemirror/addon/fold/foldgutter.css +20 -0
- package/www/codemirror/addon/fold/foldgutter.js +169 -0
- package/www/codemirror/addon/fold/indent-fold.js +48 -0
- package/www/codemirror/addon/fold/markdown-fold.js +49 -0
- package/www/codemirror/addon/fold/xml-fold.js +184 -0
- package/www/codemirror/addon/hint/anyword-hint.js +41 -0
- package/www/codemirror/addon/hint/css-hint.js +66 -0
- package/www/codemirror/addon/hint/html-hint.js +351 -0
- package/www/codemirror/addon/hint/javascript-hint.js +162 -0
- package/www/codemirror/addon/hint/show-hint.css +37 -0
- package/www/codemirror/addon/hint/show-hint.js +523 -0
- package/www/codemirror/addon/hint/sql-hint.js +304 -0
- package/www/codemirror/addon/hint/xml-hint.js +132 -0
- package/www/codemirror/addon/lint/coffeescript-lint.js +47 -0
- package/www/codemirror/addon/lint/css-lint.js +40 -0
- package/www/codemirror/addon/lint/html-lint.js +59 -0
- package/www/codemirror/addon/lint/javascript-lint.js +65 -0
- package/www/codemirror/addon/lint/json-lint.js +40 -0
- package/www/codemirror/addon/lint/lint.css +79 -0
- package/www/codemirror/addon/lint/lint.js +291 -0
- package/www/codemirror/addon/lint/yaml-lint.js +41 -0
- package/www/codemirror/addon/merge/merge.css +119 -0
- package/www/codemirror/addon/merge/merge.js +1018 -0
- package/www/codemirror/addon/mode/loadmode.js +66 -0
- package/www/codemirror/addon/mode/multiplex.js +136 -0
- package/www/codemirror/addon/mode/multiplex_test.js +49 -0
- package/www/codemirror/addon/mode/overlay.js +90 -0
- package/www/codemirror/addon/mode/simple.js +216 -0
- package/www/codemirror/addon/runmode/colorize.js +40 -0
- package/www/codemirror/addon/runmode/runmode-standalone.js +334 -0
- package/www/codemirror/addon/runmode/runmode.js +76 -0
- package/www/codemirror/addon/runmode/runmode.node.js +329 -0
- package/www/codemirror/addon/scroll/annotatescrollbar.js +128 -0
- package/www/codemirror/addon/scroll/scrollpastend.js +48 -0
- package/www/codemirror/addon/scroll/simplescrollbars.css +66 -0
- package/www/codemirror/addon/scroll/simplescrollbars.js +152 -0
- package/www/codemirror/addon/search/jump-to-line.js +53 -0
- package/www/codemirror/addon/search/match-highlighter.js +167 -0
- package/www/codemirror/addon/search/matchesonscrollbar.css +8 -0
- package/www/codemirror/addon/search/matchesonscrollbar.js +97 -0
- package/www/codemirror/addon/search/search.js +295 -0
- package/www/codemirror/addon/search/searchcursor.js +305 -0
- package/www/codemirror/addon/selection/active-line.js +72 -0
- package/www/codemirror/addon/selection/mark-selection.js +119 -0
- package/www/codemirror/addon/selection/selection-pointer.js +98 -0
- package/www/codemirror/addon/tern/tern.css +87 -0
- package/www/codemirror/addon/tern/tern.js +756 -0
- package/www/codemirror/addon/tern/worker.js +44 -0
- package/www/codemirror/addon/wrap/hardwrap.js +160 -0
- package/www/codemirror/bin/source-highlight +48 -0
- package/www/codemirror/keymap/emacs.js +545 -0
- package/www/codemirror/keymap/sublime.js +720 -0
- package/www/codemirror/keymap/vim.js +5978 -0
- package/www/codemirror/lib/codemirror.css +344 -0
- package/www/codemirror/lib/codemirror.js +9874 -0
- package/www/codemirror/mode/apl/apl.js +174 -0
- package/www/codemirror/mode/asciiarmor/asciiarmor.js +74 -0
- package/www/codemirror/mode/asn.1/asn.1.js +204 -0
- package/www/codemirror/mode/asterisk/asterisk.js +220 -0
- package/www/codemirror/mode/brainfuck/brainfuck.js +85 -0
- package/www/codemirror/mode/clike/clike.js +940 -0
- package/www/codemirror/mode/clojure/clojure.js +292 -0
- package/www/codemirror/mode/cmake/cmake.js +97 -0
- package/www/codemirror/mode/cobol/cobol.js +255 -0
- package/www/codemirror/mode/coffeescript/coffeescript.js +359 -0
- package/www/codemirror/mode/commonlisp/commonlisp.js +125 -0
- package/www/codemirror/mode/crystal/crystal.js +433 -0
- package/www/codemirror/mode/css/css.js +862 -0
- package/www/codemirror/mode/cypher/cypher.js +152 -0
- package/www/codemirror/mode/d/d.js +223 -0
- package/www/codemirror/mode/dart/dart.js +166 -0
- package/www/codemirror/mode/diff/diff.js +47 -0
- package/www/codemirror/mode/django/django.js +356 -0
- package/www/codemirror/mode/dockerfile/dockerfile.js +211 -0
- package/www/codemirror/mode/dtd/dtd.js +142 -0
- package/www/codemirror/mode/dylan/dylan.js +352 -0
- package/www/codemirror/mode/ebnf/ebnf.js +195 -0
- package/www/codemirror/mode/ecl/ecl.js +206 -0
- package/www/codemirror/mode/eiffel/eiffel.js +160 -0
- package/www/codemirror/mode/elm/elm.js +245 -0
- package/www/codemirror/mode/erlang/erlang.js +619 -0
- package/www/codemirror/mode/factor/factor.js +85 -0
- package/www/codemirror/mode/fcl/fcl.js +173 -0
- package/www/codemirror/mode/forth/forth.js +180 -0
- package/www/codemirror/mode/fortran/fortran.js +188 -0
- package/www/codemirror/mode/gas/gas.js +353 -0
- package/www/codemirror/mode/gfm/gfm.js +129 -0
- package/www/codemirror/mode/gherkin/gherkin.js +178 -0
- package/www/codemirror/mode/go/go.js +187 -0
- package/www/codemirror/mode/groovy/groovy.js +247 -0
- package/www/codemirror/mode/haml/haml.js +161 -0
- package/www/codemirror/mode/handlebars/handlebars.js +70 -0
- package/www/codemirror/mode/haskell/haskell.js +268 -0
- package/www/codemirror/mode/haskell-literate/haskell-literate.js +43 -0
- package/www/codemirror/mode/haxe/haxe.js +515 -0
- package/www/codemirror/mode/htmlembedded/htmlembedded.js +37 -0
- package/www/codemirror/mode/htmlmixed/htmlmixed.js +153 -0
- package/www/codemirror/mode/http/http.js +113 -0
- package/www/codemirror/mode/idl/idl.js +290 -0
- package/www/codemirror/mode/javascript/javascript.js +960 -0
- package/www/codemirror/mode/jinja2/jinja2.js +193 -0
- package/www/codemirror/mode/jsx/jsx.js +148 -0
- package/www/codemirror/mode/julia/julia.js +390 -0
- package/www/codemirror/mode/livescript/livescript.js +280 -0
- package/www/codemirror/mode/lua/lua.js +160 -0
- package/www/codemirror/mode/markdown/markdown.js +886 -0
- package/www/codemirror/mode/mathematica/mathematica.js +176 -0
- package/www/codemirror/mode/mbox/mbox.js +129 -0
- package/www/codemirror/mode/meta.js +221 -0
- package/www/codemirror/mode/mirc/mirc.js +193 -0
- package/www/codemirror/mode/mllike/mllike.js +359 -0
- package/www/codemirror/mode/modelica/modelica.js +245 -0
- package/www/codemirror/mode/mscgen/mscgen.js +175 -0
- package/www/codemirror/mode/mumps/mumps.js +148 -0
- package/www/codemirror/mode/nginx/nginx.js +178 -0
- package/www/codemirror/mode/nsis/nsis.js +95 -0
- package/www/codemirror/mode/ntriples/ntriples.js +195 -0
- package/www/codemirror/mode/octave/octave.js +139 -0
- package/www/codemirror/mode/oz/oz.js +252 -0
- package/www/codemirror/mode/pascal/pascal.js +136 -0
- package/www/codemirror/mode/pegjs/pegjs.js +111 -0
- package/www/codemirror/mode/perl/perl.js +836 -0
- package/www/codemirror/mode/php/php.js +234 -0
- package/www/codemirror/mode/pig/pig.js +178 -0
- package/www/codemirror/mode/powershell/powershell.js +398 -0
- package/www/codemirror/mode/properties/properties.js +78 -0
- package/www/codemirror/mode/protobuf/protobuf.js +72 -0
- package/www/codemirror/mode/pug/pug.js +591 -0
- package/www/codemirror/mode/puppet/puppet.js +220 -0
- package/www/codemirror/mode/python/python.js +402 -0
- package/www/codemirror/mode/q/q.js +139 -0
- package/www/codemirror/mode/r/r.js +190 -0
- package/www/codemirror/mode/rpm/changes/index.html +66 -0
- package/www/codemirror/mode/rpm/rpm.js +109 -0
- package/www/codemirror/mode/rst/rst.js +557 -0
- package/www/codemirror/mode/ruby/ruby.js +303 -0
- package/www/codemirror/mode/rust/rust.js +72 -0
- package/www/codemirror/mode/sas/sas.js +303 -0
- package/www/codemirror/mode/sass/sass.js +459 -0
- package/www/codemirror/mode/scheme/scheme.js +284 -0
- package/www/codemirror/mode/shell/shell.js +168 -0
- package/www/codemirror/mode/sieve/sieve.js +193 -0
- package/www/codemirror/mode/slim/slim.js +575 -0
- package/www/codemirror/mode/smalltalk/smalltalk.js +168 -0
- package/www/codemirror/mode/smarty/smarty.js +225 -0
- package/www/codemirror/mode/solr/solr.js +104 -0
- package/www/codemirror/mode/soy/soy.js +665 -0
- package/www/codemirror/mode/sparql/sparql.js +184 -0
- package/www/codemirror/mode/spreadsheet/spreadsheet.js +112 -0
- package/www/codemirror/mode/sql/sql.js +525 -0
- package/www/codemirror/mode/stex/stex.js +264 -0
- package/www/codemirror/mode/stylus/stylus.js +775 -0
- package/www/codemirror/mode/swift/swift.js +221 -0
- package/www/codemirror/mode/tcl/tcl.js +140 -0
- package/www/codemirror/mode/textile/textile.js +469 -0
- package/www/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
- package/www/codemirror/mode/tiddlywiki/tiddlywiki.js +308 -0
- package/www/codemirror/mode/tiki/tiki.css +26 -0
- package/www/codemirror/mode/tiki/tiki.js +312 -0
- package/www/codemirror/mode/toml/toml.js +88 -0
- package/www/codemirror/mode/tornado/tornado.js +68 -0
- package/www/codemirror/mode/troff/troff.js +84 -0
- package/www/codemirror/mode/ttcn/ttcn.js +283 -0
- package/www/codemirror/mode/ttcn-cfg/ttcn-cfg.js +214 -0
- package/www/codemirror/mode/turtle/turtle.js +162 -0
- package/www/codemirror/mode/twig/twig.js +141 -0
- package/www/codemirror/mode/vb/vb.js +275 -0
- package/www/codemirror/mode/vbscript/vbscript.js +350 -0
- package/www/codemirror/mode/velocity/velocity.js +202 -0
- package/www/codemirror/mode/verilog/verilog.js +781 -0
- package/www/codemirror/mode/vhdl/vhdl.js +189 -0
- package/www/codemirror/mode/vue/vue.js +77 -0
- package/www/codemirror/mode/wast/wast.js +132 -0
- package/www/codemirror/mode/webidl/webidl.js +195 -0
- package/www/codemirror/mode/xml/xml.js +417 -0
- package/www/codemirror/mode/xquery/xquery.js +448 -0
- package/www/codemirror/mode/yacas/yacas.js +204 -0
- package/www/codemirror/mode/yaml/yaml.js +120 -0
- package/www/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js +72 -0
- package/www/codemirror/mode/z80/z80.js +116 -0
- package/www/codemirror/package.json +52 -0
- package/www/codemirror/rollup.config.js +52 -0
- package/www/codemirror/src/addon/runmode/codemirror-standalone.js +24 -0
- package/www/codemirror/src/addon/runmode/codemirror.node.js +21 -0
- package/www/codemirror/src/addon/runmode/runmode-standalone.js +2 -0
- package/www/codemirror/src/addon/runmode/runmode.node.js +2 -0
- package/www/codemirror/src/codemirror.js +3 -0
- package/www/codemirror/src/display/Display.js +116 -0
- package/www/codemirror/src/display/focus.js +50 -0
- package/www/codemirror/src/display/gutters.js +44 -0
- package/www/codemirror/src/display/highlight_worker.js +55 -0
- package/www/codemirror/src/display/line_numbers.js +48 -0
- package/www/codemirror/src/display/mode_state.js +22 -0
- package/www/codemirror/src/display/operations.js +206 -0
- package/www/codemirror/src/display/scroll_events.js +132 -0
- package/www/codemirror/src/display/scrollbars.js +194 -0
- package/www/codemirror/src/display/scrolling.js +186 -0
- package/www/codemirror/src/display/selection.js +173 -0
- package/www/codemirror/src/display/update_display.js +267 -0
- package/www/codemirror/src/display/update_line.js +189 -0
- package/www/codemirror/src/display/update_lines.js +82 -0
- package/www/codemirror/src/display/view_tracking.js +153 -0
- package/www/codemirror/src/edit/CodeMirror.js +217 -0
- package/www/codemirror/src/edit/commands.js +178 -0
- package/www/codemirror/src/edit/deleteNearSelection.js +30 -0
- package/www/codemirror/src/edit/drop_events.js +130 -0
- package/www/codemirror/src/edit/fromTextArea.js +61 -0
- package/www/codemirror/src/edit/global_events.js +45 -0
- package/www/codemirror/src/edit/key_events.js +163 -0
- package/www/codemirror/src/edit/legacy.js +62 -0
- package/www/codemirror/src/edit/main.js +69 -0
- package/www/codemirror/src/edit/methods.js +555 -0
- package/www/codemirror/src/edit/mouse_events.js +417 -0
- package/www/codemirror/src/edit/options.js +194 -0
- package/www/codemirror/src/edit/utils.js +7 -0
- package/www/codemirror/src/input/ContentEditableInput.js +546 -0
- package/www/codemirror/src/input/TextareaInput.js +380 -0
- package/www/codemirror/src/input/indent.js +71 -0
- package/www/codemirror/src/input/input.js +134 -0
- package/www/codemirror/src/input/keymap.js +147 -0
- package/www/codemirror/src/input/keynames.js +17 -0
- package/www/codemirror/src/input/movement.js +111 -0
- package/www/codemirror/src/line/highlight.js +284 -0
- package/www/codemirror/src/line/line_data.js +349 -0
- package/www/codemirror/src/line/pos.js +40 -0
- package/www/codemirror/src/line/saw_special_spans.js +10 -0
- package/www/codemirror/src/line/spans.js +390 -0
- package/www/codemirror/src/line/utils_line.js +85 -0
- package/www/codemirror/src/measurement/position_measurement.js +702 -0
- package/www/codemirror/src/measurement/widgets.js +26 -0
- package/www/codemirror/src/model/Doc.js +436 -0
- package/www/codemirror/src/model/change_measurement.js +61 -0
- package/www/codemirror/src/model/changes.js +339 -0
- package/www/codemirror/src/model/chunk.js +167 -0
- package/www/codemirror/src/model/document_data.js +112 -0
- package/www/codemirror/src/model/history.js +228 -0
- package/www/codemirror/src/model/line_widget.js +78 -0
- package/www/codemirror/src/model/mark_text.js +293 -0
- package/www/codemirror/src/model/selection.js +84 -0
- package/www/codemirror/src/model/selection_updates.js +216 -0
- package/www/codemirror/src/modes.js +96 -0
- package/www/codemirror/src/util/StringStream.js +90 -0
- package/www/codemirror/src/util/bidi.js +215 -0
- package/www/codemirror/src/util/browser.js +34 -0
- package/www/codemirror/src/util/dom.js +101 -0
- package/www/codemirror/src/util/event.js +103 -0
- package/www/codemirror/src/util/feature_detection.js +84 -0
- package/www/codemirror/src/util/misc.js +168 -0
- package/www/codemirror/src/util/operation_group.js +72 -0
- package/www/codemirror/theme/3024-day.css +41 -0
- package/www/codemirror/theme/3024-night.css +39 -0
- package/www/codemirror/theme/abbott.css +268 -0
- package/www/codemirror/theme/abcdef.css +32 -0
- package/www/codemirror/theme/ambiance-mobile.css +5 -0
- package/www/codemirror/theme/ambiance.css +74 -0
- package/www/codemirror/theme/ayu-dark.css +44 -0
- package/www/codemirror/theme/ayu-mirage.css +45 -0
- package/www/codemirror/theme/base16-dark.css +40 -0
- package/www/codemirror/theme/base16-light.css +38 -0
- package/www/codemirror/theme/bespin.css +34 -0
- package/www/codemirror/theme/blackboard.css +32 -0
- package/www/codemirror/theme/cobalt.css +25 -0
- package/www/codemirror/theme/colorforth.css +33 -0
- package/www/codemirror/theme/darcula.css +53 -0
- package/www/codemirror/theme/dracula.css +40 -0
- package/www/codemirror/theme/duotone-dark.css +35 -0
- package/www/codemirror/theme/duotone-light.css +36 -0
- package/www/codemirror/theme/eclipse.css +23 -0
- package/www/codemirror/theme/elegant.css +13 -0
- package/www/codemirror/theme/erlang-dark.css +34 -0
- package/www/codemirror/theme/gruvbox-dark.css +39 -0
- package/www/codemirror/theme/hopscotch.css +34 -0
- package/www/codemirror/theme/icecoder.css +43 -0
- package/www/codemirror/theme/idea.css +42 -0
- package/www/codemirror/theme/isotope.css +34 -0
- package/www/codemirror/theme/juejin.css +30 -0
- package/www/codemirror/theme/lesser-dark.css +47 -0
- package/www/codemirror/theme/liquibyte.css +95 -0
- package/www/codemirror/theme/lucario.css +37 -0
- package/www/codemirror/theme/material-darker.css +135 -0
- package/www/codemirror/theme/material-ocean.css +141 -0
- package/www/codemirror/theme/material-palenight.css +141 -0
- package/www/codemirror/theme/material.css +141 -0
- package/www/codemirror/theme/mbo.css +37 -0
- package/www/codemirror/theme/mdn-like.css +46 -0
- package/www/codemirror/theme/midnight.css +39 -0
- package/www/codemirror/theme/monokai.css +41 -0
- package/www/codemirror/theme/moxer.css +143 -0
- package/www/codemirror/theme/neat.css +12 -0
- package/www/codemirror/theme/neo.css +43 -0
- package/www/codemirror/theme/night.css +27 -0
- package/www/codemirror/theme/nord.css +42 -0
- package/www/codemirror/theme/oceanic-next.css +46 -0
- package/www/codemirror/theme/panda-syntax.css +85 -0
- package/www/codemirror/theme/paraiso-dark.css +38 -0
- package/www/codemirror/theme/paraiso-light.css +38 -0
- package/www/codemirror/theme/pastel-on-dark.css +52 -0
- package/www/codemirror/theme/railscasts.css +34 -0
- package/www/codemirror/theme/rubyblue.css +25 -0
- package/www/codemirror/theme/seti.css +44 -0
- package/www/codemirror/theme/shadowfox.css +52 -0
- package/www/codemirror/theme/solarized.css +165 -0
- package/www/codemirror/theme/ssms.css +16 -0
- package/www/codemirror/theme/the-matrix.css +30 -0
- package/www/codemirror/theme/tomorrow-night-bright.css +35 -0
- package/www/codemirror/theme/tomorrow-night-eighties.css +38 -0
- package/www/codemirror/theme/ttcn.css +64 -0
- package/www/codemirror/theme/twilight.css +32 -0
- package/www/codemirror/theme/vibrant-ink.css +34 -0
- package/www/codemirror/theme/xq-dark.css +53 -0
- package/www/codemirror/theme/xq-light.css +43 -0
- package/www/codemirror/theme/yeti.css +44 -0
- package/www/codemirror/theme/yonce.css +59 -0
- package/www/codemirror/theme/zenburn.css +37 -0
- package/www/index.html +216 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { signalLater } from "../util/operation_group.js"
|
|
2
|
+
import { ensureCursorVisible } from "../display/scrolling.js"
|
|
3
|
+
import { clipPos, cmp, Pos } from "../line/pos.js"
|
|
4
|
+
import { getLine } from "../line/utils_line.js"
|
|
5
|
+
import { hasHandler, signal, signalCursorActivity } from "../util/event.js"
|
|
6
|
+
import { lst, sel_dontScroll } from "../util/misc.js"
|
|
7
|
+
|
|
8
|
+
import { addSelectionToHistory } from "./history.js"
|
|
9
|
+
import { normalizeSelection, Range, Selection, simpleSelection } from "./selection.js"
|
|
10
|
+
|
|
11
|
+
// The 'scroll' parameter given to many of these indicated whether
|
|
12
|
+
// the new cursor position should be scrolled into view after
|
|
13
|
+
// modifying the selection.
|
|
14
|
+
|
|
15
|
+
// If shift is held or the extend flag is set, extends a range to
|
|
16
|
+
// include a given position (and optionally a second position).
|
|
17
|
+
// Otherwise, simply returns the range between the given positions.
|
|
18
|
+
// Used for cursor motion and such.
|
|
19
|
+
export function extendRange(range, head, other, extend) {
|
|
20
|
+
if (extend) {
|
|
21
|
+
let anchor = range.anchor
|
|
22
|
+
if (other) {
|
|
23
|
+
let posBefore = cmp(head, anchor) < 0
|
|
24
|
+
if (posBefore != (cmp(other, anchor) < 0)) {
|
|
25
|
+
anchor = head
|
|
26
|
+
head = other
|
|
27
|
+
} else if (posBefore != (cmp(head, other) < 0)) {
|
|
28
|
+
head = other
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return new Range(anchor, head)
|
|
32
|
+
} else {
|
|
33
|
+
return new Range(other || head, head)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Extend the primary selection range, discard the rest.
|
|
38
|
+
export function extendSelection(doc, head, other, options, extend) {
|
|
39
|
+
if (extend == null) extend = doc.cm && (doc.cm.display.shift || doc.extend)
|
|
40
|
+
setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Extend all selections (pos is an array of selections with length
|
|
44
|
+
// equal the number of selections)
|
|
45
|
+
export function extendSelections(doc, heads, options) {
|
|
46
|
+
let out = []
|
|
47
|
+
let extend = doc.cm && (doc.cm.display.shift || doc.extend)
|
|
48
|
+
for (let i = 0; i < doc.sel.ranges.length; i++)
|
|
49
|
+
out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend)
|
|
50
|
+
let newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex)
|
|
51
|
+
setSelection(doc, newSel, options)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Updates a single range in the selection.
|
|
55
|
+
export function replaceOneSelection(doc, i, range, options) {
|
|
56
|
+
let ranges = doc.sel.ranges.slice(0)
|
|
57
|
+
ranges[i] = range
|
|
58
|
+
setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Reset the selection to a single range.
|
|
62
|
+
export function setSimpleSelection(doc, anchor, head, options) {
|
|
63
|
+
setSelection(doc, simpleSelection(anchor, head), options)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Give beforeSelectionChange handlers a change to influence a
|
|
67
|
+
// selection update.
|
|
68
|
+
function filterSelectionChange(doc, sel, options) {
|
|
69
|
+
let obj = {
|
|
70
|
+
ranges: sel.ranges,
|
|
71
|
+
update: function(ranges) {
|
|
72
|
+
this.ranges = []
|
|
73
|
+
for (let i = 0; i < ranges.length; i++)
|
|
74
|
+
this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
|
|
75
|
+
clipPos(doc, ranges[i].head))
|
|
76
|
+
},
|
|
77
|
+
origin: options && options.origin
|
|
78
|
+
}
|
|
79
|
+
signal(doc, "beforeSelectionChange", doc, obj)
|
|
80
|
+
if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj)
|
|
81
|
+
if (obj.ranges != sel.ranges) return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1)
|
|
82
|
+
else return sel
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function setSelectionReplaceHistory(doc, sel, options) {
|
|
86
|
+
let done = doc.history.done, last = lst(done)
|
|
87
|
+
if (last && last.ranges) {
|
|
88
|
+
done[done.length - 1] = sel
|
|
89
|
+
setSelectionNoUndo(doc, sel, options)
|
|
90
|
+
} else {
|
|
91
|
+
setSelection(doc, sel, options)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Set a new selection.
|
|
96
|
+
export function setSelection(doc, sel, options) {
|
|
97
|
+
setSelectionNoUndo(doc, sel, options)
|
|
98
|
+
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function setSelectionNoUndo(doc, sel, options) {
|
|
102
|
+
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
|
|
103
|
+
sel = filterSelectionChange(doc, sel, options)
|
|
104
|
+
|
|
105
|
+
let bias = options && options.bias ||
|
|
106
|
+
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1)
|
|
107
|
+
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true))
|
|
108
|
+
|
|
109
|
+
if (!(options && options.scroll === false) && doc.cm && doc.cm.getOption("readOnly") != "nocursor")
|
|
110
|
+
ensureCursorVisible(doc.cm)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setSelectionInner(doc, sel) {
|
|
114
|
+
if (sel.equals(doc.sel)) return
|
|
115
|
+
|
|
116
|
+
doc.sel = sel
|
|
117
|
+
|
|
118
|
+
if (doc.cm) {
|
|
119
|
+
doc.cm.curOp.updateInput = 1
|
|
120
|
+
doc.cm.curOp.selectionChanged = true
|
|
121
|
+
signalCursorActivity(doc.cm)
|
|
122
|
+
}
|
|
123
|
+
signalLater(doc, "cursorActivity", doc)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Verify that the selection does not partially select any atomic
|
|
127
|
+
// marked ranges.
|
|
128
|
+
export function reCheckSelection(doc) {
|
|
129
|
+
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Return a selection that does not partially select any atomic
|
|
133
|
+
// ranges.
|
|
134
|
+
function skipAtomicInSelection(doc, sel, bias, mayClear) {
|
|
135
|
+
let out
|
|
136
|
+
for (let i = 0; i < sel.ranges.length; i++) {
|
|
137
|
+
let range = sel.ranges[i]
|
|
138
|
+
let old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
|
|
139
|
+
let newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
|
|
140
|
+
let newHead = range.head == range.anchor ? newAnchor : skipAtomic(doc, range.head, old && old.head, bias, mayClear)
|
|
141
|
+
if (out || newAnchor != range.anchor || newHead != range.head) {
|
|
142
|
+
if (!out) out = sel.ranges.slice(0, i)
|
|
143
|
+
out[i] = new Range(newAnchor, newHead)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
|
|
150
|
+
let line = getLine(doc, pos.line)
|
|
151
|
+
if (line.markedSpans) for (let i = 0; i < line.markedSpans.length; ++i) {
|
|
152
|
+
let sp = line.markedSpans[i], m = sp.marker
|
|
153
|
+
|
|
154
|
+
// Determine if we should prevent the cursor being placed to the left/right of an atomic marker
|
|
155
|
+
// Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
|
|
156
|
+
// is with selectLeft/Right
|
|
157
|
+
let preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft
|
|
158
|
+
let preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight
|
|
159
|
+
|
|
160
|
+
if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
|
|
161
|
+
(sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
|
|
162
|
+
if (mayClear) {
|
|
163
|
+
signal(m, "beforeCursorEnter")
|
|
164
|
+
if (m.explicitlyCleared) {
|
|
165
|
+
if (!line.markedSpans) break
|
|
166
|
+
else {--i; continue}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (!m.atomic) continue
|
|
170
|
+
|
|
171
|
+
if (oldPos) {
|
|
172
|
+
let near = m.find(dir < 0 ? 1 : -1), diff
|
|
173
|
+
if (dir < 0 ? preventCursorRight : preventCursorLeft)
|
|
174
|
+
near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null)
|
|
175
|
+
if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
|
|
176
|
+
return skipAtomicInner(doc, near, pos, dir, mayClear)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let far = m.find(dir < 0 ? -1 : 1)
|
|
180
|
+
if (dir < 0 ? preventCursorLeft : preventCursorRight)
|
|
181
|
+
far = movePos(doc, far, dir, far.line == pos.line ? line : null)
|
|
182
|
+
return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return pos
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Ensure a given position is not inside an atomic range.
|
|
189
|
+
export function skipAtomic(doc, pos, oldPos, bias, mayClear) {
|
|
190
|
+
let dir = bias || 1
|
|
191
|
+
let found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
|
|
192
|
+
(!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
|
|
193
|
+
skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
|
|
194
|
+
(!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true))
|
|
195
|
+
if (!found) {
|
|
196
|
+
doc.cantEdit = true
|
|
197
|
+
return Pos(doc.first, 0)
|
|
198
|
+
}
|
|
199
|
+
return found
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function movePos(doc, pos, dir, line) {
|
|
203
|
+
if (dir < 0 && pos.ch == 0) {
|
|
204
|
+
if (pos.line > doc.first) return clipPos(doc, Pos(pos.line - 1))
|
|
205
|
+
else return null
|
|
206
|
+
} else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
|
|
207
|
+
if (pos.line < doc.first + doc.size - 1) return Pos(pos.line + 1, 0)
|
|
208
|
+
else return null
|
|
209
|
+
} else {
|
|
210
|
+
return new Pos(pos.line, pos.ch + dir)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function selectAll(cm) {
|
|
215
|
+
cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll)
|
|
216
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { copyObj, createObj } from "./util/misc.js"
|
|
2
|
+
|
|
3
|
+
// Known modes, by name and by MIME
|
|
4
|
+
export let modes = {}, mimeModes = {}
|
|
5
|
+
|
|
6
|
+
// Extra arguments are stored as the mode's dependencies, which is
|
|
7
|
+
// used by (legacy) mechanisms like loadmode.js to automatically
|
|
8
|
+
// load a mode. (Preferred mechanism is the require/define calls.)
|
|
9
|
+
export function defineMode(name, mode) {
|
|
10
|
+
if (arguments.length > 2)
|
|
11
|
+
mode.dependencies = Array.prototype.slice.call(arguments, 2)
|
|
12
|
+
modes[name] = mode
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function defineMIME(mime, spec) {
|
|
16
|
+
mimeModes[mime] = spec
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Given a MIME type, a {name, ...options} config object, or a name
|
|
20
|
+
// string, return a mode config object.
|
|
21
|
+
export function resolveMode(spec) {
|
|
22
|
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
|
23
|
+
spec = mimeModes[spec]
|
|
24
|
+
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
|
25
|
+
let found = mimeModes[spec.name]
|
|
26
|
+
if (typeof found == "string") found = {name: found}
|
|
27
|
+
spec = createObj(found, spec)
|
|
28
|
+
spec.name = found.name
|
|
29
|
+
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
|
30
|
+
return resolveMode("application/xml")
|
|
31
|
+
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
|
|
32
|
+
return resolveMode("application/json")
|
|
33
|
+
}
|
|
34
|
+
if (typeof spec == "string") return {name: spec}
|
|
35
|
+
else return spec || {name: "null"}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Given a mode spec (anything that resolveMode accepts), find and
|
|
39
|
+
// initialize an actual mode object.
|
|
40
|
+
export function getMode(options, spec) {
|
|
41
|
+
spec = resolveMode(spec)
|
|
42
|
+
let mfactory = modes[spec.name]
|
|
43
|
+
if (!mfactory) return getMode(options, "text/plain")
|
|
44
|
+
let modeObj = mfactory(options, spec)
|
|
45
|
+
if (modeExtensions.hasOwnProperty(spec.name)) {
|
|
46
|
+
let exts = modeExtensions[spec.name]
|
|
47
|
+
for (let prop in exts) {
|
|
48
|
+
if (!exts.hasOwnProperty(prop)) continue
|
|
49
|
+
if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop]
|
|
50
|
+
modeObj[prop] = exts[prop]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
modeObj.name = spec.name
|
|
54
|
+
if (spec.helperType) modeObj.helperType = spec.helperType
|
|
55
|
+
if (spec.modeProps) for (let prop in spec.modeProps)
|
|
56
|
+
modeObj[prop] = spec.modeProps[prop]
|
|
57
|
+
|
|
58
|
+
return modeObj
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// This can be used to attach properties to mode objects from
|
|
62
|
+
// outside the actual mode definition.
|
|
63
|
+
export let modeExtensions = {}
|
|
64
|
+
export function extendMode(mode, properties) {
|
|
65
|
+
let exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {})
|
|
66
|
+
copyObj(properties, exts)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function copyState(mode, state) {
|
|
70
|
+
if (state === true) return state
|
|
71
|
+
if (mode.copyState) return mode.copyState(state)
|
|
72
|
+
let nstate = {}
|
|
73
|
+
for (let n in state) {
|
|
74
|
+
let val = state[n]
|
|
75
|
+
if (val instanceof Array) val = val.concat([])
|
|
76
|
+
nstate[n] = val
|
|
77
|
+
}
|
|
78
|
+
return nstate
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Given a mode and a state (for that mode), find the inner mode and
|
|
82
|
+
// state at the position that the state refers to.
|
|
83
|
+
export function innerMode(mode, state) {
|
|
84
|
+
let info
|
|
85
|
+
while (mode.innerMode) {
|
|
86
|
+
info = mode.innerMode(state)
|
|
87
|
+
if (!info || info.mode == mode) break
|
|
88
|
+
state = info.state
|
|
89
|
+
mode = info.mode
|
|
90
|
+
}
|
|
91
|
+
return info || {mode: mode, state: state}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function startState(mode, a1, a2) {
|
|
95
|
+
return mode.startState ? mode.startState(a1, a2) : true
|
|
96
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { countColumn } from "./misc.js"
|
|
2
|
+
|
|
3
|
+
// STRING STREAM
|
|
4
|
+
|
|
5
|
+
// Fed to the mode parsers, provides helper functions to make
|
|
6
|
+
// parsers more succinct.
|
|
7
|
+
|
|
8
|
+
class StringStream {
|
|
9
|
+
constructor(string, tabSize, lineOracle) {
|
|
10
|
+
this.pos = this.start = 0
|
|
11
|
+
this.string = string
|
|
12
|
+
this.tabSize = tabSize || 8
|
|
13
|
+
this.lastColumnPos = this.lastColumnValue = 0
|
|
14
|
+
this.lineStart = 0
|
|
15
|
+
this.lineOracle = lineOracle
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
eol() {return this.pos >= this.string.length}
|
|
19
|
+
sol() {return this.pos == this.lineStart}
|
|
20
|
+
peek() {return this.string.charAt(this.pos) || undefined}
|
|
21
|
+
next() {
|
|
22
|
+
if (this.pos < this.string.length)
|
|
23
|
+
return this.string.charAt(this.pos++)
|
|
24
|
+
}
|
|
25
|
+
eat(match) {
|
|
26
|
+
let ch = this.string.charAt(this.pos)
|
|
27
|
+
let ok
|
|
28
|
+
if (typeof match == "string") ok = ch == match
|
|
29
|
+
else ok = ch && (match.test ? match.test(ch) : match(ch))
|
|
30
|
+
if (ok) {++this.pos; return ch}
|
|
31
|
+
}
|
|
32
|
+
eatWhile(match) {
|
|
33
|
+
let start = this.pos
|
|
34
|
+
while (this.eat(match)){}
|
|
35
|
+
return this.pos > start
|
|
36
|
+
}
|
|
37
|
+
eatSpace() {
|
|
38
|
+
let start = this.pos
|
|
39
|
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos
|
|
40
|
+
return this.pos > start
|
|
41
|
+
}
|
|
42
|
+
skipToEnd() {this.pos = this.string.length}
|
|
43
|
+
skipTo(ch) {
|
|
44
|
+
let found = this.string.indexOf(ch, this.pos)
|
|
45
|
+
if (found > -1) {this.pos = found; return true}
|
|
46
|
+
}
|
|
47
|
+
backUp(n) {this.pos -= n}
|
|
48
|
+
column() {
|
|
49
|
+
if (this.lastColumnPos < this.start) {
|
|
50
|
+
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue)
|
|
51
|
+
this.lastColumnPos = this.start
|
|
52
|
+
}
|
|
53
|
+
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
|
|
54
|
+
}
|
|
55
|
+
indentation() {
|
|
56
|
+
return countColumn(this.string, null, this.tabSize) -
|
|
57
|
+
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
|
|
58
|
+
}
|
|
59
|
+
match(pattern, consume, caseInsensitive) {
|
|
60
|
+
if (typeof pattern == "string") {
|
|
61
|
+
let cased = str => caseInsensitive ? str.toLowerCase() : str
|
|
62
|
+
let substr = this.string.substr(this.pos, pattern.length)
|
|
63
|
+
if (cased(substr) == cased(pattern)) {
|
|
64
|
+
if (consume !== false) this.pos += pattern.length
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
let match = this.string.slice(this.pos).match(pattern)
|
|
69
|
+
if (match && match.index > 0) return null
|
|
70
|
+
if (match && consume !== false) this.pos += match[0].length
|
|
71
|
+
return match
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
current(){return this.string.slice(this.start, this.pos)}
|
|
75
|
+
hideFirstChars(n, inner) {
|
|
76
|
+
this.lineStart += n
|
|
77
|
+
try { return inner() }
|
|
78
|
+
finally { this.lineStart -= n }
|
|
79
|
+
}
|
|
80
|
+
lookAhead(n) {
|
|
81
|
+
let oracle = this.lineOracle
|
|
82
|
+
return oracle && oracle.lookAhead(n)
|
|
83
|
+
}
|
|
84
|
+
baseToken() {
|
|
85
|
+
let oracle = this.lineOracle
|
|
86
|
+
return oracle && oracle.baseToken(this.pos)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default StringStream
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { lst } from "./misc.js"
|
|
2
|
+
|
|
3
|
+
// BIDI HELPERS
|
|
4
|
+
|
|
5
|
+
export function iterateBidiSections(order, from, to, f) {
|
|
6
|
+
if (!order) return f(from, to, "ltr", 0)
|
|
7
|
+
let found = false
|
|
8
|
+
for (let i = 0; i < order.length; ++i) {
|
|
9
|
+
let part = order[i]
|
|
10
|
+
if (part.from < to && part.to > from || from == to && part.to == from) {
|
|
11
|
+
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i)
|
|
12
|
+
found = true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (!found) f(from, to, "ltr")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export let bidiOther = null
|
|
19
|
+
export function getBidiPartAt(order, ch, sticky) {
|
|
20
|
+
let found
|
|
21
|
+
bidiOther = null
|
|
22
|
+
for (let i = 0; i < order.length; ++i) {
|
|
23
|
+
let cur = order[i]
|
|
24
|
+
if (cur.from < ch && cur.to > ch) return i
|
|
25
|
+
if (cur.to == ch) {
|
|
26
|
+
if (cur.from != cur.to && sticky == "before") found = i
|
|
27
|
+
else bidiOther = i
|
|
28
|
+
}
|
|
29
|
+
if (cur.from == ch) {
|
|
30
|
+
if (cur.from != cur.to && sticky != "before") found = i
|
|
31
|
+
else bidiOther = i
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return found != null ? found : bidiOther
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Bidirectional ordering algorithm
|
|
38
|
+
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
|
|
39
|
+
// that this (partially) implements.
|
|
40
|
+
|
|
41
|
+
// One-char codes used for character types:
|
|
42
|
+
// L (L): Left-to-Right
|
|
43
|
+
// R (R): Right-to-Left
|
|
44
|
+
// r (AL): Right-to-Left Arabic
|
|
45
|
+
// 1 (EN): European Number
|
|
46
|
+
// + (ES): European Number Separator
|
|
47
|
+
// % (ET): European Number Terminator
|
|
48
|
+
// n (AN): Arabic Number
|
|
49
|
+
// , (CS): Common Number Separator
|
|
50
|
+
// m (NSM): Non-Spacing Mark
|
|
51
|
+
// b (BN): Boundary Neutral
|
|
52
|
+
// s (B): Paragraph Separator
|
|
53
|
+
// t (S): Segment Separator
|
|
54
|
+
// w (WS): Whitespace
|
|
55
|
+
// N (ON): Other Neutrals
|
|
56
|
+
|
|
57
|
+
// Returns null if characters are ordered as they appear
|
|
58
|
+
// (left-to-right), or an array of sections ({from, to, level}
|
|
59
|
+
// objects) in the order in which they occur visually.
|
|
60
|
+
let bidiOrdering = (function() {
|
|
61
|
+
// Character types for codepoints 0 to 0xff
|
|
62
|
+
let lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
|
|
63
|
+
// Character types for codepoints 0x600 to 0x6f9
|
|
64
|
+
let arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"
|
|
65
|
+
function charType(code) {
|
|
66
|
+
if (code <= 0xf7) return lowTypes.charAt(code)
|
|
67
|
+
else if (0x590 <= code && code <= 0x5f4) return "R"
|
|
68
|
+
else if (0x600 <= code && code <= 0x6f9) return arabicTypes.charAt(code - 0x600)
|
|
69
|
+
else if (0x6ee <= code && code <= 0x8ac) return "r"
|
|
70
|
+
else if (0x2000 <= code && code <= 0x200b) return "w"
|
|
71
|
+
else if (code == 0x200c) return "b"
|
|
72
|
+
else return "L"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
|
|
76
|
+
let isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/
|
|
77
|
+
|
|
78
|
+
function BidiSpan(level, from, to) {
|
|
79
|
+
this.level = level
|
|
80
|
+
this.from = from; this.to = to
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return function(str, direction) {
|
|
84
|
+
let outerType = direction == "ltr" ? "L" : "R"
|
|
85
|
+
|
|
86
|
+
if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) return false
|
|
87
|
+
let len = str.length, types = []
|
|
88
|
+
for (let i = 0; i < len; ++i)
|
|
89
|
+
types.push(charType(str.charCodeAt(i)))
|
|
90
|
+
|
|
91
|
+
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
|
92
|
+
// change the type of the NSM to the type of the previous
|
|
93
|
+
// character. If the NSM is at the start of the level run, it will
|
|
94
|
+
// get the type of sor.
|
|
95
|
+
for (let i = 0, prev = outerType; i < len; ++i) {
|
|
96
|
+
let type = types[i]
|
|
97
|
+
if (type == "m") types[i] = prev
|
|
98
|
+
else prev = type
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// W2. Search backwards from each instance of a European number
|
|
102
|
+
// until the first strong type (R, L, AL, or sor) is found. If an
|
|
103
|
+
// AL is found, change the type of the European number to Arabic
|
|
104
|
+
// number.
|
|
105
|
+
// W3. Change all ALs to R.
|
|
106
|
+
for (let i = 0, cur = outerType; i < len; ++i) {
|
|
107
|
+
let type = types[i]
|
|
108
|
+
if (type == "1" && cur == "r") types[i] = "n"
|
|
109
|
+
else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R" }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// W4. A single European separator between two European numbers
|
|
113
|
+
// changes to a European number. A single common separator between
|
|
114
|
+
// two numbers of the same type changes to that type.
|
|
115
|
+
for (let i = 1, prev = types[0]; i < len - 1; ++i) {
|
|
116
|
+
let type = types[i]
|
|
117
|
+
if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1"
|
|
118
|
+
else if (type == "," && prev == types[i+1] &&
|
|
119
|
+
(prev == "1" || prev == "n")) types[i] = prev
|
|
120
|
+
prev = type
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// W5. A sequence of European terminators adjacent to European
|
|
124
|
+
// numbers changes to all European numbers.
|
|
125
|
+
// W6. Otherwise, separators and terminators change to Other
|
|
126
|
+
// Neutral.
|
|
127
|
+
for (let i = 0; i < len; ++i) {
|
|
128
|
+
let type = types[i]
|
|
129
|
+
if (type == ",") types[i] = "N"
|
|
130
|
+
else if (type == "%") {
|
|
131
|
+
let end
|
|
132
|
+
for (end = i + 1; end < len && types[end] == "%"; ++end) {}
|
|
133
|
+
let replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"
|
|
134
|
+
for (let j = i; j < end; ++j) types[j] = replace
|
|
135
|
+
i = end - 1
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// W7. Search backwards from each instance of a European number
|
|
140
|
+
// until the first strong type (R, L, or sor) is found. If an L is
|
|
141
|
+
// found, then change the type of the European number to L.
|
|
142
|
+
for (let i = 0, cur = outerType; i < len; ++i) {
|
|
143
|
+
let type = types[i]
|
|
144
|
+
if (cur == "L" && type == "1") types[i] = "L"
|
|
145
|
+
else if (isStrong.test(type)) cur = type
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// N1. A sequence of neutrals takes the direction of the
|
|
149
|
+
// surrounding strong text if the text on both sides has the same
|
|
150
|
+
// direction. European and Arabic numbers act as if they were R in
|
|
151
|
+
// terms of their influence on neutrals. Start-of-level-run (sor)
|
|
152
|
+
// and end-of-level-run (eor) are used at level run boundaries.
|
|
153
|
+
// N2. Any remaining neutrals take the embedding direction.
|
|
154
|
+
for (let i = 0; i < len; ++i) {
|
|
155
|
+
if (isNeutral.test(types[i])) {
|
|
156
|
+
let end
|
|
157
|
+
for (end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
|
|
158
|
+
let before = (i ? types[i-1] : outerType) == "L"
|
|
159
|
+
let after = (end < len ? types[end] : outerType) == "L"
|
|
160
|
+
let replace = before == after ? (before ? "L" : "R") : outerType
|
|
161
|
+
for (let j = i; j < end; ++j) types[j] = replace
|
|
162
|
+
i = end - 1
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Here we depart from the documented algorithm, in order to avoid
|
|
167
|
+
// building up an actual levels array. Since there are only three
|
|
168
|
+
// levels (0, 1, 2) in an implementation that doesn't take
|
|
169
|
+
// explicit embedding into account, we can build up the order on
|
|
170
|
+
// the fly, without following the level-based algorithm.
|
|
171
|
+
let order = [], m
|
|
172
|
+
for (let i = 0; i < len;) {
|
|
173
|
+
if (countsAsLeft.test(types[i])) {
|
|
174
|
+
let start = i
|
|
175
|
+
for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
|
|
176
|
+
order.push(new BidiSpan(0, start, i))
|
|
177
|
+
} else {
|
|
178
|
+
let pos = i, at = order.length, isRTL = direction == "rtl" ? 1 : 0
|
|
179
|
+
for (++i; i < len && types[i] != "L"; ++i) {}
|
|
180
|
+
for (let j = pos; j < i;) {
|
|
181
|
+
if (countsAsNum.test(types[j])) {
|
|
182
|
+
if (pos < j) { order.splice(at, 0, new BidiSpan(1, pos, j)); at += isRTL }
|
|
183
|
+
let nstart = j
|
|
184
|
+
for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
|
|
185
|
+
order.splice(at, 0, new BidiSpan(2, nstart, j))
|
|
186
|
+
at += isRTL
|
|
187
|
+
pos = j
|
|
188
|
+
} else ++j
|
|
189
|
+
}
|
|
190
|
+
if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i))
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (direction == "ltr") {
|
|
194
|
+
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
|
|
195
|
+
order[0].from = m[0].length
|
|
196
|
+
order.unshift(new BidiSpan(0, 0, m[0].length))
|
|
197
|
+
}
|
|
198
|
+
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
|
|
199
|
+
lst(order).to -= m[0].length
|
|
200
|
+
order.push(new BidiSpan(0, len - m[0].length, len))
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return direction == "rtl" ? order.reverse() : order
|
|
205
|
+
}
|
|
206
|
+
})()
|
|
207
|
+
|
|
208
|
+
// Get the bidi ordering for the given line (and cache it). Returns
|
|
209
|
+
// false for lines that are fully left-to-right, and an array of
|
|
210
|
+
// BidiSpan objects otherwise.
|
|
211
|
+
export function getOrder(line, direction) {
|
|
212
|
+
let order = line.order
|
|
213
|
+
if (order == null) order = line.order = bidiOrdering(line.text, direction)
|
|
214
|
+
return order
|
|
215
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Kludges for bugs and behavior differences that can't be feature
|
|
2
|
+
// detected are enabled based on userAgent etc sniffing.
|
|
3
|
+
let userAgent = navigator.userAgent
|
|
4
|
+
let platform = navigator.platform
|
|
5
|
+
|
|
6
|
+
export let gecko = /gecko\/\d/i.test(userAgent)
|
|
7
|
+
let ie_upto10 = /MSIE \d/.test(userAgent)
|
|
8
|
+
let ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
|
|
9
|
+
let edge = /Edge\/(\d+)/.exec(userAgent)
|
|
10
|
+
export let ie = ie_upto10 || ie_11up || edge
|
|
11
|
+
export let ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1])
|
|
12
|
+
export let webkit = !edge && /WebKit\//.test(userAgent)
|
|
13
|
+
let qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
|
|
14
|
+
export let chrome = !edge && /Chrome\/(\d+)/.exec(userAgent)
|
|
15
|
+
export let chrome_version = chrome && +chrome[1]
|
|
16
|
+
export let presto = /Opera\//.test(userAgent)
|
|
17
|
+
export let safari = /Apple Computer/.test(navigator.vendor)
|
|
18
|
+
export let mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
|
|
19
|
+
export let phantom = /PhantomJS/.test(userAgent)
|
|
20
|
+
|
|
21
|
+
export let ios = safari && (/Mobile\/\w+/.test(userAgent) || navigator.maxTouchPoints > 2)
|
|
22
|
+
export let android = /Android/.test(userAgent)
|
|
23
|
+
// This is woefully incomplete. Suggestions for alternative methods welcome.
|
|
24
|
+
export let mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
|
|
25
|
+
export let mac = ios || /Mac/.test(platform)
|
|
26
|
+
export let chromeOS = /\bCrOS\b/.test(userAgent)
|
|
27
|
+
export let windows = /win/i.test(platform)
|
|
28
|
+
|
|
29
|
+
let presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
|
|
30
|
+
if (presto_version) presto_version = Number(presto_version[1])
|
|
31
|
+
if (presto_version && presto_version >= 15) { presto = false; webkit = true }
|
|
32
|
+
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
|
|
33
|
+
export let flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
|
|
34
|
+
export let captureRightClick = gecko || (ie && ie_version >= 9)
|