From 2b476c87b8666dc750a5f1551a2fd365a9f2b25a Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Thu, 22 Oct 2026 12:47:18 -0400 Subject: [PATCH 1/2] parse-rfd: Update @asciidoctor/core from 2.2.9 to 3.0.4 --- .github/workflows/test.yml | 17 ++ parse-rfd/parser/package-lock.json | 295 ++++++++--------------------- parse-rfd/parser/package.json | 2 +- 3 files changed, 95 insertions(+), 219 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ddde640..ade7a7e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -127,3 +127,20 @@ jobs: echo " cargo xtask generate" exit 1 fi + + parser: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Verify parse-rfd parser bundle + working-directory: parse-rfd/parser + run: | + npm ci + npm run build + if ! git diff --quiet HEAD -- dist/index.js; then + git diff --stat HEAD -- dist/index.js + echo "parse-rfd/parser/dist/index.js does not match a fresh build from index.js and package-lock.json" + echo "To fix, rebuild the bundle and commit the result:" + echo " cd parse-rfd/parser && npm ci && npm run build" + exit 1 + fi diff --git a/parse-rfd/parser/package-lock.json b/parse-rfd/parser/package-lock.json index 00983aec..d5b96fa7 100644 --- a/parse-rfd/parser/package-lock.json +++ b/parse-rfd/parser/package-lock.json @@ -5,59 +5,36 @@ "packages": { "": { "dependencies": { - "@asciidoctor/core": "^2.2.6", + "@asciidoctor/core": "^3.0.4", "@vercel/ncc": "^0.45.0", "html-to-text": "^9.0.2" } }, "node_modules/@asciidoctor/core": { - "version": "2.2.9", - "resolved": "https://registry.npmjs.org/@asciidoctor/core/-/core-2.2.9.tgz", - "integrity": "sha512-tIPRHo1T2SFmAm+j77cDsj0RuaszP7xJxsaVTTAF5CwKyTbazw9TnIVlpIWM5yWfIWAWcAZy92RcnPgMJwny1w==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@asciidoctor/core/-/core-3.0.4.tgz", + "integrity": "sha512-41SDMi7iRRBViPe0L6VWFTe55bv6HEOJeRqMj5+E5wB1YPdUPuTucL4UAESPZM6OWmn4t/5qM5LusXomFUVwVQ==", "license": "MIT", "dependencies": { - "asciidoctor-opal-runtime": "0.3.4", - "unxhr": "~1.2" + "@asciidoctor/opal-runtime": "3.0.1", + "unxhr": "1.2.0" }, "engines": { - "node": ">=8.11", - "npm": ">=5.0.0", - "yarn": ">=1.1.0" + "node": ">=16", + "npm": ">=8" } }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "node_modules/@asciidoctor/opal-runtime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@asciidoctor/opal-runtime/-/opal-runtime-3.0.1.tgz", + "integrity": "sha512-iW7ACahOG0zZft4A/4CqDcc7JX+fWRNjV5tFAVkNCzwZD+EnFolPaUOPYt8jzadc0+Bgd80cQTtRMQnaaV1kkg==", "license": "MIT", "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" + "glob": "8.1.0", + "unxhr": "1.2.0" }, "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "license": "MIT", - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "license": "MIT", - "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - }, - "engines": { - "node": ">= 8" + "node": ">=16" } }, "node_modules/@selderee/plugin-htmlparser2": { @@ -82,29 +59,19 @@ "ncc": "dist/ncc/cli.js" } }, - "node_modules/asciidoctor-opal-runtime": { - "version": "0.3.4", - "resolved": "https://registry.npmjs.org/asciidoctor-opal-runtime/-/asciidoctor-opal-runtime-0.3.4.tgz", - "integrity": "sha512-zqd6zn1LV+PZ69AP/kEbB00zuPHMIAJY3IX8+aZV+X1qOwatYvKGjsMmdMc5ApfhtkjZ4mYkqiTPJWnEnBiMJg==", - "license": "MIT", - "dependencies": { - "fast-glob": "~3.3", - "unxhr": "~1.2" - }, - "engines": { - "node": ">=8.11" - } + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" }, - "node_modules/braces": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", - "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "node_modules/brace-expansion": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", + "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", "license": "MIT", "dependencies": { - "fill-range": "^7.1.1" - }, - "engines": { - "node": ">=8" + "balanced-match": "^1.0.0" } }, "node_modules/deepmerge": { @@ -183,53 +150,30 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, - "node_modules/fast-glob": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", - "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", - "license": "MIT", - "dependencies": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.8" - }, - "engines": { - "node": ">=8.6.0" - } + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "license": "ISC" }, - "node_modules/fastq": { - "version": "1.20.3", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz", - "integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==", + "node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", "license": "ISC", "dependencies": { - "reusify": "^1.0.4" - } - }, - "node_modules/fill-range": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", - "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "license": "MIT", - "dependencies": { - "to-regex-range": "^5.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" }, "engines": { - "node": ">=8" - } - }, - "node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "license": "ISC", - "dependencies": { - "is-glob": "^4.0.1" + "node": ">=12" }, - "engines": { - "node": ">= 6" + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/html-to-text": { @@ -267,35 +211,22 @@ "entities": "^4.4.0" } }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "license": "MIT", + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "license": "ISC", "dependencies": { - "is-extglob": "^2.1.1" - }, - "engines": { - "node": ">=0.10.0" + "once": "^1.3.0", + "wrappy": "1" } }, - "node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "license": "MIT", - "engines": { - "node": ">=0.12.0" - } + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" }, "node_modules/leac": { "version": "0.6.0", @@ -306,26 +237,25 @@ "url": "https://ko-fi.com/killymxi" } }, - "node_modules/merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "license": "MIT", + "node_modules/minimatch": { + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz", + "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, "engines": { - "node": ">= 8" + "node": ">=10" } }, - "node_modules/micromatch": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", - "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", - "license": "MIT", + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", "dependencies": { - "braces": "^3.0.3", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=8.6" + "wrappy": "1" } }, "node_modules/parseley": { @@ -350,71 +280,6 @@ "url": "https://ko-fi.com/killymxi" } }, - "node_modules/picomatch": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", - "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", - "license": "MIT", - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/reusify": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", - "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", - "license": "MIT", - "engines": { - "iojs": ">=1.0.0", - "node": ">=0.10.0" - } - }, - "node_modules/run-parallel": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", - "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, "node_modules/selderee": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/selderee/-/selderee-0.11.0.tgz", @@ -427,18 +292,6 @@ "url": "https://ko-fi.com/killymxi" } }, - "node_modules/to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "license": "MIT", - "dependencies": { - "is-number": "^7.0.0" - }, - "engines": { - "node": ">=8.0" - } - }, "node_modules/unxhr": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/unxhr/-/unxhr-1.2.0.tgz", @@ -447,6 +300,12 @@ "engines": { "node": ">=8.11" } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" } } } diff --git a/parse-rfd/parser/package.json b/parse-rfd/parser/package.json index d7e01d72..bebdcf10 100644 --- a/parse-rfd/parser/package.json +++ b/parse-rfd/parser/package.json @@ -3,7 +3,7 @@ "build": "ncc build index -o dist" }, "dependencies": { - "@asciidoctor/core": "^2.2.6", + "@asciidoctor/core": "^3.0.4", "@vercel/ncc": "^0.45.0", "html-to-text": "^9.0.2" } From 60fdb53ebe0327b856c7d17265c6890413c60a3b Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Thu, 22 Oct 2026 13:36:53 -0400 Subject: [PATCH 2/2] Update dist --- parse-rfd/parser/dist/index.js | 102775 +++++++++++++++--------------- 1 file changed, 50400 insertions(+), 52375 deletions(-) diff --git a/parse-rfd/parser/dist/index.js b/parse-rfd/parser/dist/index.js index 9c7b1c11..244be76a 100644 --- a/parse-rfd/parser/dist/index.js +++ b/parse-rfd/parser/dist/index.js @@ -1,58402 +1,56431 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 853: -/***/ (function(module, __unused_webpack_exports, __nccwpck_require__) { - -/* global Opal, Asciidoctor, ASCIIDOCTOR_JS_VERSION */ -const Opal = (__nccwpck_require__(9560)/* .Opal */ .s) - -// Node module -;(function (root, factory) { - module.exports = factory - // default export for ES6 module interop - module.exports["default"] = factory -}(this, function (moduleConfig) { -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/electron/io"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $send = Opal.send, $gvars = Opal.gvars, $writer = nil; - if ($gvars.stdout == null) $gvars.stdout = nil; - if ($gvars.stderr == null) $gvars.stderr = nil; - - Opal.add_stubs(['$write_proc=', '$-']); - - - $writer = [function(s){console.log(s)}]; - $send($gvars.stdout, 'write_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [function(s){console.error(s)}]; - $send($gvars.stderr, 'write_proc=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/node"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; - - Opal.add_stubs(['$==', '$require']); - - - var isElectron = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && typeof navigator.userAgent.indexOf('Electron') !== -1, - platform, - engine, - framework, - ioModule; - - if (typeof moduleConfig === 'object' && typeof moduleConfig.runtime === 'object') { - var runtime = moduleConfig.runtime; - platform = runtime.platform; - engine = runtime.engine; - framework = runtime.framework; - ioModule = runtime.ioModule; - } +/***/ 9380: +/***/ ((module) => { - ioModule = ioModule || 'node'; - platform = platform || 'node'; - engine = engine || 'v8'; - if (isElectron) { - framework = framework || 'electron'; - } else { - framework = framework || ''; - } -; - Opal.const_set($nesting[0], 'JAVASCRIPT_IO_MODULE', ioModule); - Opal.const_set($nesting[0], 'JAVASCRIPT_PLATFORM', platform); - Opal.const_set($nesting[0], 'JAVASCRIPT_ENGINE', engine); - Opal.const_set($nesting[0], 'JAVASCRIPT_FRAMEWORK', framework); - if ($$($nesting, 'JAVASCRIPT_FRAMEWORK')['$==']("electron")) { - self.$require("asciidoctor/js/opal_ext/electron/io")}; - -// Load Opal modules -Opal.load("pathname"); -Opal.load("nodejs"); -; -}; +"use strict"; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/node/abstract_node"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass; +module.exports = balanced; +function balanced(a, b, str) { + if (a instanceof RegExp) a = maybeMatch(a, str); + if (b instanceof RegExp) b = maybeMatch(b, str); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + var r = range(a, b, str); - var $nesting = [self].concat($parent_nesting); + return r && { + start: r[0], + end: r[1], + pre: str.slice(0, r[0]), + body: str.slice(r[0] + a.length, r[1]), + post: str.slice(r[1] + b.length) + }; +} - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'AbstractNode'); +function maybeMatch(reg, str) { + var m = str.match(reg); + return m ? m[0] : null; +} - var $nesting = [self].concat($parent_nesting), $AbstractNode_generate_data_uri_from_uri$1; - if (self.__xmlhttprequest__ == null) self.__xmlhttprequest__ = nil; +balanced.range = range; +function range(a, b, str) { + var begs, beg, left, right, result; + var ai = str.indexOf(a); + var bi = str.indexOf(b, ai + 1); + var i = ai; - - self.__xmlhttprequest__ = __nccwpck_require__(4315); - var __XMLHttpRequest__ = self.__xmlhttprequest__.XMLHttpRequest; - return (Opal.def(self, '$generate_data_uri_from_uri', $AbstractNode_generate_data_uri_from_uri$1 = function $$generate_data_uri_from_uri(image_uri, cache_uri) { - var self = this; + if (ai >= 0 && bi > 0) { + if(a===b) { + return [ai, bi]; + } + begs = []; + left = str.length; - - - if (cache_uri == null) { - cache_uri = false; - }; - - var contentType = '' - var b64encoded = '' - var status = -1 + while (i >= 0 && !result) { + if (i == ai) { + begs.push(i); + ai = str.indexOf(a, i + 1); + } else if (begs.length == 1) { + result = [ begs.pop(), bi ]; + } else { + beg = begs.pop(); + if (beg < left) { + left = beg; + right = bi; + } - try { - var xhr = new __XMLHttpRequest__(); - xhr.open('GET', image_uri, false); - xhr.responseType = 'arraybuffer'; - xhr.addEventListener('load', function() { - status = this.status - if (status === 200) { - var arrayBuffer = this.response; - b64encoded = Buffer.from(arrayBuffer).toString('base64'); - contentType = this.getResponseHeader('content-type') - } - }) - xhr.send(null) - } - catch (e) { - // something bad happened! - status = 0 - } - if (status === 404 || (status === 0 && !b64encoded)) { - self.$logger().$warn('could not retrieve image data from URI: ' + image_uri) - return image_uri + bi = str.indexOf(b, i + 1); } - return 'data:' + contentType + ';base64,' + b64encoded - ; - }, $AbstractNode_generate_data_uri_from_uri$1.$$arity = -2), nil) && 'generate_data_uri_from_uri'; - })($nesting[0], null, $nesting) - })($nesting[0], $nesting) -}; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/node/open_uri"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; + i = ai < bi && ai >= 0 ? ai : bi; + } - Opal.add_stubs(['$require', '$new', '$<<', '$rewind']); - - self.$require("stringio"); - return (function($base, $parent_nesting) { - var self = $module($base, 'OpenURI'); + if (begs.length) { + result = [ left, right ]; + } + } - var $nesting = [self].concat($parent_nesting), $OpenURI_open_uri$1; - if (self.__xmlhttprequest__ == null) self.__xmlhttprequest__ = nil; + return result; +} - - self.__xmlhttprequest__ = __nccwpck_require__(4315); - var __XMLHttpRequest__ = self.__xmlhttprequest__.XMLHttpRequest; - Opal.defs($$($nesting, 'OpenURI'), '$open_uri', $OpenURI_open_uri$1 = function $$open_uri(uri, $a) { - var $post_args, rest, $iter = $OpenURI_open_uri$1.$$p, $yield = $iter || nil, self = this, io = nil, data = nil; - if ($iter) $OpenURI_open_uri$1.$$p = null; - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - rest = $post_args;; - io = $$$('::', 'StringIO').$new(); - data = ""; - - var contentType = '' - var status = -1 +/***/ }), - try { - var xhr = new __XMLHttpRequest__() - xhr.open('GET', uri, false) - xhr.responseType = 'text' - xhr.addEventListener('load', function() { - status = this.status - if (status === 200) { - data = this.responseText - contentType = this.getResponseHeader('content-type') - } - }) - xhr.send(null) - } - catch (e) { - // something bad happened! - status = 0 - } - if (status === 404 || (status === 0 && !data)) { - throw $$($nesting, 'IOError').$new('No such file or directory: ' + uri) - } - ; - io['$<<'](data); - io.$rewind(); - if (($yield !== nil)) { - return Opal.yield1($yield, io); - } else { - return io - }; - }, $OpenURI_open_uri$1.$$arity = -2); - })($nesting[0], $nesting); -}; +/***/ 4691: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/node/stylesheet"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy; +var balanced = __nccwpck_require__(9380); - Opal.add_stubs(['$rstrip', '$read', '$join']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); +module.exports = expandTop; - var $nesting = [self].concat($parent_nesting); +var escSlash = '\0SLASH'+Math.random()+'\0'; +var escOpen = '\0OPEN'+Math.random()+'\0'; +var escClose = '\0CLOSE'+Math.random()+'\0'; +var escComma = '\0COMMA'+Math.random()+'\0'; +var escPeriod = '\0PERIOD'+Math.random()+'\0'; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Stylesheets'); +var EXPANSION_MAX = 100000 + +// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An +// input like `'{a,b}'.repeat(1500)` stays under that count - its output is +// truncated to 100k results - while making every result ~1500 characters +// long. The result set, and the intermediate arrays built while combining +// brace sets, then grow large enough to exhaust memory and crash the process +// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of +// characters the accumulator may hold at any point, so memory stays flat no +// matter how many brace groups are chained. The limit sits well above any +// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M +// characters) so legitimate input is unaffected. +var EXPANSION_MAX_LENGTH = 4000000 + +// `expand` recurses once per level of brace *nesting* - both when expanding a +// set's comma members and when re-wrapping a set whose body is a single part. +// The CVE-2026-14257 fix made the *tail* iterative (recursion on `m.post`, one +// level per chained group), which left nesting depth unbounded: about 3,100 +// levels of `{{{...a,b...}}}` - only ~6KB of input - exhausted the native stack +// and crashed the process. `EXPANSION_MAX_DEPTH` bounds how deep the parser +// will follow nesting. It sits far above any realistic pattern and well below +// the depth at which the stack runs out. +var EXPANSION_MAX_DEPTH = 1000 + +// Bash keeps a quirk where a brace group followed by a comma set still expands +// (`{a},b}`). The parser implements it by rewriting the string and restarting +// the scan, absorbing one `}` per pass. `n` trailing braces therefore cost `n` +// full passes over a string that itself grows by one `escClose` sentinel each +// time - quadratic in `n`, with a ~26x constant from the sentinel's length. +// 128KB of `'{a}' + '}'.repeat(n) + ',z}'` blocked the event loop for 27 +// seconds to produce two results. `EXPANSION_MAX_REWRITES` bounds how many +// times the scan may restart. Real `{a},b}` input needs a handful. +var EXPANSION_MAX_REWRITES = 1000 - var $nesting = [self].concat($parent_nesting), $Stylesheets_primary_stylesheet_data$1; +function numeric(str) { + return parseInt(str, 10) == str + ? parseInt(str, 10) + : str.charCodeAt(0); +} - self.$$prototype.primary_stylesheet_data = nil; - return (Opal.def(self, '$primary_stylesheet_data', $Stylesheets_primary_stylesheet_data$1 = function $$primary_stylesheet_data() { - var $a, self = this, __path__ = nil, stylesheets_dir = nil; +function escapeBraces(str) { + return str.split('\\\\').join(escSlash) + .split('\\{').join(escOpen) + .split('\\}').join(escClose) + .split('\\,').join(escComma) + .split('\\.').join(escPeriod); +} - - __path__ = __nccwpck_require__(1017); - if ($truthy(__path__.basename(__dirname) === 'node' && __path__.basename(__path__.dirname(__dirname)) === 'dist')) { - stylesheets_dir = __nccwpck_require__.ab + "css" - } else { - stylesheets_dir = __path__.join(__dirname, 'css') - }; - return (self.primary_stylesheet_data = ($truthy($a = self.primary_stylesheet_data) ? $a : $$$('::', 'IO').$read($$$('::', 'File').$join(stylesheets_dir, "asciidoctor.css")).$rstrip())); - }, $Stylesheets_primary_stylesheet_data$1.$$arity = 0), nil) && 'primary_stylesheet_data' - })($nesting[0], null, $nesting) - })($nesting[0], $nesting) -}; +function unescapeBraces(str) { + return str.split(escSlash).join('\\') + .split(escOpen).join('{') + .split(escClose).join('}') + .split(escComma).join(',') + .split(escPeriod).join('.'); +} -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/node/template"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy, $send = Opal.send; - Opal.add_stubs(['$[]', '$clear', '$===', '$caches', '$class', '$scan', '$node_name', '$raise', '$ctx', '$==', '$strip', '$rstrip', '$key?', '$merge', '$file', '$[]=', '$-', '$private', '$new', '$each', '$directory?', '$system_path', '$scan_dir', '$update', '$select', '$glob', '$file?', '$basename', '$<', '$size', '$split', '$start_with?', '$slice', '$length', '$to_sym', '$node_require']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); +// Like `target.push(...items)` but doesn't overflow the stack +function pushAll(target, items) { + for (var i = 0; i < items.length; i++) { + target.push(items[i]); + } +} - var $nesting = [self].concat($parent_nesting); +// Basically just str.split(","), but handling cases +// where we have nested braced sections, which should be +// treated as individual members, like {a,{b,c},d} +function parseCommaParts(str) { + var parts = []; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'TemplateConverter'); + // Walk the brace groups iteratively. Recursing on `post` once per group let a + // chain of them exhaust the stack - the parsing-side counterpart to + // the `expand` overflow fixed for CVE-2026-14257, and not something `max` or + // `maxLength` can bound, since it happens before expansion. + // + // The part the next chunk continues + var carry = ''; - var $nesting = [self].concat($parent_nesting), $TemplateConverter_caches$1, $TemplateConverter_clear_caches$2, $TemplateConverter_initialize$3, $TemplateConverter_convert$4, $TemplateConverter_handles$ques$5, $TemplateConverter_templates$6, $TemplateConverter_register$7, $TemplateConverter_scan$8, $TemplateConverter_node_require$11, $TemplateConverter_scan_dir$12; + for (;;) { + var m = balanced('{', '}', str); - self.$$prototype.templates = self.$$prototype.caches = self.$$prototype.backend = self.$$prototype.engine = self.$$prototype.template_dirs = nil; - - self.caches = $hash2(["scans", "templates"], {"scans": $hash2([], {}), "templates": $hash2([], {})}); - Opal.defs(self, '$caches', $TemplateConverter_caches$1 = function $$caches() { - var self = this; - if (self.caches == null) self.caches = nil; + if (!m) { + var tail = str.split(','); + tail[0] = carry + tail[0]; + pushAll(parts, tail); + return parts; + } - return self.caches - }, $TemplateConverter_caches$1.$$arity = 0); - Opal.defs(self, '$clear_caches', $TemplateConverter_clear_caches$2 = function $$clear_caches() { - var self = this; - if (self.caches == null) self.caches = nil; + var pre = m.pre; + var body = m.body; + var post = m.post; + var p = pre.split(','); - - if ($truthy(self.caches['$[]']("scans"))) { - self.caches['$[]']("scans").$clear()}; - if ($truthy(self.caches['$[]']("templates"))) { - return self.caches['$[]']("templates").$clear() - } else { - return nil - }; - }, $TemplateConverter_clear_caches$2.$$arity = 0); - - Opal.def(self, '$initialize', $TemplateConverter_initialize$3 = function $$initialize(backend, template_dirs, opts) { - var $a, self = this, $case = nil; + p[0] = carry + p[0]; + p[p.length-1] += '{' + body + '}'; - - - if (opts == null) { - opts = $hash2([], {}); - }; - self.backend = backend; - self.templates = $hash2([], {}); - self.template_dirs = template_dirs; - self.engine = opts['$[]']("template_engine"); - self.engine_options = ($truthy($a = opts['$[]']("template_engine_options")) ? $a : $hash2([], {})); - $case = opts['$[]']("template_cache"); - if (true['$===']($case)) {self.caches = self.$class().$caches()} - else if ($$$('::', 'Hash')['$===']($case)) {self.caches = opts['$[]']("template_cache")} - else {self.caches = $hash2([], {})}; - return self.$scan(); - }, $TemplateConverter_initialize$3.$$arity = -3); - - Opal.def(self, '$convert', $TemplateConverter_convert$4 = function $$convert(node, template_name, opts) { - var $a, self = this, template = nil, helpers_ctx = nil; + if (!post.length) { + pushAll(parts, p); + return parts; + } - - - if (template_name == null) { - template_name = nil; - }; - - if (opts == null) { - opts = nil; - }; - if ($truthy((template = self.templates['$[]']((template_name = ($truthy($a = template_name) ? $a : node.$node_name())))))) { - } else { - self.$raise("" + "Could not find a custom template to handle transform: " + (template_name)) - }; - helpers_ctx = ($truthy($a = self.templates['$[]']("helpers.js")) ? self.templates['$[]']("helpers.js").$ctx() : $a); - if (template_name['$==']("document")) { - return (template.render({node: node, opts: fromHash(opts), helpers: helpers_ctx})).$strip() - } else { - return (template.render({node: node, opts: fromHash(opts), helpers: helpers_ctx})).$rstrip() - }; - }, $TemplateConverter_convert$4.$$arity = -2); - - Opal.def(self, '$handles?', $TemplateConverter_handles$ques$5 = function(name) { - var self = this; + carry = p.pop(); + pushAll(parts, p); + str = post; + } +} - return self.templates['$key?'](name) - }, $TemplateConverter_handles$ques$5.$$arity = 1); - - Opal.def(self, '$templates', $TemplateConverter_templates$6 = function $$templates() { - var self = this; +function expandTop(str, options) { + if (!str) + return []; - return self.templates.$merge() - }, $TemplateConverter_templates$6.$$arity = 0); - - Opal.def(self, '$register', $TemplateConverter_register$7 = function $$register(name, template) { - var $a, self = this, $writer = nil, template_cache = nil; + options = options || {}; + var max = options.max == null ? EXPANSION_MAX : options.max; + var maxLength = options.maxLength == null ? EXPANSION_MAX_LENGTH : options.maxLength; + var maxDepth = options.maxDepth == null ? EXPANSION_MAX_DEPTH : options.maxDepth; + var maxRewrites = options.maxRewrites == null ? EXPANSION_MAX_REWRITES : options.maxRewrites; - - $writer = [name, (function() {if ($truthy((template_cache = ($truthy($a = self.caches['$[]']("templates")) ? template.$file : $a)))) { - - $writer = [template.$file(), template]; - $send(template_cache, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - } else { - return template - }; return nil; })()]; - $send(self.templates, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $TemplateConverter_register$7.$$arity = 2); - self.$private(); - - Opal.def(self, '$scan', $TemplateConverter_scan$8 = function $$scan() { - var $$9, self = this, path_resolver = nil, backend = nil, engine = nil; + // I don't know why Bash 4.3 does this, but it does. + // Anything starting with {} will have the first two bytes preserved + // but *only* at the top level, so {},a}b will not expand to anything, + // but a{},b}c will be expanded to [a}c,abc]. + // One could argue that this is a bug in Bash, but since the goal of + // this module is to match Bash's rules, we escape a leading {} + if (str.substr(0, 2) === '{}') { + str = '\\{\\}' + str.substr(2); + } - - path_resolver = $$($nesting, 'PathResolver').$new(); - backend = self.backend; - engine = self.engine; - return $send(self.template_dirs, 'each', [], ($$9 = function(template_dir){var self = $$9.$$s || this, $$10, file_pattern = nil, engine_dir = nil, backend_dir = nil, pattern = nil, scan_cache = nil, template_cache = nil, templates = nil, $writer = nil; - if (self.caches == null) self.caches = nil; - if (self.templates == null) self.templates = nil; + return expand(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces); +} - - - if (template_dir == null) { - template_dir = nil; - }; - if ($truthy($$$('::', 'File')['$directory?']((template_dir = path_resolver.$system_path(template_dir))))) { - } else { - return nil; - }; - if ($truthy(engine)) { - - file_pattern = "" + "*." + (engine); - if ($truthy($$$('::', 'File')['$directory?']((engine_dir = "" + (template_dir) + "/" + (engine))))) { - template_dir = engine_dir}; - } else { - file_pattern = "*" - }; - if ($truthy($$$('::', 'File')['$directory?']((backend_dir = "" + (template_dir) + "/" + (backend))))) { - template_dir = backend_dir}; - pattern = "" + (template_dir) + "/" + (file_pattern); - if ($truthy((scan_cache = self.caches['$[]']("scans")))) { - - template_cache = self.caches['$[]']("templates"); - if ($truthy((templates = scan_cache['$[]'](pattern)))) { - } else { - templates = (($writer = [pattern, self.$scan_dir(template_dir, pattern, template_cache)]), $send(scan_cache, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)]) - }; - $send(templates, 'each', [], ($$10 = function(name, template){var self = $$10.$$s || this; - if (self.templates == null) self.templates = nil; +function embrace(str) { + return '{' + str + '}'; +} +function isPadded(el) { + return /^-?0\d/.test(el); +} - - - if (name == null) { - name = nil; - }; - - if (template == null) { - template = nil; - }; - $writer = [name, (($writer = [template.$file(), template]), $send(template_cache, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])]; - $send(self.templates, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$10.$$s = self, $$10.$$arity = 2, $$10)); - } else { - self.templates.$update(self.$scan_dir(template_dir, pattern, self.caches['$[]']("templates"))) - }; - return nil;}, $$9.$$s = self, $$9.$$arity = 1, $$9)); - }, $TemplateConverter_scan$8.$$arity = 0); - - Opal.def(self, '$node_require', $TemplateConverter_node_require$11 = function $$node_require(module_name) { - var self = this; +function lte(i, y) { + return i <= y; +} +function gte(i, y) { + return i >= y; +} - - try { - return require(module_name) +// Build `{ acc[a] + pre + values[v] }` for every combination, capping the +// number of results at `max` and the total number of characters at `maxLength`. +// This is the one place output grows, so bounding it here keeps the single +// accumulator - and therefore memory - flat regardless of how many brace groups +// are combined (CVE-2026-14257). +function combine( + acc, + pre, + values, + max, + maxLength, + dropEmpties +) { + var out = [] + var length = 0 + for (var a = 0; a < acc.length; a++) { + for (var v = 0; v < values.length; v++) { + if (out.length >= max) return out + var expansion = acc[a] + pre + values[v] + // Bash drops empty results at the top level. Skip them before they count + // against `max`, so `max` bounds the number of *kept* results. + if (dropEmpties && !expansion) continue + if (length + expansion.length > maxLength) return out + out.push(expansion) + length += expansion.length + } + } + return out +} + +// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`) +// sequence body. +function expandSequence( + body, + isAlphaSequence, + max, + maxLength +) { + var n = body.split(/\.\./) + var N = [] + // A sequence body always splits into two or three parts, but the compiler + // can't know that. + /* c8 ignore start */ + if (n[0] === undefined || n[1] === undefined) { + return N + } + /* c8 ignore stop */ + var x = numeric(n[0]) + var y = numeric(n[1]) + var width = Math.max(n[0].length, n[1].length) + var incr = + n.length === 3 && n[2] !== undefined ? + Math.max(Math.abs(numeric(n[2])), 1) + : 1 + var test = lte + var reverse = y < x + if (reverse) { + incr *= -1 + test = gte + } + var pad = n.some(isPadded) + + var length = 0 + for (var i = x; test(i, y) && N.length < max; i += incr) { + var c + if (isAlphaSequence) { + c = String.fromCharCode(i) + if (c === '\\') { + c = '' } - catch (e) { - throw $$($nesting, 'IOError').$new("" + "Unable to require the module '" + (module_name) + "', please make sure that the module is installed.") + } else { + c = String(i) + if (pad) { + var need = width - c.length + if (need > 0) { + var z = new Array(need + 1).join('0') + if (i < 0) { + c = '-' + z + c.slice(1) + } else { + c = z + c + } + } } - - }, $TemplateConverter_node_require$11.$$arity = 1); - return (Opal.def(self, '$scan_dir', $TemplateConverter_scan_dir$12 = function $$scan_dir(template_dir, pattern, template_cache) { - var $a, $$13, $$14, self = this, result = nil, helpers = nil, $writer = nil; + } + if (length + c.length > maxLength) break + N.push(c) + length += c.length + } + return N +} - - - if (template_cache == null) { - template_cache = nil; - }; - $a = [$hash2([], {}), nil], (result = $a[0]), (helpers = $a[1]), $a; - var enginesContext = {}; - $send($send($$$('::', 'Dir').$glob(pattern), 'select', [], ($$13 = function(match){var self = $$13.$$s || this; +function expand( + str, + max, + maxLength, + maxDepth, + depth, + maxRewrites, + isTop +) { + // Too deeply nested to keep following: treat the rest as literal, the same + // way a group that cannot expand is already handled. Truncating rather than + // throwing keeps expansion total, matching `max` and `maxLength`. + if (depth > maxDepth) { + return [str]; + } - - - if (match == null) { - match = nil; - }; - return $$$('::', 'File')['$file?'](match);}, $$13.$$s = self, $$13.$$arity = 1, $$13)), 'each', [], ($$14 = function(file){var self = $$14.$$s || this, $b, basename = nil, path_segments = nil, name = nil, template = nil, extsym = nil, $case = nil, nunjucks = nil, handlebars = nil, ejs = nil, pug = nil, $writer = nil; + // Consume the string's top-level brace groups left to right, threading a + // running set of combined prefixes (`acc`). Expanding the tail iteratively - + // rather than recursing on `m.post` once per group - keeps the native stack + // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no + // longer overflow the stack, and leaves a single accumulator whose size + // `maxLength` bounds directly (CVE-2026-14257). + var acc = [''] + + // Bash drops empty results, but only when the *first* top-level group is a + // comma set - a sequence like `{a..\}` may legitimately yield ''. The drop + // is on the final strings, so it is applied to whichever `combine` produces + // them (the one with no brace set left in the tail). + // How many times the `{a},b}` rewrite below has restarted the scan. Each pass + // re-reads the whole string, so leaving this unbounded is quadratic. + var rewrites = 0 + var dropEmpties = false + var firstGroup = true + + for (;;) { + const m = balanced('{', '}', str) + + // No brace set left: the rest of the string is literal. + if (!m) { + return combine(acc, str, [''], max, maxLength, dropEmpties) + } + + // no need to expand pre, since it is guaranteed to be free of brace-sets + const pre = m.pre + + if (/\$$/.test(pre)) { + acc = combine( + acc, + pre + '{' + m.body + '}', + [''], + max, + maxLength, + dropEmpties && !m.post.length + ) + firstGroup = false + if (!m.post.length) break + str = m.post + continue + } - - - if (file == null) { - file = nil; - }; - if ((basename = $$$('::', 'File').$basename(file))['$==']("helpers.js")) { - - helpers = file; - return nil;; - } else if ($truthy($rb_lt((path_segments = basename.$split(".")).$size(), 2))) { - return nil;}; - if ((name = path_segments['$[]'](0))['$==']("block_ruler")) { - name = "thematic_break" - } else if ($truthy(name['$start_with?']("block_"))) { - name = name.$slice(6, name.$length())}; - if ($truthy(($truthy($b = template_cache) ? (template = template_cache['$[]'](file)) : $b))) { - } else { - - extsym = path_segments['$[]'](-1).$to_sym(); - $case = extsym; - if ("nunjucks"['$===']($case) || "njk"['$===']($case)) { - nunjucks = self.$node_require("nunjucks"); - - var fs = __nccwpck_require__(7147) - var env - if (enginesContext.nunjucks && enginesContext.nunjucks.environment) { - env = enginesContext.nunjucks.environment - } else { - var opts = self.engine_options['nunjucks'] || {} - delete opts.web // unsupported option - env = nunjucks.configure(template_dir, opts) - enginesContext.nunjucks = { environment: env } - } - template = Object.assign(nunjucks.compile(fs.readFileSync(file, 'utf8'), env), { '$file': function() { return file } }) - ;} - else if ("handlebars"['$===']($case) || "hbs"['$===']($case)) { - handlebars = self.$node_require("handlebars"); - - var fs = __nccwpck_require__(7147) - var env - var opts = self.engine_options['handlebars'] || {} - if (enginesContext.handlebars && enginesContext.handlebars.environment) { - env = enginesContext.handlebars.environment - } else { - env = handlebars.create() - enginesContext.handlebars = { environment: env } - } - template = { render: env.compile(fs.readFileSync(file, 'utf8'), opts), '$file': function() { return file } } - ;} - else if ("ejs"['$===']($case)) { - ejs = self.$node_require("ejs"); - - var fs = __nccwpck_require__(7147) - var opts = self.engine_options['ejs'] || {} - opts.filename = file - // unsupported options - delete opts.async - delete opts.client - template = { render: ejs.compile(fs.readFileSync(file, 'utf8'), opts), '$file': function() { return file } } - ;} - else if ("pug"['$===']($case)) { - pug = self.$node_require("pug"); - - var opts = self.engine_options['pug'] || {} - opts.filename = file - template = { render: pug.compileFile(file, opts), '$file': function() { return file } } - ;} - else if ("js"['$===']($case)) {template = { render: require(file), '$file': function() { return file } }} - else { - var registry = Opal.Asciidoctor.TemplateEngine.registry - var templateEngine = registry[extsym] - if (templateEngine && typeof templateEngine.compile === 'function') { - template = Object.assign(templateEngine.compile(file, name), { '$file': function() { return file } }) - } else { - template = undefined - } - }; - }; - if ($truthy(template)) { - - $writer = [name, template]; - $send(result, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - } else { - return nil - };}, $$14.$$s = self, $$14.$$arity = 1, $$14)); - if ($truthy(($truthy($a = helpers) ? $a : $$$('::', 'File')['$file?']((helpers = "" + (template_dir) + "/helpers.js"))))) { - - - var ctx = require(helpers) - if (typeof ctx.configure === 'function') { - ctx.configure(enginesContext) + var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body); + var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body); + var isSequence = isNumericSequence || isAlphaSequence; + var isOptions = m.body.indexOf(',') >= 0; + if (!isSequence && !isOptions) { + // {a},b} + if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) { + rewrites++; + str = m.pre + '{' + m.body + escClose + m.post; + isTop = true; + continue; + } + // Nothing here expands, so the whole remaining string is literal. + return combine( + acc, + pre + '{' + m.body + '}' + m.post, + [''], + max, + maxLength, + dropEmpties + ) + } + + if (firstGroup) { + dropEmpties = isTop && !isSequence + firstGroup = false + } + + var values; + if (isSequence) { + values = expandSequence(m.body, isAlphaSequence, max, maxLength); + } else { + var n = parseCommaParts(m.body); + if (n.length === 1 && n[0] !== undefined) { + // x{{a,b}}y ==> x{a}y x{b}y + n = expand(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace); + //XXX is this necessary? Can't seem to hit it in tests. + /* c8 ignore start */ + if (n.length === 1) { + acc = combine( + acc, + pre + n[0], + [''], + max, + maxLength, + dropEmpties && !m.post.length + ) + if (!m.post.length) break + str = m.post + continue } - ; - - $writer = ["helpers.js", { '$file': function() { return helpers }, $ctx: function() { return ctx } }]; - $send(result, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];;}; - return result; - }, $TemplateConverter_scan_dir$12.$$arity = -3), nil) && 'scan_dir'; - })($$($nesting, 'Converter'), $$$($$($nesting, 'Converter'), 'Base'), $nesting) - })($nesting[0], $nesting) -}; + /* c8 ignore stop */ + } -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/node"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; + // Values that `combine` is going to drop as empty produce no result, so + // they must not count against `max` - otherwise `{a,,b}` with `max: 2` + // would stop at `['a', '']` and yield one result instead of two. Skipping + // them outright keeps `values` bounded while leaving `max` a bound on + // *kept* results. + var dropsEmpties = dropEmpties && !m.post.length && !pre + for (var d = 0; dropsEmpties && d < acc.length; d++) { + if (acc[d]) { + dropsEmpties = false + } + } - Opal.add_stubs(['$require']); - - self.$require("asciidoctor/js/asciidoctor_ext/node/abstract_node"); - self.$require("asciidoctor/js/asciidoctor_ext/node/open_uri"); - self.$require("asciidoctor/js/asciidoctor_ext/node/stylesheet"); - return self.$require("asciidoctor/js/asciidoctor_ext/node/template"); -}; + values = [] + var valuesLength = 0 + outer: for (var j = 0; j < n.length; j++) { + var expanded = expand(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false) + for (var k = 0; k < expanded.length; k++) { + var v = expanded[k] + if (dropsEmpties && !v) continue + if (values.length >= max || valuesLength + v.length > maxLength) { + break outer + } + values.push(v) + valuesLength += v.length + } + } + } -/* Generated by Opal 0.11.99.dev */ -Opal.modules["set"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); + acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length) + if (!m.post.length) break + str = m.post } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy, $send = Opal.send, $module = Opal.module; - - Opal.add_stubs(['$include', '$new', '$nil?', '$===', '$raise', '$each', '$add', '$merge', '$class', '$respond_to?', '$subtract', '$dup', '$join', '$to_a', '$equal?', '$instance_of?', '$==', '$instance_variable_get', '$is_a?', '$size', '$all?', '$include?', '$[]=', '$-', '$enum_for', '$[]', '$<<', '$replace', '$delete', '$select', '$each_key', '$to_proc', '$empty?', '$eql?', '$instance_eval', '$clear', '$<', '$<=', '$keys']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Set'); - var $nesting = [self].concat($parent_nesting), $Set_$$$1, $Set_initialize$2, $Set_dup$4, $Set_$minus$5, $Set_inspect$6, $Set_$eq_eq$7, $Set_add$9, $Set_classify$10, $Set_collect$excl$13, $Set_delete$15, $Set_delete$ques$16, $Set_delete_if$17, $Set_add$ques$20, $Set_each$21, $Set_empty$ques$22, $Set_eql$ques$23, $Set_clear$25, $Set_include$ques$26, $Set_merge$27, $Set_replace$29, $Set_size$30, $Set_subtract$31, $Set_$$33, $Set_superset$ques$34, $Set_proper_superset$ques$36, $Set_subset$ques$38, $Set_proper_subset$ques$40, $Set_to_a$42; + return acc +} - self.$$prototype.hash = nil; - - self.$include($$($nesting, 'Enumerable')); - Opal.defs(self, '$[]', $Set_$$$1 = function($a) { - var $post_args, ary, self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - ary = $post_args;; - return self.$new(ary); - }, $Set_$$$1.$$arity = -1); - - Opal.def(self, '$initialize', $Set_initialize$2 = function $$initialize(enum$) { - var $iter = $Set_initialize$2.$$p, block = $iter || nil, $$3, self = this; +/***/ }), - if ($iter) $Set_initialize$2.$$p = null; - - - if ($iter) $Set_initialize$2.$$p = null;; - - if (enum$ == null) { - enum$ = nil; - }; - self.hash = $hash2([], {}); - if ($truthy(enum$['$nil?']())) { - return nil}; - if ($truthy($$($nesting, 'Enumerable')['$==='](enum$))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "value must be enumerable") - }; - if ($truthy(block)) { - return $send(enum$, 'each', [], ($$3 = function(item){var self = $$3.$$s || this; +/***/ 2569: +/***/ ((module) => { - - - if (item == null) { - item = nil; - }; - return self.$add(Opal.yield1(block, item));}, $$3.$$s = self, $$3.$$arity = 1, $$3)) - } else { - return self.$merge(enum$) - }; - }, $Set_initialize$2.$$arity = -1); - - Opal.def(self, '$dup', $Set_dup$4 = function $$dup() { - var self = this, result = nil; +"use strict"; - - result = self.$class().$new(); - return result.$merge(self); - }, $Set_dup$4.$$arity = 0); - - Opal.def(self, '$-', $Set_$minus$5 = function(enum$) { - var self = this; - - if ($truthy(enum$['$respond_to?']("each"))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "value must be enumerable") - }; - return self.$dup().$subtract(enum$); - }, $Set_$minus$5.$$arity = 1); - Opal.alias(self, "difference", "-"); - - Opal.def(self, '$inspect', $Set_inspect$6 = function $$inspect() { - var self = this; +var isMergeableObject = function isMergeableObject(value) { + return isNonNullObject(value) + && !isSpecial(value) +}; - return "" + "#" - }, $Set_inspect$6.$$arity = 0); - - Opal.def(self, '$==', $Set_$eq_eq$7 = function(other) { - var $a, $$8, self = this; +function isNonNullObject(value) { + return !!value && typeof value === 'object' +} - if ($truthy(self['$equal?'](other))) { - return true - } else if ($truthy(other['$instance_of?'](self.$class()))) { - return self.hash['$=='](other.$instance_variable_get("@hash")) - } else if ($truthy(($truthy($a = other['$is_a?']($$($nesting, 'Set'))) ? self.$size()['$=='](other.$size()) : $a))) { - return $send(other, 'all?', [], ($$8 = function(o){var self = $$8.$$s || this; - if (self.hash == null) self.hash = nil; +function isSpecial(value) { + var stringValue = Object.prototype.toString.call(value); - - - if (o == null) { - o = nil; - }; - return self.hash['$include?'](o);}, $$8.$$s = self, $$8.$$arity = 1, $$8)) - } else { - return false - } - }, $Set_$eq_eq$7.$$arity = 1); - - Opal.def(self, '$add', $Set_add$9 = function $$add(o) { - var self = this, $writer = nil; + return stringValue === '[object RegExp]' + || stringValue === '[object Date]' + || isReactElement(value) +} - - - $writer = [o, true]; - $send(self.hash, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - return self; - }, $Set_add$9.$$arity = 1); - Opal.alias(self, "<<", "add"); - - Opal.def(self, '$classify', $Set_classify$10 = function $$classify() { - var $iter = $Set_classify$10.$$p, block = $iter || nil, $$11, $$12, self = this, result = nil; +// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 +var canUseSymbol = typeof Symbol === 'function' && Symbol.for; +var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; - if ($iter) $Set_classify$10.$$p = null; - - - if ($iter) $Set_classify$10.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("classify") - }; - result = $send($$($nesting, 'Hash'), 'new', [], ($$11 = function(h, k){var self = $$11.$$s || this, $writer = nil; +function isReactElement(value) { + return value.$$typeof === REACT_ELEMENT_TYPE +} - - - if (h == null) { - h = nil; - }; - - if (k == null) { - k = nil; - }; - $writer = [k, self.$class().$new()]; - $send(h, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$11.$$s = self, $$11.$$arity = 2, $$11)); - $send(self, 'each', [], ($$12 = function(item){var self = $$12.$$s || this; +function emptyTarget(val) { + return Array.isArray(val) ? [] : {} +} - - - if (item == null) { - item = nil; - }; - return result['$[]'](Opal.yield1(block, item)).$add(item);}, $$12.$$s = self, $$12.$$arity = 1, $$12)); - return result; - }, $Set_classify$10.$$arity = 0); - - Opal.def(self, '$collect!', $Set_collect$excl$13 = function() { - var $iter = $Set_collect$excl$13.$$p, block = $iter || nil, $$14, self = this, result = nil; +function cloneUnlessOtherwiseSpecified(value, options) { + return (options.clone !== false && options.isMergeableObject(value)) + ? deepmerge(emptyTarget(value), value, options) + : value +} - if ($iter) $Set_collect$excl$13.$$p = null; - - - if ($iter) $Set_collect$excl$13.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("collect!") - }; - result = self.$class().$new(); - $send(self, 'each', [], ($$14 = function(item){var self = $$14.$$s || this; +function defaultArrayMerge(target, source, options) { + return target.concat(source).map(function(element) { + return cloneUnlessOtherwiseSpecified(element, options) + }) +} - - - if (item == null) { - item = nil; - }; - return result['$<<'](Opal.yield1(block, item));}, $$14.$$s = self, $$14.$$arity = 1, $$14)); - return self.$replace(result); - }, $Set_collect$excl$13.$$arity = 0); - Opal.alias(self, "map!", "collect!"); - - Opal.def(self, '$delete', $Set_delete$15 = function(o) { - var self = this; - - - self.hash.$delete(o); - return self; - }, $Set_delete$15.$$arity = 1); - - Opal.def(self, '$delete?', $Set_delete$ques$16 = function(o) { - var self = this; - - if ($truthy(self['$include?'](o))) { - - self.$delete(o); - return self; - } else { - return nil - } - }, $Set_delete$ques$16.$$arity = 1); - - Opal.def(self, '$delete_if', $Set_delete_if$17 = function $$delete_if() { - var $$18, $$19, $iter = $Set_delete_if$17.$$p, $yield = $iter || nil, self = this; - - if ($iter) $Set_delete_if$17.$$p = null; - - if (($yield !== nil)) { - } else { - return self.$enum_for("delete_if") - }; - $send($send(self, 'select', [], ($$18 = function(o){var self = $$18.$$s || this; - - - - if (o == null) { - o = nil; - }; - return Opal.yield1($yield, o);;}, $$18.$$s = self, $$18.$$arity = 1, $$18)), 'each', [], ($$19 = function(o){var self = $$19.$$s || this; - if (self.hash == null) self.hash = nil; - - - - if (o == null) { - o = nil; - }; - return self.hash.$delete(o);}, $$19.$$s = self, $$19.$$arity = 1, $$19)); - return self; - }, $Set_delete_if$17.$$arity = 0); - - Opal.def(self, '$add?', $Set_add$ques$20 = function(o) { - var self = this; - - if ($truthy(self['$include?'](o))) { - return nil - } else { - return self.$add(o) - } - }, $Set_add$ques$20.$$arity = 1); - - Opal.def(self, '$each', $Set_each$21 = function $$each() { - var $iter = $Set_each$21.$$p, block = $iter || nil, self = this; - - if ($iter) $Set_each$21.$$p = null; - - - if ($iter) $Set_each$21.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("each") - }; - $send(self.hash, 'each_key', [], block.$to_proc()); - return self; - }, $Set_each$21.$$arity = 0); - - Opal.def(self, '$empty?', $Set_empty$ques$22 = function() { - var self = this; - - return self.hash['$empty?']() - }, $Set_empty$ques$22.$$arity = 0); - - Opal.def(self, '$eql?', $Set_eql$ques$23 = function(other) { - var $$24, self = this; - - return self.hash['$eql?']($send(other, 'instance_eval', [], ($$24 = function(){var self = $$24.$$s || this; - if (self.hash == null) self.hash = nil; - - return self.hash}, $$24.$$s = self, $$24.$$arity = 0, $$24))) - }, $Set_eql$ques$23.$$arity = 1); - - Opal.def(self, '$clear', $Set_clear$25 = function $$clear() { - var self = this; - - - self.hash.$clear(); - return self; - }, $Set_clear$25.$$arity = 0); - - Opal.def(self, '$include?', $Set_include$ques$26 = function(o) { - var self = this; - - return self.hash['$include?'](o) - }, $Set_include$ques$26.$$arity = 1); - Opal.alias(self, "member?", "include?"); - - Opal.def(self, '$merge', $Set_merge$27 = function $$merge(enum$) { - var $$28, self = this; - - - $send(enum$, 'each', [], ($$28 = function(item){var self = $$28.$$s || this; - - - - if (item == null) { - item = nil; - }; - return self.$add(item);}, $$28.$$s = self, $$28.$$arity = 1, $$28)); - return self; - }, $Set_merge$27.$$arity = 1); - - Opal.def(self, '$replace', $Set_replace$29 = function $$replace(enum$) { - var self = this; - - - self.$clear(); - self.$merge(enum$); - return self; - }, $Set_replace$29.$$arity = 1); - - Opal.def(self, '$size', $Set_size$30 = function $$size() { - var self = this; - - return self.hash.$size() - }, $Set_size$30.$$arity = 0); - Opal.alias(self, "length", "size"); - - Opal.def(self, '$subtract', $Set_subtract$31 = function $$subtract(enum$) { - var $$32, self = this; - - - $send(enum$, 'each', [], ($$32 = function(item){var self = $$32.$$s || this; - - - - if (item == null) { - item = nil; - }; - return self.$delete(item);}, $$32.$$s = self, $$32.$$arity = 1, $$32)); - return self; - }, $Set_subtract$31.$$arity = 1); - - Opal.def(self, '$|', $Set_$$33 = function(enum$) { - var self = this; - - - if ($truthy(enum$['$respond_to?']("each"))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "value must be enumerable") - }; - return self.$dup().$merge(enum$); - }, $Set_$$33.$$arity = 1); - - Opal.def(self, '$superset?', $Set_superset$ques$34 = function(set) { - var $a, $$35, self = this; - - - ($truthy($a = set['$is_a?']($$($nesting, 'Set'))) ? $a : self.$raise($$($nesting, 'ArgumentError'), "value must be a set")); - if ($truthy($rb_lt(self.$size(), set.$size()))) { - return false}; - return $send(set, 'all?', [], ($$35 = function(o){var self = $$35.$$s || this; +function getMergeFunction(key, options) { + if (!options.customMerge) { + return deepmerge + } + var customMerge = options.customMerge(key); + return typeof customMerge === 'function' ? customMerge : deepmerge +} - - - if (o == null) { - o = nil; - }; - return self['$include?'](o);}, $$35.$$s = self, $$35.$$arity = 1, $$35)); - }, $Set_superset$ques$34.$$arity = 1); - Opal.alias(self, ">=", "superset?"); - - Opal.def(self, '$proper_superset?', $Set_proper_superset$ques$36 = function(set) { - var $a, $$37, self = this; +function getEnumerableOwnPropertySymbols(target) { + return Object.getOwnPropertySymbols + ? Object.getOwnPropertySymbols(target).filter(function(symbol) { + return Object.propertyIsEnumerable.call(target, symbol) + }) + : [] +} - - ($truthy($a = set['$is_a?']($$($nesting, 'Set'))) ? $a : self.$raise($$($nesting, 'ArgumentError'), "value must be a set")); - if ($truthy($rb_le(self.$size(), set.$size()))) { - return false}; - return $send(set, 'all?', [], ($$37 = function(o){var self = $$37.$$s || this; +function getKeys(target) { + return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) +} - - - if (o == null) { - o = nil; - }; - return self['$include?'](o);}, $$37.$$s = self, $$37.$$arity = 1, $$37)); - }, $Set_proper_superset$ques$36.$$arity = 1); - Opal.alias(self, ">", "proper_superset?"); - - Opal.def(self, '$subset?', $Set_subset$ques$38 = function(set) { - var $a, $$39, self = this; +function propertyIsOnObject(object, property) { + try { + return property in object + } catch(_) { + return false + } +} - - ($truthy($a = set['$is_a?']($$($nesting, 'Set'))) ? $a : self.$raise($$($nesting, 'ArgumentError'), "value must be a set")); - if ($truthy($rb_lt(set.$size(), self.$size()))) { - return false}; - return $send(self, 'all?', [], ($$39 = function(o){var self = $$39.$$s || this; +// Protects from prototype poisoning and unexpected merging up the prototype chain. +function propertyIsUnsafe(target, key) { + return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, + && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, + && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. +} - - - if (o == null) { - o = nil; - }; - return set['$include?'](o);}, $$39.$$s = self, $$39.$$arity = 1, $$39)); - }, $Set_subset$ques$38.$$arity = 1); - Opal.alias(self, "<=", "subset?"); - - Opal.def(self, '$proper_subset?', $Set_proper_subset$ques$40 = function(set) { - var $a, $$41, self = this; +function mergeObject(target, source, options) { + var destination = {}; + if (options.isMergeableObject(target)) { + getKeys(target).forEach(function(key) { + destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); + }); + } + getKeys(source).forEach(function(key) { + if (propertyIsUnsafe(target, key)) { + return + } - - ($truthy($a = set['$is_a?']($$($nesting, 'Set'))) ? $a : self.$raise($$($nesting, 'ArgumentError'), "value must be a set")); - if ($truthy($rb_le(set.$size(), self.$size()))) { - return false}; - return $send(self, 'all?', [], ($$41 = function(o){var self = $$41.$$s || this; + if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { + destination[key] = getMergeFunction(key, options)(target[key], source[key], options); + } else { + destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); + } + }); + return destination +} - - - if (o == null) { - o = nil; - }; - return set['$include?'](o);}, $$41.$$s = self, $$41.$$arity = 1, $$41)); - }, $Set_proper_subset$ques$40.$$arity = 1); - Opal.alias(self, "<", "proper_subset?"); - Opal.alias(self, "+", "|"); - Opal.alias(self, "union", "|"); - return (Opal.def(self, '$to_a', $Set_to_a$42 = function $$to_a() { - var self = this; +function deepmerge(target, source, options) { + options = options || {}; + options.arrayMerge = options.arrayMerge || defaultArrayMerge; + options.isMergeableObject = options.isMergeableObject || isMergeableObject; + // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() + // implementations can use it. The caller may not replace it. + options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; - return self.hash.$keys() - }, $Set_to_a$42.$$arity = 0), nil) && 'to_a'; - })($nesting[0], null, $nesting); - return (function($base, $parent_nesting) { - var self = $module($base, 'Enumerable'); + var sourceIsArray = Array.isArray(source); + var targetIsArray = Array.isArray(target); + var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; - var $nesting = [self].concat($parent_nesting), $Enumerable_to_set$43; + if (!sourceAndTargetTypesMatch) { + return cloneUnlessOtherwiseSpecified(source, options) + } else if (sourceIsArray) { + return options.arrayMerge(target, source, options) + } else { + return mergeObject(target, source, options) + } +} - - Opal.def(self, '$to_set', $Enumerable_to_set$43 = function $$to_set($a, $b) { - var $iter = $Enumerable_to_set$43.$$p, block = $iter || nil, $post_args, klass, args, self = this; +deepmerge.all = function deepmergeAll(array, options) { + if (!Array.isArray(array)) { + throw new Error('first argument should be an array') + } - if ($iter) $Enumerable_to_set$43.$$p = null; - - - if ($iter) $Enumerable_to_set$43.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - if ($post_args.length > 0) { - klass = $post_args[0]; - $post_args.splice(0, 1); - } - if (klass == null) { - klass = $$($nesting, 'Set'); - }; - - args = $post_args;; - return $send(klass, 'new', [self].concat(Opal.to_a(args)), block.$to_proc()); - }, $Enumerable_to_set$43.$$arity = -1) - })($nesting[0], $nesting); + return array.reduce(function(prev, next) { + return deepmerge(prev, next, options) + }, {}) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/kernel"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $send = Opal.send; - - Opal.add_stubs(['$new']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); +var deepmerge_1 = deepmerge; - var $nesting = [self].concat($parent_nesting), $Kernel_open$1, $Kernel___dir__$2; +module.exports = deepmerge_1; - - - Opal.def(self, '$open', $Kernel_open$1 = function $$open(path, $a) { - var $post_args, rest, $iter = $Kernel_open$1.$$p, $yield = $iter || nil, self = this, file = nil; - if ($iter) $Kernel_open$1.$$p = null; - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - rest = $post_args;; - file = $send($$($nesting, 'File'), 'new', [path].concat(Opal.to_a(rest))); - if (($yield !== nil)) { - return Opal.yield1($yield, file); - } else { - return file - }; - }, $Kernel_open$1.$$arity = -2); - - Opal.def(self, '$__dir__', $Kernel___dir__$2 = function $$__dir__() { - var self = this; +/***/ }), - return "" - }, $Kernel___dir__$2.$$arity = 0); - })($nesting[0], $nesting) -}; +/***/ 5803: +/***/ ((__unused_webpack_module, exports) => { -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/file"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $gvars = Opal.gvars; +"use strict"; - Opal.add_stubs(['$attr_reader', '$delete', '$gsub', '$read', '$size', '$to_enum', '$chomp', '$each_line', '$readlines', '$split']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'File'); +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.attributeNames = exports.elementNames = void 0; +exports.elementNames = new Map([ + "altGlyph", + "altGlyphDef", + "altGlyphItem", + "animateColor", + "animateMotion", + "animateTransform", + "clipPath", + "feBlend", + "feColorMatrix", + "feComponentTransfer", + "feComposite", + "feConvolveMatrix", + "feDiffuseLighting", + "feDisplacementMap", + "feDistantLight", + "feDropShadow", + "feFlood", + "feFuncA", + "feFuncB", + "feFuncG", + "feFuncR", + "feGaussianBlur", + "feImage", + "feMerge", + "feMergeNode", + "feMorphology", + "feOffset", + "fePointLight", + "feSpecularLighting", + "feSpotLight", + "feTile", + "feTurbulence", + "foreignObject", + "glyphRef", + "linearGradient", + "radialGradient", + "textPath", +].map(function (val) { return [val.toLowerCase(), val]; })); +exports.attributeNames = new Map([ + "definitionURL", + "attributeName", + "attributeType", + "baseFrequency", + "baseProfile", + "calcMode", + "clipPathUnits", + "diffuseConstant", + "edgeMode", + "filterUnits", + "glyphRef", + "gradientTransform", + "gradientUnits", + "kernelMatrix", + "kernelUnitLength", + "keyPoints", + "keySplines", + "keyTimes", + "lengthAdjust", + "limitingConeAngle", + "markerHeight", + "markerUnits", + "markerWidth", + "maskContentUnits", + "maskUnits", + "numOctaves", + "pathLength", + "patternContentUnits", + "patternTransform", + "patternUnits", + "pointsAtX", + "pointsAtY", + "pointsAtZ", + "preserveAlpha", + "preserveAspectRatio", + "primitiveUnits", + "refX", + "refY", + "repeatCount", + "repeatDur", + "requiredExtensions", + "requiredFeatures", + "specularConstant", + "specularExponent", + "spreadMethod", + "startOffset", + "stdDeviation", + "stitchTiles", + "surfaceScale", + "systemLanguage", + "tableValues", + "targetX", + "targetY", + "textLength", + "viewBox", + "viewTarget", + "xChannelSelector", + "yChannelSelector", + "zoomAndPan", +].map(function (val) { return [val.toLowerCase(), val]; })); - var $nesting = [self].concat($parent_nesting), $File_initialize$1, $File_read$2, $File_each_line$3, $File_readlines$4; - self.$$prototype.eof = self.$$prototype.path = nil; - - self.$attr_reader("eof"); - self.$attr_reader("lineno"); - self.$attr_reader("path"); - - Opal.def(self, '$initialize', $File_initialize$1 = function $$initialize(path, flags) { - var self = this, encoding_flag_regexp = nil; +/***/ }), - - - if (flags == null) { - flags = "r"; - }; - self.path = path; - self.contents = nil; - self.eof = false; - self.lineno = 0; - flags = flags.$delete("b"); - encoding_flag_regexp = /:(.*)/; - flags = flags.$gsub(encoding_flag_regexp, ""); - return (self.flags = flags); - }, $File_initialize$1.$$arity = -2); - - Opal.def(self, '$read', $File_read$2 = function $$read() { - var self = this, res = nil; +/***/ 9943: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { - if ($truthy(self.eof)) { - return "" - } else { - - res = $$($nesting, 'File').$read(self.path); - self.eof = true; - self.lineno = res.$size(); - return res; - } - }, $File_read$2.$$arity = 0); - - Opal.def(self, '$each_line', $File_each_line$3 = function $$each_line(separator) { - var $iter = $File_each_line$3.$$p, block = $iter || nil, self = this, lines = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; +"use strict"; - if ($iter) $File_each_line$3.$$p = null; - - - if ($iter) $File_each_line$3.$$p = null;; - - if (separator == null) { - separator = $gvars["/"]; - }; - if ($truthy(self.eof)) { - return (function() {if ((block !== nil)) { - return self - } else { - return [].$to_enum() - }; return nil; })()}; - if ((block !== nil)) { - - lines = $$($nesting, 'File').$read(self.path); - - self.eof = false; - self.lineno = 0; - var chomped = lines.$chomp(), - trailing = lines.length != chomped.length, - splitted = chomped.split(separator); - for (var i = 0, length = splitted.length; i < length; i++) { - self.lineno += 1; - if (i < length - 1 || trailing) { - Opal.yield1(block, splitted[i] + separator); - } - else { - Opal.yield1(block, splitted[i]); - } +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; } - self.eof = true; - ; - return self; - } else { - return self.$read().$each_line() - }; - }, $File_each_line$3.$$arity = -1); - - Opal.def(self, '$readlines', $File_readlines$4 = function $$readlines() { - var self = this; - - return $$($nesting, 'File').$readlines(self.path) - }, $File_readlines$4.$$arity = 0); - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $readlines$5, $file$ques$6, $readable$ques$7, $read$8; - - - - Opal.def(self, '$readlines', $readlines$5 = function $$readlines(path, separator) { - var self = this, content = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; - - - - if (separator == null) { - separator = $gvars["/"]; - }; - content = $$($nesting, 'File').$read(path); - return content.$split(separator); - }, $readlines$5.$$arity = -2); - - Opal.def(self, '$file?', $file$ques$6 = function(path) { - var self = this; - - return true - }, $file$ques$6.$$arity = 1); - - Opal.def(self, '$readable?', $readable$ques$7 = function(path) { - var self = this; - - return true - }, $readable$ques$7.$$arity = 1); - return (Opal.def(self, '$read', $read$8 = function $$read(path) { - var self = this; - - return "" - }, $read$8.$$arity = 1), nil) && 'read'; - })(Opal.get_singleton_class(self), $nesting); - })($nesting[0], null, $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IO'); - - var $nesting = [self].concat($parent_nesting), $IO_read$9; - - return (Opal.defs(self, '$read', $IO_read$9 = function $$read(path) { - var self = this; - - return $$($nesting, 'File').$read(path) - }, $IO_read$9.$$arity = 1), nil) && 'read' - })($nesting[0], null, $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/match_data"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send; - - Opal.add_stubs(['$[]=', '$-']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'MatchData'); - - var $nesting = [self].concat($parent_nesting), $MatchData_$$$eq$1; - - self.$$prototype.matches = nil; - return (Opal.def(self, '$[]=', $MatchData_$$$eq$1 = function(idx, val) { - var self = this, $writer = nil; - - - $writer = [idx, val]; - $send(self.matches, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $MatchData_$$$eq$1.$$arity = 2), nil) && '[]=' - })($nesting[0], null, $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/string"] = function(Opal) { - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; - - Opal.add_stubs(['$method_defined?', '$<', '$length', '$bytes', '$to_s', '$byteslice', '$==', '$>=', '$-', '$_original_byteslice', '$_original_unpack']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'String'); - - var $nesting = [self].concat($parent_nesting), $String_limit_bytesize$1, $String_byteslice$2, $String_unpack$3; - - - if ($truthy(self['$method_defined?']("limit_bytesize"))) { - } else { - - Opal.def(self, '$limit_bytesize', $String_limit_bytesize$1 = function $$limit_bytesize(size) { - var self = this, result = nil; - - - if ($truthy($rb_lt(size, self.$bytes().$length()))) { - } else { - return self.$to_s() - }; - result = self.$byteslice(0, size); - return result.$to_s(); - }, $String_limit_bytesize$1.$$arity = 1) - }; - if ($truthy(self['$method_defined?']("limit"))) { - } else { - Opal.alias(self, "limit", "limit_bytesize") + return t; }; - Opal.alias(self, "_original_byteslice", "byteslice"); - - Opal.def(self, '$byteslice', $String_byteslice$2 = function $$byteslice(index, length) { - var $a, $b, self = this; - - - - if (length == null) { - length = 1; - }; - if ($truthy(($truthy($a = (($b = index['$=='](3)) ? $rb_ge(length, index) : index['$=='](3))) ? self.charCodeAt() === 65279 : $a))) { - return (self.substr(1)).$byteslice(0, $rb_minus(length, 3)) - } else { - return self.$_original_byteslice(index, length) - }; - }, $String_byteslice$2.$$arity = -2); - Opal.alias(self, "_original_unpack", "unpack"); - return (Opal.def(self, '$unpack', $String_unpack$3 = function $$unpack(format) { - var self = this; - - if (format['$==']("C3")) { - if ($truthy(self.charCodeAt() === 65279)) { - return [239, 187, 191] - } else { - - var bytes = [] - for (var i=0; i < 3; i++) { - if (i < self.length) { - bytes.push(self.charCodeAt(i)) - } else { - bytes.push(nil) - } - } - return bytes - - } - } else { - return self.$_original_unpack(format) - } - }, $String_unpack$3.$$arity = 1), nil) && 'unpack'; - })($nesting[0], null, $nesting) + return __assign.apply(this, arguments); }; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/uri"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; - - Opal.add_stubs(['$extend']); - return (function($base, $parent_nesting) { - var self = $module($base, 'URI'); - - var $nesting = [self].concat($parent_nesting), $URI_parse$1, $URI_path$2; - - - Opal.defs(self, '$parse', $URI_parse$1 = function $$parse(str) { - var self = this; - - return str.$extend($$($nesting, 'URI')) - }, $URI_parse$1.$$arity = 1); - - Opal.def(self, '$path', $URI_path$2 = function $$path() { - var self = this; - - return self - }, $URI_path$2.$$arity = 0); - })($nesting[0], $nesting) +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; }; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.render = void 0; +/* + * Module dependencies + */ +var ElementType = __importStar(__nccwpck_require__(1108)); +var entities_1 = __nccwpck_require__(8467); +/** + * Mixed-case SVG and MathML tags & attributes + * recognized by the HTML parser. + * + * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign + */ +var foreignNames_js_1 = __nccwpck_require__(5803); +var unencodedElements = new Set([ + "style", + "script", + "xmp", + "iframe", + "noembed", + "noframes", + "plaintext", + "noscript", +]); +function replaceQuotes(value) { + return value.replace(/"/g, """); +} +/** + * Format attributes + */ +function formatAttributes(attributes, opts) { + var _a; + if (!attributes) + return; + var encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false + ? replaceQuotes + : opts.xmlMode || opts.encodeEntities !== "utf8" + ? entities_1.encodeXML + : entities_1.escapeAttribute; + return Object.keys(attributes) + .map(function (key) { + var _a, _b; + var value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : ""; + if (opts.xmlMode === "foreign") { + /* Fix up mixed-case attribute names */ + key = (_b = foreignNames_js_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key; + } + if (!opts.emptyAttrs && !opts.xmlMode && value === "") { + return key; + } + return "".concat(key, "=\"").concat(encode(value), "\""); + }) + .join(" "); +} +/** + * Self-enclosing tags + */ +var singleTag = new Set([ + "area", + "base", + "basefont", + "br", + "col", + "command", + "embed", + "frame", + "hr", + "img", + "input", + "isindex", + "keygen", + "link", + "meta", + "param", + "source", + "track", + "wbr", +]); +/** + * Renders a DOM node or an array of DOM nodes to a string. + * + * Can be thought of as the equivalent of the `outerHTML` of the passed node(s). + * + * @param node Node to be rendered. + * @param options Changes serialization behavior + */ +function render(node, options) { + if (options === void 0) { options = {}; } + var nodes = "length" in node ? node : [node]; + var output = ""; + for (var i = 0; i < nodes.length; i++) { + output += renderNode(nodes[i], options); + } + return output; +} +exports.render = render; +exports["default"] = render; +function renderNode(node, options) { + switch (node.type) { + case ElementType.Root: + return render(node.children, options); + // @ts-expect-error We don't use `Doctype` yet + case ElementType.Doctype: + case ElementType.Directive: + return renderDirective(node); + case ElementType.Comment: + return renderComment(node); + case ElementType.CDATA: + return renderCdata(node); + case ElementType.Script: + case ElementType.Style: + case ElementType.Tag: + return renderTag(node, options); + case ElementType.Text: + return renderText(node, options); + } +} +var foreignModeIntegrationPoints = new Set([ + "mi", + "mo", + "mn", + "ms", + "mtext", + "annotation-xml", + "foreignObject", + "desc", + "title", +]); +var foreignElements = new Set(["svg", "math"]); +function renderTag(elem, opts) { + var _a; + // Handle SVG / MathML in HTML + if (opts.xmlMode === "foreign") { + /* Fix up mixed-case element names */ + elem.name = (_a = foreignNames_js_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name; + /* Exit foreign mode at integration points */ + if (elem.parent && + foreignModeIntegrationPoints.has(elem.parent.name)) { + opts = __assign(__assign({}, opts), { xmlMode: false }); + } + } + if (!opts.xmlMode && foreignElements.has(elem.name)) { + opts = __assign(__assign({}, opts), { xmlMode: "foreign" }); + } + var tag = "<".concat(elem.name); + var attribs = formatAttributes(elem.attribs, opts); + if (attribs) { + tag += " ".concat(attribs); + } + if (elem.children.length === 0 && + (opts.xmlMode + ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags + opts.selfClosingTags !== false + : // User explicitly asked for self-closing tags, even in HTML mode + opts.selfClosingTags && singleTag.has(elem.name))) { + if (!opts.xmlMode) + tag += " "; + tag += "/>"; + } + else { + tag += ">"; + if (elem.children.length > 0) { + tag += render(elem.children, opts); + } + if (opts.xmlMode || !singleTag.has(elem.name)) { + tag += ""); + } + } + return tag; +} +function renderDirective(elem) { + return "<".concat(elem.data, ">"); +} +function renderText(elem, opts) { + var _a; + var data = elem.data || ""; + // If entities weren't decoded, no need to encode them back + if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false && + !(!opts.xmlMode && + elem.parent && + unencodedElements.has(elem.parent.name))) { + data = + opts.xmlMode || opts.encodeEntities !== "utf8" + ? (0, entities_1.encodeXML)(data) + : (0, entities_1.escapeText)(data); + } + return data; +} +function renderCdata(elem) { + return ""); +} +function renderComment(elem) { + return ""); +} -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/base64"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $hash2 = Opal.hash2, $truthy = Opal.truthy; - Opal.add_stubs(['$delete']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Base64'); +/***/ }), - var $nesting = [self].concat($parent_nesting), $Base64_decode64$1, $Base64_encode64$2, $Base64_strict_decode64$3, $Base64_strict_encode64$4, $Base64_urlsafe_decode64$5, $Base64_urlsafe_encode64$6; +/***/ 1108: +/***/ ((__unused_webpack_module, exports) => { - - - var encode, decode; - encode = Opal.global.btoa || function (input) { - var buffer; - if (input instanceof Buffer) { - buffer = input; - } else { - buffer = Buffer.from(input.toString(), 'binary'); - } - return buffer.toString('base64'); - }; - decode = Opal.global.atob || function (input) { - return Buffer.from(input, 'base64').toString('binary'); - }; - ; - Opal.defs(self, '$decode64', $Base64_decode64$1 = function $$decode64(string) { - var self = this; +"use strict"; - return decode(string.replace(/\r?\n/g, '')); - }, $Base64_decode64$1.$$arity = 1); - Opal.defs(self, '$encode64', $Base64_encode64$2 = function $$encode64(string) { - var self = this; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0; +/** Types of elements found in htmlparser2's DOM */ +var ElementType; +(function (ElementType) { + /** Type for the root element of a document */ + ElementType["Root"] = "root"; + /** Type for Text */ + ElementType["Text"] = "text"; + /** Type for */ + ElementType["Directive"] = "directive"; + /** Type for */ + ElementType["Comment"] = "comment"; + /** Type for \n" + ((function() {if ($truthy(doc['$attr?']("highlightjs-languages"))) { - return $send(doc.$attr("highlightjs-languages").$split(","), 'map', [], ($$6 = function(lang){var self = $$6.$$s || this; - - - - if (lang == null) { - lang = nil; - }; - return "" + "\n";}, $$6.$$s = self, $$6.$$arity = 1, $$6)).$join() - } else { - return "" - }; return nil; })()) + "" - }; - }, $HighlightJsAdapter_docinfo$5.$$arity = 3), nil) && 'docinfo'; - })($$($nesting, 'SyntaxHighlighter'), $$$($$($nesting, 'SyntaxHighlighter'), 'Base'), $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/syntax_highlighter"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $klass = Opal.klass; - - Opal.add_stubs(['$attr_reader', '$raise', '$class', '$extend', '$private_class_method', '$register', '$map', '$to_s', '$each', '$[]=', '$registry', '$-', '$[]', '$for', '$===', '$new', '$name', '$private', '$include', '$==', '$delete', '$join', '$content']); - - (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); - - (function($base, $parent_nesting) { - var self = $module($base, 'SyntaxHighlighter'); - - var $nesting = [self].concat($parent_nesting), $SyntaxHighlighter_initialize$1, $SyntaxHighlighter_docinfo$ques$2, $SyntaxHighlighter_docinfo$3, $SyntaxHighlighter_highlight$ques$4, $SyntaxHighlighter_highlight$5, $SyntaxHighlighter_format$6, $SyntaxHighlighter_write_stylesheet$ques$7, $SyntaxHighlighter_write_stylesheet$8, $SyntaxHighlighter_included$9; - - - self.$attr_reader("name"); - - Opal.def(self, '$initialize', $SyntaxHighlighter_initialize$1 = function $$initialize(name, backend, opts) { - var self = this; - - - - if (backend == null) { - backend = "html5"; - }; - - if (opts == null) { - opts = $hash2([], {}); - }; - return (self.name = (self.pre_class = name)); - }, $SyntaxHighlighter_initialize$1.$$arity = -2); - - Opal.def(self, '$docinfo?', $SyntaxHighlighter_docinfo$ques$2 = function(location) { - var self = this; - - return nil - }, $SyntaxHighlighter_docinfo$ques$2.$$arity = 1); - - Opal.def(self, '$docinfo', $SyntaxHighlighter_docinfo$3 = function $$docinfo(location, doc, opts) { - var self = this; - - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("docinfo") + " method since #docinfo? returns true") - }, $SyntaxHighlighter_docinfo$3.$$arity = 3); - - Opal.def(self, '$highlight?', $SyntaxHighlighter_highlight$ques$4 = function() { - var self = this; - - return nil - }, $SyntaxHighlighter_highlight$ques$4.$$arity = 0); - - Opal.def(self, '$highlight', $SyntaxHighlighter_highlight$5 = function $$highlight(node, source, lang, opts) { - var self = this; - - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("highlight") + " method since #highlight? returns true") - }, $SyntaxHighlighter_highlight$5.$$arity = 4); - - Opal.def(self, '$format', $SyntaxHighlighter_format$6 = function $$format(node, lang, opts) { - var self = this; - - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("format") + " method") - }, $SyntaxHighlighter_format$6.$$arity = 3); - - Opal.def(self, '$write_stylesheet?', $SyntaxHighlighter_write_stylesheet$ques$7 = function(doc) { - var self = this; - - return nil - }, $SyntaxHighlighter_write_stylesheet$ques$7.$$arity = 1); - - Opal.def(self, '$write_stylesheet', $SyntaxHighlighter_write_stylesheet$8 = function $$write_stylesheet(doc, to_dir) { - var self = this; - - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("write_stylesheet") + " method since #write_stylesheet? returns true") - }, $SyntaxHighlighter_write_stylesheet$8.$$arity = 2); - Opal.defs(self, '$included', $SyntaxHighlighter_included$9 = function $$included(into) { - var self = this; - - return into.$extend($$($nesting, 'Config')) - }, $SyntaxHighlighter_included$9.$$arity = 1); - self.$private_class_method("included"); - (function($base, $parent_nesting) { - var self = $module($base, 'Config'); - - var $nesting = [self].concat($parent_nesting), $Config_register_for$10; - - - Opal.def(self, '$register_for', $Config_register_for$10 = function $$register_for($a) { - var $post_args, names, $$11, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - return $send($$($nesting, 'SyntaxHighlighter'), 'register', [self].concat(Opal.to_a($send(names, 'map', [], ($$11 = function(name){var self = $$11.$$s || this; - - - - if (name == null) { - name = nil; - }; - return name.$to_s();}, $$11.$$s = self, $$11.$$arity = 1, $$11))))); - }, $Config_register_for$10.$$arity = -1) - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Factory'); - - var $nesting = [self].concat($parent_nesting), $Factory_register$12, $Factory_for$14, $Factory_create$15, $Factory_registry$16; - - - - Opal.def(self, '$register', $Factory_register$12 = function $$register(syntax_highlighter, $a) { - var $post_args, names, $$13, self = this; - - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - names = $post_args;; - return $send(names, 'each', [], ($$13 = function(name){var self = $$13.$$s || this, $writer = nil; - - - - if (name == null) { - name = nil; - }; - $writer = [name, syntax_highlighter]; - $send(self.$registry(), '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$13.$$s = self, $$13.$$arity = 1, $$13)); - }, $Factory_register$12.$$arity = -2); - - Opal.def(self, '$for', $Factory_for$14 = function(name) { - var self = this; - - return self.$registry()['$[]'](name) - }, $Factory_for$14.$$arity = 1); - - Opal.def(self, '$create', $Factory_create$15 = function $$create(name, backend, opts) { - var self = this, syntax_hl = nil; - - - - if (backend == null) { - backend = "html5"; - }; - - if (opts == null) { - opts = $hash2([], {}); - }; - if ($truthy((syntax_hl = self.$for(name)))) { - - if ($truthy($$$('::', 'Class')['$==='](syntax_hl))) { - syntax_hl = syntax_hl.$new(name, backend, opts)}; - if ($truthy(syntax_hl.$name())) { - } else { - self.$raise($$$('::', 'NameError'), "" + (syntax_hl.$class()) + " must specify a value for `name'") - }; - return syntax_hl; - } else { - return nil - }; - }, $Factory_create$15.$$arity = -2); - self.$private(); - - Opal.def(self, '$registry', $Factory_registry$16 = function $$registry() { - var self = this; - - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'Factory')) + " subclass " + (self.$class()) + " must implement the #" + ("registry") + " method") - }, $Factory_registry$16.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'CustomFactory'); - - var $nesting = [self].concat($parent_nesting), $CustomFactory_initialize$17; - - - self.$include($$($nesting, 'Factory')); - - Opal.def(self, '$initialize', $CustomFactory_initialize$17 = function $$initialize(seed_registry) { - var $a, self = this; - - - - if (seed_registry == null) { - seed_registry = nil; - }; - return (self.registry = ($truthy($a = seed_registry) ? $a : $hash2([], {}))); - }, $CustomFactory_initialize$17.$$arity = -1); - self.$private(); - return self.$attr_reader("registry"); - })($nesting[0], null, $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'DefaultFactory'); - - var $nesting = [self].concat($parent_nesting), $DefaultFactory_registry$18; - - - self.$include($$($nesting, 'Factory')); - (Opal.class_variable_set($nesting[0], '@@registry', $hash2([], {}))); - self.$private(); - - Opal.def(self, '$registry', $DefaultFactory_registry$18 = function $$registry() { - var $a, self = this; - - return (($a = $nesting[0].$$cvars['@@registry']) == null ? nil : $a) - }, $DefaultFactory_registry$18.$$arity = 0); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - } else { - nil - }; - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'DefaultFactoryProxy'); - - var $nesting = [self].concat($parent_nesting); - - - self.$include($$($nesting, 'DefaultFactory')); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - return nil - } else { - return nil - }; - })($nesting[0], $$($nesting, 'CustomFactory'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Base'); - - var $nesting = [self].concat($parent_nesting), $Base_format$19; - - self.$$prototype.pre_class = nil; - - self.$include($$($nesting, 'SyntaxHighlighter')); - return (Opal.def(self, '$format', $Base_format$19 = function $$format(node, lang, opts) { - var $$20, $$21, self = this, class_attr_val = nil, transform = nil, pre = nil, code = nil, $writer = nil; - - - class_attr_val = (function() {if ($truthy(opts['$[]']("nowrap"))) { - return "" + (self.pre_class) + " highlight nowrap" - } else { - return "" + (self.pre_class) + " highlight" - }; return nil; })(); - if ($truthy((transform = opts['$[]']("transform")))) { - - transform['$[]']((pre = $hash2(["class"], {"class": class_attr_val})), (code = (function() {if ($truthy(lang)) { - return $hash2(["data-lang"], {"data-lang": lang}) - } else { - return $hash2([], {}) - }; return nil; })())); - if ($truthy((lang = code.$delete("data-lang")))) { - - $writer = ["data-lang", lang]; - $send(code, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];}; - return "" + "" + (node.$content()) + ""; - } else { - return "" + "
" + (node.$content()) + "
" - }; - }, $Base_format$19.$$arity = 3), nil) && 'format'; - })($nesting[0], null, $nesting); - self.$extend($$($nesting, 'DefaultFactory')); - })($nesting[0], $nesting) - })($nesting[0], $nesting); - self.$require("asciidoctor/syntax_highlighter.rb"+ '/../' + "syntax_highlighter/highlightjs"); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - return nil - } else { - return nil - }; -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/timings"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $gvars = Opal.gvars; - - Opal.add_stubs(['$now', '$[]=', '$-', '$delete', '$reduce', '$+', '$[]', '$>', '$time', '$puts', '$sprintf', '$to_f', '$read_parse', '$convert', '$read_parse_convert', '$private', '$const_defined?', '$==', '$clock_gettime']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Timings'); - - var $nesting = [self].concat($parent_nesting), $Timings_initialize$1, $Timings_start$2, $Timings_record$3, $Timings_time$4, $Timings_read$6, $Timings_parse$7, $Timings_read_parse$8, $Timings_convert$9, $Timings_read_parse_convert$10, $Timings_write$11, $Timings_total$12, $Timings_print_report$13, $a, $b, $c, $d, $e, $Timings_now$14, $Timings_now$15; - - self.$$prototype.timers = self.$$prototype.log = nil; - - - Opal.def(self, '$initialize', $Timings_initialize$1 = function $$initialize() { - var self = this; - - - self.log = $hash2([], {}); - return (self.timers = $hash2([], {})); - }, $Timings_initialize$1.$$arity = 0); - - Opal.def(self, '$start', $Timings_start$2 = function $$start(key) { - var self = this, $writer = nil; - - - $writer = [key, self.$now()]; - $send(self.timers, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $Timings_start$2.$$arity = 1); - - Opal.def(self, '$record', $Timings_record$3 = function $$record(key) { - var self = this, $writer = nil; - - - $writer = [key, $rb_minus(self.$now(), self.timers.$delete(key))]; - $send(self.log, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $Timings_record$3.$$arity = 1); - - Opal.def(self, '$time', $Timings_time$4 = function $$time($a) { - var $post_args, keys, $$5, self = this, time = nil; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - keys = $post_args;; - time = $send(keys, 'reduce', [0], ($$5 = function(sum, key){var self = $$5.$$s || this, $b; - if (self.log == null) self.log = nil; - - - - if (sum == null) { - sum = nil; - }; - - if (key == null) { - key = nil; - }; - return $rb_plus(sum, ($truthy($b = self.log['$[]'](key)) ? $b : 0));}, $$5.$$s = self, $$5.$$arity = 2, $$5)); - if ($truthy($rb_gt(time, 0))) { - return time - } else { - return nil - }; - }, $Timings_time$4.$$arity = -1); - - Opal.def(self, '$read', $Timings_read$6 = function $$read() { - var self = this; - - return self.$time("read") - }, $Timings_read$6.$$arity = 0); - - Opal.def(self, '$parse', $Timings_parse$7 = function $$parse() { - var self = this; - - return self.$time("parse") - }, $Timings_parse$7.$$arity = 0); - - Opal.def(self, '$read_parse', $Timings_read_parse$8 = function $$read_parse() { - var self = this; - - return self.$time("read", "parse") - }, $Timings_read_parse$8.$$arity = 0); - - Opal.def(self, '$convert', $Timings_convert$9 = function $$convert() { - var self = this; - - return self.$time("convert") - }, $Timings_convert$9.$$arity = 0); - - Opal.def(self, '$read_parse_convert', $Timings_read_parse_convert$10 = function $$read_parse_convert() { - var self = this; - - return self.$time("read", "parse", "convert") - }, $Timings_read_parse_convert$10.$$arity = 0); - - Opal.def(self, '$write', $Timings_write$11 = function $$write() { - var self = this; - - return self.$time("write") - }, $Timings_write$11.$$arity = 0); - - Opal.def(self, '$total', $Timings_total$12 = function $$total() { - var self = this; - - return self.$time("read", "parse", "convert", "write") - }, $Timings_total$12.$$arity = 0); - - Opal.def(self, '$print_report', $Timings_print_report$13 = function $$print_report(to, subject) { - var self = this; - if ($gvars.stdout == null) $gvars.stdout = nil; - - - - if (to == null) { - to = $gvars.stdout; - }; - - if (subject == null) { - subject = nil; - }; - if ($truthy(subject)) { - to.$puts("" + "Input file: " + (subject))}; - to.$puts("" + " Time to read and parse source: " + (self.$sprintf("%05.5f", self.$read_parse().$to_f()))); - to.$puts("" + " Time to convert document: " + (self.$sprintf("%05.5f", self.$convert().$to_f()))); - return to.$puts("" + " Total time (read, parse and convert): " + (self.$sprintf("%05.5f", self.$read_parse_convert().$to_f()))); - }, $Timings_print_report$13.$$arity = -1); - self.$private(); - if ($truthy(($truthy($a = $$$('::', 'Process')['$const_defined?']("CLOCK_MONOTONIC", false)) ? ((($b = $$$('::', 'Process', 'skip_raise')) && ($c = $b, $c) && ($d = $c) && ((($e = $d.$clock_gettime) && !$e.$$stub) || $d['$respond_to_missing?']('clock_gettime'))) ? 'method' : nil)['$==']("method") : $a))) { - - Opal.const_set($nesting[0], 'CLOCK_ID', $$$($$$('::', 'Process'), 'CLOCK_MONOTONIC')); - return (Opal.def(self, '$now', $Timings_now$14 = function $$now() { - var self = this; - - return $$$('::', 'Process').$clock_gettime($$($nesting, 'CLOCK_ID')) - }, $Timings_now$14.$$arity = 0), nil) && 'now'; - } else { - return (Opal.def(self, '$now', $Timings_now$15 = function $$now() { - var self = this; - - return $$$('::', 'Time').$now() - }, $Timings_now$15.$$arity = 0), nil) && 'now' - }; - })($nesting[0], null, $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/converter/composite"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy; - - Opal.add_stubs(['$attr_reader', '$each', '$respond_to?', '$composed', '$init_backend_traits', '$backend_traits', '$new', '$find_converter', '$[]=', '$-', '$convert', '$converter_for', '$node_name', '$[]', '$handles?', '$raise']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'CompositeConverter'); - - var $nesting = [self].concat($parent_nesting), $CompositeConverter_initialize$1, $CompositeConverter_convert$4, $CompositeConverter_converter_for$5, $CompositeConverter_find_converter$6; - - self.$$prototype.converter_cache = self.$$prototype.converters = nil; - - self.$attr_reader("converters"); - - Opal.def(self, '$initialize', $CompositeConverter_initialize$1 = function $$initialize(backend, $a, $b) { - var $post_args, $kwargs, converters, backend_traits_source, $$2, $$3, self = this; - - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - $kwargs = Opal.extract_kwargs($post_args); - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - converters = $post_args;; - - backend_traits_source = $kwargs.$$smap["backend_traits_source"]; - if (backend_traits_source == null) { - backend_traits_source = nil - }; - self.backend = backend; - $send((self.converters = converters), 'each', [], ($$2 = function(converter){var self = $$2.$$s || this; - - - - if (converter == null) { - converter = nil; - }; - if ($truthy(converter['$respond_to?']("composed"))) { - return converter.$composed(self) - } else { - return nil - };}, $$2.$$s = self, $$2.$$arity = 1, $$2)); - if ($truthy(backend_traits_source)) { - self.$init_backend_traits(backend_traits_source.$backend_traits())}; - return (self.converter_cache = $send($$$('::', 'Hash'), 'new', [], ($$3 = function(hash, key){var self = $$3.$$s || this, $writer = nil; - - - - if (hash == null) { - hash = nil; - }; - - if (key == null) { - key = nil; - }; - $writer = [key, self.$find_converter(key)]; - $send(hash, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$3.$$s = self, $$3.$$arity = 2, $$3))); - }, $CompositeConverter_initialize$1.$$arity = -2); - - Opal.def(self, '$convert', $CompositeConverter_convert$4 = function $$convert(node, transform, opts) { - var $a, self = this; - - - - if (transform == null) { - transform = nil; - }; - - if (opts == null) { - opts = nil; - }; - return self.$converter_for((transform = ($truthy($a = transform) ? $a : node.$node_name()))).$convert(node, transform, opts); - }, $CompositeConverter_convert$4.$$arity = -2); - - Opal.def(self, '$converter_for', $CompositeConverter_converter_for$5 = function $$converter_for(transform) { - var self = this; - - return self.converter_cache['$[]'](transform) - }, $CompositeConverter_converter_for$5.$$arity = 1); - return (Opal.def(self, '$find_converter', $CompositeConverter_find_converter$6 = function $$find_converter(transform) {try { - - var $$7, self = this; - - - $send(self.converters, 'each', [], ($$7 = function(candidate){var self = $$7.$$s || this; - - - - if (candidate == null) { - candidate = nil; - }; - if ($truthy(candidate['$handles?'](transform))) { - Opal.ret(candidate) - } else { - return nil - };}, $$7.$$s = self, $$7.$$arity = 1, $$7)); - return self.$raise("" + "Could not find a converter to handle transform: " + (transform)); - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $CompositeConverter_find_converter$6.$$arity = 1), nil) && 'find_converter'; - })($$($nesting, 'Converter'), $$$($$($nesting, 'Converter'), 'Base'), $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/converter/html5"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $send = Opal.send, $hash2 = Opal.hash2, $truthy = Opal.truthy, $gvars = Opal.gvars; - - Opal.add_stubs(['$register_for', '$default=', '$-', '$==', '$[]', '$init_backend_traits', '$node_name', '$===', '$convert_inline_quoted', '$convert_paragraph', '$convert_inline_anchor', '$convert_section', '$convert_listing', '$convert_literal', '$convert_ulist', '$convert_olist', '$convert_dlist', '$convert_admonition', '$convert_colist', '$convert_embedded', '$convert_example', '$convert_floating_title', '$convert_image', '$convert_inline_break', '$convert_inline_button', '$convert_inline_callout', '$convert_inline_footnote', '$convert_inline_image', '$convert_inline_indexterm', '$convert_inline_kbd', '$convert_inline_menu', '$convert_open', '$convert_page_break', '$convert_preamble', '$convert_quote', '$convert_sidebar', '$convert_stem', '$convert_table', '$convert_thematic_break', '$convert_verse', '$convert_video', '$convert_document', '$convert_toc', '$convert_pass', '$convert_audio', '$empty?', '$attr', '$attr?', '$<<', '$include?', '$sub_replacements', '$gsub', '$extname', '$slice', '$length', '$doctitle', '$normalize_web_path', '$primary_stylesheet_data', '$instance', '$read_contents', '$syntax_highlighter', '$size', '$docinfo', '$id', '$sections?', '$doctype', '$role?', '$role', '$join', '$noheader', '$convert', '$converter', '$generate_manname_section', '$header?', '$notitle', '$title', '$header', '$each', '$authors', '$>', '$name', '$email', '$sub_macros', '$+', '$downcase', '$concat', '$content', '$footnotes?', '$!', '$footnotes', '$index', '$text', '$nofooter', '$docinfo?', '$[]=', '$delete_at', '$inspect', '$!=', '$to_i', '$attributes', '$document', '$sections', '$level', '$caption', '$captioned_title', '$numbered', '$<=', '$<', '$sectname', '$sectnum', '$convert_outline', '$title?', '$icon_uri', '$compact', '$media_uri', '$option?', '$append_boolean_attribute', '$style', '$items', '$blocks?', '$text?', '$chomp', '$safe', '$read_svg_contents', '$alt', '$image_uri', '$encode_attribute_value', '$append_link_constraint_attrs', '$highlight?', '$to_sym', '$format', '$*', '$count', '$start_with?', '$end_with?', '$list_marker_keyword', '$parent', '$warn', '$logger', '$context', '$error', '$new', '$columns', '$to_h', '$rows', '$colspan', '$rowspan', '$unshift', '$shift', '$split', '$pop', '$nil_or_empty?', '$type', '$catalog', '$get_root_document', '$xreftext', '$target', '$reftext', '$chop', '$sub', '$match', '$private', '$upcase', '$nested?', '$parent_document', '$to_s', '$handles?', '$send']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Html5Converter'); - - var $nesting = [self].concat($parent_nesting), $Html5Converter_initialize$1, $Html5Converter_convert$2, $Html5Converter_convert_document$3, $Html5Converter_convert_embedded$6, $Html5Converter_convert_outline$8, $Html5Converter_convert_section$10, $Html5Converter_convert_admonition$11, $Html5Converter_convert_audio$12, $Html5Converter_convert_colist$13, $Html5Converter_convert_dlist$16, $Html5Converter_convert_example$23, $Html5Converter_convert_floating_title$24, $Html5Converter_convert_image$25, $Html5Converter_convert_listing$26, $Html5Converter_convert_literal$27, $Html5Converter_convert_stem$28, $Html5Converter_convert_olist$30, $Html5Converter_convert_open$32, $Html5Converter_convert_page_break$33, $Html5Converter_convert_paragraph$34, $Html5Converter_convert_preamble$35, $Html5Converter_convert_quote$36, $Html5Converter_convert_thematic_break$37, $Html5Converter_convert_sidebar$38, $Html5Converter_convert_table$39, $Html5Converter_convert_toc$44, $Html5Converter_convert_ulist$45, $Html5Converter_convert_verse$47, $Html5Converter_convert_video$48, $Html5Converter_convert_inline_anchor$49, $Html5Converter_convert_inline_break$50, $Html5Converter_convert_inline_button$51, $Html5Converter_convert_inline_callout$52, $Html5Converter_convert_inline_footnote$53, $Html5Converter_convert_inline_image$54, $Html5Converter_convert_inline_indexterm$55, $Html5Converter_convert_inline_kbd$56, $Html5Converter_convert_inline_menu$57, $Html5Converter_convert_inline_quoted$58, $Html5Converter_read_svg_contents$59, $Html5Converter_append_boolean_attribute$61, $Html5Converter_append_link_constraint_attrs$62, $Html5Converter_encode_attribute_value$63, $Html5Converter_generate_manname_section$64, $Html5Converter_get_root_document$65, $Html5Converter_method_missing$66, $Html5Converter_respond_to_missing$ques$67, $writer = nil; - - self.$$prototype.void_element_slash = self.$$prototype.xml_mode = self.$$prototype.refs = self.$$prototype.resolving_xref = nil; - - self.$register_for("html5"); - - $writer = [["", ""]]; - $send(Opal.const_set($nesting[0], 'QUOTE_TAGS', $hash2(["monospaced", "emphasis", "strong", "double", "single", "mark", "superscript", "subscript", "asciimath", "latexmath"], {"monospaced": ["", "", true], "emphasis": ["", "", true], "strong": ["", "", true], "double": ["“", "”"], "single": ["‘", "’"], "mark": ["", "", true], "superscript": ["", "", true], "subscript": ["", "", true], "asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]})), 'default=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - Opal.const_set($nesting[0], 'DropAnchorRx', /<(?:a\b[^>]*|\/a)>/); - Opal.const_set($nesting[0], 'StemBreakRx', / *\\\n(?:\\?\n)*|\n\n+/); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - - Opal.const_set($nesting[0], 'SvgPreambleRx', new RegExp("" + "^" + ($$($nesting, 'CC_ALL')) + "*?(?=])")); - Opal.const_set($nesting[0], 'SvgStartTagRx', /^]*)?>/); - } else { - nil - }; - Opal.const_set($nesting[0], 'DimensionAttributeRx', new RegExp("" + "\\s(?:width|height|style)=([\"'])" + ($$($nesting, 'CC_ANY')) + "*?\\1")); - - Opal.def(self, '$initialize', $Html5Converter_initialize$1 = function $$initialize(backend, opts) { - var self = this, syntax = nil; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - self.backend = backend; - if (opts['$[]']("htmlsyntax")['$==']("xml")) { - - syntax = "xml"; - self.xml_mode = true; - self.void_element_slash = "/"; - } else { - - syntax = "html"; - self.xml_mode = nil; - self.void_element_slash = ""; - }; - return self.$init_backend_traits($hash2(["basebackend", "filetype", "htmlsyntax", "outfilesuffix", "supports_templates"], {"basebackend": "html", "filetype": "html", "htmlsyntax": syntax, "outfilesuffix": ".html", "supports_templates": true})); - }, $Html5Converter_initialize$1.$$arity = -2); - - Opal.def(self, '$convert', $Html5Converter_convert$2 = function $$convert(node, transform, opts) { - var $iter = $Html5Converter_convert$2.$$p, $yield = $iter || nil, self = this, $case = nil, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - - if ($iter) $Html5Converter_convert$2.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - - if (transform == null) { - transform = node.$node_name(); - }; - - if (opts == null) { - opts = nil; - }; - return (function() {$case = transform; - if ("inline_quoted"['$===']($case)) {return self.$convert_inline_quoted(node)} - else if ("paragraph"['$===']($case)) {return self.$convert_paragraph(node)} - else if ("inline_anchor"['$===']($case)) {return self.$convert_inline_anchor(node)} - else if ("section"['$===']($case)) {return self.$convert_section(node)} - else if ("listing"['$===']($case)) {return self.$convert_listing(node)} - else if ("literal"['$===']($case)) {return self.$convert_literal(node)} - else if ("ulist"['$===']($case)) {return self.$convert_ulist(node)} - else if ("olist"['$===']($case)) {return self.$convert_olist(node)} - else if ("dlist"['$===']($case)) {return self.$convert_dlist(node)} - else if ("admonition"['$===']($case)) {return self.$convert_admonition(node)} - else if ("colist"['$===']($case)) {return self.$convert_colist(node)} - else if ("embedded"['$===']($case)) {return self.$convert_embedded(node)} - else if ("example"['$===']($case)) {return self.$convert_example(node)} - else if ("floating_title"['$===']($case)) {return self.$convert_floating_title(node)} - else if ("image"['$===']($case)) {return self.$convert_image(node)} - else if ("inline_break"['$===']($case)) {return self.$convert_inline_break(node)} - else if ("inline_button"['$===']($case)) {return self.$convert_inline_button(node)} - else if ("inline_callout"['$===']($case)) {return self.$convert_inline_callout(node)} - else if ("inline_footnote"['$===']($case)) {return self.$convert_inline_footnote(node)} - else if ("inline_image"['$===']($case)) {return self.$convert_inline_image(node)} - else if ("inline_indexterm"['$===']($case)) {return self.$convert_inline_indexterm(node)} - else if ("inline_kbd"['$===']($case)) {return self.$convert_inline_kbd(node)} - else if ("inline_menu"['$===']($case)) {return self.$convert_inline_menu(node)} - else if ("open"['$===']($case)) {return self.$convert_open(node)} - else if ("page_break"['$===']($case)) {return self.$convert_page_break(node)} - else if ("preamble"['$===']($case)) {return self.$convert_preamble(node)} - else if ("quote"['$===']($case)) {return self.$convert_quote(node)} - else if ("sidebar"['$===']($case)) {return self.$convert_sidebar(node)} - else if ("stem"['$===']($case)) {return self.$convert_stem(node)} - else if ("table"['$===']($case)) {return self.$convert_table(node)} - else if ("thematic_break"['$===']($case)) {return self.$convert_thematic_break(node)} - else if ("verse"['$===']($case)) {return self.$convert_verse(node)} - else if ("video"['$===']($case)) {return self.$convert_video(node)} - else if ("document"['$===']($case)) {return self.$convert_document(node)} - else if ("toc"['$===']($case)) {return self.$convert_toc(node)} - else if ("pass"['$===']($case)) {return self.$convert_pass(node)} - else if ("audio"['$===']($case)) {return self.$convert_audio(node)} - else {return $send(self, Opal.find_super_dispatcher(self, 'convert', $Html5Converter_convert$2, false), $zuper, $iter)}})(); - }, $Html5Converter_convert$2.$$arity = -2); - - Opal.def(self, '$convert_document', $Html5Converter_convert_document$3 = function $$convert_document(node) { - var $a, $b, $c, $$4, $$5, self = this, br = nil, slash = nil, asset_uri_scheme = nil, cdn_base_url = nil, linkcss = nil, max_width_attr = nil, result = nil, lang_attribute = nil, authors = nil, icon_href = nil, icon_type = nil, icon_ext = nil, webfonts = nil, iconfont_stylesheet = nil, syntax_hl = nil, syntax_hl_docinfo_head_idx = nil, docinfo_content = nil, id_attr = nil, sectioned = nil, classes = nil, details = nil, idx = nil, $writer = nil, eqnums_val = nil, eqnums_opt = nil; - - - br = "" + ""; - if ($truthy((asset_uri_scheme = node.$attr("asset-uri-scheme", "https"))['$empty?']())) { - } else { - asset_uri_scheme = "" + (asset_uri_scheme) + ":" - }; - cdn_base_url = "" + (asset_uri_scheme) + "//cdnjs.cloudflare.com/ajax/libs"; - linkcss = node['$attr?']("linkcss"); - max_width_attr = (function() {if ($truthy(node['$attr?']("max-width"))) { - return "" + " style=\"max-width: " + (node.$attr("max-width")) + ";\"" - } else { - return "" - }; return nil; })(); - result = [""]; - lang_attribute = (function() {if ($truthy(node['$attr?']("nolang"))) { - return "" - } else { - return "" + " lang=\"" + (node.$attr("lang", "en")) + "\"" - }; return nil; })(); - result['$<<']("" + ""); - result['$<<']("" + "\n" + "\n" + "\n" + "\n" + ""); - if ($truthy(node['$attr?']("app-name"))) { - result['$<<']("" + "")}; - if ($truthy(node['$attr?']("description"))) { - result['$<<']("" + "")}; - if ($truthy(node['$attr?']("keywords"))) { - result['$<<']("" + "")}; - if ($truthy(node['$attr?']("authors"))) { - result['$<<']("" + "")}; - if ($truthy(node['$attr?']("copyright"))) { - result['$<<']("" + "")}; - if ($truthy(node['$attr?']("favicon"))) { - - if ($truthy((icon_href = node.$attr("favicon"))['$empty?']())) { - - icon_href = "favicon.ico"; - icon_type = "image/x-icon"; - } else if ($truthy((icon_ext = $$($nesting, 'Helpers').$extname(icon_href, nil)))) { - icon_type = (function() {if (icon_ext['$=='](".ico")) { - return "image/x-icon" - } else { - return "" + "image/" + (icon_ext.$slice(1, icon_ext.$length())) - }; return nil; })() - } else { - icon_type = "image/x-icon" - }; - result['$<<']("" + "");}; - result['$<<']("" + "" + (node.$doctitle($hash2(["sanitize", "use_fallback"], {"sanitize": true, "use_fallback": true}))) + ""); - if ($truthy($$($nesting, 'DEFAULT_STYLESHEET_KEYS')['$include?'](node.$attr("stylesheet")))) { - - if ($truthy((webfonts = node.$attr("webfonts")))) { - result['$<<']("" + "")}; - if ($truthy(linkcss)) { - result['$<<']("" + "") - } else { - result['$<<']("" + "") - }; - } else if ($truthy(node['$attr?']("stylesheet"))) { - if ($truthy(linkcss)) { - result['$<<']("" + "") - } else { - result['$<<']("" + "") - }}; - if ($truthy(node['$attr?']("icons", "font"))) { - if ($truthy(node['$attr?']("iconfont-remote"))) { - result['$<<']("" + "") - } else { - - iconfont_stylesheet = "" + (node.$attr("iconfont-name", "font-awesome")) + ".css"; - result['$<<']("" + ""); - }}; - if ($truthy((syntax_hl = node.$syntax_highlighter()))) { - result['$<<']((syntax_hl_docinfo_head_idx = result.$size()))}; - if ($truthy((docinfo_content = node.$docinfo())['$empty?']())) { - } else { - result['$<<'](docinfo_content) - }; - result['$<<'](""); - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(($truthy($a = ($truthy($b = ($truthy($c = (sectioned = node['$sections?']())) ? node['$attr?']("toc-class") : $c)) ? node['$attr?']("toc") : $b)) ? node['$attr?']("toc-placement", "auto") : $a))) { - classes = [node.$doctype(), node.$attr("toc-class"), "" + "toc-" + (node.$attr("toc-position", "header"))] - } else { - classes = [node.$doctype()] - }; - if ($truthy(node['$role?']())) { - classes['$<<'](node.$role())}; - result['$<<']("" + ""); - if ($truthy((docinfo_content = node.$docinfo("header"))['$empty?']())) { - } else { - result['$<<'](docinfo_content) - }; - if ($truthy(node.$noheader())) { - } else { - - result['$<<']("" + "
"); - if (node.$doctype()['$==']("manpage")) { - - result['$<<']("" + "

" + (node.$doctitle()) + " Manual Page

"); - if ($truthy(($truthy($a = ($truthy($b = sectioned) ? node['$attr?']("toc") : $b)) ? node['$attr?']("toc-placement", "auto") : $a))) { - result['$<<']("" + "
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
")}; - if ($truthy(node['$attr?']("manpurpose"))) { - result['$<<'](self.$generate_manname_section(node))}; - } else { - - if ($truthy(node['$header?']())) { - - if ($truthy(node.$notitle())) { - } else { - result['$<<']("" + "

" + (node.$header().$title()) + "

") - }; - details = []; - idx = 1; - $send(node.$authors(), 'each', [], ($$4 = function(author){var self = $$4.$$s || this; - - - - if (author == null) { - author = nil; - }; - details['$<<']("" + "" + (node.$sub_replacements(author.$name())) + "" + (br)); - if ($truthy(author.$email())) { - details['$<<']("" + "" + (node.$sub_macros(author.$email())) + "" + (br))}; - return (idx = $rb_plus(idx, 1));}, $$4.$$s = self, $$4.$$arity = 1, $$4)); - if ($truthy(node['$attr?']("revnumber"))) { - details['$<<']("" + "" + (($truthy($a = node.$attr("version-label")) ? $a : "").$downcase()) + " " + (node.$attr("revnumber")) + ((function() {if ($truthy(node['$attr?']("revdate"))) { - return "," - } else { - return "" - }; return nil; })()) + "")}; - if ($truthy(node['$attr?']("revdate"))) { - details['$<<']("" + "" + (node.$attr("revdate")) + "")}; - if ($truthy(node['$attr?']("revremark"))) { - details['$<<']("" + (br) + "" + (node.$attr("revremark")) + "")}; - if ($truthy(details['$empty?']())) { - } else { - - result['$<<']("
"); - result.$concat(details); - result['$<<']("
"); - };}; - if ($truthy(($truthy($a = ($truthy($b = sectioned) ? node['$attr?']("toc") : $b)) ? node['$attr?']("toc-placement", "auto") : $a))) { - result['$<<']("" + "
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
")}; - }; - result['$<<']("
"); - }; - result['$<<']("" + "
\n" + (node.$content()) + "\n" + "
"); - if ($truthy(($truthy($a = node['$footnotes?']()) ? node['$attr?']("nofootnotes")['$!']() : $a))) { - - result['$<<']("" + "
\n" + ""); - $send(node.$footnotes(), 'each', [], ($$5 = function(footnote){var self = $$5.$$s || this; - - - - if (footnote == null) { - footnote = nil; - }; - return result['$<<']("" + "
\n" + "" + (footnote.$index()) + ". " + (footnote.$text()) + "\n" + "
");}, $$5.$$s = self, $$5.$$arity = 1, $$5)); - result['$<<']("
");}; - if ($truthy(node.$nofooter())) { - } else { - - result['$<<']("" + "
"); - result['$<<']("
"); - if ($truthy(node['$attr?']("revnumber"))) { - result['$<<']("" + (node.$attr("version-label")) + " " + (node.$attr("revnumber")) + (br))}; - if ($truthy(($truthy($a = node['$attr?']("last-update-label")) ? node['$attr?']("reproducible")['$!']() : $a))) { - result['$<<']("" + (node.$attr("last-update-label")) + " " + (node.$attr("docdatetime")))}; - result['$<<']("
"); - result['$<<']("
"); - }; - if ($truthy(syntax_hl)) { - - if ($truthy(syntax_hl['$docinfo?']("head"))) { - - $writer = [syntax_hl_docinfo_head_idx, syntax_hl.$docinfo("head", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_closing_tag_slash": slash}))]; - $send(result, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)]; - } else { - result.$delete_at(syntax_hl_docinfo_head_idx) - }; - if ($truthy(syntax_hl['$docinfo?']("footer"))) { - result['$<<'](syntax_hl.$docinfo("footer", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_closing_tag_slash": slash})))};}; - if ($truthy(node['$attr?']("stem"))) { - - eqnums_val = node.$attr("eqnums", "none"); - if ($truthy(eqnums_val['$empty?']())) { - eqnums_val = "AMS"}; - eqnums_opt = "" + " equationNumbers: { autoNumber: \"" + (eqnums_val) + "\" } "; - result['$<<']("" + "\n" + "");}; - if ($truthy((docinfo_content = node.$docinfo("footer"))['$empty?']())) { - } else { - result['$<<'](docinfo_content) - }; - result['$<<'](""); - result['$<<'](""); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_document$3.$$arity = 1); - - Opal.def(self, '$convert_embedded', $Html5Converter_convert_embedded$6 = function $$convert_embedded(node) { - var $a, $b, $c, $$7, self = this, result = nil, id_attr = nil, toc_p = nil; - - - result = []; - if (node.$doctype()['$==']("manpage")) { - - if ($truthy(node.$notitle())) { - } else { - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - result['$<<']("" + "" + (node.$doctitle()) + " Manual Page"); - }; - if ($truthy(node['$attr?']("manpurpose"))) { - result['$<<'](self.$generate_manname_section(node))}; - } else if ($truthy(($truthy($a = node['$header?']()) ? node.$notitle()['$!']() : $a))) { - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - result['$<<']("" + "" + (node.$header().$title()) + "");}; - if ($truthy(($truthy($a = ($truthy($b = ($truthy($c = node['$sections?']()) ? node['$attr?']("toc") : $c)) ? (toc_p = node.$attr("toc-placement"))['$!=']("macro") : $b)) ? toc_p['$!=']("preamble") : $a))) { - result['$<<']("" + "
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
")}; - result['$<<'](node.$content()); - if ($truthy(($truthy($a = node['$footnotes?']()) ? node['$attr?']("nofootnotes")['$!']() : $a))) { - - result['$<<']("" + "
\n" + ""); - $send(node.$footnotes(), 'each', [], ($$7 = function(footnote){var self = $$7.$$s || this; - - - - if (footnote == null) { - footnote = nil; - }; - return result['$<<']("" + "
\n" + "" + (footnote.$index()) + ". " + (footnote.$text()) + "\n" + "
");}, $$7.$$s = self, $$7.$$arity = 1, $$7)); - result['$<<']("
");}; - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_embedded$6.$$arity = 1); - - Opal.def(self, '$convert_outline', $Html5Converter_convert_outline$8 = function $$convert_outline(node, opts) { - var $a, $b, $$9, self = this, sectnumlevels = nil, toclevels = nil, sections = nil, result = nil; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - if ($truthy(node['$sections?']())) { - } else { - return nil - }; - sectnumlevels = ($truthy($a = opts['$[]']("sectnumlevels")) ? $a : ($truthy($b = node.$document().$attributes()['$[]']("sectnumlevels")) ? $b : 3).$to_i()); - toclevels = ($truthy($a = opts['$[]']("toclevels")) ? $a : ($truthy($b = node.$document().$attributes()['$[]']("toclevels")) ? $b : 2).$to_i()); - sections = node.$sections(); - result = ["" + "
    "]; - $send(sections, 'each', [], ($$9 = function(section){var self = $$9.$$s || this, $c, slevel = nil, stitle = nil, $case = nil, signifier = nil, child_toc_level = nil; - - - - if (section == null) { - section = nil; - }; - slevel = section.$level(); - if ($truthy(section.$caption())) { - stitle = section.$captioned_title() - } else if ($truthy(($truthy($c = section.$numbered()) ? $rb_le(slevel, sectnumlevels) : $c))) { - if ($truthy(($truthy($c = $rb_lt(slevel, 2)) ? node.$document().$doctype()['$==']("book") : $c))) { - $case = section.$sectname(); - if ("chapter"['$===']($case)) {stitle = "" + ((function() {if ($truthy((signifier = node.$document().$attributes()['$[]']("chapter-signifier")))) { - return "" + (signifier) + " " - } else { - return "" - }; return nil; })()) + (section.$sectnum()) + " " + (section.$title())} - else if ("part"['$===']($case)) {stitle = "" + ((function() {if ($truthy((signifier = node.$document().$attributes()['$[]']("part-signifier")))) { - return "" + (signifier) + " " - } else { - return "" - }; return nil; })()) + (section.$sectnum(nil, ":")) + " " + (section.$title())} - else {stitle = "" + (section.$sectnum()) + " " + (section.$title())} - } else { - stitle = "" + (section.$sectnum()) + " " + (section.$title()) - } - } else { - stitle = section.$title() - }; - if ($truthy(stitle['$include?']("" + (stitle) + ""); - result['$<<'](child_toc_level); - return result['$<<'](""); - } else { - return result['$<<']("" + "
  • " + (stitle) + "
  • ") - };}, $$9.$$s = self, $$9.$$arity = 1, $$9)); - result['$<<']("
"); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_outline$8.$$arity = -2); - - Opal.def(self, '$convert_section', $Html5Converter_convert_section$10 = function $$convert_section(node) { - var $a, $b, self = this, doc_attrs = nil, level = nil, title = nil, $case = nil, signifier = nil, id_attr = nil, id = nil, role = nil; - - - doc_attrs = node.$document().$attributes(); - level = node.$level(); - if ($truthy(node.$caption())) { - title = node.$captioned_title() - } else if ($truthy(($truthy($a = node.$numbered()) ? $rb_le(level, ($truthy($b = doc_attrs['$[]']("sectnumlevels")) ? $b : 3).$to_i()) : $a))) { - if ($truthy(($truthy($a = $rb_lt(level, 2)) ? node.$document().$doctype()['$==']("book") : $a))) { - $case = node.$sectname(); - if ("chapter"['$===']($case)) {title = "" + ((function() {if ($truthy((signifier = doc_attrs['$[]']("chapter-signifier")))) { - return "" + (signifier) + " " - } else { - return "" - }; return nil; })()) + (node.$sectnum()) + " " + (node.$title())} - else if ("part"['$===']($case)) {title = "" + ((function() {if ($truthy((signifier = doc_attrs['$[]']("part-signifier")))) { - return "" + (signifier) + " " - } else { - return "" - }; return nil; })()) + (node.$sectnum(nil, ":")) + " " + (node.$title())} - else {title = "" + (node.$sectnum()) + " " + (node.$title())} - } else { - title = "" + (node.$sectnum()) + " " + (node.$title()) - } - } else { - title = node.$title() - }; - if ($truthy(node.$id())) { - - id_attr = "" + " id=\"" + ((id = node.$id())) + "\""; - if ($truthy(doc_attrs['$[]']("sectlinks"))) { - title = "" + "" + (title) + ""}; - if ($truthy(doc_attrs['$[]']("sectanchors"))) { - if (doc_attrs['$[]']("sectanchors")['$==']("after")) { - title = "" + (title) + "" - } else { - title = "" + "" + (title) - }}; - } else { - id_attr = "" - }; - if (level['$=='](0)) { - return "" + "" + (title) + "\n" + (node.$content()) - } else { - return "" + "
\n" + "" + (title) + "\n" + ((function() {if (level['$=='](1)) { - return "" + "
\n" + (node.$content()) + "\n" + "
" - } else { - return node.$content() - }; return nil; })()) + "\n" + "
" - }; - }, $Html5Converter_convert_section$10.$$arity = 1); - - Opal.def(self, '$convert_admonition', $Html5Converter_convert_admonition$11 = function $$convert_admonition(node) { - var $a, self = this, id_attr = nil, name = nil, title_element = nil, label = nil, role = nil; - - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - name = node.$attr("name"); - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - if ($truthy(node.$document()['$attr?']("icons"))) { - if ($truthy(($truthy($a = node.$document()['$attr?']("icons", "font")) ? node['$attr?']("icon")['$!']() : $a))) { - label = "" + "" - } else { - label = "" + "\""" - } - } else { - label = "" + "
" + (node.$attr("textlabel")) + "
" - }; - return "" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + (label) + "\n" + "\n" + (title_element) + (node.$content()) + "\n" + "
\n" + ""; - }, $Html5Converter_convert_admonition$11.$$arity = 1); - - Opal.def(self, '$convert_audio', $Html5Converter_convert_audio$12 = function $$convert_audio(node) { - var $a, self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, start_t = nil, end_t = nil, time_anchor = nil; - - - xml = self.xml_mode; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["audioblock", node.$role()].$compact(); - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - start_t = node.$attr("start"); - end_t = node.$attr("end"); - time_anchor = (function() {if ($truthy(($truthy($a = start_t) ? $a : end_t))) { - return "" + "#t=" + (($truthy($a = start_t) ? $a : "")) + ((function() {if ($truthy(end_t)) { - return "" + "," + (end_t) - } else { - return "" - }; return nil; })()) - } else { - return "" - }; return nil; })(); - return "" + "\n" + (title_element) + "
\n" + "\n" + "
\n" + ""; - }, $Html5Converter_convert_audio$12.$$arity = 1); - - Opal.def(self, '$convert_colist', $Html5Converter_convert_colist$13 = function $$convert_colist(node) { - var $a, $$14, $$15, self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, font_icons = nil, num = nil; - - - result = []; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["colist", node.$style(), node.$role()].$compact(); - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - result['$<<']("" + ""); - if ($truthy(node['$title?']())) { - result['$<<']("" + "
" + (node.$title()) + "
")}; - if ($truthy(node.$document()['$attr?']("icons"))) { - - result['$<<'](""); - $a = [node.$document()['$attr?']("icons", "font"), 0], (font_icons = $a[0]), (num = $a[1]), $a; - $send(node.$items(), 'each', [], ($$14 = function(item){var self = $$14.$$s || this, num_label = nil; - if (self.void_element_slash == null) self.void_element_slash = nil; - - - - if (item == null) { - item = nil; - }; - num = $rb_plus(num, 1); - if ($truthy(font_icons)) { - num_label = "" + "" + (num) + "" - } else { - num_label = "" + "\""" - }; - return result['$<<']("" + "\n" + "\n" + "\n" + "");}, $$14.$$s = self, $$14.$$arity = 1, $$14)); - result['$<<']("
" + (num_label) + "" + (item.$text()) + ((function() {if ($truthy(item['$blocks?']())) { - return $rb_plus($$($nesting, 'LF'), item.$content()) - } else { - return "" - }; return nil; })()) + "
"); - } else { - - result['$<<']("
    "); - $send(node.$items(), 'each', [], ($$15 = function(item){var self = $$15.$$s || this; - - - - if (item == null) { - item = nil; - }; - return result['$<<']("" + "
  1. \n" + "

    " + (item.$text()) + "

    " + ((function() {if ($truthy(item['$blocks?']())) { - return $rb_plus($$($nesting, 'LF'), item.$content()) - } else { - return "" - }; return nil; })()) + "\n" + "
  2. ");}, $$15.$$s = self, $$15.$$arity = 1, $$15)); - result['$<<']("
"); - }; - result['$<<'](""); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_colist$13.$$arity = 1); - - Opal.def(self, '$convert_dlist', $Html5Converter_convert_dlist$16 = function $$convert_dlist(node) { - var $$17, $a, $$19, $$21, self = this, result = nil, id_attribute = nil, $case = nil, classes = nil, class_attribute = nil, slash = nil, col_style_attribute = nil, dt_style_attribute = nil; - - - result = []; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - $case = node.$style(); - if ("qanda"['$===']($case)) {classes = ["qlist", "qanda", node.$role()]} - else if ("horizontal"['$===']($case)) {classes = ["hdlist", node.$role()]} - else {classes = ["dlist", node.$style(), node.$role()]}; - class_attribute = "" + " class=\"" + (classes.$compact().$join(" ")) + "\""; - result['$<<']("" + ""); - if ($truthy(node['$title?']())) { - result['$<<']("" + "
" + (node.$title()) + "
")}; - $case = node.$style(); - if ("qanda"['$===']($case)) { - result['$<<']("
    "); - $send(node.$items(), 'each', [], ($$17 = function(terms, dd){var self = $$17.$$s || this, $$18; - - - - if (terms == null) { - terms = nil; - }; - - if (dd == null) { - dd = nil; - }; - result['$<<']("
  1. "); - $send(terms, 'each', [], ($$18 = function(dt){var self = $$18.$$s || this; - - - - if (dt == null) { - dt = nil; - }; - return result['$<<']("" + "

    " + (dt.$text()) + "

    ");}, $$18.$$s = self, $$18.$$arity = 1, $$18)); - if ($truthy(dd)) { - - if ($truthy(dd['$text?']())) { - result['$<<']("" + "

    " + (dd.$text()) + "

    ")}; - if ($truthy(dd['$blocks?']())) { - result['$<<'](dd.$content())};}; - return result['$<<']("
  2. ");}, $$17.$$s = self, $$17.$$arity = 2, $$17)); - result['$<<']("
");} - else if ("horizontal"['$===']($case)) { - slash = self.void_element_slash; - result['$<<'](""); - if ($truthy(($truthy($a = node['$attr?']("labelwidth")) ? $a : node['$attr?']("itemwidth")))) { - - result['$<<'](""); - col_style_attribute = (function() {if ($truthy(node['$attr?']("labelwidth"))) { - return "" + " style=\"width: " + (node.$attr("labelwidth").$chomp("%")) + "%;\"" - } else { - return "" - }; return nil; })(); - result['$<<']("" + ""); - col_style_attribute = (function() {if ($truthy(node['$attr?']("itemwidth"))) { - return "" + " style=\"width: " + (node.$attr("itemwidth").$chomp("%")) + "%;\"" - } else { - return "" - }; return nil; })(); - result['$<<']("" + ""); - result['$<<']("");}; - $send(node.$items(), 'each', [], ($$19 = function(terms, dd){var self = $$19.$$s || this, $$20, first_term = nil; - - - - if (terms == null) { - terms = nil; - }; - - if (dd == null) { - dd = nil; - }; - result['$<<'](""); - result['$<<']("" + ""); - result['$<<'](""); - return result['$<<']("");}, $$19.$$s = self, $$19.$$arity = 2, $$19)); - result['$<<']("
"); - first_term = true; - $send(terms, 'each', [], ($$20 = function(dt){var self = $$20.$$s || this; - - - - if (dt == null) { - dt = nil; - }; - if ($truthy(first_term)) { - } else { - result['$<<']("" + "") - }; - result['$<<'](dt.$text()); - return (first_term = nil);}, $$20.$$s = self, $$20.$$arity = 1, $$20)); - result['$<<'](""); - if ($truthy(dd)) { - - if ($truthy(dd['$text?']())) { - result['$<<']("" + "

" + (dd.$text()) + "

")}; - if ($truthy(dd['$blocks?']())) { - result['$<<'](dd.$content())};}; - result['$<<']("
");} - else { - result['$<<']("
"); - dt_style_attribute = (function() {if ($truthy(node.$style())) { - return "" - } else { - return " class=\"hdlist1\"" - }; return nil; })(); - $send(node.$items(), 'each', [], ($$21 = function(terms, dd){var self = $$21.$$s || this, $$22; - - - - if (terms == null) { - terms = nil; - }; - - if (dd == null) { - dd = nil; - }; - $send(terms, 'each', [], ($$22 = function(dt){var self = $$22.$$s || this; - - - - if (dt == null) { - dt = nil; - }; - return result['$<<']("" + "" + (dt.$text()) + "");}, $$22.$$s = self, $$22.$$arity = 1, $$22)); - if ($truthy(dd)) { - } else { - return nil; - }; - result['$<<']("
"); - if ($truthy(dd['$text?']())) { - result['$<<']("" + "

" + (dd.$text()) + "

")}; - if ($truthy(dd['$blocks?']())) { - result['$<<'](dd.$content())}; - return result['$<<']("
");}, $$21.$$s = self, $$21.$$arity = 2, $$21)); - result['$<<']("
");}; - result['$<<'](""); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_dlist$16.$$arity = 1); - - Opal.def(self, '$convert_example', $Html5Converter_convert_example$23 = function $$convert_example(node) { - var self = this, id_attribute = nil, class_attribute = nil, summary_element = nil, title_element = nil, role = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(node['$option?']("collapsible"))) { - - class_attribute = (function() {if ($truthy(node.$role())) { - return "" + " class=\"" + (node.$role()) + "\"" - } else { - return "" - }; return nil; })(); - summary_element = (function() {if ($truthy(node['$title?']())) { - return "" + "" + (node.$title()) + "" - } else { - return "Details" - }; return nil; })(); - return "" + "\n" + (summary_element) + "\n" + "
\n" + (node.$content()) + "\n" + "
\n" + ""; - } else { - - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$captioned_title()) + "
\n" - } else { - return "" - }; return nil; })(); - return "" + "\n" + (title_element) + "
\n" + (node.$content()) + "\n" + "
\n" + ""; - }; - }, $Html5Converter_convert_example$23.$$arity = 1); - - Opal.def(self, '$convert_floating_title', $Html5Converter_convert_floating_title$24 = function $$convert_floating_title(node) { - var self = this, tag_name = nil, id_attribute = nil, classes = nil; - - - tag_name = "" + "h" + ($rb_plus(node.$level(), 1)); - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = [node.$style(), node.$role()].$compact(); - return "" + "<" + (tag_name) + (id_attribute) + " class=\"" + (classes.$join(" ")) + "\">" + (node.$title()) + ""; - }, $Html5Converter_convert_floating_title$24.$$arity = 1); - - Opal.def(self, '$convert_image', $Html5Converter_convert_image$25 = function $$convert_image(node) { - var $a, $b, self = this, target = nil, width_attr = nil, height_attr = nil, img = nil, fallback = nil, id_attr = nil, classes = nil, class_attr = nil, title_el = nil; - - - target = node.$attr("target"); - width_attr = (function() {if ($truthy(node['$attr?']("width"))) { - return "" + " width=\"" + (node.$attr("width")) + "\"" - } else { - return "" - }; return nil; })(); - height_attr = (function() {if ($truthy(node['$attr?']("height"))) { - return "" + " height=\"" + (node.$attr("height")) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(($truthy($a = ($truthy($b = node['$attr?']("format", "svg")) ? $b : target['$include?'](".svg"))) ? $rb_lt(node.$document().$safe(), $$$($$($nesting, 'SafeMode'), 'SECURE')) : $a))) { - if ($truthy(node['$option?']("inline"))) { - img = ($truthy($a = self.$read_svg_contents(node, target)) ? $a : "" + "" + (node.$alt()) + "") - } else if ($truthy(node['$option?']("interactive"))) { - - fallback = (function() {if ($truthy(node['$attr?']("fallback"))) { - return "" + "\""" - } else { - return "" + "" + (node.$alt()) + "" - }; return nil; })(); - img = "" + "" + (fallback) + ""; - } else { - img = "" + "\""" - } - } else { - img = "" + "\""" - }; - if ($truthy(node['$attr?']("link"))) { - img = "" + "" + (img) + ""}; - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["imageblock"]; - if ($truthy(node['$attr?']("float"))) { - classes['$<<'](node.$attr("float"))}; - if ($truthy(node['$attr?']("align"))) { - classes['$<<']("" + "text-" + (node.$attr("align")))}; - if ($truthy(node.$role())) { - classes['$<<'](node.$role())}; - class_attr = "" + " class=\"" + (classes.$join(" ")) + "\""; - title_el = (function() {if ($truthy(node['$title?']())) { - return "" + "\n
" + (node.$captioned_title()) + "
" - } else { - return "" - }; return nil; })(); - return "" + "\n" + "
\n" + (img) + "\n" + "
" + (title_el) + "\n" + ""; - }, $Html5Converter_convert_image$25.$$arity = 1); - - Opal.def(self, '$convert_listing', $Html5Converter_convert_listing$26 = function $$convert_listing(node) { - var $a, self = this, nowrap = nil, lang = nil, syntax_hl = nil, opts = nil, doc_attrs = nil, $writer = nil, pre_open = nil, pre_close = nil, id_attribute = nil, title_element = nil, role = nil; - - - nowrap = ($truthy($a = node['$option?']("nowrap")) ? $a : node.$document()['$attr?']("prewrap")['$!']()); - if (node.$style()['$==']("source")) { - - lang = node.$attr("language"); - if ($truthy((syntax_hl = node.$document().$syntax_highlighter()))) { - - opts = (function() {if ($truthy(syntax_hl['$highlight?']())) { - return $hash2(["css_mode", "style"], {"css_mode": ($truthy($a = (doc_attrs = node.$document().$attributes())['$[]']("" + (syntax_hl.$name()) + "-css")) ? $a : "class").$to_sym(), "style": doc_attrs['$[]']("" + (syntax_hl.$name()) + "-style")}) - } else { - return $hash2([], {}) - }; return nil; })(); - - $writer = ["nowrap", nowrap]; - $send(opts, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - } else { - - pre_open = "" + "
";
-            pre_close = "
"; - }; - } else { - - pre_open = "" + ""; - pre_close = ""; - }; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$captioned_title()) + "
\n" - } else { - return "" - }; return nil; })(); - return "" + "\n" + (title_element) + "
\n" + ((function() {if ($truthy(syntax_hl)) { - - return syntax_hl.$format(node, lang, opts); - } else { - return $rb_plus($rb_plus(pre_open, ($truthy($a = node.$content()) ? $a : "")), pre_close) - }; return nil; })()) + "\n" + "
\n" + ""; - }, $Html5Converter_convert_listing$26.$$arity = 1); - - Opal.def(self, '$convert_literal', $Html5Converter_convert_literal$27 = function $$convert_literal(node) { - var $a, self = this, id_attribute = nil, title_element = nil, nowrap = nil, role = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - nowrap = ($truthy($a = node.$document()['$attr?']("prewrap")['$!']()) ? $a : node['$option?']("nowrap")); - return "" + "\n" + (title_element) + "
\n" + "" + (node.$content()) + "\n" + "
\n" + ""; - }, $Html5Converter_convert_literal$27.$$arity = 1); - - Opal.def(self, '$convert_stem', $Html5Converter_convert_stem$28 = function $$convert_stem(node) { - var $a, $b, $$29, self = this, id_attribute = nil, title_element = nil, style = nil, open = nil, close = nil, equation = nil, br = nil, role = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - $b = $$($nesting, 'BLOCK_MATH_DELIMITERS')['$[]']((style = node.$style().$to_sym())), $a = Opal.to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])), $b; - if ($truthy((equation = node.$content()))) { - - if ($truthy((($a = style['$==']("asciimath")) ? equation['$include?']($$($nesting, 'LF')) : style['$==']("asciimath")))) { - - br = "" + ($$($nesting, 'LF')) + ""; - equation = $send(equation, 'gsub', [$$($nesting, 'StemBreakRx')], ($$29 = function(){var self = $$29.$$s || this, $c; + if (this.ended) + this.tokenizer.end(); + }; + /** + * Alias of `write`, for backwards compatibility. + * + * @param chunk Chunk to parse. + * @deprecated + */ + Parser.prototype.parseChunk = function (chunk) { + this.write(chunk); + }; + /** + * Alias of `end`, for backwards compatibility. + * + * @param chunk Optional final chunk to parse. + * @deprecated + */ + Parser.prototype.done = function (chunk) { + this.end(chunk); + }; + return Parser; +}()); +exports.Parser = Parser; +//# sourceMappingURL=Parser.js.map - return "" + (close) + ($rb_times(br, $rb_minus((($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$count($$($nesting, 'LF')), 1))) + ($$($nesting, 'LF')) + (open)}, $$29.$$s = self, $$29.$$arity = 0, $$29));}; - if ($truthy(($truthy($a = equation['$start_with?'](open)) ? equation['$end_with?'](close) : $a))) { - } else { - equation = "" + (open) + (equation) + (close) - }; - } else { - equation = "" - }; - return "" + "\n" + (title_element) + "
\n" + (equation) + "\n" + "
\n" + ""; - }, $Html5Converter_convert_stem$28.$$arity = 1); - - Opal.def(self, '$convert_olist', $Html5Converter_convert_olist$30 = function $$convert_olist(node) { - var $$31, self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, type_attribute = nil, keyword = nil, start_attribute = nil, reversed_attribute = nil; +/***/ }), - - result = []; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["olist", node.$style(), node.$role()].$compact(); - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - result['$<<']("" + ""); - if ($truthy(node['$title?']())) { - result['$<<']("" + "
" + (node.$title()) + "
")}; - type_attribute = (function() {if ($truthy((keyword = node.$list_marker_keyword()))) { - return "" + " type=\"" + (keyword) + "\"" - } else { - return "" - }; return nil; })(); - start_attribute = (function() {if ($truthy(node['$attr?']("start"))) { - return "" + " start=\"" + (node.$attr("start")) + "\"" - } else { - return "" - }; return nil; })(); - reversed_attribute = (function() {if ($truthy(node['$option?']("reversed"))) { - - return self.$append_boolean_attribute("reversed", self.xml_mode); - } else { - return "" - }; return nil; })(); - result['$<<']("" + "
    "); - $send(node.$items(), 'each', [], ($$31 = function(item){var self = $$31.$$s || this; +/***/ 4341: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { - - - if (item == null) { - item = nil; - }; - if ($truthy(item.$id())) { - result['$<<']("" + "
  1. ") - } else if ($truthy(item.$role())) { - result['$<<']("" + "
  2. ") - } else { - result['$<<']("
  3. ") - }; - result['$<<']("" + "

    " + (item.$text()) + "

    "); - if ($truthy(item['$blocks?']())) { - result['$<<'](item.$content())}; - return result['$<<']("
  4. ");}, $$31.$$s = self, $$31.$$arity = 1, $$31)); - result['$<<']("
"); - result['$<<'](""); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_olist$30.$$arity = 1); - - Opal.def(self, '$convert_open', $Html5Converter_convert_open$32 = function $$convert_open(node) { - var $a, $b, $c, self = this, style = nil, id_attr = nil, title_el = nil, role = nil; +"use strict"; - if ((style = node.$style())['$==']("abstract")) { - if ($truthy((($a = node.$parent()['$=='](node.$document())) ? node.$document().$doctype()['$==']("book") : node.$parent()['$=='](node.$document())))) { - - self.$logger().$warn("abstract block cannot be used in a document without a title when doctype is book. Excluding block content."); - return ""; - } else { - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_el = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - return "" + "\n" + (title_el) + "
\n" + (node.$content()) + "\n" + "
\n" + ""; - } - } else if ($truthy((($a = style['$==']("partintro")) ? ($truthy($b = ($truthy($c = $rb_gt(node.$level(), 0)) ? $c : node.$parent().$context()['$!=']("section"))) ? $b : node.$document().$doctype()['$!=']("book")) : style['$==']("partintro")))) { - - self.$logger().$error("partintro block can only be used when doctype is book and must be a child of a book part. Excluding block content."); - return ""; - } else { - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_el = (function() {if ($truthy(node['$title?']())) { - return "" + "
" + (node.$title()) + "
\n" - } else { - return "" - }; return nil; })(); - return "" + " this.sectionStart) { + this.cbs.ontext(this.sectionStart, this.index); + } + this.state = State.BeforeTagName; + this.sectionStart = this.index; + } + else if (this.decodeEntities && c === CharCodes.Amp) { + this.state = State.BeforeEntity; + } + }; + Tokenizer.prototype.stateSpecialStartSequence = function (c) { + var isEnd = this.sequenceIndex === this.currentSequence.length; + var isMatch = isEnd + ? // If we are at the end of the sequence, make sure the tag name has ended + isEndOfTagSection(c) + : // Otherwise, do a case-insensitive comparison + (c | 0x20) === this.currentSequence[this.sequenceIndex]; + if (!isMatch) { + this.isSpecial = false; + } + else if (!isEnd) { + this.sequenceIndex++; + return; + } + this.sequenceIndex = 0; + this.state = State.InTagName; + this.stateInTagName(c); + }; + /** Look for an end tag. For tags, also decode entities. */ + Tokenizer.prototype.stateInSpecialTag = function (c) { + if (this.sequenceIndex === this.currentSequence.length) { + if (c === CharCodes.Gt || isWhitespace(c)) { + var endOfText = this.index - this.currentSequence.length; + if (this.sectionStart < endOfText) { + // Spoof the index so that reported locations match up. + var actualIndex = this.index; + this.index = endOfText; + this.cbs.ontext(this.sectionStart, endOfText); + this.index = actualIndex; + } + this.isSpecial = false; + this.sectionStart = endOfText + 2; // Skip over the `</` + this.stateInClosingTagName(c); + return; // We are done; skip the rest of the function. + } + this.sequenceIndex = 0; + } + if ((c | 0x20) === this.currentSequence[this.sequenceIndex]) { + this.sequenceIndex += 1; + } + else if (this.sequenceIndex === 0) { + if (this.currentSequence === Sequences.TitleEnd) { + // We have to parse entities in <title> tags. + if (this.decodeEntities && c === CharCodes.Amp) { + this.state = State.BeforeEntity; + } + } + else if (this.fastForwardTo(CharCodes.Lt)) { + // Outside of <title> tags, we can fast-forward. + this.sequenceIndex = 1; + } + } + else { + // If we see a `<`, set the sequence index to 1; useful for eg. `<</script>`. + this.sequenceIndex = Number(c === CharCodes.Lt); + } + }; + Tokenizer.prototype.stateCDATASequence = function (c) { + if (c === Sequences.Cdata[this.sequenceIndex]) { + if (++this.sequenceIndex === Sequences.Cdata.length) { + this.state = State.InCommentLike; + this.currentSequence = Sequences.CdataEnd; + this.sequenceIndex = 0; + this.sectionStart = this.index + 1; + } + } + else { + this.sequenceIndex = 0; + this.state = State.InDeclaration; + this.stateInDeclaration(c); // Reconsume the character + } + }; + /** + * When we wait for one specific character, we can speed things up + * by skipping through the buffer until we find it. + * + * @returns Whether the character was found. + */ + Tokenizer.prototype.fastForwardTo = function (c) { + while (++this.index < this.buffer.length + this.offset) { + if (this.buffer.charCodeAt(this.index - this.offset) === c) { + return true; + } + } + /* + * We increment the index at the end of the `parse` loop, + * so set it to `buffer.length - 1` here. + * + * TODO: Refactor `parse` to increment index before calling states. + */ + this.index = this.buffer.length + this.offset - 1; + return false; + }; + /** + * Comments and CDATA end with `-->` and `]]>`. + * + * Their common qualities are: + * - Their end sequences have a distinct character they start with. + * - That character is then repeated, so we have to check multiple repeats. + * - All characters but the start character of the sequence can be skipped. + */ + Tokenizer.prototype.stateInCommentLike = function (c) { + if (c === this.currentSequence[this.sequenceIndex]) { + if (++this.sequenceIndex === this.currentSequence.length) { + if (this.currentSequence === Sequences.CdataEnd) { + this.cbs.oncdata(this.sectionStart, this.index, 2); + } + else { + this.cbs.oncomment(this.sectionStart, this.index, 2); + } + this.sequenceIndex = 0; + this.sectionStart = this.index + 1; + this.state = State.Text; + } + } + else if (this.sequenceIndex === 0) { + // Fast-forward to the first character of the sequence + if (this.fastForwardTo(this.currentSequence[0])) { + this.sequenceIndex = 1; + } + } + else if (c !== this.currentSequence[this.sequenceIndex - 1]) { + // Allow long sequences, eg. --->, ]]]> + this.sequenceIndex = 0; + } + }; + /** + * HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name. + * + * XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar). + * We allow anything that wouldn't end the tag. + */ + Tokenizer.prototype.isTagStartChar = function (c) { + return this.xmlMode ? !isEndOfTagSection(c) : isASCIIAlpha(c); + }; + Tokenizer.prototype.startSpecial = function (sequence, offset) { + this.isSpecial = true; + this.currentSequence = sequence; + this.sequenceIndex = offset; + this.state = State.SpecialStartSequence; + }; + Tokenizer.prototype.stateBeforeTagName = function (c) { + if (c === CharCodes.ExclamationMark) { + this.state = State.BeforeDeclaration; + this.sectionStart = this.index + 1; + } + else if (c === CharCodes.Questionmark) { + this.state = State.InProcessingInstruction; + this.sectionStart = this.index + 1; + } + else if (this.isTagStartChar(c)) { + var lower = c | 0x20; + this.sectionStart = this.index; + if (!this.xmlMode && lower === Sequences.TitleEnd[2]) { + this.startSpecial(Sequences.TitleEnd, 3); + } + else { + this.state = + !this.xmlMode && lower === Sequences.ScriptEnd[2] + ? State.BeforeSpecialS + : State.InTagName; + } + } + else if (c === CharCodes.Slash) { + this.state = State.BeforeClosingTagName; + } + else { + this.state = State.Text; + this.stateText(c); + } + }; + Tokenizer.prototype.stateInTagName = function (c) { + if (isEndOfTagSection(c)) { + this.cbs.onopentagname(this.sectionStart, this.index); + this.sectionStart = -1; + this.state = State.BeforeAttributeName; + this.stateBeforeAttributeName(c); + } + }; + Tokenizer.prototype.stateBeforeClosingTagName = function (c) { + if (isWhitespace(c)) { + // Ignore + } + else if (c === CharCodes.Gt) { + this.state = State.Text; + } + else { + this.state = this.isTagStartChar(c) + ? State.InClosingTagName + : State.InSpecialComment; + this.sectionStart = this.index; + } + }; + Tokenizer.prototype.stateInClosingTagName = function (c) { + if (c === CharCodes.Gt || isWhitespace(c)) { + this.cbs.onclosetag(this.sectionStart, this.index); + this.sectionStart = -1; + this.state = State.AfterClosingTagName; + this.stateAfterClosingTagName(c); + } + }; + Tokenizer.prototype.stateAfterClosingTagName = function (c) { + // Skip everything until ">" + if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { + this.state = State.Text; + this.baseState = State.Text; + this.sectionStart = this.index + 1; + } + }; + Tokenizer.prototype.stateBeforeAttributeName = function (c) { + if (c === CharCodes.Gt) { + this.cbs.onopentagend(this.index); + if (this.isSpecial) { + this.state = State.InSpecialTag; + this.sequenceIndex = 0; + } + else { + this.state = State.Text; + } + this.baseState = this.state; + this.sectionStart = this.index + 1; + } + else if (c === CharCodes.Slash) { + this.state = State.InSelfClosingTag; + } + else if (!isWhitespace(c)) { + this.state = State.InAttributeName; + this.sectionStart = this.index; + } + }; + Tokenizer.prototype.stateInSelfClosingTag = function (c) { + if (c === CharCodes.Gt) { + this.cbs.onselfclosingtag(this.index); + this.state = State.Text; + this.baseState = State.Text; + this.sectionStart = this.index + 1; + this.isSpecial = false; // Reset special state, in case of self-closing special tags + } + else if (!isWhitespace(c)) { + this.state = State.BeforeAttributeName; + this.stateBeforeAttributeName(c); } - }, $Html5Converter_convert_open$32.$$arity = 1); - - Opal.def(self, '$convert_page_break', $Html5Converter_convert_page_break$33 = function $$convert_page_break(node) { - var self = this; - - return "<div style=\"page-break-after: always;\"></div>" - }, $Html5Converter_convert_page_break$33.$$arity = 1); - - Opal.def(self, '$convert_paragraph', $Html5Converter_convert_paragraph$34 = function $$convert_paragraph(node) { - var self = this, attributes = nil; - - - if ($truthy(node.$role())) { - attributes = "" + ((function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })()) + " class=\"paragraph " + (node.$role()) + "\"" - } else if ($truthy(node.$id())) { - attributes = "" + " id=\"" + (node.$id()) + "\" class=\"paragraph\"" - } else { - attributes = " class=\"paragraph\"" - }; - if ($truthy(node['$title?']())) { - return "" + "<div" + (attributes) + ">\n" + "<div class=\"title\">" + (node.$title()) + "</div>\n" + "<p>" + (node.$content()) + "</p>\n" + "</div>" - } else { - return "" + "<div" + (attributes) + ">\n" + "<p>" + (node.$content()) + "</p>\n" + "</div>" - }; - }, $Html5Converter_convert_paragraph$34.$$arity = 1); - Opal.alias(self, "convert_pass", "content_only"); - - Opal.def(self, '$convert_preamble', $Html5Converter_convert_preamble$35 = function $$convert_preamble(node) { - var $a, $b, self = this, doc = nil, toc = nil; - - - if ($truthy(($truthy($a = ($truthy($b = (doc = node.$document())['$attr?']("toc-placement", "preamble")) ? doc['$sections?']() : $b)) ? doc['$attr?']("toc") : $a))) { - toc = "" + "\n" + "<div id=\"toc\" class=\"" + (doc.$attr("toc-class", "toc")) + "\">\n" + "<div id=\"toctitle\">" + (doc.$attr("toc-title")) + "</div>\n" + (doc.$converter().$convert(doc, "outline")) + "\n" + "</div>" - } else { - toc = "" - }; - return "" + "<div id=\"preamble\">\n" + "<div class=\"sectionbody\">\n" + (node.$content()) + "\n" + "</div>" + (toc) + "\n" + "</div>"; - }, $Html5Converter_convert_preamble$35.$$arity = 1); - - Opal.def(self, '$convert_quote', $Html5Converter_convert_quote$36 = function $$convert_quote(node) { - var $a, self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["quoteblock", node.$role()].$compact(); - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "\n<div class=\"title\">" + (node.$title()) + "</div>" - } else { - return "" - }; return nil; })(); - attribution = (function() {if ($truthy(node['$attr?']("attribution"))) { - - return node.$attr("attribution"); - } else { - return nil - }; return nil; })(); - citetitle = (function() {if ($truthy(node['$attr?']("citetitle"))) { - - return node.$attr("citetitle"); - } else { - return nil - }; return nil; })(); - if ($truthy(($truthy($a = attribution) ? $a : citetitle))) { - - cite_element = (function() {if ($truthy(citetitle)) { - return "" + "<cite>" + (citetitle) + "</cite>" - } else { - return "" - }; return nil; })(); - attribution_text = (function() {if ($truthy(attribution)) { - return "" + "— " + (attribution) + ((function() {if ($truthy(citetitle)) { - return "" + "<br" + (self.void_element_slash) + ">\n" - } else { - return "" - }; return nil; })()) - } else { - return "" - }; return nil; })(); - attribution_element = "" + "\n<div class=\"attribution\">\n" + (attribution_text) + (cite_element) + "\n</div>"; - } else { - attribution_element = "" - }; - return "" + "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<blockquote>\n" + (node.$content()) + "\n" + "</blockquote>" + (attribution_element) + "\n" + "</div>"; - }, $Html5Converter_convert_quote$36.$$arity = 1); - - Opal.def(self, '$convert_thematic_break', $Html5Converter_convert_thematic_break$37 = function $$convert_thematic_break(node) { - var self = this; - - return "" + "<hr" + (self.void_element_slash) + ">" - }, $Html5Converter_convert_thematic_break$37.$$arity = 1); - - Opal.def(self, '$convert_sidebar', $Html5Converter_convert_sidebar$38 = function $$convert_sidebar(node) { - var self = this, id_attribute = nil, title_element = nil, role = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "<div class=\"title\">" + (node.$title()) + "</div>\n" - } else { - return "" - }; return nil; })(); - return "" + "<div" + (id_attribute) + " class=\"sidebarblock" + ((function() {if ($truthy((role = node.$role()))) { - return "" + " " + (role) - } else { - return "" - }; return nil; })()) + "\">\n" + "<div class=\"content\">\n" + (title_element) + (node.$content()) + "\n" + "</div>\n" + "</div>"; - }, $Html5Converter_convert_sidebar$38.$$arity = 1); - - Opal.def(self, '$convert_table', $Html5Converter_convert_table$39 = function $$convert_table(node) { - var $a, $$40, $$41, self = this, result = nil, id_attribute = nil, frame = nil, classes = nil, stripes = nil, style_attribute = nil, autowidth = nil, tablewidth = nil, role = nil, class_attribute = nil, slash = nil; - - - result = []; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - if ((frame = node.$attr("frame", "all", "table-frame"))['$==']("topbot")) { - frame = "ends"}; - classes = ["tableblock", "" + "frame-" + (frame), "" + "grid-" + (node.$attr("grid", "all", "table-grid"))]; - if ($truthy((stripes = node.$attr("stripes", nil, "table-stripes")))) { - classes['$<<']("" + "stripes-" + (stripes))}; - style_attribute = ""; - if ($truthy(($truthy($a = (autowidth = node['$option?']("autowidth"))) ? node['$attr?']("width")['$!']() : $a))) { - classes['$<<']("fit-content") - } else if ((tablewidth = node.$attr("tablepcwidth"))['$=='](100)) { - classes['$<<']("stretch") - } else { - style_attribute = "" + " style=\"width: " + (tablewidth) + "%;\"" - }; - if ($truthy(node['$attr?']("float"))) { - classes['$<<'](node.$attr("float"))}; - if ($truthy((role = node.$role()))) { - classes['$<<'](role)}; - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - result['$<<']("" + "<table" + (id_attribute) + (class_attribute) + (style_attribute) + ">"); - if ($truthy(node['$title?']())) { - result['$<<']("" + "<caption class=\"title\">" + (node.$captioned_title()) + "</caption>")}; - if ($truthy($rb_gt(node.$attr("rowcount"), 0))) { - - slash = self.void_element_slash; - result['$<<']("<colgroup>"); - if ($truthy(autowidth)) { - result = $rb_plus(result, $$($nesting, 'Array').$new(node.$columns().$size(), "" + "<col" + (slash) + ">")) - } else { - $send(node.$columns(), 'each', [], ($$40 = function(col){var self = $$40.$$s || this; - - - - if (col == null) { - col = nil; - }; - return result['$<<']((function() {if ($truthy(col['$option?']("autowidth"))) { - return "" + "<col" + (slash) + ">" - } else { - return "" + "<col style=\"width: " + (col.$attr("colpcwidth")) + "%;\"" + (slash) + ">" - }; return nil; })());}, $$40.$$s = self, $$40.$$arity = 1, $$40)) - }; - result['$<<']("</colgroup>"); - $send(node.$rows().$to_h(), 'each', [], ($$41 = function(tsec, rows){var self = $$41.$$s || this, $$42; - - - - if (tsec == null) { - tsec = nil; - }; - - if (rows == null) { - rows = nil; - }; - if ($truthy(rows['$empty?']())) { - return nil;}; - result['$<<']("" + "<t" + (tsec) + ">"); - $send(rows, 'each', [], ($$42 = function(row){var self = $$42.$$s || this, $$43; - - - - if (row == null) { - row = nil; - }; - result['$<<']("<tr>"); - $send(row, 'each', [], ($$43 = function(cell){var self = $$43.$$s || this, $b, cell_content = nil, $case = nil, cell_tag_name = nil, cell_class_attribute = nil, cell_colspan_attribute = nil, cell_rowspan_attribute = nil, cell_style_attribute = nil; - - - - if (cell == null) { - cell = nil; - }; - if (tsec['$==']("head")) { - cell_content = cell.$text() - } else { - $case = cell.$style(); - if ("asciidoc"['$===']($case)) {cell_content = "" + "<div class=\"content\">" + (cell.$content()) + "</div>"} - else if ("literal"['$===']($case)) {cell_content = "" + "<div class=\"literal\"><pre>" + (cell.$text()) + "</pre></div>"} - else {cell_content = (function() {if ($truthy((cell_content = cell.$content())['$empty?']())) { - return "" - } else { - return "" + "<p class=\"tableblock\">" + (cell_content.$join("" + "</p>\n" + "<p class=\"tableblock\">")) + "</p>" - }; return nil; })()} - }; - cell_tag_name = (function() {if ($truthy(($truthy($b = tsec['$==']("head")) ? $b : cell.$style()['$==']("header")))) { - return "th" - } else { - return "td" - }; return nil; })(); - cell_class_attribute = "" + " class=\"tableblock halign-" + (cell.$attr("halign")) + " valign-" + (cell.$attr("valign")) + "\""; - cell_colspan_attribute = (function() {if ($truthy(cell.$colspan())) { - return "" + " colspan=\"" + (cell.$colspan()) + "\"" - } else { - return "" - }; return nil; })(); - cell_rowspan_attribute = (function() {if ($truthy(cell.$rowspan())) { - return "" + " rowspan=\"" + (cell.$rowspan()) + "\"" - } else { - return "" - }; return nil; })(); - cell_style_attribute = (function() {if ($truthy(node.$document()['$attr?']("cellbgcolor"))) { - return "" + " style=\"background-color: " + (node.$document().$attr("cellbgcolor")) + ";\"" - } else { - return "" - }; return nil; })(); - return result['$<<']("" + "<" + (cell_tag_name) + (cell_class_attribute) + (cell_colspan_attribute) + (cell_rowspan_attribute) + (cell_style_attribute) + ">" + (cell_content) + "</" + (cell_tag_name) + ">");}, $$43.$$s = self, $$43.$$arity = 1, $$43)); - return result['$<<']("</tr>");}, $$42.$$s = self, $$42.$$arity = 1, $$42)); - return result['$<<']("" + "</t" + (tsec) + ">");}, $$41.$$s = self, $$41.$$arity = 2, $$41));}; - result['$<<']("</table>"); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_table$39.$$arity = 1); - - Opal.def(self, '$convert_toc', $Html5Converter_convert_toc$44 = function $$convert_toc(node) { - var $a, $b, self = this, doc = nil, id_attr = nil, title_id_attr = nil, title = nil, levels = nil, role = nil; - - - if ($truthy(($truthy($a = ($truthy($b = (doc = node.$document())['$attr?']("toc-placement", "macro")) ? doc['$sections?']() : $b)) ? doc['$attr?']("toc") : $a))) { - } else { - return "<!-- toc disabled -->" - }; - if ($truthy(node.$id())) { - - id_attr = "" + " id=\"" + (node.$id()) + "\""; - title_id_attr = "" + " id=\"" + (node.$id()) + "title\""; - } else { - - id_attr = " id=\"toc\""; - title_id_attr = " id=\"toctitle\""; - }; - title = (function() {if ($truthy(node['$title?']())) { - return node.$title() - } else { - - return doc.$attr("toc-title"); - }; return nil; })(); - levels = (function() {if ($truthy(node['$attr?']("levels"))) { - return node.$attr("levels").$to_i() - } else { - return nil - }; return nil; })(); - role = (function() {if ($truthy(node['$role?']())) { - return node.$role() - } else { - - return doc.$attr("toc-class", "toc"); - }; return nil; })(); - return "" + "<div" + (id_attr) + " class=\"" + (role) + "\">\n" + "<div" + (title_id_attr) + " class=\"title\">" + (title) + "</div>\n" + (doc.$converter().$convert(doc, "outline", $hash2(["toclevels"], {"toclevels": levels}))) + "\n" + "</div>"; - }, $Html5Converter_convert_toc$44.$$arity = 1); - - Opal.def(self, '$convert_ulist', $Html5Converter_convert_ulist$45 = function $$convert_ulist(node) { - var $$46, self = this, result = nil, id_attribute = nil, div_classes = nil, marker_checked = nil, marker_unchecked = nil, checklist = nil, ul_class_attribute = nil; - - - result = []; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - div_classes = ["ulist", node.$style(), node.$role()].$compact(); - marker_checked = (marker_unchecked = ""); - if ($truthy((checklist = node['$option?']("checklist")))) { - - div_classes.$unshift(div_classes.$shift(), "checklist"); - ul_class_attribute = " class=\"checklist\""; - if ($truthy(node['$option?']("interactive"))) { - if ($truthy(self.xml_mode)) { - - marker_checked = "<input type=\"checkbox\" data-item-complete=\"1\" checked=\"checked\"/> "; - marker_unchecked = "<input type=\"checkbox\" data-item-complete=\"0\"/> "; - } else { - - marker_checked = "<input type=\"checkbox\" data-item-complete=\"1\" checked> "; - marker_unchecked = "<input type=\"checkbox\" data-item-complete=\"0\"> "; + }; + Tokenizer.prototype.stateInAttributeName = function (c) { + if (c === CharCodes.Eq || isEndOfTagSection(c)) { + this.cbs.onattribname(this.sectionStart, this.index); + this.sectionStart = -1; + this.state = State.AfterAttributeName; + this.stateAfterAttributeName(c); + } + }; + Tokenizer.prototype.stateAfterAttributeName = function (c) { + if (c === CharCodes.Eq) { + this.state = State.BeforeAttributeValue; + } + else if (c === CharCodes.Slash || c === CharCodes.Gt) { + this.cbs.onattribend(QuoteType.NoValue, this.index); + this.state = State.BeforeAttributeName; + this.stateBeforeAttributeName(c); + } + else if (!isWhitespace(c)) { + this.cbs.onattribend(QuoteType.NoValue, this.index); + this.state = State.InAttributeName; + this.sectionStart = this.index; + } + }; + Tokenizer.prototype.stateBeforeAttributeValue = function (c) { + if (c === CharCodes.DoubleQuote) { + this.state = State.InAttributeValueDq; + this.sectionStart = this.index + 1; + } + else if (c === CharCodes.SingleQuote) { + this.state = State.InAttributeValueSq; + this.sectionStart = this.index + 1; + } + else if (!isWhitespace(c)) { + this.sectionStart = this.index; + this.state = State.InAttributeValueNq; + this.stateInAttributeValueNoQuotes(c); // Reconsume token + } + }; + Tokenizer.prototype.handleInAttributeValue = function (c, quote) { + if (c === quote || + (!this.decodeEntities && this.fastForwardTo(quote))) { + this.cbs.onattribdata(this.sectionStart, this.index); + this.sectionStart = -1; + this.cbs.onattribend(quote === CharCodes.DoubleQuote + ? QuoteType.Double + : QuoteType.Single, this.index); + this.state = State.BeforeAttributeName; + } + else if (this.decodeEntities && c === CharCodes.Amp) { + this.baseState = this.state; + this.state = State.BeforeEntity; + } + }; + Tokenizer.prototype.stateInAttributeValueDoubleQuotes = function (c) { + this.handleInAttributeValue(c, CharCodes.DoubleQuote); + }; + Tokenizer.prototype.stateInAttributeValueSingleQuotes = function (c) { + this.handleInAttributeValue(c, CharCodes.SingleQuote); + }; + Tokenizer.prototype.stateInAttributeValueNoQuotes = function (c) { + if (isWhitespace(c) || c === CharCodes.Gt) { + this.cbs.onattribdata(this.sectionStart, this.index); + this.sectionStart = -1; + this.cbs.onattribend(QuoteType.Unquoted, this.index); + this.state = State.BeforeAttributeName; + this.stateBeforeAttributeName(c); + } + else if (this.decodeEntities && c === CharCodes.Amp) { + this.baseState = this.state; + this.state = State.BeforeEntity; + } + }; + Tokenizer.prototype.stateBeforeDeclaration = function (c) { + if (c === CharCodes.OpeningSquareBracket) { + this.state = State.CDATASequence; + this.sequenceIndex = 0; + } + else { + this.state = + c === CharCodes.Dash + ? State.BeforeComment + : State.InDeclaration; + } + }; + Tokenizer.prototype.stateInDeclaration = function (c) { + if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { + this.cbs.ondeclaration(this.sectionStart, this.index); + this.state = State.Text; + this.sectionStart = this.index + 1; + } + }; + Tokenizer.prototype.stateInProcessingInstruction = function (c) { + if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { + this.cbs.onprocessinginstruction(this.sectionStart, this.index); + this.state = State.Text; + this.sectionStart = this.index + 1; + } + }; + Tokenizer.prototype.stateBeforeComment = function (c) { + if (c === CharCodes.Dash) { + this.state = State.InCommentLike; + this.currentSequence = Sequences.CommentEnd; + // Allow short comments (eg. <!-->) + this.sequenceIndex = 2; + this.sectionStart = this.index + 1; + } + else { + this.state = State.InDeclaration; + } + }; + Tokenizer.prototype.stateInSpecialComment = function (c) { + if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { + this.cbs.oncomment(this.sectionStart, this.index, 0); + this.state = State.Text; + this.sectionStart = this.index + 1; + } + }; + Tokenizer.prototype.stateBeforeSpecialS = function (c) { + var lower = c | 0x20; + if (lower === Sequences.ScriptEnd[3]) { + this.startSpecial(Sequences.ScriptEnd, 4); + } + else if (lower === Sequences.StyleEnd[3]) { + this.startSpecial(Sequences.StyleEnd, 4); + } + else { + this.state = State.InTagName; + this.stateInTagName(c); // Consume the token again + } + }; + Tokenizer.prototype.stateBeforeEntity = function (c) { + // Start excess with 1 to include the '&' + this.entityExcess = 1; + this.entityResult = 0; + if (c === CharCodes.Number) { + this.state = State.BeforeNumericEntity; + } + else if (c === CharCodes.Amp) { + // We have two `&` characters in a row. Stay in the current state. + } + else { + this.trieIndex = 0; + this.trieCurrent = this.entityTrie[0]; + this.state = State.InNamedEntity; + this.stateInNamedEntity(c); + } + }; + Tokenizer.prototype.stateInNamedEntity = function (c) { + this.entityExcess += 1; + this.trieIndex = (0, decode_js_1.determineBranch)(this.entityTrie, this.trieCurrent, this.trieIndex + 1, c); + if (this.trieIndex < 0) { + this.emitNamedEntity(); + this.index--; + return; + } + this.trieCurrent = this.entityTrie[this.trieIndex]; + var masked = this.trieCurrent & decode_js_1.BinTrieFlags.VALUE_LENGTH; + // If the branch is a value, store it and continue + if (masked) { + // The mask is the number of bytes of the value, including the current byte. + var valueLength = (masked >> 14) - 1; + // If we have a legacy entity while parsing strictly, just skip the number of bytes + if (!this.allowLegacyEntity() && c !== CharCodes.Semi) { + this.trieIndex += valueLength; } - } else if ($truthy(node.$document()['$attr?']("icons", "font"))) { - - marker_checked = "<i class=\"fa fa-check-square-o\"></i> "; - marker_unchecked = "<i class=\"fa fa-square-o\"></i> "; - } else { - - marker_checked = "✓ "; - marker_unchecked = "❏ "; - }; - } else { - ul_class_attribute = (function() {if ($truthy(node.$style())) { - return "" + " class=\"" + (node.$style()) + "\"" - } else { - return "" - }; return nil; })() - }; - result['$<<']("" + "<div" + (id_attribute) + " class=\"" + (div_classes.$join(" ")) + "\">"); - if ($truthy(node['$title?']())) { - result['$<<']("" + "<div class=\"title\">" + (node.$title()) + "</div>")}; - result['$<<']("" + "<ul" + (ul_class_attribute) + ">"); - $send(node.$items(), 'each', [], ($$46 = function(item){var self = $$46.$$s || this, $a; - - - - if (item == null) { - item = nil; - }; - if ($truthy(item.$id())) { - result['$<<']("" + "<li id=\"" + (item.$id()) + "\"" + ((function() {if ($truthy(item.$role())) { - return "" + " class=\"" + (item.$role()) + "\"" - } else { - return "" - }; return nil; })()) + ">") - } else if ($truthy(item.$role())) { - result['$<<']("" + "<li class=\"" + (item.$role()) + "\">") - } else { - result['$<<']("<li>") - }; - if ($truthy(($truthy($a = checklist) ? item['$attr?']("checkbox") : $a))) { - result['$<<']("" + "<p>" + ((function() {if ($truthy(item['$attr?']("checked"))) { - return marker_checked - } else { - return marker_unchecked - }; return nil; })()) + (item.$text()) + "</p>") - } else { - result['$<<']("" + "<p>" + (item.$text()) + "</p>") - }; - if ($truthy(item['$blocks?']())) { - result['$<<'](item.$content())}; - return result['$<<']("</li>");}, $$46.$$s = self, $$46.$$arity = 1, $$46)); - result['$<<']("</ul>"); - result['$<<']("</div>"); - return result.$join($$($nesting, 'LF')); - }, $Html5Converter_convert_ulist$45.$$arity = 1); - - Opal.def(self, '$convert_verse', $Html5Converter_convert_verse$47 = function $$convert_verse(node) { - var $a, self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil; - - - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["verseblock", node.$role()].$compact(); - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "\n<div class=\"title\">" + (node.$title()) + "</div>" - } else { - return "" - }; return nil; })(); - attribution = (function() {if ($truthy(node['$attr?']("attribution"))) { - - return node.$attr("attribution"); - } else { - return nil - }; return nil; })(); - citetitle = (function() {if ($truthy(node['$attr?']("citetitle"))) { - - return node.$attr("citetitle"); - } else { - return nil - }; return nil; })(); - if ($truthy(($truthy($a = attribution) ? $a : citetitle))) { - - cite_element = (function() {if ($truthy(citetitle)) { - return "" + "<cite>" + (citetitle) + "</cite>" - } else { - return "" - }; return nil; })(); - attribution_text = (function() {if ($truthy(attribution)) { - return "" + "— " + (attribution) + ((function() {if ($truthy(citetitle)) { - return "" + "<br" + (self.void_element_slash) + ">\n" - } else { - return "" - }; return nil; })()) - } else { - return "" - }; return nil; })(); - attribution_element = "" + "\n<div class=\"attribution\">\n" + (attribution_text) + (cite_element) + "\n</div>"; - } else { - attribution_element = "" - }; - return "" + "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<pre class=\"content\">" + (node.$content()) + "</pre>" + (attribution_element) + "\n" + "</div>"; - }, $Html5Converter_convert_verse$47.$$arity = 1); - - Opal.def(self, '$convert_video', $Html5Converter_convert_video$48 = function $$convert_video(node) { - var $a, $b, self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, width_attribute = nil, height_attribute = nil, $case = nil, asset_uri_scheme = nil, start_anchor = nil, delimiter = nil, target = nil, hash = nil, hash_param = nil, autoplay_param = nil, loop_param = nil, muted_param = nil, rel_param_val = nil, start_param = nil, end_param = nil, has_loop_param = nil, mute_param = nil, controls_param = nil, fs_param = nil, fs_attribute = nil, modest_param = nil, theme_param = nil, hl_param = nil, list = nil, list_param = nil, playlist = nil, poster_attribute = nil, val = nil, preload_attribute = nil, start_t = nil, end_t = nil, time_anchor = nil; - - - xml = self.xml_mode; - id_attribute = (function() {if ($truthy(node.$id())) { - return "" + " id=\"" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - classes = ["videoblock"]; - if ($truthy(node['$attr?']("float"))) { - classes['$<<'](node.$attr("float"))}; - if ($truthy(node['$attr?']("align"))) { - classes['$<<']("" + "text-" + (node.$attr("align")))}; - if ($truthy(node.$role())) { - classes['$<<'](node.$role())}; - class_attribute = "" + " class=\"" + (classes.$join(" ")) + "\""; - title_element = (function() {if ($truthy(node['$title?']())) { - return "" + "\n<div class=\"title\">" + (node.$title()) + "</div>" - } else { - return "" - }; return nil; })(); - width_attribute = (function() {if ($truthy(node['$attr?']("width"))) { - return "" + " width=\"" + (node.$attr("width")) + "\"" - } else { - return "" - }; return nil; })(); - height_attribute = (function() {if ($truthy(node['$attr?']("height"))) { - return "" + " height=\"" + (node.$attr("height")) + "\"" - } else { - return "" - }; return nil; })(); - return (function() {$case = node.$attr("poster"); - if ("vimeo"['$===']($case)) { - if ($truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) { - } else { - asset_uri_scheme = "" + (asset_uri_scheme) + ":" - }; - start_anchor = (function() {if ($truthy(node['$attr?']("start"))) { - return "" + "#at=" + (node.$attr("start")) - } else { - return "" - }; return nil; })(); - delimiter = ["?"]; - $b = node.$attr("target").$split("/", 2), $a = Opal.to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (hash = ($a[1] == null ? nil : $a[1])), $b; - hash_param = (function() {if ($truthy((hash = ($truthy($a = hash) ? $a : node.$attr("hash"))))) { - return "" + (($truthy($a = delimiter.$pop()) ? $a : "&")) + "h=" + (hash) - } else { - return "" - }; return nil; })(); - autoplay_param = (function() {if ($truthy(node['$option?']("autoplay"))) { - return "" + (($truthy($a = delimiter.$pop()) ? $a : "&")) + "autoplay=1" - } else { - return "" - }; return nil; })(); - loop_param = (function() {if ($truthy(node['$option?']("loop"))) { - return "" + (($truthy($a = delimiter.$pop()) ? $a : "&")) + "loop=1" - } else { - return "" - }; return nil; })(); - muted_param = (function() {if ($truthy(node['$option?']("muted"))) { - return "" + (($truthy($a = delimiter.$pop()) ? $a : "&")) + "muted=1" - } else { - return "" - }; return nil; })(); - return "" + "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<iframe" + (width_attribute) + (height_attribute) + " src=\"" + (asset_uri_scheme) + "//player.vimeo.com/video/" + (target) + (hash_param) + (autoplay_param) + (loop_param) + (muted_param) + (start_anchor) + "\" frameborder=\"0\"" + ((function() {if ($truthy(node['$option?']("nofullscreen"))) { - return "" - } else { - - return self.$append_boolean_attribute("allowfullscreen", xml); - }; return nil; })()) + "></iframe>\n" + "</div>\n" + "</div>";} - else if ("youtube"['$===']($case)) { - if ($truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) { - } else { - asset_uri_scheme = "" + (asset_uri_scheme) + ":" - }; - rel_param_val = (function() {if ($truthy(node['$option?']("related"))) { - return 1 - } else { - return 0 - }; return nil; })(); - start_param = (function() {if ($truthy(node['$attr?']("start"))) { - return "" + "&start=" + (node.$attr("start")) - } else { - return "" - }; return nil; })(); - end_param = (function() {if ($truthy(node['$attr?']("end"))) { - return "" + "&end=" + (node.$attr("end")) - } else { - return "" - }; return nil; })(); - autoplay_param = (function() {if ($truthy(node['$option?']("autoplay"))) { - return "&autoplay=1" - } else { - return "" - }; return nil; })(); - loop_param = (function() {if ($truthy((has_loop_param = node['$option?']("loop")))) { - return "&loop=1" - } else { - return "" - }; return nil; })(); - mute_param = (function() {if ($truthy(node['$option?']("muted"))) { - return "&mute=1" - } else { - return "" - }; return nil; })(); - controls_param = (function() {if ($truthy(node['$option?']("nocontrols"))) { - return "&controls=0" - } else { - return "" - }; return nil; })(); - if ($truthy(node['$option?']("nofullscreen"))) { - - fs_param = "&fs=0"; - fs_attribute = ""; - } else { - - fs_param = ""; - fs_attribute = self.$append_boolean_attribute("allowfullscreen", xml); - }; - modest_param = (function() {if ($truthy(node['$option?']("modest"))) { - return "&modestbranding=1" - } else { - return "" - }; return nil; })(); - theme_param = (function() {if ($truthy(node['$attr?']("theme"))) { - return "" + "&theme=" + (node.$attr("theme")) - } else { - return "" - }; return nil; })(); - hl_param = (function() {if ($truthy(node['$attr?']("lang"))) { - return "" + "&hl=" + (node.$attr("lang")) - } else { - return "" - }; return nil; })(); - $b = node.$attr("target").$split("/", 2), $a = Opal.to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (list = ($a[1] == null ? nil : $a[1])), $b; - if ($truthy((list = ($truthy($a = list) ? $a : node.$attr("list"))))) { - list_param = "" + "&list=" + (list) - } else { - - $b = target.$split(",", 2), $a = Opal.to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (playlist = ($a[1] == null ? nil : $a[1])), $b; - if ($truthy((playlist = ($truthy($a = playlist) ? $a : node.$attr("playlist"))))) { - list_param = "" + "&playlist=" + (target) + "," + (playlist) - } else { - list_param = (function() {if ($truthy(has_loop_param)) { - return "" + "&playlist=" + (target) - } else { - return "" - }; return nil; })() - }; - }; - return "" + "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<iframe" + (width_attribute) + (height_attribute) + " src=\"" + (asset_uri_scheme) + "//www.youtube.com/embed/" + (target) + "?rel=" + (rel_param_val) + (start_param) + (end_param) + (autoplay_param) + (loop_param) + (mute_param) + (controls_param) + (list_param) + (fs_param) + (modest_param) + (theme_param) + (hl_param) + "\" frameborder=\"0\"" + (fs_attribute) + "></iframe>\n" + "</div>\n" + "</div>";} + else { + // Add 1 as we have already incremented the excess + var entityStart = this.index - this.entityExcess + 1; + if (entityStart > this.sectionStart) { + this.emitPartial(this.sectionStart, entityStart); + } + // If this is a surrogate pair, consume the next two bytes + this.entityResult = this.trieIndex; + this.trieIndex += valueLength; + this.entityExcess = 0; + this.sectionStart = this.index + 1; + if (valueLength === 0) { + this.emitNamedEntity(); + } + } + } + }; + Tokenizer.prototype.emitNamedEntity = function () { + this.state = this.baseState; + if (this.entityResult === 0) { + return; + } + var valueLength = (this.entityTrie[this.entityResult] & decode_js_1.BinTrieFlags.VALUE_LENGTH) >> + 14; + switch (valueLength) { + case 1: { + this.emitCodePoint(this.entityTrie[this.entityResult] & + ~decode_js_1.BinTrieFlags.VALUE_LENGTH); + break; + } + case 2: { + this.emitCodePoint(this.entityTrie[this.entityResult + 1]); + break; + } + case 3: { + this.emitCodePoint(this.entityTrie[this.entityResult + 1]); + this.emitCodePoint(this.entityTrie[this.entityResult + 2]); + } + } + }; + Tokenizer.prototype.stateBeforeNumericEntity = function (c) { + if ((c | 0x20) === CharCodes.LowerX) { + this.entityExcess++; + this.state = State.InHexEntity; + } else { - poster_attribute = (function() {if ($truthy((val = node.$attr("poster"))['$nil_or_empty?']())) { - return "" - } else { - return "" + " poster=\"" + (node.$media_uri(val)) + "\"" - }; return nil; })(); - preload_attribute = (function() {if ($truthy((val = node.$attr("preload"))['$nil_or_empty?']())) { - return "" - } else { - return "" + " preload=\"" + (val) + "\"" - }; return nil; })(); - start_t = node.$attr("start"); - end_t = node.$attr("end"); - time_anchor = (function() {if ($truthy(($truthy($a = start_t) ? $a : end_t))) { - return "" + "#t=" + (($truthy($a = start_t) ? $a : "")) + ((function() {if ($truthy(end_t)) { - return "" + "," + (end_t) - } else { - return "" - }; return nil; })()) - } else { - return "" - }; return nil; })(); - return "" + "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<video src=\"" + (node.$media_uri(node.$attr("target"))) + (time_anchor) + "\"" + (width_attribute) + (height_attribute) + (poster_attribute) + ((function() {if ($truthy(node['$option?']("autoplay"))) { - - return self.$append_boolean_attribute("autoplay", xml); - } else { - return "" - }; return nil; })()) + ((function() {if ($truthy(node['$option?']("muted"))) { - - return self.$append_boolean_attribute("muted", xml); - } else { - return "" - }; return nil; })()) + ((function() {if ($truthy(node['$option?']("nocontrols"))) { - return "" - } else { - - return self.$append_boolean_attribute("controls", xml); - }; return nil; })()) + ((function() {if ($truthy(node['$option?']("loop"))) { - - return self.$append_boolean_attribute("loop", xml); - } else { - return "" - }; return nil; })()) + (preload_attribute) + ">\n" + "Your browser does not support the video tag.\n" + "</video>\n" + "</div>\n" + "</div>";}})(); - }, $Html5Converter_convert_video$48.$$arity = 1); - - Opal.def(self, '$convert_inline_anchor', $Html5Converter_convert_inline_anchor$49 = function $$convert_inline_anchor(node) { - var $a, $b, self = this, $case = nil, path = nil, attrs = nil, text = nil, ref = nil, refid = nil, top = nil, outer = nil; - - return (function() {$case = node.$type(); - if ("xref"['$===']($case)) { - if ($truthy((path = node.$attributes()['$[]']("path")))) { - - attrs = self.$append_link_constraint_attrs(node, (function() {if ($truthy(node.$role())) { - return ["" + " class=\"" + (node.$role()) + "\""] - } else { - return [] - }; return nil; })()).$join(); - text = ($truthy($a = node.$text()) ? $a : path); - } else { - - attrs = (function() {if ($truthy(node.$role())) { - return "" + " class=\"" + (node.$role()) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy((text = node.$text()))) { - } else if ($truthy($$($nesting, 'AbstractNode')['$===']((ref = ($truthy($a = (self.refs = ($truthy($b = self.refs) ? $b : node.$document().$catalog()['$[]']("refs")))['$[]']((refid = node.$attributes()['$[]']("refid")))) ? $a : (function() {if ($truthy(refid['$nil_or_empty?']())) { - - return (top = self.$get_root_document(node)); - } else { - return nil - }; return nil; })()))))) { - if ($truthy(($truthy($a = (self.resolving_xref = ($truthy($b = self.resolving_xref) ? $b : (outer = true)))) ? outer : $a))) { - - if ($truthy((text = ref.$xreftext(node.$attr("xrefstyle", nil, true))))) { - if ($truthy(text['$include?']("<a"))) { - text = text.$gsub($$($nesting, 'DropAnchorRx'), "")} - } else { - text = (function() {if ($truthy(top)) { - return "[^top]" - } else { - return "" + "[" + (refid) + "]" - }; return nil; })() - }; - self.resolving_xref = nil; - } else { - text = (function() {if ($truthy(top)) { - return "[^top]" - } else { - return "" + "[" + (refid) + "]" - }; return nil; })() + this.state = State.InNumericEntity; + this.stateInNumericEntity(c); + } + }; + Tokenizer.prototype.emitNumericEntity = function (strict) { + var entityStart = this.index - this.entityExcess - 1; + var numberStart = entityStart + 2 + Number(this.state === State.InHexEntity); + if (numberStart !== this.index) { + // Emit leading data if any + if (entityStart > this.sectionStart) { + this.emitPartial(this.sectionStart, entityStart); } - } else { - text = "" + "[" + (refid) + "]" - }; - }; - return "" + "<a href=\"" + (node.$target()) + "\"" + (attrs) + ">" + (text) + "</a>";} - else if ("ref"['$===']($case)) {return "" + "<a id=\"" + (node.$id()) + "\"></a>"} - else if ("link"['$===']($case)) { - attrs = (function() {if ($truthy(node.$id())) { - return ["" + " id=\"" + (node.$id()) + "\""] - } else { - return [] - }; return nil; })(); - if ($truthy(node.$role())) { - attrs['$<<']("" + " class=\"" + (node.$role()) + "\"")}; - if ($truthy(node['$attr?']("title"))) { - attrs['$<<']("" + " title=\"" + (node.$attr("title")) + "\"")}; - return "" + "<a href=\"" + (node.$target()) + "\"" + (self.$append_link_constraint_attrs(node, attrs).$join()) + ">" + (node.$text()) + "</a>";} - else if ("bibref"['$===']($case)) {return "" + "<a id=\"" + (node.$id()) + "\"></a>[" + (($truthy($a = node.$reftext()) ? $a : node.$id())) + "]"} - else { - self.$logger().$warn("" + "unknown anchor type: " + (node.$type().$inspect())); - return nil;}})() - }, $Html5Converter_convert_inline_anchor$49.$$arity = 1); - - Opal.def(self, '$convert_inline_break', $Html5Converter_convert_inline_break$50 = function $$convert_inline_break(node) { - var self = this; - - return "" + (node.$text()) + "<br" + (self.void_element_slash) + ">" - }, $Html5Converter_convert_inline_break$50.$$arity = 1); - - Opal.def(self, '$convert_inline_button', $Html5Converter_convert_inline_button$51 = function $$convert_inline_button(node) { - var self = this; - - return "" + "<b class=\"button\">" + (node.$text()) + "</b>" - }, $Html5Converter_convert_inline_button$51.$$arity = 1); - - Opal.def(self, '$convert_inline_callout', $Html5Converter_convert_inline_callout$52 = function $$convert_inline_callout(node) { - var self = this, src = nil, guard = nil; - - if ($truthy(node.$document()['$attr?']("icons", "font"))) { - return "" + "<i class=\"conum\" data-value=\"" + (node.$text()) + "\"></i><b>(" + (node.$text()) + ")</b>" - } else if ($truthy(node.$document()['$attr?']("icons"))) { - - src = node.$icon_uri("" + "callouts/" + (node.$text())); - return "" + "<img src=\"" + (src) + "\" alt=\"" + (node.$text()) + "\"" + (self.void_element_slash) + ">"; - } else if ($truthy($$$('::', 'Array')['$===']((guard = node.$attributes()['$[]']("guard"))))) { - return "" + "<!--<b class=\"conum\">(" + (node.$text()) + ")</b>-->" - } else { - return "" + (guard) + "<b class=\"conum\">(" + (node.$text()) + ")</b>" + this.sectionStart = this.index + Number(strict); + this.emitCodePoint((0, decode_js_1.replaceCodePoint)(this.entityResult)); } - }, $Html5Converter_convert_inline_callout$52.$$arity = 1); - - Opal.def(self, '$convert_inline_footnote', $Html5Converter_convert_inline_footnote$53 = function $$convert_inline_footnote(node) { - var self = this, index = nil, id_attr = nil; - - if ($truthy((index = node.$attr("index")))) { - if (node.$type()['$==']("xref")) { - return "" + "<sup class=\"footnoteref\">[<a class=\"footnote\" href=\"#_footnotedef_" + (index) + "\" title=\"View footnote.\">" + (index) + "</a>]</sup>" - } else { - - id_attr = (function() {if ($truthy(node.$id())) { - return "" + " id=\"_footnote_" + (node.$id()) + "\"" - } else { - return "" - }; return nil; })(); - return "" + "<sup class=\"footnote\"" + (id_attr) + ">[<a id=\"_footnoteref_" + (index) + "\" class=\"footnote\" href=\"#_footnotedef_" + (index) + "\" title=\"View footnote.\">" + (index) + "</a>]</sup>"; - } - } else if (node.$type()['$==']("xref")) { - return "" + "<sup class=\"footnoteref red\" title=\"Unresolved footnote reference.\">[" + (node.$text()) + "]</sup>" - } else { - return nil + this.state = this.baseState; + }; + Tokenizer.prototype.stateInNumericEntity = function (c) { + if (c === CharCodes.Semi) { + this.emitNumericEntity(true); } - }, $Html5Converter_convert_inline_footnote$53.$$arity = 1); - - Opal.def(self, '$convert_inline_image', $Html5Converter_convert_inline_image$54 = function $$convert_inline_image(node) { - var $a, $b, self = this, target = nil, type = nil, icons = nil, i_class_attr_val = nil, attrs = nil, img = nil, fallback = nil, class_attr_val = nil, role = nil; - - - target = node.$target(); - if ((type = ($truthy($a = node.$type()) ? $a : "image"))['$==']("icon")) { - if ((icons = node.$document().$attr("icons"))['$==']("font")) { - - i_class_attr_val = "" + "fa fa-" + (target); - if ($truthy(node['$attr?']("size"))) { - i_class_attr_val = "" + (i_class_attr_val) + " fa-" + (node.$attr("size"))}; - if ($truthy(node['$attr?']("flip"))) { - i_class_attr_val = "" + (i_class_attr_val) + " fa-flip-" + (node.$attr("flip")) - } else if ($truthy(node['$attr?']("rotate"))) { - i_class_attr_val = "" + (i_class_attr_val) + " fa-rotate-" + (node.$attr("rotate"))}; - attrs = (function() {if ($truthy(node['$attr?']("title"))) { - return "" + " title=\"" + (node.$attr("title")) + "\"" - } else { - return "" - }; return nil; })(); - img = "" + "<i class=\"" + (i_class_attr_val) + "\"" + (attrs) + "></i>"; - } else if ($truthy(icons)) { - - attrs = (function() {if ($truthy(node['$attr?']("width"))) { - return "" + " width=\"" + (node.$attr("width")) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(node['$attr?']("height"))) { - attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""}; - if ($truthy(node['$attr?']("title"))) { - attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""}; - img = "" + "<img src=\"" + (node.$icon_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">"; - } else { - img = "" + "[" + (node.$alt()) + "]" - } - } else { - - attrs = (function() {if ($truthy(node['$attr?']("width"))) { - return "" + " width=\"" + (node.$attr("width")) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(node['$attr?']("height"))) { - attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""}; - if ($truthy(node['$attr?']("title"))) { - attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""}; - if ($truthy(($truthy($a = ($truthy($b = node['$attr?']("format", "svg")) ? $b : target['$include?'](".svg"))) ? $rb_lt(node.$document().$safe(), $$$($$($nesting, 'SafeMode'), 'SECURE')) : $a))) { - if ($truthy(node['$option?']("inline"))) { - img = ($truthy($a = self.$read_svg_contents(node, target)) ? $a : "" + "<span class=\"alt\">" + (node.$alt()) + "</span>") - } else if ($truthy(node['$option?']("interactive"))) { - - fallback = (function() {if ($truthy(node['$attr?']("fallback"))) { - return "" + "<img src=\"" + (node.$image_uri(node.$attr("fallback"))) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">" - } else { - return "" + "<span class=\"alt\">" + (node.$alt()) + "</span>" - }; return nil; })(); - img = "" + "<object type=\"image/svg+xml\" data=\"" + (node.$image_uri(target)) + "\"" + (attrs) + ">" + (fallback) + "</object>"; - } else { - img = "" + "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">" + else if (isNumber(c)) { + this.entityResult = this.entityResult * 10 + (c - CharCodes.Zero); + this.entityExcess++; + } + else { + if (this.allowLegacyEntity()) { + this.emitNumericEntity(false); } - } else { - img = "" + "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">" - }; - }; - if ($truthy(node['$attr?']("link"))) { - img = "" + "<a class=\"image\" href=\"" + (node.$attr("link")) + "\"" + (self.$append_link_constraint_attrs(node).$join()) + ">" + (img) + "</a>"}; - class_attr_val = type; - if ($truthy((role = node.$role()))) { - class_attr_val = (function() {if ($truthy(node['$attr?']("float"))) { - return "" + (class_attr_val) + " " + (node.$attr("float")) + " " + (role) - } else { - return "" + (class_attr_val) + " " + (role) - }; return nil; })() - } else if ($truthy(node['$attr?']("float"))) { - class_attr_val = "" + (class_attr_val) + " " + (node.$attr("float"))}; - return "" + "<span class=\"" + (class_attr_val) + "\">" + (img) + "</span>"; - }, $Html5Converter_convert_inline_image$54.$$arity = 1); - - Opal.def(self, '$convert_inline_indexterm', $Html5Converter_convert_inline_indexterm$55 = function $$convert_inline_indexterm(node) { - var self = this; - - if (node.$type()['$==']("visible")) { - return node.$text() - } else { - return "" + else { + this.state = this.baseState; + } + this.index--; } - }, $Html5Converter_convert_inline_indexterm$55.$$arity = 1); - - Opal.def(self, '$convert_inline_kbd', $Html5Converter_convert_inline_kbd$56 = function $$convert_inline_kbd(node) { - var self = this, keys = nil; - - if ((keys = node.$attr("keys")).$size()['$=='](1)) { - return "" + "<kbd>" + (keys['$[]'](0)) + "</kbd>" - } else { - return "" + "<span class=\"keyseq\"><kbd>" + (keys.$join("</kbd>+<kbd>")) + "</kbd></span>" + }; + Tokenizer.prototype.stateInHexEntity = function (c) { + if (c === CharCodes.Semi) { + this.emitNumericEntity(true); } - }, $Html5Converter_convert_inline_kbd$56.$$arity = 1); - - Opal.def(self, '$convert_inline_menu', $Html5Converter_convert_inline_menu$57 = function $$convert_inline_menu(node) { - var self = this, caret = nil, submenu_joiner = nil, menu = nil, submenus = nil, menuitem = nil; - - - caret = (function() {if ($truthy(node.$document()['$attr?']("icons", "font"))) { - return " <i class=\"fa fa-angle-right caret\"></i> " - } else { - return " <b class=\"caret\">›</b> " - }; return nil; })(); - submenu_joiner = "" + "</b>" + (caret) + "<b class=\"submenu\">"; - menu = node.$attr("menu"); - if ($truthy((submenus = node.$attr("submenus"))['$empty?']())) { - if ($truthy((menuitem = node.$attr("menuitem")))) { - return "" + "<span class=\"menuseq\"><b class=\"menu\">" + (menu) + "</b>" + (caret) + "<b class=\"menuitem\">" + (menuitem) + "</b></span>" - } else { - return "" + "<b class=\"menuref\">" + (menu) + "</b>" - } - } else { - return "" + "<span class=\"menuseq\"><b class=\"menu\">" + (menu) + "</b>" + (caret) + "<b class=\"submenu\">" + (submenus.$join(submenu_joiner)) + "</b>" + (caret) + "<b class=\"menuitem\">" + (node.$attr("menuitem")) + "</b></span>" - }; - }, $Html5Converter_convert_inline_menu$57.$$arity = 1); - - Opal.def(self, '$convert_inline_quoted', $Html5Converter_convert_inline_quoted$58 = function $$convert_inline_quoted(node) { - var $a, $b, self = this, open = nil, close = nil, tag = nil, class_attr = nil; - - - $b = $$($nesting, 'QUOTE_TAGS')['$[]'](node.$type()), $a = Opal.to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])), (tag = ($a[2] == null ? nil : $a[2])), $b; - if ($truthy(node.$id())) { - - class_attr = (function() {if ($truthy(node.$role())) { - return "" + " class=\"" + (node.$role()) + "\"" - } else { - return "" - }; return nil; })(); - if ($truthy(tag)) { - return "" + (open.$chop()) + " id=\"" + (node.$id()) + "\"" + (class_attr) + ">" + (node.$text()) + (close) - } else { - return "" + "<span id=\"" + (node.$id()) + "\"" + (class_attr) + ">" + (open) + (node.$text()) + (close) + "</span>" - }; - } else if ($truthy(node.$role())) { - if ($truthy(tag)) { - return "" + (open.$chop()) + " class=\"" + (node.$role()) + "\">" + (node.$text()) + (close) - } else { - return "" + "<span class=\"" + (node.$role()) + "\">" + (open) + (node.$text()) + (close) + "</span>" - } - } else { - return "" + (open) + (node.$text()) + (close) - }; - }, $Html5Converter_convert_inline_quoted$58.$$arity = 1); - - Opal.def(self, '$read_svg_contents', $Html5Converter_read_svg_contents$59 = function $$read_svg_contents(node, target) { - var $$60, self = this, svg = nil, old_start_tag = nil, new_start_tag = nil, start_tag_match = nil; - - - if ($truthy((svg = node.$read_contents(target, $hash2(["start", "normalize", "label", "warn_if_empty"], {"start": node.$document().$attr("imagesdir"), "normalize": true, "label": "SVG", "warn_if_empty": true}))))) { - - if ($truthy(svg['$empty?']())) { - return nil}; - if ($truthy(svg['$start_with?']("<svg"))) { - } else { - svg = svg.$sub($$($nesting, 'SvgPreambleRx'), "") - }; - old_start_tag = (new_start_tag = (start_tag_match = nil)); - $send(["width", "height"], 'each', [], ($$60 = function(dim){var self = $$60.$$s || this, $a, $b; - - - - if (dim == null) { - dim = nil; - }; - if ($truthy(node['$attr?'](dim))) { - } else { - return nil; - }; - if ($truthy(new_start_tag)) { - } else { - - if ((start_tag_match = ($truthy($a = start_tag_match) ? $a : ($truthy($b = svg.$match($$($nesting, 'SvgStartTagRx'))) ? $b : "no_match")))['$==']("no_match")) { - return nil;}; - new_start_tag = (old_start_tag = start_tag_match['$[]'](0)).$gsub($$($nesting, 'DimensionAttributeRx'), ""); - }; - return (new_start_tag = "" + (new_start_tag.$chop()) + " " + (dim) + "=\"" + (node.$attr(dim)) + "\">");}, $$60.$$s = self, $$60.$$arity = 1, $$60)); - if ($truthy(new_start_tag)) { - svg = "" + (new_start_tag) + (svg['$[]'](Opal.Range.$new(old_start_tag.$length(), -1, false)))};}; - return svg; - }, $Html5Converter_read_svg_contents$59.$$arity = 2); - self.$private(); - - Opal.def(self, '$append_boolean_attribute', $Html5Converter_append_boolean_attribute$61 = function $$append_boolean_attribute(name, xml) { - var self = this; - - if ($truthy(xml)) { - return "" + " " + (name) + "=\"" + (name) + "\"" - } else { - return "" + " " + (name) + else if (isNumber(c)) { + this.entityResult = this.entityResult * 16 + (c - CharCodes.Zero); + this.entityExcess++; } - }, $Html5Converter_append_boolean_attribute$61.$$arity = 2); - - Opal.def(self, '$append_link_constraint_attrs', $Html5Converter_append_link_constraint_attrs$62 = function $$append_link_constraint_attrs(node, attrs) { - var $a, self = this, rel = nil, window = nil; - - - - if (attrs == null) { - attrs = []; - }; - if ($truthy(node['$option?']("nofollow"))) { - rel = "nofollow"}; - if ($truthy((window = node.$attributes()['$[]']("window")))) { - - attrs['$<<']("" + " target=\"" + (window) + "\""); - if ($truthy(($truthy($a = window['$==']("_blank")) ? $a : node['$option?']("noopener")))) { - attrs['$<<']((function() {if ($truthy(rel)) { - return "" + " rel=\"" + (rel) + " noopener\"" - } else { - return " rel=\"noopener\"" - }; return nil; })())}; - } else if ($truthy(rel)) { - attrs['$<<']("" + " rel=\"" + (rel) + "\"")}; - return attrs; - }, $Html5Converter_append_link_constraint_attrs$62.$$arity = -2); - - Opal.def(self, '$encode_attribute_value', $Html5Converter_encode_attribute_value$63 = function $$encode_attribute_value(val) { - var self = this; - - if ($truthy(val['$include?']("\""))) { - - return val.$gsub("\"", """); - } else { - return val + else if (isHexDigit(c)) { + this.entityResult = + this.entityResult * 16 + ((c | 0x20) - CharCodes.LowerA + 10); + this.entityExcess++; } - }, $Html5Converter_encode_attribute_value$63.$$arity = 1); - - Opal.def(self, '$generate_manname_section', $Html5Converter_generate_manname_section$64 = function $$generate_manname_section(node) { - var $a, self = this, manname_title = nil, next_section = nil, next_section_title = nil, manname_id_attr = nil, manname_id = nil; - - - manname_title = node.$attr("manname-title", "Name"); - if ($truthy(($truthy($a = (next_section = node.$sections()['$[]'](0))) ? (next_section_title = next_section.$title())['$=='](next_section_title.$upcase()) : $a))) { - manname_title = manname_title.$upcase()}; - manname_id_attr = (function() {if ($truthy((manname_id = node.$attr("manname-id")))) { - return "" + " id=\"" + (manname_id) + "\"" - } else { - return "" - }; return nil; })(); - return "" + "<h2" + (manname_id_attr) + ">" + (manname_title) + "</h2>\n" + "<div class=\"sectionbody\">\n" + "<p>" + (node.$attr("mannames").$join(", ")) + " - " + (node.$attr("manpurpose")) + "</p>\n" + "</div>"; - }, $Html5Converter_generate_manname_section$64.$$arity = 1); - - Opal.def(self, '$get_root_document', $Html5Converter_get_root_document$65 = function $$get_root_document(node) { - var $a, self = this; - - - while ($truthy((node = node.$document())['$nested?']())) { - node = node.$parent_document() - }; - return node; - }, $Html5Converter_get_root_document$65.$$arity = 1); - - Opal.def(self, '$method_missing', $Html5Converter_method_missing$66 = function $$method_missing(id, $a) { - var $post_args, args, $b, $iter = $Html5Converter_method_missing$66.$$p, $yield = $iter || nil, self = this, name = nil, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - - if ($iter) $Html5Converter_method_missing$66.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; + else { + if (this.allowLegacyEntity()) { + this.emitNumericEntity(false); + } + else { + this.state = this.baseState; + } + this.index--; } - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - if ($truthy(($truthy($b = (name = id.$to_s())['$start_with?']("convert_")['$!']()) ? self['$handles?'](name) : $b))) { - - return $send(self, 'send', ["" + "convert_" + (name)].concat(Opal.to_a(args))); - } else { - return $send(self, Opal.find_super_dispatcher(self, 'method_missing', $Html5Converter_method_missing$66, false), $zuper, $iter) - }; - }, $Html5Converter_method_missing$66.$$arity = -2); - return (Opal.def(self, '$respond_to_missing?', $Html5Converter_respond_to_missing$ques$67 = function(id, $a) { - var $post_args, options, $b, self = this, name = nil; - - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - options = $post_args;; - return ($truthy($b = (name = id.$to_s())['$start_with?']("convert_")['$!']()) ? self['$handles?'](name) : $b); - }, $Html5Converter_respond_to_missing$ques$67.$$arity = -2), nil) && 'respond_to_missing?'; - })($$($nesting, 'Converter'), $$$($$($nesting, 'Converter'), 'Base'), $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/extensions"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $hash2 = Opal.hash2, $send = Opal.send, $hash = Opal.hash; - - Opal.add_stubs(['$==', '$[]=', '$config', '$-', '$const_defined?', '$singleton_class?', '$include', '$const_get', '$extend', '$attr_reader', '$merge', '$class', '$update', '$raise', '$document', '$doctype', '$[]', '$+', '$level', '$delete', '$>', '$casecmp', '$new', '$title=', '$sectname=', '$special=', '$fetch', '$numbered=', '$!', '$key?', '$attr?', '$special', '$numbered', '$generate_id', '$title', '$id=', '$update_attributes', '$tr', '$basename', '$create_block', '$assign_caption', '$===', '$parse_blocks', '$empty?', '$include?', '$sub_attributes', '$parse', '$each', '$define_method', '$unshift', '$shift', '$send', '$size', '$binding', '$receiver', '$define_singleton_method', '$instance_exec', '$to_proc', '$call', '$option', '$flatten', '$respond_to?', '$to_s', '$partition', '$to_i', '$<<', '$compact', '$inspect', '$attr_accessor', '$to_set', '$match?', '$resolve_regexp', '$method', '$register', '$values', '$groups', '$arity', '$activate', '$add_document_processor', '$any?', '$select', '$add_syntax_processor', '$to_sym', '$instance_variable_get', '$kind', '$private', '$join', '$map', '$split', '$capitalize', '$instance_variable_set', '$resolve_args', '$enable_dsl', '$singleton_class', '$process_block_given?', '$source_location', '$freeze', '$resolve_class', '$<', '$update_config', '$as_symbol', '$name', '$name=', '$pop', '$-@', '$next_auto_id', '$generate_name']); - - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - } else { - nil - }; - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); - - (function($base, $parent_nesting) { - var self = $module($base, 'Extensions'); - - var $nesting = [self].concat($parent_nesting); - - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Processor'); - - var $nesting = [self].concat($parent_nesting), $Processor_initialize$4, $Processor_update_config$5, $Processor_process$6, $Processor_create_section$7, $Processor_create_block$8, $Processor_create_list$9, $Processor_create_list_item$10, $Processor_create_image_block$11, $Processor_create_inline$12, $Processor_parse_content$13, $Processor_parse_attributes$14, $Processor$15; - - self.$$prototype.config = nil; - - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $config$1, $option$2, $enable_dsl$3; - - - - Opal.def(self, '$config', $config$1 = function $$config() { - var $a, self = this; - if (self.config == null) self.config = nil; - - return (self.config = ($truthy($a = self.config) ? $a : $hash2([], {}))) - }, $config$1.$$arity = 0); - - Opal.def(self, '$option', $option$2 = function $$option(key, default_value) { - var self = this, $writer = nil; - - - $writer = [key, default_value]; - $send(self.$config(), '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $option$2.$$arity = 2); - - Opal.def(self, '$enable_dsl', $enable_dsl$3 = function $$enable_dsl() { - var self = this; - - if ($truthy(self['$const_defined?']("DSL"))) { - if ($truthy(self['$singleton_class?']())) { - return self.$include(self.$const_get("DSL")) - } else { - return self.$extend(self.$const_get("DSL")) - } - } else { - return nil + }; + Tokenizer.prototype.allowLegacyEntity = function () { + return (!this.xmlMode && + (this.baseState === State.Text || + this.baseState === State.InSpecialTag)); + }; + /** + * Remove data that has already been consumed from the buffer. + */ + Tokenizer.prototype.cleanup = function () { + // If we are inside of text or attributes, emit what we already have. + if (this.running && this.sectionStart !== this.index) { + if (this.state === State.Text || + (this.state === State.InSpecialTag && this.sequenceIndex === 0)) { + this.cbs.ontext(this.sectionStart, this.index); + this.sectionStart = this.index; } - }, $enable_dsl$3.$$arity = 0); - return Opal.alias(self, "use_dsl", "enable_dsl"); - })(Opal.get_singleton_class(self), $nesting); - self.$attr_reader("config"); - - Opal.def(self, '$initialize', $Processor_initialize$4 = function $$initialize(config) { - var self = this; - - - - if (config == null) { - config = $hash2([], {}); - }; - return (self.config = self.$class().$config().$merge(config)); - }, $Processor_initialize$4.$$arity = -1); - - Opal.def(self, '$update_config', $Processor_update_config$5 = function $$update_config(config) { - var self = this; - - return self.config.$update(config) - }, $Processor_update_config$5.$$arity = 1); - - Opal.def(self, '$process', $Processor_process$6 = function $$process($a) { - var $post_args, args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'Processor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method"); - }, $Processor_process$6.$$arity = -1); - - Opal.def(self, '$create_section', $Processor_create_section$7 = function $$create_section(parent, title, attrs, opts) { - var $a, self = this, doc = nil, book = nil, doctype = nil, level = nil, style = nil, sectname = nil, special = nil, sect = nil, $writer = nil, id = nil; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - doc = parent.$document(); - book = (doctype = doc.$doctype())['$==']("book"); - level = ($truthy($a = opts['$[]']("level")) ? $a : $rb_plus(parent.$level(), 1)); - if ($truthy((style = attrs.$delete("style")))) { - if ($truthy(($truthy($a = book) ? style['$==']("abstract") : $a))) { - $a = ["chapter", 1], (sectname = $a[0]), (level = $a[1]), $a - } else { - - $a = [style, true], (sectname = $a[0]), (special = $a[1]), $a; - if (level['$=='](0)) { - level = 1}; + else if (this.state === State.InAttributeValueDq || + this.state === State.InAttributeValueSq || + this.state === State.InAttributeValueNq) { + this.cbs.onattribdata(this.sectionStart, this.index); + this.sectionStart = this.index; } - } else if ($truthy(book)) { - sectname = (function() {if (level['$=='](0)) { - return "part" - } else { - - if ($truthy($rb_gt(level, 1))) { - return "section" - } else { - return "chapter" - }; - }; return nil; })() - } else if ($truthy((($a = doctype['$==']("manpage")) ? title.$casecmp("synopsis")['$=='](0) : doctype['$==']("manpage")))) { - $a = ["synopsis", true], (sectname = $a[0]), (special = $a[1]), $a - } else { - sectname = "section" - }; - sect = $$($nesting, 'Section').$new(parent, level); - $a = [title, sectname], sect['$title=']($a[0]), sect['$sectname=']($a[1]), $a; - if ($truthy(special)) { - - - $writer = [true]; - $send(sect, 'special=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - if ($truthy(opts.$fetch("numbered", style['$==']("appendix")))) { - - $writer = [true]; - $send(sect, 'numbered=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)]; - } else if ($truthy(($truthy($a = opts['$key?']("numbered")['$!']()) ? doc['$attr?']("sectnums", "all") : $a))) { - - $writer = [(function() {if ($truthy(($truthy($a = book) ? level['$=='](1) : $a))) { - return "chapter" - } else { - return true - }; return nil; })()]; - $send(sect, 'numbered=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];}; - } else if ($truthy($rb_gt(level, 0))) { - if ($truthy(opts.$fetch("numbered", doc['$attr?']("sectnums")))) { - - $writer = [(function() {if ($truthy(sect.$special())) { - return ($truthy($a = parent.$numbered()) ? true : $a) - } else { - return true - }; return nil; })()]; - $send(sect, 'numbered=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];} - } else if ($truthy(opts.$fetch("numbered", ($truthy($a = book) ? doc['$attr?']("partnums") : $a)))) { - - $writer = [true]; - $send(sect, 'numbered=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];}; - if ((id = attrs['$[]']("id"))['$=='](false)) { - attrs.$delete("id") - } else { - - $writer = [(($writer = ["id", ($truthy($a = id) ? $a : (function() {if ($truthy(doc['$attr?']("sectids"))) { - - return $$($nesting, 'Section').$generate_id(sect.$title(), doc); - } else { - return nil - }; return nil; })())]), $send(attrs, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])]; - $send(sect, 'id=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)]; - }; - sect.$update_attributes(attrs); - return sect; - }, $Processor_create_section$7.$$arity = -4); - - Opal.def(self, '$create_block', $Processor_create_block$8 = function $$create_block(parent, context, source, attrs, opts) { - var self = this; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - return $$($nesting, 'Block').$new(parent, context, $hash2(["source", "attributes"], {"source": source, "attributes": attrs}).$merge(opts)); - }, $Processor_create_block$8.$$arity = -5); - - Opal.def(self, '$create_list', $Processor_create_list$9 = function $$create_list(parent, context, attrs) { - var self = this, list = nil; - - - - if (attrs == null) { - attrs = nil; - }; - list = $$($nesting, 'List').$new(parent, context); - if ($truthy(attrs)) { - list.$update_attributes(attrs)}; - return list; - }, $Processor_create_list$9.$$arity = -3); - - Opal.def(self, '$create_list_item', $Processor_create_list_item$10 = function $$create_list_item(parent, text) { - var self = this; - - - - if (text == null) { - text = nil; - }; - return $$($nesting, 'ListItem').$new(parent, text); - }, $Processor_create_list_item$10.$$arity = -2); - - Opal.def(self, '$create_image_block', $Processor_create_image_block$11 = function $$create_image_block(parent, attrs, opts) { - var $a, self = this, target = nil, $writer = nil, title = nil, block = nil; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - if ($truthy((target = attrs['$[]']("target")))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "Unable to create an image block, target attribute is required") - }; - ($truthy($a = attrs['$[]']("alt")) ? $a : (($writer = ["alt", (($writer = ["default-alt", $$($nesting, 'Helpers').$basename(target, true).$tr("_-", " ")]), $send(attrs, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])]), $send(attrs, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - title = (function() {if ($truthy(attrs['$key?']("title"))) { - - return attrs.$delete("title"); - } else { - return nil - }; return nil; })(); - block = self.$create_block(parent, "image", nil, attrs, opts); - if ($truthy(title)) { - - - $writer = [title]; - $send(block, 'title=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - block.$assign_caption(attrs.$delete("caption"), "figure");}; - return block; - }, $Processor_create_image_block$11.$$arity = -3); - - Opal.def(self, '$create_inline', $Processor_create_inline$12 = function $$create_inline(parent, context, text, opts) { - var self = this; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - return $$($nesting, 'Inline').$new(parent, context, text, (function() {if (context['$==']("quoted")) { - - return $hash2(["type"], {"type": "unquoted"}).$merge(opts); - } else { - return opts - }; return nil; })()); - }, $Processor_create_inline$12.$$arity = -4); - - Opal.def(self, '$parse_content', $Processor_parse_content$13 = function $$parse_content(parent, content, attributes) { - var self = this, reader = nil; - - - - if (attributes == null) { - attributes = nil; - }; - reader = (function() {if ($truthy($$($nesting, 'Reader')['$==='](content))) { - return content - } else { - - return $$($nesting, 'Reader').$new(content); - }; return nil; })(); - $$($nesting, 'Parser').$parse_blocks(reader, parent, attributes); - return parent; - }, $Processor_parse_content$13.$$arity = -3); - - Opal.def(self, '$parse_attributes', $Processor_parse_attributes$14 = function $$parse_attributes(block, attrlist, opts) { - var $a, self = this; - - - - if (opts == null) { - opts = $hash2([], {}); - }; - if ($truthy((function() {if ($truthy(attrlist)) { - return attrlist['$empty?']() - } else { - return true - }; return nil; })())) { - return $hash2([], {})}; - if ($truthy(($truthy($a = opts['$[]']("sub_attributes")) ? attrlist['$include?']($$($nesting, 'ATTR_REF_HEAD')) : $a))) { - attrlist = block.$sub_attributes(attrlist)}; - return $$($nesting, 'AttributeList').$new(attrlist).$parse(($truthy($a = opts['$[]']("positional_attributes")) ? $a : [])); - }, $Processor_parse_attributes$14.$$arity = -3); - return $send([["create_paragraph", "create_block", "paragraph"], ["create_open_block", "create_block", "open"], ["create_example_block", "create_block", "example"], ["create_pass_block", "create_block", "pass"], ["create_listing_block", "create_block", "listing"], ["create_literal_block", "create_block", "literal"], ["create_anchor", "create_inline", "anchor"], ["create_inline_pass", "create_inline", "quoted"]], 'each', [], ($Processor$15 = function(method_name, delegate_method_name, context){var self = $Processor$15.$$s || this, $$16; - - - - if (method_name == null) { - method_name = nil; - }; - - if (delegate_method_name == null) { - delegate_method_name = nil; - }; - - if (context == null) { - context = nil; - }; - return $send(self, 'define_method', [method_name], ($$16 = function($a){var self = $$16.$$s || this, $post_args, args; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - args.$unshift(args.$shift(), context); - return $send(self, 'send', [delegate_method_name].concat(Opal.to_a(args)));}, $$16.$$s = self, $$16.$$arity = -1, $$16));}, $Processor$15.$$s = self, $Processor$15.$$arity = 3, $Processor$15)); - })($nesting[0], null, $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'ProcessorDsl'); - - var $nesting = [self].concat($parent_nesting), $ProcessorDsl_option$17, $ProcessorDsl_process$18, $ProcessorDsl_process_block_given$ques$20; - - - - Opal.def(self, '$option', $ProcessorDsl_option$17 = function $$option(key, value) { - var self = this, $writer = nil; - - - $writer = [key, value]; - $send(self.$config(), '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - }, $ProcessorDsl_option$17.$$arity = 2); - - Opal.def(self, '$process', $ProcessorDsl_process$18 = function $$process($a) { - var $iter = $ProcessorDsl_process$18.$$p, block = $iter || nil, $post_args, args, $b, $$19, self = this, context = nil; - if (self.process_block == null) self.process_block = nil; - - if ($iter) $ProcessorDsl_process$18.$$p = null; - - - if ($iter) $ProcessorDsl_process$18.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ((block !== nil)) { - - if ($truthy(args['$empty?']())) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "wrong number of arguments (given " + (args.$size()) + ", expected 0)") - }; - if ($truthy(($truthy($b = block.$binding()) ? self['$=='](block.$binding().$receiver()) : $b))) { - } else { - - context = self; - $send(block, 'define_singleton_method', ["call"], ($$19 = function($c){var self = $$19.$$s || this, $post_args, m_args; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - m_args = $post_args;; - return $send(context, 'instance_exec', Opal.to_a(m_args), block.$to_proc());}, $$19.$$s = self, $$19.$$arity = -1, $$19)); - }; - return (self.process_block = block); - } else if ($truthy((($b = self['process_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) { - return $send(self.process_block, 'call', Opal.to_a(args)) - } else { - return self.$raise($$$('::', 'NotImplementedError'), "" + (self.$class()) + " #" + ("process") + " method called before being registered") - }; - }, $ProcessorDsl_process$18.$$arity = -1); - - Opal.def(self, '$process_block_given?', $ProcessorDsl_process_block_given$ques$20 = function() { - var $a, self = this; - - return (($a = self['process_block'], $a != null && $a !== nil) ? 'instance-variable' : nil) - }, $ProcessorDsl_process_block_given$ques$20.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'DocumentProcessorDsl'); + } + }; + Tokenizer.prototype.shouldContinue = function () { + return this.index < this.buffer.length + this.offset && this.running; + }; + /** + * Iterates through the buffer, calling the function corresponding to the current state. + * + * States that are more likely to be hit are higher up, as a performance improvement. + */ + Tokenizer.prototype.parse = function () { + while (this.shouldContinue()) { + var c = this.buffer.charCodeAt(this.index - this.offset); + switch (this.state) { + case State.Text: { + this.stateText(c); + break; + } + case State.SpecialStartSequence: { + this.stateSpecialStartSequence(c); + break; + } + case State.InSpecialTag: { + this.stateInSpecialTag(c); + break; + } + case State.CDATASequence: { + this.stateCDATASequence(c); + break; + } + case State.InAttributeValueDq: { + this.stateInAttributeValueDoubleQuotes(c); + break; + } + case State.InAttributeName: { + this.stateInAttributeName(c); + break; + } + case State.InCommentLike: { + this.stateInCommentLike(c); + break; + } + case State.InSpecialComment: { + this.stateInSpecialComment(c); + break; + } + case State.BeforeAttributeName: { + this.stateBeforeAttributeName(c); + break; + } + case State.InTagName: { + this.stateInTagName(c); + break; + } + case State.InClosingTagName: { + this.stateInClosingTagName(c); + break; + } + case State.BeforeTagName: { + this.stateBeforeTagName(c); + break; + } + case State.AfterAttributeName: { + this.stateAfterAttributeName(c); + break; + } + case State.InAttributeValueSq: { + this.stateInAttributeValueSingleQuotes(c); + break; + } + case State.BeforeAttributeValue: { + this.stateBeforeAttributeValue(c); + break; + } + case State.BeforeClosingTagName: { + this.stateBeforeClosingTagName(c); + break; + } + case State.AfterClosingTagName: { + this.stateAfterClosingTagName(c); + break; + } + case State.BeforeSpecialS: { + this.stateBeforeSpecialS(c); + break; + } + case State.InAttributeValueNq: { + this.stateInAttributeValueNoQuotes(c); + break; + } + case State.InSelfClosingTag: { + this.stateInSelfClosingTag(c); + break; + } + case State.InDeclaration: { + this.stateInDeclaration(c); + break; + } + case State.BeforeDeclaration: { + this.stateBeforeDeclaration(c); + break; + } + case State.BeforeComment: { + this.stateBeforeComment(c); + break; + } + case State.InProcessingInstruction: { + this.stateInProcessingInstruction(c); + break; + } + case State.InNamedEntity: { + this.stateInNamedEntity(c); + break; + } + case State.BeforeEntity: { + this.stateBeforeEntity(c); + break; + } + case State.InHexEntity: { + this.stateInHexEntity(c); + break; + } + case State.InNumericEntity: { + this.stateInNumericEntity(c); + break; + } + default: { + // `this._state === State.BeforeNumericEntity` + this.stateBeforeNumericEntity(c); + } + } + this.index++; + } + this.cleanup(); + }; + Tokenizer.prototype.finish = function () { + if (this.state === State.InNamedEntity) { + this.emitNamedEntity(); + } + // If there is remaining data, emit it in a reasonable way + if (this.sectionStart < this.index) { + this.handleTrailingData(); + } + this.cbs.onend(); + }; + /** Handle any trailing data. */ + Tokenizer.prototype.handleTrailingData = function () { + var endIndex = this.buffer.length + this.offset; + if (this.state === State.InCommentLike) { + if (this.currentSequence === Sequences.CdataEnd) { + this.cbs.oncdata(this.sectionStart, endIndex, 0); + } + else { + this.cbs.oncomment(this.sectionStart, endIndex, 0); + } + } + else if (this.state === State.InNumericEntity && + this.allowLegacyEntity()) { + this.emitNumericEntity(false); + // All trailing data will have been consumed + } + else if (this.state === State.InHexEntity && + this.allowLegacyEntity()) { + this.emitNumericEntity(false); + // All trailing data will have been consumed + } + else if (this.state === State.InTagName || + this.state === State.BeforeAttributeName || + this.state === State.BeforeAttributeValue || + this.state === State.AfterAttributeName || + this.state === State.InAttributeName || + this.state === State.InAttributeValueSq || + this.state === State.InAttributeValueDq || + this.state === State.InAttributeValueNq || + this.state === State.InClosingTagName) { + /* + * If we are currently in an opening or closing tag, us not calling the + * respective callback signals that the tag should be ignored. + */ + } + else { + this.cbs.ontext(this.sectionStart, endIndex); + } + }; + Tokenizer.prototype.emitPartial = function (start, endIndex) { + if (this.baseState !== State.Text && + this.baseState !== State.InSpecialTag) { + this.cbs.onattribdata(start, endIndex); + } + else { + this.cbs.ontext(start, endIndex); + } + }; + Tokenizer.prototype.emitCodePoint = function (cp) { + if (this.baseState !== State.Text && + this.baseState !== State.InSpecialTag) { + this.cbs.onattribentity(cp); + } + else { + this.cbs.ontextentity(cp); + } + }; + return Tokenizer; +}()); +exports["default"] = Tokenizer; +//# sourceMappingURL=Tokenizer.js.map - var $nesting = [self].concat($parent_nesting), $DocumentProcessorDsl_prefer$21; +/***/ }), - - self.$include($$($nesting, 'ProcessorDsl')); - - Opal.def(self, '$prefer', $DocumentProcessorDsl_prefer$21 = function $$prefer() { - var self = this; +/***/ 5368: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { - return self.$option("position", ">>") - }, $DocumentProcessorDsl_prefer$21.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'SyntaxProcessorDsl'); +"use strict"; - var $nesting = [self].concat($parent_nesting), $SyntaxProcessorDsl_named$22, $SyntaxProcessorDsl_content_model$23, $SyntaxProcessorDsl_positional_attributes$24, $SyntaxProcessorDsl_default_attributes$25, $SyntaxProcessorDsl_resolve_attributes$26; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.DomUtils = exports.parseFeed = exports.getFeed = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DefaultHandler = exports.DomHandler = exports.Parser = void 0; +var Parser_js_1 = __nccwpck_require__(4525); +var Parser_js_2 = __nccwpck_require__(4525); +Object.defineProperty(exports, "Parser", ({ enumerable: true, get: function () { return Parser_js_2.Parser; } })); +var domhandler_1 = __nccwpck_require__(7792); +var domhandler_2 = __nccwpck_require__(7792); +Object.defineProperty(exports, "DomHandler", ({ enumerable: true, get: function () { return domhandler_2.DomHandler; } })); +// Old name for DomHandler +Object.defineProperty(exports, "DefaultHandler", ({ enumerable: true, get: function () { return domhandler_2.DomHandler; } })); +// Helper methods +/** + * Parses the data, returns the resulting document. + * + * @param data The data that should be parsed. + * @param options Optional options for the parser and DOM builder. + */ +function parseDocument(data, options) { + var handler = new domhandler_1.DomHandler(undefined, options); + new Parser_js_1.Parser(handler, options).end(data); + return handler.root; +} +exports.parseDocument = parseDocument; +/** + * Parses data, returns an array of the root nodes. + * + * Note that the root nodes still have a `Document` node as their parent. + * Use `parseDocument` to get the `Document` node instead. + * + * @param data The data that should be parsed. + * @param options Optional options for the parser and DOM builder. + * @deprecated Use `parseDocument` instead. + */ +function parseDOM(data, options) { + return parseDocument(data, options).children; +} +exports.parseDOM = parseDOM; +/** + * Creates a parser instance, with an attached DOM handler. + * + * @param callback A callback that will be called once parsing has been completed. + * @param options Optional options for the parser and DOM builder. + * @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM. + */ +function createDomStream(callback, options, elementCallback) { + var handler = new domhandler_1.DomHandler(callback, options, elementCallback); + return new Parser_js_1.Parser(handler, options); +} +exports.createDomStream = createDomStream; +var Tokenizer_js_1 = __nccwpck_require__(4341); +Object.defineProperty(exports, "Tokenizer", ({ enumerable: true, get: function () { return __importDefault(Tokenizer_js_1).default; } })); +/* + * All of the following exports exist for backwards-compatibility. + * They should probably be removed eventually. + */ +exports.ElementType = __importStar(__nccwpck_require__(1108)); +var domutils_1 = __nccwpck_require__(2357); +var domutils_2 = __nccwpck_require__(2357); +Object.defineProperty(exports, "getFeed", ({ enumerable: true, get: function () { return domutils_2.getFeed; } })); +var parseFeedDefaultOptions = { xmlMode: true }; +/** + * Parse a feed. + * + * @param feed The feed that should be parsed, as a string. + * @param options Optionally, options for parsing. When using this, you should set `xmlMode` to `true`. + */ +function parseFeed(feed, options) { + if (options === void 0) { options = parseFeedDefaultOptions; } + return (0, domutils_1.getFeed)(parseDOM(feed, options)); +} +exports.parseFeed = parseFeed; +exports.DomUtils = __importStar(__nccwpck_require__(2357)); +//# sourceMappingURL=index.js.map - - self.$include($$($nesting, 'ProcessorDsl')); - - Opal.def(self, '$named', $SyntaxProcessorDsl_named$22 = function $$named(value) { - var self = this; +/***/ }), - if ($truthy($$($nesting, 'Processor')['$==='](self))) { - return (self.name = value) - } else { - return self.$option("name", value) - } - }, $SyntaxProcessorDsl_named$22.$$arity = 1); - - Opal.def(self, '$content_model', $SyntaxProcessorDsl_content_model$23 = function $$content_model(value) { - var self = this; +/***/ 3176: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - return self.$option("content_model", value) - }, $SyntaxProcessorDsl_content_model$23.$$arity = 1); - Opal.alias(self, "parse_content_as", "content_model"); - - Opal.def(self, '$positional_attributes', $SyntaxProcessorDsl_positional_attributes$24 = function $$positional_attributes($a) { - var $post_args, value, self = this; +var wrappy = __nccwpck_require__(8264) +var reqs = Object.create(null) +var once = __nccwpck_require__(5560) - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - return self.$option("positional_attrs", value.$flatten()); - }, $SyntaxProcessorDsl_positional_attributes$24.$$arity = -1); - Opal.alias(self, "name_positional_attributes", "positional_attributes"); - Opal.alias(self, "positional_attrs", "positional_attributes"); - - Opal.def(self, '$default_attributes', $SyntaxProcessorDsl_default_attributes$25 = function $$default_attributes(value) { - var self = this; +module.exports = wrappy(inflight) - return self.$option("default_attrs", value) - }, $SyntaxProcessorDsl_default_attributes$25.$$arity = 1); - Opal.alias(self, "default_attrs", "default_attributes"); - - Opal.def(self, '$resolve_attributes', $SyntaxProcessorDsl_resolve_attributes$26 = function $$resolve_attributes($a) { - var $post_args, args, $b, $$27, $$28, self = this, $case = nil, names = nil, defaults = nil; +function inflight (key, cb) { + if (reqs[key]) { + reqs[key].push(cb) + return null + } else { + reqs[key] = [cb] + return makeres(key) + } +} - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy($rb_gt(args.$size(), 1))) { - } else if ($truthy((args = args.$fetch(0, true))['$respond_to?']("to_sym"))) { - args = [args]}; - return (function() {$case = args; - if (true['$===']($case)) { - self.$option("positional_attrs", []); - return self.$option("default_attrs", $hash2([], {}));} - else if ($$$('::', 'Array')['$===']($case)) { - $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]), $b; - $send(args, 'each', [], ($$27 = function(arg){var self = $$27.$$s || this, $c, $d, name = nil, _ = nil, value = nil, idx = nil, $writer = nil; +function makeres (key) { + return once(function RES () { + var cbs = reqs[key] + var len = cbs.length + var args = slice(arguments) - - - if (arg == null) { - arg = nil; - }; - if ($truthy((arg = arg.$to_s())['$include?']("="))) { - - $d = arg.$partition("="), $c = Opal.to_ary($d), (name = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (value = ($c[2] == null ? nil : $c[2])), $d; - if ($truthy(name['$include?'](":"))) { - - $d = name.$partition(":"), $c = Opal.to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d; - idx = (function() {if (idx['$==']("@")) { - return names.$size() - } else { - return idx.$to_i() - }; return nil; })(); - - $writer = [idx, name]; - $send(names, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];;}; - - $writer = [name, value]; - $send(defaults, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else if ($truthy(arg['$include?'](":"))) { - - $d = arg.$partition(":"), $c = Opal.to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d; - idx = (function() {if (idx['$==']("@")) { - return names.$size() - } else { - return idx.$to_i() - }; return nil; })(); - - $writer = [idx, name]; - $send(names, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else { - return names['$<<'](arg) - };}, $$27.$$s = self, $$27.$$arity = 1, $$27)); - self.$option("positional_attrs", names.$compact()); - return self.$option("default_attrs", defaults);} - else if ($$$('::', 'Hash')['$===']($case)) { - $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]), $b; - $send(args, 'each', [], ($$28 = function(key, val){var self = $$28.$$s || this, $c, $d, name = nil, idx = nil, _ = nil, $writer = nil; + // XXX It's somewhat ambiguous whether a new callback added in this + // pass should be queued for later execution if something in the + // list of callbacks throws, or if it should just be discarded. + // However, it's such an edge case that it hardly matters, and either + // choice is likely as surprising as the other. + // As it happens, we do go ahead and schedule it for later execution. + try { + for (var i = 0; i < len; i++) { + cbs[i].apply(null, args) + } + } finally { + if (cbs.length > len) { + // added more in the interim. + // de-zalgo, just in case, but don't call again. + cbs.splice(0, len) + process.nextTick(function () { + RES.apply(null, args) + }) + } else { + delete reqs[key] + } + } + }) +} - - - if (key == null) { - key = nil; - }; - - if (val == null) { - val = nil; - }; - if ($truthy((name = key.$to_s())['$include?'](":"))) { - - $d = name.$partition(":"), $c = Opal.to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d; - idx = (function() {if (idx['$==']("@")) { - return names.$size() - } else { - return idx.$to_i() - }; return nil; })(); - - $writer = [idx, name]; - $send(names, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];;}; - if ($truthy(val)) { - - $writer = [name, val]; - $send(defaults, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - } else { - return nil - };}, $$28.$$s = self, $$28.$$arity = 2, $$28)); - self.$option("positional_attrs", names.$compact()); - return self.$option("default_attrs", defaults);} - else {return self.$raise($$$('::', 'ArgumentError'), "" + "unsupported attributes specification for macro: " + (args.$inspect()))}})(); - }, $SyntaxProcessorDsl_resolve_attributes$26.$$arity = -1); - Opal.alias(self, "resolves_attributes", "resolve_attributes"); - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Preprocessor'); +function slice (args) { + var length = args.length + var array = [] - var $nesting = [self].concat($parent_nesting), $Preprocessor_process$29; + for (var i = 0; i < length; i++) array[i] = args[i] + return array +} - return (Opal.def(self, '$process', $Preprocessor_process$29 = function $$process(document, reader) { - var self = this; - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'Preprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $Preprocessor_process$29.$$arity = 2), nil) && 'process' - })($nesting[0], $$($nesting, 'Processor'), $nesting); - Opal.const_set($$($nesting, 'Preprocessor'), 'DSL', $$($nesting, 'DocumentProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'TreeProcessor'); +/***/ }), - var $nesting = [self].concat($parent_nesting), $TreeProcessor_process$30; +/***/ 9598: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - return (Opal.def(self, '$process', $TreeProcessor_process$30 = function $$process(document) { - var self = this; +try { + var util = __nccwpck_require__(9023); + /* istanbul ignore next */ + if (typeof util.inherits !== 'function') throw ''; + module.exports = util.inherits; +} catch (e) { + /* istanbul ignore next */ + module.exports = __nccwpck_require__(6589); +} - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'TreeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $TreeProcessor_process$30.$$arity = 1), nil) && 'process' - })($nesting[0], $$($nesting, 'Processor'), $nesting); - Opal.const_set($$($nesting, 'TreeProcessor'), 'DSL', $$($nesting, 'DocumentProcessorDsl')); - Opal.const_set($nesting[0], 'Treeprocessor', $$($nesting, 'TreeProcessor')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Postprocessor'); - var $nesting = [self].concat($parent_nesting), $Postprocessor_process$31; +/***/ }), - return (Opal.def(self, '$process', $Postprocessor_process$31 = function $$process(document, output) { - var self = this; +/***/ 6589: +/***/ ((module) => { - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'Postprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $Postprocessor_process$31.$$arity = 2), nil) && 'process' - })($nesting[0], $$($nesting, 'Processor'), $nesting); - Opal.const_set($$($nesting, 'Postprocessor'), 'DSL', $$($nesting, 'DocumentProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IncludeProcessor'); +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }) + } + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } + } +} - var $nesting = [self].concat($parent_nesting), $IncludeProcessor_process$32, $IncludeProcessor_handles$ques$33; - - - Opal.def(self, '$process', $IncludeProcessor_process$32 = function $$process(document, reader, target, attributes) { - var self = this; +/***/ }), - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'IncludeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $IncludeProcessor_process$32.$$arity = 4); - return (Opal.def(self, '$handles?', $IncludeProcessor_handles$ques$33 = function(target) { - var self = this; +/***/ 7489: +/***/ ((module) => { - return true - }, $IncludeProcessor_handles$ques$33.$$arity = 1), nil) && 'handles?'; - })($nesting[0], $$($nesting, 'Processor'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'IncludeProcessorDsl'); +const isWindows = typeof process === 'object' && + process && + process.platform === 'win32' +module.exports = isWindows ? { sep: '\\' } : { sep: '/' } - var $nesting = [self].concat($parent_nesting), $IncludeProcessorDsl_handles$ques$34; - - self.$include($$($nesting, 'DocumentProcessorDsl')); - - Opal.def(self, '$handles?', $IncludeProcessorDsl_handles$ques$34 = function($a) { - var $iter = $IncludeProcessorDsl_handles$ques$34.$$p, block = $iter || nil, $post_args, args, $b, self = this; - if (self.handles_block == null) self.handles_block = nil; +/***/ }), - if ($iter) $IncludeProcessorDsl_handles$ques$34.$$p = null; - - - if ($iter) $IncludeProcessorDsl_handles$ques$34.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ((block !== nil)) { - - if ($truthy(args['$empty?']())) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "wrong number of arguments (given " + (args.$size()) + ", expected 0)") - }; - return (self.handles_block = block); - } else if ($truthy((($b = self['handles_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) { - return self.handles_block.$call(args['$[]'](0)) - } else { - return true - }; - }, $IncludeProcessorDsl_handles$ques$34.$$arity = -1); - })($nesting[0], $nesting); - Opal.const_set($$($nesting, 'IncludeProcessor'), 'DSL', $$($nesting, 'IncludeProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'DocinfoProcessor'); +/***/ 3772: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - var $nesting = [self].concat($parent_nesting), $DocinfoProcessor_initialize$35, $DocinfoProcessor_process$36; +const minimatch = module.exports = (p, pattern, options = {}) => { + assertValidPattern(pattern) - self.$$prototype.config = nil; - - - Opal.def(self, '$initialize', $DocinfoProcessor_initialize$35 = function $$initialize(config) { - var $a, $iter = $DocinfoProcessor_initialize$35.$$p, $yield = $iter || nil, self = this, $writer = nil; + // shortcut: comments match nothing. + if (!options.nocomment && pattern.charAt(0) === '#') { + return false + } - if ($iter) $DocinfoProcessor_initialize$35.$$p = null; - - - if (config == null) { - config = $hash2([], {}); - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $DocinfoProcessor_initialize$35, false), [config], null); - return ($truthy($a = self.config['$[]']("location")) ? $a : (($writer = ["location", "head"]), $send(self.config, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - }, $DocinfoProcessor_initialize$35.$$arity = -1); - return (Opal.def(self, '$process', $DocinfoProcessor_process$36 = function $$process(document) { - var self = this; + return new Minimatch(pattern, options).match(p) +} - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'DocinfoProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $DocinfoProcessor_process$36.$$arity = 1), nil) && 'process'; - })($nesting[0], $$($nesting, 'Processor'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'DocinfoProcessorDsl'); +module.exports = minimatch - var $nesting = [self].concat($parent_nesting), $DocinfoProcessorDsl_at_location$37; +const path = __nccwpck_require__(7489) +minimatch.sep = path.sep - - self.$include($$($nesting, 'DocumentProcessorDsl')); - - Opal.def(self, '$at_location', $DocinfoProcessorDsl_at_location$37 = function $$at_location(value) { - var self = this; +const GLOBSTAR = Symbol('globstar **') +minimatch.GLOBSTAR = GLOBSTAR +const expand = __nccwpck_require__(4691) - return self.$option("location", value) - }, $DocinfoProcessorDsl_at_location$37.$$arity = 1); - })($nesting[0], $nesting); - Opal.const_set($$($nesting, 'DocinfoProcessor'), 'DSL', $$($nesting, 'DocinfoProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'BlockProcessor'); +const plTypes = { + '!': { open: '(?:(?!(?:', close: '))[^/]*?)'}, + '?': { open: '(?:', close: ')?' }, + '+': { open: '(?:', close: ')+' }, + '*': { open: '(?:', close: ')*' }, + '@': { open: '(?:', close: ')' } +} - var $nesting = [self].concat($parent_nesting), $BlockProcessor_initialize$38, $BlockProcessor_process$39; +// any single thing other than / +// don't need to escape / when using new RegExp() +const qmark = '[^/]' - self.$$prototype.config = nil; - - self.$attr_accessor("name"); - - Opal.def(self, '$initialize', $BlockProcessor_initialize$38 = function $$initialize(name, config) { - var $a, $iter = $BlockProcessor_initialize$38.$$p, $yield = $iter || nil, self = this, $case = nil, $writer = nil; +// * => any number of characters +const star = qmark + '*?' - if ($iter) $BlockProcessor_initialize$38.$$p = null; - - - if (name == null) { - name = nil; - }; - - if (config == null) { - config = $hash2([], {}); - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $BlockProcessor_initialize$38, false), [config], null); - self.name = ($truthy($a = name) ? $a : self.config['$[]']("name")); - $case = self.config['$[]']("contexts"); - if ($$$('::', 'NilClass')['$===']($case)) {($truthy($a = self.config['$[]']("contexts")) ? $a : (($writer = ["contexts", ["open", "paragraph"].$to_set()]), $send(self.config, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)]))} - else if ($$$('::', 'Symbol')['$===']($case)) { - $writer = ["contexts", [self.config['$[]']("contexts")].$to_set()]; - $send(self.config, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];} - else { - $writer = ["contexts", self.config['$[]']("contexts").$to_set()]; - $send(self.config, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];}; - return ($truthy($a = self.config['$[]']("content_model")) ? $a : (($writer = ["content_model", "compound"]), $send(self.config, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - }, $BlockProcessor_initialize$38.$$arity = -1); - return (Opal.def(self, '$process', $BlockProcessor_process$39 = function $$process(parent, reader, attributes) { - var self = this; +// ** when dots are allowed. Anything goes, except .. and . +// not (^ or / followed by one or two dots followed by $ or /), +// followed by anything, any number of times. +const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?' - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'BlockProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $BlockProcessor_process$39.$$arity = 3), nil) && 'process'; - })($nesting[0], $$($nesting, 'Processor'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'BlockProcessorDsl'); +// not a ^ or / followed by a dot, +// followed by anything, any number of times. +const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?' - var $nesting = [self].concat($parent_nesting), $BlockProcessorDsl_contexts$40; +// "abc" -> { a:true, b:true, c:true } +const charSet = s => s.split('').reduce((set, c) => { + set[c] = true + return set +}, {}) - - self.$include($$($nesting, 'SyntaxProcessorDsl')); - - Opal.def(self, '$contexts', $BlockProcessorDsl_contexts$40 = function $$contexts($a) { - var $post_args, value, self = this; +// characters that need to be escaped in RegExp. +const reSpecials = charSet('().*{}+?[]^$\\!') - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - return self.$option("contexts", value.$flatten().$to_set()); - }, $BlockProcessorDsl_contexts$40.$$arity = -1); - Opal.alias(self, "on_contexts", "contexts"); - Opal.alias(self, "on_context", "contexts"); - Opal.alias(self, "bind_to", "contexts"); - })($nesting[0], $nesting); - Opal.const_set($$($nesting, 'BlockProcessor'), 'DSL', $$($nesting, 'BlockProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'MacroProcessor'); +// characters that indicate we have to add the pattern start +const addPatternStartSet = charSet('[.(') - var $nesting = [self].concat($parent_nesting), $MacroProcessor_initialize$41, $MacroProcessor_process$42; +// normalizes slashes. +const slashSplit = /\/+/ - self.$$prototype.config = nil; - - self.$attr_accessor("name"); - - Opal.def(self, '$initialize', $MacroProcessor_initialize$41 = function $$initialize(name, config) { - var $a, $iter = $MacroProcessor_initialize$41.$$p, $yield = $iter || nil, self = this, $writer = nil; +minimatch.filter = (pattern, options = {}) => + (p, i, list) => minimatch(p, pattern, options) - if ($iter) $MacroProcessor_initialize$41.$$p = null; - - - if (name == null) { - name = nil; - }; - - if (config == null) { - config = $hash2([], {}); - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $MacroProcessor_initialize$41, false), [config], null); - self.name = ($truthy($a = name) ? $a : self.config['$[]']("name")); - return ($truthy($a = self.config['$[]']("content_model")) ? $a : (($writer = ["content_model", "attributes"]), $send(self.config, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - }, $MacroProcessor_initialize$41.$$arity = -1); - return (Opal.def(self, '$process', $MacroProcessor_process$42 = function $$process(parent, target, attributes) { - var self = this; +const ext = (a, b = {}) => { + const t = {} + Object.keys(a).forEach(k => t[k] = a[k]) + Object.keys(b).forEach(k => t[k] = b[k]) + return t +} - return self.$raise($$$('::', 'NotImplementedError'), "" + ($$($nesting, 'MacroProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") - }, $MacroProcessor_process$42.$$arity = 3), nil) && 'process'; - })($nesting[0], $$($nesting, 'Processor'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'MacroProcessorDsl'); +minimatch.defaults = def => { + if (!def || typeof def !== 'object' || !Object.keys(def).length) { + return minimatch + } - var $nesting = [self].concat($parent_nesting), $MacroProcessorDsl_resolve_attributes$43; + const orig = minimatch - - self.$include($$($nesting, 'SyntaxProcessorDsl')); - - Opal.def(self, '$resolve_attributes', $MacroProcessorDsl_resolve_attributes$43 = function $$resolve_attributes($a) { - var $post_args, args, $b, $iter = $MacroProcessorDsl_resolve_attributes$43.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + const m = (p, pattern, options) => orig(p, pattern, ext(def, options)) + m.Minimatch = class Minimatch extends orig.Minimatch { + constructor (pattern, options) { + super(pattern, ext(def, options)) + } + } + m.Minimatch.defaults = options => orig.defaults(ext(def, options)).Minimatch + m.filter = (pattern, options) => orig.filter(pattern, ext(def, options)) + m.defaults = options => orig.defaults(ext(def, options)) + m.makeRe = (pattern, options) => orig.makeRe(pattern, ext(def, options)) + m.braceExpand = (pattern, options) => orig.braceExpand(pattern, ext(def, options)) + m.match = (list, pattern, options) => orig.match(list, pattern, ext(def, options)) - if ($iter) $MacroProcessorDsl_resolve_attributes$43.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy((($b = args.$size()['$=='](1)) ? args['$[]'](0)['$!']() : args.$size()['$=='](1)))) { - return self.$option("content_model", "text") - } else { - - $send(self, Opal.find_super_dispatcher(self, 'resolve_attributes', $MacroProcessorDsl_resolve_attributes$43, false), $zuper, $iter); - return self.$option("content_model", "attributes"); - }; - }, $MacroProcessorDsl_resolve_attributes$43.$$arity = -1); - Opal.alias(self, "resolves_attributes", "resolve_attributes"); - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'BlockMacroProcessor'); + return m +} - var $nesting = [self].concat($parent_nesting), $BlockMacroProcessor_name$44; - self.$$prototype.name = nil; - return (Opal.def(self, '$name', $BlockMacroProcessor_name$44 = function $$name() { - var self = this; - - if ($truthy($$($nesting, 'MacroNameRx')['$match?'](self.name.$to_s()))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "invalid name for block macro: " + (self.name)) - }; - return self.name; - }, $BlockMacroProcessor_name$44.$$arity = 0), nil) && 'name' - })($nesting[0], $$($nesting, 'MacroProcessor'), $nesting); - Opal.const_set($$($nesting, 'BlockMacroProcessor'), 'DSL', $$($nesting, 'MacroProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'InlineMacroProcessor'); - var $nesting = [self].concat($parent_nesting), $InlineMacroProcessor_regexp$45, $InlineMacroProcessor_resolve_regexp$46; - self.$$prototype.config = self.$$prototype.name = nil; - - (Opal.class_variable_set($nesting[0], '@@rx_cache', $hash2([], {}))); - - Opal.def(self, '$regexp', $InlineMacroProcessor_regexp$45 = function $$regexp() { - var $a, self = this, $writer = nil; +// Brace expansion: +// a{b,c}d -> abd acd +// a{b,}c -> abc ac +// a{0..3}d -> a0d a1d a2d a3d +// a{b,c{d,e}f}g -> abg acdfg acefg +// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg +// +// Invalid sets are not expanded. +// a{2..}b -> a{2..}b +// a{b}c -> a{b}c +minimatch.braceExpand = (pattern, options) => braceExpand(pattern, options) - return ($truthy($a = self.config['$[]']("regexp")) ? $a : (($writer = ["regexp", self.$resolve_regexp(self.name.$to_s(), self.config['$[]']("format"))]), $send(self.config, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])) - }, $InlineMacroProcessor_regexp$45.$$arity = 0); - return (Opal.def(self, '$resolve_regexp', $InlineMacroProcessor_resolve_regexp$46 = function $$resolve_regexp(name, format) { - var $a, $b, self = this, $writer = nil; +const braceExpand = (pattern, options = {}) => { + assertValidPattern(pattern) - - if ($truthy($$($nesting, 'MacroNameRx')['$match?'](name))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "invalid name for inline macro: " + (name)) - }; - return ($truthy($a = (($b = $nesting[0].$$cvars['@@rx_cache']) == null ? nil : $b)['$[]']([name, format])) ? $a : (($writer = [[name, format], new RegExp("" + "\\\\?" + (name) + ":" + ((function() {if (format['$==']("short")) { - return "(){0}" - } else { - return "(\\S+?)" - }; return nil; })()) + "\\[(|" + ($$($nesting, 'CC_ANY')) + "*?[^\\\\])\\]")]), $send((($b = $nesting[0].$$cvars['@@rx_cache']) == null ? nil : $b), '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - }, $InlineMacroProcessor_resolve_regexp$46.$$arity = 2), nil) && 'resolve_regexp'; - })($nesting[0], $$($nesting, 'MacroProcessor'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'InlineMacroProcessorDsl'); + // Thanks to Yeting Li <https://github.com/yetingli> for + // improving this regexp to avoid a ReDOS vulnerability. + if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { + // shortcut. no need to expand. + return [pattern] + } - var $nesting = [self].concat($parent_nesting), $InlineMacroProcessorDsl_format$47, $InlineMacroProcessorDsl_match$48; + return expand(pattern) +} - - self.$include($$($nesting, 'MacroProcessorDsl')); - - Opal.def(self, '$format', $InlineMacroProcessorDsl_format$47 = function $$format(value) { - var self = this; +const MAX_PATTERN_LENGTH = 1024 * 64 +const assertValidPattern = pattern => { + if (typeof pattern !== 'string') { + throw new TypeError('invalid pattern') + } - return self.$option("format", value) - }, $InlineMacroProcessorDsl_format$47.$$arity = 1); - Opal.alias(self, "match_format", "format"); - Opal.alias(self, "using_format", "format"); - - Opal.def(self, '$match', $InlineMacroProcessorDsl_match$48 = function $$match(value) { - var self = this; + if (pattern.length > MAX_PATTERN_LENGTH) { + throw new TypeError('pattern is too long') + } +} - return self.$option("regexp", value) - }, $InlineMacroProcessorDsl_match$48.$$arity = 1); - })($nesting[0], $nesting); - Opal.const_set($$($nesting, 'InlineMacroProcessor'), 'DSL', $$($nesting, 'InlineMacroProcessorDsl')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Extension'); +// parse a component of the expanded set. +// At this point, no pattern may contain "/" in it +// so we're going to return a 2d array, where each entry is the full +// pattern, split on '/', and then turned into a regular expression. +// A regexp is made at the end which joins each array with an +// escaped /, and another full one which joins each regexp with |. +// +// Following the lead of Bash 4.1, note that "**" only has special meaning +// when it is the *only* thing in a path portion. Otherwise, any series +// of * is equivalent to a single *. Globstar behavior is enabled by +// default, and can be disabled by setting options.noglobstar. +const SUBPARSE = Symbol('subparse') - var $nesting = [self].concat($parent_nesting), $Extension_initialize$49; +minimatch.makeRe = (pattern, options) => + new Minimatch(pattern, options || {}).makeRe() - - self.$attr_reader("kind"); - self.$attr_reader("config"); - self.$attr_reader("instance"); - return (Opal.def(self, '$initialize', $Extension_initialize$49 = function $$initialize(kind, instance, config) { - var self = this; +minimatch.match = (list, pattern, options = {}) => { + const mm = new Minimatch(pattern, options) + list = list.filter(f => mm.match(f)) + if (mm.options.nonull && !list.length) { + list.push(pattern) + } + return list +} - - self.kind = kind; - self.instance = instance; - return (self.config = config); - }, $Extension_initialize$49.$$arity = 3), nil) && 'initialize'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'ProcessorExtension'); +// replace stuff like \* with * +const globUnescape = s => s.replace(/\\(.)/g, '$1') +const charUnescape = s => s.replace(/\\([^-\]])/g, '$1') +const regExpEscape = s => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') +const braExpEscape = s => s.replace(/[[\]\\]/g, '\\$&') + +class Minimatch { + constructor (pattern, options) { + assertValidPattern(pattern) + + if (!options) options = {} + + this.options = options + this.maxGlobstarRecursion = options.maxGlobstarRecursion !== undefined + ? options.maxGlobstarRecursion : 200 + this.set = [] + this.pattern = pattern + this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || + options.allowWindowsEscape === false + if (this.windowsPathsNoEscape) { + this.pattern = this.pattern.replace(/\\/g, '/') + } + this.regexp = null + this.negate = false + this.comment = false + this.empty = false + this.partial = !!options.partial + + // make the set of regexps etc. + this.make() + } + + debug () {} + + make () { + const pattern = this.pattern + const options = this.options + + // empty patterns and comments match nothing. + if (!options.nocomment && pattern.charAt(0) === '#') { + this.comment = true + return + } + if (!pattern) { + this.empty = true + return + } - var $nesting = [self].concat($parent_nesting), $ProcessorExtension_initialize$50; + // step 1: figure out negation, etc. + this.parseNegate() - - self.$attr_reader("process_method"); - return (Opal.def(self, '$initialize', $ProcessorExtension_initialize$50 = function $$initialize(kind, instance, process_method) { - var $a, $iter = $ProcessorExtension_initialize$50.$$p, $yield = $iter || nil, self = this; + // step 2: expand braces + let set = this.globSet = this.braceExpand() - if ($iter) $ProcessorExtension_initialize$50.$$p = null; - - - if (process_method == null) { - process_method = nil; - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $ProcessorExtension_initialize$50, false), [kind, instance, instance.$config()], null); - return (self.process_method = ($truthy($a = process_method) ? $a : instance.$method("process"))); - }, $ProcessorExtension_initialize$50.$$arity = -3), nil) && 'initialize'; - })($nesting[0], $$($nesting, 'Extension'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Group'); + if (options.debug) this.debug = (...args) => console.error(...args) - var $nesting = [self].concat($parent_nesting), $Group_activate$52; + this.debug(this.pattern, set) - - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $register$51; + // step 3: now we have a set, so turn each one into a series of path-portion + // matching patterns. + // These will be regexps, except in the case of "**", which is + // set to the GLOBSTAR object for globstar behavior, + // and will not contain any / characters + set = this.globParts = set.map(s => s.split(slashSplit)) - return (Opal.def(self, '$register', $register$51 = function $$register(name) { - var self = this; + this.debug(this.pattern, set) - - - if (name == null) { - name = nil; - }; - return $$($nesting, 'Extensions').$register(name, self); - }, $register$51.$$arity = -1), nil) && 'register' - })(Opal.get_singleton_class(self), $nesting); - return (Opal.def(self, '$activate', $Group_activate$52 = function $$activate(registry) { - var self = this; + // glob --> regexps + set = set.map((s, si, set) => s.map(this.parse, this)) - return self.$raise($$$('::', 'NotImplementedError')) - }, $Group_activate$52.$$arity = 1), nil) && 'activate'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Registry'); + this.debug(this.pattern, set) - var $nesting = [self].concat($parent_nesting), $Registry_initialize$53, $Registry_activate$54, $Registry_preprocessor$56, $Registry_preprocessors$ques$57, $Registry_preprocessors$58, $Registry_tree_processor$59, $Registry_tree_processors$ques$60, $Registry_tree_processors$61, $Registry_postprocessor$62, $Registry_postprocessors$ques$63, $Registry_postprocessors$64, $Registry_include_processor$65, $Registry_include_processors$ques$66, $Registry_include_processors$67, $Registry_docinfo_processor$68, $Registry_docinfo_processors$ques$69, $Registry_docinfo_processors$71, $Registry_block$73, $Registry_blocks$ques$74, $Registry_registered_for_block$ques$75, $Registry_find_block_extension$76, $Registry_block_macro$77, $Registry_block_macros$ques$78, $Registry_registered_for_block_macro$ques$79, $Registry_find_block_macro_extension$80, $Registry_inline_macro$81, $Registry_inline_macros$ques$82, $Registry_registered_for_inline_macro$ques$83, $Registry_find_inline_macro_extension$84, $Registry_inline_macros$85, $Registry_prefer$86, $Registry_add_document_processor$87, $Registry_add_syntax_processor$89, $Registry_resolve_args$91, $Registry_as_symbol$92; + // filter out everything that didn't compile properly. + set = set.filter(s => s.indexOf(false) === -1) - self.$$prototype.groups = self.$$prototype.preprocessor_extensions = self.$$prototype.tree_processor_extensions = self.$$prototype.postprocessor_extensions = self.$$prototype.include_processor_extensions = self.$$prototype.docinfo_processor_extensions = self.$$prototype.block_extensions = self.$$prototype.block_macro_extensions = self.$$prototype.inline_macro_extensions = nil; - - self.$attr_reader("document"); - self.$attr_reader("groups"); - - Opal.def(self, '$initialize', $Registry_initialize$53 = function $$initialize(groups) { - var self = this; + this.debug(this.pattern, set) - - - if (groups == null) { - groups = $hash2([], {}); - }; - self.groups = groups; - self.preprocessor_extensions = (self.tree_processor_extensions = (self.postprocessor_extensions = (self.include_processor_extensions = (self.docinfo_processor_extensions = (self.block_extensions = (self.block_macro_extensions = (self.inline_macro_extensions = nil))))))); - return (self.document = nil); - }, $Registry_initialize$53.$$arity = -1); - - Opal.def(self, '$activate', $Registry_activate$54 = function $$activate(document) { - var $$55, self = this, ext_groups = nil; + this.set = set + } - - self.document = document; - if ($truthy((ext_groups = $rb_plus($$($nesting, 'Extensions').$groups().$values(), self.groups.$values()))['$empty?']())) { - } else { - $send(ext_groups, 'each', [], ($$55 = function(group){var self = $$55.$$s || this, $case = nil; + parseNegate () { + if (this.options.nonegate) return - - - if (group == null) { - group = nil; - }; - return (function() {$case = group; - if ($$$('::', 'Proc')['$===']($case)) {return (function() {$case = group.$arity(); - if ((0)['$===']($case) || (-1)['$===']($case)) {return $send(self, 'instance_exec', [], group.$to_proc())} - else if ((1)['$===']($case)) {return group.$call(self)} - else { return nil }})()} - else if ($$$('::', 'Class')['$===']($case)) {return group.$new().$activate(self)} - else {return group.$activate(self)}})();}, $$55.$$s = self, $$55.$$arity = 1, $$55)) - }; - return self; - }, $Registry_activate$54.$$arity = 1); - - Opal.def(self, '$preprocessor', $Registry_preprocessor$56 = function $$preprocessor($a) { - var $iter = $Registry_preprocessor$56.$$p, block = $iter || nil, $post_args, args, self = this; + const pattern = this.pattern + let negate = false + let negateOffset = 0 - if ($iter) $Registry_preprocessor$56.$$p = null; - - - if ($iter) $Registry_preprocessor$56.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_document_processor', ["preprocessor", args], block.$to_proc()); - }, $Registry_preprocessor$56.$$arity = -1); - - Opal.def(self, '$preprocessors?', $Registry_preprocessors$ques$57 = function() { - var self = this; + for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) { + negate = !negate + negateOffset++ + } - return self.preprocessor_extensions['$!']()['$!']() - }, $Registry_preprocessors$ques$57.$$arity = 0); - - Opal.def(self, '$preprocessors', $Registry_preprocessors$58 = function $$preprocessors() { - var self = this; + if (negateOffset) this.pattern = pattern.slice(negateOffset) + this.negate = negate + } - return self.preprocessor_extensions - }, $Registry_preprocessors$58.$$arity = 0); - - Opal.def(self, '$tree_processor', $Registry_tree_processor$59 = function $$tree_processor($a) { - var $iter = $Registry_tree_processor$59.$$p, block = $iter || nil, $post_args, args, self = this; + // set partial to true to test if, for example, + // "/a/b" matches the start of "/*/b/*/d" + // Partial means, if you run out of file before you run + // out of pattern, then that's fine, as long as all + // the parts match. + matchOne (file, pattern, partial) { + if (pattern.indexOf(GLOBSTAR) !== -1) { + return this._matchGlobstar(file, pattern, partial, 0, 0) + } + return this._matchOne(file, pattern, partial, 0, 0) + } - if ($iter) $Registry_tree_processor$59.$$p = null; - - - if ($iter) $Registry_tree_processor$59.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_document_processor', ["tree_processor", args], block.$to_proc()); - }, $Registry_tree_processor$59.$$arity = -1); - - Opal.def(self, '$tree_processors?', $Registry_tree_processors$ques$60 = function() { - var self = this; + _matchGlobstar (file, pattern, partial, fileIndex, patternIndex) { + // find first globstar from patternIndex + let firstgs = -1 + for (let i = patternIndex; i < pattern.length; i++) { + if (pattern[i] === GLOBSTAR) { firstgs = i; break } + } - return self.tree_processor_extensions['$!']()['$!']() - }, $Registry_tree_processors$ques$60.$$arity = 0); - - Opal.def(self, '$tree_processors', $Registry_tree_processors$61 = function $$tree_processors() { - var self = this; + // find last globstar + let lastgs = -1 + for (let i = pattern.length - 1; i >= 0; i--) { + if (pattern[i] === GLOBSTAR) { lastgs = i; break } + } - return self.tree_processor_extensions - }, $Registry_tree_processors$61.$$arity = 0); - Opal.alias(self, "treeprocessor", "tree_processor"); - Opal.alias(self, "treeprocessors?", "tree_processors?"); - Opal.alias(self, "treeprocessors", "tree_processors"); - - Opal.def(self, '$postprocessor', $Registry_postprocessor$62 = function $$postprocessor($a) { - var $iter = $Registry_postprocessor$62.$$p, block = $iter || nil, $post_args, args, self = this; + const head = pattern.slice(patternIndex, firstgs) + const body = partial ? pattern.slice(firstgs + 1) : pattern.slice(firstgs + 1, lastgs) + const tail = partial ? [] : pattern.slice(lastgs + 1) - if ($iter) $Registry_postprocessor$62.$$p = null; - - - if ($iter) $Registry_postprocessor$62.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_document_processor', ["postprocessor", args], block.$to_proc()); - }, $Registry_postprocessor$62.$$arity = -1); - - Opal.def(self, '$postprocessors?', $Registry_postprocessors$ques$63 = function() { - var self = this; + // check the head + if (head.length) { + const fileHead = file.slice(fileIndex, fileIndex + head.length) + if (!this._matchOne(fileHead, head, partial, 0, 0)) { + return false + } + fileIndex += head.length + } - return self.postprocessor_extensions['$!']()['$!']() - }, $Registry_postprocessors$ques$63.$$arity = 0); - - Opal.def(self, '$postprocessors', $Registry_postprocessors$64 = function $$postprocessors() { - var self = this; + // check the tail + let fileTailMatch = 0 + if (tail.length) { + if (tail.length + fileIndex > file.length) return false - return self.postprocessor_extensions - }, $Registry_postprocessors$64.$$arity = 0); - - Opal.def(self, '$include_processor', $Registry_include_processor$65 = function $$include_processor($a) { - var $iter = $Registry_include_processor$65.$$p, block = $iter || nil, $post_args, args, self = this; + const tailStart = file.length - tail.length + if (this._matchOne(file, tail, partial, tailStart, 0)) { + fileTailMatch = tail.length + } else { + // affordance for stuff like a/**/* matching a/b/ + if (file[file.length - 1] !== '' || + fileIndex + tail.length === file.length) { + return false + } + if (!this._matchOne(file, tail, partial, tailStart - 1, 0)) { + return false + } + fileTailMatch = tail.length + 1 + } + } - if ($iter) $Registry_include_processor$65.$$p = null; - - - if ($iter) $Registry_include_processor$65.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_document_processor', ["include_processor", args], block.$to_proc()); - }, $Registry_include_processor$65.$$arity = -1); - - Opal.def(self, '$include_processors?', $Registry_include_processors$ques$66 = function() { - var self = this; + // if body is empty (single ** between head and tail) + if (!body.length) { + let sawSome = !!fileTailMatch + for (let i = fileIndex; i < file.length - fileTailMatch; i++) { + const f = String(file[i]) + sawSome = true + if (f === '.' || f === '..' || + (!this.options.dot && f.charAt(0) === '.')) { + return false + } + } + return partial || sawSome + } - return self.include_processor_extensions['$!']()['$!']() - }, $Registry_include_processors$ques$66.$$arity = 0); - - Opal.def(self, '$include_processors', $Registry_include_processors$67 = function $$include_processors() { - var self = this; + // split body into segments at each GLOBSTAR + const bodySegments = [[[], 0]] + let currentBody = bodySegments[0] + let nonGsParts = 0 + const nonGsPartsSums = [0] + for (const b of body) { + if (b === GLOBSTAR) { + nonGsPartsSums.push(nonGsParts) + currentBody = [[], 0] + bodySegments.push(currentBody) + } else { + currentBody[0].push(b) + nonGsParts++ + } + } - return self.include_processor_extensions - }, $Registry_include_processors$67.$$arity = 0); - - Opal.def(self, '$docinfo_processor', $Registry_docinfo_processor$68 = function $$docinfo_processor($a) { - var $iter = $Registry_docinfo_processor$68.$$p, block = $iter || nil, $post_args, args, self = this; + let idx = bodySegments.length - 1 + const fileLength = file.length - fileTailMatch + for (const b of bodySegments) { + b[1] = fileLength - (nonGsPartsSums[idx--] + b[0].length) + } - if ($iter) $Registry_docinfo_processor$68.$$p = null; - - - if ($iter) $Registry_docinfo_processor$68.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_document_processor', ["docinfo_processor", args], block.$to_proc()); - }, $Registry_docinfo_processor$68.$$arity = -1); - - Opal.def(self, '$docinfo_processors?', $Registry_docinfo_processors$ques$69 = function(location) { - var $$70, self = this; + return !!this._matchGlobStarBodySections( + file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch + ) + } - - - if (location == null) { - location = nil; - }; - if ($truthy(self.docinfo_processor_extensions)) { - if ($truthy(location)) { - return $send(self.docinfo_processor_extensions, 'any?', [], ($$70 = function(ext){var self = $$70.$$s || this; + // return false for "nope, not matching" + // return null for "not matching, cannot keep trying" + _matchGlobStarBodySections ( + file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail + ) { + const bs = bodySegments[bodyIndex] + if (!bs) { + // just make sure there are no bad dots + for (let i = fileIndex; i < file.length; i++) { + sawTail = true + const f = file[i] + if (f === '.' || f === '..' || + (!this.options.dot && f.charAt(0) === '.')) { + return false + } + } + return sawTail + } - - - if (ext == null) { - ext = nil; - }; - return ext.$config()['$[]']("location")['$=='](location);}, $$70.$$s = self, $$70.$$arity = 1, $$70)) - } else { - return true - } - } else { - return false - }; - }, $Registry_docinfo_processors$ques$69.$$arity = -1); - - Opal.def(self, '$docinfo_processors', $Registry_docinfo_processors$71 = function $$docinfo_processors(location) { - var $$72, self = this; + const [body, after] = bs + while (fileIndex <= after) { + const m = this._matchOne( + file.slice(0, fileIndex + body.length), + body, + partial, + fileIndex, + 0 + ) + // if limit exceeded, no match. intentional false negative, + // acceptable break in correctness for security. + if (m && globStarDepth < this.maxGlobstarRecursion) { + const sub = this._matchGlobStarBodySections( + file, bodySegments, + fileIndex + body.length, bodyIndex + 1, + partial, globStarDepth + 1, sawTail + ) + if (sub !== false) { + return sub + } + } + const f = file[fileIndex] + if (f === '.' || f === '..' || + (!this.options.dot && f.charAt(0) === '.')) { + return false + } + fileIndex++ + } + return partial || null + } - - - if (location == null) { - location = nil; - }; - if ($truthy(self.docinfo_processor_extensions)) { - if ($truthy(location)) { - return $send(self.docinfo_processor_extensions, 'select', [], ($$72 = function(ext){var self = $$72.$$s || this; + _matchOne (file, pattern, partial, fileIndex, patternIndex) { + let fi, pi, fl, pl + for ( + fi = fileIndex, pi = patternIndex, fl = file.length, pl = pattern.length + ; (fi < fl) && (pi < pl) + ; fi++, pi++ + ) { + this.debug('matchOne loop') + const p = pattern[pi] + const f = file[fi] - - - if (ext == null) { - ext = nil; - }; - return ext.$config()['$[]']("location")['$=='](location);}, $$72.$$s = self, $$72.$$arity = 1, $$72)) - } else { - return self.docinfo_processor_extensions - } - } else { - return nil - }; - }, $Registry_docinfo_processors$71.$$arity = -1); - - Opal.def(self, '$block', $Registry_block$73 = function $$block($a) { - var $iter = $Registry_block$73.$$p, block = $iter || nil, $post_args, args, self = this; + this.debug(pattern, p, f) - if ($iter) $Registry_block$73.$$p = null; - - - if ($iter) $Registry_block$73.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_syntax_processor', ["block", args], block.$to_proc()); - }, $Registry_block$73.$$arity = -1); - - Opal.def(self, '$blocks?', $Registry_blocks$ques$74 = function() { - var self = this; + // should be impossible. + // some invalid regexp stuff in the set. + /* istanbul ignore if */ + if (p === false || p === GLOBSTAR) return false - return self.block_extensions['$!']()['$!']() - }, $Registry_blocks$ques$74.$$arity = 0); - - Opal.def(self, '$registered_for_block?', $Registry_registered_for_block$ques$75 = function(name, context) { - var self = this, ext = nil; + // something other than ** + // non-magic patterns just have to match exactly + // patterns with magic have been turned into regexps. + let hit + if (typeof p === 'string') { + hit = f === p + this.debug('string match', p, f, hit) + } else { + hit = f.match(p) + this.debug('pattern match', p, f, hit) + } - if ($truthy((ext = self.block_extensions['$[]'](name.$to_sym())))) { - if ($truthy(ext.$config()['$[]']("contexts")['$include?'](context))) { - return ext - } else { - return false - } - } else { - return false - } - }, $Registry_registered_for_block$ques$75.$$arity = 2); - - Opal.def(self, '$find_block_extension', $Registry_find_block_extension$76 = function $$find_block_extension(name) { - var self = this; + if (!hit) return false + } - return self.block_extensions['$[]'](name.$to_sym()) - }, $Registry_find_block_extension$76.$$arity = 1); - - Opal.def(self, '$block_macro', $Registry_block_macro$77 = function $$block_macro($a) { - var $iter = $Registry_block_macro$77.$$p, block = $iter || nil, $post_args, args, self = this; + // now either we fell off the end of the pattern, or we're done. + if (fi === fl && pi === pl) { + // ran out of pattern and filename at the same time. + // an exact hit! + return true + } else if (fi === fl) { + // ran out of file, but still had pattern left. + // this is ok if we're doing the match as part of + // a glob fs traversal. + return partial + } else /* istanbul ignore else */ if (pi === pl) { + // ran out of pattern, still have file left. + // this is only acceptable if we're on the very last + // empty segment of a file with a trailing slash. + // a/* should match a/b/ + return (fi === fl - 1) && (file[fi] === '') + } - if ($iter) $Registry_block_macro$77.$$p = null; - - - if ($iter) $Registry_block_macro$77.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_syntax_processor', ["block_macro", args], block.$to_proc()); - }, $Registry_block_macro$77.$$arity = -1); - - Opal.def(self, '$block_macros?', $Registry_block_macros$ques$78 = function() { - var self = this; + // should be unreachable. + /* istanbul ignore next */ + throw new Error('wtf?') + } - return self.block_macro_extensions['$!']()['$!']() - }, $Registry_block_macros$ques$78.$$arity = 0); - - Opal.def(self, '$registered_for_block_macro?', $Registry_registered_for_block_macro$ques$79 = function(name) { - var self = this, ext = nil; + braceExpand () { + return braceExpand(this.pattern, this.options) + } - if ($truthy((ext = self.block_macro_extensions['$[]'](name.$to_sym())))) { - return ext - } else { - return false - } - }, $Registry_registered_for_block_macro$ques$79.$$arity = 1); - - Opal.def(self, '$find_block_macro_extension', $Registry_find_block_macro_extension$80 = function $$find_block_macro_extension(name) { - var self = this; + parse (pattern, isSub) { + assertValidPattern(pattern) - return self.block_macro_extensions['$[]'](name.$to_sym()) - }, $Registry_find_block_macro_extension$80.$$arity = 1); - - Opal.def(self, '$inline_macro', $Registry_inline_macro$81 = function $$inline_macro($a) { - var $iter = $Registry_inline_macro$81.$$p, block = $iter || nil, $post_args, args, self = this; + const options = this.options - if ($iter) $Registry_inline_macro$81.$$p = null; - - - if ($iter) $Registry_inline_macro$81.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'add_syntax_processor', ["inline_macro", args], block.$to_proc()); - }, $Registry_inline_macro$81.$$arity = -1); - - Opal.def(self, '$inline_macros?', $Registry_inline_macros$ques$82 = function() { - var self = this; + // shortcuts + if (pattern === '**') { + if (!options.noglobstar) + return GLOBSTAR + else + pattern = '*' + } + if (pattern === '') return '' + + let re = '' + let hasMagic = false + let escaping = false + // ? => one single character + const patternListStack = [] + const negativeLists = [] + let stateChar + let inClass = false + let reClassStart = -1 + let classStart = -1 + let cs + let pl + let sp + // . and .. never match anything that doesn't start with ., + // even when options.dot is set. However, if the pattern + // starts with ., then traversal patterns can match. + let dotTravAllowed = pattern.charAt(0) === '.' + let dotFileAllowed = options.dot || dotTravAllowed + const patternStart = () => + dotTravAllowed + ? '' + : dotFileAllowed + ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))' + : '(?!\\.)' + const subPatternStart = (p) => + p.charAt(0) === '.' + ? '' + : options.dot + ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))' + : '(?!\\.)' + + + const clearStateChar = () => { + if (stateChar) { + // we had some state-tracking character + // that wasn't consumed by this pass. + switch (stateChar) { + case '*': + re += star + hasMagic = true + break + case '?': + re += qmark + hasMagic = true + break + default: + re += '\\' + stateChar + break + } + this.debug('clearStateChar %j %j', stateChar, re) + stateChar = false + } + } - return self.inline_macro_extensions['$!']()['$!']() - }, $Registry_inline_macros$ques$82.$$arity = 0); - - Opal.def(self, '$registered_for_inline_macro?', $Registry_registered_for_inline_macro$ques$83 = function(name) { - var self = this, ext = nil; + for (let i = 0, c; (i < pattern.length) && (c = pattern.charAt(i)); i++) { + this.debug('%s\t%s %s %j', pattern, i, re, c) - if ($truthy((ext = self.inline_macro_extensions['$[]'](name.$to_sym())))) { - return ext - } else { - return false - } - }, $Registry_registered_for_inline_macro$ques$83.$$arity = 1); - - Opal.def(self, '$find_inline_macro_extension', $Registry_find_inline_macro_extension$84 = function $$find_inline_macro_extension(name) { - var self = this; + // skip over any that are escaped. + if (escaping) { + /* istanbul ignore next - completely not allowed, even escaped. */ + if (c === '/') { + return false + } - return self.inline_macro_extensions['$[]'](name.$to_sym()) - }, $Registry_find_inline_macro_extension$84.$$arity = 1); - - Opal.def(self, '$inline_macros', $Registry_inline_macros$85 = function $$inline_macros() { - var self = this; + if (reSpecials[c]) { + re += '\\' + } + re += c + escaping = false + continue + } - return self.inline_macro_extensions.$values() - }, $Registry_inline_macros$85.$$arity = 0); - - Opal.def(self, '$prefer', $Registry_prefer$86 = function $$prefer($a) { - var $iter = $Registry_prefer$86.$$p, block = $iter || nil, $post_args, args, self = this, extension = nil, arg0 = nil, extensions_store = nil; + switch (c) { + /* istanbul ignore next */ + case '/': { + // Should already be path-split by now. + return false + } - if ($iter) $Registry_prefer$86.$$p = null; - - - if ($iter) $Registry_prefer$86.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - extension = (function() {if ($truthy($$($nesting, 'ProcessorExtension')['$===']((arg0 = args.$shift())))) { - return arg0 - } else { - - return $send(self, 'send', [arg0].concat(Opal.to_a(args)), block.$to_proc()); - }; return nil; })(); - extensions_store = self.$instance_variable_get(((("" + "@") + (extension.$kind())) + "_extensions").$to_sym()); - extensions_store.$unshift(extensions_store.$delete(extension)); - return extension; - }, $Registry_prefer$86.$$arity = -1); - self.$private(); - - Opal.def(self, '$add_document_processor', $Registry_add_document_processor$87 = function $$add_document_processor(kind, args) { - var $iter = $Registry_add_document_processor$87.$$p, block = $iter || nil, $$88, $a, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, config = nil, processor = nil, extension = nil, processor_class = nil, processor_instance = nil; + case '\\': + if (inClass && pattern.charAt(i + 1) === '-') { + re += c + continue + } - if ($iter) $Registry_add_document_processor$87.$$p = null; - - - if ($iter) $Registry_add_document_processor$87.$$p = null;; - kind_name = kind.$to_s().$tr("_", " "); - kind_class_symbol = $send(kind_name.$split(), 'map', [], ($$88 = function(it){var self = $$88.$$s || this; + clearStateChar() + escaping = true + continue - - - if (it == null) { - it = nil; - }; - return it.$capitalize();}, $$88.$$s = self, $$88.$$arity = 1, $$88)).$join().$to_sym(); - kind_class = $$($nesting, 'Extensions').$const_get(kind_class_symbol, false); - kind_java_class = (function() {if ($truthy((($a = $$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil))) { - - return $$$($$$('::', 'AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false); - } else { - return nil - }; return nil; })(); - kind_store = ($truthy($b = self.$instance_variable_get(((("" + "@") + (kind)) + "_extensions").$to_sym())) ? $b : self.$instance_variable_set(((("" + "@") + (kind)) + "_extensions").$to_sym(), [])); - if ((block !== nil)) { - - config = self.$resolve_args(args, 1); - (processor = kind_class.$new(config)).$singleton_class().$enable_dsl(); - if (block.$arity()['$=='](0)) { - $send(processor, 'instance_exec', [], block.$to_proc()) - } else { - Opal.yield1(block, processor) - }; - if ($truthy(processor['$process_block_given?']())) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "No block specified to process " + (kind_name) + " extension at " + (block.$source_location())) - }; - processor.$freeze(); - extension = $$($nesting, 'ProcessorExtension').$new(kind, processor); - } else { - - $c = self.$resolve_args(args, 2), $b = Opal.to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])), $c; - if ($truthy((processor_class = $$($nesting, 'Helpers').$resolve_class(processor)))) { - - if ($truthy(($truthy($b = $rb_lt(processor_class, kind_class)) ? $b : ($truthy($c = kind_java_class) ? $rb_lt(processor_class, kind_java_class) : $c)))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "Invalid type for " + (kind_name) + " extension: " + (processor)) - }; - processor_instance = processor_class.$new(config); - processor_instance.$freeze(); - extension = $$($nesting, 'ProcessorExtension').$new(kind, processor_instance); - } else if ($truthy(($truthy($b = kind_class['$==='](processor)) ? $b : ($truthy($c = kind_java_class) ? kind_java_class['$==='](processor) : $c)))) { - - processor.$update_config(config); - processor.$freeze(); - extension = $$($nesting, 'ProcessorExtension').$new(kind, processor); - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args)) - }; - }; - if (extension.$config()['$[]']("position")['$=='](">>")) { - - kind_store.$unshift(extension); - } else { - - kind_store['$<<'](extension); - }; - return extension; - }, $Registry_add_document_processor$87.$$arity = 2); - - Opal.def(self, '$add_syntax_processor', $Registry_add_syntax_processor$89 = function $$add_syntax_processor(kind, args) { - var $iter = $Registry_add_syntax_processor$89.$$p, block = $iter || nil, $$90, $a, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, name = nil, config = nil, processor = nil, $writer = nil, processor_class = nil, processor_instance = nil; + // the various stateChar values + // for the "extglob" stuff. + case '?': + case '*': + case '+': + case '@': + case '!': + this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c) + + // all of those are literals inside a class, except that + // the glob [!a] means [^a] in regexp + if (inClass) { + this.debug(' in class') + if (c === '!' && i === classStart + 1) c = '^' + re += c + continue + } - if ($iter) $Registry_add_syntax_processor$89.$$p = null; - - - if ($iter) $Registry_add_syntax_processor$89.$$p = null;; - kind_name = kind.$to_s().$tr("_", " "); - kind_class_symbol = $send(kind_name.$split(), 'map', [], ($$90 = function(it){var self = $$90.$$s || this; + // coalesce consecutive non-globstar * characters + if (c === '*' && stateChar === '*') continue + + // if we already have a stateChar, then it means + // that there was something like ** or +? in there. + // Handle the stateChar, then proceed with this one. + this.debug('call clearStateChar %j', stateChar) + clearStateChar() + stateChar = c + // if extglob is disabled, then +(asdf|foo) isn't a thing. + // just clear the statechar *now*, rather than even diving into + // the patternList stuff. + if (options.noext) clearStateChar() + continue + + case '(': { + if (inClass) { + re += '(' + continue + } - - - if (it == null) { - it = nil; - }; - return it.$capitalize();}, $$90.$$s = self, $$90.$$arity = 1, $$90))['$<<']("Processor").$join().$to_sym(); - kind_class = $$($nesting, 'Extensions').$const_get(kind_class_symbol, false); - kind_java_class = (function() {if ($truthy((($a = $$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil))) { - - return $$$($$$('::', 'AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false); - } else { - return nil - }; return nil; })(); - kind_store = ($truthy($b = self.$instance_variable_get(((("" + "@") + (kind)) + "_extensions").$to_sym())) ? $b : self.$instance_variable_set(((("" + "@") + (kind)) + "_extensions").$to_sym(), $hash2([], {}))); - if ((block !== nil)) { - - $c = self.$resolve_args(args, 2), $b = Opal.to_ary($c), (name = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])), $c; - (processor = kind_class.$new(self.$as_symbol(name), config)).$singleton_class().$enable_dsl(); - if (block.$arity()['$=='](0)) { - $send(processor, 'instance_exec', [], block.$to_proc()) - } else { - Opal.yield1(block, processor) - }; - if ($truthy((name = self.$as_symbol(processor.$name())))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "No name specified for " + (kind_name) + " extension at " + (block.$source_location())) - }; - if ($truthy(processor['$process_block_given?']())) { - } else { - self.$raise($$$('::', 'NoMethodError'), "" + "No block specified to process " + (kind_name) + " extension at " + (block.$source_location())) - }; - processor.$freeze(); - - $writer = [name, $$($nesting, 'ProcessorExtension').$new(kind, processor)]; - $send(kind_store, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else { - - $c = self.$resolve_args(args, 3), $b = Opal.to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (name = ($b[1] == null ? nil : $b[1])), (config = ($b[2] == null ? nil : $b[2])), $c; - if ($truthy((processor_class = $$($nesting, 'Helpers').$resolve_class(processor)))) { - - if ($truthy(($truthy($b = $rb_lt(processor_class, kind_class)) ? $b : ($truthy($c = kind_java_class) ? $rb_lt(processor_class, kind_java_class) : $c)))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "Class specified for " + (kind_name) + " extension does not inherit from " + (kind_class) + ": " + (processor)) - }; - processor_instance = processor_class.$new(self.$as_symbol(name), config); - if ($truthy((name = self.$as_symbol(processor_instance.$name())))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "No name specified for " + (kind_name) + " extension: " + (processor)) - }; - processor_instance.$freeze(); - - $writer = [name, $$($nesting, 'ProcessorExtension').$new(kind, processor_instance)]; - $send(kind_store, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else if ($truthy(($truthy($b = kind_class['$==='](processor)) ? $b : ($truthy($c = kind_java_class) ? kind_java_class['$==='](processor) : $c)))) { - - processor.$update_config(config); - if ($truthy((name = (function() {if ($truthy(name)) { - - - $writer = [self.$as_symbol(name)]; - $send(processor, 'name=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else { - - return self.$as_symbol(processor.$name()); - }; return nil; })()))) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "No name specified for " + (kind_name) + " extension: " + (processor)) - }; - processor.$freeze(); - - $writer = [name, $$($nesting, 'ProcessorExtension').$new(kind, processor)]; - $send(kind_store, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - } else { - return self.$raise($$$('::', 'ArgumentError'), "" + "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args)) - }; - }; - }, $Registry_add_syntax_processor$89.$$arity = 2); - - Opal.def(self, '$resolve_args', $Registry_resolve_args$91 = function $$resolve_args(args, expect) { - var self = this, opts = nil, missing = nil; + if (!stateChar) { + re += '\\(' + continue + } - - opts = (function() {if ($truthy($$$('::', 'Hash')['$==='](args['$[]'](-1)))) { - return args.$pop() - } else { - return $hash2([], {}) - }; return nil; })(); - if (expect['$=='](1)) { - return opts}; - if ($truthy($rb_gt((missing = $rb_minus($rb_minus(expect, 1), args.$size())), 0))) { - args = $rb_plus(args, $$$('::', 'Array').$new(missing)) - } else if ($truthy($rb_lt(missing, 0))) { - args.$pop(missing['$-@']())}; - args['$<<'](opts); - return args; - }, $Registry_resolve_args$91.$$arity = 2); - return (Opal.def(self, '$as_symbol', $Registry_as_symbol$92 = function $$as_symbol(name) { - var self = this; + const plEntry = { + type: stateChar, + start: i - 1, + reStart: re.length, + open: plTypes[stateChar].open, + close: plTypes[stateChar].close, + } + this.debug(this.pattern, '\t', plEntry) + patternListStack.push(plEntry) + // negation is (?:(?!(?:js)(?:<rest>))[^/]*) + re += plEntry.open + // next entry starts with a dot maybe? + if (plEntry.start === 0 && plEntry.type !== '!') { + dotTravAllowed = true + re += subPatternStart(pattern.slice(i + 1)) + } + this.debug('plType %j %j', stateChar, re) + stateChar = false + continue + } - if ($truthy(name)) { - return name.$to_sym() - } else { - return nil + case ')': { + const plEntry = patternListStack[patternListStack.length - 1] + if (inClass || !plEntry) { + re += '\\)' + continue } - }, $Registry_as_symbol$92.$$arity = 1), nil) && 'as_symbol'; - })($nesting[0], null, $nesting); - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $generate_name$93, $next_auto_id$94, $groups$95, $create$96, $register$97, $unregister_all$98, $unregister$99; + patternListStack.pop() - - - Opal.def(self, '$generate_name', $generate_name$93 = function $$generate_name() { - var self = this; + // closing an extglob + clearStateChar() + hasMagic = true + pl = plEntry + // negation is (?:(?!js)[^/]*) + // The others are (?:<pattern>)<type> + re += pl.close + if (pl.type === '!') { + negativeLists.push(Object.assign(pl, { reEnd: re.length })) + } + continue + } - return "" + "extgrp" + (self.$next_auto_id()) - }, $generate_name$93.$$arity = 0); - - Opal.def(self, '$next_auto_id', $next_auto_id$94 = function $$next_auto_id() { - var $a, self = this; - if (self.auto_id == null) self.auto_id = nil; + case '|': { + const plEntry = patternListStack[patternListStack.length - 1] + if (inClass || !plEntry) { + re += '\\|' + continue + } - - self.auto_id = ($truthy($a = self.auto_id) ? $a : -1); - return (self.auto_id = $rb_plus(self.auto_id, 1)); - }, $next_auto_id$94.$$arity = 0); - - Opal.def(self, '$groups', $groups$95 = function $$groups() { - var $a, self = this; - if (self.groups == null) self.groups = nil; + clearStateChar() + re += '|' + // next subpattern can start with a dot? + if (plEntry.start === 0 && plEntry.type !== '!') { + dotTravAllowed = true + re += subPatternStart(pattern.slice(i + 1)) + } + continue + } - return (self.groups = ($truthy($a = self.groups) ? $a : $hash2([], {}))) - }, $groups$95.$$arity = 0); - - Opal.def(self, '$create', $create$96 = function $$create(name) { - var $iter = $create$96.$$p, block = $iter || nil, $a, self = this; + // these are mostly the same in regexp and glob + case '[': + // swallow any state-tracking char before the [ + clearStateChar() - if ($iter) $create$96.$$p = null; - - - if ($iter) $create$96.$$p = null;; - - if (name == null) { - name = nil; - }; - if ((block !== nil)) { - return $$($nesting, 'Registry').$new($hash(($truthy($a = name) ? $a : self.$generate_name()), block)) - } else { - return $$($nesting, 'Registry').$new() - }; - }, $create$96.$$arity = -1); - - Opal.def(self, '$register', $register$97 = function $$register($a) { - var $iter = $register$97.$$p, block = $iter || nil, $post_args, args, $b, self = this, argc = nil, resolved_group = nil, group = nil, name = nil, $writer = nil; + if (inClass) { + re += '\\' + c + continue + } - if ($iter) $register$97.$$p = null; - - - if ($iter) $register$97.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - argc = args.$size(); - if ((block !== nil)) { - resolved_group = block - } else if ($truthy((group = args.$pop()))) { - resolved_group = ($truthy($b = $$($nesting, 'Helpers').$resolve_class(group)) ? $b : group) - } else { - self.$raise($$$('::', 'ArgumentError'), "Extension group to register not specified") - }; - name = ($truthy($b = args.$pop()) ? $b : self.$generate_name()); - if ($truthy(args['$empty?']())) { - } else { - self.$raise($$$('::', 'ArgumentError'), "" + "Wrong number of arguments (" + (argc) + " for 1..2)") - }; - - $writer = [name.$to_sym(), resolved_group]; - $send(self.$groups(), '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; - }, $register$97.$$arity = -1); - - Opal.def(self, '$unregister_all', $unregister_all$98 = function $$unregister_all() { - var self = this; + inClass = true + classStart = i + reClassStart = re.length + re += c + continue + + case ']': + // a right bracket shall lose its special + // meaning and represent itself in + // a bracket expression if it occurs + // first in the list. -- POSIX.2 2.8.3.2 + if (i === classStart + 1 || !inClass) { + re += '\\' + c + continue + } - - self.groups = $hash2([], {}); - return nil; - }, $unregister_all$98.$$arity = 0); - return (Opal.def(self, '$unregister', $unregister$99 = function $$unregister($a) { - var $post_args, names, $$100, self = this; + // split where the last [ was, make sure we don't have + // an invalid re. if so, re-walk the contents of the + // would-be class to re-translate any characters that + // were passed through as-is + // TODO: It would probably be faster to determine this + // without a try/catch and a new RegExp, but it's tricky + // to do safely. For now, this is safe and works. + cs = pattern.substring(classStart + 1, i) + try { + RegExp('[' + braExpEscape(charUnescape(cs)) + ']') + // looks good, finish up the class. + re += c + } catch (er) { + // out of order ranges in JS are errors, but in glob syntax, + // they're just a range that matches nothing. + re = re.substring(0, reClassStart) + '(?:$.)' // match nothing ever + } + hasMagic = true + inClass = false + continue - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - $send(names, 'each', [], ($$100 = function(group){var self = $$100.$$s || this; - if (self.groups == null) self.groups = nil; + default: + // swallow any state char that wasn't consumed + clearStateChar() - - - if (group == null) { - group = nil; - }; - return self.groups.$delete(group.$to_sym());}, $$100.$$s = self, $$100.$$arity = 1, $$100)); - return nil; - }, $unregister$99.$$arity = -1), nil) && 'unregister'; - })(Opal.get_singleton_class(self), $nesting); - })($nesting[0], $nesting) - })($nesting[0], $nesting); -}; + if (reSpecials[c] && !(c === '^' && inClass)) { + re += '\\' + } -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/stylesheet"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy; + re += c + break + + } // switch + } // for + + // handle the case where we left a class open. + // "[abc" is valid, equivalent to "\[abc" + if (inClass) { + // split where the last [ was, and escape it + // this is a huge pita. We now have to re-walk + // the contents of the would-be class to re-translate + // any characters that were passed through as-is + cs = pattern.slice(classStart + 1) + sp = this.parse(cs, SUBPARSE) + re = re.substring(0, reClassStart) + '\\[' + sp[0] + hasMagic = hasMagic || sp[1] + } + + // handle the case where we had a +( thing at the *end* + // of the pattern. + // each pattern list stack adds 3 chars, and we need to go through + // and escape any | chars that were passed through as-is for the regexp. + // Go through and escape them, taking care not to double-escape any + // | chars that were already escaped. + for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) { + let tail + tail = re.slice(pl.reStart + pl.open.length) + this.debug('setting tail', re, pl) + // maybe some even number of \, then maybe 1 \, followed by a | + tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => { + /* istanbul ignore else - should already be done */ + if (!$2) { + // the | isn't already escaped, so escape it. + $2 = '\\' + } + + // need to escape all those slashes *again*, without escaping the + // one that we need for escaping the | character. As it works out, + // escaping an even number of slashes can be done by simply repeating + // it exactly after itself. That's why this trick works. + // + // I am sorry that you have to see this. + return $1 + $1 + $2 + '|' + }) - Opal.add_stubs(['$rstrip', '$read', '$join']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + this.debug('tail=%j\n %s', tail, tail, pl, re) + const t = pl.type === '*' ? star + : pl.type === '?' ? qmark + : '\\' + pl.type - var $nesting = [self].concat($parent_nesting); + hasMagic = true + re = re.slice(0, pl.reStart) + t + '\\(' + tail + } - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Stylesheets'); + // handle trailing things that only matter at the very end. + clearStateChar() + if (escaping) { + // trailing \\ + re += '\\\\' + } - var $nesting = [self].concat($parent_nesting), $Stylesheets_primary_stylesheet_data$1; + // only need to apply the nodot start if the re starts with + // something that could conceivably capture a dot + const addPatternStart = addPatternStartSet[re.charAt(0)] - self.$$prototype.primary_stylesheet_data = nil; - return (Opal.def(self, '$primary_stylesheet_data', $Stylesheets_primary_stylesheet_data$1 = function $$primary_stylesheet_data() { - var $a, self = this; + // Hack to work around lack of negative lookbehind in JS + // A pattern like: *.!(x).!(y|z) needs to ensure that a name + // like 'a.xyz.yz' doesn't match. So, the first negative + // lookahead, has to look ALL the way ahead, to the end of + // the pattern. + for (let n = negativeLists.length - 1; n > -1; n--) { + const nl = negativeLists[n] - return (self.primary_stylesheet_data = ($truthy($a = self.primary_stylesheet_data) ? $a : $$$('::', 'IO').$read($$$('::', 'File').$join("css", "asciidoctor.css")).$rstrip())) - }, $Stylesheets_primary_stylesheet_data$1.$$arity = 0), nil) && 'primary_stylesheet_data' - })($nesting[0], null, $nesting) - })($nesting[0], $nesting) -}; + const nlBefore = re.slice(0, nl.reStart) + const nlFirst = re.slice(nl.reStart, nl.reEnd - 8) + let nlAfter = re.slice(nl.reEnd) + const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/document"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass; + // Handle nested stuff like *(*.js|!(*.json)), where open parens + // mean that we should *not* include the ) in the bit that is considered + // "after" the negated section. + const closeParensBefore = nlBefore.split(')').length + const openParensBefore = nlBefore.split('(').length - closeParensBefore + let cleanAfter = nlAfter + for (let i = 0; i < openParensBefore; i++) { + cleanAfter = cleanAfter.replace(/\)[+*?]?/, '') + } + nlAfter = cleanAfter - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + const dollar = nlAfter === '' && isSub !== SUBPARSE ? '(?:$|\\/)' : '' - var $nesting = [self].concat($parent_nesting); + re = nlBefore + nlFirst + nlAfter + dollar + nlLast + } - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Document'); + // if the re is not "" at this point, then we need to make sure + // it doesn't match against an empty path part. + // Otherwise a/* will match a/, which it should not. + if (re !== '' && hasMagic) { + re = '(?=.)' + re + } - var $nesting = [self].concat($parent_nesting), $Document_fill_datetime_attributes$1; + if (addPatternStart) { + re = patternStart() + re + } - return (Opal.def(self, '$fill_datetime_attributes', $Document_fill_datetime_attributes$1 = function $$fill_datetime_attributes(attrs, input_mtime) { - var self = this; + // parsing just a piece of a larger pattern. + if (isSub === SUBPARSE) { + return [re, hasMagic] + } - - var $truthy = Opal.truthy - var $falsy = Opal.falsy - var nil = Opal.nil - var utc_offset - var source_date_epoch - var localdate - var localyear - var localtime - var localdatetime - var docdate - var doctime + // if it's nocase, and the lcase/uppercase don't match, it's magic + if (options.nocase && !hasMagic) { + hasMagic = pattern.toUpperCase() !== pattern.toLowerCase() + } - var getYear = function (time, utc_offset) { - return utc_offset === 0 ? time.getUTCFullYear() : time.getFullYear() - } - var getMonth = function (time, utc_offset) { - return utc_offset === 0 ? time.getUTCMonth() : time.getMonth() - } - var getDay = function (time, utc_offset) { - return utc_offset === 0 ? time.getUTCDate() : time.getDate() - } - var getHours = function (time, utc_offset) { - return utc_offset === 0 ? time.getUTCHours() : time.getHours() - } + // skip the regexp for non-magical patterns + // unescape anything in it, though, so that it'll be + // an exact match against a file etc. + if (!hasMagic) { + return globUnescape(pattern) + } - var now = new Date() - // See https://reproducible-builds.org/specs/source-date-epoch/ - if (Opal.const_get_qualified('::', 'ENV')['$key?']('SOURCE_DATE_EPOCH')) { - now.setTime(parseInt(Opal.const_get_qualified('::', 'ENV')['$[]']('SOURCE_DATE_EPOCH')) * 1000) - source_date_epoch = now - utc_offset = 0 // utc - } else { - utc_offset = -now.getTimezoneOffset() / 60 // local date - } - // localdate and localyear - if ($truthy((localdate = attrs['$[]']('localdate')))) { - if ($falsy(localyear = attrs['$[]']('localyear'))) { - localyear = localdate.indexOf('-') === 4 ? localdate.substring(0, 4) : nil - attrs['$[]=']('localyear', localyear) - } - } else { - var now_year = getYear(now, utc_offset).toString() - var now_month = ('0' + (getMonth(now, utc_offset) + 1)).slice(-2) - var now_day = ('0' + getDay(now, utc_offset)).slice(-2) - localdate = now_year + '-' + now_month + '-' + now_day - attrs['$[]=']('localdate', localdate) - localyear = now_year - attrs['$[]=']('localyear', now_year) - } - // localtime - if ($falsy((localtime = attrs['$[]']('localtime')))) { - var hours = ('0' + (getHours(now, utc_offset))).slice(-2) - var minutes = ('0' + (now.getMinutes())).slice(-2) - var seconds = ('0' + (now.getSeconds())).slice(-2) - var utc_offset_format - if (utc_offset === 0) { - utc_offset_format = 'UTC' - } else if (utc_offset > 0) { - utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5) - } else { - utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5) - } - localtime = hours + ':' + minutes + ':' + seconds + ' ' + utc_offset_format - attrs['$[]=']('localtime', localtime) - } - // localdatetime - if ($falsy((localdatetime = attrs['$[]']('localdatetime')))) { - localdatetime = localdate + ' ' + localtime - attrs['$[]=']('localdatetime', localdatetime) - } + const flags = options.nocase ? 'i' : '' + try { + return Object.assign(new RegExp('^' + re + '$', flags), { + _glob: pattern, + _src: re, + }) + } catch (er) /* istanbul ignore next - should be impossible */ { + // If it was an invalid regular expression, then it can't match + // anything. This trick looks for a character after the end of + // the string, which is of course impossible, except in multi-line + // mode, but it's not a /m regex. + return new RegExp('$.') + } + } - // docdate, doctime and docdatetime should default to localdate, localtime and localdatetime if not otherwise set - if ($truthy(source_date_epoch)) { - input_mtime = source_date_epoch - } else if ($truthy(input_mtime)) { - utc_offset = -input_mtime.getTimezoneOffset() / 60 - } else { - input_mtime = now - } + makeRe () { + if (this.regexp || this.regexp === false) return this.regexp - // docdate and docyear - if ($truthy(docdate = attrs['$[]']('docdate'))) { - attrs['$[]=']('docyear', docdate.indexOf('-') === 4 ? docdate.substring(0, 4) : nil) - } else { - var mtime_year = getYear(input_mtime, utc_offset).toString() - var mtime_month = ('0' + (getMonth(input_mtime, utc_offset) + 1)).slice(-2) - var mtime_day = ('0' + (getDay(input_mtime, utc_offset))).slice(-2) - docdate = mtime_year + '-' + mtime_month + '-' + mtime_day - attrs['$[]=']('docdate', docdate) - if ($falsy(attrs['$[]']('docyear'))) { - attrs['$[]=']('docyear', mtime_year) + // at this point, this.set is a 2d array of partial + // pattern strings, or "**". + // + // It's better to use .match(). This function shouldn't + // be used, really, but it's pretty convenient sometimes, + // when you just want to work with a regex. + const set = this.set + + if (!set.length) { + this.regexp = false + return this.regexp + } + const options = this.options + + const twoStar = options.noglobstar ? star + : options.dot ? twoStarDot + : twoStarNoDot + const flags = options.nocase ? 'i' : '' + + // coalesce globstars and regexpify non-globstar patterns + // if it's the only item, then we just do one twoStar + // if it's the first, and there are more, prepend (\/|twoStar\/)? to next + // if it's the last, append (\/twoStar|) to previous + // if it's in the middle, append (\/|\/twoStar\/) to previous + // then filter out GLOBSTAR symbols + let re = set.map(pattern => { + pattern = pattern.map(p => + typeof p === 'string' ? regExpEscape(p) + : p === GLOBSTAR ? GLOBSTAR + : p._src + ).reduce((set, p) => { + if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) { + set.push(p) + } + return set + }, []) + pattern.forEach((p, i) => { + if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) { + return } - } - // doctime - if ($falsy(doctime = attrs['$[]']('doctime'))) { - var mtime_hours = ('0' + (getHours(input_mtime, utc_offset))).slice(-2) - var mtime_minutes = ('0' + (input_mtime.getMinutes())).slice(-2) - var mtime_seconds = ('0' + (input_mtime.getSeconds())).slice(-2) - var utc_offset_format - if (utc_offset === 0) { - utc_offset_format = 'UTC' - } else if (utc_offset > 0) { - utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5) + if (i === 0) { + if (pattern.length > 1) { + pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1] + } else { + pattern[i] = twoStar + } + } else if (i === pattern.length - 1) { + pattern[i-1] += '(?:\\\/|' + twoStar + ')?' } else { - utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5) + pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1] + pattern[i+1] = GLOBSTAR } - doctime = mtime_hours + ':' + mtime_minutes + ':' + mtime_seconds + ' ' + utc_offset_format - attrs['$[]=']('doctime', doctime) - } - // docdatetime - if ($falsy(attrs['$[]']('docdatetime'))) { - attrs['$[]=']('docdatetime', docdate + ' ' + doctime) - } - return nil - - }, $Document_fill_datetime_attributes$1.$$arity = 2), nil) && 'fill_datetime_attributes' - })($nesting[0], $$($nesting, 'AbstractBlock'), $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/substitutors"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; - - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); - - var $nesting = [self].concat($parent_nesting); + }) + return pattern.filter(p => p !== GLOBSTAR).join('/') + }).join('|') - (function($base, $parent_nesting) { - var self = $module($base, 'Substitutors'); + // must match entire pattern + // ending in a * or ** will make it less strict. + re = '^(?:' + re + ')$' - var $nesting = [self].concat($parent_nesting), $Substitutors_sub_placeholder$1; + // can match anything, as long as it's not this. + if (this.negate) re = '^(?!' + re + ').*$' - - Opal.def(self, '$sub_placeholder', $Substitutors_sub_placeholder$1 = function $$sub_placeholder(format_string, replacement) { - var self = this; + try { + this.regexp = new RegExp(re, flags) + } catch (ex) /* istanbul ignore next - should be impossible */ { + this.regexp = false + } + return this.regexp + } - return format_string.replace('%s', replacement); - }, $Substitutors_sub_placeholder$1.$$arity = 2) - })($nesting[0], $nesting) - })($nesting[0], $nesting) -}; + match (f, partial = this.partial) { + this.debug('match', f, this.pattern) + // short-circuit in the case of busted things. + // comments, etc. + if (this.comment) return false + if (this.empty) return f === '' -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/parser"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy; + if (f === '/' && partial) return true - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + const options = this.options - var $nesting = [self].concat($parent_nesting); + // windows: need to use /, not \ + if (path.sep !== '/') { + f = f.split(path.sep).join('/') + } - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Parser'); + // treat the test path as a set of pathparts. + f = f.split(slashSplit) + this.debug(this.pattern, 'split', f) - var $nesting = [self].concat($parent_nesting), $Parser_uniform$ques$1, $Parser_uniform$ques$2; + // just ONE of the pattern sets in this.set needs to match + // in order for it to be valid. If negating, then just one + // match means that we have failed. + // Either way, return on the first hit. - if ($truthy(String.prototype.repeat)) { - return (Opal.defs(self, '$uniform?', $Parser_uniform$ques$1 = function(str, chr, len) { - var self = this; + const set = this.set + this.debug(this.pattern, 'set', set) - return chr.repeat(len) === str; - }, $Parser_uniform$ques$1.$$arity = 3), nil) && 'uniform?' - } else { - return (Opal.defs(self, '$uniform?', $Parser_uniform$ques$2 = function(str, chr, len) { - var self = this; + // Find the basename of the path by looking for the last non-empty segment + let filename + for (let i = f.length - 1; i >= 0; i--) { + filename = f[i] + if (filename) break + } - return Array.apply(null, { length: len }).map(function () { return chr }).join('') === str; - }, $Parser_uniform$ques$2.$$arity = 3), nil) && 'uniform?' + for (let i = 0; i < set.length; i++) { + const pattern = set[i] + let file = f + if (options.matchBase && pattern.length === 1) { + file = [filename] } - })($nesting[0], null, $nesting) - })($nesting[0], $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext/syntax_highlighter"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy; + const hit = this.matchOne(file, pattern, partial) + if (hit) { + if (options.flipNegate) return true + return !this.negate + } + } - Opal.add_stubs(['$key?', '$registry', '$[]', '$include?', '$include', '$empty?', '$debug', '$logger', '$join', '$keys']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + // didn't get any hits. this is success if it's a negative + // pattern, failure otherwise. + if (options.flipNegate) return false + return this.negate + } - var $nesting = [self].concat($parent_nesting); + static defaults (def) { + return minimatch.defaults(def).Minimatch + } +} - (function($base, $parent_nesting) { - var self = $module($base, 'SyntaxHighlighter'); +minimatch.Minimatch = Minimatch - var $nesting = [self].concat($parent_nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Factory'); +/***/ }), - var $nesting = [self].concat($parent_nesting), $Factory_for$1; +/***/ 5560: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - - Opal.def(self, '$for', $Factory_for$1 = function(name) { - var self = this; +var wrappy = __nccwpck_require__(8264) +module.exports = wrappy(once) +module.exports.strict = wrappy(onceStrict) - if ($truthy(self.$registry()['$key?'](name))) { - return self.$registry()['$[]'](name) - } else { - - if ($truthy(self['$include?']($$($nesting, 'Logging')))) { - } else { - self.$include($$($nesting, 'Logging')) - }; - if ($truthy(self.$registry()['$empty?']())) { - self.$logger().$debug("no syntax highlighter available, functionality disabled.") - } else { - self.$logger().$debug("" + "syntax highlighter named '" + (name) + "' is not available, must be one of: '" + (self.$registry().$keys().$join("', '")) + "'.") - }; - return nil; - } - }, $Factory_for$1.$$arity = 1) - })($nesting[0], $nesting) - })($nesting[0], $nesting) - })($nesting[0], $nesting) -}; +once.proto = once(function () { + Object.defineProperty(Function.prototype, 'once', { + value: function () { + return once(this) + }, + configurable: true + }) -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/asciidoctor_ext"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; + Object.defineProperty(Function.prototype, 'onceStrict', { + value: function () { + return onceStrict(this) + }, + configurable: true + }) +}) - Opal.add_stubs(['$require']); - - self.$require("asciidoctor/js/asciidoctor_ext/stylesheet"); - self.$require("asciidoctor/js/asciidoctor_ext/document"); - self.$require("asciidoctor/js/asciidoctor_ext/substitutors"); - self.$require("asciidoctor/js/asciidoctor_ext/parser"); - self.$require("asciidoctor/js/asciidoctor_ext/syntax_highlighter"); - -// Load specific runtime -self.$require("asciidoctor/js/asciidoctor_ext/node"); -; -}; +function once (fn) { + var f = function () { + if (f.called) return f.value + f.called = true + return f.value = fn.apply(this, arguments) + } + f.called = false + return f +} -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/opal_ext/logger"] = function(Opal) { - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); +function onceStrict (fn) { + var f = function () { + if (f.called) + throw new Error(f.onceError) + f.called = true + return f.value = fn.apply(this, arguments) } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; + var name = fn.name || 'Function wrapped with `once`' + f.onceError = name + " shouldn't be called more than once" + f.called = false + return f +} - Opal.add_stubs(['$chr', '$rjust', '$message_as_string', '$<', '$write', '$call', '$[]']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Logger'); - var $nesting = [self].concat($parent_nesting), $Logger_add$2; +/***/ }), - self.$$prototype.level = self.$$prototype.progname = self.$$prototype.pipe = self.$$prototype.formatter = nil; - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Formatter'); +/***/ 1833: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { - var $nesting = [self].concat($parent_nesting), $Formatter_call$1; +/** + * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. + * + * This can be used with JS designed for browsers to improve reuse of code and + * allow the use of existing libraries. + * + * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. + * + * @author Dan DeFelippi <dan@driverdan.com> + * @contributor David Ellis <d.f.ellis@ieee.org> + * @contributor Guillaume Grossetie <ggrossetie@yuzutech.fr> + * @contributor David Jencks <djencks@apache.org> + * @license MIT + */ +const Url = __nccwpck_require__(7016) +const fs = __nccwpck_require__(9896) +const ospath = __nccwpck_require__(6928) - return (Opal.def(self, '$call', $Formatter_call$1 = function $$call(severity, time, progname, msg) { - var self = this, time_format = nil; +// 100 MB +const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100 - - time_format = time.getFullYear() + '-' + ('0'+(time.getMonth()+1)).slice(-2) + '-' + ('0'+time.getDate()).slice(-2) + 'T' + ('0'+time.getHours()).slice(-2) + ':' + ('0'+time.getMinutes()).slice(-2) + ':' + ('0'+time.getSeconds()).slice(-2) + '.' + ('00' + new Date().getMilliseconds() * 1000).slice(-6); - return "" + (severity.$chr()) + ", [" + (time_format) + "] " + (severity.$rjust(5)) + " -- " + (progname) + ": " + (self.$message_as_string(msg)); - }, $Formatter_call$1.$$arity = 4), nil) && 'call' - })($nesting[0], null, $nesting); - return (Opal.def(self, '$add', $Logger_add$2 = function $$add(severity, message, progname) { - var $iter = $Logger_add$2.$$p, block = $iter || nil, $a, self = this; +exports.XMLHttpRequest = function () { + 'use strict' - if ($iter) $Logger_add$2.$$p = null; - - - if ($iter) $Logger_add$2.$$p = null;; - - if (message == null) { - message = nil; - }; - - if (progname == null) { - progname = nil; - }; - if ($truthy($rb_lt((severity = ($truthy($a = severity) ? $a : $$($nesting, 'UNKNOWN'))), self.level))) { - return true}; - progname = ($truthy($a = progname) ? $a : self.progname); - if ($truthy(message)) { - } else if ((block !== nil)) { - message = Opal.yieldX(block, []) - } else { - - message = progname; - progname = self.progname; - }; - self.pipe.$write(self.formatter.$call(($truthy($a = $$($nesting, 'SEVERITY_LABELS')['$[]'](severity)) ? $a : "ANY"), new Date(), progname, message)); - return true; - }, $Logger_add$2.$$arity = -2), nil) && 'add'; - })($nesting[0], null, $nesting) -}; + /** + * Private variables + */ + const self = this + const http = __nccwpck_require__(8611) + const https = __nccwpck_require__(5692) -/* Generated by Opal 0.11.99.dev */ -Opal.modules["asciidoctor/js/postscript"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; + // Holds http.js objects + let request + let response - Opal.add_stubs(['$require']); - - self.$require("asciidoctor/converter/composite"); - self.$require("asciidoctor/converter/html5"); - self.$require("asciidoctor/extensions"); - self.$require("asciidoctor/js/asciidoctor_ext"); - return self.$require("asciidoctor/js/opal_ext/logger"); -}; + // Request settings + let settings = {} + + // Disable header blacklist. + // Not part of XHR specs. + let disableHeaderCheck = false -/* Generated by Opal 0.11.99.dev */ -(function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); + // Set some default headers + const defaultHeaders = { + 'User-Agent': 'node-XMLHttpRequest', + Accept: '*/*' } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $send = Opal.send, $truthy = Opal.truthy, $hash2 = Opal.hash2; - Opal.add_stubs(['$require', '$==', '$to_h', '$sort', '$map', '$constants', '$const_get', '$downcase', '$to_s', '$<=>', '$upcase', '$[]', '$values', '$new', '$attr_reader', '$instance_variable_set', '$send', '$singleton_class', '$<<', '$define', '$dirname', '$absolute_path', '$__dir__', '$join', '$home', '$pwd', '$to_set', '$tap', '$each', '$chr', '$each_key', '$slice', '$[]=', '$-', '$length', '$merge', '$default=', '$drop', '$insert']); - - self.$require("set"); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - self.$require("asciidoctor/js") - } else { - nil - }; - (function($base, $parent_nesting) { - var self = $module($base, 'Asciidoctor'); + let headers = {} + const headersCase = {} - var $nesting = [self].concat($parent_nesting), $a, $b, $Asciidoctor$7, $Asciidoctor$9, $Asciidoctor$11, $Asciidoctor$13, $writer = nil; + // These headers are not user setable. + // The following are allowed but banned in the spec: + // * user-agent + const forbiddenRequestHeaders = [ + 'accept-charset', + 'accept-encoding', + 'access-control-request-headers', + 'access-control-request-method', + 'connection', + 'content-length', + 'content-transfer-encoding', + 'cookie', + 'cookie2', + 'date', + 'expect', + 'host', + 'keep-alive', + 'origin', + 'referer', + 'te', + 'trailer', + 'transfer-encoding', + 'upgrade', + 'via' + ] - - Opal.const_set($nesting[0], 'RUBY_ENGINE_OPAL', Opal.const_set($nesting[0], 'RUBY_ENGINE', $$$('::', 'RUBY_ENGINE'))['$==']("opal")); - (function($base, $parent_nesting) { - var self = $module($base, 'SafeMode'); + // These request methods are not allowed + const forbiddenRequestMethods = [ + 'TRACE', + 'TRACK', + 'CONNECT' + ] - var $nesting = [self].concat($parent_nesting), $SafeMode$1, $SafeMode$2, $SafeMode_value_for_name$3, $SafeMode_name_for_value$4, $SafeMode_names$5; + // Send flag + let sendFlag = false + // Error flag, used when errors occur or abort is called + let errorFlag = false - - Opal.const_set($nesting[0], 'UNSAFE', 0); - Opal.const_set($nesting[0], 'SAFE', 1); - Opal.const_set($nesting[0], 'SERVER', 10); - Opal.const_set($nesting[0], 'SECURE', 20); - self.names_by_value = $send($send(self.$constants(false), 'map', [], ($SafeMode$1 = function(sym){var self = $SafeMode$1.$$s || this; + // Binary response (chunk) + const responseBinary = [] - - - if (sym == null) { - sym = nil; - }; - return [self.$const_get(sym), sym.$to_s().$downcase()];}, $SafeMode$1.$$s = self, $SafeMode$1.$$arity = 1, $SafeMode$1)), 'sort', [], ($SafeMode$2 = function($mlhs_tmp1, $mlhs_tmp2){var self = $SafeMode$2.$$s || this, $a, $b, a = nil, b = nil; + // Event listeners + const listeners = {} - - - if ($mlhs_tmp1 == null) { - $mlhs_tmp1 = nil; - }; - - if ($mlhs_tmp2 == null) { - $mlhs_tmp2 = nil; - }; - $b = $mlhs_tmp1, $a = Opal.to_ary($b), (a = ($a[0] == null ? nil : $a[0])), $b; - $b = $mlhs_tmp2, $a = Opal.to_ary($b), (b = ($a[0] == null ? nil : $a[0])), $b; - return a['$<=>'](b);}, $SafeMode$2.$$s = self, $SafeMode$2.$$arity = 2, $SafeMode$2.$$has_top_level_mlhs_arg = true, $SafeMode$2)).$to_h(); - Opal.defs(self, '$value_for_name', $SafeMode_value_for_name$3 = function $$value_for_name(name) { - var self = this; + /** + * Constants + */ - return self.$const_get(name.$upcase(), false) - }, $SafeMode_value_for_name$3.$$arity = 1); - Opal.defs(self, '$name_for_value', $SafeMode_name_for_value$4 = function $$name_for_value(value) { - var self = this; - if (self.names_by_value == null) self.names_by_value = nil; + this.UNSENT = 0 + this.OPENED = 1 + this.HEADERS_RECEIVED = 2 + this.LOADING = 3 + this.DONE = 4 - return self.names_by_value['$[]'](value) - }, $SafeMode_name_for_value$4.$$arity = 1); - Opal.defs(self, '$names', $SafeMode_names$5 = function $$names() { - var self = this; - if (self.names_by_value == null) self.names_by_value = nil; + /** + * Public vars + */ - return self.names_by_value.$values() - }, $SafeMode_names$5.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Compliance'); + // Current state + this.readyState = this.UNSENT - var $nesting = [self].concat($parent_nesting); + // default ready state change handler in case one is not set or is set late + this.onreadystatechange = null - - self.keys = $$$('::', 'Set').$new(); - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $define$6; + // Result & response + this.responseText = '' + this.responseXML = '' + this.status = null + this.statusText = null - - self.$attr_reader("keys"); - return (Opal.def(self, '$define', $define$6 = function $$define(key, value) { - var self = this; - if (self.keys == null) self.keys = nil; + // Whether cross-site Access-Control requests should be made using + // credentials such as cookies or authorization headers + this.withCredentials = false + // "text", "arraybuffer", "blob", or "document", depending on your data needs. + // Note, setting xhr.responseType = '' (or omitting) will default the response to "text". + // Omitting, '', or "text" will return a String. + // Other values will return an ArrayBuffer. + this.responseType = '' - - self.$instance_variable_set("" + "@" + (key), value); - self.$singleton_class().$send("attr_accessor", key); - self.keys['$<<'](key); - return nil; - }, $define$6.$$arity = 2), nil) && 'define'; - })(Opal.get_singleton_class(self), $nesting); - self.$define("block_terminates_paragraph", true); - self.$define("strict_verbatim_paragraphs", true); - self.$define("underline_style_section_titles", true); - self.$define("unwrap_standalone_preamble", true); - self.$define("attribute_missing", "skip"); - self.$define("attribute_undefined", "drop-line"); - self.$define("shorthand_property_syntax", true); - self.$define("natural_xrefs", true); - self.$define("unique_id_start_index", 2); - self.$define("markdown_syntax", true); - })($nesting[0], $nesting); - if ($truthy((($a = $$($nesting, 'ROOT_DIR', 'skip_raise')) ? 'constant' : nil))) { - } else { - Opal.const_set($nesting[0], 'ROOT_DIR', $$$('::', 'File').$dirname($$$('::', 'File').$absolute_path(self.$__dir__()))) - }; - Opal.const_set($nesting[0], 'LIB_DIR', $$$('::', 'File').$join($$($nesting, 'ROOT_DIR'), "lib")); - Opal.const_set($nesting[0], 'DATA_DIR', $$$('::', 'File').$join($$($nesting, 'ROOT_DIR'), "data")); - Opal.const_set($nesting[0], 'USER_HOME', (function() { try { - return $$$('::', 'Dir').$home() - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'StandardError')])) { - try { - - return ($truthy($b = $$$('::', 'ENV')['$[]']("HOME")) ? $b : $$$('::', 'Dir').$pwd()); - } finally { Opal.pop_exception() } - } else { throw $err; } - }})()); - Opal.const_set($nesting[0], 'LF', "\n"); - Opal.const_set($nesting[0], 'NULL', "\u0000"); - Opal.const_set($nesting[0], 'TAB', "\t"); - Opal.const_set($nesting[0], 'MAX_INT', 9007199254740991); - Opal.const_set($nesting[0], 'UTF_8', $$$($$$('::', 'Encoding'), 'UTF_8')); - Opal.const_set($nesting[0], 'BOM_BYTES_UTF_8', [239, 187, 191]); - Opal.const_set($nesting[0], 'BOM_BYTES_UTF_16LE', [255, 254]); - Opal.const_set($nesting[0], 'BOM_BYTES_UTF_16BE', [254, 255]); - Opal.const_set($nesting[0], 'FILE_READ_MODE', (function() {if ($truthy($$($nesting, 'RUBY_ENGINE_OPAL'))) { - return "r" - } else { - return "rb:utf-8:utf-8" - }; return nil; })()); - Opal.const_set($nesting[0], 'URI_READ_MODE', $$($nesting, 'FILE_READ_MODE')); - Opal.const_set($nesting[0], 'FILE_WRITE_MODE', (function() {if ($truthy($$($nesting, 'RUBY_ENGINE_OPAL'))) { - return "w" - } else { - return "w:utf-8" - }; return nil; })()); - Opal.const_set($nesting[0], 'DEFAULT_DOCTYPE', "article"); - Opal.const_set($nesting[0], 'DEFAULT_BACKEND', "html5"); - Opal.const_set($nesting[0], 'DEFAULT_STYLESHEET_KEYS', ["", "DEFAULT"].$to_set()); - Opal.const_set($nesting[0], 'DEFAULT_STYLESHEET_NAME', "asciidoctor.css"); - Opal.const_set($nesting[0], 'BACKEND_ALIASES', $hash2(["html", "docbook"], {"html": "html5", "docbook": "docbook5"})); - Opal.const_set($nesting[0], 'DEFAULT_PAGE_WIDTHS', $hash2(["docbook"], {"docbook": 425})); - Opal.const_set($nesting[0], 'DEFAULT_EXTENSIONS', $hash2(["html", "docbook", "pdf", "epub", "manpage", "asciidoc"], {"html": ".html", "docbook": ".xml", "pdf": ".pdf", "epub": ".epub", "manpage": ".man", "asciidoc": ".adoc"})); - Opal.const_set($nesting[0], 'ASCIIDOC_EXTENSIONS', $hash2([".adoc", ".asciidoc", ".asc", ".ad", ".txt"], {".adoc": true, ".asciidoc": true, ".asc": true, ".ad": true, ".txt": true})); - Opal.const_set($nesting[0], 'SETEXT_SECTION_LEVELS', $hash2(["=", "-", "~", "^", "+"], {"=": 0, "-": 1, "~": 2, "^": 3, "+": 4})); - Opal.const_set($nesting[0], 'ADMONITION_STYLES', ["NOTE", "TIP", "IMPORTANT", "WARNING", "CAUTION"].$to_set()); - Opal.const_set($nesting[0], 'ADMONITION_STYLE_HEADS', $send($$$('::', 'Set').$new(), 'tap', [], ($Asciidoctor$7 = function(accum){var self = $Asciidoctor$7.$$s || this, $$8; - - - - if (accum == null) { - accum = nil; - }; - return $send($$($nesting, 'ADMONITION_STYLES'), 'each', [], ($$8 = function(s){var self = $$8.$$s || this; + /** + * Private methods + */ - - - if (s == null) { - s = nil; - }; - return accum['$<<'](s.$chr());}, $$8.$$s = self, $$8.$$arity = 1, $$8));}, $Asciidoctor$7.$$s = self, $Asciidoctor$7.$$arity = 1, $Asciidoctor$7))); - Opal.const_set($nesting[0], 'PARAGRAPH_STYLES', ["comment", "example", "literal", "listing", "normal", "open", "pass", "quote", "sidebar", "source", "verse", "abstract", "partintro"].$to_set()); - Opal.const_set($nesting[0], 'VERBATIM_STYLES', ["literal", "listing", "source", "verse"].$to_set()); - Opal.const_set($nesting[0], 'DELIMITED_BLOCKS', $hash2(["--", "----", "....", "====", "****", "____", "++++", "|===", ",===", ":===", "!===", "////", "```"], {"--": ["open", ["comment", "example", "literal", "listing", "pass", "quote", "sidebar", "source", "verse", "admonition", "abstract", "partintro"].$to_set()], "----": ["listing", ["literal", "source"].$to_set()], "....": ["literal", ["listing", "source"].$to_set()], "====": ["example", ["admonition"].$to_set()], "****": ["sidebar", $$$('::', 'Set').$new()], "____": ["quote", ["verse"].$to_set()], "++++": ["pass", ["stem", "latexmath", "asciimath"].$to_set()], "|===": ["table", $$$('::', 'Set').$new()], ",===": ["table", $$$('::', 'Set').$new()], ":===": ["table", $$$('::', 'Set').$new()], "!===": ["table", $$$('::', 'Set').$new()], "////": ["comment", $$$('::', 'Set').$new()], "```": ["fenced_code", $$$('::', 'Set').$new()]})); - Opal.const_set($nesting[0], 'DELIMITED_BLOCK_HEADS', $send($hash2([], {}), 'tap', [], ($Asciidoctor$9 = function(accum){var self = $Asciidoctor$9.$$s || this, $$10; + /** + * Check if the specified header is allowed. + * + * @param header - {string} Header to validate + * @return {boolean} - False if not allowed, otherwise true + */ + const isAllowedHttpHeader = function (header) { + return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1) + } - - - if (accum == null) { - accum = nil; - }; - return $send($$($nesting, 'DELIMITED_BLOCKS'), 'each_key', [], ($$10 = function(k){var self = $$10.$$s || this, $writer = nil; + /** + * Check if the specified method is allowed. + * + * @param method - {string} Request method to validate + * @return {boolean} - False if not allowed, otherwise true + */ + const isAllowedHttpMethod = function (method) { + return (method && forbiddenRequestMethods.indexOf(method) === -1) + } - - - if (k == null) { - k = nil; - }; - $writer = [k.$slice(0, 2), true]; - $send(accum, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$10.$$s = self, $$10.$$arity = 1, $$10));}, $Asciidoctor$9.$$s = self, $Asciidoctor$9.$$arity = 1, $Asciidoctor$9))); - Opal.const_set($nesting[0], 'DELIMITED_BLOCK_TAILS', $send($hash2([], {}), 'tap', [], ($Asciidoctor$11 = function(accum){var self = $Asciidoctor$11.$$s || this, $$12; + /** + * Public methods + */ - - - if (accum == null) { - accum = nil; - }; - return $send($$($nesting, 'DELIMITED_BLOCKS'), 'each_key', [], ($$12 = function(k){var self = $$12.$$s || this, $writer = nil; + /** + * Open the connection. Currently supports local server requests. + * + * @param method - {string} Connection method (eg GET, POST) + * @param url - {string} URL for the connection. + * @param async - {boolean} Asynchronous connection. Default is true. + * @param [user] - {string} Username for basic authentication (optional) + * @param [password] - {string} Password for basic authentication (optional) + */ + this.open = function (method, url, async, user, password) { + this.abort() + errorFlag = false - - - if (k == null) { - k = nil; - }; - if (k.$length()['$=='](4)) { - - $writer = [k, k['$[]']($rb_minus(k.$length(), 1))]; - $send(accum, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - } else { - return nil - };}, $$12.$$s = self, $$12.$$arity = 1, $$12));}, $Asciidoctor$11.$$s = self, $Asciidoctor$11.$$arity = 1, $Asciidoctor$11))); - Opal.const_set($nesting[0], 'CAPTION_ATTRIBUTE_NAMES', $hash2(["example", "figure", "listing", "table"], {"example": "example-caption", "figure": "figure-caption", "listing": "listing-caption", "table": "table-caption"})); - Opal.const_set($nesting[0], 'LAYOUT_BREAK_CHARS', $hash2(["'", "<"], {"'": "thematic_break", "<": "page_break"})); - Opal.const_set($nesting[0], 'MARKDOWN_THEMATIC_BREAK_CHARS', $hash2(["-", "*", "_"], {"-": "thematic_break", "*": "thematic_break", "_": "thematic_break"})); - Opal.const_set($nesting[0], 'HYBRID_LAYOUT_BREAK_CHARS', $$($nesting, 'LAYOUT_BREAK_CHARS').$merge($$($nesting, 'MARKDOWN_THEMATIC_BREAK_CHARS'))); - Opal.const_set($nesting[0], 'NESTABLE_LIST_CONTEXTS', ["ulist", "olist", "dlist"]); - Opal.const_set($nesting[0], 'ORDERED_LIST_STYLES', ["arabic", "loweralpha", "lowerroman", "upperalpha", "upperroman"]); - Opal.const_set($nesting[0], 'ORDERED_LIST_KEYWORDS', $hash2(["loweralpha", "lowerroman", "upperalpha", "upperroman"], {"loweralpha": "a", "lowerroman": "i", "upperalpha": "A", "upperroman": "I"})); - Opal.const_set($nesting[0], 'ATTR_REF_HEAD', "{"); - Opal.const_set($nesting[0], 'LIST_CONTINUATION', "+"); - Opal.const_set($nesting[0], 'HARD_LINE_BREAK', " +"); - Opal.const_set($nesting[0], 'LINE_CONTINUATION', " \\"); - Opal.const_set($nesting[0], 'LINE_CONTINUATION_LEGACY', " +"); - Opal.const_set($nesting[0], 'BLOCK_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\[", "\\]"]})); - Opal.const_set($nesting[0], 'INLINE_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]})); - - $writer = ["asciimath"]; - $send(Opal.const_set($nesting[0], 'STEM_TYPE_ALIASES', $hash2(["latexmath", "latex", "tex"], {"latexmath": "latexmath", "latex": "latexmath", "tex": "latexmath"})), 'default=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - Opal.const_set($nesting[0], 'FONT_AWESOME_VERSION', "4.7.0"); - Opal.const_set($nesting[0], 'HIGHLIGHT_JS_VERSION', "9.18.3"); - Opal.const_set($nesting[0], 'MATHJAX_VERSION', "2.7.9"); - Opal.const_set($nesting[0], 'DEFAULT_ATTRIBUTES', $hash2(["appendix-caption", "appendix-refsig", "caution-caption", "chapter-refsig", "example-caption", "figure-caption", "important-caption", "last-update-label", "note-caption", "part-refsig", "prewrap", "sectids", "section-refsig", "table-caption", "tip-caption", "toc-placement", "toc-title", "untitled-label", "version-label", "warning-caption"], {"appendix-caption": "Appendix", "appendix-refsig": "Appendix", "caution-caption": "Caution", "chapter-refsig": "Chapter", "example-caption": "Example", "figure-caption": "Figure", "important-caption": "Important", "last-update-label": "Last updated", "note-caption": "Note", "part-refsig": "Part", "prewrap": "", "sectids": "", "section-refsig": "Section", "table-caption": "Table", "tip-caption": "Tip", "toc-placement": "auto", "toc-title": "Table of Contents", "untitled-label": "Untitled", "version-label": "Version", "warning-caption": "Warning"})); - Opal.const_set($nesting[0], 'FLEXIBLE_ATTRIBUTES', ["sectnums"]); - Opal.const_set($nesting[0], 'INTRINSIC_ATTRIBUTES', $hash2(["startsb", "endsb", "vbar", "caret", "asterisk", "tilde", "plus", "backslash", "backtick", "blank", "empty", "sp", "two-colons", "two-semicolons", "nbsp", "deg", "zwsp", "quot", "apos", "lsquo", "rsquo", "ldquo", "rdquo", "wj", "brvbar", "pp", "cpp", "amp", "lt", "gt"], {"startsb": "[", "endsb": "]", "vbar": "|", "caret": "^", "asterisk": "*", "tilde": "~", "plus": "+", "backslash": "\\", "backtick": "`", "blank": "", "empty": "", "sp": " ", "two-colons": "::", "two-semicolons": ";;", "nbsp": " ", "deg": "°", "zwsp": "​", "quot": """, "apos": "'", "lsquo": "‘", "rsquo": "’", "ldquo": "“", "rdquo": "”", "wj": "⁠", "brvbar": "¦", "pp": "++", "cpp": "C++", "amp": "&", "lt": "<", "gt": ">"})); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - } else { - nil - }; - Opal.const_set($nesting[0], 'QUOTE_SUBS', $send($hash2([], {}), 'tap', [], ($Asciidoctor$13 = function(accum){var self = $Asciidoctor$13.$$s || this, normal = nil, compat = nil; + // Check for valid request method + if (!isAllowedHttpMethod(method)) { + throw new Error('SecurityError: Request method not allowed') + } - - - if (accum == null) { - accum = nil; - }; - - $writer = [false, (normal = [["strong", "unconstrained", new RegExp("" + "\\\\?(?:\\[([^\\]]+)\\])?\\*\\*(" + ($$($nesting, 'CC_ALL')) + "+?)\\*\\*", 'm')], ["strong", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?\\*(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)\\*(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')], ["double", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?\"`(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)`\"(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')], ["single", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:`}])(?:\\[([^\\]]+)\\])?'`(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)`'(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')], ["monospaced", "unconstrained", new RegExp("" + "\\\\?(?:\\[([^\\]]+)\\])?``(" + ($$($nesting, 'CC_ALL')) + "+?)``", 'm')], ["monospaced", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:\"'`}])(?:\\[([^\\]]+)\\])?`(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)`(?![" + ($$($nesting, 'CC_WORD')) + "\"'`])", 'm')], ["emphasis", "unconstrained", new RegExp("" + "\\\\?(?:\\[([^\\]]+)\\])?__(" + ($$($nesting, 'CC_ALL')) + "+?)__", 'm')], ["emphasis", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?_(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)_(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')], ["mark", "unconstrained", new RegExp("" + "\\\\?(?:\\[([^\\]]+)\\])?##(" + ($$($nesting, 'CC_ALL')) + "+?)##", 'm')], ["mark", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + "&;:}])(?:\\[([^\\]]+)\\])?#(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)#(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')], ["superscript", "unconstrained", /\\?(?:\[([^\]]+)\])?\^(\S+?)\^/], ["subscript", "unconstrained", /\\?(?:\[([^\]]+)\])?~(\S+?)~/]])]; - $send(accum, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [true, (compat = normal.$drop(0))]; - $send(accum, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [2, ["double", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?``(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)''(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')]]; - $send(compat, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [3, ["single", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?`(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)'(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')]]; - $send(compat, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [4, ["monospaced", "unconstrained", new RegExp("" + "\\\\?(?:\\[([^\\]]+)\\])?\\+\\+(" + ($$($nesting, 'CC_ALL')) + "+?)\\+\\+", 'm')]]; - $send(compat, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [5, ["monospaced", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?\\+(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)\\+(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')]]; - $send(compat, '[]=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - return compat.$insert(3, ["emphasis", "constrained", new RegExp("" + "(^|[^" + ($$($nesting, 'CC_WORD')) + ";:}])(?:\\[([^\\]]+)\\])?'(\\S|\\S" + ($$($nesting, 'CC_ALL')) + "*?\\S)'(?!" + ($$($nesting, 'CG_WORD')) + ")", 'm')]);}, $Asciidoctor$13.$$s = self, $Asciidoctor$13.$$arity = 1, $Asciidoctor$13))); - Opal.const_set($nesting[0], 'REPLACEMENTS', [[/\\?\(C\)/, "©", "none"], [/\\?\(R\)/, "®", "none"], [/\\?\(TM\)/, "™", "none"], [/(?: |\n|^|\\)--(?: |\n|$)/, " — ", "none"], [new RegExp("" + "(" + ($$($nesting, 'CG_WORD')) + ")\\\\?--(?=" + ($$($nesting, 'CG_WORD')) + ")"), "—​", "leading"], [/\\?\.\.\./, "…​", "none"], [/\\?`'/, "’", "none"], [new RegExp("" + "(" + ($$($nesting, 'CG_ALNUM')) + ")\\\\?'(?=" + ($$($nesting, 'CG_ALPHA')) + ")"), "’", "leading"], [/\\?->/, "→", "none"], [/\\?=>/, "⇒", "none"], [/\\?<-/, "←", "none"], [/\\?<=/, "⇐", "none"], [/\\?(&)amp;((?:[a-zA-Z][a-zA-Z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-fA-F][\da-fA-F][\da-fA-F]{0,3});)/, "", "bounding"]]); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - } else { - nil - }; - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - } else { - nil - }; - })($nesting[0], $nesting); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/core_ext"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/helpers"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/logging"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/rx"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/substitutors"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/version"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_node"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_block"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/attribute_list"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/block"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/callouts"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/converter"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/document"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/inline"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/list"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/parser"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/path_resolver"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/reader"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/section"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/stylesheets"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/table"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/writer"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/load"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/convert"); - if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/syntax_highlighter"); - self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/timings"); - return self.$require("asciidoctor/js/postscript"); - } else { - return nil - }; -})(Opal); + settings = { + method: method, + url: url.toString(), + async: (typeof async !== 'boolean' ? true : async), + user: user || null, + password: password || null + } + + setState(this.OPENED) + } + + /** + * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. + * This does not conform to the W3C spec. + * + * @param state - {boolean} Enable or disable header checking. + */ + this.setDisableHeaderCheck = function (state) { + disableHeaderCheck = state + } + /** + * Sets a header for the request or appends the value if one is already set. + * + * @param header - {string} Header name + * @param value - {string} Header value + */ + this.setRequestHeader = function (header, value) { + if (this.readyState !== this.OPENED) { + throw new Error('INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN') + } + if (!isAllowedHttpHeader(header)) { + console.warn('Refused to set unsafe header "' + header + '"') + return + } + if (sendFlag) { + throw new Error('INVALID_STATE_ERR: send flag is true') + } + header = headersCase[header.toLowerCase()] || header + headersCase[header.toLowerCase()] = header + headers[header] = headers[header] ? headers[header] + ', ' + value : value + } -/* global Opal */ + /** + * Gets a header from the server response. + * + * @param header - {string} Name of header to get. + * @return {Object} - Text of the header or null if it doesn't exist. + */ + this.getResponseHeader = function (header) { + if (typeof header === 'string' && + this.readyState > this.OPENED && + response && + response.headers && + response.headers[header.toLowerCase()] && + !errorFlag + ) { + return response.headers[header.toLowerCase()] + } -/** - * Convert a JSON to an (Opal) Hash. - * @private - */ -var toHash = function (object) { - return object && !object.$$is_hash ? Opal.hash2(Object.keys(object), object) : object -} + return null + } -/** - * Convert an (Opal) Hash to JSON. - * @private - */ -var fromHash = function (hash) { - var object = {} - if (hash) { - var stringMap = hash.$$smap - for (var stringMapKey in stringMap) { - var stringMapValue = stringMap[stringMapKey] - object[stringMapKey] = stringMapValue === Opal.nil ? undefined : stringMapValue + /** + * Gets all the response headers. + * + * @return string A string with all response headers separated by CR+LF + */ + this.getAllResponseHeaders = function () { + if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { + return '' } - var numericMap = hash.$$map - if (numericMap) { - var positional = [] - for (var numericMapKey in numericMap) { - var entry = numericMap[numericMapKey] - var numericMapValue = entry.value - var index = entry.key - 1 - positional[index] = numericMapValue === Opal.nil ? undefined : numericMapValue - } - if (positional.length > 0) { - object.$positional = positional + let result = '' + + for (const i in response.headers) { + // Cookie headers are excluded + if (i !== 'set-cookie' && i !== 'set-cookie2') { + result += i + ': ' + response.headers[i] + '\r\n' } } + return result.substr(0, result.length - 2) } - return object -} -var fromHashKeys = function (hash) { - var object = {} - if (hash) { - var data = hash.$$keys - for (var key in data) { - var value = data[key].value - object[key.toString()] = value === Opal.nil ? undefined : value + /** + * Gets a request header + * + * @param name - {string} Name of header to get + * @return {string} Returns the request header or empty string if not set + */ + this.getRequestHeader = function (name) { + if (typeof name === 'string' && headersCase[name.toLowerCase()]) { + return headers[headersCase[name.toLowerCase()]] } + + return '' } - return object -} -/** - * @private - */ -var prepareOptions = function (options) { - options = toHash(options) - if (options) { - var attrs = options['$[]']('attributes') - if (attrs && typeof attrs === 'object' && attrs.constructor.name === 'Object') { - options = options.$dup() - options['$[]=']('attributes', toHash(attrs)) + /** + * Sends the request to the server. + * + * @param data - {string} Optional data to send as request body. + */ + this.send = function (data) { + if (this.readyState !== this.OPENED) { + throw new Error('INVALID_STATE_ERR: connection must be opened before send() is called') } - } - return options -} -function initializeClass (superClass, className, functions, defaultFunctions, argProxyFunctions) { - var scope = Opal.klass(Opal.Object, superClass, className, function () { }) - var postConstructFunction - var initializeFunction - var constructorFunction - var defaultFunctionsOverridden = {} - for (var functionName in functions) { - if (Object.prototype.hasOwnProperty.call(functions, functionName)) { - (function (functionName) { - var userFunction = functions[functionName] - if (functionName === 'postConstruct') { - postConstructFunction = userFunction - } else if (functionName === 'initialize') { - initializeFunction = userFunction - } else if (functionName === 'constructor') { - constructorFunction = userFunction - } else { - if (defaultFunctions && Object.prototype.hasOwnProperty.call(defaultFunctions, functionName)) { - defaultFunctionsOverridden[functionName] = true - } - Opal.def(scope, '$' + functionName, function () { - var args - if (argProxyFunctions && Object.prototype.hasOwnProperty.call(argProxyFunctions, functionName)) { - args = argProxyFunctions[functionName](arguments) - } else { - args = arguments - } - return userFunction.apply(this, args) - }) - } - }(functionName)) + if (sendFlag) { + throw new Error('INVALID_STATE_ERR: send has already been called') } - } - var initialize - if (typeof constructorFunction === 'function') { - initialize = function () { - var args = Array.from(arguments) - for (var i = 0; i < args.length; i++) { - // convert all (Opal) Hash arguments to JSON. - if (typeof args[i] === 'object' && '$$smap' in args[i]) { - args[i] = fromHash(args[i]) - } - } - args.unshift(null) - var result = new (Function.prototype.bind.apply(constructorFunction, args)) // eslint-disable-line - Object.assign(this, result) - if (typeof postConstructFunction === 'function') { - postConstructFunction.bind(this)() - } + let ssl = false + let local = false + const url = new Url.URL(settings.url) + let host + // Determine the server + switch (url.protocol) { + case 'https:': + ssl = true + host = url.hostname + break + case 'http:': + host = url.hostname + break + case 'file:': + local = true + break + case undefined: + case null: + case '': + host = 'localhost' + break + default: + throw new Error('Protocol not supported.') } - } else if (typeof initializeFunction === 'function') { - initialize = function () { - var args = Array.from(arguments) - for (var i = 0; i < args.length; i++) { - // convert all (Opal) Hash arguments to JSON. - if (typeof args[i] === 'object' && '$$smap' in args[i]) { - args[i] = fromHash(args[i]) - } + + // Load files off the local filesystem (file://) + if (local) { + if (settings.method !== 'GET') { + throw new Error('XMLHttpRequest: Only GET method is supported') } - initializeFunction.apply(this, args) - if (typeof postConstructFunction === 'function') { - postConstructFunction.bind(this)() + if (settings.async) { + fs.readFile(url, 'utf8', function (error, data) { + if (error) { + self.handleError(error, url) + } else { + self.status = 200 + self.responseText = data + setState(self.DONE) + } + }) + } else { + try { + this.responseText = fs.readFileSync(url, 'utf8') + this.status = 200 + setState(self.DONE) + } catch (e) { + this.handleError(e, url) + } } + + return } - } else { - initialize = function () { - Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize)) - if (typeof postConstructFunction === 'function') { - postConstructFunction.bind(this)() + + // Default to port 80. If accessing localhost on another port be sure + // to use http://localhost:port/path + const port = url.port || (ssl ? 443 : 80) + // Add query string if one is used + const uri = url.pathname + (url.search ? url.search : '') + + // Set the defaults if they haven't been set + for (const name in defaultHeaders) { + if (!headersCase[name.toLowerCase()]) { + headers[name] = defaultHeaders[name] } } - } - Opal.def(scope, '$initialize', initialize) - Opal.def(scope, 'super', function (func) { - if (typeof func === 'function') { - Opal.send(this, Opal.find_super_dispatcher(this, func.name, func)) - } else { - // Bind the initialize function to super(); - var argumentsList = Array.from(arguments) - for (var i = 0; i < argumentsList.length; i++) { - // convert all (Opal) Hash arguments to JSON. - if (typeof argumentsList[i] === 'object') { - argumentsList[i] = toHash(argumentsList[i]) - } + + // Set the Host header or the server may reject the request + headers.Host = host + // IPv6 addresses must be escaped with brackets + if (url.host[0] === '[') { + headers.Host = '[' + headers.Host + ']' + } + if (!((ssl && port === 443) || port === 80)) { + headers.Host += ':' + url.port + } + + // Set Basic Auth if necessary + if (settings.user) { + if (typeof settings.password === 'undefined') { + settings.password = '' } - Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), argumentsList) + const authBuf = Buffer.from(settings.user + ':' + settings.password) + headers.Authorization = 'Basic ' + authBuf.toString('base64') } - }) - if (defaultFunctions) { - for (var defaultFunctionName in defaultFunctions) { - if (Object.prototype.hasOwnProperty.call(defaultFunctions, defaultFunctionName) && !Object.prototype.hasOwnProperty.call(defaultFunctionsOverridden, defaultFunctionName)) { - (function (defaultFunctionName) { - var defaultFunction = defaultFunctions[defaultFunctionName] - Opal.def(scope, '$' + defaultFunctionName, function () { - return defaultFunction.apply(this, arguments) - }) - }(defaultFunctionName)) + + // Set content length header + if (settings.method === 'GET' || settings.method === 'HEAD') { + data = null + } else if (data) { + headers['Content-Length'] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data) + + if (!this.getRequestHeader('Content-Type')) { + headers['Content-Type'] = 'text/plain;charset=UTF-8' } + } else if (settings.method === 'POST') { + // For a post with no data set Content-Length: 0. + // This is required by buggy servers that don't meet the specs. + headers['Content-Length'] = 0 } - } - return scope -} -// Asciidoctor API + const options = { + host: host, + port: port, + path: uri, + method: settings.method, + headers: headers, + agent: false, + withCredentials: self.withCredentials + } -/** - * @namespace - * @description - * The main application interface (API) for Asciidoctor. - * This API provides methods to parse AsciiDoc content and convert it to various output formats using built-in or third-party converters. - * - * An AsciiDoc document can be as simple as a single line of content, - * though it more commonly starts with a document header that declares the document title and document attribute definitions. - * The document header is then followed by zero or more section titles, optionally nested, to organize the paragraphs, blocks, lists, etc. of the document. - * - * By default, the processor converts the AsciiDoc document to HTML 5 using a built-in converter. - * However, this behavior can be changed by specifying a different backend (e.g., +docbook+). - * A backend is a keyword for an output format (e.g., DocBook). - * That keyword, in turn, is used to select a converter, which carries out the request to convert the document to that format. - * - * @example - * asciidoctor.convertFile('document.adoc', { 'safe': 'safe' }) // Convert an AsciiDoc file - * - * asciidoctor.convert("I'm using *Asciidoctor* version {asciidoctor-version}.", { 'safe': 'safe' }) // Convert an AsciiDoc string - * - * const doc = asciidoctor.loadFile('document.adoc', { 'safe': 'safe' }) // Parse an AsciiDoc file into a document object - * - * const doc = asciidoctor.load("= Document Title\n\nfirst paragraph\n\nsecond paragraph", { 'safe': 'safe' }) // Parse an AsciiDoc string into a document object - */ -var Asciidoctor = Opal.Asciidoctor.$$class + const responseType = this.responseType || 'text' -/** - * Get Asciidoctor core version number. - * - * @returns {string} - the version number of Asciidoctor core. - * @memberof Asciidoctor - */ -Asciidoctor.prototype.getCoreVersion = function () { - return this.$$const.VERSION -} + // Reset error flag + errorFlag = false -/** - * Get Asciidoctor.js runtime environment information. - * - * @returns {Object} - the runtime environment including the ioModule, the platform, the engine and the framework. - * @memberof Asciidoctor - */ -Asciidoctor.prototype.getRuntime = function () { - return { - ioModule: Opal.const_get_qualified('::', 'JAVASCRIPT_IO_MODULE'), - platform: Opal.const_get_qualified('::', 'JAVASCRIPT_PLATFORM'), - engine: Opal.const_get_qualified('::', 'JAVASCRIPT_ENGINE'), - framework: Opal.const_get_qualified('::', 'JAVASCRIPT_FRAMEWORK') - } -} + // Handle async requests + if (settings.async) { + // Use the proper protocol + const doRequest = ssl ? https.request : http.request -/** - * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format. - * - * Accepts input as a Buffer or String. - * - * @param {string|Buffer} input - AsciiDoc input as String or Buffer - * @param {Object} options - a JSON of options to control processing (default: {}) - * @returns {string|Document} - the {@link Document} object if the converted String is written to a file, - * otherwise the converted String - * @example - * var input = '= Hello, AsciiDoc!\n' + - * 'Guillaume Grossetie <ggrossetie@example.com>\n\n' + - * 'An introduction to http://asciidoc.org[AsciiDoc].\n\n' + - * '== First Section\n\n' + - * '* item 1\n' + - * '* item 2\n'; - * - * var html = asciidoctor.convert(input); - * @memberof Asciidoctor - */ -Asciidoctor.prototype.convert = function (input, options) { - if (typeof input === 'object' && input.constructor.name === 'Buffer') { - input = input.toString('utf8') - } - var result = this.$convert(input, prepareOptions(options)) - return result === Opal.nil ? '' : result -} + // Request is being sent, set send flag + sendFlag = true -/** - * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format. - * - * @param {string} filename - source filename - * @param {Object} options - a JSON of options to control processing (default: {}) - * @returns {string|Document} - the {@link Document} object if the converted String is written to a file, - * otherwise the converted String - * @example - * var html = asciidoctor.convertFile('./document.adoc'); - * @memberof Asciidoctor - */ -Asciidoctor.prototype.convertFile = function (filename, options) { - return this.$convert_file(filename, prepareOptions(options)) -} + // As per spec, this is called here for historical reasons. + self.dispatchEvent('readystatechange') -/** - * Parse the AsciiDoc source input into an {@link Document} - * - * Accepts input as a Buffer or String. - * - * @param {string|Buffer} input - AsciiDoc input as String or Buffer - * @param {Object} options - a JSON of options to control processing (default: {}) - * @returns {Document} - the {@link Document} object - * @memberof Asciidoctor - */ -Asciidoctor.prototype.load = function (input, options) { - if (typeof input === 'object' && input.constructor.name === 'Buffer') { - input = input.toString('utf8') - } - return this.$load(input, prepareOptions(options)) -} + // Handler for the response + const responseHandler = function responseHandler (resp) { + // Set response var to the response we got back + // This is so it remains accessable outside this scope + response = resp + // Check for redirect + // @TODO Prevent looped redirects + if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { + // Change URL to the redirect location + settings.url = response.headers.location + const url = new Url.URL(settings.url) + // Set host var in case it's used later + host = url.hostname + // Options for the new request + const newOptions = { + hostname: url.hostname, + port: url.port, + path: url.path, + method: response.statusCode === 303 ? 'GET' : settings.method, + headers: headers, + withCredentials: self.withCredentials + } -/** - * Parse the contents of the AsciiDoc source file into an {@link Document} - * - * @param {string} filename - source filename - * @param {Object} options - a JSON of options to control processing (default: {}) - * @returns {Document} - the {@link Document} object - * @memberof Asciidoctor - */ -Asciidoctor.prototype.loadFile = function (filename, options) { - return this.$load_file(filename, prepareOptions(options)) -} + // Issue the new request + request = doRequest(newOptions, responseHandler).on('error', errorHandler) + request.end() + // @TODO Check if an XHR event needs to be fired here + return + } -// AbstractBlock API + const encoding = responseType === 'text' ? 'utf8' : 'binary' + if (encoding === 'utf8') { + response.setEncoding('utf8') + } -/** - * @namespace - * @extends AbstractNode - */ -var AbstractBlock = Opal.Asciidoctor.AbstractBlock + setState(self.HEADERS_RECEIVED) + self.status = response.statusCode -/** - * Append a block to this block's list of child blocks. - * @param {AbstractBlock} block - the block to append - * @returns {AbstractBlock} - the parent block to which this block was appended. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.append = function (block) { - this.$append(block) - return this -} + if (encoding === 'utf8') { + response.on('data', function (chunk) { + // Make sure there's some data + if (chunk) { + self.responseText += chunk + } + // Don't emit state changes if the connection has been aborted. + if (sendFlag) { + setState(self.LOADING) + } + }) -/** - * Get the String title of this Block with title substitions applied - * - * The following substitutions are applied to block and section titles: - * - * <code>specialcharacters</code>, <code>quotes</code>, <code>replacements</code>, <code>macros</code>, <code>attributes</code> and <code>post_replacements</code> - * - * @returns {string} - the converted String title for this Block, or undefined if the title is not set. - * @example - * block.title // "Foo 3^ # {two-colons} Bar(1)" - * block.getTitle(); // "Foo 3^ # :: Bar(1)" - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getTitle = function () { - var title = this.$title() - return title === Opal.nil ? undefined : title -} + response.on('end', function () { + if (sendFlag) { + // Discard the end event if the connection has been aborted + setState(self.DONE) + sendFlag = false + } + }) + } else { + response.on('data', function (chunk) { + // Make sure there's some data + if (chunk) { + responseBinary.push(chunk) + } + // Don't emit state changes if the connection has been aborted. + if (sendFlag) { + setState(self.LOADING) + } + }) -/** - * Set the String block title. - * - * @param {string} title - The block title - * @returns {string} - the new String title assigned to this Block. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.setTitle = function (title) { - title = typeof title === 'undefined' ? Opal.nil : title - return this['$title='](title) -} + response.on('end', function () { + // buffers are Uint8Array instances + self.response = Buffer.concat(responseBinary).buffer + if (sendFlag) { + // Discard the end event if the connection has been aborted + setState(self.DONE) + sendFlag = false + } + }) + } -/** - * Generate and assign caption to block if not already assigned. - * - * If the block has a title and a caption prefix is available for this block, - * then build a caption from this information, assign it a number and store it - * to the caption attribute on the block. - * - * If a caption has already been assigned to this block, do nothing. - * - * The parts of a complete caption are: `<prefix> <number>. <title>` - * This partial caption represents the part the precedes the title. - * - * @param {string} value - the String caption to assign to this block or nil to use document attribute. - * @param {string} captionContext - the String context to use when resolving caption-related attributes. - * If not provided, the name of the context for this block is used. Only certain contexts allow the caption to be looked up. - * - * @memberof AbstractBlock - */ -AbstractBlock.prototype.assignCaption = function (value, captionContext) { - value = typeof value === 'undefined' ? Opal.nil : value - captionContext = typeof captionContext === 'undefined' ? null : captionContext - this.$assign_caption(value, captionContext) -} + response.on('error', function (error) { + self.handleError(error, url) + }) + } -/** - * Convenience method that returns the interpreted title of the Block - * with the caption prepended. - * Concatenates the value of this Block's caption instance variable and the - * return value of this Block's title method. No space is added between the - * two values. If the Block does not have a caption, the interpreted title is - * returned. - * - * @returns {string} - the converted String title prefixed with the caption, or just the converted String title if no caption is set - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getCaptionedTitle = function () { - return this.$captioned_title() -} + // Error handler for the request + const errorHandler = function errorHandler (error) { + self.handleError(error, url) + } + + // Create the request + request = doRequest(options, responseHandler).on('error', errorHandler) + + // Node 0.4 and later won't accept empty data. Make sure it's needed. + if (data) { + request.write(data) + } + + request.end() + + self.dispatchEvent('loadstart') + } else { // Synchronous + const maxBuffer = process.env.UNXHR_MAX_BUFFER + ? parseInt(process.env.UNXHR_MAX_BUFFER) + : DEFAULT_MAX_BUFFER + const encoding = responseType === 'text' ? 'utf8' : 'binary' + const scriptPath = __nccwpck_require__.ab + "request.js" + const output = (__nccwpck_require__(5317).execSync)(`"${process.execPath}" "${scriptPath}" \ +--ssl="${ssl}" \ +--encoding="${encoding}" \ +--request-options=${JSON.stringify(JSON.stringify(options))}`, { stdio: ['pipe', 'pipe', 'pipe'], input: data, maxBuffer: maxBuffer }) + const result = JSON.parse(output.toString('utf8')) + if (result.error) { + throw translateError(result.error, url) + } else { + response = result.data + self.status = result.data.statusCode + if (encoding === 'binary') { + self.response = Uint8Array.from(result.data.binary.data).buffer + } else { + self.responseText = result.data.text + } + setState(self.DONE) + } + } + } + + /** + * Called when an error is encountered to deal with it. + */ + this.handleError = function (error, url) { + this.status = 0 + this.statusText = '' + this.responseText = '' + errorFlag = true + setState(this.DONE) + this.dispatchEvent('error', { error: translateError(error, url) }) + } + + /** + * Aborts a request. + */ + this.abort = function () { + if (request) { + request.abort() + request = null + } + + headers = defaultHeaders + this.status = 0 + this.responseText = '' + this.responseXML = '' -/** - * Get the style (block type qualifier) for this block. - * - * @returns {string} - the style for this block - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getStyle = function () { - var style = this.style - return style === Opal.nil ? undefined : style -} + errorFlag = true -/** - * Set the style for this block. - * - * @param {string} style - Style - * @memberof AbstractBlock - */ -AbstractBlock.prototype.setStyle = function (style) { - this.style = style -} + if (this.readyState !== this.UNSENT && + (this.readyState !== this.OPENED || sendFlag) && + this.readyState !== this.DONE) { + sendFlag = false + setState(this.DONE) + } + this.readyState = this.UNSENT + this.dispatchEvent('abort') + } -/** - * Get the location in the AsciiDoc source where this block begins. - * - * @returns {string} - the style for this block - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getSourceLocation = function () { - var sourceLocation = this.source_location - if (sourceLocation === Opal.nil) { - return undefined + /** + * Adds an event listener. Preferred method of binding to events. + */ + this.addEventListener = function (event, callback) { + if (!(event in listeners)) { + listeners[event] = [] + } + // Currently allows duplicate callbacks. Should it? + listeners[event].push(callback) } - sourceLocation.getFile = function () { - var file = this.file - return file === Opal.nil ? undefined : file + + /** + * Remove an event callback that has already been bound. + * Only works on the matching funciton, cannot be a copy. + */ + this.removeEventListener = function (event, callback) { + if (event in listeners) { + // Filter will return a new array with the callback removed + listeners[event] = listeners[event].filter(function (ev) { + return ev !== callback + }) + } } - sourceLocation.getDirectory = function () { - var dir = this.dir - return dir === Opal.nil ? undefined : dir + + /** + * Dispatch any events, including both "on" methods and events attached using addEventListener. + */ + this.dispatchEvent = function (event, args) { + if (typeof self['on' + event] === 'function') { + self['on' + event](args) + } + if (event in listeners) { + for (let i = 0, len = listeners[event].length; i < len; i++) { + listeners[event][i].call(self, args) + } + } } - sourceLocation.getPath = function () { - var path = this.path - return path === Opal.nil ? undefined : path + + /** + * Changes readyState and calls onreadystatechange. + * + * @param state - {Number} New state + */ + const setState = function (state) { + if (state === self.LOADING || self.readyState !== state) { + self.readyState = state + + if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { + self.dispatchEvent('readystatechange') + } + + if (self.readyState === self.DONE && !errorFlag) { + self.dispatchEvent('load') + // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) + self.dispatchEvent('loadend') + } + } } - sourceLocation.getLineNumber = function () { - var lineno = this.lineno - return lineno === Opal.nil ? undefined : lineno + + const translateError = function (error, url) { + if (typeof error === 'object') { + if (error.code === 'ENOTFOUND' || error.code === 'EAI_AGAIN') { + // XMLHttpRequest throws a DOMException when DNS lookup fails: + // code: 19 + // message: "Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://url/'." + // name: "NetworkError" + // stack: (...) + return new Error(`Failed to execute 'send' on 'XMLHttpRequest': Failed to load '${url}'.`) + } + if (error instanceof Error) { + return error + } + return new Error(JSON.stringify(error)) + } + return new Error(error) } - return sourceLocation } -/** - * Get the caption for this block. - * - * @returns {string} - the caption for this block - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getCaption = function () { - var caption = this.$caption() - return caption === Opal.nil ? undefined : caption -} -/** - * Set the caption for this block. - * - * @param {string} caption - Caption - * @memberof AbstractBlock - */ -AbstractBlock.prototype.setCaption = function (caption) { - this.caption = typeof caption === 'undefined' ? Opal.nil : caption -} +/***/ }), -/** - * Get the level of this section or the section level in which this block resides. - * - * @returns {number} - the level (Integer) of this section - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getLevel = function () { - var level = this.level - return level === Opal.nil ? undefined : level -} +/***/ 8264: +/***/ ((module) => { -/** - * Get the substitution keywords to be applied to the contents of this block. - * - * @returns {Array<string>} - the list of {string} substitution keywords associated with this block. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getSubstitutions = function () { - return this.subs -} +// Returns a wrapper function that returns a wrapped callback +// The wrapper function should do some stuff, and return a +// presumably different callback function. +// This makes sure that own properties are retained, so that +// decorations and such are not lost along the way. +module.exports = wrappy +function wrappy (fn, cb) { + if (fn && cb) return wrappy(fn)(cb) -/** - * Check whether a given substitution keyword is present in the substitutions for this block. - * - * @returns {boolean} - whether the substitution is present on this block. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.hasSubstitution = function (substitution) { - return this['$sub?'](substitution) -} + if (typeof fn !== 'function') + throw new TypeError('need wrapper function') -/** - * Remove the specified substitution keyword from the list of substitutions for this block. - * - * @memberof AbstractBlock - */ -AbstractBlock.prototype.removeSubstitution = function (substitution) { - this.$remove_sub(substitution) -} + Object.keys(fn).forEach(function (k) { + wrapper[k] = fn[k] + }) -/** - * Checks if the {@link AbstractBlock} contains any child blocks. - * - * @returns {boolean} - whether the {@link AbstractBlock} has child blocks. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.hasBlocks = function () { - return this.blocks.length > 0 -} + return wrapper -/** - * Get the list of {@link AbstractBlock} sub-blocks for this block. - * - * @returns {Array<AbstractBlock>} - a list of {@link AbstractBlock} sub-blocks - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getBlocks = function () { - return this.blocks + function wrapper() { + var args = new Array(arguments.length) + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i] + } + var ret = fn.apply(this, args) + var cb = args[args.length-1] + if (typeof ret === 'function' && ret !== cb) { + Object.keys(cb).forEach(function (k) { + ret[k] = cb[k] + }) + } + return ret + } } -/** - * Get the converted result of the child blocks by converting the children appropriate to content model that this block supports. - * - * @returns {string} - the converted result of the child blocks - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getContent = function () { - return this.$content() -} -/** - * Get the converted content for this block. - * If the block has child blocks, the content method should cause them to be converted - * and returned as content that can be included in the parent block's template. - * - * @returns {string} - the converted String content for this block - * @memberof AbstractBlock - */ -AbstractBlock.prototype.convert = function () { - return this.$convert() -} +/***/ }), -/** - * Query for all descendant block-level nodes in the document tree - * that match the specified selector (context, style, id, and/or role). - * If a function block is given, it's used as an additional filter. - * If no selector or function block is supplied, all block-level nodes in the tree are returned. - * @param {Object} [selector] - * @param {function} [block] - * @example - * doc.findBy({'context': 'section'}); - * // => { level: 0, title: "Hello, AsciiDoc!", blocks: 0 } - * // => { level: 1, title: "First Section", blocks: 1 } - * - * doc.findBy({'context': 'section'}, function (section) { return section.getLevel() === 1; }); - * // => { level: 1, title: "First Section", blocks: 1 } - * - * doc.findBy({'context': 'listing', 'style': 'source'}); - * // => { context: :listing, content_model: :verbatim, style: "source", lines: 1 } - * - * @returns {Array<AbstractBlock>} - a list of block-level nodes that match the filter or an empty list if no matches are found - * @memberof AbstractBlock - */ -AbstractBlock.prototype.findBy = function (selector, block) { - if (typeof block === 'undefined' && typeof selector === 'function') { - return Opal.send(this, 'find_by', null, selector) - } else if (typeof block === 'function') { - return Opal.send(this, 'find_by', [toHash(selector)], block) - } else { - return this.$find_by(toHash(selector)) - } -} +/***/ 2613: +/***/ ((module) => { -/** - * Get the source line number where this block started. - * @returns {number} - the source line number where this block started - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getLineNumber = function () { - var lineno = this.$lineno() - return lineno === Opal.nil ? undefined : lineno -} +"use strict"; +module.exports = require("assert"); -/** - * Check whether this block has any child Section objects. - * Only applies to Document and Section instances. - * @returns {boolean} - true if this block has child Section objects, otherwise false - * @memberof AbstractBlock - */ -AbstractBlock.prototype.hasSections = function () { - // REMIND: call directly the underlying method "$sections?" - // once https://github.com/asciidoctor/asciidoctor/pull/3591 is merged and a new version is released. - // return this['$sections?']() - return this.next_section_index !== Opal.nil && this.next_section_index > 0 -} +/***/ }), -/** - * Get the Array of child Section objects. - * Only applies to Document and Section instances. - * @memberof AbstractBlock - * @returns {Array<Section>} - an {Array} of {@link Section} objects - */ -AbstractBlock.prototype.getSections = function () { - return this.$sections() -} +/***/ 5317: +/***/ ((module) => { -/** - * Get the numeral of this block (if section, relative to parent, otherwise absolute). - * Only assigned to section if automatic section numbering is enabled. - * Only assigned to formal block (block with title) if corresponding caption attribute is present. - * If the section is an appendix, the numeral is a letter (starting with A). - * @returns {string} - the numeral - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getNumeral = function () { - return this.$numeral() -} +"use strict"; +module.exports = require("child_process"); -/** - * Set the numeral of this block. - * @param {string} value - The numeral value - * @memberof AbstractBlock - */ -AbstractBlock.prototype.setNumeral = function (value) { - this['$numeral='](value) -} +/***/ }), -/** - * A convenience method that checks whether the title of this block is defined. - * - * @returns {boolean} - a {boolean} indicating whether this block has a title. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.hasTitle = function () { - return this['$title?']() -} +/***/ 4434: +/***/ ((module) => { -/** - * Returns the converted alt text for this block image. - * @returns {string} - the {string} value of the alt attribute with XML special character and replacement substitutions applied. - * @memberof AbstractBlock - */ -AbstractBlock.prototype.getAlt = function () { - return this.$alt() -} +"use strict"; +module.exports = require("events"); -// Section API +/***/ }), -/** - * @description - * Methods for managing sections of AsciiDoc content in a document. - * - * @example - * <pre> - * section = asciidoctor.Section.create() - * section.setTitle('Section 1') - * section.setId('sect1') - * section.getBlocks().length // 0 - * section.getId() // "sect1" - * section.append(newBlock) - * section.getBlocks().length // 1 - * </pre> - * @namespace - * @extends AbstractBlock - */ -var Section = Opal.Asciidoctor.Section +/***/ 9896: +/***/ ((module) => { -/** - * Create a {Section} object. - * @param {AbstractBlock} [parent] - The parent AbstractBlock. If set, must be a Document or Section object (default: undefined) - * @param {number} [level] - The Integer level of this section (default: 1 more than parent level or 1 if parent not defined) - * @param {boolean} [numbered] - A Boolean indicating whether numbering is enabled for this Section (default: false) - * @param {Object} [opts] - An optional JSON of options (default: {}) - * @returns {Section} - a new {Section} object - * @memberof Section - */ -Section.create = function (parent, level, numbered, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return this.$new(parent, level, numbered, toHash(opts)) -} +"use strict"; +module.exports = require("fs"); -/** - * Set the level of this section or the section level in which this block resides. - * @param {number} level - Level (Integer) - * @memberof AbstractBlock - */ -Section.prototype.setLevel = function (level) { - this.level = level -} +/***/ }), -/** - * Get the 0-based index order of this section within the parent block. - * @returns {number} - * @memberof Section - */ -Section.prototype.getIndex = function () { - return this.index -} +/***/ 8611: +/***/ ((module) => { -/** - * Set the 0-based index order of this section within the parent block. - * @param {string} index - The index order of this section - * @memberof Section - */ -Section.prototype.setIndex = function (index) { - this.index = index -} +"use strict"; +module.exports = require("http"); -/** - * Get the section name of this section. - * @returns {string|undefined} - * @memberof Section - */ -Section.prototype.getSectionName = function () { - var sectname = this.sectname - return sectname === Opal.nil ? undefined : sectname -} +/***/ }), -/** - * Set the section name of this section. - * @param {string} value - The section name - * @memberof Section - */ -Section.prototype.setSectionName = function (value) { - this.sectname = value -} +/***/ 5692: +/***/ ((module) => { -/** - * Get the flag to indicate whether this is a special section or a child of one. - * @returns {boolean} - * @memberof Section - */ -Section.prototype.isSpecial = function () { - return this.special -} +"use strict"; +module.exports = require("https"); -/** - * Set the flag to indicate whether this is a special section or a child of one. - * @param {boolean} value - A flag to indicated if this is a special section - * @memberof Section - */ -Section.prototype.setSpecial = function (value) { - this.special = value -} +/***/ }), -/** - * Get the state of the numbered attribute at this section (need to preserve for creating TOC). - * @returns {boolean} - * @memberof Section - */ -Section.prototype.isNumbered = function () { - return this.numbered -} +/***/ 3339: +/***/ ((module) => { -/** - * Get the caption for this section (only relevant for appendices). - * @returns {string} - * @memberof Section - */ -Section.prototype.getCaption = function () { - var value = this.caption - return value === Opal.nil ? undefined : value -} +"use strict"; +module.exports = require("module"); -/** - * Get the name of the Section (title) - * @returns {string} - * @see {@link AbstractBlock#getTitle} - * @memberof Section - */ -Section.prototype.getName = function () { - return this.getTitle() -} +/***/ }), -/** - * @description - * Methods for managing AsciiDoc content blocks. - * - * @example - * block = asciidoctor.Block.create(parent, 'paragraph', {source: '_This_ is a <test>'}) - * block.getContent() - * // "<em>This</em> is a <test>" - * - * @namespace - * @extends AbstractBlock - */ -var Block = Opal.Asciidoctor.Block +/***/ 857: +/***/ ((module) => { -/** - * Create a {Block} object. - * @param {AbstractBlock} parent - The parent {AbstractBlock} with a compound content model to which this {Block} will be appended. - * @param {string} context - The context name for the type of content (e.g., "paragraph"). - * @param {Object} [opts] - a JSON of options to customize block initialization: (default: {}) - * @param {string} opts.content_model - indicates whether blocks can be nested in this {Block} ("compound"), - * otherwise how the lines should be processed ("simple", "verbatim", "raw", "empty"). (default: "simple") - * @param {Object} opts.attributes - a JSON of attributes (key/value pairs) to assign to this {Block}. (default: {}) - * @param {string|Array<string>} opts.source - a String or {Array} of raw source for this {Block}. (default: undefined) - * - * IMPORTANT: If you don't specify the `subs` option, you must explicitly call the `commit_subs` method to resolve and assign the substitutions - * to this block (which are resolved from the `subs` attribute, if specified, or the default substitutions based on this block's context). - * If you want to use the default subs for a block, pass the option `subs: "default"`. - * You can override the default subs using the `default_subs` option. - * - * @returns {Block} - a new {Block} object - * @memberof Block - */ -Block.create = function (parent, context, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return this.$new(parent, context, toHash(opts)) -} +"use strict"; +module.exports = require("os"); + +/***/ }), + +/***/ 6928: +/***/ ((module) => { + +"use strict"; +module.exports = require("path"); + +/***/ }), + +/***/ 7016: +/***/ ((module) => { + +"use strict"; +module.exports = require("url"); + +/***/ }), + +/***/ 9023: +/***/ ((module) => { + +"use strict"; +module.exports = require("util"); + +/***/ }), + +/***/ 7695: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { -/** - * Get the source of this block. - * @returns {string} - the String source of this block. - * @memberof Block - */ -Block.prototype.getSource = function () { - return this.$source() -} +"use strict"; -/** - * Get the source lines of this block. - * @returns {Array<string>} - the String {Array} of source lines for this block. - * @memberof Block - */ -Block.prototype.getSourceLines = function () { - return this.lines -} -// AbstractNode API +var module$1 = __nccwpck_require__(3339); +var url = __nccwpck_require__(7016); +var path = __nccwpck_require__(6928); +var fs = __nccwpck_require__(9896); +var Opal = __nccwpck_require__(1066); +var unxhr = __nccwpck_require__(1833); -/** - * @namespace - * @description - * An abstract base class that provides state and methods for managing a node of AsciiDoc content. - * The state and methods on this class are common to all content segments in an AsciiDoc document. - */ -var AbstractNode = Opal.Asciidoctor.AbstractNode +var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; +/* global Asciidoctor, ASCIIDOCTOR_JS_VERSION */ -/** - * Apply the specified substitutions to the text. - * If no substitutions are specified, the following substitutions are applied: - * <code>specialcharacters</code>, <code>quotes</code>, <code>attributes</code>, <code>replacements</code>, <code>macros</code>, and <code>post_replacements</code>. - * - * @param {string|Array<string>} text - The String or String Array of text to process; must not be undefined. - * @param {Array<string>} [subs] - The substitutions to perform; must be an Array or undefined. - * @returns {string|Array<string>} - a String or String Array to match the type of the text argument with substitutions applied. - * @memberof AbstractNode - */ -AbstractNode.prototype.applySubstitutions = function (text, subs) { - return this.$apply_subs(text, subs) -} +const __path__ = path; +const __XMLHttpRequest__ = unxhr.XMLHttpRequest; +const __asciidoctorDistDir__ = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? (__nccwpck_require__(7016).pathToFileURL)(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('asciidoctor-node.cjs', document.baseURI).href)))); +const __require__ = module$1.createRequire((typeof document === 'undefined' ? (__nccwpck_require__(7016).pathToFileURL)(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('asciidoctor-node.cjs', document.baseURI).href))); -/** - * Resolve the list of comma-delimited subs against the possible options. - * - * @param {string} subs - The comma-delimited String of substitution names or aliases. - * @param {string} [type] - A String representing the context for which the subs are being resolved (default: 'block'). - * @param {Array<string>} [defaults] - An Array of substitutions to start with when computing incremental substitutions (default: undefined). - * @param {string} [subject] - The String to use in log messages to communicate the subject for which subs are being resolved (default: undefined) - * - * @returns {Array<string>} - An Array of Strings representing the substitution operation or nothing if no subs are found. - * @memberof AbstractNode - */ -AbstractNode.prototype.resolveSubstitutions = function (subs, type, defaults, subject) { - if (typeof type === 'undefined') { - type = 'block' - } - if (typeof defaults === 'undefined') { - defaults = Opal.nil +function asciidoctorNode (moduleConfig) { +Opal.modules["asciidoctor/js/opal_ext/electron/io"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $gvars = Opal.gvars, $send = Opal.send, $a, nil = Opal.nil; + if ($gvars.stdout == null) $gvars.stdout = nil; + if ($gvars.stderr == null) $gvars.stderr = nil; + + Opal.add_stubs('write_proc='); + + $gvars.stdout['$write_proc='](function(s){console.log(s);}); + return ($a = [function(s){console.error(s);}], $send($gvars.stderr, 'write_proc=', $a), $a[$a.length - 1]); +}; + +Opal.modules["asciidoctor/js/opal_ext/node"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $const_set = Opal.const_set, $eqeq = Opal.eqeq, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting); Opal.nil; + + Opal.add_stubs('==,require'); + + + var isElectron = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && typeof navigator.userAgent.indexOf('Electron') !== -1, + platform, + engine, + framework, + ioModule; + + if (typeof moduleConfig === 'object' && typeof moduleConfig.runtime === 'object') { + var runtime = moduleConfig.runtime; + platform = runtime.platform; + engine = runtime.engine; + framework = runtime.framework; + ioModule = runtime.ioModule; } - if (typeof subject === 'undefined') { - subject = Opal.nil + + ioModule = ioModule || 'node'; + platform = platform || 'node'; + engine = engine || 'v8'; + if (isElectron) { + framework = framework || 'electron'; + } else { + framework = framework || ''; } - const value = this.$resolve_subs(subs, type, defaults, subject) - return value === Opal.nil ? undefined : value -} + $const_set($nesting[0], 'JAVASCRIPT_IO_MODULE', ioModule); + $const_set($nesting[0], 'JAVASCRIPT_PLATFORM', platform); + $const_set($nesting[0], 'JAVASCRIPT_ENGINE', engine); + $const_set($nesting[0], 'JAVASCRIPT_FRAMEWORK', framework); + if ($eqeq($$('JAVASCRIPT_FRAMEWORK'), "electron")) { + self.$require("asciidoctor/js/opal_ext/electron/io"); + } +// Load Opal modules +Opal.load("pathname"); +Opal.load("nodejs"); +}; -/** - * Call {@link AbstractNode#resolveSubstitutions} for the 'block' type. - * - * @see {@link AbstractNode#resolveSubstitutions} - */ -AbstractNode.prototype.resolveBlockSubstitutions = function (subs, defaults, subject) { - return this.resolveSubstitutions(subs, 'block', defaults, subject) -} +Opal.modules["asciidoctor/js/asciidoctor_ext/node/abstract_node"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $nesting = []; Opal.nil; -/** - * Call {@link AbstractNode#resolveSubstitutions} for the 'inline' type with the subject set as passthrough macro. - * - * @see {@link AbstractNode#resolveSubstitutions} - */ -AbstractNode.prototype.resolvePassSubstitutions = function (subs) { - return this.resolveSubstitutions(subs, 'inline', undefined, 'passthrough macro') -} + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @returns {string} - the String name of this node - * @memberof AbstractNode - */ -AbstractNode.prototype.getNodeName = function () { - return this.node_name -} + var $nesting = [self].concat($parent_nesting); -/** - * @returns {Object} - the JSON of attributes for this node - * @memberof AbstractNode - */ -AbstractNode.prototype.getAttributes = function () { - return fromHash(this.attributes) -} + return (function($base, $super) { + var self = $klass($base, $super, 'AbstractNode'); -/** - * Get the value of the specified attribute. - * If the attribute is not found on this node, fallback_name is set, and this node is not the Document node, get the value of the specified attribute from the Document node. - * - * Look for the specified attribute in the attributes on this node and return the value of the attribute, if found. - * Otherwise, if fallback_name is set (default: same as name) and this node is not the Document node, look for that attribute on the Document node and return its value, if found. - * Otherwise, return the default value (default: undefined). - * - * @param {string} name - The String of the attribute to resolve. - * @param {*} [defaultValue] - The {Object} value to return if the attribute is not found (default: undefined). - * @param {string} [fallbackName] - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name). - * - * @returns {*} - the {Object} value (typically a String) of the attribute or defaultValue if the attribute is not found. - * @memberof AbstractNode - */ -AbstractNode.prototype.getAttribute = function (name, defaultValue, fallbackName) { - var value = this.$attr(name, defaultValue, fallbackName) - return value === Opal.nil ? undefined : value -} + + return $def(self, '$generate_data_uri_from_uri', function $$generate_data_uri_from_uri(image_uri, cache_uri) { + var self = this; + + var contentType = ''; + var b64encoded = ''; + var status = -1; -/** - * Check whether the specified attribute is present on this node. - * - * @param {string} name - The String of the attribute to resolve. - * @returns {boolean} - true if the attribute is present, otherwise false - * @memberof AbstractNode - */ -AbstractNode.prototype.hasAttribute = function (name) { - return name in this.attributes.$$smap -} + try { + var xhr = new __XMLHttpRequest__(); + xhr.open('GET', image_uri, false); + xhr.responseType = 'arraybuffer'; + xhr.addEventListener('load', function() { + status = this.status; + if (status === 200) { + var arrayBuffer = this.response; + b64encoded = Buffer.from(arrayBuffer).toString('base64'); + contentType = this.getResponseHeader('content-type'); + } + }); + xhr.send(null); + } + catch (e) { + // something bad happened! + status = 0; + } + if (status === 404 || (status === 0 && !b64encoded)) { + self.$logger().$warn('could not retrieve image data from URI: ' + image_uri); + return image_uri + } + return 'data:' + contentType + ';base64,' + b64encoded + ; + }, -2) + })($nesting[0], null) + })($nesting[0], $nesting) +}; -/** - * Check if the specified attribute is defined using the same logic as {AbstractNode#getAttribute}, optionally performing acomparison with the expected value if specified. - * - * Look for the specified attribute in the attributes on this node. - * If not found, fallback_name is specified (default: same as name), and this node is not the Document node, look for that attribute on the Document node. - * In either case, if the attribute is found, and the comparison value is truthy, return whether the two values match. - * Otherwise, return whether the attribute was found. - * - * @param {string} name - The String name of the attribute to resolve. - * @param {*} [expectedValue] - The expected Object value of the attribute (default: undefined). - * @param {string} fallbackName - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name). - * - * @returns {boolean} - a Boolean indicating whether the attribute exists and, if a truthy comparison value is specified, whether the value of the attribute matches the comparison value. - * @memberof AbstractNode - */ -AbstractNode.prototype.isAttribute = function (name, expectedValue, fallbackName) { - var result = this['$attr?'](name, expectedValue, fallbackName) - return result === Opal.nil ? false : result -} +Opal.modules["asciidoctor/js/asciidoctor_ext/node/open_uri"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $slice = Opal.slice, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Assign the value to the attribute name for the current node. - * - * @param {string} name - The String attribute name to assign - * @param {*} value - The Object value to assign to the attribute (default: '') - * @param {boolean} overwrite - A Boolean indicating whether to assign the attribute if currently present in the attributes JSON (default: true) - * - * @returns {boolean} - a Boolean indicating whether the assignment was performed - * @memberof AbstractNode - */ -AbstractNode.prototype.setAttribute = function (name, value, overwrite) { - if (typeof overwrite === 'undefined') overwrite = true - return this.$set_attr(name, value, overwrite) -} + Opal.add_stubs('require,new,<<,rewind'); + + self.$require("stringio"); + return (function($base, $parent_nesting) { + var self = $module($base, 'OpenURI'); -/** - * Remove the attribute from the current node. - * @param {string} name - The String attribute name to remove - * @returns {string} - the previous {string} value, or undefined if the attribute was not present. - * @memberof AbstractNode - */ -AbstractNode.prototype.removeAttribute = function (name) { - var value = this.$remove_attr(name) - return value === Opal.nil ? undefined : value -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Get the {@link Document} to which this node belongs. - * - * @returns {Document} - the {@link Document} object to which this node belongs. - * @memberof AbstractNode - */ -AbstractNode.prototype.getDocument = function () { - return this.document -} + return $defs($$('OpenURI'), '$open_uri', function $$open_uri(uri, $a) { + var $yield = $$open_uri.$$p || nil, io = nil, data = nil; -/** - * Get the {@link AbstractNode} to which this node is attached. - * - * @memberof AbstractNode - * @returns {AbstractNode} - the {@link AbstractNode} object to which this node is attached, - * or undefined if this node has no parent. - */ -AbstractNode.prototype.getParent = function () { - var parent = this.parent - return parent === Opal.nil ? undefined : parent -} + $$open_uri.$$p = null; + + $slice(arguments, 1); + io = $$$('StringIO').$new(); + data = ""; + + var contentType = ''; + var status = -1; -/** - * @returns {boolean} - true if this {AbstractNode} is an instance of {Inline} - * @memberof AbstractNode - */ -AbstractNode.prototype.isInline = function () { - return this['$inline?']() -} + try { + var xhr = new __XMLHttpRequest__(); + xhr.open('GET', uri, false); + xhr.responseType = 'text'; + xhr.addEventListener('load', function() { + status = this.status; + if (status === 200) { + data = this.responseText; + contentType = this.getResponseHeader('content-type'); + } + }); + xhr.send(null); + } + catch (e) { + // something bad happened! + status = 0; + } + if (status === 404 || (status === 0 && !data)) { + throw $$('IOError').$new('No such file or directory: ' + uri) + } + io['$<<'](data); + io.$rewind(); + if (($yield !== nil)) { + return Opal.yield1($yield, io); + } else { + return io + } }, -2) + })($nesting[0], $nesting); +}; -/** - * @returns {boolean} - true if this {AbstractNode} is an instance of {Block} - * @memberof AbstractNode - */ -AbstractNode.prototype.isBlock = function () { - return this['$block?']() -} +Opal.modules["asciidoctor/js/asciidoctor_ext/node/stylesheet"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Checks if the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value. - * - * @param {string} expectedValue - The expected String value of the role (optional, default: undefined) - * - * @returns {boolean} - a Boolean indicating whether the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value. - * @memberof AbstractNode - */ -AbstractNode.prototype.isRole = function (expectedValue) { - return this['$role?'](expectedValue) -} + Opal.add_stubs('rstrip,read,join'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * Retrieves the space-separated String role for this node. - * - * @returns {string} - the role as a space-separated String. - * @memberof AbstractNode - */ -AbstractNode.prototype.getRole = function () { - return this.$role() -} + var $nesting = [self].concat($parent_nesting); -/** - * Checks if the specified role is present in the list of roles for this node. - * - * @param {string} name - The String name of the role to find. - * - * @returns {boolean} - a Boolean indicating whether this node has the specified role. - * @memberof AbstractNode - */ -AbstractNode.prototype.hasRole = function (name) { - return this['$has_role?'](name) -} + return (function($base, $super) { + var self = $klass($base, $super, 'Stylesheets'); -/** - * Retrieves the String role names for this node as an Array. - * - * @returns {Array<string>} - the role names as a String {Array}, which is empty if the role attribute is absent on this node. - * @memberof AbstractNode - */ -AbstractNode.prototype.getRoles = function () { - return this.$roles() -} + var $proto = self.$$prototype; -/** - * Adds the given role directly to this node. - * - * @param {string} name - The name of the role to add - * - * @returns {boolean} - a Boolean indicating whether the role was added. - * @memberof AbstractNode - */ -AbstractNode.prototype.addRole = function (name) { - return this.$add_role(name) -} + $proto.primary_stylesheet_data = nil; + return $def(self, '$primary_stylesheet_data', function $$primary_stylesheet_data() { + var self = this, stylesheets_dir = nil, $ret_or_1 = nil; -/** - * Public: Removes the given role directly from this node. - * - * @param {string} name - The name of the role to remove - * - * @returns {boolean} - a Boolean indicating whether the role was removed. - * @memberof AbstractNode - */ -AbstractNode.prototype.removeRole = function (name) { - return this.$remove_role(name) -} + + if ($truthy(__path__.basename(__asciidoctorDistDir__) === 'node' && __path__.basename(__path__.dirname(__asciidoctorDistDir__)) === 'dist')) { + stylesheets_dir = __path__.join(__path__.dirname(__asciidoctorDistDir__), 'css'); + } else { + stylesheets_dir = __path__.join(__asciidoctorDistDir__, 'css'); + } return (self.primary_stylesheet_data = ($truthy(($ret_or_1 = self.primary_stylesheet_data)) ? ($ret_or_1) : ($$$('IO').$read($$$('File').$join(stylesheets_dir, "asciidoctor.css")).$rstrip()))); + }) + })($nesting[0], null) + })($nesting[0], $nesting) +}; -/** - * A convenience method that checks if the reftext attribute is defined. - * @returns {boolean} - A Boolean indicating whether the reftext attribute is defined - * @memberof AbstractNode - */ -AbstractNode.prototype.isReftext = function () { - return this['$reftext?']() -} +Opal.modules["asciidoctor/js/asciidoctor_ext/node/template"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $return_ivar = Opal.return_ivar, $defs = Opal.defs, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $eqeq = Opal.eqeq, $send = Opal.send, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * A convenience method that returns the value of the reftext attribute with substitutions applied. - * @returns {string|undefined} - the value of the reftext attribute with substitutions applied. - * @memberof AbstractNode - */ -AbstractNode.prototype.getReftext = function () { - var reftext = this.$reftext() - return reftext === Opal.nil ? undefined : reftext -} + Opal.add_stubs('[],clear,===,caches,class,scan,node_name,raise,ctx,==,strip,rstrip,key?,merge,[]=,file,private,new,each,directory?,system_path,scan_dir,update,select,glob,file?,basename,<,size,split,start_with?,slice,length,to_sym,node_require'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @returns {string} - Get the context name for this node - * @memberof AbstractNode - */ -AbstractNode.prototype.getContext = function () { - var context = this.context - // Automatically convert Opal pseudo-symbol to String - return typeof context === 'string' ? context : context.toString() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @returns {string} - the String id of this node - * @memberof AbstractNode - */ -AbstractNode.prototype.getId = function () { - var id = this.id - return id === Opal.nil ? undefined : id -} + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'TemplateConverter'); -/** - * @param {string} id - the String id of this node - * @memberof AbstractNode - */ -AbstractNode.prototype.setId = function (id) { - this.id = id -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * A convenience method to check if the specified option attribute is enabled on the current node. - * Check if the option is enabled. This method simply checks to see if the <name>-option attribute is defined on the current node. - * - * @param {string} name - the String name of the option - * - * @return {boolean} - a Boolean indicating whether the option has been specified - * @memberof AbstractNode - */ -AbstractNode.prototype.isOption = function (name) { - return this['$option?'](name) -} + $proto.templates = $proto.caches = $proto.backend = $proto.engine = $proto.template_dirs = nil; + + self.caches = $hash2(["scans", "templates"], {"scans": $hash2([], {}), "templates": $hash2([], {})}); + $defs(self, '$caches', $return_ivar("caches")); + $defs(self, '$clear_caches', function $$clear_caches() { + var self = this; + if (self.caches == null) self.caches = nil; -/** - * Set the specified option on this node. - * This method sets the specified option on this node by setting the <name>-option attribute. - * - * @param {string} name - the String name of the option - * - * @memberof AbstractNode - */ -AbstractNode.prototype.setOption = function (name) { - return this.$set_option(name) -} + + if ($truthy(self.caches['$[]']("scans"))) { + self.caches['$[]']("scans").$clear(); + } if ($truthy(self.caches['$[]']("templates"))) { + return self.caches['$[]']("templates").$clear() + } else { + return nil + } }); + + $def(self, '$initialize', function $$initialize(backend, template_dirs, opts) { + var self = this, $ret_or_1 = nil; -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.getIconUri = function (name) { - return this.$icon_uri(name) -} + + if (opts == null) opts = $hash2([], {}); + self.backend = backend; + self.templates = $hash2([], {}); + self.template_dirs = template_dirs; + self.engine = opts['$[]']("template_engine"); + self.engine_options = ($truthy(($ret_or_1 = opts['$[]']("template_engine_options"))) ? ($ret_or_1) : ($hash2([], {}))); + if ($eqeqeq(true, ($ret_or_1 = opts['$[]']("template_cache")))) { + self.caches = self.$class().$caches(); + } else if ($eqeqeq($$$('Hash'), $ret_or_1)) { + self.caches = opts['$[]']("template_cache"); + } else { + self.caches = $hash2([], {}); + } return self.$scan(); + }, -3); + + $def(self, '$convert', function $$convert(node, template_name, opts) { + var self = this, template = nil, $ret_or_1 = nil, helpers_ctx = nil; + + + if (template_name == null) template_name = nil; + if (opts == null) opts = nil; + if (!$truthy((template = self.templates['$[]']((template_name = ($truthy(($ret_or_1 = template_name)) ? ($ret_or_1) : (node.$node_name()))))))) { + self.$raise("Could not find a custom template to handle transform: " + (template_name)); + } helpers_ctx = ($truthy(($ret_or_1 = self.templates['$[]']("helpers.js"))) ? (self.templates['$[]']("helpers.js").$ctx()) : ($ret_or_1)); + if ($eqeq(template_name, "document")) { + return (template.render({node: node, opts: fromHash(opts), helpers: helpers_ctx})).$strip() + } else { + return (template.render({node: node, opts: fromHash(opts), helpers: helpers_ctx})).$rstrip() + } }, -2); + + $def(self, '$handles?', function $TemplateConverter_handles$ques$1(name) { + var self = this; + + return self.templates['$key?'](name) + }); + + $def(self, '$templates', function $$templates() { + var self = this; + + return self.templates.$merge() + }); + + $def(self, '$register', function $$register(name, template) { + var $a, $b, self = this, template_cache = nil, $ret_or_1 = nil; + + return ($a = [name, ($truthy((template_cache = ($truthy(($ret_or_1 = self.caches['$[]']("templates"))) ? (template.$file) : ($ret_or_1)))) ? (($b = [template.$file(), template], $send(template_cache, '[]=', $b), $b[$b.length - 1])) : (template))], $send(self.templates, '[]=', $a), $a[$a.length - 1]) + }); + self.$private(); + + $def(self, '$scan', function $$scan() { + var self = this, path_resolver = nil, backend = nil, engine = nil; + + + path_resolver = $$('PathResolver').$new(); + backend = self.backend; + engine = self.engine; + return $send(self.template_dirs, 'each', [], function $$2(template_dir){var $a, self = $$2.$$s == null ? this : $$2.$$s, file_pattern = nil, engine_dir = nil, backend_dir = nil, pattern = nil, scan_cache = nil, template_cache = nil, templates = nil; + if (self.caches == null) self.caches = nil; + if (self.templates == null) self.templates = nil; + + + if (template_dir == null) template_dir = nil; + if (!$truthy($$$('File')['$directory?']((template_dir = path_resolver.$system_path(template_dir))))) { + return nil + } if ($truthy(engine)) { + + file_pattern = "*." + (engine); + if ($truthy($$$('File')['$directory?']((engine_dir = "" + (template_dir) + "/" + (engine))))) { + template_dir = engine_dir; + } } else { + file_pattern = "*"; + } if ($truthy($$$('File')['$directory?']((backend_dir = "" + (template_dir) + "/" + (backend))))) { + template_dir = backend_dir; + } pattern = "" + (template_dir) + "/" + (file_pattern); + if ($truthy((scan_cache = self.caches['$[]']("scans")))) { + + template_cache = self.caches['$[]']("templates"); + if (!$truthy((templates = scan_cache['$[]'](pattern)))) { + templates = ($a = [pattern, self.$scan_dir(template_dir, pattern, template_cache)], $send(scan_cache, '[]=', $a), $a[$a.length - 1]); + } $send(templates, 'each', [], function $$3(name, template){var $b, $c, self = $$3.$$s == null ? this : $$3.$$s; + if (self.templates == null) self.templates = nil; + + + if (name == null) name = nil; + if (template == null) template = nil; + return ($b = [name, ($c = [template.$file(), template], $send(template_cache, '[]=', $c), $c[$c.length - 1])], $send(self.templates, '[]=', $b), $b[$b.length - 1]);}, {$$s: self}); + } else { + self.templates.$update(self.$scan_dir(template_dir, pattern, self.caches['$[]']("templates"))); + } return nil;}, {$$s: self}); + }); + + $def(self, '$node_require', function $$node_require(module_name) { + + + try { + return __require__(module_name) + } + catch (e) { + throw $$('IOError').$new("Unable to require the module '" + (module_name) + "', please make sure that the module is installed.") + } + + }); + return $def(self, '$scan_dir', function $$scan_dir(template_dir, pattern, template_cache) { + var $a, self = this, result = nil, helpers = nil; + + + if (template_cache == null) template_cache = nil; + $a = [$hash2([], {}), nil], (result = $a[0]), (helpers = $a[1]); + var enginesContext = {}; + $send($send($$$('Dir').$glob(pattern), 'select', [], function $$4(match){ + + if (match == null) match = nil; + return $$$('File')['$file?'](match);}), 'each', [], function $$5(file){var $b, self = $$5.$$s == null ? this : $$5.$$s, basename = nil, path_segments = nil, name = nil, template = nil, extsym = nil, nunjucks = nil, handlebars = nil, ejs = nil, pug = nil; + + + if (file == null) file = nil; + if (($eqeq((basename = $$$('File').$basename(file)), "helpers.js") || ($eqeq((basename = $$$('File').$basename(file)), "helpers.cjs")))) { + + helpers = file; + return nil; + } else if ($truthy($rb_lt((path_segments = basename.$split(".")).$size(), 2))) { + return nil + } if ($eqeq((name = path_segments['$[]'](0)), "block_ruler")) { + name = "thematic_break"; + } else if ($truthy(name['$start_with?']("block_"))) { + name = name.$slice(6, name.$length()); + } if (!($truthy(template_cache) && ($truthy((template = template_cache['$[]'](file)))))) { + + extsym = path_segments['$[]'](-1).$to_sym(); + + switch (extsym) { + case "nunjucks": + case "njk": + + nunjucks = self.$node_require("nunjucks"); + + var env; + if (enginesContext.nunjucks && enginesContext.nunjucks.environment) { + env = enginesContext.nunjucks.environment; + } else { + var opts = self.engine_options['nunjucks'] || {}; + delete opts.web; // unsupported option + env = nunjucks.configure(template_dir, opts); + enginesContext.nunjucks = { environment: env }; + } + template = Object.assign(nunjucks.compile(fs.readFileSync(file, 'utf8'), env), { '$file': function() { return file } }) + ; + break; + case "handlebars": + case "hbs": + + handlebars = self.$node_require("handlebars"); + + var env; + var opts = self.engine_options['handlebars'] || {}; + if (enginesContext.handlebars && enginesContext.handlebars.environment) { + env = enginesContext.handlebars.environment; + } else { + env = handlebars.create(); + enginesContext.handlebars = { environment: env }; + } + template = { render: env.compile(fs.readFileSync(file, 'utf8'), opts), '$file': function() { return file } } + ; + break; + case "ejs": + + ejs = self.$node_require("ejs"); + + var opts = self.engine_options['ejs'] || {}; + opts.filename = file; + // unsupported options + delete opts.async; + delete opts.client; + template = { render: ejs.compile(fs.readFileSync(file, 'utf8'), opts), '$file': function() { return file } } + ; + break; + case "pug": + + pug = self.$node_require("pug"); + + var opts = self.engine_options['pug'] || {}; + opts.filename = file; + template = { render: pug.compileFile(file, opts), '$file': function() { return file } } + ; + break; + case "js": + case "cjs": + template = { render: __require__(file), '$file': function() { return file } }; + break; + default: + + var registry = Opal.Asciidoctor.TemplateEngine.registry; + var templateEngine = registry[extsym]; + if (templateEngine && typeof templateEngine.compile === 'function') { + template = Object.assign(templateEngine.compile(file, name), { '$file': function() { return file } }); + } else { + template = undefined; + } + + } } if ($truthy(template)) { + return ($b = [name, template], $send(result, '[]=', $b), $b[$b.length - 1]) + } else { + return nil + }}, {$$s: self}); + if ((($truthy(helpers) || ($truthy($$$('File')['$file?']((helpers = "" + (template_dir) + "/helpers.js"))))) || ($truthy($$$('File')['$file?']((helpers = "" + (template_dir) + "/helpers.cjs")))))) { + + + var ctx = __require__(helpers); + if (typeof ctx.configure === 'function') { + ctx.configure(enginesContext); + } + result['$[]=']("helpers.js", { '$file': function() { return helpers }, $ctx: function() { return ctx } }); + } return result; + }, -3); + })($$('Converter'), $$$($$('Converter'), 'Base'), $nesting) + })($nesting[0], $nesting) +}; -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.getMediaUri = function (target, assetDirKey) { - return this.$media_uri(target, assetDirKey) -} +Opal.modules["asciidoctor/js/asciidoctor_ext/node"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.getImageUri = function (targetImage, assetDirKey) { - return this.$image_uri(targetImage, assetDirKey) -} + Opal.add_stubs('require'); + + self.$require("asciidoctor/js/asciidoctor_ext/node/abstract_node"); + self.$require("asciidoctor/js/asciidoctor_ext/node/open_uri"); + self.$require("asciidoctor/js/asciidoctor_ext/node/stylesheet"); + return self.$require("asciidoctor/js/asciidoctor_ext/node/template"); +}; -/** - * Get the {Converter} instance being used to convert the current {Document}. - * @returns {Object} - * @memberof AbstractNode - */ -AbstractNode.prototype.getConverter = function () { - return this.$converter() -} +Opal.modules["set"] = Opal.return_val(Opal.nil); /* Generated by Opal 1.7.3 */ -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.readContents = function (target, options) { - return this.$read_contents(target, toHash(options)) -} +Opal.modules["asciidoctor/js/opal_ext/kernel"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $def = Opal.def, $return_val = Opal.return_val, $nesting = [], nil = Opal.nil; -/** - * Read the contents of the file at the specified path. - * This method assumes that the path is safe to read. - * It checks that the file is readable before attempting to read it. - * - * @param path - the {string} path from which to read the contents - * @param {Object} options - a JSON {Object} of options to control processing (default: {}) - * @param {boolean} options.warn_on_failure - a {boolean} that controls whether a warning is issued if the file cannot be read (default: false) - * @param {boolean} options.normalize - a {boolean} that controls whether the lines are normalized and coerced to UTF-8 (default: false) - * - * @returns {string} - the String content of the file at the specified path, or undefined if the file does not exist. - * @memberof AbstractNode - */ -AbstractNode.prototype.readAsset = function (path, options) { - var result = this.$read_asset(path, toHash(options)) - return result === Opal.nil ? undefined : result -} + Opal.add_stubs('new'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.normalizeWebPath = function (target, start, preserveTargetUri) { - return this.$normalize_web_path(target, start, preserveTargetUri) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.normalizeSystemPath = function (target, start, jail, options) { - return this.$normalize_system_path(target, start, jail, toHash(options)) -} + + + $def(self, '$open', function $$open(path, $a) { + var $post_args, rest, $yield = $$open.$$p || nil, file = nil; -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.normalizeAssetPath = function (assetRef, assetName, autoCorrect) { - return this.$normalize_asset_path(assetRef, assetName, autoCorrect) -} + $$open.$$p = null; + + $post_args = $slice(arguments, 1); + rest = $post_args; + file = $send($$('File'), 'new', [path].concat($to_a(rest))); + if (($yield !== nil)) { + return Opal.yield1($yield, file); + } else { + return file + } }, -2); + return $def(self, '$__dir__', $return_val("")); + })($nesting[0], $nesting) +}; -// Document API +Opal.modules["asciidoctor/js/opal_ext/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $gvars = Opal.gvars, $return_val = Opal.return_val, $defs = Opal.defs, $nesting = [], nil = Opal.nil; -/** - * The {@link Document} class represents a parsed AsciiDoc document. - * - * Document is the root node of a parsed AsciiDoc document.<br/> - * It provides an abstract syntax tree (AST) that represents the structure of the AsciiDoc document - * from which the Document object was parsed. - * - * Although the constructor can be used to create an empty document object, - * more commonly, you'll load the document object from AsciiDoc source - * using the primary API methods on {@link Asciidoctor}. - * When using one of these APIs, you almost always want to set the safe mode to 'safe' (or 'unsafe') - * to enable all of Asciidoctor's features. - * - * <pre> - * var doc = Asciidoctor.load('= Hello, AsciiDoc!', { 'safe': 'safe' }) - * // => Asciidoctor::Document { doctype: "article", doctitle: "Hello, AsciiDoc!", blocks: 0 } - * </pre> - * - * Instances of this class can be used to extract information from the document or alter its structure. - * As such, the Document object is most often used in extensions and by integrations. - * - * The most basic usage of the Document object is to retrieve the document's title. - * - * <pre> - * var source = '= Document Title' - * var doc = asciidoctor.load(source, { 'safe': 'safe' }) - * console.log(doc.getTitle()) // 'Document Title' - * </pre> - * - * You can also use the Document object to access document attributes defined in the header, such as the author and doctype. - * @namespace - * @extends AbstractBlock - */ -var Document = Opal.Asciidoctor.Document + Opal.add_stubs('attr_reader,delete,gsub,read,size,to_enum,chomp,each_line,readlines,split'); + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'File'); -/** - * Returns a JSON {Object} of references captured by the processor. - * - * @returns {Object} - a JSON {Object} of {AbstractNode} in the document. - * @memberof Document - */ -Document.prototype.getRefs = function () { - return fromHash(this.catalog.$$smap.refs) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * Returns an {Array} of {Document/ImageReference} captured by the processor. - * - * @returns {Array<ImageReference>} - an {Array} of {Document/ImageReference} in the document. - * Will return an empty array if the option "catalog_assets: true" was not defined on the processor. - * @memberof Document - */ -Document.prototype.getImages = function () { - return this.catalog.$$smap.images -} + $proto.eof = $proto.path = nil; + + self.$attr_reader("eof"); + self.$attr_reader("lineno"); + self.$attr_reader("path"); + + $def(self, '$initialize', function $$initialize(path, flags) { + var self = this, encoding_flag_regexp = nil; -/** - * Returns an {Array} of links captured by the processor. - * - * @returns {Array<string>} - an {Array} of links in the document. - * Will return an empty array if: - * - the function was called before the document was converted - * - the option "catalog_assets: true" was not defined on the processor - * @memberof Document - */ -Document.prototype.getLinks = function () { - return this.catalog.$$smap.links -} + + if (flags == null) flags = "r"; + self.path = path; + self.contents = nil; + self.eof = false; + self.lineno = 0; + flags = flags.$delete("b"); + encoding_flag_regexp = /:(.*)/; + flags = flags.$gsub(encoding_flag_regexp, ""); + return (self.flags = flags); + }, -2); + + $def(self, '$read', function $$read() { + var self = this, res = nil; -/** - * @returns {boolean} - true if the document has footnotes otherwise false - * @memberof Document - */ -Document.prototype.hasFootnotes = function () { - return this['$footnotes?']() -} + if ($truthy(self.eof)) { + return "" + } else { + + res = $$('File').$read(self.path); + self.eof = true; + self.lineno = res.$size(); + return res; + } + }); + + $def(self, '$each_line', function $$each_line(separator) { + var block = $$each_line.$$p || nil, self = this, lines = nil; + if ($gvars["/"] == null) $gvars["/"] = nil; -/** - * Returns an {Array} of {Document/Footnote} captured by the processor. - * - * @returns {Array<Footnote>} - an {Array} of {Document/Footnote} in the document. - * Will return an empty array if the function was called before the document was converted. - * @memberof Document - */ -Document.prototype.getFootnotes = function () { - return this.$footnotes() -} + $$each_line.$$p = null; + if (separator == null) separator = $gvars["/"]; + if ($truthy(self.eof)) { + return ((block !== nil) ? (self) : ([].$to_enum())) + } if ((block !== nil)) { + + lines = $$('File').$read(self.path); + + self.eof = false; + self.lineno = 0; + var chomped = lines.$chomp(), + trailing = lines.length != chomped.length, + splitted = chomped.split(separator); + for (var i = 0, length = splitted.length; i < length; i++) { + self.lineno += 1; + if (i < length - 1 || trailing) { + Opal.yield1(block, splitted[i] + separator); + } + else { + Opal.yield1(block, splitted[i]); + } + } + self.eof = true; + return self; + } else { + return self.$read().$each_line() + } }, -1); + + $def(self, '$readlines', function $$readlines() { + var self = this; -/** - * Returns the level-0 {Section} (i.e. the document title). - * Only stores the title, not the header attributes. - * - * @returns {string} - the level-0 {Section}. - * @memberof Document - */ -Document.prototype.getHeader = function () { - return this.header -} + return $$('File').$readlines(self.path) + }); + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @memberof Document - */ -Document.prototype.setAttribute = function (name, value) { - return this.$set_attribute(name, value) -} + + + $def(self, '$readlines', function $$readlines(path, separator) { + var content = nil; + if ($gvars["/"] == null) $gvars["/"] = nil; -/** + + if (separator == null) separator = $gvars["/"]; + content = $$('File').$read(path); + return content.$split(separator); + }, -2); + + $def(self, '$file?', $return_val(true)); + + $def(self, '$readable?', $return_val(true)); + return $def(self, '$read', $return_val("")); + })(Opal.get_singleton_class(self), $nesting); + })($nesting[0], null, $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'IO'); - * @memberof Document - */ -Document.prototype.removeAttribute = function (name) { - this.attributes.$delete(name) - this.attribute_overrides.$delete(name) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Convert the AsciiDoc document using the templates loaded by the Converter. - * If a "template_dir" is not specified, or a template is missing, the converter will fall back to using the appropriate built-in template. - * - * @param {Object} [options] - a JSON of options to control processing (default: {}) - * - * @returns {string} - * @memberof Document - */ -Document.prototype.convert = function (options) { - var result = this.$convert(toHash(options)) - return result === Opal.nil ? '' : result -} + return $defs(self, '$read', function $$read(path) { + + return $$('File').$read(path) + }) + })($nesting[0], null, $nesting); +}; -/** - * Write the output to the specified file. - * - * If the converter responds to "write", delegate the work of writing the file to that method. - * Otherwise, write the output the specified file. - * - * @param {string} output - * @param {string} target - * - * @memberof Document - */ -Document.prototype.write = function (output, target) { - return this.$write(output, target) -} +Opal.modules["asciidoctor/js/opal_ext/match_data"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $send = Opal.send, $def = Opal.def, $nesting = [], nil = Opal.nil; -/** - * @returns {string} - the full name of the author as a String - * @memberof Document - */ -Document.prototype.getAuthor = function () { - return this.$author() -} + Opal.add_stubs('[]='); + return (function($base, $super) { + var self = $klass($base, $super, 'MatchData'); -/** - * @returns {string} - * @memberof Document - */ -Document.prototype.getSource = function () { - return this.$source() -} + var $proto = self.$$prototype; -/** - * @returns {Array<string>} - * @memberof Document - */ -Document.prototype.getSourceLines = function () { - return this.$source_lines() -} + $proto.matches = nil; + return $def(self, '$[]=', function $MatchData_$$$eq$1(idx, val) { + var $a, self = this; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.isNested = function () { - return this['$nested?']() -} + return ($a = [idx, val], $send(self.matches, '[]=', $a), $a[$a.length - 1]) + }) + })($nesting[0], null) +}; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.isEmbedded = function () { - return this['$embedded?']() -} +Opal.modules["asciidoctor/js/opal_ext/string"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $def = Opal.def, $alias = Opal.alias, $rb_ge = Opal.rb_ge, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $nesting = [], nil = Opal.nil; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.hasExtensions = function () { - return this['$extensions?']() -} + Opal.add_stubs('method_defined?,<,length,bytes,to_s,byteslice,limit_bytesize,>=,==,-,_original_byteslice,unpack,_original_unpack'); + return (function($base, $super) { + var self = $klass($base, $super, 'String'); -/** - * Get the value of the doctype attribute for this document. - * @returns {string} - * @memberof Document - */ -Document.prototype.getDoctype = function () { - return this.doctype -} + + + if (!$truthy(self['$method_defined?']("limit_bytesize"))) { + + $def(self, '$limit_bytesize', function $$limit_bytesize(size) { + var self = this, result = nil; -/** - * Get the value of the backend attribute for this document. - * @returns {string} - * @memberof Document - */ -Document.prototype.getBackend = function () { - return this.backend -} + + if (!$truthy($rb_lt(size, self.$bytes().$length()))) { + return self.$to_s() + } result = self.$byteslice(0, size); + return result.$to_s(); + }); + } if (!$truthy(self['$method_defined?']("limit"))) { + $alias(self, "limit", "limit_bytesize"); + } $alias(self, "_original_byteslice", "byteslice"); + + $def(self, '$byteslice', function $$byteslice(index, length) { + var self = this; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.isBasebackend = function (base) { - return this['$basebackend?'](base) -} + + if (length == null) length = 1; + if ((($eqeq(index, 3) && ($truthy($rb_ge(length, index)))) && ($truthy(self.charCodeAt() === 65279)))) { + return (self.substr(1)).$byteslice(0, $rb_minus(length, 3)) + } else { + return self.$_original_byteslice(index, length) + } }, -2); + $alias(self, "_original_unpack", "unpack"); + return $def(self, '$unpack', function $$unpack(format) { + var self = this; -/** - * Get the title explicitly defined in the document attributes. - * @returns {string} - * @see {@link AbstractNode#getAttributes} - * @memberof Document - */ -Document.prototype.getTitle = function () { - var title = this.$title() - return title === Opal.nil ? undefined : title -} + if ($eqeq(format, "C3")) { + if ($truthy(self.charCodeAt() === 65279)) { + return [239, 187, 191] + } else { + + var bytes = []; + for (var i=0; i < 3; i++) { + if (i < self.length) { + bytes.push(self.charCodeAt(i)); + } else { + bytes.push(nil); + } + } + return bytes + + } + } else { + return self.$_original_unpack(format) + } + }); + })($nesting[0], null) +}; -/** - * Set the title on the document header - * - * Set the title of the document header to the specified value. - * If the header does not exist, it is first created. - * - * @param {string} title - the String title to assign as the title of the document header - * - * @returns {string} - the new String title assigned to the document header - * @memberof Document - */ -Document.prototype.setTitle = function (title) { - return this['$title='](title) -} +Opal.modules["asciidoctor/js/opal_ext/uri"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $defs = Opal.defs, $return_self = Opal.return_self, $def = Opal.def, $nesting = []; Opal.nil; -/** - * @returns {Document/Title} - a {@link Document/Title} - * @memberof Document - */ -Document.prototype.getDocumentTitle = function (options) { - var doctitle = this.$doctitle(toHash(options)) - return doctitle === Opal.nil ? undefined : doctitle -} + Opal.add_stubs('extend'); + return (function($base, $parent_nesting) { + var self = $module($base, 'URI'); -/** - * @see {@link Document#getDocumentTitle} - * @memberof Document - */ -Document.prototype.getDoctitle = Document.prototype.getDocumentTitle + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Get the document catalog JSON object. - * @returns {Object} - * @memberof Document - */ -Document.prototype.getCatalog = function () { - return fromHash(this.catalog) -} + + $defs(self, '$parse', function $$parse(str) { + + return str.$extend($$('URI')) + }); + return $def(self, '$path', $return_self); + })($nesting[0], $nesting) +}; -/** - * - * @returns {Object} - * @see Document#getCatalog - * @memberof Document - */ -Document.prototype.getReferences = Document.prototype.getCatalog +Opal.modules["asciidoctor/js/opal_ext/base64"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $defs = Opal.defs, $ensure_kwargs = Opal.ensure_kwargs, $truthy = Opal.truthy, $nesting = [], nil = Opal.nil; -/** - * Get the document revision date from document header (document attribute <code>revdate</code>). - * @returns {string} - * @memberof Document - */ -Document.prototype.getRevisionDate = function () { - return this.getAttribute('revdate') -} + Opal.add_stubs('delete'); + return (function($base) { + var self = $module($base, 'Base64'); -/** - * @see Document#getRevisionDate - * @returns {string} - * @memberof Document - */ -Document.prototype.getRevdate = function () { - return this.getRevisionDate() -} + + + + var encode, decode; + encode = Opal.global.btoa || function (input) { + var buffer; + if (input instanceof Buffer) { + buffer = input; + } else { + buffer = Buffer.from(input.toString(), 'binary'); + } + return buffer.toString('base64'); + }; + decode = Opal.global.atob || function (input) { + return Buffer.from(input, 'base64').toString('binary'); + }; + $defs(self, '$decode64', function $$decode64(string) { + + return decode(string.replace(/\r?\n/g, '')); + }); + $defs(self, '$encode64', function $$encode64(string) { + + return encode(string).replace(/(.{60})/g, "$1\n").replace(/([^\n])$/g, "$1\n"); + }); + $defs(self, '$strict_decode64', function $$strict_decode64(string) { + + return decode(string); + }); + $defs(self, '$strict_encode64', function $$strict_encode64(string) { + + return encode(string); + }); + $defs(self, '$urlsafe_decode64', function $$urlsafe_decode64(string) { + + return decode(string.replace(/\-/g, '+').replace(/_/g, '/')); + }); + return $defs(self, '$urlsafe_encode64', function $$urlsafe_encode64(string, $kwargs) { + var padding, str = nil; -/** - * Get the document revision number from document header (document attribute <code>revnumber</code>). - * @returns {string} - * @memberof Document - */ -Document.prototype.getRevisionNumber = function () { - return this.getAttribute('revnumber') -} + + $kwargs = $ensure_kwargs($kwargs); + + padding = $kwargs.$$smap["padding"];if (padding == null) padding = true; + str = encode(string).replace(/\+/g, '-').replace(/\//g, '_'); + if (!$truthy(padding)) { + str = str.$delete("="); + } return str; + }, -2); + })($nesting[0]) +}; -/** - * Get the document revision remark from document header (document attribute <code>revremark</code>). - * @returns {string} - * @memberof Document - */ -Document.prototype.getRevisionRemark = function () { - return this.getAttribute('revremark') -} +Opal.modules["asciidoctor/js/opal_ext/number"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $def = Opal.def, $nesting = [], $$ = Opal.$r($nesting); Opal.nil; -/** - * Assign a value to the specified attribute in the document header. - * - * The assignment will be visible when the header attributes are restored, - * typically between processor phases (e.g., between parse and convert). - * - * @param {string} name - The {string} attribute name to assign - * @param {Object} value - The {Object} value to assign to the attribute (default: '') - * @param {boolean} overwrite - A {boolean} indicating whether to assign the attribute - * if already present in the attributes Hash (default: true) - * - * @returns {boolean} - true if the assignment was performed otherwise false - * @memberof Document - */ -Document.prototype.setHeaderAttribute = function (name, value, overwrite) { - if (typeof overwrite === 'undefined') overwrite = true - if (typeof value === 'undefined') value = '' - return this.$set_header_attribute(name, value, overwrite) -} + Opal.add_stubs('coerce_to!,>'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Number'); -/** - * Convenience method to retrieve the authors of this document as an {Array} of {Document/Author} objects. - * - * This method is backed by the author-related attributes on the document. - * - * @returns {Array<Author>} - an {Array} of {Document/Author} objects. - * @memberof Document - */ -Document.prototype.getAuthors = function () { - return this.$authors() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -// Document.Footnote API + return $def(self, '$round', function $$round(ndigits) { + var self = this; + ndigits = $$('Opal')['$coerce_to!'](ndigits, $$('Integer'), "to_int"); + if ($truthy($rb_gt(ndigits, 0))) { + return Number(self.toFixed(ndigits)); + } else { + return Math.round(self); + } }, -1) + })($nesting[0], $$('Numeric'), $nesting) +}; -/** - * @namespace - * @module Document/Footnote - */ -var Footnote = Document.Footnote +Opal.modules["asciidoctor/js/opal_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; -/** - * @returns {number} - the footnote's index - * @memberof Document/Footnote - */ -Footnote.prototype.getIndex = function () { - var index = this.$$data.index - return index === Opal.nil ? undefined : index -} + Opal.add_stubs('require'); + + self.$require("asciidoctor/js/opal_ext/kernel"); + self.$require("asciidoctor/js/opal_ext/file"); + self.$require("asciidoctor/js/opal_ext/match_data"); + self.$require("asciidoctor/js/opal_ext/string"); + self.$require("asciidoctor/js/opal_ext/uri"); + self.$require("asciidoctor/js/opal_ext/base64"); + self.$require("asciidoctor/js/opal_ext/number"); + +// suppress "not supported" warning messages from Opal +Opal.config.unsupported_features_severity = 'ignore'; -/** - * @returns {number} - the footnote's id - * @memberof Document/Footnote - */ -Footnote.prototype.getId = function () { - var id = this.$$data.id - return id === Opal.nil ? undefined : id -} +// Load specific runtime +self.$require("asciidoctor/js/opal_ext/node"); +}; -/** - * @returns {string} - the footnote's text - * @memberof Document/Footnote - */ -Footnote.prototype.getText = function () { - var text = this.$$data.text - return text === Opal.nil ? undefined : text -} +Opal.modules["asciidoctor/js/rx"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $gvars = Opal.gvars, $truthy = Opal.truthy, $defs = Opal.defs, $rb_plus = Opal.rb_plus, $nesting = [], nil = Opal.nil; -// Document.ImageReference API + Opal.add_stubs('gsub,+,unpack_hex_range'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @class - * @module Document/ImageReference - */ -var ImageReference = Document.ImageReference + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @returns {string} - the image's target - * @memberof Document/ImageReference - */ -ImageReference.prototype.getTarget = function () { - return this.$$data.target -} + + $const_set($nesting[0], 'HEX_RANGE_RX', /([A-F0-9]{4})(?:-([A-F0-9]{4}))?/); + $defs(self, '$unpack_hex_range', function $$unpack_hex_range(str) { + + return $send(str, 'gsub', [$$('HEX_RANGE_RX')], function $$1(){var $a, $ret_or_1 = nil; -/** - * @returns {string} - the image's directory (imagesdir attribute) - * @memberof Document/ImageReference - */ -ImageReference.prototype.getImagesDirectory = function () { - var value = this.$$data.imagesdir - return value === Opal.nil ? undefined : value -} + return "\\u" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + (($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) ? ("-\\u" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) : ($ret_or_1)))}) + }); + $const_set($nesting[0], 'P_L', $rb_plus("A-Za-z", self.$unpack_hex_range("00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D037F03860388-038A038C038E-03A103A3-03F503F7-0481048A-052F0531-055605590561-058705D0-05EA05F0-05F20620-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280840-085808A0-08B20904-0939093D09500958-09610971-09800985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10CF10CF20D05-0D0C0D0E-0D100D12-0D3A0D3D0D4E0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC-0EDF0F000F40-0F470F49-0F6C0F88-0F8C1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510C710CD10D0-10FA10FC-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA16F1-16F81700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191E1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1BBA-1BE51C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11CF51CF61D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209C21022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2CF22CF32D00-2D252D272D2D2D30-2D672D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31BA31F0-31FF3400-4DB54E00-9FCCA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A66EA67F-A69DA6A0-A6E5A717-A71FA722-A788A78B-A78EA790-A7ADA7B0A7B1A7F7-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFA9E0-A9E4A9E6-A9EFA9FA-A9FEAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA7E-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDAAE0-AAEAAAF2-AAF4AB01-AB06AB09-AB0EAB11-AB16AB20-AB26AB28-AB2EAB30-AB5AAB5C-AB5FAB64AB65ABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC"))); + $const_set($nesting[0], 'P_Nl', self.$unpack_hex_range("16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF")); + $const_set($nesting[0], 'P_Nd', $rb_plus("0-9", self.$unpack_hex_range("0660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0DE6-0DEF0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19D91A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9A9F0-A9F9AA50-AA59ABF0-ABF9FF10-FF19"))); + $const_set($nesting[0], 'P_Pc', self.$unpack_hex_range("005F203F20402054FE33FE34FE4D-FE4FFF3F")); + $const_set($nesting[0], 'CC_ALPHA', "" + ($$('P_L')) + ($$('P_Nl'))); + $const_set($nesting[0], 'CG_ALPHA', "[" + ($$('CC_ALPHA')) + "]"); + $const_set($nesting[0], 'CC_ALNUM', "" + ($$('CC_ALPHA')) + ($$('P_Nd'))); + $const_set($nesting[0], 'CG_ALNUM', "[" + ($$('CC_ALNUM')) + "]"); + $const_set($nesting[0], 'CC_WORD', "" + ($$('CC_ALNUM')) + ($$('P_Pc'))); + $const_set($nesting[0], 'CG_WORD', "[" + ($$('CC_WORD')) + "]"); + $const_set($nesting[0], 'CG_BLANK', "[ \\t]"); + $const_set($nesting[0], 'CC_EOL', "(?=\\n|$)"); + $const_set($nesting[0], 'CG_GRAPH', "[^\\s\\x00-\\x1F\\x7F]"); + $const_set($nesting[0], 'CC_ALL', "[\\s\\S]"); + return $const_set($nesting[0], 'CC_ANY', "[^\\n]"); + })($nesting[0], $nesting) +}; -// Document.Author API +Opal.modules["strscan"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Opal = Opal.Opal, $return_ivar = Opal.return_ivar, $send = Opal.send, $alias = Opal.alias, $nesting = [], nil = Opal.nil; -/** - * The Author class represents information about an author extracted from document attributes. - * @namespace - * @module Document/Author - */ -var Author = Document.Author + Opal.add_stubs('attr_reader,anchor,empty?,===,to_s,coerce_to!,scan_until,length,size,rest,pos=,beginning_of_line?,get_byte,private'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'StringScanner'); -/** - * @returns {string} - the author's full name - * @memberof Document/Author - */ -Author.prototype.getName = function () { - var name = this.$$data.name - return name === Opal.nil ? undefined : name -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * @returns {string} - the author's first name - * @memberof Document/Author - */ -Author.prototype.getFirstName = function () { - var firstName = this.$$data.firstname - return firstName === Opal.nil ? undefined : firstName -} + $proto.pos = $proto.string = $proto.working = $proto.matched = $proto.prev_pos = $proto.match = nil; + + self.$attr_reader("pos", "matched"); + + $def(self, '$initialize', function $$initialize(string) { + var self = this; -/** - * @returns {string} - the author's middle name (or undefined if the author has no middle name) - * @memberof Document/Author - */ -Author.prototype.getMiddleName = function () { - var middleName = this.$$data.middlename - return middleName === Opal.nil ? undefined : middleName -} + + self.string = string; + self.pos = 0; + self.matched = nil; + self.working = string; + return (self.match = []); + }); + self.$attr_reader("string"); + + $def(self, '$beginning_of_line?', function $StringScanner_beginning_of_line$ques$1() { + var self = this; -/** - * @returns {string} - the author's last name - * @memberof Document/Author - */ -Author.prototype.getLastName = function () { - var lastName = this.$$data.lastname - return lastName === Opal.nil ? undefined : lastName -} + return self.pos === 0 || self.string.charAt(self.pos - 1) === "\n" + }); + + $def(self, '$scan', function $$scan(pattern) { + var self = this; -/** - * @returns {string} - the author's initials (by default based on the author's name) - * @memberof Document/Author - */ -Author.prototype.getInitials = function () { - var initials = this.$$data.initials - return initials === Opal.nil ? undefined : initials -} + + pattern = self.$anchor(pattern); + + var result = pattern.exec(self.working); -/** - * @returns {string} - the author's email - * @memberof Document/Author - */ -Author.prototype.getEmail = function () { - var email = this.$$data.email - return email === Opal.nil ? undefined : email -} + if (result == null) { + return self.matched = nil; + } + self.prev_pos = self.pos; + self.pos += result[0].length; + self.working = self.working.substring(result[0].length); + self.matched = result[0]; + self.match = result; -// private constructor -Document.RevisionInfo = function (date, number, remark) { - this.date = date - this.number = number - this.remark = remark -} + return result[0]; + }); + + $def(self, '$scan_until', function $$scan_until(pattern) { + var self = this; -/** - * @class - * @namespace - * @module Document/RevisionInfo - */ -var RevisionInfo = Document.RevisionInfo + + pattern = self.$anchor(pattern); + + var working = self.working; -/** - * Get the document revision date from document header (document attribute <code>revdate</code>). - * @returns {string} - * @memberof Document/RevisionInfo - */ -RevisionInfo.prototype.getDate = function () { - return this.date -} + for(var i = 0; working.length != i; ++i) { + var result = pattern.exec(working.substr(i)); + if (result !== null) { + var matched_size = i + result[0].length; + var matched = working.substr(0, matched_size); -/** - * Get the document revision number from document header (document attribute <code>revnumber</code>). - * @returns {string} - * @memberof Document/RevisionInfo - */ -RevisionInfo.prototype.getNumber = function () { - return this.number -} + self.matched = result[0]; + self.match = result; + self.prev_pos = self.pos + i; // Position of first character of matched + self.pos += matched_size; // Position one after last character of matched + self.working = working.substr(matched_size); -/** - * Get the document revision remark from document header (document attribute <code>revremark</code>). - * A short summary of changes in this document revision. - * @returns {string} - * @memberof Document/RevisionInfo - */ -RevisionInfo.prototype.getRemark = function () { - return this.remark -} + return matched + } + } + return self.matched = nil; + }); + + $def(self, '$[]', function $StringScanner_$$$2(idx) { + var self = this, $ret_or_1 = nil; -/** - * @returns {boolean} - true if the revision info is empty (ie. not defined), otherwise false - * @memberof Document/RevisionInfo - */ -RevisionInfo.prototype.isEmpty = function () { - return this.date === undefined && this.number === undefined && this.remark === undefined -} + + if ($truthy(self.match['$empty?']())) { + return nil + } if ($eqeqeq($$('Symbol'), ($ret_or_1 = idx))) { + idx = idx.$to_s(); + } else if (!$eqeqeq($$('String'), $ret_or_1)) { + idx = $Opal['$coerce_to!'](idx, $$('Integer'), "to_int"); + } + var match = self.match; -// SafeMode API + if (idx < 0) { + idx += match.length; + } -/** - * @namespace - */ -var SafeMode = Opal.Asciidoctor.SafeMode + if (idx < 0 || idx >= match.length) { + return nil; + } -/** - * @param {string} name - the name of the security level - * @returns {number} - the integer value of the corresponding security level - */ -SafeMode.getValueForName = function (name) { - return this.$value_for_name(name) -} + if (match[idx] == null) { + return nil; + } -/** - * @param {number} value - the integer value of the security level - * @returns {string} - the name of the corresponding security level - */ -SafeMode.getNameForValue = function (value) { - var name = this.$name_for_value(value) - return name === Opal.nil ? undefined : name -} + return match[idx]; + }); + + $def(self, '$check', function $$check(pattern) { + var self = this; -/** - * @returns {Array<string>} - the String {Array} of security levels - */ -SafeMode.getNames = function () { - return this.$names() -} + + pattern = self.$anchor(pattern); + + var result = pattern.exec(self.working); -// Callouts API + if (result == null) { + return self.matched = nil; + } -/** - * Maintains a catalog of callouts and their associations. - * @namespace - */ -var Callouts = Opal.Asciidoctor.Callouts + return self.matched = result[0]; + }); + + $def(self, '$check_until', function $$check_until(pattern) { + var self = this; -/** - * Create a new Callouts. - * @returns {Callouts} - a new Callouts - * @memberof Callouts - */ -Callouts.create = function () { - return this.$new() -} + + var old_prev_pos = self.prev_pos; + var old_pos = self.pos; + var old_working = self.working; -/** - * Register a new callout for the given list item ordinal. - * Generates a unique id for this callout based on the index of the next callout list in the document and the index of this callout since the end of the last callout list. - * - * @param {number} ordinal - the Integer ordinal (1-based) of the list item to which this callout is to be associated - * @returns {string} - The unique String id of this callout - * @example - * callouts = asciidoctor.Callouts.create() - * callouts.register(1) - * // => "CO1-1" - * callouts.nextList() - * callouts.register(2) - * // => "CO2-1" - * @memberof Callouts - */ + var result = self.$scan_until(pattern); -Callouts.prototype.register = function (ordinal) { - return this.$register(ordinal) -} -/** - * Get the next callout index in the document. - * - * Reads the next callout index in the document and advances the pointer. - * This method is used during conversion to retrieve the unique id of the callout that was generated during parsing. - * - * @returns {string} - The unique String id of the next callout in the document - * @memberof Callouts - */ -Callouts.prototype.readNextId = function () { - return this.$read_next_id() -} + self.prev_pos = old_prev_pos; + self.pos = old_pos; + self.working = old_working; -/** - * et a space-separated list of callout ids for the specified list item. - * @param {number} ordinal - the Integer ordinal (1-based) of the list item for which to retrieve the callouts - * @returns {string} - a space-separated String of callout ids associated with the specified list item - * @memberof Callouts - */ -Callouts.prototype.getCalloutIds = function (ordinal) { - return this.$callout_ids(ordinal) -} + return result; + + }); + + $def(self, '$peek', function $$peek(length) { + var self = this; -/** - * @memberof Callouts - */ -Callouts.prototype.getLists = function () { - var lists = this.lists - if (lists && lists.length > 0) { - for (var i = 0; i < lists.length; i++) { - var list = lists[i] - if (list && list.length > 0) { - for (var j = 0; j < list.length; j++) { - if (typeof list[j] === 'object' && '$$smap' in list[j]) { - list[j] = fromHash(list[j]) - } - } - } - } - } - return lists -} + return self.working.substring(0, length) + }); + + $def(self, '$eos?', function $StringScanner_eos$ques$3() { + var self = this; -/** - * @memberof Callouts - */ -Callouts.prototype.getListIndex = function () { - return this.list_index -} + return self.working.length === 0 + }); + + $def(self, '$exist?', function $StringScanner_exist$ques$4(pattern) { + var self = this; -/** - * The current list for which callouts are being collected. - * @returns {Array} - The Array of callouts at the position of the list index pointer - * @memberof Callouts - */ -Callouts.prototype.getCurrentList = function () { - var currentList = this.$current_list() - if (currentList && currentList.length > 0) { - for (var i = 0; i < currentList.length; i++) { - if (typeof currentList[i] === 'object' && '$$smap' in currentList[i]) { - currentList[i] = fromHash(currentList[i]) + + var result = pattern.exec(self.working); + + if (result == null) { + return nil; } - } - } - return currentList -} + else if (result.index == 0) { + return 0; + } + else { + return result.index + 1; + } + + }); + + $def(self, '$skip', function $$skip(pattern) { + var self = this; -/** - * Advance to the next callout list in the document. - * @memberof Callouts - */ -Callouts.prototype.nextList = function () { - return this.$nextList() -} + + pattern = self.$anchor(pattern); + + var result = pattern.exec(self.working); -/** - * Rewind the list index pointer, intended to be used when switching from the parsing to conversion phase. - * @memberof Callouts - */ -Callouts.prototype.rewind = function () { - return this.$rewind() -} + if (result == null) { + self.match = []; + return self.matched = nil; + } + else { + var match_str = result[0]; + var match_len = match_str.length; -/** - * @returns {Document/RevisionInfo} - a {@link Document/RevisionInfo} - * @memberof Document - */ -Document.prototype.getRevisionInfo = function () { - return new Document.RevisionInfo(this.getRevisionDate(), this.getRevisionNumber(), this.getRevisionRemark()) -} + self.matched = match_str; + self.match = result; + self.prev_pos = self.pos; + self.pos += match_len; + self.working = self.working.substring(match_len); -/** - * @returns {boolean} - true if the document contains revision info, otherwise false - * @memberof Document - */ -Document.prototype.hasRevisionInfo = function () { - var revisionInfo = this.getRevisionInfo() - return !revisionInfo.isEmpty() -} + return match_len; + } + }); + + $def(self, '$skip_until', function $$skip_until(pattern) { + var self = this; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.getNotitle = function () { - return this.$notitle() -} + + var result = self.$scan_until(pattern); -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.getNoheader = function () { - return this.$noheader() -} + if (result === nil) { + return nil; + } + else { + self.matched = result.substr(-1); -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.getNofooter = function () { - return this.$nofooter() -} + return result.length; + } + + }); + + $def(self, '$get_byte', function $$get_byte() { + var self = this; -/** - * @returns {boolean} - * @memberof Document - */ -Document.prototype.hasHeader = function () { - return this['$header?']() -} + + var result = nil; -/** - * Replay attribute assignments at the block level. - * - * <i>This method belongs to an internal API that deals with how attributes are managed by the processor.</i> - * If you understand why this group of methods are necessary, and what they do, feel free to use them. - * <strong>However, keep in mind they are subject to change at any time.</strong> - * - * @param {Object} blockAttributes - A JSON of attributes - * @memberof Document - */ -Document.prototype.playbackAttributes = function (blockAttributes) { - blockAttributes = toHash(blockAttributes) - if (blockAttributes) { - var attrEntries = blockAttributes['$[]']('attribute_entries') - if (attrEntries && Array.isArray(attrEntries)) { - var result = [] - for (var i = 0; i < attrEntries.length; i++) { - var attrEntryObject = attrEntries[i] - if (attrEntryObject && typeof attrEntryObject === 'object' && attrEntryObject.constructor.name === 'Object') { - attrEntryObject.$name = function () { - return this.name - } - attrEntryObject.$value = function () { - return this.value - } - attrEntryObject.$negate = function () { - return this.negate - } - } - result.push(attrEntryObject) + if (self.pos < self.string.length) { + self.prev_pos = self.pos; + self.pos += 1; + result = self.matched = self.working.substring(0, 1); + self.working = self.working.substring(1); + } + else { + self.matched = nil; } - blockAttributes['$[]=']('attribute_entries', result) - } - } - this.$playback_attributes(blockAttributes) -} -/** - * Delete the specified attribute from the document if the name is not locked. - * If the attribute is locked, false is returned. - * Otherwise, the attribute is deleted. - * - * @param {string} name - the String attribute name - * - * @returns {boolean} - true if the attribute was deleted, false if it was not because it's locked - * @memberof Document - */ -Document.prototype.deleteAttribute = function (name) { - return this.$delete_attribute(name) -} + return result; + + }); + + $def(self, '$match?', function $StringScanner_match$ques$5(pattern) { + var self = this; -/** - * Determine if the attribute has been locked by being assigned in document options. - * - * @param {string} key - The attribute key to check - * - * @returns {boolean} - true if the attribute is locked, false otherwise - * @memberof Document - */ -Document.prototype.isAttributeLocked = function (key) { - return this['$attribute_locked?'](key) -} + + pattern = self.$anchor(pattern); + + var result = pattern.exec(self.working); -/** - * Restore the attributes to the previously saved state (attributes in header). - * - * @memberof Document - */ -Document.prototype.restoreAttributes = function () { - return this.$restore_attributes() -} + if (result == null) { + return nil; + } + else { + self.prev_pos = self.pos; -/** - * Parse the AsciiDoc source stored in the {Reader} into an abstract syntax tree. - * - * If the data parameter is not nil, create a new {PreprocessorReader} and assigned it to the reader property of this object. - * Otherwise, continue with the reader that was created when the {Document} was instantiated. - * Pass the reader to {Parser.parse} to parse the source data into an abstract syntax tree. - * - * If parsing has already been performed, this method returns without performing any processing. - * - * @param {string|Array<string>} [data] - The optional replacement AsciiDoc source data as a String or String Array. (default: undefined) - * - * @returns {Document} - this {Document} - * @memberof Document - */ -Document.prototype.parse = function (data) { - return this.$parse(data) -} + return result[0].length; + } + }); + + $def(self, '$pos=', function $StringScanner_pos$eq$6(pos) { + var self = this; -/** - * @memberof Document - */ -Document.prototype.getDocinfo = function (docinfoLocation, suffix) { - return this.$docinfo(docinfoLocation, suffix) -} + + + if (pos < 0) { + pos += self.string.$length(); + } + self.pos = pos; + return (self.working = self.string.slice(pos)); + }); + + $def(self, '$matched_size', function $$matched_size() { + var self = this; -/** - * @param {string} [docinfoLocation] - A {string} for checking docinfo extensions at a given location (head or footer) (default: head) - * @returns {boolean} - * @memberof Document - */ -Document.prototype.hasDocinfoProcessors = function (docinfoLocation) { - return this['$docinfo_processors?'](docinfoLocation) -} + + if (self.matched === nil) { + return nil; + } -/** - * Increment the specified counter and store it in the block's attributes. - * - * @param {string} counterName - the String name of the counter attribute - * @param {Block} block - the {Block} on which to save the counter - * - * @returns {number} - the next number in the sequence for the specified counter - * @memberof Document - */ -Document.prototype.incrementAndStoreCounter = function (counterName, block) { - return this.$increment_and_store_counter(counterName, block) -} + return self.matched.length + + }); + + $def(self, '$post_match', function $$post_match() { + var self = this; -/** - * @deprecated Please use {Document#incrementAndStoreCounter} method. - * @memberof Document - */ -Document.prototype.counterIncrement = Document.prototype.incrementAndStoreCounter + + if (self.matched === nil) { + return nil; + } -/** - * Get the named counter and take the next number in the sequence. - * - * @param {string} name - the String name of the counter - * @param {string|number} seed - the initial value as a String or Integer - * - * @returns {number} the next number in the sequence for the specified counter - * @memberof Document - */ -Document.prototype.counter = function (name, seed) { - return this.$counter(name, seed) -} + return self.string.substr(self.pos); + + }); + + $def(self, '$pre_match', function $$pre_match() { + var self = this; -/** - * A read-only integer value indicating the level of security that should be enforced while processing this document. - * The value must be set in the Document constructor using the "safe" option. - * - * A value of 0 (UNSAFE) disables any of the security features enforced by Asciidoctor. - * - * A value of 1 (SAFE) closely parallels safe mode in AsciiDoc. - * In particular, it prevents access to files which reside outside of the parent directory of the source file and disables any macro other than the include directive. - * - * A value of 10 (SERVER) disallows the document from setting attributes that would affect the conversion of the document, - * in addition to all the security features of SafeMode.SAFE. - * For instance, this level forbids changing the backend or source-highlighter using an attribute defined in the source document header. - * This is the most fundamental level of security for server deployments (hence the name). - * - * A value of 20 (SECURE) disallows the document from attempting to read files from the file system and including the contents of them into the document, - * in addition to all the security features of SafeMode.SECURE. - * In particular, it disallows use of the include::[] directive and the embedding of binary content (data uri), stylesheets and JavaScripts referenced by the document. - * (Asciidoctor and trusted extensions may still be allowed to embed trusted content into the document). - * - * Since Asciidoctor is aiming for wide adoption, 20 (SECURE) is the default value and is recommended for server deployments. - * - * A value of 100 (PARANOID) is planned to disallow the use of passthrough macros and prevents the document from setting any known attributes, - * in addition to all the security features of SafeMode.SECURE. - * Please note that this level is not currently implemented (and therefore not enforced)! - * - * @returns {number} - An integer value indicating the level of security - * @memberof Document - */ -Document.prototype.getSafe = function () { - return this.safe -} + + if (self.matched === nil) { + return nil; + } -/** - * Get the Boolean AsciiDoc compatibility mode. - * Enabling this attribute activates the following syntax changes: - * - * * single quotes as constrained emphasis formatting marks - * * single backticks parsed as inline literal, formatted as monospace - * * single plus parsed as constrained, monospaced inline formatting - * * double plus parsed as constrained, monospaced inline formatting - * - * @returns {boolean} - * @memberof Document - */ -Document.prototype.getCompatMode = function () { - return this.compat_mode -} + return self.string.substr(0, self.prev_pos); + + }); + + $def(self, '$reset', function $$reset() { + var self = this; -/** - * Get the Boolean flag that indicates whether source map information should be tracked by the parser. - * @returns {boolean} - * @memberof Document - */ -Document.prototype.getSourcemap = function () { - var sourcemap = this.sourcemap - return sourcemap === Opal.nil ? false : sourcemap -} + + self.working = self.string; + self.matched = nil; + return (self.pos = 0); + }); + + $def(self, '$rest', $return_ivar("working")); + + $def(self, '$rest?', function $StringScanner_rest$ques$7() { + var self = this; -/** - * Set the Boolean flag that indicates whether source map information should be tracked by the parser. - * @param {boolean} value - * @memberof Document - */ -Document.prototype.setSourcemap = function (value) { - this.sourcemap = value -} + return self.working.length !== 0 + }); + + $def(self, '$rest_size', function $$rest_size() { + var self = this; -/** - * Get the JSON of document counters. - * @returns {Object} - * @memberof Document - */ -Document.prototype.getCounters = function () { - return fromHash(this.counters) -} + return self.$rest().$size() + }); + + $def(self, '$terminate', function $$terminate() { + var $a, self = this; -/** - * @returns {Object} - * @memberof Document - */ -Document.prototype.getCallouts = function () { - return this.$callouts() -} + + self.match = nil; + return ($a = [self.string.$length()], $send(self, 'pos=', $a), $a[$a.length - 1]); + }); + + $def(self, '$unscan', function $$unscan() { + var self = this; -/** - * Get the String base directory for converting this document. - * - * Defaults to directory of the source file. - * If the source is a string, defaults to the current directory. - * @returns {string} - * @memberof Document - */ -Document.prototype.getBaseDir = function () { - return this.base_dir -} + + self.pos = self.prev_pos; + self.prev_pos = nil; + self.match = nil; + return self; + }); + $alias(self, "bol?", "beginning_of_line?"); + $alias(self, "getch", "get_byte"); + self.$private(); + return $def(self, '$anchor', function $$anchor(pattern) { + + + var flags = pattern.toString().match(/\/([^\/]+)$/); + flags = flags ? flags[1] : undefined; + return new RegExp('^(?:' + pattern.source + ')', flags); + + }); + })($nesting[0], null, $nesting) +}; -/** - * Get the JSON of resolved options used to initialize this {Document}. - * @returns {Object} - * @memberof Document - */ -Document.prototype.getOptions = function () { - return fromHash(this.options) -} +Opal.modules["asciidoctor/js"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; -/** - * Get the outfilesuffix defined at the end of the header. - * @returns {string} - * @memberof Document - */ -Document.prototype.getOutfilesuffix = function () { - return this.outfilesuffix -} + Opal.add_stubs('require'); + + self.$require("asciidoctor/js/opal_ext"); + self.$require("asciidoctor/js/rx"); + return self.$require("strscan"); +}; -/** - * Get a reference to the parent Document of this nested document. - * @returns {Document|undefined} - * @memberof Document - */ -Document.prototype.getParentDocument = function () { - var parentDocument = this.parent_document - return parentDocument === Opal.nil ? undefined : parentDocument -} +Opal.modules["asciidoctor/core_ext/nil_or_empty"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $alias = Opal.alias, $nesting = [], nil = Opal.nil; -/** - * Get the {Reader} associated with this document. - * @returns {Object} - * @memberof Document - */ -Document.prototype.getReader = function () { - return this.reader -} + Opal.add_stubs('method_defined?,nil?,empty?'); + + (function($base, $super) { + var self = $klass($base, $super, 'NilClass'); -/** - * Get the {Converter} instance being used to convert the current {Document}. - * @returns {Object} - * @memberof Document - */ -Document.prototype.getConverter = function () { - return this.converter -} + + if ($truthy(self['$method_defined?']("nil_or_empty?"))) { + return nil + } else { + return $alias(self, "nil_or_empty?", "nil?") + } + })($nesting[0], null); + (function($base, $super) { + var self = $klass($base, $super, 'String'); -/** - * Get the activated {Extensions.Registry} associated with this document. - * @returns {Extensions/Registry} - * @memberof Document - */ -Document.prototype.getExtensions = function () { - var extensions = this.extensions - return extensions === Opal.nil ? undefined : extensions -} + + if ($truthy(self['$method_defined?']("nil_or_empty?"))) { + return nil + } else { + return $alias(self, "nil_or_empty?", "empty?") + } + })($nesting[0], null); + (function($base, $super) { + var self = $klass($base, $super, 'Array'); -// Document.Title API + + if ($truthy(self['$method_defined?']("nil_or_empty?"))) { + return nil + } else { + return $alias(self, "nil_or_empty?", "empty?") + } + })($nesting[0], null); + (function($base, $super) { + var self = $klass($base, $super, 'Hash'); -/** - * A partitioned title (i.e., title & subtitle). - * @namespace - * @module Document/Title - */ -var Title = Document.Title + + if ($truthy(self['$method_defined?']("nil_or_empty?"))) { + return nil + } else { + return $alias(self, "nil_or_empty?", "empty?") + } + })($nesting[0], null); + return (function($base, $super) { + var self = $klass($base, $super, 'Numeric'); -/** - * @returns {string} - * @memberof Document/Title - */ -Title.prototype.getMain = function () { - return this.main -} + + if ($truthy(self['$method_defined?']("nil_or_empty?"))) { + return nil + } else { + return $alias(self, "nil_or_empty?", "nil?") + } + })($nesting[0], null); +}; -/** - * @returns {string} - * @memberof Document/Title - */ -Title.prototype.getCombined = function () { - return this.combined -} +Opal.modules["asciidoctor/core_ext/hash/merge"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $eqeq = Opal.eqeq, $send = Opal.send, $slice = Opal.slice, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; -/** - * @returns {string} - * @memberof Document/Title - */ -Title.prototype.getSubtitle = function () { - var subtitle = this.subtitle - return subtitle === Opal.nil ? undefined : subtitle -} + Opal.add_stubs('==,arity,instance_method,send,new,<,length,dup,>,inject,merge,[]'); + if ($eqeq($$('Hash').$instance_method("merge").$arity(), 1)) { + return $$('Hash').$send("prepend", $send($$('Module'), 'new', [], function $$1(){var self = $$1.$$s == null ? this : $$1.$$s; -/** - * @returns {boolean} - * @memberof Document/Title - */ -Title.prototype.isSanitized = function () { - var sanitized = this['$sanitized?']() - return sanitized === Opal.nil ? false : sanitized -} + return $def(self, '$merge', function $$merge($a) { + var $post_args, args; $$merge.$$p || nil; var self = this, len = nil; -/** - * @returns {boolean} - * @memberof Document/Title - */ -Title.prototype.hasSubtitle = function () { - return this['$subtitle?']() -} + $$merge.$$p = null; + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy($rb_lt((len = args.$length()), 1))) { + return self.$dup() + } else { + + if ($truthy($rb_gt(len, 1))) { + return $send(args, 'inject', [self], function $$2(acc, arg){ + + if (acc == null) acc = nil; + if (arg == null) arg = nil; + return acc.$merge(arg);}) + } else { + + return $send2(self, $find_super(self, 'merge', $$merge, false, true), 'merge', [args['$[]'](0)], null); + } } }, -1)}, {$$s: self})) + } else { + return nil + } +}; -// Inline API +Opal.modules["asciidoctor/core_ext/match_data/names"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $klass = Opal.klass, $def = Opal.def, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; -/** - * Methods for managing inline elements in AsciiDoc block. - * @namespace - * @extends AbstractNode - */ -var Inline = Opal.Asciidoctor.Inline + Opal.add_stubs('method_defined?'); + if ($truthy($$('MatchData')['$method_defined?']("names"))) { + return nil + } else { + return (function($base, $super) { + var self = $klass($base, $super, 'MatchData'); -/** - * Create a new Inline element. - * @param {AbstractBlock} parent - * @param {string} context - * @param {string|undefined} text - * @param {Object|undefined} opts - * @returns {Inline} - a new Inline element - * @memberof Inline - */ -Inline.create = function (parent, context, text, opts) { - return this.$new(parent, context, text, prepareOptions(opts)) -} + + return $def(self, '$names', function $$names() { + + return [] + }) + })($nesting[0], null) + } +}; -/** - * Get the converted content for this inline node. - * - * @returns {string} - the converted String content for this inline node - * @memberof Inline - */ -Inline.prototype.convert = function () { - return this.$convert() -} +Opal.modules["asciidoctor/core_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; -/** - * Get the converted String text of this Inline node, if applicable. - * - * @returns {string|undefined} - the converted String text for this Inline node, or undefined if not applicable for this node. - * @memberof Inline - */ -Inline.prototype.getText = function () { - var text = this.$text() - return text === Opal.nil ? undefined : text -} + + self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/nil_or_empty"); + self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/hash/merge"); + return self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/match_data/names"); +}; -/** - * Get the String sub-type (aka qualifier) of this Inline node. - * - * This value is used to distinguish different variations of the same node - * category, such as different types of anchors. - * - * @returns {string} - the string sub-type of this Inline node. - * @memberof Inline - */ -Inline.prototype.getType = function () { - return this.$type() -} +Opal.modules["asciidoctor/helpers"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $gvars = Opal.gvars, $def = Opal.def, $send = Opal.send, $neqeq = Opal.neqeq, $const_set = Opal.const_set, $hash2 = Opal.hash2, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $Class = Opal.Class, $Object = Opal.Object, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Get the primary String target of this Inline node. - * - * @returns {string|undefined} - the string target of this Inline node. - * @memberof Inline - */ -Inline.prototype.getTarget = function () { - var target = this.$target() - return target === Opal.nil ? undefined : target -} + Opal.add_stubs('module_function,require,include?,include,==,path,message,raise,warn,logger,chomp,empty?,slice,unpack,[],[]=,byteslice,bytesize,map,rstrip,encode,encoding,nil_or_empty?,!=,tap,each_line,<<,!,start_with?,match?,gsub,rindex,index,basename,extname,length,directory?,dirname,mkdir_p,mkdir,private_constant,join,divmod,*,===,+,to_s,to_i,succ,class_for_name,const_get'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * Returns the converted alt text for this inline image. - * - * @returns {string} - the String value of the alt attribute. - * @memberof Inline - */ -Inline.prototype.getAlt = function () { - return this.$alt() -} + var $nesting = [self].concat($parent_nesting); -// List API + return (function($base, $parent_nesting) { + var self = $module($base, 'Helpers'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + self.$module_function(); + + $def(self, '$require_library', function $$require_library(name, gem_name, on_failure) { + var self = this, details = nil; + if ($gvars["!"] == null) $gvars["!"] = nil; + + + if (gem_name == null) gem_name = true; + if (on_failure == null) on_failure = "abort"; + try { + return self.$require(name) + } catch ($err) { + if (Opal.rescue($err, [$$$('LoadError')])) { + try { + + if (!$truthy(self['$include?']($$('Logging')))) { + self.$include($$('Logging')); + }; + if ($truthy(gem_name)) { + + if ($eqeq(gem_name, true)) { + gem_name = name; + }; + + switch (on_failure) { + case "abort": + + details = ($eqeq($gvars["!"].$path(), gem_name) ? ("") : (" (reason: " + (($truthy($gvars["!"].$path()) ? ("cannot load '" + ($gvars["!"].$path()) + "'") : ($gvars["!"].$message()))) + ")")); + self.$raise($$$('LoadError'), "asciidoctor: FAILED: required gem '" + (gem_name) + "' is not available" + (details) + ". Processing aborted."); + break; + case "warn": + + details = ($eqeq($gvars["!"].$path(), gem_name) ? ("") : (" (reason: " + (($truthy($gvars["!"].$path()) ? ("cannot load '" + ($gvars["!"].$path()) + "'") : ($gvars["!"].$message()))) + ")")); + self.$logger().$warn("optional gem '" + (gem_name) + "' is not available" + (details) + ". Functionality disabled."); + break; + default: + nil; + }; + } else + switch (on_failure) { + case "abort": + self.$raise($$$('LoadError'), "asciidoctor: FAILED: " + ($gvars["!"].$message().$chomp(".")) + ". Processing aborted."); + break; + case "warn": + self.$logger().$warn("" + ($gvars["!"].$message().$chomp(".")) + ". Functionality disabled."); + break; + default: + nil; + }; + return nil; + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -2); + + $def(self, '$prepare_source_array', function $$prepare_source_array(data, trim_end) { + var leading_2_bytes = nil, leading_bytes = nil, first = nil; -/** - * Methods for managing AsciiDoc lists (ordered, unordered and description lists). - * @namespace - * @extends AbstractBlock - */ -var List = Opal.Asciidoctor.List + + if (trim_end == null) trim_end = true; + if ($truthy(data['$empty?']())) { + return [] + } if ($eqeq((leading_2_bytes = (leading_bytes = (first = data['$[]'](0)).$unpack("C3")).$slice(0, 2)), $$('BOM_BYTES_UTF_16LE'))) { + + data['$[]='](0, first.$byteslice(2, first.$bytesize())); + return ($truthy(trim_end) ? ($send(data, 'map', [], function $$1(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE')).$rstrip();})) : ($send(data, 'map', [], function $$2(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE')).$chomp();}))); + } else if ($eqeq(leading_2_bytes, $$('BOM_BYTES_UTF_16BE'))) { + + data['$[]='](0, first.$byteslice(2, first.$bytesize())); + return ($truthy(trim_end) ? ($send(data, 'map', [], function $$3(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE')).$rstrip();})) : ($send(data, 'map', [], function $$4(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE')).$chomp();}))); + } else if ($eqeq(leading_bytes, $$('BOM_BYTES_UTF_8'))) { + data['$[]='](0, first.$byteslice(3, first.$bytesize())); + } if ($eqeq(first.$encoding(), $$('UTF_8'))) { + if ($truthy(trim_end)) { + return $send(data, 'map', [], function $$5(line){ + + if (line == null) line = nil; + return line.$rstrip();}) + } else { + return $send(data, 'map', [], function $$6(line){ + + if (line == null) line = nil; + return line.$chomp();}) + } + } else if ($truthy(trim_end)) { + return $send(data, 'map', [], function $$7(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8')).$rstrip();}) + } else { + return $send(data, 'map', [], function $$8(line){ + + if (line == null) line = nil; + return line.$encode($$('UTF_8')).$chomp();}) + } }, -2); + + $def(self, '$prepare_source_string', function $$prepare_source_string(data, trim_end) { + var leading_2_bytes = nil, leading_bytes = nil; -/** - * Checks if the {@link List} contains any child {@link ListItem}. - * - * @memberof List - * @returns {boolean} - whether the {@link List} has child {@link ListItem}. - */ -List.prototype.hasItems = function () { - return this['$items?']() -} + + if (trim_end == null) trim_end = true; + if ($truthy(data['$nil_or_empty?']())) { + return [] + } if ($eqeq((leading_2_bytes = (leading_bytes = data.$unpack("C3")).$slice(0, 2)), $$('BOM_BYTES_UTF_16LE'))) { + data = data.$byteslice(2, data.$bytesize()).$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE')); + } else if ($eqeq(leading_2_bytes, $$('BOM_BYTES_UTF_16BE'))) { + data = data.$byteslice(2, data.$bytesize()).$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE')); + } else if ($eqeq(leading_bytes, $$('BOM_BYTES_UTF_8'))) { + + data = data.$byteslice(3, data.$bytesize()); + if (!$eqeq(data.$encoding(), $$('UTF_8'))) { + data = data.$encode($$('UTF_8')); + } } else if ($neqeq(data.$encoding(), $$('UTF_8'))) { + data = data.$encode($$('UTF_8')); + } if ($truthy(trim_end)) { + return $send([], 'tap', [], function $$9(lines){ + + if (lines == null) lines = nil; + return $send(data, 'each_line', [], function $$10(line){ + + if (line == null) line = nil; + return lines['$<<'](line.$rstrip());});}) + } else { + return $send([], 'tap', [], function $$11(lines){ + + if (lines == null) lines = nil; + return $send(data, 'each_line', [], function $$12(line){ + + if (line == null) line = nil; + return lines['$<<'](line.$chomp());});}) + } }, -2); + if ($eqeq($$$('RUBY_ENGINE'), "jruby")) { + + $def(self, '$uriish?', function $Helpers_uriish$ques$13(str) { + var $ret_or_1 = nil, $ret_or_2 = nil; -/** - * Get the Array of {@link ListItem} nodes for this {@link List}. - * - * @returns {Array<ListItem>} - an Array of {@link ListItem} nodes. - * @memberof List - */ -List.prototype.getItems = function () { - return this.blocks -} + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = str['$include?'](":"))) ? (str['$start_with?']("uri:classloader:")['$!']()) : ($ret_or_2))))) { + + return $$('UriSniffRx')['$match?'](str); + } else { + return $ret_or_1 + } + }); + } else { + + $def(self, '$uriish?', function $Helpers_uriish$ques$14(str) { + var $ret_or_1 = nil; -// ListItem API + if ($truthy(($ret_or_1 = str['$include?'](":")))) { + + return $$('UriSniffRx')['$match?'](str); + } else { + return $ret_or_1 + } + }); + } + $def(self, '$encode_uri_component', function $$encode_uri_component(str) { + + + return encodeURIComponent(str).replace(/%20|[!'()*]/g, function (m) { + return m === '%20' ? '+' : '%' + m.charCodeAt(0).toString(16) + }) + + }); + + $def(self, '$encode_spaces_in_uri', function $$encode_spaces_in_uri(str) { + + if ($truthy(str['$include?'](" "))) { + + return str.$gsub(" ", "%20"); + } else { + return str + } + }); + + $def(self, '$rootname', function $$rootname(filename) { + var last_dot_idx = nil; -/** - * Methods for managing items for AsciiDoc olists, ulist, and dlists. - * - * In a description list (dlist), each item is a tuple that consists of a 2-item Array of ListItem terms and a ListItem description (i.e., [[term, term, ...], desc]. - * If a description is not set, then the second entry in the tuple is nil. - * @namespace - * @extends AbstractBlock - */ -var ListItem = Opal.Asciidoctor.ListItem + if ($truthy((last_dot_idx = filename.$rindex(".")))) { + if ($truthy(filename.$index("/", last_dot_idx))) { + return filename + } else { + + return filename.$slice(0, last_dot_idx); + } + } else { + return filename + } + }); + + $def(self, '$basename', function $$basename(filename, drop_ext) { + var self = this; -/** - * Get the converted String text of this {@link ListItem} node. - * - * @returns {string} - the converted String text for this {@link ListItem} node. - * @memberof ListItem - */ -ListItem.prototype.getText = function () { - return this.$text() -} + + if (drop_ext == null) drop_ext = nil; + if ($truthy(drop_ext)) { + return $$$('File').$basename(filename, ($eqeq(drop_ext, true) ? (self.$extname(filename)) : (drop_ext))) + } else { + return $$$('File').$basename(filename) + } }, -2); + + $def(self, '$extname?', function $Helpers_extname$ques$15(path) { + var $ret_or_1 = nil, last_dot_idx = nil; -/** - * Set the String source text of this {@link ListItem} node. - * - * @returns {string} - the new String text assigned to this {@link ListItem} - * @memberof ListItem - */ -ListItem.prototype.setText = function (text) { - return this['$text='](text) -} + if ($truthy(($ret_or_1 = (last_dot_idx = path.$rindex("."))))) { + return path.$index("/", last_dot_idx)['$!']() + } else { + return $ret_or_1 + } + }); + if ($truthy($$$($$$('File'), 'ALT_SEPARATOR'))) { + + $def(self, '$extname', function $$extname(path, fallback) { + var last_dot_idx = nil; -/** - * A convenience method that checks whether the text of this {@link ListItem} is not blank (i.e. not undefined or empty string). - * - * @returns {boolean} - whether the text is not blank - * @memberof ListItem - */ -ListItem.prototype.hasText = function () { - return this['$text?']() -} + + if (fallback == null) fallback = ""; + if ($truthy((last_dot_idx = path.$rindex(".")))) { + if (($truthy(path.$index("/", last_dot_idx)) || ($truthy(path.$index($$$($$$('File'), 'ALT_SEPARATOR'), last_dot_idx))))) { + return fallback + } else { + + return path.$slice(last_dot_idx, path.$length()); + } + } else { + return fallback + } }, -2); + } else { + + $def(self, '$extname', function $$extname(path, fallback) { + var last_dot_idx = nil; -/** - * Get the {string} used to mark this {@link ListItem}. - * - * @returns {string} - * @memberof ListItem - */ -ListItem.prototype.getMarker = function () { - return this.marker -} + + if (fallback == null) fallback = ""; + if ($truthy((last_dot_idx = path.$rindex(".")))) { + if ($truthy(path.$index("/", last_dot_idx))) { + return fallback + } else { + + return path.$slice(last_dot_idx, path.$length()); + } + } else { + return fallback + } }, -2); + } + $def(self, '$mkdir_p', function $$mkdir_p(dir) { + var self = this, parent_dir = nil; -/** - * Set the {string} used to mark this {@link ListItem}. - * - * @param {string} marker - the {string} used to mark this {@link ListItem} - * @memberof ListItem - */ -ListItem.prototype.setMarker = function (marker) { - this.marker = marker -} + if ($truthy($$$('File')['$directory?'](dir))) { + return nil + } else { + + if (!$eqeq((parent_dir = $$$('File').$dirname(dir)), ".")) { + self.$mkdir_p(parent_dir); + } + try { + return $$$('Dir').$mkdir(dir) + } catch ($err) { + if (Opal.rescue($err, [$$$('SystemCallError')])) { + try { + if ($truthy($$$('File')['$directory?'](dir))) { + return nil + } else { + return self.$raise() + } + } finally { Opal.pop_exception(); } + } else { throw $err; } + } } + }); + $const_set($nesting[0], 'ROMAN_NUMERALS', $hash2(["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"], {"M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1})); + self.$private_constant("ROMAN_NUMERALS"); + + $def(self, '$int_to_roman', function $$int_to_roman(val) { + + return $send($$('ROMAN_NUMERALS'), 'map', [], function $$16(l, i){var $a, $b, repeat = nil; -/** - * Get the {@link List} to which this {@link ListItem} is attached. - * - * @returns {List} - the {@link List} object to which this {@link ListItem} is attached, - * or undefined if this node has no parent. - * @memberof ListItem - */ -ListItem.prototype.getList = function () { - return this.$list() -} + + if (l == null) l = nil; + if (i == null) i = nil; + $b = val.$divmod(i), $a = $to_ary($b), (repeat = ($a[0] == null ? nil : $a[0])), (val = ($a[1] == null ? nil : $a[1])); + return $rb_times(l, repeat);}).$join() + }); + + $def(self, '$nextval', function $$nextval(current) { + var intval = nil; -/** - * @see {@link ListItem#getList} - * @memberof ListItem - */ -ListItem.prototype.getParent = ListItem.prototype.getList + if ($eqeqeq($$$('Integer'), current)) { + return $rb_plus(current, 1) + } else if ($eqeq((intval = current.$to_i()).$to_s(), current.$to_s())) { + return $rb_plus(intval, 1) + } else { + return current.$succ() + } + }); + + $def(self, '$resolve_class', function $$resolve_class(object) { + var self = this; -// Reader API + if ($eqeqeq($Class, object)) { + return object + } else { + + if ($eqeqeq($$$('String'), object)) { + + return self.$class_for_name(object); + } else { + return nil + } } + }); + return $def(self, '$class_for_name', function $$class_for_name(qualified_name) { + var self = this, resolved = nil; -/** @namespace */ -var Reader = Opal.Asciidoctor.Reader + try { + + if (!$eqeqeq($Class, (resolved = $Object.$const_get(qualified_name, false)))) { + self.$raise(); + }; + return resolved; + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return self.$raise($$$('NameError'), "Could not resolve class for name: " + (qualified_name)) + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + })($nesting[0], $nesting) + })($nesting[0], $nesting) +}; -/** - * Push source onto the front of the reader and switch the context based on the file, document-relative path and line information given. - * - * This method is typically used in an IncludeProcessor to add source read from the target specified. - * - * @param {string} data - * @param {string|undefined} file - * @param {string|undefined} path - * @param {number} lineno - The line number - * @param {Object} attributes - a JSON of attributes - * @returns {Reader} - this {Reader} object. - * @memberof Reader - */ -Reader.prototype.pushInclude = function (data, file, path, lineno, attributes) { - return this.$push_include(data, file, path, lineno, toHash(attributes)) -} +Opal.modules["logger"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_le = Opal.rb_le, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Get the current location of the reader's cursor, which encapsulates the file, dir, path, and lineno of the file being read. - * - * @returns {Cursor} - * @memberof Reader - */ -Reader.prototype.getCursor = function () { - return this.$cursor() -} + Opal.add_stubs('include,to_h,map,constants,const_get,to_s,format,chr,strftime,message_as_string,===,+,message,class,join,backtrace,inspect,attr_reader,attr_accessor,new,key,upcase,raise,add,to_proc,<=,<,write,call,[],now'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Logger'); -/** - * Get the remaining unprocessed lines, without consuming them, as an {Array} of {string}. - * - * Lines will not be consumed from the Reader (ie. you will be able to read these lines again). - * - * @returns {Array<string>} - the remaining unprocessed lines as an {Array} of {string}. - * @memberof Reader - */ -Reader.prototype.getLines = function () { - return this.$lines() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * Get the remaining unprocessed lines, without consuming them, as a {string}. - * - * Lines will not be consumed from the Reader (ie. you will be able to read these lines again). - * - * @returns {string} - the remaining unprocessed lines as a {string} (joined by linefeed characters). - * @memberof Reader - */ -Reader.prototype.getString = function () { - return this.$string() -} + $proto.level = $proto.progname = $proto.pipe = $proto.formatter = nil; + + (function($base, $parent_nesting) { + var self = $module($base, 'Severity'); -/** - * Check whether there are any lines left to read. - * If a previous call to this method resulted in a value of false, immediately returned the cached value. - * Otherwise, delegate to peekLine to determine if there is a next line available. - * - * @returns {boolean} - true if there are more lines, false if there are not. - * @memberof Reader - */ -Reader.prototype.hasMoreLines = function () { - return this['$has_more_lines?']() -} + var $nesting = [self].concat($parent_nesting); -/** - * Check whether this reader is empty (contains no lines). - * - * @returns {boolean} - true if there are no more lines to peek, otherwise false. - * @memberof Reader - */ -Reader.prototype.isEmpty = function () { - return this['$empty?']() -} + + $const_set($nesting[0], 'DEBUG', 0); + $const_set($nesting[0], 'INFO', 1); + $const_set($nesting[0], 'WARN', 2); + $const_set($nesting[0], 'ERROR', 3); + $const_set($nesting[0], 'FATAL', 4); + return $const_set($nesting[0], 'UNKNOWN', 5); + })($nesting[0], $nesting); + self.$include($$('Severity')); + $const_set($nesting[0], 'SEVERITY_LABELS', $send($$('Severity').$constants(), 'map', [], function $Logger$1(s){ + + if (s == null) s = nil; + return [$$('Severity').$const_get(s), s.$to_s()];}).$to_h()); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Formatter'); -/** - * Peek at the next line. - * Processes the line if not already marked as processed, but does not consume it (ie. you will be able to read this line again). - * - * This method will probe the reader for more lines. - * If there is a next line that has not previously been visited, the line is passed to the Reader#processLine method to be initialized. - * This call gives sub-classes the opportunity to do preprocessing. - * If the return value of the Reader#processLine is undefined, the data is assumed to be changed and Reader#peekLine is invoked again to perform further processing. - * - * If hasMoreLines is called immediately before peekLine, the direct flag is implicitly true (since the line is flagged as visited). - * - * @param {boolean} direct - A {boolean} flag to bypasses the check for more lines and immediately returns the first element of the internal lines {Array}. (default: false) - * @returns {string} - the next line as a {string} if there are lines remaining. - * @memberof Reader - */ -Reader.prototype.peekLine = function (direct) { - direct = direct || false - var line = this.$peek_line(direct) - return line === Opal.nil ? undefined : line -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Consume, preprocess, and return the next line. - * - * Line will be consumed from the Reader (ie. you won't be able to read this line again). - * - * @returns {string} - the next line as a {string} if data is present. - * @memberof Reader - */ -Reader.prototype.readLine = function () { - var line = this.$read_line() - return line === Opal.nil ? undefined : line -} + + $const_set($nesting[0], 'MESSAGE_FORMAT', "%s, [%s] %5s -- %s: %s\n"); + $const_set($nesting[0], 'DATE_TIME_FORMAT', "%Y-%m-%dT%H:%M:%S.%6N"); + + $def(self, '$call', function $$call(severity, time, progname, msg) { + var self = this; -/** - * Consume, preprocess, and return the remaining lines. - * - * This method calls Reader#readLine repeatedly until all lines are consumed and returns the lines as an {Array} of {string}. - * This method differs from Reader#getLines in that it processes each line in turn, hence triggering any preprocessors implemented in sub-classes. - * - * Lines will be consumed from the Reader (ie. you won't be able to read these lines again). - * - * @returns {Array<string>} - the lines read as an {Array} of {string}. - * @memberof Reader - */ -Reader.prototype.readLines = function () { - return this.$read_lines() -} + return self.$format($$('MESSAGE_FORMAT'), severity.$chr(), time.$strftime($$('DATE_TIME_FORMAT')), severity, progname, self.$message_as_string(msg)) + }); + return $def(self, '$message_as_string', function $$message_as_string(msg) { + var $ret_or_1 = nil, $ret_or_2 = nil; -/** - * Consume, preprocess, and return the remaining lines joined as a {string}. - * - * Delegates to Reader#readLines, then joins the result. - * - * Lines will be consumed from the Reader (ie. you won't be able to read these lines again). - * - * @returns {string} - the lines read joined as a {string} - * @memberof Reader - */ -Reader.prototype.read = function () { - return this.$read() -} + if ($eqeqeq($$$('String'), ($ret_or_1 = msg))) { + return msg + } else if ($eqeqeq($$$('Exception'), $ret_or_1)) { + return $rb_plus("" + (msg.$message()) + " (" + (msg.$class()) + ")\n", ($truthy(($ret_or_2 = msg.$backtrace())) ? ($ret_or_2) : ([])).$join("\n")) + } else { + return msg.$inspect() + } + }); + })($nesting[0], null, $nesting); + self.$attr_reader("level"); + self.$attr_accessor("progname"); + self.$attr_accessor("formatter"); + + $def(self, '$initialize', function $$initialize(pipe) { + var self = this; -/** - * Advance to the next line by discarding the line at the front of the stack. - * - * @returns {boolean} - a Boolean indicating whether there was a line to discard. - * @memberof Reader - */ -Reader.prototype.advance = function () { - return this.$advance() -} + + self.pipe = pipe; + self.level = $$('DEBUG'); + return (self.formatter = $$('Formatter').$new()); + }); + + $def(self, '$level=', function $Logger_level$eq$2(severity) { + var self = this, level = nil; -// Cursor API + if ($eqeqeq($$$('Integer'), severity)) { + return (self.level = severity) + } else if ($truthy((level = $$('SEVERITY_LABELS').$key(severity.$to_s().$upcase())))) { + return (self.level = level) + } else { + return self.$raise($$('ArgumentError'), "invalid log level: " + (severity)) + } + }); + + $def(self, '$info', function $$info(progname) { + var block = $$info.$$p || nil, self = this; -/** @namespace */ -var Cursor = Opal.Asciidoctor.Reader.Cursor + $$info.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('INFO'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$debug', function $$debug(progname) { + var block = $$debug.$$p || nil, self = this; -/** - * Get the file associated to the cursor. - * @returns {string|undefined} - * @memberof Cursor - */ -Cursor.prototype.getFile = function () { - var file = this.file - return file === Opal.nil ? undefined : file -} + $$debug.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('DEBUG'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$warn', function $$warn(progname) { + var block = $$warn.$$p || nil, self = this; -/** - * Get the directory associated to the cursor. - * @returns {string|undefined} - the directory associated to the cursor - * @memberof Cursor - */ -Cursor.prototype.getDirectory = function () { - var dir = this.dir - return dir === Opal.nil ? undefined : dir -} + $$warn.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('WARN'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$error', function $$error(progname) { + var block = $$error.$$p || nil, self = this; -/** - * Get the path associated to the cursor. - * @returns {string|undefined} - the path associated to the cursor (or '<stdin>') - * @memberof Cursor - */ -Cursor.prototype.getPath = function () { - var path = this.path - return path === Opal.nil ? undefined : path -} + $$error.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('ERROR'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$fatal', function $$fatal(progname) { + var block = $$fatal.$$p || nil, self = this; -/** - * Get the line number of the cursor. - * @returns {number|undefined} - the line number of the cursor - * @memberof Cursor - */ -Cursor.prototype.getLineNumber = function () { - return this.lineno -} + $$fatal.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('FATAL'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$unknown', function $$unknown(progname) { + var block = $$unknown.$$p || nil, self = this; -// Logger API (available in Asciidoctor 1.5.7+) + $$unknown.$$p = null; + if (progname == null) progname = nil; + return $send(self, 'add', [$$('UNKNOWN'), nil, progname], block.$to_proc()); + }, -1); + + $def(self, '$info?', function $Logger_info$ques$3() { + var self = this; -function initializeLoggerFormatterClass (className, functions) { - var superclass = Opal.const_get_qualified(Opal.Logger, 'Formatter') - return initializeClass(superclass, className, functions, {}, { - call: function (args) { - for (var i = 0; i < args.length; i++) { - // convert all (Opal) Hash arguments to JSON. - if (typeof args[i] === 'object' && '$$smap' in args[i]) { - args[i] = fromHash(args[i]) - } - } - return args - } - }) -} + return $rb_le(self.level, $$('INFO')) + }); + + $def(self, '$debug?', function $Logger_debug$ques$4() { + var self = this; -function initializeLoggerClass (className, functions) { - var superClass = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger') - return initializeClass(superClass, className, functions, {}, { - add: function (args) { - if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) { - var message = args[2] - var messageObject = fromHash(message) - messageObject.getText = function () { - return this.text - } - messageObject.getSourceLocation = function () { - return this.source_location - } - messageObject.$inspect = function () { - var sourceLocation = this.getSourceLocation() - if (sourceLocation) { - return sourceLocation.getPath() + ': line ' + sourceLocation.getLineNumber() + ': ' + this.getText() - } else { - return this.getText() - } - } - args[2] = messageObject - } - if (args.length >= 1) { - args[1] = args[1] === Opal.nil ? undefined : args[1] - } - return args - } - }) -} + return $rb_le(self.level, $$('DEBUG')) + }); + + $def(self, '$warn?', function $Logger_warn$ques$5() { + var self = this; -/** - * @namespace - */ -var LoggerManager = Opal.const_get_qualified(Opal.Asciidoctor, 'LoggerManager', true) + return $rb_le(self.level, $$('WARN')) + }); + + $def(self, '$error?', function $Logger_error$ques$6() { + var self = this; -// Alias -Opal.Asciidoctor.LoggerManager = LoggerManager + return $rb_le(self.level, $$('ERROR')) + }); + + $def(self, '$fatal?', function $Logger_fatal$ques$7() { + var self = this; -/** - * @memberof LoggerManager - */ -LoggerManager.getLogger = function () { - return this.$logger() -} + return $rb_le(self.level, $$('FATAL')) + }); + return $def(self, '$add', function $$add(severity, message, progname) { + var block = $$add.$$p || nil, self = this, $ret_or_1 = nil; -/** - * @memberof LoggerManager - */ -LoggerManager.setLogger = function (logger) { - this['$logger='](logger) -} + $$add.$$p = null; + if (message == null) message = nil; + if (progname == null) progname = nil; + if ($truthy($rb_lt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), self.level))) { + return true + } progname = ($truthy(($ret_or_1 = progname)) ? ($ret_or_1) : (self.progname)); + if (!$truthy(message)) { + if ((block !== nil)) { + message = Opal.yieldX(block, []); + } else { + + message = progname; + progname = self.progname; + } + } self.pipe.$write(self.formatter.$call(($truthy(($ret_or_1 = $$('SEVERITY_LABELS')['$[]'](severity))) ? ($ret_or_1) : ("ANY")), $$$('Time').$now(), progname, message)); + return true; + }, -2); + })($nesting[0], null, $nesting) +}; -/** - * @memberof LoggerManager - */ -LoggerManager.newLogger = function (name, functions) { - return initializeLoggerClass(name, functions).$new() -} +Opal.modules["asciidoctor/logging"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $send = Opal.send, $def = Opal.def, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $const_set = Opal.const_set, $hash2 = Opal.hash2, $eqeqeq = Opal.eqeqeq, $gvars = Opal.gvars, $alias = Opal.alias, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * @memberof LoggerManager - */ -LoggerManager.newFormatter = function (name, functions) { - return initializeLoggerFormatterClass(name, functions).$new() -} + Opal.add_stubs('require,attr_reader,progname=,formatter=,new,level=,>,[],===,inspect,to_h,map,constants,const_get,<<,clear,empty?,max,attr_accessor,memoize_logger,private,logger,extend,private_class_method,merge'); + + self.$require("logger"); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @namespace - */ -var LoggerSeverity = Opal.const_get_qualified(Opal.Logger, 'Severity', true) + var $nesting = [self].concat($parent_nesting); -// Alias -Opal.Asciidoctor.LoggerSeverity = LoggerSeverity + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Logger'); -/** - * @memberof LoggerSeverity - */ -LoggerSeverity.get = function (severity) { - return LoggerSeverity.$constants()[severity] -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * @namespace - */ -var LoggerFormatter = Opal.const_get_qualified(Opal.Logger, 'Formatter', true) + $proto.max_severity = nil; + + self.$attr_reader("max_severity"); + + $def(self, '$initialize', function $$initialize($a) { + var $post_args, args, $b, $yield = $$initialize.$$p || nil, self = this; -// Alias -Opal.Asciidoctor.LoggerFormatter = LoggerFormatter + $$initialize.$$p = null; + + $post_args = $slice(arguments); + args = $post_args; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', $to_a(args), $yield); + self['$progname=']("asciidoctor"); + self['$formatter=']($$('BasicFormatter').$new()); + return ($b = [$$('WARN')], $send(self, 'level=', $b), $b[$b.length - 1]); + }, -1); + + $def(self, '$add', function $$add(severity, message, progname) { + var $yield = $$add.$$p || nil, self = this, $ret_or_1 = nil; -/** - * @memberof LoggerFormatter - */ -LoggerFormatter.prototype.call = function (severity, time, programName, message) { - return this.$call(LoggerSeverity.get(severity), time, programName, message) -} + $$add.$$p = null; + + if (message == null) message = nil; + if (progname == null) progname = nil; + if ($truthy($rb_gt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), (self.max_severity = ($truthy(($ret_or_1 = self.max_severity)) ? ($ret_or_1) : (severity)))))) { + self.max_severity = severity; + } return $send2(self, $find_super(self, 'add', $$add, false, true), 'add', [severity, message, progname], $yield); + }, -2); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'BasicFormatter'); -/** - * @namespace - */ -var MemoryLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'MemoryLogger', true) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -// Alias -Opal.Asciidoctor.MemoryLogger = MemoryLogger + + $const_set($nesting[0], 'SEVERITY_LABEL_SUBSTITUTES', $hash2(["WARN", "FATAL"], {"WARN": "WARNING", "FATAL": "FAILED"})); + return $def(self, '$call', function $$call(severity, _, progname, msg) { + var $ret_or_1 = nil; -/** - * Create a new MemoryLogger. - * @returns {MemoryLogger} - a MemoryLogger - * @memberof MemoryLogger - */ -MemoryLogger.create = function () { - return this.$new() -} + return "" + (progname) + ": " + (($truthy(($ret_or_1 = $$('SEVERITY_LABEL_SUBSTITUTES')['$[]'](severity))) ? ($ret_or_1) : (severity))) + ": " + (($eqeqeq($$$('String'), msg) ? (msg) : (msg.$inspect()))) + ($$('LF')) + }); + })($nesting[0], $$('Formatter'), $nesting); + return (function($base) { + var self = $module($base, 'AutoFormattingMessage'); -/** - * @returns {Array<Object>} - a list of messages - * @memberof MemoryLogger - */ -MemoryLogger.prototype.getMessages = function () { - var messages = this.messages - var result = [] - for (var i = 0; i < messages.length; i++) { - var message = messages[i] - var messageObject = fromHash(message) - if (typeof messageObject.message === 'string') { - messageObject.getText = function () { - return this.message - } - } else { - // also convert the message attribute - messageObject.message = fromHash(messageObject.message) - messageObject.getText = function () { - return this.message.text - } - } - messageObject.getSeverity = function () { - return this.severity.toString() - } - messageObject.getSourceLocation = function () { - return this.message.source_location - } - result.push(messageObject) - } - return result -} + + return $def(self, '$inspect', function $$inspect() { + var self = this, sloc = nil; -var Logging = Opal.const_get_qualified(Opal.Asciidoctor, 'Logging', true) + if ($truthy((sloc = self['$[]']("source_location")))) { + return "" + (sloc) + ": " + (self['$[]']("text")) + } else { + return self['$[]']("text") + } + }) + })($nesting[0]); + })($nesting[0], $$$('Logger'), $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'MemoryLogger'); -Opal.Asciidoctor.Logging = Logging + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -Logging.getLogger = function () { - return LoggerManager.$logger() -} + $proto.messages = nil; + + $const_set($nesting[0], 'SEVERITY_SYMBOL_BY_VALUE', $send($$('Severity').$constants(false), 'map', [], function $MemoryLogger$1(c){ + + if (c == null) c = nil; + return [$$('Severity').$const_get(c), c];}).$to_h()); + self.$attr_reader("messages"); + + $def(self, '$initialize', function $$initialize() { + var self = this; -Logging.createLogMessage = function (text, context) { - return Logging.prototype.$message_with_context(text, toHash(context)) -} + + self['$level=']($$('WARN')); + return (self.messages = []); + }); + + $def(self, '$add', function $$add(severity, message, progname) { + var $yield = $$add.$$p || nil, self = this, $ret_or_1 = nil; -// alias + $$add.$$p = null; + + if (message == null) message = nil; + if (progname == null) progname = nil; + message = ($truthy(($ret_or_1 = message)) ? ($ret_or_1) : (($yield !== nil) ? (Opal.yieldX($yield, [])) : (progname))); + self.messages['$<<']($hash2(["severity", "message"], {"severity": $$('SEVERITY_SYMBOL_BY_VALUE')['$[]'](($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), "message": message})); + return true; + }, -2); + + $def(self, '$clear', function $$clear() { + var self = this; -/** - * @memberof Reader - */ -Reader.prototype.getLogger = Logging.getLogger -/** - * @memberof Reader - */ -Reader.prototype.createLogMessage = Logging.createLogMessage + return self.messages.$clear() + }); + + $def(self, '$empty?', function $MemoryLogger_empty$ques$2() { + var self = this; -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.getLogger = Logging.getLogger -/** - * @memberof AbstractNode - */ -AbstractNode.prototype.createLogMessage = Logging.createLogMessage + return self.messages['$empty?']() + }); + return $def(self, '$max_severity', function $$max_severity() { + var self = this; -/** - * @namespace - */ -var Logger = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger', true) + if ($truthy(self['$empty?']())) { + return nil + } else { + return $send(self.messages, 'map', [], function $$3(m){ + + if (m == null) m = nil; + return $$('Severity').$const_get(m['$[]']("severity"));}).$max() + } + }); + })($nesting[0], $$$('Logger'), $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'NullLogger'); -// Alias -Opal.Asciidoctor.Logger = Logger + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * @returns {number|undefined} - the maximum severity - * @memberof Logger - */ -Logger.prototype.getMaxSeverity = function () { - var result = this.max_severity - return result === Opal.nil ? undefined : result -} -/** - * @returns {LoggerFormatter} - the formatter - * @memberof Logger - */ -Logger.prototype.getFormatter = function () { - return this.formatter -} -/** - * @param {LoggerFormatter} formatter - the formatter - * @memberof Logger - */ -Logger.prototype.setFormatter = function (formatter) { - this.formatter = formatter -} -/** - * @returns {number} - the logging severity threshold - * @memberof Logger - */ -Logger.prototype.getLevel = function () { - return this.level -} -/** - * @param {number} level - the logging severity threshold - * @memberof Logger - */ -Logger.prototype.setLevel = function (level) { - this.level = level -} -/** - * @returns {string} - the program name - * @memberof Logger - */ -Logger.prototype.getProgramName = function () { - return this.progname -} -/** - * @param {string} programName - the program name - * @memberof Logger - */ -Logger.prototype.setProgramName = function (programName) { - this.progname = programName -} + $proto.max_severity = nil; + + self.$attr_reader("max_severity"); + + $def(self, '$initialize', function $$initialize() { + var $a, self = this; -var RubyLogger = Opal.const_get_qualified('::', 'Logger') + return ($a = [$$('WARN')], $send(self, 'level=', $a), $a[$a.length - 1]) + }); + return $def(self, '$add', function $$add(severity, message, progname) { + var self = this, $ret_or_1 = nil; + if ($truthy($rb_gt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), (self.max_severity = ($truthy(($ret_or_1 = self.max_severity)) ? ($ret_or_1) : (severity)))))) { + self.max_severity = severity; + } return true; + }, -2); + })($nesting[0], $$$('Logger'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'LoggerManager'); -var log = function (logger, level, message) { - logger['$' + level](message) -} -RubyLogger.prototype.add = function (severity, message, programName) { - var severityValue = typeof severity === 'string' ? LoggerSeverity[severity.toUpperCase()] : severity - this.$add(severityValue, message, programName) -} -RubyLogger.prototype.log = RubyLogger.prototype.add -RubyLogger.prototype.debug = function (message) { - log(this, 'debug', message) -} -RubyLogger.prototype.info = function (message) { - log(this, 'info', message) -} -RubyLogger.prototype.warn = function (message) { - log(this, 'warn', message) -} -RubyLogger.prototype.error = function (message) { - log(this, 'error', message) -} -RubyLogger.prototype.fatal = function (message) { - log(this, 'fatal', message) -} -RubyLogger.prototype.isDebugEnabled = function () { - return this['$debug?']() -} -RubyLogger.prototype.isInfoEnabled = function () { - return this['$info?']() -} -RubyLogger.prototype.isWarnEnabled = function () { - return this['$warn?']() -} -RubyLogger.prototype.isErrorEnabled = function () { - return this['$error?']() -} -RubyLogger.prototype.isFatalEnabled = function () { - return this['$fatal?']() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @namespace - */ -var NullLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'NullLogger', true) + + self.logger_class = $$('Logger'); + return (function(self, $parent_nesting) { -// Alias -Opal.Asciidoctor.NullLogger = NullLogger + + self.$attr_accessor("logger_class"); + + $def(self, '$logger', function $$logger(pipe) { + var self = this, $ret_or_1 = nil; + if (self.logger == null) self.logger = nil; + if (self.logger_class == null) self.logger_class = nil; + if ($gvars.stderr == null) $gvars.stderr = nil; -/** - * Create a new NullLogger. - * @returns {NullLogger} - a NullLogger - * @memberof NullLogger - */ -NullLogger.create = function () { - return this.$new() -} + + if (pipe == null) pipe = $gvars.stderr; + self.$memoize_logger(); + return (self.logger = ($truthy(($ret_or_1 = self.logger)) ? ($ret_or_1) : (self.logger_class.$new(pipe)))); + }, -1); + + $def(self, '$logger=', function $logger$eq$4(new_logger) { + var self = this, $ret_or_1 = nil; + if (self.logger_class == null) self.logger_class = nil; + if ($gvars.stderr == null) $gvars.stderr = nil; -/** - * @returns {number|undefined} - the maximum severity - * @memberof NullLogger - */ -NullLogger.prototype.getMaxSeverity = function () { - return this.max_severity -} + return (self.logger = ($truthy(($ret_or_1 = new_logger)) ? ($ret_or_1) : (self.logger_class.$new($gvars.stderr)))) + }); + self.$private(); + return $def(self, '$memoize_logger', function $$memoize_logger() { + var self = this; -// Alias -Opal.Asciidoctor.StopIteration = Opal.StopIteration + return (function(self, $parent_nesting) { + + + $alias(self, "logger", "logger"); + return self.$attr_reader("logger"); + })(Opal.get_singleton_class(self)) + }); + })(Opal.get_singleton_class(self)); + })($nesting[0], $nesting); + return (function($base, $parent_nesting) { + var self = $module($base, 'Logging'); -/** - * @namespace - */ -var Timings = Opal.const_get_qualified(Opal.Asciidoctor, 'Timings', true) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -// Alias -Opal.Asciidoctor.Timings = Timings + + $defs(self, '$included', function $$included(into) { + + return into.$extend($$('Logging')) + }); + self.$private_class_method("included"); + + $def(self, '$logger', function $$logger() { + + return $$('LoggerManager').$logger() + }); + return $def(self, '$message_with_context', function $$message_with_context(text, context) { + + + if (context == null) context = $hash2([], {}); + return $hash2(["text"], {"text": text}).$merge(context).$extend($$$($$('Logger'), 'AutoFormattingMessage')); + }, -2); + })($nesting[0], $nesting); + })($nesting[0], $nesting); +}; -/** - * Create a new Timings. - * @returns {Timings} - a Timings - * @memberof Timings - */ -Timings.create = function () { - return this.$new() -} +Opal.modules["asciidoctor/rx"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $regexp = Opal.regexp, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Print a report to the specified output. - * The report will include: - * - the time to read and parse source - * - the time to convert document - * - the total time (read, parse and convert) - * @param {RubyLogger|console|Object} [to] - an optional output (by default stdout) - * @param {string} [subject] - an optional subject (usually the file name) - * @memberof Timings - */ -Timings.prototype.printReport = function (to, subject) { - var outputFunction - if (to) { - if (typeof to.$add === 'function') { - outputFunction = function (message) { - to.$add(1, message) - } - } else if (typeof to.log === 'function') { - outputFunction = to.log - } else if (typeof to.write === 'function') { - outputFunction = function (message) { - to.write(message, 'utf-8') - } - } else { - throw new Error('The output should be a Stream (with a write function), an object with a log function or a Ruby Logger (with a add function)') - } - } else { - outputFunction = function (message) { - Opal.gvars.stdout.$write(message) - } - } - if (subject) { - outputFunction('Input file: ' + subject) - } - outputFunction(' Time to read and parse source: ' + this.$read_parse().toFixed(2)) - outputFunction(' Time to convert document: ' + this.$convert().toFixed(2)) - outputFunction(' Total time (read, parse and convert): ' + this.$read_parse_convert().toFixed(2)) -} + Opal.add_stubs('join,to_a,new,[]=,empty?,escape'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @namespace - * @description - * This API is experimental and subject to change. - * - * A pluggable adapter for integrating a syntax (aka code) highlighter into AsciiDoc processing. - * - * There are two types of syntax highlighter adapters. The first performs syntax highlighting during the convert phase. - * This adapter type must define a "handlesHighlighting" method that returns true. - * The companion "highlight" method will then be called to handle the "specialcharacters" substitution for source blocks. - * - * The second assumes syntax highlighting is performed on the client (e.g., when the HTML document is loaded). - * This adapter type must define a "hasDocinfo" method that returns true. - * The companion "docinfo" method will then be called to insert markup into the output document. - * The docinfo functionality is available to both adapter types. - * - * Asciidoctor.js provides several a built-in adapter for highlight.js. - * Additional adapters can be registered using SyntaxHighlighter.register. - */ -var SyntaxHighlighter = Opal.const_get_qualified(Opal.Asciidoctor, 'SyntaxHighlighter', true) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + $module($nesting[0], 'Rx'); + $const_set($nesting[0], 'AuthorInfoLineRx', $regexp(["^(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*)(?: +(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*))?(?: +(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*))?(?: +<([^>]+)>)?$"])); + $const_set($nesting[0], 'AuthorDelimiterRx', /;(?: |$)/); + $const_set($nesting[0], 'RevisionInfoLineRx', $regexp(["^(?:[^\\d{]*(", $$('CC_ANY'), "*?),)? *(?!:)(", $$('CC_ANY'), "*?)(?: *(?!^),?: *(", $$('CC_ANY'), "*))?$"])); + $const_set($nesting[0], 'ManpageTitleVolnumRx', $regexp(["^(", $$('CC_ANY'), "+?) *\\( *(", $$('CC_ANY'), "+?) *\\)$"])); + $const_set($nesting[0], 'ManpageNamePurposeRx', $regexp(["^(", $$('CC_ANY'), "+?) +- +(", $$('CC_ANY'), "+)$"])); + $const_set($nesting[0], 'ConditionalDirectiveRx', $regexp(["^(\\\\)?(ifdef|ifndef|ifeval|endif)::(\\S*?(?:([,+])\\S*?)?)\\[(", $$('CC_ANY'), "+)?\\]$"])); + $const_set($nesting[0], 'EvalExpressionRx', $regexp(["^(", $$('CC_ANY'), "+?) *([=!><]=|[><]) *(", $$('CC_ANY'), "+)$"])); + $const_set($nesting[0], 'IncludeDirectiveRx', $regexp(["^(\\\\)?include::([^\\s\\[](?:[^\\[]*[^\\s\\[])?)\\[(", $$('CC_ANY'), "+)?\\]$"])); + $const_set($nesting[0], 'TagDirectiveRx', /\b(?:tag|(e)nd)::(\S+?)\[\](?=$|[ \r])/m); + $const_set($nesting[0], 'AttributeEntryRx', $regexp(["^:(!?", $$('CG_WORD'), "[^:]*):(?:[ \\t]+(", $$('CC_ANY'), "*))?$"])); + $const_set($nesting[0], 'InvalidAttributeNameCharsRx', $regexp(["[^", $$('CC_WORD'), "-]"])); + $const_set($nesting[0], 'AttributeEntryPassMacroRx', $regexp(["^pass:([a-z]+(?:,[a-z-]+)*)?\\[(", $$('CC_ALL'), "*)\\]$"])); + $const_set($nesting[0], 'AttributeReferenceRx', $regexp(["(\\\\)?\\{(", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*|(set|counter2?):", $$('CC_ANY'), "+?)(\\\\)?\\}"])); + $const_set($nesting[0], 'BlockAnchorRx', $regexp(["^\\[\\[(?:|([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+))?)\\]\\]$"])); + $const_set($nesting[0], 'BlockAttributeListRx', $regexp(["^\\[(|[", $$('CC_WORD'), ".#%{,\"']", $$('CC_ANY'), "*)\\]$"])); + $const_set($nesting[0], 'BlockAttributeLineRx', $regexp(["^\\[(?:|[", $$('CC_WORD'), ".#%{,\"']", $$('CC_ANY'), "*|\\[(?:|[", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*(?:, *", $$('CC_ANY'), "+)?)\\])\\]$"])); + $const_set($nesting[0], 'BlockTitleRx', $regexp(["^\\.(\\.?[^ \\t.]", $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'AdmonitionParagraphRx', $regexp(["^(", $$('ADMONITION_STYLES').$to_a().$join("|"), "):[ \\t]+"])); + $const_set($nesting[0], 'LiteralParagraphRx', $regexp(["^([ \\t]+", $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'AtxSectionTitleRx', $regexp(["^(=={0,5})[ \\t]+(", $$('CC_ANY'), "+?)(?:[ \\t]+\\1)?$"])); + $const_set($nesting[0], 'ExtAtxSectionTitleRx', $regexp(["^(=={0,5}|#\\\#{0,5})[ \\t]+(", $$('CC_ANY'), "+?)(?:[ \\t]+\\1)?$"])); + $const_set($nesting[0], 'SetextSectionTitleRx', $regexp(["^((?!\\.)", $$('CC_ANY'), "*?", $$('CG_ALNUM'), $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'InlineSectionAnchorRx', $regexp([" (\\\\)?\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+))?\\]\\]$"])); + $const_set($nesting[0], 'InvalidSectionIdCharsRx', $regexp(["<[^>]+>|&(?:[a-z][a-z]+\\d{0,2}|#\\d\\d\\d{0,4}|#x[\\da-f][\\da-f][\\da-f]{0,3});|[^ ", $$('CC_WORD'), "\\-.]+?"])); + $const_set($nesting[0], 'SectionLevelStyleRx', /^sect\d$/); + $const_set($nesting[0], 'AnyListRx', $regexp(["^(?:[ \\t]*(?:-|\\*\\**|\\.\\.*|\\u2022|\\d+\\.|[a-zA-Z]\\.|[IVXivx]+\\))[ \\t]|(?!//[^/])[ \\t]*[^ \\t]", $$('CC_ANY'), "*?(?::::{0,2}|;;)(?:$|[ \\t])|<(?:\\d+|\\.)>[ \\t])"])); + $const_set($nesting[0], 'UnorderedListRx', $regexp(["^[ \\t]*(-|\\*\\**|\\u2022)[ \\t]+(", $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'OrderedListRx', $regexp(["^[ \\t]*(\\.\\.*|\\d+\\.|[a-zA-Z]\\.|[IVXivx]+\\))[ \\t]+(", $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'OrderedListMarkerRxMap', $hash2(["arabic", "loweralpha", "lowerroman", "upperalpha", "upperroman"], {"arabic": /\d+\./, "loweralpha": /[a-z]\./, "lowerroman": /[ivx]+\)/, "upperalpha": /[A-Z]\./, "upperroman": /[IVX]+\)/})); + $const_set($nesting[0], 'DescriptionListRx', $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?)(:::{0,2}|;;)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"])); + $const_set($nesting[0], 'DescriptionListSiblingRx', $hash2(["::", ":::", "::::", ";;"], {"::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), ":::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(:::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), "::::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(::::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), ";;": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?)(;;)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"])})); + $const_set($nesting[0], 'CalloutListRx', $regexp(["^<(\\d+|\\.)>[ \\t]+(", $$('CC_ANY'), "*)$"])); + $const_set($nesting[0], 'CalloutExtractRx', /((?:\/\/|#|--|;;) ?)?(\\)?<!?(|--)(\d+|\.)\3>(?=(?: ?\\?<!?\3(?:\d+|\.)\3>)*$)/); + $const_set($nesting[0], 'CalloutExtractRxt', "(\\\\)?<()(\\d+|\\.)>(?=(?: ?\\\\?<(?:\\d+|\\.)>)*$)"); + $const_set($nesting[0], 'CalloutExtractRxMap', $send($$$('Hash'), 'new', [], function $Asciidoctor$1(h, k){var $a; + + + if (h == null) h = nil; + if (k == null) k = nil; + return ($a = [k, $regexp(["(", ($truthy(k['$empty?']()) ? ("") : ("" + ($$$('Regexp').$escape(k)) + " ?")), ")?", $$('CalloutExtractRxt')])], $send(h, '[]=', $a), $a[$a.length - 1]);})); + $const_set($nesting[0], 'CalloutScanRx', $regexp(["\\\\?<!?(|--)(\\d+|\\.)\\1>(?=(?: ?\\\\?<!?\\1(?:\\d+|\\.)\\1>)*", $$('CC_EOL'), ")"])); + $const_set($nesting[0], 'CalloutSourceRx', $regexp(["((?://|#|--|;;) ?)?(\\\\)?<!?(|--)(\\d+|\\.)\\3>(?=(?: ?\\\\?<!?\\3(?:\\d+|\\.)\\3>)*", $$('CC_EOL'), ")"])); + $const_set($nesting[0], 'CalloutSourceRxt', "(\\\\)?<()(\\d+|\\.)>(?=(?: ?\\\\?<(?:\\d+|\\.)>)*" + ($$('CC_EOL')) + ")"); + $const_set($nesting[0], 'CalloutSourceRxMap', $send($$$('Hash'), 'new', [], function $Asciidoctor$2(h, k){var $a; + + + if (h == null) h = nil; + if (k == null) k = nil; + return ($a = [k, $regexp(["(", ($truthy(k['$empty?']()) ? ("") : ("" + ($$$('Regexp').$escape(k)) + " ?")), ")?", $$('CalloutSourceRxt')])], $send(h, '[]=', $a), $a[$a.length - 1]);})); + $const_set($nesting[0], 'ListRxMap', $hash2(["ulist", "olist", "dlist", "colist"], {"ulist": $$('UnorderedListRx'), "olist": $$('OrderedListRx'), "dlist": $$('DescriptionListRx'), "colist": $$('CalloutListRx')})); + $const_set($nesting[0], 'ColumnSpecRx', /^(?:(\d+)\*)?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?(\d+%?|~)?([a-z])?$/); + $const_set($nesting[0], 'CellSpecStartRx', /^[ \t]*(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/); + $const_set($nesting[0], 'CellSpecEndRx', /[ \t]+(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/); + $const_set($nesting[0], 'CustomBlockMacroRx', $regexp(["^(", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*)::(|\\S|\\S", $$('CC_ANY'), "*?\\S)\\[(", $$('CC_ANY'), "+)?\\]$"])); + $const_set($nesting[0], 'BlockMediaMacroRx', $regexp(["^(image|video|audio)::(\\S|\\S", $$('CC_ANY'), "*?\\S)\\[(", $$('CC_ANY'), "+)?\\]$"])); + $const_set($nesting[0], 'BlockTocMacroRx', $regexp(["^toc::\\[(", $$('CC_ANY'), "+)?\\]$"])); + $const_set($nesting[0], 'InlineAnchorRx', $regexp(["(\\\\)?(?:\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]|anchor:([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)\\[(?:\\]|(", $$('CC_ANY'), "*?[^\\\\])\\]))"])); + $const_set($nesting[0], 'InlineAnchorScanRx', $regexp(["(?:^|[^\\\\\\[])\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]|(?:^|[^\\\\])anchor:([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)\\[(?:\\]|(", $$('CC_ANY'), "*?[^\\\\])\\])"])); + $const_set($nesting[0], 'LeadingInlineAnchorRx', $regexp(["^\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]"])); + $const_set($nesting[0], 'InlineBiblioAnchorRx', $regexp(["^\\[\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]\\]"])); + $const_set($nesting[0], 'InlineEmailRx', $regexp(["([\\\\>:/])?", $$('CG_WORD'), "(?:&|[", $$('CC_WORD'), "\\-.%+])*@", $$('CG_ALNUM'), "[", $$('CC_ALNUM'), "_\\-.]*\\.[a-zA-Z]{2,5}\\b"])); + $const_set($nesting[0], 'InlineFootnoteMacroRx', $regexp(["\\\\?footnote(?:(ref):|:([", $$('CC_WORD'), "-]+)?)\\[(?:|(", $$('CC_ALL'), "*?[^\\\\]))\\](?!</a>)"], 'm')); + $const_set($nesting[0], 'InlineImageMacroRx', $regexp(["\\\\?i(?:mage|con):([^:\\s\\[](?:[^\\n\\[]*[^\\s\\[])?)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm')); + $const_set($nesting[0], 'InlineIndextermMacroRx', $regexp(["\\\\?(?:(indexterm2?):\\[(", $$('CC_ALL'), "*?[^\\\\])\\]|\\(\\((", $$('CC_ALL'), "+?)\\)\\)(?!\\)))"], 'm')); + $const_set($nesting[0], 'InlineKbdBtnMacroRx', $regexp(["(\\\\)?(kbd|btn):\\[(", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm')); + $const_set($nesting[0], 'InlineLinkRx', $regexp(["(^|link:|", $$('CG_BLANK'), "|<|[>\\(\\)\\[\\];\"'])(\\\\?(?:https?|file|ftp|irc)://)(?:([^\\s\\[\\]]+)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]|([^\\s\\[\\]<]*([^\\s,.?!\\[\\]<\\)])))"], 'm')); + $const_set($nesting[0], 'InlineLinkMacroRx', $regexp(["\\\\?(?:link|(mailto)):(|[^:\\s\\[][^\\s\\[]*)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm')); + $const_set($nesting[0], 'MacroNameRx', $regexp(["^", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*$"])); + $const_set($nesting[0], 'InlineStemMacroRx', $regexp(["\\\\?(stem|(?:latex|ascii)math):([a-z]+(?:,[a-z-]+)*)?\\[(", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm')); + $const_set($nesting[0], 'InlineMenuMacroRx', $regexp(["\\\\?menu:(", $$('CG_WORD'), "|[", $$('CC_WORD'), "&][^\\n\\[]*[^\\s\\[])\\[ *(?:|(", $$('CC_ALL'), "*?[^\\\\]))\\]"], 'm')); + $const_set($nesting[0], 'InlineMenuRx', $regexp(["\\\\?\"([", $$('CC_WORD'), "&][^\"]*?[ \\n]+>[ \\n]+[^\"]*)\""])); + $const_set($nesting[0], 'InlinePassRx', $hash(false, ["+", "-]", $regexp(["((?:^|[^", $$('CC_WORD'), ";:\\\\])(?=(\\[)|\\+)|\\\\(?=\\[)|(?=\\\\\\+))(?:\\2(x-|[^\\]]+ x-)\\]|(?:\\[([^\\]]+)\\])?(?=(\\\\)?\\+))(\\5?(\\+|`)(\\S|\\S", $$('CC_ALL'), "*?\\S)\\7)(?!", $$('CG_WORD'), ")"], 'm')], true, ["`", nil, $regexp(["(^|[^`", $$('CC_WORD'), "])(?:(\\Z)()|\\[([^\\]]+)\\](?=(\\\\))?)?(\\5?(`)([^`\\s]|[^`\\s]", $$('CC_ALL'), "*?\\S)\\7)(?![`", $$('CC_WORD'), "])"], 'm')])); + $const_set($nesting[0], 'InlinePassMacroRx', $regexp(["(?:(?:(\\\\?)\\[([^\\]]+)\\])?(\\\\{0,2})(\\+\\+\\+?|\\$\\$)(", $$('CC_ALL'), "*?)\\4|(\\\\?)pass:([a-z]+(?:,[a-z-]+)*)?\\[(|", $$('CC_ALL'), "*?[^\\\\])\\])"], 'm')); + $const_set($nesting[0], 'InlineXrefMacroRx', $regexp(["\\\\?(?:<<([", $$('CC_WORD'), "#/.:{]", $$('CC_ALL'), "*?)>>|xref:([", $$('CC_WORD'), "#/.:{]", $$('CC_ALL'), "*?)\\[(?:\\]|(", $$('CC_ALL'), "*?[^\\\\])\\]))"], 'm')); + $const_set($nesting[0], 'HardLineBreakRx', $regexp(["^(", $$('CC_ANY'), "*) \\+$"], 'm')); + $const_set($nesting[0], 'MarkdownThematicBreakRx', /^ {0,3}([-*_])( *)\1\2\1$/); + $const_set($nesting[0], 'ExtLayoutBreakRx', /^(?:'{3,}|<{3,}|([-*_])( *)\1\2\1)$/); + $const_set($nesting[0], 'BlankLineRx', /\n{2,}/); + $const_set($nesting[0], 'EscapedSpaceRx', /\\([ \t\n])/); + $const_set($nesting[0], 'ReplaceableTextRx', /[&']|--|\.\.\.|\([CRT]M?\)/); + $const_set($nesting[0], 'SpaceDelimiterRx', /([^\\])[ \t\n]+/); + $const_set($nesting[0], 'SubModifierSniffRx', /[+-]/); + $const_set($nesting[0], 'TrailingDigitsRx', /\d+$/); + $const_set($nesting[0], 'UriSniffRx', $regexp(["^", $$('CG_ALPHA'), "[", $$('CC_ALNUM'), ".+-]+:/{0,2}"])); + return $const_set($nesting[0], 'XmlSanitizeRx', /<[^>]+>/); + })($nesting[0], $nesting) +}; -// Alias -Opal.Asciidoctor.SyntaxHighlighter = SyntaxHighlighter +Opal.modules["asciidoctor/substitutors"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $hash2 = Opal.hash2, $hash = Opal.hash, $rb_plus = Opal.rb_plus, $regexp = Opal.regexp, $not = Opal.not, $truthy = Opal.truthy, $send = Opal.send, $def = Opal.def, $alias = Opal.alias, $gvars = Opal.gvars, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $neqeq = Opal.neqeq, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_gt = Opal.rb_gt, $slice = Opal.slice, $rb_minus = Opal.rb_minus, $rb_lt = Opal.rb_lt, $rb_times = Opal.rb_times, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Associates the syntax highlighter class or object with the specified names. - * - * @description This API is experimental and subject to change. - * - * @param {string|Array} names - A {string} name or an {Array} of {string} names - * @param functions - A list of functions representing a {SyntaxHighlighter} or a {SyntaxHighlighter} class to instantiate - * @memberof SyntaxHighlighter - */ -SyntaxHighlighter.register = function (names, functions) { - var name = typeof names === 'string' ? names : names[0] - if (typeof functions === 'function') { - var classObject = functions - var prototype = classObject.prototype - var properties = Object.getOwnPropertyNames(prototype) - functions = {} - for (var propertyIdx in properties) { - var propertyName = properties[propertyIdx] - functions[propertyName] = prototype[propertyName] - } - } - var scope = initializeClass(SyntaxHighlighterBase, name, functions, {}, { - format: function (args) { - if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) { - args[2] = fromHash(args[2]) - } - if (args.length >= 1) { - args[1] = args[1] === Opal.nil ? undefined : args[1] - } - return args - }, - highlight: function (args) { - if (args.length >= 3 && typeof args[3] === 'object' && '$$smap' in args[3]) { - var opts = args[3] - opts = fromHash(opts) - for (var key in opts) { - var value = opts[key] - if (key === 'callouts') { - var callouts = fromHashKeys(value) - for (var idx in callouts) { - var callout = callouts[idx] - for (var i = 0; i < callout.length; i++) { - var items = callout[i] - for (var j = 0; j < items.length; j++) { - items[j] = items[j] === Opal.nil ? undefined : items[j] - } - } - } - opts[key] = callouts - } else { - opts[key] = value === Opal.nil ? undefined : value - } - } - args[3] = opts - } - if (args.length >= 2) { - args[2] = args[2] === Opal.nil ? undefined : args[2] - } - return args - } - }) - for (var functionName in functions) { - if (Object.prototype.hasOwnProperty.call(functions, functionName)) { - (function (functionName) { - var userFunction = functions[functionName] - if (functionName === 'handlesHighlighting') { - Opal.def(scope, '$highlight?', function () { - return userFunction.call() - }) - } else if (functionName === 'hasDocinfo') { - Opal.def(scope, '$docinfo?', function (location) { - return userFunction.apply(this, [location]) - }) - } - }(functionName)) - } - } - Opal.def(scope, '$name', function () { - return name - }) - SyntaxHighlighter.$register(scope, names) - return scope -} + Opal.add_stubs('freeze,+,keys,!,empty?,===,[],join,include?,extract_passthroughs,each,sub_specialchars,sub_quotes,sub_attributes,sub_replacements,sub_macros,highlight_source,sub_callouts,sub_post_replacements,warn,logger,restore_passthroughs,clear,split,apply_subs,gsub,match?,compat_mode,convert_quoted_text,attributes,==,shift,store_attribute,!=,attribute_undefined,counter,key?,downcase,attribute_missing,info,squeeze,delete,reject,start_with?,do_replacement,inline_macros?,extensions,inline_macros,regexp,instance,slice,length,names,config,merge,[]=,normalize_text,parse_attributes,process_method,expand_subs,text=,text,convert,class,strip,index,min,compact,>,end_with?,map,chop,new,pop,rstrip,register,tr,basename,parse,lstrip,split_simple_csv,-,partition,extract_attributes_from_text,sub,encode_uri_component,style,extname?,rindex,catalog,info?,fetch,outfilesuffix,natural_xrefs,resolve_id,find,footnotes,id,<,size,<<,attr?,attr,to_s,read_next_id,callouts,highlight?,syntax_highlighter,sub_source,extract_callouts,name,to_i,to_sym,resolve_lines_to_highlight,highlight,nil_or_empty?,restore_callouts,count,to_a,|,sort,*,parse_quoted_text_attributes,resolve_pass_subs,basebackend?,error,chr,drop,&,resolve_subs,resolve_block_subs,parse_into,private,shorthand_property_syntax,each_char'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * Retrieves the syntax highlighter class or object registered for the specified name. - * - * @description This API is experimental and subject to change. - * - * @param {string} name - The {string} name of the syntax highlighter to retrieve. - * @returns {SyntaxHighlighter} - the {SyntaxHighlighter} registered for this name. - * @memberof SyntaxHighlighter - */ -SyntaxHighlighter.get = function (name) { - var result = SyntaxHighlighter.$for(name) - return result === Opal.nil ? undefined : result -} + var $nesting = [self].concat($parent_nesting); -/** - * @deprecated Please use {SyntaxHighlighter#get} method as "for" is a reserved keyword. - */ -SyntaxHighlighter.for = SyntaxHighlighter.get + return (function($base, $parent_nesting) { + var self = $module($base, 'Substitutors'); -/** - * @namespace - */ -var SyntaxHighlighterBase = Opal.const_get_qualified(SyntaxHighlighter, 'Base', true) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + $const_set($nesting[0], 'SpecialCharsRx', /[<&>]/); + $const_set($nesting[0], 'SpecialCharsTr', $hash2([">", "<", "&"], {">": ">", "<": "<", "&": "&"})); + $const_set($nesting[0], 'QuotedTextSniffRx', $hash(false, /[*_`#^~]/, true, /[*'_+#^~]/)); + $const_set($nesting[0], 'BASIC_SUBS', ["specialcharacters"]).$freeze(); + $const_set($nesting[0], 'HEADER_SUBS', ["specialcharacters", "attributes"]).$freeze(); + $const_set($nesting[0], 'NO_SUBS', []).$freeze(); + $const_set($nesting[0], 'NORMAL_SUBS', ["specialcharacters", "quotes", "attributes", "replacements", "macros", "post_replacements"]).$freeze(); + $const_set($nesting[0], 'REFTEXT_SUBS', ["specialcharacters", "quotes", "replacements"]).$freeze(); + $const_set($nesting[0], 'VERBATIM_SUBS', ["specialcharacters", "callouts"]).$freeze(); + $const_set($nesting[0], 'SUB_GROUPS', $hash2(["none", "normal", "verbatim", "specialchars"], {"none": $$('NO_SUBS'), "normal": $$('NORMAL_SUBS'), "verbatim": $$('VERBATIM_SUBS'), "specialchars": $$('BASIC_SUBS')})); + $const_set($nesting[0], 'SUB_HINTS', $hash2(["a", "m", "n", "p", "q", "r", "c", "v"], {"a": "attributes", "m": "macros", "n": "normal", "p": "post_replacements", "q": "quotes", "r": "replacements", "c": "specialcharacters", "v": "verbatim"})); + $const_set($nesting[0], 'SUB_OPTIONS', $hash2(["block", "inline"], {"block": $rb_plus($rb_plus($$('SUB_GROUPS').$keys(), $$('NORMAL_SUBS')), ["callouts"]), "inline": $rb_plus($$('SUB_GROUPS').$keys(), $$('NORMAL_SUBS'))})); + $const_set($nesting[0], 'CAN', "\u0018"); + $const_set($nesting[0], 'DEL', "\u007F"); + $const_set($nesting[0], 'PASS_START', "\u0096"); + $const_set($nesting[0], 'PASS_END', "\u0097"); + $const_set($nesting[0], 'PassSlotRx', $regexp([$$('PASS_START'), "(\\d+)", $$('PASS_END')])); + $const_set($nesting[0], 'HighlightedPassSlotRx', $regexp(["<span\\b[^>]*>", $$('PASS_START'), "</span>[^\\d]*(\\d+)[^\\d]*<span\\b[^>]*>", $$('PASS_END'), "</span>"])); + $const_set($nesting[0], 'RS', "\\"); + $const_set($nesting[0], 'R_SB', "]"); + $const_set($nesting[0], 'ESC_R_SB', "\\]"); + $const_set($nesting[0], 'PLUS', "+"); + + $def(self, '$apply_subs', function $$apply_subs(text, subs) { + var self = this, is_multiline = nil, passthrus = nil, $ret_or_1 = nil, clear_passthrus = nil; + if (self.passthroughs == null) self.passthroughs = nil; + if (self.passthroughs_locked == null) self.passthroughs_locked = nil; -// Alias -Opal.Asciidoctor.SyntaxHighlighterBase = SyntaxHighlighterBase + + if (subs == null) subs = $$('NORMAL_SUBS'); + if (($truthy(text['$empty?']()) || ($not(subs)))) { + return text + } if ($truthy((is_multiline = $$$('Array')['$==='](text)))) { + text = ($truthy(text['$[]'](1)) ? (text.$join($$('LF'))) : (text['$[]'](0))); + } if ($truthy(subs['$include?']("macros"))) { + + text = self.$extract_passthroughs(text); + if (!$truthy(self.passthroughs['$empty?']())) { + + passthrus = self.passthroughs; + self.passthroughs_locked = ($truthy(($ret_or_1 = self.passthroughs_locked)) ? ($ret_or_1) : ((clear_passthrus = true))); + } } $send(subs, 'each', [], function $$1(type){var self = $$1.$$s == null ? this : $$1.$$s; -/** - * Statically register the current class in the registry for the specified names. - * - * @description This API is experimental and subject to change. - * - * @param {string|Array<string>} names - A {string} name or an {Array} of {string} names - * @memberof SyntaxHighlighterBase - */ -SyntaxHighlighterBase.prototype.registerFor = function (names) { - SyntaxHighlighter.$register(this, names) -} + + if (type == null) type = nil; + + switch (type) { + case "specialcharacters": + return (text = self.$sub_specialchars(text)) + case "quotes": + return (text = self.$sub_quotes(text)) + case "attributes": + if ($truthy(text['$include?']($$('ATTR_REF_HEAD')))) { + return (text = self.$sub_attributes(text)) + } else { + return nil + } + case "replacements": + return (text = self.$sub_replacements(text)) + case "macros": + return (text = self.$sub_macros(text)) + case "highlight": + return (text = self.$highlight_source(text, subs['$include?']("callouts"))) + case "callouts": + if ($truthy(subs['$include?']("highlight"))) { + return nil + } else { + return (text = self.$sub_callouts(text)) + } + case "post_replacements": + return (text = self.$sub_post_replacements(text)) + default: + return self.$logger().$warn("unknown substitution type " + (type)) + }}, {$$s: self}); + if ($truthy(passthrus)) { + + text = self.$restore_passthroughs(text); + if ($truthy(clear_passthrus)) { + + passthrus.$clear(); + self.passthroughs_locked = nil; + } } if ($truthy(is_multiline)) { + + return text.$split($$('LF'), -1); + } else { + return text + } }, -2); + + $def(self, '$apply_normal_subs', function $$apply_normal_subs(text) { + var self = this; -// Table API + return self.$apply_subs(text, $$('NORMAL_SUBS')) + }); + + $def(self, '$apply_header_subs', function $$apply_header_subs(text) { + var self = this; -/** - * Methods for managing AsciiDoc tables. - * @namespace - * @extends AbstractBlock - */ -var Table = Opal.Asciidoctor.Table + return self.$apply_subs(text, $$('HEADER_SUBS')) + }); + $alias(self, "apply_title_subs", "apply_subs"); + + $def(self, '$apply_reftext_subs', function $$apply_reftext_subs(text) { + var self = this; -/** - * Create a new Table element. - * @param {AbstractBlock} parent - * @param {Object|undefined} attributes - * @returns {Table} - a new {Table} object - */ -Table.create = function (parent, attributes) { - return this.$new(parent, toHash(attributes)) -} + return self.$apply_subs(text, $$('REFTEXT_SUBS')) + }); + + $def(self, '$sub_specialchars', function $$sub_specialchars(text) { + + if ((($truthy(text['$include?'](">")) || ($truthy(text['$include?']("&")))) || ($truthy(text['$include?']("<"))))) { + + return text.$gsub($$('SpecialCharsRx'), $$('SpecialCharsTr')); + } else { + return text + } + }); + $alias(self, "sub_specialcharacters", "sub_specialchars"); + + $def(self, '$sub_quotes', function $$sub_quotes(text) { + var self = this, compat = nil; + if (self.document == null) self.document = nil; -/** - * Get the caption of the table. - * @returns {string} - * @memberof Table - */ -Table.prototype.getCaption = function () { - return this.caption -} + + if ($truthy($$('QuotedTextSniffRx')['$[]']((compat = self.document.$compat_mode()))['$match?'](text))) { + $send($$('QUOTE_SUBS')['$[]'](compat), 'each', [], function $$2(type, scope, pattern){var self = $$2.$$s == null ? this : $$2.$$s; -/** - * Get the rows of this table. - * @returns {Table.Rows} - an {Table.Rows} object with the members "head", "body" and "foot" - * @memberof Table - */ -Table.prototype.getRows = function () { - return this.rows -} + + if (type == null) type = nil; + if (scope == null) scope = nil; + if (pattern == null) pattern = nil; + return (text = $send(text, 'gsub', [pattern], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s; + if ($gvars["~"] == null) $gvars["~"] = nil; -/** - * Get the columns of this table. - * @returns {Array<Column>} - * @memberof Table - */ -Table.prototype.getColumns = function () { - return this.columns -} + return self.$convert_quoted_text($gvars["~"], type, scope)}, {$$s: self}));}, {$$s: self}); + } return text; + }); + + $def(self, '$sub_attributes', function $$sub_attributes(text, opts) { + var self = this, doc_attrs = nil, drop = nil, drop_line = nil, drop_line_severity = nil, drop_empty_line = nil, attribute_undefined = nil, attribute_missing = nil, lines = nil; + if (self.document == null) self.document = nil; -/** - * Get the head rows of this table. - * @returns {Array<Array<Cell>>} - an Array of Array of Cell - * @memberof Table - */ -Table.prototype.getHeadRows = function () { - return this.rows.head -} + + if (opts == null) opts = $hash2([], {}); + doc_attrs = self.document.$attributes(); + drop = (drop_line = (drop_line_severity = (drop_empty_line = (attribute_undefined = (attribute_missing = nil))))); + text = $send(text, 'gsub', [$$('AttributeReferenceRx')], function $$4(){var $a, $b, self = $$4.$$s == null ? this : $$4.$$s, args = nil, $ret_or_2 = nil, value = nil, $ret_or_3 = nil, key = nil, $ret_or_4 = nil; + if (self.document == null) self.document = nil; -/** - * Check if the table has a head rows. - * @returns {boolean} - * @memberof Table - */ -Table.prototype.hasHeadRows = function () { - return this.rows !== Opal.nil && this.rows.head.length > 0 -} + if (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS')) || ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), $$('RS'))))) { + return "{" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) + "}" + } else if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) { + + switch ((args = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)).$split(":", 3)).$shift()) { + case "set": + + $b = $$('Parser').$store_attribute(args['$[]'](0), ($truthy(($ret_or_2 = args['$[]'](1))) ? ($ret_or_2) : ("")), self.document), $a = $to_ary($b), (($a[0] == null ? nil : $a[0])), (value = ($a[1] == null ? nil : $a[1])); + if (($truthy(value) || ($neqeq((attribute_undefined = ($truthy(($ret_or_2 = attribute_undefined)) ? ($ret_or_2) : (($truthy(($ret_or_3 = doc_attrs['$[]']("attribute-undefined"))) ? ($ret_or_3) : ($$('Compliance').$attribute_undefined()))))), "drop-line")))) { + return (drop = (drop_empty_line = $$('DEL'))) + } else { + return (drop = (drop_line = $$('CAN'))) + } case "counter2": + + $send(self.document, 'counter', $to_a(args)); + return (drop = (drop_empty_line = $$('DEL'))); + default: + return $send(self.document, 'counter', $to_a(args)) + } + } else if ($truthy(doc_attrs['$key?']((key = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)).$downcase())))) { + return doc_attrs['$[]'](key) + } else if ($truthy((value = $$('INTRINSIC_ATTRIBUTES')['$[]'](key)))) { + return value + } else + switch ((attribute_missing = ($truthy(($ret_or_2 = attribute_missing)) ? ($ret_or_2) : (($truthy(($ret_or_3 = ($truthy(($ret_or_4 = opts['$[]']("attribute_missing"))) ? ($ret_or_4) : (doc_attrs['$[]']("attribute-missing"))))) ? ($ret_or_3) : ($$('Compliance').$attribute_missing())))))) { + case "drop": + return (drop = (drop_empty_line = $$('DEL'))) + case "drop-line": + + if ($eqeq((drop_line_severity = ($truthy(($ret_or_2 = drop_line_severity)) ? ($ret_or_2) : (($truthy(($ret_or_3 = opts['$[]']("drop_line_severity"))) ? ($ret_or_3) : ("info"))))), "info")) { + $send(self.$logger(), 'info', [], function $$5(){ + return "dropping line containing reference to missing attribute: " + (key)}); + } return (drop = (drop_line = $$('CAN'))); + case "warn": + + self.$logger().$warn("skipping reference to missing attribute: " + (key)); + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)); + default: + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + }}, {$$s: self}); + if ($truthy(drop)) { + if ($truthy(drop_empty_line)) { + + lines = text.$squeeze($$('DEL')).$split($$('LF'), -1); + if ($truthy(drop_line)) { + return $send(lines, 'reject', [], function $$6(line){var $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil; -/** - * Get the body rows of this table. - * @returns {Array<Array<Cell>>} - an Array of Array of Cell - * @memberof Table - */ -Table.prototype.getBodyRows = function () { - return this.rows.body -} + + if (line == null) line = nil; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = line['$==']($$('DEL')))) ? ($ret_or_3) : (line['$==']($$('CAN')))))) ? ($ret_or_2) : (line['$start_with?']($$('CAN'))))))) { + return $ret_or_1 + } else { + + return line['$include?']($$('CAN')); + }}).$join($$('LF')).$delete($$('DEL')) + } else { + return $send(lines, 'reject', [], function $$7(line){ + + if (line == null) line = nil; + return line['$==']($$('DEL'));}).$join($$('LF')).$delete($$('DEL')) + } } else if ($truthy(text['$include?']($$('LF')))) { + return $send(text.$split($$('LF'), -1), 'reject', [], function $$8(line){var $ret_or_1 = nil, $ret_or_2 = nil; -/** - * Check if the table has a body rows. - * @returns {boolean} - */ -Table.prototype.hasBodyRows = function () { - return this.rows !== Opal.nil && this.rows.body.length > 0 -} + + if (line == null) line = nil; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = line['$==']($$('CAN')))) ? ($ret_or_2) : (line['$start_with?']($$('CAN'))))))) { + return $ret_or_1 + } else { + + return line['$include?']($$('CAN')); + }}).$join($$('LF')) + } else { + return "" + } + } else { + return text + } }, -2); + + $def(self, '$sub_replacements', function $$sub_replacements(text) { + var self = this; -/** - * Get the foot rows of this table. - * @returns {Array<Array<Cell>>} - an Array of Array of Cell - * @memberof Table - */ -Table.prototype.getFootRows = function () { - return this.rows.foot -} + + if ($truthy($$('ReplaceableTextRx')['$match?'](text))) { + $send($$('REPLACEMENTS'), 'each', [], function $$9(pattern, replacement, restore){var self = $$9.$$s == null ? this : $$9.$$s; -/** - * Check if the table has a foot rows. - * @returns {boolean} - */ -Table.prototype.hasFootRows = function () { - return this.rows !== Opal.nil && this.rows.foot.length > 0 -} + + if (pattern == null) pattern = nil; + if (replacement == null) replacement = nil; + if (restore == null) restore = nil; + return (text = $send(text, 'gsub', [pattern], function $$10(){var self = $$10.$$s == null ? this : $$10.$$s; + if ($gvars["~"] == null) $gvars["~"] = nil; -/** - * Check if the table has a header option set. - * @returns {boolean} - * @memberof Table - */ -Table.prototype.hasHeaderOption = function () { - return this.has_header_option -} + return self.$do_replacement($gvars["~"], replacement, restore)}, {$$s: self}));}, {$$s: self}); + } return text; + }); + + $def(self, '$sub_macros', function $$sub_macros(text) { + var self = this, found_square_bracket = nil, found_colon = nil, found_macroish = nil, $ret_or_1 = nil, found_macroish_short = nil, doc_attrs = nil, doc = nil, extensions = nil; + if (self.document == null) self.document = nil; + if (self.parent == null) self.parent = nil; + if (self.context == null) self.context = nil; -/** - * Check if the table has the footer option set. - * @returns {boolean} - * @memberof Table - */ -Table.prototype.hasFooterOption = function () { - var footerOption = this.getAttributes()['footer-option'] - return footerOption === '' -} + + found_square_bracket = text['$include?']("["); + found_colon = text['$include?'](":"); + found_macroish = ($truthy(($ret_or_1 = found_square_bracket)) ? (found_colon) : ($ret_or_1)); + found_macroish_short = ($truthy(($ret_or_1 = found_macroish)) ? (text['$include?'](":[")) : ($ret_or_1)); + doc_attrs = (doc = self.document).$attributes(); + if (($truthy((extensions = doc.$extensions())) && ($truthy(extensions['$inline_macros?']())))) { + $send(extensions.$inline_macros(), 'each', [], function $$11(extension){var self = $$11.$$s == null ? this : $$11.$$s; -/** - * Check if the table has the autowidth option set. - * @returns {boolean} - * @memberof Table - */ -Table.prototype.hasAutowidthOption = function () { - var autowidthOption = this.getAttributes()['autowidth-option'] - return autowidthOption === '' -} + + if (extension == null) extension = nil; + return (text = $send(text, 'gsub', [extension.$instance().$regexp()], function $$12(){var $a, $b, self = $$12.$$s == null ? this : $$12.$$s, match = nil, target = nil, content = nil, attributes = nil, default_attrs = nil, ext_config = nil, $ret_or_2 = nil, replacement = nil, inline_subs = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; -/** - * Get the number of rows in the table. - * Please note that the header and footer rows are also counted. - * @returns {number|undefined} - * @memberof Table - */ -Table.prototype.getRowCount = function () { - return this.getAttribute('rowcount') -} + + if ($truthy((match = (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy($gvars["~"].$names()['$empty?']())) { + $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2))], (target = $a[0]), (content = $a[1]); + } else { + $a = [(function() { try { + return $gvars["~"]['$[]']("target") + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})(), (function() { try { + return $gvars["~"]['$[]']("content") + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})()], (target = $a[0]), (content = $a[1]); + } attributes = ($truthy((default_attrs = (ext_config = extension.$config())['$[]']("default_attrs"))) ? (default_attrs.$merge()) : ($hash2([], {}))); + if ($truthy(content)) { + + if ($truthy(content['$empty?']())) { + if (!$eqeq(ext_config['$[]']("content_model"), "attributes")) { + attributes['$[]=']("text", content); + } + } else { + + content = self.$normalize_text(content, true, true); + if ($eqeq(ext_config['$[]']("content_model"), "attributes")) { + self.$parse_attributes(content, ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))) ? ($ret_or_1) : ([])), $hash2(["into"], {"into": attributes})); + } else { + attributes['$[]=']("text", content); + } } target = ($truthy(($ret_or_1 = target)) ? ($ret_or_1) : ($eqeq(ext_config['$[]']("format"), "short") ? (content) : (target))); + } if ($eqeqeq($$('Inline'), (replacement = extension.$process_method()['$[]'](self, target, attributes)))) { + + if (($truthy((inline_subs = replacement.$attributes().$delete("subs"))) && ($truthy((inline_subs = self.$expand_subs(inline_subs, "custom inline macro")))))) { + replacement['$text='](self.$apply_subs(replacement.$text(), inline_subs)); + } return replacement.$convert(); + } else if ($truthy(replacement)) { + + $send(self.$logger(), 'info', [], function $$13(){ + return "expected substitution value for custom inline macro to be of type Inline; got " + (replacement.$class()) + ": " + (match)}); + return replacement; + } else { + return "" + }}, {$$s: self}));}, {$$s: self}); + } if ($truthy(doc_attrs['$key?']("experimental"))) { + + if (($truthy(found_macroish_short) && (($truthy(text['$include?']("kbd:")) || ($truthy(text['$include?']("btn:"))))))) { + text = $send(text, 'gsub', [$$('InlineKbdBtnMacroRx')], function $$14(){var $a, self = $$14.$$s == null ? this : $$14.$$s, keys = nil, delim_idx = nil, delim = nil; -/** - * Set the number of rows in the table. - * Please note that the header and footer rows are also counted. - * @param {number} value - the value - * @memberof Table - */ -Table.prototype.setRowCount = function (value) { - this.setAttribute('rowcount', value) -} + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } else if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), "kbd")) { + + if ($truthy((keys = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$strip())['$include?']($$('R_SB')))) { + keys = keys.$gsub($$('ESC_R_SB'), $$('R_SB')); + } if (($truthy($rb_gt(keys.$length(), 1)) && ($truthy((delim_idx = ($truthy((delim_idx = keys.$index(",", 1))) ? ([delim_idx, keys.$index("+", 1)].$compact().$min()) : (keys.$index("+", 1)))))))) { + + delim = keys.$slice(delim_idx, 1); + if ($truthy(keys['$end_with?'](delim))) { + + keys = $send(keys.$chop().$split(delim, -1), 'map', [], function $$15(key){ + + if (key == null) key = nil; + return key.$strip();}); + keys['$[]='](-1, $rb_plus(keys['$[]'](-1), delim)); + } else { + keys = $send(keys.$split(delim), 'map', [], function $$16(key){ + + if (key == null) key = nil; + return key.$strip();}); + } } else { + keys = [keys]; + } return $$('Inline').$new(self, "kbd", nil, $hash2(["attributes"], {"attributes": $hash2(["keys"], {"keys": keys})})).$convert(); + } else { + return $$('Inline').$new(self, "button", self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), true, true)).$convert() + }}, {$$s: self}); + } if (($truthy(found_macroish) && ($truthy(text['$include?']("menu:"))))) { + text = $send(text, 'gsub', [$$('InlineMenuMacroRx')], function $$17(){var $a, self = $$17.$$s == null ? this : $$17.$$s, menu = nil, items = nil, delim = nil, submenus = nil, menuitem = nil; -/** - * Get the number of columns in the table. - * @returns {number|undefined} - * @memberof Table - */ -Table.prototype.getColumnCount = function () { - return this.getAttribute('colcount') -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } menu = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)); + if ($truthy((items = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) { + + if ($truthy(items['$include?']($$('R_SB')))) { + items = items.$gsub($$('ESC_R_SB'), $$('R_SB')); + } if ($truthy((delim = ($truthy(items['$include?'](">")) ? (">") : (($truthy(items['$include?'](",")) ? (",") : (nil))))))) { + + submenus = $send(items.$split(delim), 'map', [], function $$18(it){ + + if (it == null) it = nil; + return it.$strip();}); + menuitem = submenus.$pop(); + } else { + $a = [[], items.$rstrip()], (submenus = $a[0]), (menuitem = $a[1]); + } } else { + $a = [[], nil], (submenus = $a[0]), (menuitem = $a[1]); + } return $$('Inline').$new(self, "menu", nil, $hash2(["attributes"], {"attributes": $hash2(["menu", "submenus", "menuitem"], {"menu": menu, "submenus": submenus, "menuitem": menuitem})})).$convert();}, {$$s: self}); + } if (($truthy(text['$include?']("\"")) && ($truthy(text['$include?'](">"))))) { + text = $send(text, 'gsub', [$$('InlineMenuRx')], function $$19(){var $a, $b, $c, self = $$19.$$s == null ? this : $$19.$$s, menu = nil, submenus = nil, menuitem = nil; -/** - * Set the number of columns in the table. - * @param {number} value - the value - * @memberof Table - */ -Table.prototype.setColumnCount = function (value) { - this.setAttribute('colcount', value) -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } $b = $send((($c = $gvars['~']) === nil ? nil : $c['$[]'](1)).$split(">"), 'map', [], function $$20(it){ + + if (it == null) it = nil; + return it.$strip();}), $a = $to_ary($b), (menu = ($a[0] == null ? nil : $a[0])), (submenus = $slice($a, 1)); + menuitem = submenus.$pop(); + return $$('Inline').$new(self, "menu", nil, $hash2(["attributes"], {"attributes": $hash2(["menu", "submenus", "menuitem"], {"menu": menu, "submenus": submenus, "menuitem": menuitem})})).$convert();}, {$$s: self}); + } } if (($truthy(found_macroish) && (($truthy(text['$include?']("image:")) || ($truthy(text['$include?']("icon:"))))))) { + text = $send(text, 'gsub', [$$('InlineImageMacroRx')], function $$21(){var $a, self = $$21.$$s == null ? this : $$21.$$s, type = nil, posattrs = nil, target = nil, attrs = nil; -// Rows + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } else if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']("icon:"))) { + $a = ["icon", ["size"]], (type = $a[0]), (posattrs = $a[1]); + } else { + $a = ["image", ["alt", "width", "height"]], (type = $a[0]), (posattrs = $a[1]); + } target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)); + attrs = self.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), posattrs, $hash2(["unescape_input"], {"unescape_input": true})); + if (!$eqeq(type, "icon")) { + + doc.$register("images", target); + attrs['$[]=']("imagesdir", doc_attrs['$[]']("imagesdir")); + } if ($truthy(($ret_or_1 = attrs['$[]']("alt")))) ; else { + attrs['$[]=']("alt", ($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attrs, '[]=', $a), $a[$a.length - 1])); + } return $$('Inline').$new(self, "image", nil, $hash2(["type", "target", "attributes"], {"type": type, "target": target, "attributes": attrs})).$convert();}, {$$s: self}); + } if ((($truthy(text['$include?']("((")) && ($truthy(text['$include?']("))")))) || (($truthy(found_macroish_short) && ($truthy(text['$include?']("dexterm"))))))) { + text = $send(text, 'gsub', [$$('InlineIndextermMacroRx')], function $$22(){var $a, $b, self = $$22.$$s == null ? this : $$22.$$s, attrlist = nil, primary = nil, attrs = nil, see_also = nil, term = nil, $ret_or_2 = nil, $ret_or_3 = nil, encl_text = nil, visible = nil, before = nil, after = nil, see = nil, subbed_term = nil, terms = nil; -/** - * @namespace - */ -var Rows = Opal.Asciidoctor.Table.Rows + + switch ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) { + case "indexterm": + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy((attrlist = self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), true, true))['$include?']("="))) { + if ($truthy((primary = (attrs = $$('AttributeList').$new(attrlist, self).$parse())['$[]'](1)))) { + + attrs['$[]=']("terms", [primary]); + if ($truthy((see_also = attrs['$[]']("see-also")))) { + attrs['$[]=']("see-also", ($truthy(see_also['$include?'](",")) ? ($send(see_also.$split(","), 'map', [], function $$23(it){ + + if (it == null) it = nil; + return it.$lstrip();})) : ([see_also]))); + } } else { + attrs = $hash2(["terms"], {"terms": attrlist}); + } + } else { + attrs = $hash2(["terms"], {"terms": self.$split_simple_csv(attrlist)}); + } return $$('Inline').$new(self, "indexterm", nil, $hash2(["attributes"], {"attributes": attrs})).$convert(); + case "indexterm2": + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy((term = self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), true, true))['$include?']("="))) { + + term = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = (attrs = $$('AttributeList').$new(term, self).$parse())['$[]'](1))) ? ($ret_or_3) : ((attrs = nil))))) ? ($ret_or_2) : (term)); + if (($truthy(attrs) && ($truthy((see_also = attrs['$[]']("see-also")))))) { + attrs['$[]=']("see-also", ($truthy(see_also['$include?'](",")) ? ($send(see_also.$split(","), 'map', [], function $$24(it){ + + if (it == null) it = nil; + return it.$lstrip();})) : ([see_also]))); + } } return $$('Inline').$new(self, "indexterm", term, $hash2(["attributes", "type"], {"attributes": attrs, "type": "visible"})).$convert(); + default: + + encl_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + if (($truthy(encl_text['$start_with?']("(")) && ($truthy(encl_text['$end_with?'](")"))))) { + + encl_text = encl_text.$slice(1, $rb_minus(encl_text.$length(), 2)); + $a = [true, "(", ")"], (visible = $a[0]), (before = $a[1]), (after = $a[2]); + } else { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } + } else { + + visible = true; + if ($truthy(encl_text['$start_with?']("("))) { + if ($truthy(encl_text['$end_with?'](")"))) { + $a = [encl_text.$slice(1, $rb_minus(encl_text.$length(), 2)), false], (encl_text = $a[0]), (visible = $a[1]); + } else { + $a = [encl_text.$slice(1, encl_text.$length()), "(", ""], (encl_text = $a[0]), (before = $a[1]), (after = $a[2]); + } + } else if ($truthy(encl_text['$end_with?'](")"))) { + $a = [encl_text.$chop(), "", ")"], (encl_text = $a[0]), (before = $a[1]), (after = $a[2]); + } } if ($truthy(visible)) { + + if ($truthy((term = self.$normalize_text(encl_text, true))['$include?'](";&"))) { + if ($truthy(term['$include?'](" >> "))) { + + $b = term.$partition(" >> "), $a = $to_ary($b), (term = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (see = ($a[2] == null ? nil : $a[2])); + attrs = $hash2(["see"], {"see": see}); + } else if ($truthy(term['$include?'](" &> "))) { + + $b = term.$split(" &> "), $a = $to_ary($b), (term = ($a[0] == null ? nil : $a[0])), (see_also = $slice($a, 1)); + attrs = $hash2(["see-also"], {"see-also": see_also}); + } + } subbed_term = $$('Inline').$new(self, "indexterm", term, $hash2(["attributes", "type"], {"attributes": attrs, "type": "visible"})).$convert(); + } else { + + attrs = $hash2([], {}); + if ($truthy((terms = self.$normalize_text(encl_text, true))['$include?'](";&"))) { + if ($truthy(terms['$include?'](" >> "))) { + + $b = terms.$partition(" >> "), $a = $to_ary($b), (terms = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (see = ($a[2] == null ? nil : $a[2])); + attrs['$[]=']("see", see); + } else if ($truthy(terms['$include?'](" &> "))) { + + $b = terms.$split(" &> "), $a = $to_ary($b), (terms = ($a[0] == null ? nil : $a[0])), (see_also = $slice($a, 1)); + attrs['$[]=']("see-also", see_also); + } + } attrs['$[]=']("terms", self.$split_simple_csv(terms)); + subbed_term = $$('Inline').$new(self, "indexterm", nil, $hash2(["attributes"], {"attributes": attrs})).$convert(); + } if ($truthy(before)) { + return "" + (before) + (subbed_term) + (after) + } else { + return subbed_term + } }}, {$$s: self}); + } if (($truthy(found_colon) && ($truthy(text['$include?']("://"))))) { + text = $send(text, 'gsub', [$$('InlineLinkRx')], function $$25(){var $a, $b, self = $$25.$$s == null ? this : $$25.$$s, target = nil, rs_idx = nil, prefix = nil, suffix = nil, link_text = nil, attrs = nil, link_opts = nil, new_link_text = nil, bare = nil; + + + if ($truthy((target = $rb_plus((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) ? ($ret_or_1) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))))))['$start_with?']($$('RS')))) { + return $rb_plus((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(0, (rs_idx = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$length())), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice($rb_plus(rs_idx, 1), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())) + } $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)), ""], (prefix = $a[0]), (suffix = $a[1]); + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))) { + + if ($eqeq(prefix, "link:")) { + prefix = ""; + } if ($truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))['$empty?']())) { + link_text = nil; + } } else { + + + switch (prefix) { + case "link:": + case "\"": + case "'": + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + } + switch ((($a = $gvars['~']) === nil ? nil : $a['$[]'](6))) { + case ";": + + if (($truthy(prefix['$start_with?']("<")) && ($truthy(target['$end_with?'](">"))))) { + + prefix = prefix.$slice(4, prefix.$length()); + target = target.$slice(0, $rb_minus(target.$length(), 4)); + } else if ($truthy((target = target.$chop())['$end_with?'](")"))) { + + target = target.$chop(); + suffix = ");"; + } else { + suffix = ";"; + } if ($truthy(target['$end_with?']("://"))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + } break; + case ":": + + if ($truthy((target = target.$chop())['$end_with?'](")"))) { + + target = target.$chop(); + suffix = "):"; + } else { + suffix = ":"; + } if ($truthy(target['$end_with?']("://"))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + } break; + } } $a = [nil, $hash2(["type"], {"type": "link"})], (attrs = $a[0]), (link_opts = $a[1]); + if ($truthy(link_text)) { + + if ($truthy(link_text['$include?']($$('R_SB')))) { + new_link_text = (link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB'))); + } if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) { + + $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])); + new_link_text = link_text; + link_opts['$[]=']("id", attrs['$[]']("id")); + } if ($truthy(link_text['$end_with?']("^"))) { + + new_link_text = (link_text = link_text.$chop()); + if ($truthy(attrs)) { + if ($truthy(($ret_or_1 = attrs['$[]']("window")))) ; else { + attrs['$[]=']("window", "_blank"); + } + } else { + attrs = $hash2(["window"], {"window": "_blank"}); + } } if (($truthy(new_link_text) && ($truthy(new_link_text['$empty?']())))) { + + link_text = ($truthy(doc_attrs['$key?']("hide-uri-scheme")) ? (target.$sub($$('UriSniffRx'), "")) : (target)); + bare = true; + } } else { + + link_text = ($truthy(doc_attrs['$key?']("hide-uri-scheme")) ? (target.$sub($$('UriSniffRx'), "")) : (target)); + bare = true; + } if ($truthy(bare)) { + if ($truthy(attrs)) { + attrs['$[]=']("role", ($truthy(attrs['$key?']("role")) ? ("bare " + (attrs['$[]']("role"))) : ("bare"))); + } else { + attrs = $hash2(["role"], {"role": "bare"}); + } + } doc.$register("links", ($a = ["target", target], $send(link_opts, '[]=', $a), $a[$a.length - 1])); + if ($truthy(attrs)) { + link_opts['$[]=']("attributes", attrs); + } return "" + (prefix) + ($$('Inline').$new(self, "anchor", link_text, link_opts).$convert()) + (suffix);}, {$$s: self}); + } if (($truthy(found_macroish) && (($truthy(text['$include?']("link:")) || ($truthy(text['$include?']("ilto:"))))))) { + text = $send(text, 'gsub', [$$('InlineLinkMacroRx')], function $$26(){var $a, $b, self = $$26.$$s == null ? this : $$26.$$s, mailto = nil, target = nil, mailto_text = nil, attrs = nil, link_opts = nil, link_text = nil; -/** - * Create a new Rows element. - * @param {array<array<Cell>>} head - * @param {array<array<Cell>>} foot - * @param {array<array<Cell>>} body - * @returns Rows - */ -Rows.create = function (head, foot, body) { - return this.$new(head, foot, body) -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } else if ($truthy((mailto = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) { + target = $rb_plus("mailto:", (mailto_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))); + } else { + target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)); + } $a = [nil, $hash2(["type"], {"type": "link"})], (attrs = $a[0]), (link_opts = $a[1]); + if (!$truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))['$empty?']())) { + + if ($truthy(link_text['$include?']($$('R_SB')))) { + link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB')); + } if ($truthy(mailto)) { + if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?'](","))))) { + + $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])); + link_opts['$[]=']("id", attrs['$[]']("id")); + if ($truthy(attrs['$key?'](2))) { + if ($truthy(attrs['$key?'](3))) { + target = "" + (target) + "?subject=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](2))) + "&body=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](3))); + } else { + target = "" + (target) + "?subject=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](2))); + } + } } + } else if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) { + + $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])); + link_opts['$[]=']("id", attrs['$[]']("id")); + } if ($truthy(link_text['$end_with?']("^"))) { + + link_text = link_text.$chop(); + if ($truthy(attrs)) { + if ($truthy(($ret_or_1 = attrs['$[]']("window")))) ; else { + attrs['$[]=']("window", "_blank"); + } + } else { + attrs = $hash2(["window"], {"window": "_blank"}); + } } } if ($truthy(link_text['$empty?']())) { + if ($truthy(mailto)) { + link_text = mailto_text; + } else { + + if ($truthy(doc_attrs['$key?']("hide-uri-scheme"))) { + if ($truthy((link_text = target.$sub($$('UriSniffRx'), ""))['$empty?']())) { + link_text = target; + } + } else { + link_text = target; + } if ($truthy(attrs)) { + attrs['$[]=']("role", ($truthy(attrs['$key?']("role")) ? ("bare " + (attrs['$[]']("role"))) : ("bare"))); + } else { + attrs = $hash2(["role"], {"role": "bare"}); + } } + } doc.$register("links", ($a = ["target", target], $send(link_opts, '[]=', $a), $a[$a.length - 1])); + if ($truthy(attrs)) { + link_opts['$[]=']("attributes", attrs); + } return $$('Inline').$new(self, "anchor", link_text, link_opts).$convert();}, {$$s: self}); + } if ($truthy(text['$include?']("@"))) { + text = $send(text, 'gsub', [$$('InlineEmailRx')], function $$27(){var $a, self = $$27.$$s == null ? this : $$27.$$s, target = nil, address = nil; -/** - * Get head rows. - * @returns {array<array<Cell>>} - */ -Rows.prototype.getHead = function () { - return this.head -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + return ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS')) ? ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)))) + } target = $rb_plus("mailto:", (address = (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)))); + doc.$register("links", target); + return $$('Inline').$new(self, "anchor", address, $hash2(["type", "target"], {"type": "link", "target": target})).$convert();}, {$$s: self}); + } if ((($truthy(found_square_bracket) && ($eqeq(self.context, "list_item"))) && ($eqeq(self.parent.$style(), "bibliography")))) { + text = $send(text, 'sub', [$$('InlineBiblioAnchorRx')], function $$28(){var $a, self = $$28.$$s == null ? this : $$28.$$s; -/** - * Get foot rows. - * @returns {array<array<Cell>>} - */ -Rows.prototype.getFoot = function () { - return this.foot -} + return $$('Inline').$new(self, "anchor", (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), $hash2(["type", "id"], {"type": "bibref", "id": (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))})).$convert()}, {$$s: self}); + } if ((($truthy(found_square_bracket) && ($truthy(text['$include?']("[[")))) || (($truthy(found_macroish) && ($truthy(text['$include?']("or:"))))))) { + text = $send(text, 'gsub', [$$('InlineAnchorRx')], function $$29(){var $a, self = $$29.$$s == null ? this : $$29.$$s, id = nil, reftext = nil; -/** - * Get body rows. - * @returns {array<array<Cell>>} - */ -Rows.prototype.getBody = function () { - return this.body -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy((id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) { + reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + } else { + + id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4)); + if (($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)))) && ($truthy(reftext['$include?']($$('R_SB')))))) { + reftext = reftext.$gsub($$('ESC_R_SB'), $$('R_SB')); + } } return $$('Inline').$new(self, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id})).$convert();}, {$$s: self}); + } if ((($truthy(text['$include?']("&")) && ($truthy(text['$include?'](";&l")))) || (($truthy(found_macroish) && ($truthy(text['$include?']("xref:"))))))) { + text = $send(text, 'gsub', [$$('InlineXrefMacroRx')], function $$30(){var $a, $b, self = $$30.$$s == null ? this : $$30.$$s, attrs = nil, refid = nil, link_text = nil, macro = nil, fragment = nil, hash_idx = nil, fragment_len = nil, path = nil, src2src = nil, target = nil; -/** - * Retrieve the rows grouped by section as a nested Array. - * - * Creates a 2-dimensional array of two element entries. - * The first element is the section name as a string. - * The second element is the Array of rows in that section. - * The entries are in document order (head, foot, body). - * @returns {[[string, array<array<Cell>>], [string, array<array<Cell>>], [string, array<array<Cell>>]]} - */ -Rows.prototype.bySection = function () { - return [['head', this.head], ['body', this.body], ['foot', this.foot]] -} + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } attrs = $hash2([], {}); + if ($truthy((refid = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) { + if ($truthy(refid['$include?'](","))) { + + $b = refid.$partition(","), $a = $to_ary($b), (refid = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (link_text = ($a[2] == null ? nil : $a[2])); + if ($truthy((link_text = link_text.$lstrip())['$empty?']())) { + link_text = nil; + } } + } else { + + macro = true; + refid = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)); + if ($truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3))))) { + + if ($truthy(link_text['$include?']($$('R_SB')))) { + link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB')); + } if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) { + $b = self.$extract_attributes_from_text(link_text), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])); + } } } if ($truthy(doc.$compat_mode())) { + fragment = refid; + } else if (($truthy((hash_idx = refid.$index("#"))) && ($neqeq(refid['$[]']($rb_minus(hash_idx, 1)), "&")))) { + if ($truthy($rb_gt(hash_idx, 0))) { + + if ($truthy($rb_gt((fragment_len = $rb_minus($rb_minus(refid.$length(), 1), hash_idx)), 0))) { + $a = [refid.$slice(0, hash_idx), refid.$slice($rb_plus(hash_idx, 1), fragment_len)], (path = $a[0]), (fragment = $a[1]); + } else { + path = refid.$chop(); + } if ($truthy(macro)) { + if ($truthy(path['$end_with?'](".adoc"))) { + src2src = (path = path.$slice(0, $rb_minus(path.$length(), 5))); + } else if ($not($$('Helpers')['$extname?'](path))) { + src2src = path; + } + } else if ($truthy($send(path, 'end_with?', $to_a($$('ASCIIDOC_EXTENSIONS').$keys())))) { + src2src = (path = path.$slice(0, path.$rindex("."))); + } else { + src2src = path; + } } else { + $a = [refid, refid.$slice(1, refid.$length())], (target = $a[0]), (fragment = $a[1]); + } + } else if ($truthy(macro)) { + if ($truthy(refid['$end_with?'](".adoc"))) { + src2src = (path = refid.$slice(0, $rb_minus(refid.$length(), 5))); + } else if ($truthy($$('Helpers')['$extname?'](refid))) { + path = refid; + } else { + fragment = refid; + } + } else { + fragment = refid; + } if ($truthy(target)) { + + refid = fragment; + if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) { + self.$logger().$info("possible invalid reference: " + (refid)); + } } else if ($truthy(path)) { + if (($truthy(src2src) && (($eqeq(doc.$attributes()['$[]']("docname"), path) || ($truthy(doc.$catalog()['$[]']("includes")['$[]'](path))))))) { + if ($truthy(fragment)) { + + $a = [fragment, nil, "#" + (fragment)], (refid = $a[0]), (path = $a[1]), (target = $a[2]); + if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) { + self.$logger().$info("possible invalid reference: " + (refid)); + } } else { + $a = [nil, nil, "#"], (refid = $a[0]), (path = $a[1]), (target = $a[2]); + } + } else { + + $a = [path, "" + (($truthy(($ret_or_1 = doc.$attributes()['$[]']("relfileprefix"))) ? ($ret_or_1) : (""))) + (path) + (($truthy(src2src) ? (doc.$attributes().$fetch("relfilesuffix", doc.$outfilesuffix())) : ("")))], (refid = $a[0]), (path = $a[1]); + if ($truthy(fragment)) { + $a = ["" + (refid) + "#" + (fragment), "" + (path) + "#" + (fragment)], (refid = $a[0]), (target = $a[1]); + } else { + target = path; + } } + } else if (($truthy(doc.$compat_mode()) || ($not($$('Compliance').$natural_xrefs())))) { + + $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]); + if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) { + self.$logger().$info("possible invalid reference: " + (refid)); + } } else if ($truthy(doc.$catalog()['$[]']("refs")['$[]'](fragment))) { + $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]); + } else if ((($truthy(fragment['$include?'](" ")) || ($neqeq(fragment.$downcase(), fragment))) && ($truthy((refid = doc.$resolve_id(fragment)))))) { + $a = [refid, "#" + (refid)], (fragment = $a[0]), (target = $a[1]); + } else { + + $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]); + if ($truthy(self.$logger()['$info?']())) { + self.$logger().$info("possible invalid reference: " + (refid)); + } } attrs['$[]=']("path", path); + attrs['$[]=']("fragment", fragment); + attrs['$[]=']("refid", refid); + return $$('Inline').$new(self, "anchor", link_text, $hash2(["type", "target", "attributes"], {"type": "xref", "target": target, "attributes": attrs})).$convert();}, {$$s: self}); + } if (($truthy(found_macroish) && ($truthy(text['$include?']("tnote"))))) { + text = $send(text, 'gsub', [$$('InlineFootnoteMacroRx')], function $$31(){var $a, $b, $c, self = $$31.$$s == null ? this : $$31.$$s, id = nil, content = nil, footnote = nil, index = nil, type = nil, target = nil; + + + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) { + + $b = (($c = $gvars['~']) === nil ? nil : $c['$[]'](3)).$split(",", 2), $a = $to_ary($b), (id = ($a[0] == null ? nil : $a[0])), (content = ($a[1] == null ? nil : $a[1])); + if (!$truthy(doc.$compat_mode())) { + self.$logger().$warn("found deprecated footnoteref macro: " + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))) + "; use footnote macro with target instead"); + } } else { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + } + } else { + + id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)); + content = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + } if ($truthy(id)) { + if ($truthy((footnote = $send(doc.$footnotes(), 'find', [], function $$32(candidate){ + + if (candidate == null) candidate = nil; + return candidate.$id()['$=='](id);})))) { + + $a = [footnote.$index(), footnote.$text()], (index = $a[0]), (content = $a[1]); + $a = ["xref", id, nil], (type = $a[0]), (target = $a[1]), (id = $a[2]); + } else if ($truthy(content)) { + + content = self.$restore_passthroughs(self.$normalize_text(content, true, true)); + index = doc.$counter("footnote-number"); + doc.$register("footnotes", $$$($$('Document'), 'Footnote').$new(index, id, content)); + $a = ["ref", nil], (type = $a[0]), (target = $a[1]); + } else { + + self.$logger().$warn("invalid footnote reference: " + (id)); + $a = ["xref", id, id, nil], (type = $a[0]), (target = $a[1]), (content = $a[2]), (id = $a[3]); + } + } else if ($truthy(content)) { + + content = self.$restore_passthroughs(self.$normalize_text(content, true, true)); + index = doc.$counter("footnote-number"); + doc.$register("footnotes", $$$($$('Document'), 'Footnote').$new(index, id, content)); + type = (target = nil); + } else { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)) + } return $$('Inline').$new(self, "footnote", content, $hash2(["attributes", "id", "target", "type"], {"attributes": $hash2(["index"], {"index": index}), "id": id, "target": target, "type": type})).$convert();}, {$$s: self}); + } return text; + }); + + $def(self, '$sub_post_replacements', function $$sub_post_replacements(text) { + var self = this, lines = nil, last = nil; + if (self.document == null) self.document = nil; + if (self.attributes == null) self.attributes = nil; -// Table Column + if (($truthy(self.attributes['$[]']("hardbreaks-option")) || ($truthy(self.document.$attributes()['$[]']("hardbreaks-option"))))) { + + lines = text.$split($$('LF'), -1); + if ($truthy($rb_lt(lines.$size(), 2))) { + return text + } last = lines.$pop(); + return $send(lines, 'map', [], function $$33(line){var self = $$33.$$s == null ? this : $$33.$$s; -/** - * Methods to manage the columns of an AsciiDoc table. - * In particular, it keeps track of the column specs. - * @namespace - * @extends AbstractNode - */ -var Column = Opal.Asciidoctor.Table.Column + + if (line == null) line = nil; + return $$('Inline').$new(self, "break", ($truthy(line['$end_with?']($$('HARD_LINE_BREAK'))) ? (line.$slice(0, $rb_minus(line.$length(), 2))) : (line)), $hash2(["type"], {"type": "line"})).$convert();}, {$$s: self})['$<<'](last).$join($$('LF')); + } else if (($truthy(text['$include?']($$('PLUS'))) && ($truthy(text['$include?']($$('HARD_LINE_BREAK')))))) { + return $send(text, 'gsub', [$$('HardLineBreakRx')], function $$34(){var $a, self = $$34.$$s == null ? this : $$34.$$s; -/** - * Create a new Column element. - * @param {Table} table - * @param {number} index - * @param {Object|undefined} attributes - * @returns Column - */ -Column.create = function (table, index, attributes) { - return this.$new(table, index, toHash(attributes)) -} + return $$('Inline').$new(self, "break", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $hash2(["type"], {"type": "line"})).$convert()}, {$$s: self}) + } else { + return text + } + }); + + $def(self, '$sub_source', function $$sub_source(source, process_callouts) { + var self = this; -/** - * Get the column number of this cell. - * @returns {number|undefined} - * @memberof Column - */ -Column.prototype.getColumnNumber = function () { - return this.getAttribute('colnumber') -} + if ($truthy(process_callouts)) { + return self.$sub_callouts(self.$sub_specialchars(source)) + } else { + + return self.$sub_specialchars(source); + } + }); + + $def(self, '$sub_callouts', function $$sub_callouts(text) { + var self = this, callout_rx = nil, autonum = nil; -/** - * Get the width of this cell. - * @returns {string|undefined} - * @memberof Column - */ -Column.prototype.getWidth = function () { - return this.getAttribute('width') -} + + callout_rx = ($truthy(self['$attr?']("line-comment")) ? ($$('CalloutSourceRxMap')['$[]'](self.$attr("line-comment"))) : ($$('CalloutSourceRx'))); + autonum = 0; + return $send(text, 'gsub', [callout_rx], function $$35(){var $a, self = $$35.$$s == null ? this : $$35.$$s, $ret_or_1 = nil; + if (self.document == null) self.document = nil; -/** - * Get the horizontal align of this cell. - * @returns {string|undefined} - * @memberof Column - */ -Column.prototype.getHorizontalAlign = function () { - return this.getAttribute('halign') -} + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$sub($$('RS'), "") + } else { + return $$('Inline').$new(self, "callout", ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))), $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) ? ($ret_or_1) : (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), "--") ? (["<!--", "-->"]) : (nil))))})})).$convert() + }}, {$$s: self}); + }); + + $def(self, '$highlight_source', function $$highlight_source(source, process_callouts) { + var $a, $b, self = this, syntax_hl = nil, callout_marks = nil, doc_attrs = nil, syntax_hl_name = nil, start_line_number = nil, linenums_mode = nil, $ret_or_1 = nil, highlight_lines = nil, highlighted = nil, source_offset = nil; + if (self.document == null) self.document = nil; + if (self.passthroughs == null) self.passthroughs = nil; -/** - * Get the vertical align of this cell. - * @returns {string|undefined} - * @memberof Column - */ -Column.prototype.getVerticalAlign = function () { - return this.getAttribute('valign') -} + + if (!($truthy((syntax_hl = self.document.$syntax_highlighter())) && ($truthy(syntax_hl['$highlight?']())))) { + return self.$sub_source(source, process_callouts) + } if ($truthy(process_callouts)) { + $b = self.$extract_callouts(source), $a = $to_ary($b), (source = ($a[0] == null ? nil : $a[0])), (callout_marks = ($a[1] == null ? nil : $a[1])); + } doc_attrs = self.document.$attributes(); + syntax_hl_name = syntax_hl.$name(); + if (($truthy((linenums_mode = ($truthy(self['$attr?']("linenums")) ? (($truthy(($ret_or_1 = doc_attrs['$[]']("" + (syntax_hl_name) + "-linenums-mode"))) ? ($ret_or_1) : ("table")).$to_sym()) : (nil)))) && ($truthy($rb_lt((start_line_number = self.$attr("start", 1).$to_i()), 1))))) { + start_line_number = 1; + } if ($truthy(self['$attr?']("highlight"))) { + highlight_lines = self.$resolve_lines_to_highlight(source, self.$attr("highlight"), start_line_number); + } $b = syntax_hl.$highlight(self, source, self.$attr("language"), $hash2(["callouts", "css_mode", "highlight_lines", "number_lines", "start_line_number", "style"], {"callouts": callout_marks, "css_mode": ($truthy(($ret_or_1 = doc_attrs['$[]']("" + (syntax_hl_name) + "-css"))) ? ($ret_or_1) : ("class")).$to_sym(), "highlight_lines": highlight_lines, "number_lines": linenums_mode, "start_line_number": start_line_number, "style": doc_attrs['$[]']("" + (syntax_hl_name) + "-style")})), $a = $to_ary($b), (highlighted = ($a[0] == null ? nil : $a[0])), (source_offset = ($a[1] == null ? nil : $a[1])); + if (!$truthy(self.passthroughs['$empty?']())) { + highlighted = highlighted.$gsub($$('HighlightedPassSlotRx'), "" + ($$('PASS_START')) + "\\1" + ($$('PASS_END'))); + } if ($truthy(callout_marks['$nil_or_empty?']())) { + return highlighted + } else { + + return self.$restore_callouts(highlighted, callout_marks, source_offset); + } }); + + $def(self, '$resolve_lines_to_highlight', function $$resolve_lines_to_highlight(source, spec, start) { + var lines = nil, shift = nil; -/** - * Get the style of this cell. - * @returns {string} - * @memberof Column - */ -Column.prototype.getStyle = function () { - var style = this.style - return style === Opal.nil ? undefined : style -} + + if (start == null) start = nil; + lines = []; + if ($truthy(spec['$include?'](" "))) { + spec = spec.$delete(" "); + } $send(($truthy(spec['$include?'](",")) ? (spec.$split(",")) : (spec.$split(";"))), 'map', [], function $$36(entry){var $a, $b, negate = nil, delim = nil, from = nil, to = nil, line = nil; + + + if (entry == null) entry = nil; + if ($truthy(entry['$start_with?']("!"))) { + + entry = entry.$slice(1, entry.$length()); + negate = true; + } if ($truthy((delim = ($truthy(entry['$include?']("..")) ? ("..") : (($truthy(entry['$include?']("-")) ? ("-") : (nil))))))) { + + $b = entry.$partition(delim), $a = $to_ary($b), (from = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (to = ($a[2] == null ? nil : $a[2])); + if (($truthy(to['$empty?']()) || ($truthy($rb_lt((to = to.$to_i()), 0))))) { + to = $rb_plus(source.$count($$('LF')), 1); + } if ($truthy(negate)) { + return (lines = $rb_minus(lines, Opal.Range.$new(from.$to_i(), to, false).$to_a())) + } else { + return (lines = lines['$|'](Opal.Range.$new(from.$to_i(), to, false).$to_a())) + } } else if ($truthy(negate)) { + return lines.$delete(entry.$to_i()) + } else if ($not(lines['$include?']((line = entry.$to_i())))) { + return lines['$<<'](line) + } else { + return nil + }}); + if (!$eqeq((shift = ($truthy(start) ? ($rb_minus(start, 1)) : (0))), 0)) { + lines = $send(lines, 'map', [], function $$37(it){ + + if (it == null) it = nil; + return $rb_minus(it, shift);}); + } return lines.$sort(); + }, -3); + + $def(self, '$extract_passthroughs', function $$extract_passthroughs(text) { + var $a, $b, self = this, compat_mode = nil, passthrus = nil, pass_inline_char1 = nil, pass_inline_char2 = nil, pass_inline_rx = nil; + if (self.document == null) self.document = nil; + if (self.passthroughs == null) self.passthroughs = nil; -// Table Cell + + compat_mode = self.document.$compat_mode(); + passthrus = self.passthroughs; + if ((($truthy(text['$include?']("++")) || ($truthy(text['$include?']("$$")))) || ($truthy(text['$include?']("ss:"))))) { + text = $send(text, 'gsub', [$$('InlinePassMacroRx')], function $$38(){var $a, self = $$38.$$s == null ? this : $$38.$$s, boundary = nil, attrlist = nil, escape_count = nil, preceding = nil, old_behavior = nil, attributes = nil, subs = nil, passthru_key = nil, $ret_or_1 = nil; -/** - * Methods for managing the cells in an AsciiDoc table. - * @namespace - * @extends AbstractBlock - */ -var Cell = Opal.Asciidoctor.Table.Cell + + if ($truthy((boundary = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))) { + + if (($truthy(compat_mode) && ($eqeq(boundary, "++")))) { + return "" + (($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) ? ("" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + "[" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) + "]" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) : ("" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))))) + "++" + (self.$extract_passthroughs((($a = $gvars['~']) === nil ? nil : $a['$[]'](5)))) + "++" + } if ($truthy((attrlist = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) { + if ($truthy($rb_gt((escape_count = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$length()), 0))) { + return "" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + "[" + (attrlist) + "]" + ($rb_times($$('RS'), $rb_minus(escape_count, 1))) + (boundary) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))) + (boundary) + } else if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS'))) { + preceding = "[" + (attrlist) + "]"; + } else if ($eqeq(boundary, "++")) { + if ($eqeq(attrlist, "x-")) { + + old_behavior = true; + attributes = $hash2([], {}); + } else if ($truthy(attrlist['$end_with?'](" x-"))) { + + old_behavior = true; + attributes = self.$parse_quoted_text_attributes(attrlist.$slice(0, $rb_minus(attrlist.$length(), 3))); + } else { + attributes = self.$parse_quoted_text_attributes(attrlist); + } + } else { + attributes = self.$parse_quoted_text_attributes(attrlist); + } + } else if ($truthy($rb_gt((escape_count = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$length()), 0))) { + return "" + ($rb_times($$('RS'), $rb_minus(escape_count, 1))) + (boundary) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))) + (boundary) + } subs = ($eqeq(boundary, "+++") ? ([]) : ($$('BASIC_SUBS'))); + if ($truthy(attributes)) { + if ($truthy(old_behavior)) { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type", "attributes"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": $$('NORMAL_SUBS'), "type": "monospaced", "attributes": attributes})); + } else { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type", "attributes"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": subs, "type": "unquoted", "attributes": attributes})); + } + } else { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": subs})); + } } else { + + if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](6)), $$('RS'))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()) + } if ($truthy((subs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](7))))) { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](8)), nil, true), "subs": self.$resolve_pass_subs(subs)})); + } else { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text"], {"text": self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](8)), nil, true)})); + } } return "" + (($truthy(($ret_or_1 = preceding)) ? ($ret_or_1) : (""))) + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self}); + } $b = $$('InlinePassRx')['$[]'](compat_mode), $a = $to_ary($b), (pass_inline_char1 = ($a[0] == null ? nil : $a[0])), (pass_inline_char2 = ($a[1] == null ? nil : $a[1])), (pass_inline_rx = ($a[2] == null ? nil : $a[2])); + if (($truthy(text['$include?'](pass_inline_char1)) || (($truthy(pass_inline_char2) && ($truthy(text['$include?'](pass_inline_char2))))))) { + text = $send(text, 'gsub', [pass_inline_rx], function $$39(){var $c, self = $$39.$$s == null ? this : $$39.$$s, preceding = nil, attrlist = nil, $ret_or_1 = nil, escaped = nil, quoted_text = nil, format_mark = nil, content = nil, old_behavior = nil, old_behavior_forced = nil, attributes = nil, passthru_key = nil, subs = nil; -/** - * Create a new Cell element - * @param {Column} column - * @param {string} cellText - * @param {Object|undefined} attributes - * @param {Object|undefined} opts - * @returns {Cell} - */ -Cell.create = function (column, cellText, attributes, opts) { - return this.$new(column, cellText, toHash(attributes), toHash(opts)) -} + + preceding = (($c = $gvars['~']) === nil ? nil : $c['$[]'](1)); + attrlist = ($truthy(($ret_or_1 = (($c = $gvars['~']) === nil ? nil : $c['$[]'](4)))) ? ($ret_or_1) : ((($c = $gvars['~']) === nil ? nil : $c['$[]'](3)))); + if ($truthy((($c = $gvars['~']) === nil ? nil : $c['$[]'](5)))) { + escaped = true; + } quoted_text = (($c = $gvars['~']) === nil ? nil : $c['$[]'](6)); + format_mark = (($c = $gvars['~']) === nil ? nil : $c['$[]'](7)); + content = (($c = $gvars['~']) === nil ? nil : $c['$[]'](8)); + if ($truthy(compat_mode)) { + old_behavior = true; + } else if (($truthy(attrlist) && (($eqeq(attrlist, "x-") || ($truthy(attrlist['$end_with?'](" x-"))))))) { + old_behavior = (old_behavior_forced = true); + } if ($truthy(attrlist)) { + if ($truthy(escaped)) { + return "" + (preceding) + "[" + (attrlist) + "]" + (quoted_text.$slice(1, quoted_text.$length())) + } else if ($eqeq(preceding, $$('RS'))) { + + if (($truthy(old_behavior_forced) && ($eqeq(format_mark, "`")))) { + return "" + (preceding) + "[" + (attrlist) + "]" + (quoted_text) + } preceding = "[" + (attrlist) + "]"; + } else if ($truthy(old_behavior_forced)) { + attributes = ($eqeq(attrlist, "x-") ? ($hash2([], {})) : (self.$parse_quoted_text_attributes(attrlist.$slice(0, $rb_minus(attrlist.$length(), 3))))); + } else { + attributes = self.$parse_quoted_text_attributes(attrlist); + } + } else if ($truthy(escaped)) { + return "" + (preceding) + (quoted_text.$slice(1, quoted_text.$length())) + } else if (($truthy(compat_mode) && ($eqeq(preceding, $$('RS'))))) { + return quoted_text + } if ($truthy(compat_mode)) { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": $$('BASIC_SUBS'), "attributes": attributes, "type": "monospaced"})); + } else if ($truthy(attributes)) { + if ($truthy(old_behavior)) { + + subs = ($eqeq(format_mark, "`") ? ($$('BASIC_SUBS')) : ($$('NORMAL_SUBS'))); + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": subs, "attributes": attributes, "type": "monospaced"})); + } else { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": $$('BASIC_SUBS'), "attributes": attributes, "type": "unquoted"})); + } + } else { + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": content, "subs": $$('BASIC_SUBS')})); + } return "" + (preceding) + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self}); + } if (($truthy(text['$include?'](":")) && (($truthy(text['$include?']("stem:")) || ($truthy(text['$include?']("math:"))))))) { + text = $send(text, 'gsub', [$$('InlineStemMacroRx')], function $$40(){var $c, self = $$40.$$s == null ? this : $$40.$$s, type = nil, subs = nil, content = nil, passthru_key = nil; + if (self.document == null) self.document = nil; -/** - * Get the column span of this {@link Cell} node. - * @returns {number} - An Integer of the number of columns this cell will span (default: undefined) - * @memberof Cell - */ -Cell.prototype.getColumnSpan = function () { - var colspan = this.colspan - return colspan === Opal.nil ? undefined : colspan -} + + if ($truthy((($c = $gvars['~']) === nil ? nil : $c['$[]'](0))['$start_with?']($$('RS')))) { + return (($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$slice(1, (($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$length()) + } if ($eqeq((type = (($c = $gvars['~']) === nil ? nil : $c['$[]'](1)).$to_sym()), "stem")) { + type = $$('STEM_TYPE_ALIASES')['$[]'](self.document.$attributes()['$[]']("stem")).$to_sym(); + } subs = (($c = $gvars['~']) === nil ? nil : $c['$[]'](2)); + content = self.$normalize_text((($c = $gvars['~']) === nil ? nil : $c['$[]'](3)), nil, true); + if ((($eqeq(type, "latexmath") && ($truthy(content['$start_with?']("$")))) && ($truthy(content['$end_with?']("$"))))) { + content = content.$slice(1, $rb_minus(content.$length(), 2)); + } subs = ($truthy(subs) ? (self.$resolve_pass_subs(subs)) : (($truthy(self.document['$basebackend?']("html")) ? ($$('BASIC_SUBS')) : (nil)))); + passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type"], {"text": content, "subs": subs, "type": type})); + return "" + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self}); + } return text; + }); + + $def(self, '$restore_passthroughs', function $$restore_passthroughs(text) { + var self = this, passthrus = nil; + if (self.passthroughs == null) self.passthroughs = nil; -/** - * Set the column span of this {@link Cell} node. - * @param {number} value - * @returns {number} - The new colspan value - * @memberof Cell - */ -Cell.prototype.setColumnSpan = function (value) { - return this['$colspan='](value) -} + + passthrus = self.passthroughs; + return $send(text, 'gsub', [$$('PassSlotRx')], function $$41(){var $a, self = $$41.$$s == null ? this : $$41.$$s, pass = nil, subbed_text = nil, type = nil, attributes = nil, id = nil; -/** - * Get the row span of this {@link Cell} node - * @returns {number|undefined} - An Integer of the number of rows this cell will span (default: undefined) - * @memberof Cell - */ -Cell.prototype.getRowSpan = function () { - var rowspan = this.rowspan - return rowspan === Opal.nil ? undefined : rowspan -} + if ($truthy((pass = passthrus['$[]']((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$to_i())))) { + + subbed_text = self.$apply_subs(pass['$[]']("text"), pass['$[]']("subs")); + if ($truthy((type = pass['$[]']("type")))) { + + if ($truthy((attributes = pass['$[]']("attributes")))) { + id = attributes['$[]']("id"); + } subbed_text = $$('Inline').$new(self, "quoted", subbed_text, $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert(); + } if ($truthy(subbed_text['$include?']($$('PASS_START')))) { + return self.$restore_passthroughs(subbed_text) + } else { + return subbed_text + } } else { + + self.$logger().$error("unresolved passthrough detected: " + (text)); + return "??pass??"; + }}, {$$s: self}); + }); + + $def(self, '$resolve_subs', function $$resolve_subs(subs, type, defaults, subject) { + var self = this, candidates = nil, modifiers_present = nil, resolved = nil, invalid = nil; -/** - * Set the row span of this {@link Cell} node - * @param {number} value - * @returns {number} - The new rowspan value - * @memberof Cell - */ -Cell.prototype.setRowSpan = function (value) { - return this['$rowspan='](value) -} + + if (type == null) type = "block"; + if (defaults == null) defaults = nil; + if (subject == null) subject = nil; + if ($truthy(subs['$nil_or_empty?']())) { + return nil + } candidates = nil; + if ($truthy(subs['$include?'](" "))) { + subs = subs.$delete(" "); + } modifiers_present = $$('SubModifierSniffRx')['$match?'](subs); + $send(subs.$split(","), 'each', [], function $$42(key){var modifier_operation = nil, first = nil, resolved_keys = nil, resolved_key = nil, candidate = nil, $ret_or_1 = nil; -/** - * Get the content of the cell. - * This method should not be used for cells in the head row or that have the literal style. - * @returns {string} - * @memberof Cell - */ -Cell.prototype.getContent = function () { - return this.$content() -} + + if (key == null) key = nil; + modifier_operation = nil; + if ($truthy(modifiers_present)) { + if ($eqeq((first = key.$chr()), "+")) { + + modifier_operation = "append"; + key = key.$slice(1, key.$length()); + } else if ($eqeq(first, "-")) { + + modifier_operation = "remove"; + key = key.$slice(1, key.$length()); + } else if ($truthy(key['$end_with?']("+"))) { + + modifier_operation = "prepend"; + key = key.$chop(); + } + } key = key.$to_sym(); + if (($eqeq(type, "inline") && (($eqeq(key, "verbatim") || ($eqeq(key, "v")))))) { + resolved_keys = $$('BASIC_SUBS'); + } else if ($truthy($$('SUB_GROUPS')['$key?'](key))) { + resolved_keys = $$('SUB_GROUPS')['$[]'](key); + } else if ((($eqeq(type, "inline") && ($eqeq(key.$length(), 1))) && ($truthy($$('SUB_HINTS')['$key?'](key))))) { + + resolved_key = $$('SUB_HINTS')['$[]'](key); + if ($truthy((candidate = $$('SUB_GROUPS')['$[]'](resolved_key)))) { + resolved_keys = candidate; + } else { + resolved_keys = [resolved_key]; + } } else { + resolved_keys = [key]; + } if ($truthy(modifier_operation)) { + + candidates = ($truthy(($ret_or_1 = candidates)) ? ($ret_or_1) : (($truthy(defaults) ? (defaults.$drop(0)) : ([])))); + + switch (modifier_operation) { + case "append": + return (candidates = $rb_plus(candidates, resolved_keys)) + case "prepend": + return (candidates = $rb_plus(resolved_keys, candidates)) + case "remove": + return (candidates = $rb_minus(candidates, resolved_keys)) + default: + return nil + } } else { + + candidates = ($truthy(($ret_or_1 = candidates)) ? ($ret_or_1) : ([])); + return (candidates = $rb_plus(candidates, resolved_keys)); + }}); + if (!$truthy(candidates)) { + return nil + } resolved = candidates['$&']($$('SUB_OPTIONS')['$[]'](type)); + if (!$truthy($rb_minus(candidates, resolved)['$empty?']())) { + + invalid = $rb_minus(candidates, resolved); + self.$logger().$warn("invalid substitution type" + (($truthy($rb_gt(invalid.$size(), 1)) ? ("s") : (""))) + (($truthy(subject) ? (" for ") : (""))) + (subject) + ": " + (invalid.$join(", "))); + } return resolved; + }, -2); + + $def(self, '$resolve_block_subs', function $$resolve_block_subs(subs, defaults, subject) { + var self = this; -/** - * Get the text of the cell. - * @returns {string} - * @memberof Cell - */ -Cell.prototype.getText = function () { - return this.$text() -} + return self.$resolve_subs(subs, "block", defaults, subject) + }); + + $def(self, '$resolve_pass_subs', function $$resolve_pass_subs(subs) { + var self = this; -/** - * Get the source of the cell. - * @returns {string} - * @memberof Cell - */ -Cell.prototype.getSource = function () { - return this.$source() -} + return self.$resolve_subs(subs, "inline", nil, "passthrough macro") + }); + + $def(self, '$expand_subs', function $$expand_subs(subs, subject) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, expanded_subs = nil; -/** - * Get the lines of the cell. - * @returns {Array<string>} - * @memberof Cell - */ -Cell.prototype.getLines = function () { - return this.$lines() -} + + if (subject == null) subject = nil; + if ($eqeqeq($$$('Symbol'), ($ret_or_1 = subs))) { + if ($eqeq(subs, "none")) { + return nil + } else if ($truthy(($ret_or_2 = $$('SUB_GROUPS')['$[]'](subs)))) { + return $ret_or_2 + } else { + return [subs] + } + } else if ($eqeqeq($$$('Array'), $ret_or_1)) { + + expanded_subs = []; + $send(subs, 'each', [], function $$43(key){var sub_group = nil; -/** - * Get the line number of the cell. - * @returns {number|undefined} - * @memberof Cell - */ -Cell.prototype.getLineNumber = function () { - var lineno = this.$lineno() - return lineno === Opal.nil ? undefined : lineno -} + + if (key == null) key = nil; + if ($eqeq(key, "none")) { + return nil + } else if ($truthy((sub_group = $$('SUB_GROUPS')['$[]'](key)))) { + return (expanded_subs = $rb_plus(expanded_subs, sub_group)) + } else { + return expanded_subs['$<<'](key) + }}); + if ($truthy(expanded_subs['$empty?']())) { + return nil + } else { + return expanded_subs + } } else { + return self.$resolve_subs(subs, "inline", nil, subject) + } }, -2); + + $def(self, '$commit_subs', function $$commit_subs() { + var self = this, default_subs = nil, custom_subs = nil, $ret_or_1 = nil, idx = nil, syntax_hl = nil; + if (self.default_subs == null) self.default_subs = nil; + if (self.content_model == null) self.content_model = nil; + if (self.context == null) self.context = nil; + if (self.subs == null) self.subs = nil; + if (self.attributes == null) self.attributes = nil; + if (self.document == null) self.document = nil; + if (self.style == null) self.style = nil; -/** - * Get the source file of the cell. - * @returns {string|undefined} - * @memberof Cell - */ -Cell.prototype.getFile = function () { - var file = this.$file() - return file === Opal.nil ? undefined : file -} + + if (!$truthy((default_subs = self.default_subs))) { + + switch (self.content_model) { + case "simple": + default_subs = $$('NORMAL_SUBS'); + break; + case "verbatim": + default_subs = ($eqeq(self.context, "verse") ? ($$('NORMAL_SUBS')) : ($$('VERBATIM_SUBS'))); + break; + case "raw": + default_subs = ($eqeq(self.context, "stem") ? ($$('BASIC_SUBS')) : ($$('NO_SUBS'))); + break; + default: + return self.subs + } + } if ($truthy((custom_subs = self.attributes['$[]']("subs")))) { + self.subs = ($truthy(($ret_or_1 = self.$resolve_block_subs(custom_subs, default_subs, self.context))) ? ($ret_or_1) : ([])); + } else { + self.subs = default_subs.$drop(0); + } if ((((($eqeq(self.context, "listing") && ($eqeq(self.style, "source"))) && ($truthy((syntax_hl = self.document.$syntax_highlighter())))) && ($truthy(syntax_hl['$highlight?']()))) && ($truthy((idx = self.subs.$index("specialcharacters")))))) { + self.subs['$[]='](idx, "highlight"); + } return nil; + }); + + $def(self, '$parse_attributes', function $$parse_attributes(attrlist, posattrs, opts) { + var self = this, block = nil, into = nil; + if (self.document == null) self.document = nil; -/** - * Get the style of the cell. - * @returns {string|undefined} - * @memberof Cell - */ -Cell.prototype.getStyle = function () { - var style = this.$style() - return style === Opal.nil ? undefined : style -} + + if (posattrs == null) posattrs = []; + if (opts == null) opts = $hash2([], {}); + if ($truthy(($truthy(attrlist) ? (attrlist['$empty?']()) : (true)))) { + return $hash2([], {}) + } if ($truthy(opts['$[]']("unescape_input"))) { + attrlist = self.$normalize_text(attrlist, true, true); + } if (($truthy(opts['$[]']("sub_input")) && ($truthy(attrlist['$include?']($$('ATTR_REF_HEAD')))))) { + attrlist = self.document.$sub_attributes(attrlist); + } if ($truthy(opts['$[]']("sub_result"))) { + block = self; + } if ($truthy((into = opts['$[]']("into")))) { + return $$('AttributeList').$new(attrlist, block).$parse_into(into, posattrs) + } else { + return $$('AttributeList').$new(attrlist, block).$parse(posattrs) + } }, -2); + self.$private(); + + $def(self, '$extract_attributes_from_text', function $$extract_attributes_from_text(text, default_text) { + var self = this, attrlist = nil, resolved_text = nil, attrs = nil; -/** - * Get the column of this cell. - * @returns {Column|undefined} - * @memberof Cell - */ -Cell.prototype.getColumn = function () { - var column = this.$column() - return column === Opal.nil ? undefined : column -} + + if (default_text == null) default_text = nil; + attrlist = ($truthy(text['$include?']($$('LF'))) ? (text.$tr($$('LF'), " ")) : (text)); + if ($truthy((resolved_text = (attrs = $$('AttributeList').$new(attrlist, self).$parse())['$[]'](1)))) { + if ($eqeq(resolved_text, attrlist)) { + return [text, attrs.$clear()] + } else { + return [resolved_text, attrs] + } + } else { + return [default_text, attrs] + } }, -2); + + $def(self, '$extract_callouts', function $$extract_callouts(source) { + var self = this, callout_marks = nil, autonum = nil, lineno = nil, last_lineno = nil, callout_rx = nil; -/** - * Get the width of this cell. - * @returns {string|undefined} - * @memberof Cell - */ -Cell.prototype.getWidth = function () { - return this.getAttribute('width') -} + + callout_marks = $hash2([], {}); + autonum = (lineno = 0); + last_lineno = nil; + callout_rx = ($truthy(self['$attr?']("line-comment")) ? ($$('CalloutExtractRxMap')['$[]'](self.$attr("line-comment"))) : ($$('CalloutExtractRx'))); + source = $send(source.$split($$('LF'), -1), 'map', [], function $$44(line){ + + if (line == null) line = nil; + lineno = $rb_plus(lineno, 1); + return $send(line, 'gsub', [callout_rx], function $$45(){var $a, $ret_or_1 = nil; -/** - * Get the column width in percentage of this cell. - * @returns {string|undefined} - * @memberof Cell - */ -Cell.prototype.getColumnPercentageWidth = function () { - return this.getAttribute('colpcwidth') -} + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) { + return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$sub($$('RS'), "") + } else { + + ($truthy(($ret_or_1 = callout_marks['$[]'](lineno))) ? ($ret_or_1) : (($a = [lineno, []], $send(callout_marks, '[]=', $a), $a[$a.length - 1])))['$<<']([($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) ? ($ret_or_1) : (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), "--") ? (["<!--", "-->"]) : (nil)))), ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))]); + last_lineno = lineno; + return ""; + }});}).$join($$('LF')); + if ($truthy(last_lineno)) { + if ($eqeq(last_lineno, lineno)) { + source = "" + (source) + ($$('LF')); + } + } else { + callout_marks = nil; + } return [source, callout_marks]; + }); + + $def(self, '$restore_callouts', function $$restore_callouts(source, callout_marks, source_offset) { + var self = this, preamble = nil, lineno = nil; -/** - * Get the nested {Document} of this cell when style is 'asciidoc'. - * @returns {Document|undefined} - the nested {Document} - * @memberof Cell - */ -Cell.prototype.getInnerDocument = function () { - var innerDocument = this.inner_document - return innerDocument === Opal.nil ? undefined : innerDocument -} + + if (source_offset == null) source_offset = nil; + if ($truthy(source_offset)) { + + preamble = source.$slice(0, source_offset); + source = source.$slice(source_offset, source.$length()); + } else { + preamble = ""; + } lineno = 0; + return $rb_plus(preamble, $send(source.$split($$('LF'), -1), 'map', [], function $$46(line){var $a, $b, self = $$46.$$s == null ? this : $$46.$$s, conums = nil, guard = nil, numeral = nil; + if (self.document == null) self.document = nil; -// Templates + + if (line == null) line = nil; + if ($truthy((conums = callout_marks.$delete((lineno = $rb_plus(lineno, 1)))))) { + if ($eqeq(conums.$size(), 1)) { + + $b = conums['$[]'](0), $a = $to_ary($b), (guard = ($a[0] == null ? nil : $a[0])), (numeral = ($a[1] == null ? nil : $a[1])); + return "" + (line) + ($$('Inline').$new(self, "callout", numeral, $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": guard})})).$convert()); + } else { + return "" + (line) + ($send(conums, 'map', [], function $$47(guard_it, numeral_it){var self = $$47.$$s == null ? this : $$47.$$s; + if (self.document == null) self.document = nil; -/** - * @description - * This API is experimental and subject to change. - * - * Please note that this API is currently only available in a Node environment. - * We recommend to use a custom converter if you are running in the browser. - * - * @namespace - * @module Converter/TemplateConverter - */ -var TemplateConverter = Opal.Asciidoctor.Converter.TemplateConverter + + if (guard_it == null) guard_it = nil; + if (numeral_it == null) numeral_it = nil; + return $$('Inline').$new(self, "callout", numeral_it, $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": guard_it})})).$convert();}, {$$s: self}).$join(" ")) + } + } else { + return line + }}, {$$s: self}).$join($$('LF'))); + }, -3); + + $def(self, '$convert_quoted_text', function $$convert_quoted_text(match, type, scope) { + var self = this, attrs = nil, unescaped_attrs = nil, attrlist = nil, id = nil, attributes = nil; -if (TemplateConverter) { - // Alias - Opal.Asciidoctor.TemplateConverter = TemplateConverter + + if ($truthy(match['$[]'](0)['$start_with?']($$('RS')))) { + if (($eqeq(scope, "constrained") && ($truthy((attrs = match['$[]'](2)))))) { + unescaped_attrs = "[" + (attrs) + "]"; + } else { + return match['$[]'](0).$slice(1, match['$[]'](0).$length()) + } + } if ($eqeq(scope, "constrained")) { + if ($truthy(unescaped_attrs)) { + return "" + (unescaped_attrs) + ($$('Inline').$new(self, "quoted", match['$[]'](3), $hash2(["type"], {"type": type})).$convert()) + } else { + + if ($truthy((attrlist = match['$[]'](2)))) { + + id = (attributes = self.$parse_quoted_text_attributes(attrlist))['$[]']("id"); + if ($eqeq(type, "mark")) { + type = "unquoted"; + } } return "" + (match['$[]'](1)) + ($$('Inline').$new(self, "quoted", match['$[]'](3), $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert()); + } + } else { + + if ($truthy((attrlist = match['$[]'](1)))) { + + id = (attributes = self.$parse_quoted_text_attributes(attrlist))['$[]']("id"); + if ($eqeq(type, "mark")) { + type = "unquoted"; + } } return $$('Inline').$new(self, "quoted", match['$[]'](2), $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert(); + } }); + + $def(self, '$do_replacement', function $$do_replacement(m, replacement, restore) { + var captured = nil; + + if ($truthy((captured = m['$[]'](0))['$include?']($$('RS')))) { + return captured.$sub($$('RS'), "") + } else + switch (restore) { + case "none": + return replacement + case "bounding": + return $rb_plus($rb_plus(m['$[]'](1), replacement), m['$[]'](2)) + default: + return $rb_plus(m['$[]'](1), replacement) + } + }); + + $def(self, '$parse_quoted_text_attributes', function $$parse_quoted_text_attributes(str) { + var $a, $b, self = this, before = nil, after = nil, attrs = nil, id = nil, roles = nil; - /** - * Create a new TemplateConverter. - * @param {string} backend - the backend name - * @param templateDirectories - a list of template directories - * @param {Object} opts - a JSON of options - * @param {string} opts.template_engine - the name of the template engine - * @param {Object} [opts.template_cache] - an optional template cache - * @param {Object} [opts.template_cache.scans] - a JSON of template objects keyed by template name keyed by path patterns - * @param {Object} [opts.template_cache.templates] - a JSON of template objects keyed by file paths - * @returns {TemplateConverter} - * @memberof Converter/TemplateConverter - */ - TemplateConverter.create = function (backend, templateDirectories, opts) { - if (opts && opts.template_cache) { - opts.template_cache = toHash(opts.template_cache) - } - this.$new(backend, templateDirectories, toHash(opts)) - } + + if ($truthy(str['$include?']($$('ATTR_REF_HEAD')))) { + str = self.$sub_attributes(str); + } if ($truthy(str['$include?'](","))) { + str = str.$slice(0, str.$index(",")); + } if ($truthy((str = str.$strip())['$empty?']())) { + return $hash2([], {}) + } else if (($truthy(str['$start_with?'](".", "#")) && ($truthy($$('Compliance').$shorthand_property_syntax())))) { + + $b = str.$partition("#"), $a = $to_ary($b), (before = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (after = ($a[2] == null ? nil : $a[2])); + attrs = $hash2([], {}); + if ($truthy(after['$empty?']())) { + if ($truthy($rb_gt(before.$length(), 1))) { + attrs['$[]=']("role", before.$tr(".", " ").$lstrip()); + } + } else { + + $b = after.$partition("."), $a = $to_ary($b), (id = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (roles = ($a[2] == null ? nil : $a[2])); + if (!$truthy(id['$empty?']())) { + attrs['$[]=']("id", id); + } if ($truthy(roles['$empty?']())) { + if ($truthy($rb_gt(before.$length(), 1))) { + attrs['$[]=']("role", before.$tr(".", " ").$lstrip()); + } + } else if ($truthy($rb_gt(before.$length(), 1))) { + attrs['$[]=']("role", $rb_plus($rb_plus(before, "."), roles).$tr(".", " ").$lstrip()); + } else { + attrs['$[]=']("role", roles.$tr(".", " ")); + } } return attrs; + } else { + return $hash2(["role"], {"role": str}) + } }); + + $def(self, '$normalize_text', function $$normalize_text(text, normalize_whitespace, unescape_closing_square_brackets) { + + + if (normalize_whitespace == null) normalize_whitespace = nil; + if (unescape_closing_square_brackets == null) unescape_closing_square_brackets = nil; + if (!$truthy(text['$empty?']())) { + + if ($truthy(normalize_whitespace)) { + text = text.$strip().$tr($$('LF'), " "); + } if (($truthy(unescape_closing_square_brackets) && ($truthy(text['$include?']($$('R_SB')))))) { + text = text.$gsub($$('ESC_R_SB'), $$('R_SB')); + } } return text; + }, -2); + return $def(self, '$split_simple_csv', function $$split_simple_csv(str) { + var values = nil, accum = nil, quote_open = nil; - /** - * @returns {Object} - The global cache - * @memberof Converter/TemplateConverter - */ - TemplateConverter.getCache = function () { - var caches = fromHash(this.caches) - if (caches) { - if (caches.scans) { - caches.scans = fromHash(caches.scans) - for (var key in caches.scans) { - caches.scans[key] = fromHash(caches.scans[key]) + if ($truthy(str['$empty?']())) { + return [] + } else if ($truthy(str['$include?']("\""))) { + + values = []; + accum = ""; + quote_open = nil; + $send(str, 'each_char', [], function $$48(c){ + + if (c == null) c = nil; + + switch (c) { + case ",": + if ($truthy(quote_open)) { + return (accum = $rb_plus(accum, c)) + } else { + + values['$<<'](accum.$strip()); + return (accum = ""); + } + case "\"": + return (quote_open = quote_open['$!']()) + default: + return (accum = $rb_plus(accum, c)) + }}); + return values['$<<'](accum.$strip()); + } else { + return $send(str.$split(","), 'map', [], function $$49(it){ + + if (it == null) it = nil; + return it.$strip();}) } - } - if (caches.templates) { - caches.templates = fromHash(caches.templates) - } - } - return caches - } - - /** - * Clear the global cache. - * @memberof Converter/TemplateConverter - */ - TemplateConverter.clearCache = function () { - this.$clear_caches() - } + }); + })($nesting[0], $nesting) + })($nesting[0], $nesting) +}; - /** - * Convert an {AbstractNode} to the backend format using the named template. - * - * Looks for a template that matches the value of the template name or, - * if the template name is not specified, the value of the {@see AbstractNode.getNodeName} function. - * - * @param {AbstractNode} node - the AbstractNode to convert - * @param {string} templateName - the {string} name of the template to use, or the node name of the node if a template name is not specified. (optional, default: undefined) - * @param {Object} opts - an optional JSON that is passed as local variables to the template. (optional, default: undefined) - * @returns {string} - The {string} result from rendering the template - * @memberof Converter/TemplateConverter - */ - TemplateConverter.prototype.convert = function (node, templateName, opts) { - return this.$convert(node, templateName, toHash(opts)) - } +Opal.modules["asciidoctor/version"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $nesting = []; Opal.nil; - /** - * Checks whether there is a template registered with the specified name. - * - * @param {string} name - the {string} template name - * @returns {boolean} - a {boolean} that indicates whether a template is registered for the specified template name. - * @memberof Converter/TemplateConverter - */ - TemplateConverter.prototype.handles = function (name) { - return this['$handles?'](name) - } + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - /** - * Retrieves the templates that this converter manages. - * - * @returns {Object} - a JSON of template objects keyed by template name - * @memberof Converter/TemplateConverter - */ - TemplateConverter.prototype.getTemplates = function () { - return fromHash(this.$templates()) - } + var $nesting = [self].concat($parent_nesting); - /** - * Registers a template with this converter. - * - * @param {string} name - the {string} template name - * @param {Object} template - the template object to register - * @returns {Object} - the template object - * @memberof Converter/TemplateConverter - */ - TemplateConverter.prototype.register = function (name, template) { - return this.$register(name, template) - } + return $const_set($nesting[0], 'VERSION', "2.0.20") + })($nesting[0], $nesting) +}; - /** - * @namespace - * @description - * This API is experimental and subject to change. - * - * Please note that this API is currently only available in a Node environment. - * We recommend to use a custom converter if you are running in the browser. - * - * A pluggable adapter for integrating a template engine into the built-in template converter. - */ - var TemplateEngine = {} - TemplateEngine.registry = {} +Opal.modules["asciidoctor/abstract_node"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $truthy = Opal.truthy, $def = Opal.def, $send = Opal.send, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_lt = Opal.rb_lt, $not = Opal.not, $to_ary = Opal.to_ary, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // Alias - Opal.Asciidoctor.TemplateEngine = TemplateEngine + Opal.add_stubs('include,attr_reader,attr_accessor,==,document,to_s,[],merge,raise,converter,attributes,key?,[]=,delete,tap,new,each_key,end_with?,<<,slice,-,length,update,split,include?,===,join,empty?,apply_reftext_subs,attr?,attr,extname?,image_uri,<,safe,normalize_web_path,uriish?,encode_spaces_in_uri,generate_data_uri_from_uri,generate_data_uri,extname,normalize_system_path,readable?,strict_encode64,binread,warn,logger,require_library,!,open_uri,content_type,read,base_dir,root?,path_resolver,system_path,web_path,!=,prepare_source_string,fetch,read_asset'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - /** - * Register a template engine adapter for the given names. - * @param {string|Array} names - a {string} name or an {Array} of {string} names - * @param {Object} templateEngineAdapter - a template engine adapter instance - * @example - * const fs = require('fs') - * class DotTemplateEngineAdapter { - * constructor () { - * this.doT = require('dot') - * } - * compile (file, _) { - * const templateFn = this.doT.template(fs.readFileSync(file, 'utf8')) - * return { - * render: templateFn - * } - * } - * } - * asciidoctor.TemplateEngine.register('dot, new DotTemplateEngineAdapter()) - * @memberof TemplateEngine - */ - TemplateEngine.register = function (names, templateEngineAdapter) { - if (typeof names === 'string') { - this.registry[names] = templateEngineAdapter - } else { - // array - for (var i = 0; i < names.length; i++) { - var name = names[i] - this.registry[name] = templateEngineAdapter - } - } - } -} + var $nesting = [self].concat($parent_nesting); -/* global Opal, fromHash, toHash, initializeClass */ -// Extensions API + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'AbstractNode'); -/** - * @private - */ -var toBlock = function (block) { - // arity is a mandatory field - block.$$arity = block.length - return block -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -var registerExtension = function (registry, type, processor, name) { - if (typeof processor === 'object' || processor.$$is_class) { - // processor is an instance or a class - return registry['$' + type](processor, name) - } else { - // processor is a function/lambda - return Opal.send(registry, type, name && [name], toBlock(processor)) - } -} + $proto.document = $proto.attributes = $proto.parent = nil; + + self.$include($$('Logging')); + self.$include($$('Substitutors')); + self.$attr_reader("attributes"); + self.$attr_reader("context"); + self.$attr_reader("document"); + self.$attr_accessor("id"); + self.$attr_reader("node_name"); + self.$attr_reader("parent"); + + $def(self, '$initialize', function $$initialize(parent, context, opts) { + var self = this, attrs = nil; -/** - * @namespace - * @description - * Extensions provide a way to participate in the parsing and converting - * phases of the AsciiDoc processor or extend the AsciiDoc syntax. - * - * The various extensions participate in AsciiDoc processing as follows: - * - * 1. After the source lines are normalized, {{@link Extensions/Preprocessor}}s modify or replace - * the source lines before parsing begins. {{@link Extensions/IncludeProcessor}}s are used to - * process include directives for targets which they claim to handle. - * 2. The Parser parses the block-level content into an abstract syntax tree. - * Custom blocks and block macros are processed by associated {{@link Extensions/BlockProcessor}}s - * and {{@link Extensions/BlockMacroProcessor}}s, respectively. - * 3. {{@link Extensions/TreeProcessor}}s are run on the abstract syntax tree. - * 4. Conversion of the document begins, at which point inline markup is processed - * and converted. Custom inline macros are processed by associated {InlineMacroProcessor}s. - * 5. {{@link Extensions/Postprocessor}}s modify or replace the converted document. - * 6. The output is written to the output stream. - * - * Extensions may be registered globally using the {Extensions.register} method - * or added to a custom {Registry} instance and passed as an option to a single - * Asciidoctor processor. - * - * @example - * asciidoctor.Extensions.register(function () { - * this.block(function () { - * var self = this; - * self.named('shout'); - * self.onContext('paragraph'); - * self.process(function (parent, reader) { - * var lines = reader.getLines().map(function (l) { return l.toUpperCase(); }); - * return self.createBlock(parent, 'paragraph', lines); - * }); - * }); - * }); - */ -var Extensions = Opal.const_get_qualified(Opal.Asciidoctor, 'Extensions') + + if (opts == null) opts = $hash2([], {}); + if ($eqeq(context, "document")) { + self.document = self; + } else if ($truthy(parent)) { + self.document = (self.parent = parent).$document(); + } self.node_name = (self.context = context).$to_s(); + self.attributes = ($truthy((attrs = opts['$[]']("attributes"))) ? (attrs.$merge()) : ($hash2([], {}))); + return (self.passthroughs = []); + }, -3); + + $def(self, '$block?', function $AbstractNode_block$ques$1() { + var self = this; -// Alias -Opal.Asciidoctor.Extensions = Extensions + return self.$raise($$$('NotImplementedError')) + }); + + $def(self, '$inline?', function $AbstractNode_inline$ques$2() { + var self = this; -/** - * Create a new {@link Extensions/Registry}. - * @param {string} name - * @param {function} block - * @memberof Extensions - * @returns {Extensions/Registry} - returns a {@link Extensions/Registry} - */ -Extensions.create = function (name, block) { - if (typeof name === 'function' && typeof block === 'undefined') { - return Opal.send(this, 'create', null, toBlock(name)) - } else if (typeof block === 'function') { - return Opal.send(this, 'create', [name], toBlock(block)) - } else { - return this.$create() - } -} + return self.$raise($$$('NotImplementedError')) + }); + + $def(self, '$converter', function $$converter() { + var self = this; -/** - * @memberof Extensions - */ -Extensions.register = function (name, block) { - if (typeof name === 'function' && typeof block === 'undefined') { - return Opal.send(this, 'register', null, toBlock(name)) - } else { - return Opal.send(this, 'register', [name], toBlock(block)) - } -} + return self.document.$converter() + }); + + $def(self, '$parent=', function $AbstractNode_parent$eq$3(parent) { + var $a, self = this; -/** - * Get statically-registered extension groups. - * @memberof Extensions - */ -Extensions.getGroups = function () { - return fromHash(this.$groups()) -} + return $a = [parent, parent.$document()], (self.parent = $a[0]), (self.document = $a[1]), $a + }); + + $def(self, '$attr', function $$attr(name, default_value, fallback_name) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil; -/** - * Unregister all statically-registered extension groups. - * @memberof Extensions - */ -Extensions.unregisterAll = function () { - this.$unregister_all() -} + + if (default_value == null) default_value = nil; + if (fallback_name == null) fallback_name = nil; + if ($truthy(($ret_or_1 = self.attributes['$[]'](name.$to_s())))) { + return $ret_or_1 + } else { + + if ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = fallback_name)) ? (self.parent) : ($ret_or_4)))) ? (self.document.$attributes()['$[]'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s())) : ($ret_or_3))))) { + return $ret_or_2 + } else { + return default_value + } } }, -2); + + $def(self, '$attr?', function $AbstractNode_attr$ques$4(name, expected_value, fallback_name) { + var self = this, $ret_or_1 = nil; -/** - * Unregister the specified statically-registered extension groups. - * - * NOTE Opal cannot delete an entry from a Hash that is indexed by symbol, so - * we have to resort to using low-level operations in this method. - * - * @memberof Extensions - */ -Extensions.unregister = function () { - var names = Array.prototype.concat.apply([], arguments) - var groups = this.$groups() - var groupNameIdx = {} - for (var i = 0, groupSymbolNames = groups.$$keys; i < groupSymbolNames.length; i++) { - var groupSymbolName = groupSymbolNames[i] - groupNameIdx[groupSymbolName.toString()] = groupSymbolName - } - for (var j = 0; j < names.length; j++) { - var groupStringName = names[j] - if (groupStringName in groupNameIdx) Opal.hash_delete(groups, groupNameIdx[groupStringName]) - } -} + + if (expected_value == null) expected_value = nil; + if (fallback_name == null) fallback_name = nil; + if ($truthy(expected_value)) { + return expected_value['$=='](($truthy(($ret_or_1 = self.attributes['$[]'](name.$to_s()))) ? ($ret_or_1) : ((($truthy(fallback_name) && ($truthy(self.parent))) ? (self.document.$attributes()['$[]'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s())) : (nil))))) + } else if ($truthy(($ret_or_1 = self.attributes['$key?'](name.$to_s())))) { + return $ret_or_1 + } else { + + if (($truthy(fallback_name) && ($truthy(self.parent)))) { + + return self.document.$attributes()['$key?'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s()); + } else { + return false + } } }, -2); + + $def(self, '$set_attr', function $$set_attr(name, value, overwrite) { + var self = this; -/** - * @namespace - * @module Extensions/Registry - */ -var Registry = Extensions.Registry + + if (value == null) value = ""; + if (overwrite == null) overwrite = true; + if (($eqeq(overwrite, false) && ($truthy(self.attributes['$key?'](name))))) { + return false + } else { + + self.attributes['$[]='](name, value); + return true; + } }, -2); + + $def(self, '$remove_attr', function $$remove_attr(name) { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.getGroups = Extensions.getGroups + return self.attributes.$delete(name) + }); + + $def(self, '$option?', function $AbstractNode_option$ques$5(name) { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.unregisterAll = function () { - this.groups = Opal.hash() -} + if ($truthy(self.attributes['$[]']("" + (name) + "-option"))) { + return true + } else { + return false + } + }); + + $def(self, '$set_option', function $$set_option(name) { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.unregister = Extensions.unregister + + self.attributes['$[]=']("" + (name) + "-option", ""); + return nil; + }); + + $def(self, '$enabled_options', function $$enabled_options() { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.prefer = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - if (typeof processor === 'object' || processor.$$is_class) { - // processor is an instance or a class - return this.$prefer(name, processor) - } else { - // processor is a function/lambda - return Opal.send(this, 'prefer', name && [name], toBlock(processor)) - } -} + return $send($$$('Set').$new(), 'tap', [], function $$6(accum){var self = $$6.$$s == null ? this : $$6.$$s; + if (self.attributes == null) self.attributes = nil; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.block = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'block', processor, name) -} + + if (accum == null) accum = nil; + return $send(self.attributes, 'each_key', [], function $$7(k){ + + if (k == null) k = nil; + if ($truthy(k.$to_s()['$end_with?']("-option"))) { + return accum['$<<'](k.$slice(0, $rb_minus(k.$length(), 7))) + } else { + return nil + }});}, {$$s: self}) + }); + + $def(self, '$update_attributes', function $$update_attributes(new_attributes) { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.inlineMacro = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'inline_macro', processor, name) -} + return self.attributes.$update(new_attributes) + }); + + $def(self, '$role', function $$role() { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.includeProcessor = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'include_processor', processor, name) -} + return self.attributes['$[]']("role") + }); + + $def(self, '$roles', function $$roles() { + var self = this, val = nil; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.blockMacro = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'block_macro', processor, name) -} + if ($truthy((val = self.attributes['$[]']("role")))) { + return val.$split() + } else { + return [] + } + }); + + $def(self, '$role?', function $AbstractNode_role$ques$8(expected_value) { + var self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.treeProcessor = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'tree_processor', processor, name) -} + + if (expected_value == null) expected_value = nil; + if ($truthy(expected_value)) { + return expected_value['$=='](self.attributes['$[]']("role")) + } else { + + return self.attributes['$key?']("role"); + } }, -1); + + $def(self, '$has_role?', function $AbstractNode_has_role$ques$9(name) { + var self = this, val = nil; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.postprocessor = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'postprocessor', processor, name) -} + if ($truthy((val = self.attributes['$[]']("role")))) { + + return (((" ") + (val)) + " ")['$include?'](" " + (name) + " "); + } else { + return false + } + }); + + $def(self, '$role=', function $AbstractNode_role$eq$10(names) { + var $a, self = this; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.preprocessor = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'preprocessor', processor, name) -} + return ($a = ["role", ($eqeqeq($$$('Array'), names) ? (names.$join(" ")) : (names))], $send(self.attributes, '[]=', $a), $a[$a.length - 1]) + }); + + $def(self, '$add_role', function $$add_role(name) { + var self = this, val = nil; -/** - * @memberof Extensions/Registry - */ -Registry.prototype.docinfoProcessor = function (name, processor) { - if (arguments.length === 1) { - processor = name - name = null - } - return registerExtension(this, 'docinfo_processor', processor, name) -} + if ($truthy((val = self.attributes['$[]']("role")))) { + if ($truthy((((" ") + (val)) + " ")['$include?'](" " + (name) + " "))) { + return false + } else { + + self.attributes['$[]=']("role", "" + (val) + " " + (name)); + return true; + } + } else { + + self.attributes['$[]=']("role", name); + return true; + } + }); + + $def(self, '$remove_role', function $$remove_role(name) { + var self = this, val = nil; -/** - * Checks whether any {{@link Extensions/Preprocessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/Preprocessor}} extensions are registered. - */ -Registry.prototype.hasPreprocessors = function () { - return this['$preprocessors?']() -} + if (($truthy((val = self.attributes['$[]']("role"))) && ($truthy((val = val.$split()).$delete(name))))) { + + if ($truthy(val['$empty?']())) { + self.attributes.$delete("role"); + } else { + self.attributes['$[]=']("role", val.$join(" ")); + } return true; + } else { + return false + } + }); + + $def(self, '$reftext', function $$reftext() { + var self = this, val = nil; -/** - * Checks whether any {{@link Extensions/TreeProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/TreeProcessor}} extensions are registered. - */ -Registry.prototype.hasTreeProcessors = function () { - return this['$tree_processors?']() -} + if ($truthy((val = self.attributes['$[]']("reftext")))) { + + return self.$apply_reftext_subs(val); + } else { + return nil + } + }); + + $def(self, '$reftext?', function $AbstractNode_reftext$ques$11() { + var self = this; -/** - * Checks whether any {{@link Extensions/IncludeProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/IncludeProcessor}} extensions are registered. - */ -Registry.prototype.hasIncludeProcessors = function () { - return this['$include_processors?']() -} + return self.attributes['$key?']("reftext") + }); + + $def(self, '$icon_uri', function $$icon_uri(name) { + var self = this, icon = nil; -/** - * Checks whether any {{@link Extensions/Postprocessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/Postprocessor}} extensions are registered. - */ -Registry.prototype.hasPostprocessors = function () { - return this['$postprocessors?']() -} + + if ($truthy(self['$attr?']("icon"))) { + + icon = self.$attr("icon"); + if (!$truthy($$('Helpers')['$extname?'](icon))) { + icon = "" + (icon) + "." + (self.document.$attr("icontype", "png")); + } } else { + icon = "" + (name) + "." + (self.document.$attr("icontype", "png")); + } return self.$image_uri(icon, "iconsdir"); + }); + + $def(self, '$image_uri', function $$image_uri(target_image, asset_dir_key) { + var self = this, doc = nil, images_base = nil; -/** - * Checks whether any {{@link Extensions/DocinfoProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined) - * @returns a {boolean} indicating whether any {{@link Extensions/DocinfoProcessor}} extensions are registered. - */ -Registry.prototype.hasDocinfoProcessors = function (location) { - return this['$docinfo_processors?'](location) -} + + if (asset_dir_key == null) asset_dir_key = "imagesdir"; + if (($truthy($rb_lt((doc = self.document).$safe(), $$$($$('SafeMode'), 'SECURE'))) && ($truthy(doc['$attr?']("data-uri"))))) { + if ((($truthy($$('Helpers')['$uriish?'](target_image)) && ($truthy((target_image = $$('Helpers').$encode_spaces_in_uri(target_image))))) || (((($truthy(asset_dir_key) && ($truthy((images_base = doc.$attr(asset_dir_key))))) && ($truthy($$('Helpers')['$uriish?'](images_base)))) && ($truthy((target_image = self.$normalize_web_path(target_image, images_base, false)))))))) { + if ($truthy(doc['$attr?']("allow-uri-read"))) { + + return self.$generate_data_uri_from_uri(target_image, doc['$attr?']("cache-uri")); + } else { + return target_image + } + } else { + return self.$generate_data_uri(target_image, asset_dir_key) + } + } else { + return self.$normalize_web_path(target_image, ($truthy(asset_dir_key) ? (doc.$attr(asset_dir_key)) : (nil))) + } }, -2); + + $def(self, '$media_uri', function $$media_uri(target, asset_dir_key) { + var self = this; -/** - * Checks whether any {{@link Extensions/BlockProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/BlockProcessor}} extensions are registered. - */ -Registry.prototype.hasBlocks = function () { - return this['$blocks?']() -} + + if (asset_dir_key == null) asset_dir_key = "imagesdir"; + return self.$normalize_web_path(target, ($truthy(asset_dir_key) ? (self.document.$attr(asset_dir_key)) : (nil))); + }, -2); + + $def(self, '$generate_data_uri', function $$generate_data_uri(target_image, asset_dir_key) { + var self = this, ext = nil, mimetype = nil, image_path = nil; -/** - * Checks whether any {{@link Extensions/BlockMacroProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/BlockMacroProcessor}} extensions are registered. - */ -Registry.prototype.hasBlockMacros = function () { - return this['$block_macros?']() -} + + if (asset_dir_key == null) asset_dir_key = nil; + if ($truthy((ext = $$('Helpers').$extname(target_image, nil)))) { + mimetype = ($eqeq(ext, ".svg") ? ("image/svg+xml") : ("image/" + (ext.$slice(1, ext.$length())))); + } else { + mimetype = "application/octet-stream"; + } if ($truthy(asset_dir_key)) { + image_path = self.$normalize_system_path(target_image, self.document.$attr(asset_dir_key), nil, $hash2(["target_name"], {"target_name": "image"})); + } else { + image_path = self.$normalize_system_path(target_image); + } if ($truthy($$$('File')['$readable?'](image_path))) { + return "data:" + (mimetype) + ";base64," + ($$$('Base64').$strict_encode64($$$('File').$binread(image_path))) + } else { + + self.$logger().$warn("image to embed not found or not readable: " + (image_path)); + return "data:" + (mimetype) + ";base64,"; + } }, -2); + + $def(self, '$generate_data_uri_from_uri', function $$generate_data_uri_from_uri(image_uri, cache_uri) { + var $a, $b, self = this, mimetype = nil, bindata = nil; -/** - * Checks whether any {{@link Extensions/InlineMacroProcessor}} extensions have been registered. - * - * @memberof Extensions/Registry - * @returns a {boolean} indicating whether any {{@link Extensions/InlineMacroProcessor}} extensions are registered. - */ -Registry.prototype.hasInlineMacros = function () { - return this['$inline_macros?']() -} + + if (cache_uri == null) cache_uri = false; + if ($truthy(cache_uri)) { + $$('Helpers').$require_library("open-uri/cached", "open-uri-cached"); + } else if ($not($$('RUBY_ENGINE_OPAL'))) { + $$$('OpenURI'); + } + try { + + $b = $send($$$('OpenURI'), 'open_uri', [image_uri, $$('URI_READ_MODE')], function $$12(f){ + + if (f == null) f = nil; + return [f.$content_type(), f.$read()];}), $a = $to_ary($b), (mimetype = ($a[0] == null ? nil : $a[0])), (bindata = ($a[1] == null ? nil : $a[1])), $b; + return "data:" + (mimetype) + ";base64," + ($$$('Base64').$strict_encode64(bindata)); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + self.$logger().$warn("could not retrieve image data from URI: " + (image_uri)); + return image_uri; + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -2); + + $def(self, '$normalize_asset_path', function $$normalize_asset_path(asset_ref, asset_name, autocorrect) { + var self = this; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/Preprocessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getPreprocessors = function () { - return this.$preprocessors() -} + + if (asset_name == null) asset_name = "path"; + if (autocorrect == null) autocorrect = true; + return self.$normalize_system_path(asset_ref, self.document.$base_dir(), nil, $hash2(["target_name", "recover"], {"target_name": asset_name, "recover": autocorrect})); + }, -2); + + $def(self, '$normalize_system_path', function $$normalize_system_path(target, start, jail, opts) { + var self = this, doc = nil, $ret_or_1 = nil; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/TreeProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getTreeProcessors = function () { - return this.$tree_processors() -} + + if (start == null) start = nil; + if (jail == null) jail = nil; + if (opts == null) opts = $hash2([], {}); + if ($truthy($rb_lt((doc = self.document).$safe(), $$$($$('SafeMode'), 'SAFE')))) { + if ($truthy(start)) { + if (!$truthy(doc.$path_resolver()['$root?'](start))) { + start = $$$('File').$join(doc.$base_dir(), start); + } + } else { + start = doc.$base_dir(); + } + } else { + + start = ($truthy(($ret_or_1 = start)) ? ($ret_or_1) : (doc.$base_dir())); + jail = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (doc.$base_dir())); + } return doc.$path_resolver().$system_path(target, start, jail, opts); + }, -2); + + $def(self, '$normalize_web_path', function $$normalize_web_path(target, start, preserve_uri_target) { + var self = this; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/IncludeProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getIncludeProcessors = function () { - return this.$include_processors() -} + + if (start == null) start = nil; + if (preserve_uri_target == null) preserve_uri_target = true; + if (($truthy(preserve_uri_target) && ($truthy($$('Helpers')['$uriish?'](target))))) { + return $$('Helpers').$encode_spaces_in_uri(target) + } else { + return self.document.$path_resolver().$web_path(target, start) + } }, -2); + + $def(self, '$read_asset', function $$read_asset(path, opts) { + var self = this, $ret_or_1 = nil; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/Postprocessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getPostprocessors = function () { - return this.$postprocessors() -} + + if (opts == null) opts = $hash2([], {}); + if (!$eqeqeq($$$('Hash'), opts)) { + opts = $hash2(["warn_on_failure"], {"warn_on_failure": opts['$!='](false)}); + } if ($truthy($$$('File')['$readable?'](path))) { + if ($truthy(opts['$[]']("normalize"))) { + + return $$('Helpers').$prepare_source_string($$$('File').$read(path, $hash2(["mode"], {"mode": $$('FILE_READ_MODE')}))).$join($$('LF')); + } else { + + return $$$('File').$read(path, $hash2(["mode"], {"mode": $$('FILE_READ_MODE')})); + } + } else if ($truthy(opts['$[]']("warn_on_failure"))) { + + self.$logger().$warn("" + (($truthy(($ret_or_1 = self.$attr("docfile"))) ? ($ret_or_1) : ("<stdin>"))) + ": " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("file"))) + " does not exist or cannot be read: " + (path)); + return nil; + } else { + return nil + } }, -2); + + $def(self, '$read_contents', function $$read_contents(target, opts) { + var self = this, doc = nil, start = nil, contents = nil, $ret_or_1 = nil; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/DocinfoProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined) - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getDocinfoProcessors = function (location) { - return this.$docinfo_processors(location) -} + + if (opts == null) opts = $hash2([], {}); + doc = self.document; + if (($truthy($$('Helpers')['$uriish?'](target)) || ((($truthy((start = opts['$[]']("start"))) && ($truthy($$('Helpers')['$uriish?'](start)))) && ($truthy((target = doc.$path_resolver().$web_path(target, start)))))))) { + if ($truthy(doc['$attr?']("allow-uri-read"))) { + + if ($truthy(doc['$attr?']("cache-uri"))) { + $$('Helpers').$require_library("open-uri/cached", "open-uri-cached"); + } + try { + if ($truthy(opts['$[]']("normalize"))) { + contents = $$('Helpers').$prepare_source_string($send($$$('OpenURI'), 'open_uri', [target, $$('URI_READ_MODE')], function $$13(f){ + + if (f == null) f = nil; + return f.$read();})).$join($$('LF')); + } else { + contents = $send($$$('OpenURI'), 'open_uri', [target, $$('URI_READ_MODE')], function $$14(f){ + + if (f == null) f = nil; + return f.$read();}); + } + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + if ($truthy(opts.$fetch("warn_on_failure", true))) { + self.$logger().$warn("could not retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target)); + } + } finally { Opal.pop_exception(); } + } else { throw $err; } + } } else if ($truthy(opts.$fetch("warn_on_failure", true))) { + self.$logger().$warn("cannot retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target) + " (allow-uri-read attribute not enabled)"); + } + } else { + + target = self.$normalize_system_path(target, opts['$[]']("start"), nil, $hash2(["target_name"], {"target_name": ($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))})); + contents = self.$read_asset(target, $hash2(["normalize", "warn_on_failure", "label"], {"normalize": opts['$[]']("normalize"), "warn_on_failure": opts.$fetch("warn_on_failure", true), "label": opts['$[]']("label")})); + } if ((($truthy(contents) && ($truthy(opts['$[]']("warn_if_empty")))) && ($truthy(contents['$empty?']())))) { + self.$logger().$warn("contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " is empty: " + (target)); + } return contents; + }, -2); + return $def(self, '$is_uri?', function $AbstractNode_is_uri$ques$15(str) { + + return $$('Helpers')['$uriish?'](str) + }); + })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/BlockProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getBlocks = function () { - return this.block_extensions.$values() -} +Opal.modules["asciidoctor/abstract_block"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $return_val = Opal.return_val, $truthy = Opal.truthy, $alias = Opal.alias, $send = Opal.send, $rb_plus = Opal.rb_plus, $not = Opal.not, $neqeq = Opal.neqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/BlockMacroProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getBlockMacros = function () { - return this.block_macro_extensions.$values() -} + Opal.add_stubs('attr_reader,attr_writer,attr_accessor,==,===,level,file,lineno,playback_attributes,convert,converter,join,map,to_s,parent,parent=,<<,empty?,Integer,find_by_internal,to_proc,find_by,context,[],items,+,find_index,include?,next_adjacent_block,blocks,select,sub_specialchars,match?,sub_replacements,title,apply_title_subs,delete,!,reftext,nil_or_empty?,sub_placeholder,sub_quotes,compat_mode,attributes,chomp,increment_and_store_counter,index=,numbered,sectname,numeral=,counter,caption=,numeral,int_to_roman,each,assign_numeral,reindex_sections,protected,has_role?,raise,header?,!=,flatten,head,rows,merge,body,foot,style,inner_document'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * Retrieves the Extension proxy objects for all the {{@link Extensions/InlineMacroProcessor}} instances stored in this registry. - * - * @memberof Extensions/Registry - * @returns an {array} of Extension proxy objects. - */ -Registry.prototype.getInlineMacros = function () { - return this.$inline_macros() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Get any {{@link Extensions/InlineMacroProcessor}} extensions are registered to handle the specified inline macro name. - * - * @param name - the {string} inline macro name - * @memberof Extensions/Registry - * @returns the Extension proxy object for the {{@link Extensions/InlineMacroProcessor}} that matches the inline macro name or undefined if no match is found. - */ -Registry.prototype.getInlineMacroFor = function (name) { - var result = this['$registered_for_inline_macro?'](name) - return result === false ? undefined : result -} + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'AbstractBlock'); -/** - * Get any {{@link Extensions/BlockProcessor}} extensions are registered to handle the specified block name appearing on the specified context. - * @param name - the {string} block name - * @param context - the context of the block: paragraph, open... (optional) - * @memberof Extensions/Registry - * @returns the Extension proxy object for the {{@link Extensions/BlockProcessor}} that matches the block name and context or undefined if no match is found. - */ -Registry.prototype.getBlockFor = function (name, context) { - if (typeof context === 'undefined') { - var ext = this.$find_block_extension(name) - return ext === Opal.nil ? undefined : ext - } - var result = this['$registered_for_block?'](name, context) - return result === false ? undefined : result -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * Get any {{@link Extensions/BlockMacroProcessor}} extensions are registered to handle the specified macro name. - * - * @param name - the {string} macro name - * @memberof Extensions/Registry - * @returns the Extension proxy object for the {{@link Extensions/BlockMacroProcessor}} that matches the macro name or undefined if no match is found. - */ -Registry.prototype.getBlockMacroFor = function (name) { - var result = this['$registered_for_block_macro?'](name) - return result === false ? undefined : result -} + $proto.source_location = $proto.document = $proto.attributes = $proto.blocks = $proto.numeral = $proto.context = $proto.parent = $proto.caption = $proto.style = $proto.converted_title = $proto.title = $proto.subs = $proto.next_section_index = $proto.next_section_ordinal = $proto.id = $proto.header = nil; + + self.$attr_reader("blocks"); + self.$attr_writer("caption"); + self.$attr_accessor("content_model"); + self.$attr_accessor("level"); + self.$attr_accessor("numeral"); + self.$attr_accessor("source_location"); + self.$attr_accessor("style"); + self.$attr_reader("subs"); + + $def(self, '$initialize', function $$initialize(parent, context, opts) { + var $yield = $$initialize.$$p || nil, self = this; -/** - * @namespace - * @module Extensions/Processor - */ -var Processor = Extensions.Processor + $$initialize.$$p = null; + + if (opts == null) opts = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield); + self.content_model = "compound"; + self.blocks = []; + self.subs = []; + self.id = (self.title = (self.caption = (self.numeral = (self.style = (self.default_subs = (self.source_location = nil)))))); + if (($eqeq(context, "document") || ($eqeq(context, "section")))) { + + self.level = (self.next_section_index = 0); + return (self.next_section_ordinal = 1); + } else if ($eqeqeq($$('AbstractBlock'), parent)) { + return (self.level = parent.$level()) + } else { + return (self.level = nil) + } }, -3); + + $def(self, '$block?', $return_val(true)); + + $def(self, '$inline?', $return_val(false)); + + $def(self, '$file', function $$file() { + var self = this, $ret_or_1 = nil; -/** - * The extension will be added to the beginning of the list for that extension type. (default is append). - * @memberof Extensions/Processor - * @deprecated Please use the <code>prefer</pre> function on the {@link Extensions/Registry}, - * the {@link Extensions/IncludeProcessor}, - * the {@link Extensions/TreeProcessor}, - * the {@link Extensions/Postprocessor}, - * the {@link Extensions/Preprocessor} - * or the {@link Extensions/DocinfoProcessor} - */ -Processor.prototype.prepend = function () { - this.$option('position', '>>') -} + if ($truthy(($ret_or_1 = self.source_location))) { + return self.source_location.$file() + } else { + return $ret_or_1 + } + }); + + $def(self, '$lineno', function $$lineno() { + var self = this, $ret_or_1 = nil; -/** - * @memberof Extensions/Processor - */ -Processor.prototype.process = function (block) { - var handler = { - apply: function (target, thisArg, argumentsList) { - for (var i = 0; i < argumentsList.length; i++) { - // convert all (Opal) Hash arguments to JSON. - if (typeof argumentsList[i] === 'object' && '$$smap' in argumentsList[i]) { - argumentsList[i] = fromHash(argumentsList[i]) + if ($truthy(($ret_or_1 = self.source_location))) { + return self.source_location.$lineno() + } else { + return $ret_or_1 } - } - return target.apply(thisArg, argumentsList) - } - } - var blockProxy = new Proxy(block, handler) - return Opal.send(this, 'process', null, toBlock(blockProxy)) -} + }); + + $def(self, '$convert', function $$convert() { + var self = this; -/** - * @param {string} name - * @memberof Extensions/Processor - */ -Processor.prototype.named = function (name) { - return this.$named(name) -} + + self.document.$playback_attributes(self.attributes); + return self.$converter().$convert(self); + }); + $alias(self, "render", "convert"); + + $def(self, '$content', function $$content() { + var self = this; -/** - * Creates a block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string} context - * @param {string|Array<string>} source - * @param {Object|undefined} attrs - A JSON of attributes - * @param {Object|undefined} opts - A JSON of options - * @return {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createBlock = function (parent, context, source, attrs, opts) { - return this.$create_block(parent, context, source, toHash(attrs), toHash(opts)) -} + return $send(self.blocks, 'map', [], function $$1(b){ + + if (b == null) b = nil; + return b.$convert();}).$join($$('LF')) + }); + + $def(self, '$context=', function $AbstractBlock_context$eq$2(context) { + var self = this; -/** - * Creates a list block node and links it to the specified parent. - * - * @param parent - The parent Block (Block, Section, or Document) of this new list block. - * @param {string} context - The list context (e.g., ulist, olist, colist, dlist) - * @param {Object} attrs - An object of attributes to set on this list block - * @returns {List} - * @memberof Extensions/Processor - */ -Processor.prototype.createList = function (parent, context, attrs) { - return this.$create_list(parent, context, toHash(attrs)) -} + return (self.node_name = (self.context = context).$to_s()) + }); + + $def(self, '$<<', function $AbstractBlock_$lt$lt$3(block) { + var self = this; -/** - * Creates a list item node and links it to the specified parent. - * - * @param {List} parent - The parent {List} of this new list item block. - * @param {string} text - The text of the list item. - * @returns {ListItem} - * @memberof Extensions/Processor - */ -Processor.prototype.createListItem = function (parent, text) { - return this.$create_list_item(parent, text) -} + + if (!$eqeq(block.$parent(), self)) { + block['$parent='](self); + } self.blocks['$<<'](block); + return self; + }); + $alias(self, "append", "<<"); + + $def(self, '$blocks?', function $AbstractBlock_blocks$ques$4() { + var self = this; -/** - * Creates an image block node and links it to the specified parent. - * @param {Block|Section|Document} parent - The parent Block of this new image block. - * @param {Object} attrs - A JSON of attributes - * @param {string} attrs.target - the target attribute to set the source of the image. - * @param {string} attrs.alt - the alt attribute to specify an alternative text for the image. - * @param {Object} opts - A JSON of options - * @returns {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createImageBlock = function (parent, attrs, opts) { - return this.$create_image_block(parent, toHash(attrs), toHash(opts)) -} + if ($truthy(self.blocks['$empty?']())) { + return false + } else { + return true + } + }); + + $def(self, '$sections?', $return_val(false)); + + $def(self, '$number', function $$number() { + var self = this; -/** - * Creates a paragraph block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - a paragraph {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createParagraph = function (parent, source, attrs, opts) { - return this.$create_paragraph(parent, source, toHash(attrs), toHash(opts)) -} + try { + + return self.$Integer(self.numeral); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return self.numeral + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + + $def(self, '$number=', function $AbstractBlock_number$eq$5(val) { + var self = this; -/** - * Creates an open block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - an open {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createOpenBlock = function (parent, source, attrs, opts) { - return this.$create_open_block(parent, source, toHash(attrs), toHash(opts)) -} + return (self.numeral = val.$to_s()) + }); + + $def(self, '$find_by', function $$find_by(selector) { + var block = $$find_by.$$p || nil, self = this, result = nil; -/** - * Creates an example block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - an example {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createExampleBlock = function (parent, source, attrs, opts) { - return this.$create_example_block(parent, source, toHash(attrs), toHash(opts)) -} + $$find_by.$$p = null; + if (selector == null) selector = $hash2([], {}); + try { + return $send(self, 'find_by_internal', [selector, (result = [])], block.$to_proc()) + } catch ($err) { + if (Opal.rescue($err, [$$$('StopIteration')])) { + try { + return result + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -1); + $alias(self, "query", "find_by"); + + $def(self, '$next_adjacent_block', function $$next_adjacent_block() { + var self = this, p = nil, sib = nil; -/** - * Creates a literal block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - a literal {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createPassBlock = function (parent, source, attrs, opts) { - return this.$create_pass_block(parent, source, toHash(attrs), toHash(opts)) -} + if ($eqeq(self.context, "document")) { + return nil + } else if (($eqeq((p = self.parent).$context(), "dlist") && ($eqeq(self.context, "list_item")))) { + if ($truthy((sib = p.$items()['$[]']($rb_plus($send(p.$items(), 'find_index', [], function $$6(terms, desc){var self = $$6.$$s == null ? this : $$6.$$s, $ret_or_1 = nil; -/** - * Creates a listing block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - a listing {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createListingBlock = function (parent, source, attrs, opts) { - return this.$create_listing_block(parent, source, toHash(attrs), toHash(opts)) -} + + if (terms == null) terms = nil; + if (desc == null) desc = nil; + if ($truthy(($ret_or_1 = terms['$include?'](self)))) { + return $ret_or_1 + } else { + return desc['$=='](self) + }}, {$$s: self}), 1))))) { + return sib + } else { + return p.$next_adjacent_block() + } + } else if ($truthy((sib = p.$blocks()['$[]']($rb_plus(p.$blocks().$find_index(self), 1))))) { + return sib + } else { + return p.$next_adjacent_block() + } + }); + + $def(self, '$sections', function $$sections() { + var self = this; -/** - * Creates a literal block and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string|Array<string>} source - The source - * @param {Object|undefined} attrs - An object of attributes to set on this block - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Block} - a literal {Block} - * @memberof Extensions/Processor - */ -Processor.prototype.createLiteralBlock = function (parent, source, attrs, opts) { - return this.$create_literal_block(parent, source, toHash(attrs), toHash(opts)) -} + return $send(self.blocks, 'select', [], function $$7(block){ + + if (block == null) block = nil; + return block.$context()['$==']("section");}) + }); + + $def(self, '$alt', function $$alt() { + var self = this, text = nil; -/** - * Creates an inline anchor and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string} text - The text - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Inline} - an {Inline} anchor - * @memberof Extensions/Processor - */ -Processor.prototype.createAnchor = function (parent, text, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return this.$create_anchor(parent, text, toHash(opts)) -} + if ($truthy((text = self.attributes['$[]']("alt")))) { + if ($eqeq(text, self.attributes['$[]']("default-alt"))) { + return self.$sub_specialchars(text) + } else { + + text = self.$sub_specialchars(text); + if ($truthy($$('ReplaceableTextRx')['$match?'](text))) { + + return self.$sub_replacements(text); + } else { + return text + } } + } else { + return "" + } + }); + + $def(self, '$caption', function $$caption() { + var self = this; -/** - * Creates an inline pass and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. - * @param {string} text - The text - * @param {Object|undefined} opts - An object of options to set on this block - * @returns {Inline} - an {Inline} pass - * @memberof Extensions/Processor - */ -Processor.prototype.createInlinePass = function (parent, text, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return this.$create_inline_pass(parent, text, toHash(opts)) -} + if ($eqeq(self.context, "admonition")) { + return self.attributes['$[]']("textlabel") + } else { + return self.caption + } + }); + + $def(self, '$captioned_title', function $$captioned_title() { + var self = this; -/** - * Creates an inline node and links it to the specified parent. - * - * @param {Block|Section|Document} parent - The parent Block of this new inline node. - * @param {string} context - The context name - * @param {string} text - The text - * @param {Object|undefined} opts - A JSON of options - * @returns {Inline} - an {Inline} node - * @memberof Extensions/Processor - */ -Processor.prototype.createInline = function (parent, context, text, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return this.$create_inline(parent, context, text, toHash(opts)) -} + return "" + (self.caption) + (self.$title()) + }); + + $def(self, '$list_marker_keyword', function $$list_marker_keyword(list_type) { + var self = this, $ret_or_1 = nil; -/** - * Parses blocks in the content and attaches the block to the parent. - * @param {AbstractBlock} parent - the parent block - * @param {string|Array<string>} content - the content - * @param {Object|undefined} attrs - an object of attributes - * @returns {AbstractNode} - The parent node into which the blocks are parsed. - * @memberof Extensions/Processor - */ -Processor.prototype.parseContent = function (parent, content, attrs) { - return this.$parse_content(parent, content, attrs) -} + + if (list_type == null) list_type = nil; + return $$('ORDERED_LIST_KEYWORDS')['$[]'](($truthy(($ret_or_1 = list_type)) ? ($ret_or_1) : (self.style))); + }, -1); + + $def(self, '$title', function $$title() { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; -/** - * Parses the attrlist String into a JSON of attributes - * @param {AbstractBlock} block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs) - * @param {string} attrlist - the list of attributes as a String - * @param {Object|undefined} opts - an optional JSON of options to control processing: - * - positional_attributes: an Array of attribute names to map positional arguments to (optional, default: []) - * - sub_attributes: enables attribute substitution on the attrlist argument (optional, default: false) - * - * @returns - a JSON of parsed attributes - * @memberof Extensions/Processor - */ -Processor.prototype.parseAttributes = function (block, attrlist, opts) { - if (opts && opts.attributes) { - opts.attributes = toHash(opts.attributes) - } - return fromHash(this.$parse_attributes(block, attrlist, toHash(opts))) -} + return (self.converted_title = ($truthy(($ret_or_1 = self.converted_title)) ? ($ret_or_1) : ($truthy(($ret_or_2 = self.title)) ? (self.$apply_title_subs(self.title)) : ($ret_or_2)))) + }); + + $def(self, '$title?', function $AbstractBlock_title$ques$8() { + var self = this; -/** - * @param {string|Array<string>} value - Name of a positional attribute or an Array of positional attribute names - * @memberof Extensions/Processor - */ -Processor.prototype.positionalAttributes = function (value) { - return this.$positional_attrs(value) -} + if ($truthy(self.title)) { + return true + } else { + return false + } + }); + + $def(self, '$title=', function $AbstractBlock_title$eq$9(val) { + var self = this; -/** - * Specify how to resolve attributes. - * - * @param {string|Array<string>|Object|boolean} [value] - A specification to resolve attributes. - * @memberof Extensions/Processor - */ -Processor.prototype.resolveAttributes = function (value) { - if (typeof value === 'object' && !Array.isArray(value)) { - return this.$resolves_attributes(toHash(value)) - } - if (arguments.length > 1) { - return this.$resolves_attributes(Array.prototype.slice.call(arguments)) - } - if (typeof value === 'undefined') { - // Convert to nil otherwise an exception is thrown at: - // https://github.com/asciidoctor/asciidoctor/blob/0bcb4addc17b307f62975aad203fb556a1bcd8a5/lib/asciidoctor/extensions.rb#L583 - // - // if args.size == 1 && !args[0] - // - // In the above Ruby code, args[0] is undefined and Opal will try to call the function "!" on an undefined object. - return this.$resolves_attributes(Opal.nil) - } - return this.$resolves_attributes(value) -} + + self.converted_title = nil; + return (self.title = val); + }); + + $def(self, '$sub?', function $AbstractBlock_sub$ques$10(name) { + var self = this; + + return self.subs['$include?'](name) + }); + + $def(self, '$remove_sub', function $$remove_sub(sub) { + var self = this; -/** - * @deprecated Please use the <code>resolveAttributes</pre> function on the {@link Extensions/Processor}. - * @memberof Extensions/Processor - * @see {Processor#resolveAttributes} - */ -Processor.prototype.resolvesAttributes = Processor.prototype.resolveAttributes + + self.subs.$delete(sub); + return nil; + }); + + $def(self, '$xreftext', function $$xreftext(xrefstyle) { + var self = this, val = nil, quoted_title = nil, prefix = nil, caption_attr_name = nil; -/** - * Get the configuration JSON for this processor instance. - * @memberof Extensions/Processor - */ -Processor.prototype.getConfig = function () { - return fromHash(this.config) -} + + if (xrefstyle == null) xrefstyle = nil; + if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) { + return val + } else if ((($truthy(xrefstyle) && ($truthy(self.title))) && ($not(self.caption['$nil_or_empty?']())))) { + + switch (xrefstyle) { + case "full": + + quoted_title = self.$sub_placeholder(self.$sub_quotes(($truthy(self.document.$compat_mode()) ? ("``%s''") : ("\"`%s`\""))), self.$title()); + if ((($truthy(self.numeral) && ($truthy((caption_attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](self.context))))) && ($truthy((prefix = self.document.$attributes()['$[]'](caption_attr_name)))))) { + return "" + (prefix) + " " + (self.numeral) + ", " + (quoted_title) + } else { + return "" + (self.caption.$chomp(". ")) + ", " + (quoted_title) + } case "short": + if ((($truthy(self.numeral) && ($truthy((caption_attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](self.context))))) && ($truthy((prefix = self.document.$attributes()['$[]'](caption_attr_name)))))) { + return "" + (prefix) + " " + (self.numeral) + } else { + return self.caption.$chomp(". ") + } + default: + return self.$title() + } + } else { + return self.$title() + } }, -1); + + $def(self, '$assign_caption', function $$assign_caption(value, caption_context) { + var self = this, $ret_or_1 = nil, prefix = nil, attr_name = nil; -/** - * @memberof Extensions/Processor - */ -Processor.prototype.option = function (key, value) { - this.$option(key, value) -} + + if (caption_context == null) caption_context = self.context; + if ((($truthy(self.caption) || ($not(self.title))) || ($truthy((self.caption = ($truthy(($ret_or_1 = value)) ? ($ret_or_1) : (self.document.$attributes()['$[]']("caption")))))))) { + return nil + } else if (($truthy((attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](caption_context))) && ($truthy((prefix = self.document.$attributes()['$[]'](attr_name)))))) { + + self.caption = "" + (prefix) + " " + ((self.numeral = self.document.$increment_and_store_counter("" + (caption_context) + "-number", self))) + ". "; + return nil; + } else { + return nil + } }, -2); + + $def(self, '$assign_numeral', function $$assign_numeral(section) { + var $a, self = this, like = nil, sectname = nil, caption = nil; -/** - * @namespace - * @module Extensions/BlockProcessor - */ -var BlockProcessor = Extensions.BlockProcessor + + self.next_section_index = $rb_plus(($a = [self.next_section_index], $send(section, 'index=', $a), $a[$a.length - 1]), 1); + if ($truthy((like = section.$numbered()))) { + if ($eqeq((sectname = section.$sectname()), "appendix")) { + + section['$numeral='](self.document.$counter("appendix-number", "A")); + section['$caption='](($truthy((caption = self.document.$attributes()['$[]']("appendix-caption"))) ? ("" + (caption) + " " + (section.$numeral()) + ": ") : ("" + (section.$numeral()) + ". "))); + } else if (($eqeq(sectname, "chapter") || ($eqeq(like, "chapter")))) { + section['$numeral='](self.document.$counter("chapter-number", 1).$to_s()); + } else { + + section['$numeral='](($eqeq(sectname, "part") ? ($$('Helpers').$int_to_roman(self.next_section_ordinal)) : (self.next_section_ordinal.$to_s()))); + self.next_section_ordinal = $rb_plus(self.next_section_ordinal, 1); + } + } return nil; + }); + + $def(self, '$reindex_sections', function $$reindex_sections() { + var self = this; -/** - * @param {Object} value - a JSON of default values for attributes - * @memberof Extensions/BlockProcessor - */ -BlockProcessor.prototype.defaultAttributes = function (value) { - this.$default_attributes(toHash(value)) -} + + self.next_section_index = 0; + self.next_section_ordinal = 1; + return $send(self.blocks, 'each', [], function $$11(block){var self = $$11.$$s == null ? this : $$11.$$s; -/** - * @param {string} context - A context name - * @memberof Extensions/BlockProcessor - */ -BlockProcessor.prototype.onContext = function (context) { - return this.$on_context(context) -} + + if (block == null) block = nil; + if ($eqeq(block.$context(), "section")) { + + self.$assign_numeral(block); + return block.$reindex_sections(); + } else { + return nil + }}, {$$s: self}); + }); + self.$protected(); + return $def(self, '$find_by_internal', function $$find_by_internal(selector, result) { + var block = $$find_by_internal.$$p || nil, self = this, id_selector = nil, role_selector = nil, style_selector = nil, any_context = nil, context_selector = nil, verdict = nil; -/** - * @param {...string} contexts - A list of context names - * @memberof Extensions/BlockProcessor - */ -BlockProcessor.prototype.onContexts = function (contexts) { - return this.$on_contexts(Array.prototype.slice.call(arguments)) -} + $$find_by_internal.$$p = null; + if (selector == null) selector = $hash2([], {}); + if (result == null) result = []; + if ((((($truthy((any_context = ($truthy((context_selector = selector['$[]']("context"))) ? (nil) : (true)))) || ($eqeq(context_selector, self.context))) && (($not((style_selector = selector['$[]']("style"))) || ($eqeq(style_selector, self.style))))) && (($not((role_selector = selector['$[]']("role"))) || ($truthy(self['$has_role?'](role_selector)))))) && (($not((id_selector = selector['$[]']("id"))) || ($eqeq(id_selector, self.id)))))) { + if ((block !== nil)) { + if ($truthy((verdict = Opal.yield1(block, self)))) { + + switch (verdict) { + case "prune": + + result['$<<'](self); + if ($truthy(id_selector)) { + self.$raise($$$('StopIteration')); + } return result; + case "reject": + + if ($truthy(id_selector)) { + self.$raise($$$('StopIteration')); + } return result; + case "stop": + self.$raise($$$('StopIteration')); + break; + default: + + result['$<<'](self); + if ($truthy(id_selector)) { + self.$raise($$$('StopIteration')); + } } + } else if ($truthy(id_selector)) { + self.$raise($$$('StopIteration')); + } + } else { + + result['$<<'](self); + if ($truthy(id_selector)) { + self.$raise($$$('StopIteration')); + } } + } + switch (self.context) { + case "document": + if (!$eqeq(context_selector, "document")) { + + if (($truthy(self['$header?']()) && (($truthy(any_context) || ($eqeq(context_selector, "section")))))) { + $send(self.header, 'find_by_internal', [selector, result], block.$to_proc()); + } $send(self.blocks, 'each', [], function $$12(b){ + + if (b == null) b = nil; + if (($eqeq(context_selector, "section") && ($neqeq(b.$context(), "section")))) { + return nil + } return $send(b, 'find_by_internal', [selector, result], block.$to_proc());}); + } + break; + case "dlist": + if (($truthy(any_context) || ($neqeq(context_selector, "section")))) { + $send(self.blocks.$flatten(), 'each', [], function $$13(b){ + + if (b == null) b = nil; + if ($truthy(b)) { + return $send(b, 'find_by_internal', [selector, result], block.$to_proc()) + } else { + return nil + }}); + } + break; + case "table": + if ($truthy(selector['$[]']("traverse_documents"))) { + + $send(self.$rows().$head(), 'each', [], function $$14(r){ + + if (r == null) r = nil; + return $send(r, 'each', [], function $$15(c){ + + if (c == null) c = nil; + return $send(c, 'find_by_internal', [selector, result], block.$to_proc());});}); + if ($eqeq(context_selector, "inner_document")) { + selector = selector.$merge($hash2(["context"], {"context": "document"})); + } $send($rb_plus(self.$rows().$body(), self.$rows().$foot()), 'each', [], function $$16(r){ + + if (r == null) r = nil; + return $send(r, 'each', [], function $$17(c){ + + if (c == null) c = nil; + $send(c, 'find_by_internal', [selector, result], block.$to_proc()); + if ($eqeq(c.$style(), "asciidoc")) { + return $send(c.$inner_document(), 'find_by_internal', [selector, result], block.$to_proc()) + } else { + return nil + }});}); + } else { + $send($rb_plus($rb_plus(self.$rows().$head(), self.$rows().$body()), self.$rows().$foot()), 'each', [], function $$18(r){ + + if (r == null) r = nil; + return $send(r, 'each', [], function $$19(c){ + + if (c == null) c = nil; + return $send(c, 'find_by_internal', [selector, result], block.$to_proc());});}); + } + break; + default: + $send(self.blocks, 'each', [], function $$20(b){ + + if (b == null) b = nil; + if (($eqeq(context_selector, "section") && ($neqeq(b.$context(), "section")))) { + return nil + } return $send(b, 'find_by_internal', [selector, result], block.$to_proc());}); + } return result; + }, -1); + })($nesting[0], $$('AbstractNode'), $nesting) + })($nesting[0], $nesting) +}; -/** - * @returns {string} - * @memberof Extensions/BlockProcessor - */ -BlockProcessor.prototype.getName = function () { - var name = this.name - return name === Opal.nil ? undefined : name -} +Opal.modules["asciidoctor/attribute_list"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash = Opal.hash, $regexp = Opal.regexp, $hash2 = Opal.hash2, $def = Opal.def, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $send = Opal.send, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * @param {string} value - * @memberof Extensions/BlockProcessor - */ -BlockProcessor.prototype.parseContentAs = function (value) { - this.$parse_content_as(value) -} + Opal.add_stubs('new,[],update,parse,parse_attribute,eos?,skip_delimiter,+,rekey,each_with_index,[]=,private,skip_blank,===,peek,parse_attribute_value,get_byte,start_with?,scan_name,end_with?,rstrip,string,==,unscan,scan_to_delimiter,*,include?,delete,each,split,empty?,apply_subs,scan_to_quote,gsub,skip,scan'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @namespace - * @module Extensions/BlockMacroProcessor - */ -var BlockMacroProcessor = Extensions.BlockMacroProcessor + var $nesting = [self].concat($parent_nesting); -/** - * @param {Object} value - a JSON of default values for attributes - * @memberof Extensions/BlockMacroProcessor - */ -BlockMacroProcessor.prototype.defaultAttributes = function (value) { - this.$default_attributes(toHash(value)) -} + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'AttributeList'); -/** - * @returns {string} - the block macro name - * @memberof Extensions/BlockMacroProcessor - */ -BlockMacroProcessor.prototype.getName = function () { - var name = this.name - return name === Opal.nil ? undefined : name -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/** - * @param {string} value - * @memberof Extensions/BlockMacroProcessor - */ -BlockMacroProcessor.prototype.parseContentAs = function (value) { - this.$parse_content_as(value) -} + $proto.attributes = $proto.scanner = $proto.delimiter = $proto.block = $proto.delimiter_skip_pattern = $proto.delimiter_boundary_pattern = nil; + + $const_set($nesting[0], 'APOS', "'"); + $const_set($nesting[0], 'BACKSLASH', "\\"); + $const_set($nesting[0], 'QUOT', "\""); + $const_set($nesting[0], 'BoundaryRx', $hash($$('QUOT'), /.*?[^\\](?=")/, $$('APOS'), /.*?[^\\](?=')/, ",", /.*?(?=[ \t]*(,|$))/)); + $const_set($nesting[0], 'EscapedQuotes', $hash($$('QUOT'), "\\\"", $$('APOS'), "\\'")); + $const_set($nesting[0], 'NameRx', $regexp([$$('CG_WORD'), "[", $$('CC_WORD'), "\\-.]*"])); + $const_set($nesting[0], 'BlankRx', /[ \t]+/); + $const_set($nesting[0], 'SkipRx', $hash2([","], {",": /[ \t]*(,|$)/})); + + $def(self, '$initialize', function $$initialize(source, block, delimiter) { + var self = this; -/** - * @namespace - * @module Extensions/InlineMacroProcessor - */ -var InlineMacroProcessor = Extensions.InlineMacroProcessor + + if (block == null) block = nil; + if (delimiter == null) delimiter = ","; + self.scanner = $$$('StringScanner').$new(source); + self.block = block; + self.delimiter = delimiter; + self.delimiter_skip_pattern = $$('SkipRx')['$[]'](delimiter); + self.delimiter_boundary_pattern = $$('BoundaryRx')['$[]'](delimiter); + return (self.attributes = nil); + }, -2); + + $def(self, '$parse_into', function $$parse_into(attributes, positional_attrs) { + var self = this; -/** - * @param {Object} value - a JSON of default values for attributes - * @memberof Extensions/InlineMacroProcessor - */ -InlineMacroProcessor.prototype.defaultAttributes = function (value) { - this.$default_attributes(toHash(value)) -} + + if (positional_attrs == null) positional_attrs = []; + return attributes.$update(self.$parse(positional_attrs)); + }, -2); + + $def(self, '$parse', function $$parse(positional_attrs) { + var self = this, index = nil; -/** - * @returns {string} - the inline macro name - * @memberof Extensions/InlineMacroProcessor - */ -InlineMacroProcessor.prototype.getName = function () { - var name = this.name - return name === Opal.nil ? undefined : name -} + + if (positional_attrs == null) positional_attrs = []; + if ($truthy(self.attributes)) { + return self.attributes + } self.attributes = $hash2([], {}); + index = 0; + while ($truthy(self.$parse_attribute(index, positional_attrs))) { + + if ($truthy(self.scanner['$eos?']())) { + break + } self.$skip_delimiter(); + index = $rb_plus(index, 1); + } return self.attributes; + }, -1); + + $def(self, '$rekey', function $$rekey(positional_attrs) { + var self = this; -/** - * @param {string} value - * @memberof Extensions/InlineMacroProcessor - */ -InlineMacroProcessor.prototype.parseContentAs = function (value) { - this.$parse_content_as(value) -} + return $$('AttributeList').$rekey(self.attributes, positional_attrs) + }); + $defs(self, '$rekey', function $$rekey(attributes, positional_attrs) { + + + $send(positional_attrs, 'each_with_index', [], function $$1(key, index){var $a, val = nil; -/** - * @param {string} value - * @memberof Extensions/InlineMacroProcessor - */ -InlineMacroProcessor.prototype.matchFormat = function (value) { - this.$match_format(value) -} + + if (key == null) key = nil; + if (index == null) index = nil; + if (($truthy(key) && ($truthy((val = attributes['$[]']($rb_plus(index, 1))))))) { + return ($a = [key, val], $send(attributes, '[]=', $a), $a[$a.length - 1]) + } else { + return nil + }}); + return attributes; + }); + self.$private(); + + $def(self, '$parse_attribute', function $$parse_attribute(index, positional_attrs) { + var self = this, continue$ = nil, $ret_or_1 = nil, name = nil, single_quoted = nil, skipped = nil, $ret_or_2 = nil, $ret_or_3 = nil, c = nil, value = nil, positional_attr_name = nil; -/** - * @param {RegExp} value - * @memberof Extensions/InlineMacroProcessor - */ -InlineMacroProcessor.prototype.match = function (value) { - this.$match(value) -} + + continue$ = true; + self.$skip_blank(); + if ($eqeqeq($$('QUOT'), ($ret_or_1 = self.scanner.$peek(1)))) { + name = self.$parse_attribute_value(self.scanner.$get_byte()); + } else if ($eqeqeq($$('APOS'), $ret_or_1)) { + + name = self.$parse_attribute_value(self.scanner.$get_byte()); + if (!$truthy(name['$start_with?']($$('APOS')))) { + single_quoted = true; + } } else { + + skipped = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = (name = self.$scan_name()))) ? (self.$skip_blank()) : ($ret_or_3)))) ? ($ret_or_2) : (0)); + if ($truthy(self.scanner['$eos?']())) { + + if (!($truthy(name) || ($truthy(self.scanner.$string().$rstrip()['$end_with?'](self.delimiter))))) { + return nil + } continue$ = nil; + } else if ($eqeq((c = self.scanner.$get_byte()), self.delimiter)) { + self.scanner.$unscan(); + } else if ($truthy(name)) { + if ($eqeq(c, "=")) { + + self.$skip_blank(); + if ($eqeqeq($$('QUOT'), ($ret_or_2 = (c = self.scanner.$get_byte())))) { + value = self.$parse_attribute_value(c); + } else if ($eqeqeq($$('APOS'), $ret_or_2)) { + + value = self.$parse_attribute_value(c); + if (!$truthy(value['$start_with?']($$('APOS')))) { + single_quoted = true; + } } else if ($eqeqeq(self.delimiter, $ret_or_2)) { + + value = ""; + self.scanner.$unscan(); + } else if ($eqeqeq(nil, $ret_or_2)) { + value = ""; + } else { + + value = "" + (c) + (self.$scan_to_delimiter()); + if ($eqeq(value, "None")) { + return true + } } } else { + name = "" + (name) + ($rb_times(" ", skipped)) + (c) + (self.$scan_to_delimiter()); + } + } else { + name = "" + (c) + (self.$scan_to_delimiter()); + } } if ($truthy(value)) { + + switch (name) { + case "options": + case "opts": + if ($truthy(value['$include?'](","))) { + + if ($truthy(value['$include?'](" "))) { + value = value.$delete(" "); + } $send(value.$split(","), 'each', [], function $$2(opt){var $a, self = $$2.$$s == null ? this : $$2.$$s; + if (self.attributes == null) self.attributes = nil; -/** - * @namespace - * @module Extensions/IncludeProcessor - */ -var IncludeProcessor = Extensions.IncludeProcessor + + if (opt == null) opt = nil; + if ($truthy(opt['$empty?']())) { + return nil + } else { + return ($a = ["" + (opt) + "-option", ""], $send(self.attributes, '[]=', $a), $a[$a.length - 1]) + }}, {$$s: self}); + } else if (!$truthy(value['$empty?']())) { + self.attributes['$[]=']("" + (value) + "-option", ""); + } + break; + default: + if (($truthy(single_quoted) && ($truthy(self.block)))) { + + switch (name) { + case "title": + case "reftext": + self.attributes['$[]='](name, value); + break; + default: + self.attributes['$[]='](name, self.block.$apply_subs(value)); + } + } else { + self.attributes['$[]='](name, value); + } + } + } else { + + if (($truthy(single_quoted) && ($truthy(self.block)))) { + name = self.block.$apply_subs(name); + } if (($truthy((positional_attr_name = positional_attrs['$[]'](index))) && ($truthy(name)))) { + self.attributes['$[]='](positional_attr_name, name); + } self.attributes['$[]=']($rb_plus(index, 1), name); + } return continue$; + }); + + $def(self, '$parse_attribute_value', function $$parse_attribute_value(quote) { + var self = this, value = nil; -/** - * @memberof Extensions/IncludeProcessor - */ -IncludeProcessor.prototype.handles = function (block) { - return Opal.send(this, 'handles?', null, toBlock(block)) -} + if ($eqeq(self.scanner.$peek(1), quote)) { + + self.scanner.$get_byte(); + return ""; + } else if ($truthy((value = self.$scan_to_quote(quote)))) { + + self.scanner.$get_byte(); + if ($truthy(value['$include?']($$('BACKSLASH')))) { + + return value.$gsub($$('EscapedQuotes')['$[]'](quote), quote); + } else { + return value + } } else { + return "" + (quote) + (self.$scan_to_delimiter()) + } + }); + + $def(self, '$skip_blank', function $$skip_blank() { + var self = this; -/** - * @memberof Extensions/IncludeProcessor - */ -IncludeProcessor.prototype.prefer = function () { - this.$prefer() -} + return self.scanner.$skip($$('BlankRx')) + }); + + $def(self, '$skip_delimiter', function $$skip_delimiter() { + var self = this; -/** - * @namespace - * @module Extensions/TreeProcessor - */ -var TreeProcessor = Extensions.TreeProcessor + return self.scanner.$skip(self.delimiter_skip_pattern) + }); + + $def(self, '$scan_name', function $$scan_name() { + var self = this; -/** - * @memberof Extensions/TreeProcessor - */ -TreeProcessor.prototype.prefer = function () { - this.$prefer() -} + return self.scanner.$scan($$('NameRx')) + }); + + $def(self, '$scan_to_delimiter', function $$scan_to_delimiter() { + var self = this; -/** - * @namespace - * @module Extensions/Postprocessor - */ -var Postprocessor = Extensions.Postprocessor + return self.scanner.$scan(self.delimiter_boundary_pattern) + }); + return $def(self, '$scan_to_quote', function $$scan_to_quote(quote) { + var self = this; -/** - * @memberof Extensions/Postprocessor - */ -Postprocessor.prototype.prefer = function () { - this.$prefer() -} + return self.scanner.$scan($$('BoundaryRx')['$[]'](quote)) + }); + })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; -/** - * @namespace - * @module Extensions/Preprocessor - */ -var Preprocessor = Extensions.Preprocessor +Opal.modules["asciidoctor/block"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash2 = Opal.hash2, $alias = Opal.alias, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * @memberof Extensions/Preprocessor - */ -Preprocessor.prototype.prefer = function () { - this.$prefer() -} + Opal.add_stubs('default=,context,attr_accessor,[],key?,===,drop,delete,[]=,to_s,commit_subs,nil_or_empty?,prepare_source_string,apply_subs,join,<,size,empty?,rstrip,shift,pop,==,warn,logger,class,object_id,inspect'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * @namespace - * @module Extensions/DocinfoProcessor - */ -var DocinfoProcessor = Extensions.DocinfoProcessor + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * @memberof Extensions/DocinfoProcessor - */ -DocinfoProcessor.prototype.prefer = function () { - this.$prefer() -} + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Block'); -/** - * @param {string} value - The docinfo location ("head", "header" or "footer") - * @memberof Extensions/DocinfoProcessor - */ -DocinfoProcessor.prototype.atLocation = function (value) { - this.$at_location(value) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -function initializeProcessorClass (superclassName, className, functions) { - var superClass = Opal.const_get_qualified(Extensions, superclassName) - return initializeClass(superClass, className, functions, { - 'handles?': function () { - return true - } - }) -} + $proto.attributes = $proto.content_model = $proto.lines = $proto.subs = $proto.blocks = $proto.context = $proto.style = nil; + + $const_set($nesting[0], 'DEFAULT_CONTENT_MODEL', $hash2(["audio", "image", "listing", "literal", "stem", "open", "page_break", "pass", "thematic_break", "video"], {"audio": "empty", "image": "empty", "listing": "verbatim", "literal": "verbatim", "stem": "raw", "open": "compound", "page_break": "empty", "pass": "raw", "thematic_break": "empty", "video": "empty"}))['$default=']("simple"); + $alias(self, "blockname", "context"); + self.$attr_accessor("lines"); + + $def(self, '$initialize', function $$initialize(parent, context, opts) { + var $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil, subs = nil, raw_source = nil; -// Postprocessor + $$initialize.$$p = null; + + if (opts == null) opts = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield); + self.content_model = ($truthy(($ret_or_1 = opts['$[]']("content_model"))) ? ($ret_or_1) : ($$('DEFAULT_CONTENT_MODEL')['$[]'](context))); + if ($truthy(opts['$key?']("subs"))) { + if ($truthy((subs = opts['$[]']("subs")))) { + + if ($eqeqeq("default", ($ret_or_1 = subs))) { + self.default_subs = opts['$[]']("default_subs"); + } else if ($eqeqeq($$$('Array'), $ret_or_1)) { + + self.default_subs = subs.$drop(0); + self.attributes.$delete("subs"); + } else { + + self.default_subs = nil; + self.attributes['$[]=']("subs", subs.$to_s()); + } self.$commit_subs(); + } else { + + self.default_subs = []; + self.attributes.$delete("subs"); + } + } else { + self.default_subs = nil; + } if ($truthy((raw_source = opts['$[]']("source"))['$nil_or_empty?']())) { + return (self.lines = []) + } else if ($eqeqeq($$$('String'), raw_source)) { + return (self.lines = $$('Helpers').$prepare_source_string(raw_source)) + } else { + return (self.lines = raw_source.$drop(0)) + } }, -3); + + $def(self, '$content', function $$content() { + var $yield = $$content.$$p || nil, self = this, result = nil, $ret_or_2 = nil, first = nil, last = nil; -/** - * Create a postprocessor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createPostprocessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('Postprocessor', name, functions) -} + $$content.$$p = null; + + switch (self.content_model) { + case "compound": + return $send2(self, $find_super(self, 'content', $$content, false, true), 'content', [], $yield) + case "simple": + return self.$apply_subs(self.lines.$join($$('LF')), self.subs) + case "verbatim": + case "raw": + + result = self.$apply_subs(self.lines, self.subs); + if ($truthy($rb_lt(result.$size(), 2))) { + if ($truthy(($ret_or_2 = result['$[]'](0)))) { + return $ret_or_2 + } else { + return "" + } + } else { + + while ($truthy(($truthy(($ret_or_2 = (first = result['$[]'](0)))) ? (first.$rstrip()['$empty?']()) : ($ret_or_2)))) { + result.$shift(); + } while ($truthy(($truthy(($ret_or_2 = (last = result['$[]'](-1)))) ? (last.$rstrip()['$empty?']()) : ($ret_or_2)))) { + result.$pop(); + } return result.$join($$('LF')); + } default: + + if (!$eqeq(self.content_model, "empty")) { + self.$logger().$warn("unknown content model '" + (self.content_model) + "' for block: " + (self)); + } return nil; + } + }); + + $def(self, '$source', function $$source() { + var self = this; -/** - * Create and instantiate a postprocessor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newPostprocessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createPostprocessor(name, functions).$new() -} + return self.lines.$join($$('LF')) + }); + return $def(self, '$to_s', function $$to_s() { + var self = this, content_summary = nil; -// Preprocessor + + content_summary = ($eqeq(self.content_model, "compound") ? ("blocks: " + (self.blocks.$size())) : ("lines: " + (self.lines.$size()))); + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {context: " + (self.context.$inspect()) + ", content_model: " + (self.content_model.$inspect()) + ", style: " + (self.style.$inspect()) + ", " + (content_summary) + "}>"; + }); + })($nesting[0], $$('AbstractBlock'), $nesting) + })($nesting[0], $nesting) +}; -/** - * Create a preprocessor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createPreprocessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('Preprocessor', name, functions) -} +Opal.modules["asciidoctor/callouts"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_le = Opal.rb_le, $rb_minus = Opal.rb_minus, $send = Opal.send, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil; -/** - * Create and instantiate a preprocessor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newPreprocessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createPreprocessor(name, functions).$new() -} + Opal.add_stubs('next_list,<<,current_list,to_i,generate_next_callout_id,+,<=,size,[],-,chop,join,map,==,<,private,generate_callout_id'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -// Tree Processor + var $nesting = [self].concat($parent_nesting); -/** - * Create a tree processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createTreeProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('TreeProcessor', name, functions) -} + return (function($base, $super) { + var self = $klass($base, $super, 'Callouts'); -/** - * Create and instantiate a tree processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newTreeProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createTreeProcessor(name, functions).$new() -} + var $proto = self.$$prototype; -// Include Processor + $proto.co_index = $proto.lists = $proto.list_index = nil; + + + $def(self, '$initialize', function $$initialize() { + var self = this; -/** - * Create an include processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createIncludeProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('IncludeProcessor', name, functions) -} + + self.lists = []; + self.list_index = 0; + return self.$next_list(); + }); + + $def(self, '$register', function $$register(li_ordinal) { + var self = this, id = nil; + + + self.$current_list()['$<<']($hash2(["ordinal", "id"], {"ordinal": li_ordinal.$to_i(), "id": (id = self.$generate_next_callout_id())})); + self.co_index = $rb_plus(self.co_index, 1); + return id; + }); + + $def(self, '$read_next_id', function $$read_next_id() { + var self = this, id = nil, list = nil; + + + id = nil; + list = self.$current_list(); + if ($truthy($rb_le(self.co_index, list.$size()))) { + id = list['$[]']($rb_minus(self.co_index, 1))['$[]']("id"); + } self.co_index = $rb_plus(self.co_index, 1); + return id; + }); + + $def(self, '$callout_ids', function $$callout_ids(li_ordinal) { + var self = this; + + return $send(self.$current_list(), 'map', [], function $$1(it){ + + if (it == null) it = nil; + if ($eqeq(it['$[]']("ordinal"), li_ordinal)) { + return "" + (it['$[]']("id")) + " " + } else { + return "" + }}).$join().$chop() + }); + + $def(self, '$current_list', function $$current_list() { + var self = this; -/** - * Create and instantiate an include processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newIncludeProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createIncludeProcessor(name, functions).$new() -} + return self.lists['$[]']($rb_minus(self.list_index, 1)) + }); + + $def(self, '$next_list', function $$next_list() { + var self = this; -// Docinfo Processor + + self.list_index = $rb_plus(self.list_index, 1); + if ($truthy($rb_lt(self.lists.$size(), self.list_index))) { + self.lists['$<<']([]); + } self.co_index = 1; + return nil; + }); + + $def(self, '$rewind', function $$rewind() { + var self = this; -/** - * Create a Docinfo processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createDocinfoProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('DocinfoProcessor', name, functions) -} + + self.list_index = 1; + self.co_index = 1; + return nil; + }); + self.$private(); + + $def(self, '$generate_next_callout_id', function $$generate_next_callout_id() { + var self = this; -/** - * Create and instantiate a Docinfo processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newDocinfoProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createDocinfoProcessor(name, functions).$new() -} + return self.$generate_callout_id(self.list_index, self.co_index) + }); + return $def(self, '$generate_callout_id', function $$generate_callout_id(list_index, co_index) { + + return "CO" + (list_index) + "-" + (co_index) + }); + })($nesting[0], null) + })($nesting[0], $nesting) +}; -// Block Processor +Opal.modules["asciidoctor/converter/composite"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $send = Opal.send, $truthy = Opal.truthy, $def = Opal.def, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Create a block processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createBlockProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('BlockProcessor', name, functions) -} + Opal.add_stubs('attr_reader,each,respond_to?,composed,init_backend_traits,backend_traits,new,[]=,find_converter,convert,converter_for,node_name,[],handles?,raise'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -/** - * Create and instantiate a block processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newBlockProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createBlockProcessor(name, functions).$new() -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -// Inline Macro Processor + return (function($base, $super) { + var self = $klass($base, $super, 'CompositeConverter'); -/** - * Create an inline macro processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createInlineMacroProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('InlineMacroProcessor', name, functions) -} + var $proto = self.$$prototype; -/** - * Create and instantiate an inline macro processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newInlineMacroProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createInlineMacroProcessor(name, functions).$new() -} + $proto.converter_cache = $proto.converters = nil; + + self.$attr_reader("converters"); + + $def(self, '$initialize', function $$initialize(backend, $a, $b) { + var $post_args, $kwargs, converters, backend_traits_source, self = this; -// Block Macro Processor + + $post_args = $slice(arguments, 1); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + converters = $post_args; + + backend_traits_source = $kwargs.$$smap["backend_traits_source"];if (backend_traits_source == null) backend_traits_source = nil; + self.backend = backend; + $send((self.converters = converters), 'each', [], function $$1(converter){var self = $$1.$$s == null ? this : $$1.$$s; -/** - * Create a block macro processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.createBlockMacroProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return initializeProcessorClass('BlockMacroProcessor', name, functions) -} + + if (converter == null) converter = nil; + if ($truthy(converter['$respond_to?']("composed"))) { + return converter.$composed(self) + } else { + return nil + }}, {$$s: self}); + if ($truthy(backend_traits_source)) { + self.$init_backend_traits(backend_traits_source.$backend_traits()); + } return (self.converter_cache = $send($$$('Hash'), 'new', [], function $$2(hash, key){var $c, self = $$2.$$s == null ? this : $$2.$$s; -/** - * Create and instantiate a block macro processor - * @description this API is experimental and subject to change - * @memberof Extensions - */ -Extensions.newBlockMacroProcessor = function (name, functions) { - if (arguments.length === 1) { - functions = name - name = null - } - return this.createBlockMacroProcessor(name, functions).$new() -} + + if (hash == null) hash = nil; + if (key == null) key = nil; + return ($c = [key, self.$find_converter(key)], $send(hash, '[]=', $c), $c[$c.length - 1]);}, {$$s: self})); + }, -2); + + $def(self, '$convert', function $$convert(node, transform, opts) { + var self = this, $ret_or_1 = nil; -// Converter API + + if (transform == null) transform = nil; + if (opts == null) opts = nil; + return self.$converter_for((transform = ($truthy(($ret_or_1 = transform)) ? ($ret_or_1) : (node.$node_name())))).$convert(node, transform, opts); + }, -2); + + $def(self, '$converter_for', function $$converter_for(transform) { + var self = this; -/** - * @namespace - * @module Converter - */ -var Converter = Opal.const_get_qualified(Opal.Asciidoctor, 'Converter') + return self.converter_cache['$[]'](transform) + }); + return $def(self, '$find_converter', function $$find_converter(transform) {try { var $t_return = $thrower('return'); + var self = this; -// Alias -Opal.Asciidoctor.Converter = Converter + + $send(self.converters, 'each', [], function $$3(candidate){ + + if (candidate == null) candidate = nil; + if ($truthy(candidate['$handles?'](transform))) { + $t_return.$throw(candidate); + } else { + return nil + };}, {$$ret: $t_return}); + return self.$raise("Could not find a converter to handle transform: " + (transform));} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }); + })($$('Converter'), $$$($$('Converter'), 'Base')) + })($nesting[0], $nesting) +}; -/** - * Convert the specified node. - * - * @param {AbstractNode} node - the AbstractNode to convert - * @param {string} transform - an optional String transform that hints at - * which transformation should be applied to this node. - * @param {Object} opts - a JSON of options that provide additional hints about how to convert the node (default: {}) - * @returns the {Object} result of the conversion, typically a {string}. - * @memberof Converter - */ -Converter.prototype.convert = function (node, transform, opts) { - return this.$convert(node, transform, toHash(opts)) -} +Opal.modules["asciidoctor/converter"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $defs = Opal.defs, $send = Opal.send, $alias = Opal.alias, $slice = Opal.slice, $to_a = Opal.to_a, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $eqeqeq = Opal.eqeqeq, $Class = Opal.Class, $klass = Opal.klass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, $rb_plus = Opal.rb_plus, $gvars = Opal.gvars, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/** - * Create an instance of the converter bound to the specified backend. - * - * @param {string} backend - look for a converter bound to this keyword. - * @param {Object} opts - a JSON of options to pass to the converter (default: {}) - * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST. - * @memberof Converter - */ -Converter.create = function (backend, opts) { - return this.$create(backend, toHash(opts)) -} + Opal.add_stubs('autoload,attr_reader,raise,class,[],sub,slice,length,==,[]=,backend_traits,derive_backend_traits,register,map,to_s,new,create,default,each,default=,registry,for,===,supports_templates?,merge,private,include,delete,clear,send,extend,private_class_method,node_name,+,name,receiver,warn,logger,respond_to?,content'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); -// Converter Factory API + var $nesting = [self].concat($parent_nesting); -/** - * @namespace - * @module Converter/Factory - */ -var ConverterFactory = Opal.Asciidoctor.Converter.Factory + return (function($base, $parent_nesting) { + var self = $module($base, 'Converter'); -var ConverterBase = Opal.Asciidoctor.Converter.Base + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -// Alias -Opal.Asciidoctor.ConverterFactory = ConverterFactory + + self.$autoload("CompositeConverter", "" + ("asciidoctor") + "/converter/composite"); + self.$attr_reader("backend"); + + $def(self, '$initialize', function $$initialize(backend, opts) { + var self = this; -var ConverterBackendTraits = Opal.Asciidoctor.Converter.BackendTraits + + if (opts == null) opts = $hash2([], {}); + return (self.backend = backend); + }, -2); + + $def(self, '$convert', function $$convert(node, transform, opts) { + var self = this; + if (self.backend == null) self.backend = nil; + return self.$raise($$$('NotImplementedError'), "" + (self.$class()) + " (backend: " + (self.backend) + ") must implement the #" + ("convert") + " method"); + }, -2); + + $def(self, '$handles?', $return_val(true)); + $defs(self, '$derive_backend_traits', function $$derive_backend_traits(backend, basebackend) { + var outfilesuffix = nil, $ret_or_1 = nil, filetype = nil; -// Alias -Opal.Asciidoctor.ConverterBackendTraits = ConverterBackendTraits + + if (basebackend == null) basebackend = nil; + if (!$truthy(backend)) { + return $hash2([], {}) + } if ($truthy((outfilesuffix = $$('DEFAULT_EXTENSIONS')['$[]']((basebackend = ($truthy(($ret_or_1 = basebackend)) ? ($ret_or_1) : (backend.$sub($$('TrailingDigitsRx'), "")))))))) { + filetype = outfilesuffix.$slice(1, outfilesuffix.$length()); + } else { + outfilesuffix = "." + ((filetype = basebackend)); + } if ($eqeq(filetype, "html")) { + return $hash2(["basebackend", "filetype", "htmlsyntax", "outfilesuffix"], {"basebackend": basebackend, "filetype": filetype, "htmlsyntax": "html", "outfilesuffix": outfilesuffix}) + } else { + return $hash2(["basebackend", "filetype", "outfilesuffix"], {"basebackend": basebackend, "filetype": filetype, "outfilesuffix": outfilesuffix}) + } }, -2); + (function($base, $parent_nesting) { + var self = $module($base, 'BackendTraits'); -/** - * Register a custom converter in the global converter factory to handle conversion to the specified backends. - * If the backend value is an asterisk, the converter is used to handle any backend that does not have an explicit converter. - * - * @param converter - The Converter instance to register - * @param backends {Array} - A {string} {Array} of backend names that this converter should be registered to handle (optional, default: ['*']) - * @return {*} - Returns nothing - * @memberof Converter/Factory - */ -ConverterFactory.register = function (converter, backends) { - var object - var buildBackendTraitsFromObject = function (obj) { - return Object.assign({}, - obj.basebackend ? { basebackend: obj.basebackend } : {}, - obj.outfilesuffix ? { outfilesuffix: obj.outfilesuffix } : {}, - obj.filetype ? { filetype: obj.filetype } : {}, - obj.htmlsyntax ? { htmlsyntax: obj.htmlsyntax } : {}, - obj.supports_templates ? { supports_templates: obj.supports_templates } : {} - ) - } - var assignBackendTraitsToInstance = function (obj, instance) { - if (obj.backend_traits) { - instance.backend_traits = toHash(obj.backend_traits) - } else if (obj.backendTraits) { - instance.backend_traits = toHash(obj.backendTraits) - } else if (obj.basebackend || obj.outfilesuffix || obj.filetype || obj.htmlsyntax || obj.supports_templates) { - instance.backend_traits = toHash(buildBackendTraitsFromObject(obj)) - } - } - var bridgeHandlesMethodToInstance = function (obj, instance) { - bridgeMethodToInstance(obj, instance, '$handles?', 'handles', function () { - return true - }) - } - var bridgeComposedMethodToInstance = function (obj, instance) { - bridgeMethodToInstance(obj, instance, '$composed', 'composed') - } - var bridgeEqEqMethodToInstance = function (obj, instance) { - bridgeMethodToInstance(obj, instance, '$==', '==', function (other) { - return instance === other - }) - } - var bridgeSendMethodToInstance = function (obj, instance) { - bridgeMethodToInstance(obj, instance, '$send', 'send', function (symbol) { - var args = Array.prototype.slice.call(arguments, 1) - var func = instance['$' + symbol] - if (func) { - return func.apply(instance, args) - } - throw new Error(`undefined method \`${symbol}\` for \`${instance.toString()}\``) - }) - } - var bridgeMethodToInstance = function (obj, instance, methodName, functionName, defaultImplementation) { - if (typeof obj[methodName] === 'undefined') { - if (typeof obj[functionName] === 'function') { - instance[methodName] = obj[functionName] - } else if (defaultImplementation) { - instance[methodName] = defaultImplementation - } - } - } - var addRespondToMethod = function (instance) { - if (typeof instance['$respond_to?'] !== 'function') { - instance['$respond_to?'] = function (name) { - return typeof this[name] === 'function' - } - } - } - if (typeof converter === 'function') { - // Class - object = initializeClass(ConverterBase, converter.constructor.name, { - initialize: function (backend, opts) { - var self = this - var result = new converter(backend, opts) // eslint-disable-line - Object.assign(this, result) - assignBackendTraitsToInstance(result, self) - var propertyNames = Object.getOwnPropertyNames(converter.prototype) - for (var i = 0; i < propertyNames.length; i++) { - var propertyName = propertyNames[i] - if (propertyName !== 'constructor') { - self[propertyName] = result[propertyName] - } - } - if (typeof result.$convert === 'undefined' && typeof result.convert === 'function') { - self.$convert = result.convert - } - bridgeHandlesMethodToInstance(result, self) - bridgeComposedMethodToInstance(result, self) - addRespondToMethod(self) - self.super(backend, opts) - } - }) - object.$extend(ConverterBackendTraits) - } else if (typeof converter === 'object') { - // Instance - if (typeof converter.$convert === 'undefined' && typeof converter.convert === 'function') { - converter.$convert = converter.convert - } - assignBackendTraitsToInstance(converter, converter) - if (converter.backend_traits) { - // "extends" ConverterBackendTraits - var converterBackendTraitsFunctionNames = [ - 'basebackend', - 'filetype', - 'htmlsyntax', - 'outfilesuffix', - 'supports_templates', - 'supports_templates?', - 'init_backend_traits', - 'backend_traits' - ] - for (var functionName of converterBackendTraitsFunctionNames) { - converter['$' + functionName] = ConverterBackendTraits.prototype['$' + functionName] - } - converter.$$meta = ConverterBackendTraits - } - bridgeHandlesMethodToInstance(converter, converter) - bridgeComposedMethodToInstance(converter, converter) - bridgeEqEqMethodToInstance(converter, converter) - bridgeSendMethodToInstance(converter, converter) - addRespondToMethod(converter) - object = converter - } - var args = [object].concat(backends) - return Converter.$register.apply(Converter, args) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/** - * Retrieves the singleton instance of the converter factory. - * - * @param {boolean} initialize - instantiate the singleton if it has not yet - * been instantiated. If this value is false and the singleton has not yet been - * instantiated, this method returns a fresh instance. - * @returns {Converter/Factory} an instance of the converter factory. - * @memberof Converter/Factory - */ -ConverterFactory.getDefault = function (initialize) { - return this.$default(initialize) -} + + + $def(self, '$basebackend', function $$basebackend(value) { + var $a, self = this; -/** - * Create an instance of the converter bound to the specified backend. - * - * @param {string} backend - look for a converter bound to this keyword. - * @param {Object} opts - a JSON of options to pass to the converter (default: {}) - * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST. - * @memberof Converter/Factory - */ -ConverterFactory.prototype.create = function (backend, opts) { - return this.$create(backend, toHash(opts)) -} + + if (value == null) value = nil; + if ($truthy(value)) { + + return ($a = ["basebackend", value], $send(self.$backend_traits(value), '[]=', $a), $a[$a.length - 1]); + } else { + return self.$backend_traits()['$[]']("basebackend") + } }, -1); + + $def(self, '$filetype', function $$filetype(value) { + var $a, self = this; -/** - * Get the converter registry. - * @returns the registry of converter instances or classes keyed by backend name - * @memberof Converter/Factory - */ -ConverterFactory.getRegistry = function () { - return fromHash(Converter.$registry()) -} + + if (value == null) value = nil; + if ($truthy(value)) { + + return ($a = ["filetype", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]); + } else { + return self.$backend_traits()['$[]']("filetype") + } }, -1); + + $def(self, '$htmlsyntax', function $$htmlsyntax(value) { + var $a, self = this; -/** - * Lookup the custom converter registered with this factory to handle the specified backend. - * - * @param {string} backend - The {string} backend name. - * @returns the {Converter} class or instance registered to convert the specified backend or undefined if no match is found. - * @memberof Converter/Factory - */ -ConverterFactory.for = function (backend) { - const converter = Converter.$for(backend) - return converter === Opal.nil ? undefined : converter -} + + if (value == null) value = nil; + if ($truthy(value)) { + + return ($a = ["htmlsyntax", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]); + } else { + return self.$backend_traits()['$[]']("htmlsyntax") + } }, -1); + + $def(self, '$outfilesuffix', function $$outfilesuffix(value) { + var $a, self = this; -/* - * Unregister any custom converter classes that are registered with this factory. - * Intended for testing only! - */ -ConverterFactory.unregisterAll = function () { - var internalRegistry = Converter.DefaultFactory.$$cvars['@@registry'] - Converter.DefaultFactory.$$cvars['@@registry'] = toHash({ html5: internalRegistry['$[]']('html5') }) -} + + if (value == null) value = nil; + if ($truthy(value)) { + + return ($a = ["outfilesuffix", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]); + } else { + return self.$backend_traits()['$[]']("outfilesuffix") + } }, -1); + + $def(self, '$supports_templates', function $$supports_templates(value) { + var $a, self = this; -// Built-in converter + + if (value == null) value = true; + return ($a = ["supports_templates", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]); + }, -1); + + $def(self, '$supports_templates?', function $BackendTraits_supports_templates$ques$1() { + var self = this; -/** - * @namespace - * @module Converter/Html5Converter - */ -var Html5Converter = Opal.Asciidoctor.Converter.Html5Converter + return self.$backend_traits()['$[]']("supports_templates") + }); + + $def(self, '$init_backend_traits', function $$init_backend_traits(value) { + var self = this, $ret_or_1 = nil; -// Alias -Opal.Asciidoctor.Html5Converter = Html5Converter + + if (value == null) value = nil; + return (self.backend_traits = ($truthy(($ret_or_1 = value)) ? ($ret_or_1) : ($hash2([], {})))); + }, -1); + + $def(self, '$backend_traits', function $$backend_traits(basebackend) { + var self = this, $ret_or_1 = nil; + if (self.backend_traits == null) self.backend_traits = nil; + if (self.backend == null) self.backend = nil; -/** - * Create a new Html5Converter. - * @returns {Html5Converter} - a Html5Converter - * @memberof Converter/Html5Converter - */ -Html5Converter.create = function () { - return this.$new() -} + + if (basebackend == null) basebackend = nil; + return (self.backend_traits = ($truthy(($ret_or_1 = self.backend_traits)) ? ($ret_or_1) : ($$('Converter').$derive_backend_traits(self.backend, basebackend)))); + }, -1); + $alias(self, "backend_info", "backend_traits"); + return $defs(self, '$derive_backend_traits', function $$derive_backend_traits(backend, basebackend) { + + + if (basebackend == null) basebackend = nil; + return $$('Converter').$derive_backend_traits(backend, basebackend); + }, -2); + })($nesting[0], $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'Config'); -/** - * Converts an {AbstractNode} using the given transform. - * This method must be implemented by a concrete converter class. - * - * @param {AbstractNode} node - The concrete instance of AbstractNode to convert. - * @param {string} [transform] - An optional String transform that hints at which transformation should be applied to this node. - * If a transform is not given, the transform is often derived from the value of the {AbstractNode#getNodeName} property. (optional, default: undefined) - * @param {Object} [opts]- An optional JSON of options hints about how to convert the node. (optional, default: undefined) - * - * @returns {string} - the String result. - * @memberof Converter/Html5Converter - */ -Html5Converter.prototype.convert = function (node, transform, opts) { - return this.$convert(node, transform, opts) -} + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + return $def(self, '$register_for', function $$register_for($a) { + var $post_args, backends, self = this; -var ASCIIDOCTOR_JS_VERSION = '2.2.6'; + + $post_args = $slice(arguments); + backends = $post_args; + return $send($$('Converter'), 'register', [self].concat($to_a($send(backends, 'map', [], function $$2(backend){ + + if (backend == null) backend = nil; + return backend.$to_s();})))); + }, -1) + })($nesting[0], $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'Factory'); - /** - * Get Asciidoctor.js version number. - * - * @memberof Asciidoctor - * @returns {string} - returns the version number of Asciidoctor.js. - */ - Asciidoctor.prototype.getVersion = function () { - return ASCIIDOCTOR_JS_VERSION - } - return Opal.Asciidoctor -})) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + $defs(self, '$new', function $Factory_new$3($a, $b) { + var $post_args, $kwargs, converters, proxy_default; -/***/ }), + + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + + if ($post_args.length > 0) converters = $post_args.shift();if (converters == null) converters = nil; + + proxy_default = $kwargs.$$smap["proxy_default"];if (proxy_default == null) proxy_default = true; + if ($truthy(proxy_default)) { + + return $$('DefaultFactoryProxy').$new(converters); + } else { + + return $$('CustomFactory').$new(converters); + } }, -1); + $defs(self, '$default', function $Factory_default$4($a) { -/***/ 9560: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + + $slice(arguments); + return $$('Converter'); + }, -1); + $defs(self, '$create', function $$create(backend, opts) { + var self = this; -/* global globalThis, self */ -var globalObject -if (typeof globalThis !== 'undefined') { - globalObject = globalThis -} else if (typeof self !== 'undefined') { - globalObject = self -} else if (typeof window !== 'undefined') { - globalObject = window -} else if (typeof global !== 'undefined') { - globalObject = global -} else { - throw new Error('Unable to locate global object. Unsupported runtime.') -} -if (globalObject && globalObject.Opal) { - // Opal is already loaded! - var rubyEngineVersion = globalObject.Opal.$$['RUBY_ENGINE_VERSION'] - if (!rubyEngineVersion.startsWith('0.11')) { - // incompatible version! - throw new Error('Opal is already loaded and version ' + rubyEngineVersion + ' is not compatible with 0.11. Please upgrade Asciidoctor.js to the latest version.') - } -} else { - // load Opal - __nccwpck_require__(4274) - __nccwpck_require__(8555) - __nccwpck_require__(4007) - __nccwpck_require__(9442) -} + + if (opts == null) opts = $hash2([], {}); + return self.$default().$create(backend, opts); + }, -2); + + $def(self, '$register', function $$register(converter, $a) { + var $post_args, backends, self = this; -module.exports.s = globalObject.Opal + + $post_args = $slice(arguments, 1); + backends = $post_args; + return $send(backends, 'each', [], function $$5(backend){var $b, self = $$5.$$s == null ? this : $$5.$$s; + + if (backend == null) backend = nil; + if ($eqeq(backend, "*")) { + + return ($b = [converter], $send(self.$registry(), 'default=', $b), $b[$b.length - 1]); + } else { + + return ($b = [backend, converter], $send(self.$registry(), '[]=', $b), $b[$b.length - 1]); + }}, {$$s: self}); + }, -2); + + $def(self, '$for', function $Factory_for$6(backend) { + var self = this; -/***/ }), + return self.$registry()['$[]'](backend) + }); + + $def(self, '$create', function $$create(backend, opts) { + var self = this, converter = nil, template_dirs = nil, delegate_backend = nil; -/***/ 8555: -/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { + + if (opts == null) opts = $hash2([], {}); + if ($truthy((converter = self.$for(backend)))) { + + if ($eqeqeq($Class, converter)) { + converter = converter.$new(backend, opts); + } if ((($truthy((template_dirs = opts['$[]']("template_dirs"))) && ($eqeqeq($$('BackendTraits'), converter))) && ($truthy(converter['$supports_templates?']())))) { + return $$('CompositeConverter').$new(backend, $$('TemplateConverter').$new(backend, template_dirs, opts), converter, $hash2(["backend_traits_source"], {"backend_traits_source": converter})) + } else { + return converter + } } else if ($truthy((template_dirs = opts['$[]']("template_dirs")))) { + if (($truthy((delegate_backend = opts['$[]']("delegate_backend"))) && ($truthy((converter = self.$for(delegate_backend)))))) { + + if ($eqeqeq($Class, converter)) { + converter = converter.$new(delegate_backend, opts); + } return $$('CompositeConverter').$new(backend, $$('TemplateConverter').$new(backend, template_dirs, opts), converter, $hash2(["backend_traits_source"], {"backend_traits_source": converter})); + } else { + return $$('TemplateConverter').$new(backend, template_dirs, opts) + } + } else { + return nil + } }, -2); + + $def(self, '$converters', function $$converters() { + var self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/kernel"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; + return self.$registry().$merge() + }); + self.$private(); + return $def(self, '$registry', function $$registry() { + var self = this; - Opal.add_stubs(['$warn', '$to_str']); - - Opal.exit = process.exit; - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); + return self.$raise($$$('NotImplementedError'), "" + ($$('Factory')) + " subclass " + (self.$class()) + " must implement the #" + ("registry") + " method") + }); + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'CustomFactory'); - var $nesting = [self].concat($parent_nesting), $Kernel_caller$1, $Kernel_node_require$2; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - Opal.const_set($nesting[0], 'NODE_REQUIRE', require); - - Opal.def(self, '$caller', $Kernel_caller$1 = function $$caller($a) { - var $post_args, args, self = this; + + self.$include($$('Factory')); + + $def(self, '$initialize', function $$initialize(seed_registry) { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var stack; - try { - var err = Error("my error"); - throw err; - } catch(e) { - stack = e.stack; - } - return stack.$split("\n").slice(3); - ; - }, $Kernel_caller$1.$$arity = -1); - - Opal.def(self, '$node_require', $Kernel_node_require$2 = function $$node_require(path) { - var self = this; + + if (seed_registry == null) seed_registry = nil; + if ($truthy(seed_registry)) { + + seed_registry['$default='](seed_registry.$delete("*")); + return (self.registry = seed_registry); + } else { + return (self.registry = $hash2([], {})) + } }, -1); + + $def(self, '$unregister_all', function $$unregister_all() { + var $a, self = this; - - self.$warn("[DEPRECATION] node_require is deprecated. Please use `require('module')` instead."); - return $$($nesting, 'NODE_REQUIRE')(path.$to_str()); - }, $Kernel_node_require$2.$$arity = 1); - })($nesting[0], $nesting); - return Opal.const_set($nesting[0], 'ARGV', process.argv.slice(2)); -}; + return ($a = [nil], $send(self.$registry().$clear(), 'default=', $a), $a[$a.length - 1]) + }); + self.$private(); + return self.$attr_reader("registry"); + })($nesting[0], null, $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'DefaultFactory'); -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/file"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $gvars = Opal.gvars; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.add_stubs(['$raise', '$warn', '$const_get', '$new', '$const_defined?', '$const_set', '$include', '$size', '$respond_to?', '$path', '$join', '$call', '$exist?', '$realpath', '$!=', '$close', '$to_path', '$pwd', '$to_str', '$include?', '$delete', '$match?', '$sub', '$attr_reader', '$to_a', '$each_line', '$to_enum', '$read', '$chomp']); - - - var warnings = {}, errno_code, errno_codes = [ - 'EACCES', - 'EISDIR', - 'EMFILE', - 'ENOENT', - 'EPERM' - ]; + + self.$include($$('Factory')); + self.$private(); + $class_variable_set($nesting[0], '@@registry', $hash2([], {})); + + $def(self, '$registry', function $$registry() { + + return $class_variable_get($nesting[0], '@@registry', false) + }); + return nil; + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'DefaultFactoryProxy'); - function handle_unsupported_feature(message) { - switch (Opal.config.unsupported_features_severity) { - case 'error': - $$($nesting, 'Kernel').$raise($$($nesting, 'NotImplementedError'), message) - break; - case 'warning': - warn(message) - break; - default: // ignore - // noop - } - } - function warn(string) { - if (warnings[string]) { - return; - } - warnings[string] = true; - self.$warn(string); - } - function is_utf8(bytes) { - var i = 0; - while (i < bytes.length) { - if ((// ASCII - bytes[i] === 0x09 || - bytes[i] === 0x0A || - bytes[i] === 0x0D || - (0x20 <= bytes[i] && bytes[i] <= 0x7E) - ) - ) { - i += 1; - continue; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if ((// non-overlong 2-byte - (0xC2 <= bytes[i] && bytes[i] <= 0xDF) && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) - ) - ) { - i += 2; - continue; - } + + self.$include($$('DefaultFactory')); + return nil; + })($nesting[0], $$('CustomFactory'), $nesting); + $defs(self, '$included', function $$included(into) { + + + into.$send("include", $$('BackendTraits')); + return into.$extend($$('Config')); + }); + self.$private_class_method("included"); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Base'); - if ((// excluding overlongs - bytes[i] === 0xE0 && - (0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) - ) || - (// straight 3-byte - ((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || - bytes[i] === 0xEE || - bytes[i] === 0xEF) && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) - ) || - (// excluding surrogates - bytes[i] === 0xED && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x9F) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) - ) - ) { - i += 3; - continue; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - if ((// planes 1-3 - bytes[i] === 0xF0 && - (0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) || - (// planes 4-15 - (0xF1 <= bytes[i] && bytes[i] <= 0xF3) && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) || - (// plane 16 - bytes[i] === 0xF4 && - (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && - (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && - (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) - ) - ) { - i += 4; - continue; - } + $proto.backend = nil; + + self.$include($$('Logging')); + self.$include($$('Converter')); + + $def(self, '$convert', function $$convert(node, transform, opts) { + var self = this, ex = nil; + if ($gvars["!"] == null) $gvars["!"] = nil; - return false; - } + + if (transform == null) transform = node.$node_name(); + if (opts == null) opts = nil; + try { + if ($truthy(opts)) { + + return self.$send($rb_plus("convert_", transform), node, opts); + } else { + + return self.$send($rb_plus("convert_", transform), node); + } + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + if (!(($eqeqeq($$$('NoMethodError'), (ex = $gvars["!"])) && ($eqeq(ex.$receiver(), self))) && ($eqeq(ex.$name().$to_s(), transform)))) { + self.$raise(); + }; + self.$logger().$warn("missing convert handler for " + (ex.$name()) + " node in " + (self.backend) + " backend (" + (self.$class()) + ")"); + return nil; + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -2); + + $def(self, '$handles?', function $Base_handles$ques$7(transform) { + var self = this; - return true; - } - function executeIOAction(action) { - try { - return action(); - } catch (error) { - if (errno_codes.indexOf(error.code) >= 0) { - var error_class = $$($nesting, 'Errno').$const_get(error.code) - throw (error_class).$new(error.message); - } - throw error; - } - } + return self['$respond_to?']("convert_" + (transform)) + }); + + $def(self, '$content_only', function $$content_only(node) { + + return node.$content() + }); + return $def(self, '$skip', $return_val(nil)); + })($nesting[0], null, $nesting); + return self.$extend($$('DefaultFactory')); + })($nesting[0], $nesting) + })($nesting[0], $nesting) +}; - for(var i = 0, ii = errno_codes.length; i < ii; i++) { - errno_code = errno_codes[i]; - if (!$$($nesting, 'Errno')['$const_defined?'](errno_code)) { - $$($nesting, 'Errno').$const_set(errno_code, $$($nesting, 'Class').$new($$($nesting, 'SystemCallError'))) - } - } -; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'File'); +Opal.modules["asciidoctor/document"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, $alias = Opal.alias, $truthy = Opal.truthy, $def = Opal.def, $hash2 = Opal.hash2, $not = Opal.not, $to_ary = Opal.to_ary, $return_ivar = Opal.return_ivar, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_minus = Opal.rb_minus, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $hash = Opal.hash, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $neqeq = Opal.neqeq, $thrower = Opal.thrower, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $gvars = Opal.gvars, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - var $nesting = [self].concat($parent_nesting), $File_read$1, $File_write$2, $File_exist$ques$3, $File_realpath$4, $File_join$5, $File_directory$ques$6, $File_file$ques$7, $File_readable$ques$8, $File_size$9, $File_open$10, $File_stat$11, $File_mtime$12, $File_symlink$ques$13, $File_absolute_path$14, $File_initialize$15, $File_read$16, $File_readlines$17, $File_each_line$18, $File_write$19, $File_flush$20, $File_close$21, $File_mtime$22; - if (self.__fs__ == null) self.__fs__ = nil; - if (self.__path__ == null) self.__path__ = nil; - if (self.__util__ == null) self.__util__ = nil; + Opal.add_stubs('new,target,attr_reader,nil?,<<,[],[]=,main,include?,strip,squeeze,gsub,!,empty?,rpartition,attr_accessor,catalog,delete,base_dir,options,merge,instance_variable_get,attributes,safe,compat_mode,outfilesuffix,sourcemap,path_resolver,converter,extensions,syntax_highlighter,each,end_with?,start_with?,slice,-,length,chop,==,downcase,===,extname,value_for_name,key?,freeze,attribute_undefined,attribute_missing,update,&,keys,name_for_value,expand_path,pwd,to_s,>=,+,abs,to_i,delete_if,update_doctype_attributes,cursor,parse,restore_attributes,update_backend_attributes,fetch,fill_datetime_attributes,activate,groups,create,to_proc,preprocessors?,preprocessors,process_method,tree_processors?,tree_processors,!=,counter,nil_or_empty?,attribute_locked?,nextval,value,save_to,increment_and_store_counter,register,tap,xreftext,>,source,source_lines,doctitle,sectname=,title=,first_section,title,reftext,<,find,context,header?,assign_numeral,clear_playback_attributes,save_attributes,name,negate,rewind,replace,apply_attribute_value_subs,delete?,start,doctype,content_model,warn,logger,content,convert,postprocessors?,postprocessors,record,write,respond_to?,chomp,class,write_alternate_pages,map,split,resolve_docinfo_subs,normalize_system_path,read_asset,apply_subs,docinfo_processors?,join,concat,compact,docinfo_processors,object_id,inspect,size,private,=~,resolve_pass_subs,apply_header_subs,limit_bytesize,bytesize,valid_encoding?,byteslice,resolve_subs,utc,at,Integer,now,index,strftime,year,utc_offset,partition,create_converter,basebackend,filetype,htmlsyntax,derive_backend_traits,raise'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - self.$$prototype.eof = self.$$prototype.binary_flag = self.$$prototype.path = self.$$prototype.fd = nil; - - self.$include($$$($$$('::', 'IO'), 'Writable')); - self.$include($$$($$$('::', 'IO'), 'Readable')); - self.__fs__ = __nccwpck_require__(7147); - self.__path__ = __nccwpck_require__(1017); - self.__util__ = __nccwpck_require__(3837); - var __fs__ = self.__fs__; - var __path__ = self.__path__; - var __util__ = self.__util__; - var __TextEncoder__ = typeof TextEncoder !== 'undefined' ? TextEncoder : __util__.TextEncoder; - var __TextDecoder__ = typeof TextDecoder !== 'undefined' ? TextDecoder : __util__.TextDecoder; - var __utf8TextDecoder__ = new __TextDecoder__('utf8'); - var __textEncoder__ = new __TextEncoder__(); - if ($truthy(__path__.sep !== $$($nesting, 'Separator'))) { - Opal.const_set($nesting[0], 'ALT_SEPARATOR', __path__.sep)}; - Opal.defs(self, '$read', $File_read$1 = function $$read(path) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return executeIOAction(function(){return __fs__.readFileSync(path).toString()}) - }, $File_read$1.$$arity = 1); - Opal.defs(self, '$write', $File_write$2 = function $$write(path, data) { - var self = this; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Document'); - - executeIOAction(function(){return __fs__.writeFileSync(path, data)}); - return data.$size(); - }, $File_write$2.$$arity = 2); - Opal.defs(self, '$exist?', $File_exist$ques$3 = function(path) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.attributes = $proto.safe = $proto.sourcemap = $proto.reader = $proto.base_dir = $proto.parsed = $proto.parent_document = $proto.extensions = $proto.options = $proto.counters = $proto.catalog = $proto.reftexts = $proto.next_section_index = $proto.header = $proto.blocks = $proto.header_attributes = $proto.attributes_modified = $proto.backend = $proto.attribute_overrides = $proto.timings = $proto.converter = $proto.outfilesuffix = $proto.docinfo_processor_extensions = $proto.document = $proto.max_attribute_value_size = $proto.id = $proto.doctype = nil; - if ($truthy(path['$respond_to?']("path"))) { - path = path.$path()}; - return executeIOAction(function(){return __fs__.existsSync(path)}); - }, $File_exist$ques$3.$$arity = 1); - Opal.defs(self, '$realpath', $File_realpath$4 = function $$realpath(pathname, dir_string, cache) { - var $iter = $File_realpath$4.$$p, block = $iter || nil, self = this; + $const_set($nesting[0], 'ImageReference', $send($$$('Struct'), 'new', ["target", "imagesdir"], function $Document$1(){var self = $Document$1.$$s == null ? this : $Document$1.$$s; + + return $alias(self, "to_s", "target")}, {$$s: self})); + $const_set($nesting[0], 'Footnote', $$$('Struct').$new("index", "id", "text")); + (function($base, $super) { + var self = $klass($base, $super, 'AttributeEntry'); - if ($iter) $File_realpath$4.$$p = null; - - - if ($iter) $File_realpath$4.$$p = null;; - - if (dir_string == null) { - dir_string = nil; - }; - - if (cache == null) { - cache = nil; - }; - if ($truthy(dir_string)) { - pathname = self.$join(dir_string, pathname)}; - if ((block !== nil)) { - __fs__.realpath(pathname, cache, function(error, realpath){ - if (error) Opal.IOError.$new(error.message) - else block.$call(realpath) - }) - } else { - return executeIOAction(function(){return __fs__.realpathSync(pathname, cache)}) - }; - }, $File_realpath$4.$$arity = -2); - Opal.defs(self, '$join', $File_join$5 = function $$join($a) { - var $post_args, paths, self = this; + self.$attr_reader("name", "value", "negate"); + + $def(self, '$initialize', function $$initialize(name, value, negate) { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - paths = $post_args;; - return __path__.posix.join.apply(__path__, paths); - }, $File_join$5.$$arity = -1); - Opal.defs(self, '$directory?', $File_directory$ques$6 = function(path) { - var self = this, result = nil, realpath = nil; + + if (negate == null) negate = nil; + self.name = name; + self.value = value; + return (self.negate = ($truthy(negate['$nil?']()) ? (value['$nil?']()) : (negate))); + }, -3); + return $def(self, '$save_to', function $$save_to(block_attributes) { + var $a, self = this, $ret_or_1 = nil; - - if ($truthy(self['$exist?'](path))) { - } else { - return false - }; - result = executeIOAction(function(){return !!__fs__.lstatSync(path).isDirectory()}); - if ($truthy(result)) { - } else { + + ($truthy(($ret_or_1 = block_attributes['$[]']("attribute_entries"))) ? ($ret_or_1) : (($a = ["attribute_entries", []], $send(block_attributes, '[]=', $a), $a[$a.length - 1])))['$<<'](self); + return self; + }); + })($nesting[0], null); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Title'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + + $proto.subtitle = nil; - realpath = self.$realpath(path); - if ($truthy(realpath['$!='](path))) { - result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isDirectory()})}; - }; - return result; - }, $File_directory$ques$6.$$arity = 1); - Opal.defs(self, '$file?', $File_file$ques$7 = function(path) { - var self = this, result = nil, realpath = nil; + self.$attr_reader("main"); + $alias(self, "title", "main"); + self.$attr_reader("subtitle"); + self.$attr_reader("combined"); + + $def(self, '$initialize', function $$initialize(val, opts) { + var $a, $b, self = this, sep = nil, $ret_or_1 = nil; - - if ($truthy(self['$exist?'](path))) { - } else { - return false - }; - result = executeIOAction(function(){return !!__fs__.lstatSync(path).isFile()}); - if ($truthy(result)) { - } else { + + if (opts == null) opts = $hash2([], {}); + if (($truthy((self.sanitized = opts['$[]']("sanitize"))) && ($truthy(val['$include?']("<"))))) { + val = val.$gsub($$('XmlSanitizeRx'), "").$squeeze(" ").$strip(); + } if (($truthy((sep = ($truthy(($ret_or_1 = opts['$[]']("separator"))) ? ($ret_or_1) : (":")))['$empty?']()) || ($not(val['$include?']((sep = "" + (sep) + " ")))))) { + + self.main = val; + self.subtitle = nil; + } else { + $b = val.$rpartition(sep), $a = $to_ary($b), (self.main = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (self.subtitle = ($a[2] == null ? nil : $a[2])); + } return (self.combined = val); + }, -2); - realpath = self.$realpath(path); - if ($truthy(realpath['$!='](path))) { - result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isFile()})}; - }; - return result; - }, $File_file$ques$7.$$arity = 1); - Opal.defs(self, '$readable?', $File_readable$ques$8 = function(path) { - var self = this; + $def(self, '$sanitized?', $return_ivar("sanitized")); + + $def(self, '$subtitle?', function $Title_subtitle$ques$2() { + var self = this; + if ($truthy(self.subtitle)) { + return true + } else { + return false + } + }); + return $def(self, '$to_s', $return_ivar("combined")); + })($nesting[0], null, $nesting); + $const_set($nesting[0], 'Author', $$$('Struct').$new("name", "firstname", "middlename", "lastname", "initials", "email")); + self.$attr_reader("safe"); + self.$attr_reader("compat_mode"); + self.$attr_reader("backend"); + self.$attr_reader("doctype"); + self.$attr_accessor("sourcemap"); + self.$attr_reader("catalog"); + $alias(self, "references", "catalog"); + self.$attr_reader("counters"); + self.$attr_reader("header"); + self.$attr_reader("base_dir"); + self.$attr_reader("options"); + self.$attr_reader("outfilesuffix"); + self.$attr_reader("parent_document"); + self.$attr_reader("reader"); + self.$attr_reader("path_resolver"); + self.$attr_reader("converter"); + self.$attr_reader("syntax_highlighter"); + self.$attr_reader("extensions"); - if ($truthy(self['$exist?'](path))) { - } else { - return false - }; - return "" + "\n" + " try {\n" + " __fs__.accessSync(path, __fs__.R_OK);\n" + " return true;\n" + " } catch (error) {\n" + " return false;\n" + " }\n" + " "; - }, $File_readable$ques$8.$$arity = 1); - Opal.defs(self, '$size', $File_size$9 = function $$size(path) { - var self = this; - - return executeIOAction(function(){return __fs__.lstatSync(path).size}); - }, $File_size$9.$$arity = 1); - Opal.defs(self, '$open', $File_open$10 = function $$open(path, mode) { - var $iter = $File_open$10.$$p, $yield = $iter || nil, self = this, file = nil; + $def(self, '$initialize', function $$initialize(data, options) { + var $b, $c, $d, $e; $$initialize.$$p || nil; var self = this, parent_doc = nil, $ret_or_1 = nil, attr_overrides = nil, parent_doctype = nil, initialize_extensions = nil, to_file = nil, safe_mode = nil, input_mtime = nil, standalone = nil, attrs = nil, safe_mode_name = nil, base_dir_val = nil, backend_val = nil, doctype_val = nil, size = nil, initial_backend = nil, ext_registry = nil, ext_block = nil; - if ($iter) $File_open$10.$$p = null; - - - if (mode == null) { - mode = "r"; - }; - file = self.$new(path, mode); - if (($yield !== nil)) { + $$initialize.$$p = null; - return (function() { try { - return Opal.yield1($yield, file); - } finally { - file.$close() - }; })(); - } else { - return file - }; - }, $File_open$10.$$arity = -2); - Opal.defs(self, '$stat', $File_stat$11 = function $$stat(path) { - var self = this; + if (data == null) data = nil; + if (options == null) options = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [self, "document"], null); + if ($truthy((parent_doc = options.$delete("parent")))) { + + self.parent_document = parent_doc; + if ($truthy(($ret_or_1 = options['$[]']("base_dir")))) ; else { + options['$[]=']("base_dir", parent_doc.$base_dir()); + } if ($truthy(parent_doc.$options()['$[]']("catalog_assets"))) { + options['$[]=']("catalog_assets", true); + } if ($truthy(parent_doc.$options()['$[]']("to_dir"))) { + options['$[]=']("to_dir", parent_doc.$options()['$[]']("to_dir")); + } self.catalog = parent_doc.$catalog().$merge($hash2(["footnotes"], {"footnotes": []})); + self.attribute_overrides = (attr_overrides = parent_doc.$instance_variable_get("@attribute_overrides").$merge(parent_doc.$attributes())); + attr_overrides.$delete("compat-mode"); + parent_doctype = attr_overrides.$delete("doctype"); + attr_overrides.$delete("notitle"); + attr_overrides.$delete("showtitle"); + attr_overrides.$delete("toc"); + self.attributes['$[]=']("toc-placement", ($truthy(($ret_or_1 = attr_overrides.$delete("toc-placement"))) ? ($ret_or_1) : ("auto"))); + attr_overrides.$delete("toc-position"); + self.safe = parent_doc.$safe(); + if ($truthy((self.compat_mode = parent_doc.$compat_mode()))) { + self.attributes['$[]=']("compat-mode", ""); + } self.outfilesuffix = parent_doc.$outfilesuffix(); + self.sourcemap = parent_doc.$sourcemap(); + self.timings = nil; + self.path_resolver = parent_doc.$path_resolver(); + self.converter = parent_doc.$converter(); + initialize_extensions = nil; + self.extensions = parent_doc.$extensions(); + self.syntax_highlighter = parent_doc.$syntax_highlighter(); + } else { + + self.parent_document = nil; + self.catalog = $hash2(["ids", "refs", "footnotes", "links", "images", "callouts", "includes"], {"ids": $hash2([], {}), "refs": $hash2([], {}), "footnotes": [], "links": [], "images": [], "callouts": $$('Callouts').$new(), "includes": $hash2([], {})}); + self.attribute_overrides = (attr_overrides = $hash2([], {})); + $send(($truthy(($ret_or_1 = options['$[]']("attributes"))) ? ($ret_or_1) : ($hash2([], {}))), 'each', [], function $$3(key, val){var $a; + + if (key == null) key = nil; + if (val == null) val = nil; + if ($truthy(key['$end_with?']("@"))) { + if ($truthy(key['$start_with?']("!"))) { + $a = [key.$slice(1, $rb_minus(key.$length(), 2)), false], (key = $a[0]), (val = $a[1]); + } else if ($truthy(key['$end_with?']("!@"))) { + $a = [key.$slice(0, $rb_minus(key.$length(), 2)), false], (key = $a[0]), (val = $a[1]); + } else { + $a = [key.$chop(), "" + (val) + "@"], (key = $a[0]), (val = $a[1]); + } + } else if ($truthy(key['$start_with?']("!"))) { + $a = [key.$slice(1, key.$length()), ($eqeq(val, "@") ? (false) : (nil))], (key = $a[0]), (val = $a[1]); + } else if ($truthy(key['$end_with?']("!"))) { + $a = [key.$chop(), ($eqeq(val, "@") ? (false) : (nil))], (key = $a[0]), (val = $a[1]); + } return ($a = [key.$downcase(), val], $send(attr_overrides, '[]=', $a), $a[$a.length - 1]);}); + if ($eqeqeq($$$('String'), (to_file = options['$[]']("to_file")))) { + attr_overrides['$[]=']("outfilesuffix", $$('Helpers').$extname(to_file)); + } if ($not((safe_mode = options['$[]']("safe")))) { + self.safe = $$$($$('SafeMode'), 'SECURE'); + } else if ($eqeqeq($$$('Integer'), safe_mode)) { + self.safe = safe_mode; + } else { + self.safe = (function() { try { + + return $$('SafeMode').$value_for_name(safe_mode); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return $$$($$('SafeMode'), 'SECURE') + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})(); + } input_mtime = options.$delete("input_mtime"); + self.compat_mode = attr_overrides['$key?']("compat-mode"); + self.sourcemap = options['$[]']("sourcemap"); + self.timings = options.$delete("timings"); + self.path_resolver = $$('PathResolver').$new(); + initialize_extensions = (($truthy((($b = $$$('::', 'Asciidoctor', 'skip_raise')) && ($$$($b, 'Extensions', 'skip_raise')) ? 'constant' : nil)) || ($truthy(options['$key?']("extensions")))) ? ($$$($$$('Asciidoctor'), 'Extensions')) : (nil)); + self.extensions = nil; + if (($truthy(options['$key?']("header_footer")) && ($not(options['$key?']("standalone"))))) { + options['$[]=']("standalone", options['$[]']("header_footer")); + } } self.parsed = (self.reftexts = (self.header = (self.header_attributes = nil))); + self.counters = $hash2([], {}); + self.attributes_modified = $$$('Set').$new(); + self.docinfo_processor_extensions = $hash2([], {}); + standalone = options['$[]']("standalone"); + (self.options = options).$freeze(); + attrs = self.attributes; + if (!$truthy(parent_doc)) { + + attrs['$[]=']("attribute-undefined", $$('Compliance').$attribute_undefined()); + attrs['$[]=']("attribute-missing", $$('Compliance').$attribute_missing()); + attrs.$update($$('DEFAULT_ATTRIBUTES')); + } if ($truthy(standalone)) { + + attr_overrides['$[]=']("embedded", nil); + attrs['$[]=']("copycss", ""); + attrs['$[]=']("iconfont-remote", ""); + attrs['$[]=']("stylesheet", ""); + attrs['$[]=']("webfonts", ""); + } else { + + attr_overrides['$[]=']("embedded", ""); + if (($truthy(attr_overrides['$key?']("showtitle")) && ($eqeq(attr_overrides.$keys()['$&'](["notitle", "showtitle"])['$[]'](-1), "showtitle")))) { + attr_overrides['$[]=']("notitle", $hash(nil, "", false, "@", "@", false)['$[]'](attr_overrides['$[]']("showtitle"))); + } else if ($truthy(attr_overrides['$key?']("notitle"))) { + attr_overrides['$[]=']("showtitle", $hash(nil, "", false, "@", "@", false)['$[]'](attr_overrides['$[]']("notitle"))); + } else { + attrs['$[]=']("notitle", ""); + } } attr_overrides['$[]=']("asciidoctor", ""); + attr_overrides['$[]=']("asciidoctor-version", $$$($$$('Asciidoctor'), 'VERSION')); + attr_overrides['$[]=']("safe-mode-name", (safe_mode_name = $$('SafeMode').$name_for_value(self.safe))); + attr_overrides['$[]=']("safe-mode-" + (safe_mode_name), ""); + attr_overrides['$[]=']("safe-mode-level", self.safe); + if ($truthy(($ret_or_1 = attr_overrides['$[]']("max-include-depth")))) ; else { + attr_overrides['$[]=']("max-include-depth", 64); + } if ($truthy(($ret_or_1 = attr_overrides['$[]']("allow-uri-read")))) ; else { + attr_overrides['$[]=']("allow-uri-read", nil); + } if ($truthy(attr_overrides['$key?']("numbered"))) { + attr_overrides['$[]=']("sectnums", attr_overrides.$delete("numbered")); + } if ($truthy(attr_overrides['$key?']("hardbreaks"))) { + attr_overrides['$[]=']("hardbreaks-option", attr_overrides.$delete("hardbreaks")); + } if ($truthy((base_dir_val = options['$[]']("base_dir")))) { + self.base_dir = ($c = ["docdir", $$$('File').$expand_path(base_dir_val)], $send(attr_overrides, '[]=', $c), $c[$c.length - 1]); + } else if ($truthy(attr_overrides['$[]']("docdir"))) { + self.base_dir = attr_overrides['$[]']("docdir"); + } else { + self.base_dir = ($c = ["docdir", $$$('Dir').$pwd()], $send(attr_overrides, '[]=', $c), $c[$c.length - 1]); + } if ($truthy((backend_val = options['$[]']("backend")))) { + attr_overrides['$[]=']("backend", backend_val.$to_s()); + } if ($truthy((doctype_val = options['$[]']("doctype")))) { + attr_overrides['$[]=']("doctype", doctype_val.$to_s()); + } if ($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SERVER')))) { + + if ($truthy(($ret_or_1 = attr_overrides['$[]']("copycss")))) ; else { + attr_overrides['$[]=']("copycss", nil); + } if ($truthy(($ret_or_1 = attr_overrides['$[]']("source-highlighter")))) ; else { + attr_overrides['$[]=']("source-highlighter", nil); + } if ($truthy(($ret_or_1 = attr_overrides['$[]']("backend")))) ; else { + attr_overrides['$[]=']("backend", $$('DEFAULT_BACKEND')); + } if (($not(parent_doc) && ($truthy(attr_overrides['$key?']("docfile"))))) { + attr_overrides['$[]=']("docfile", attr_overrides['$[]']("docfile")['$[]'](Opal.Range.$new($rb_plus(attr_overrides['$[]']("docdir").$length(), 1), -1, false))); + } attr_overrides['$[]=']("docdir", ""); + if ($truthy(($ret_or_1 = attr_overrides['$[]']("user-home")))) ; else { + attr_overrides['$[]=']("user-home", "."); + } if ($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SECURE')))) { + + if (!$truthy(attr_overrides['$key?']("max-attribute-value-size"))) { + attr_overrides['$[]=']("max-attribute-value-size", 4096); + } if (!$truthy(attr_overrides['$key?']("linkcss"))) { + attr_overrides['$[]=']("linkcss", ""); + } if ($truthy(($ret_or_1 = attr_overrides['$[]']("icons")))) ; else { + attr_overrides['$[]=']("icons", nil); + } } } else if ($truthy(($ret_or_1 = attr_overrides['$[]']("user-home")))) ; else { + attr_overrides['$[]=']("user-home", $$('USER_HOME')); + } self.max_attribute_value_size = ($truthy((size = ($truthy(($ret_or_1 = attr_overrides['$[]']("max-attribute-value-size"))) ? ($ret_or_1) : (($c = ["max-attribute-value-size", nil], $send(attr_overrides, '[]=', $c), $c[$c.length - 1]))))) ? (size.$to_i().$abs()) : (nil)); + $send(attr_overrides, 'delete_if', [], function $$4(key, val){var $d, verdict = nil; + + + if (key == null) key = nil; + if (val == null) val = nil; + if ($truthy(val)) { + + if (($eqeqeq($$$('String'), val) && ($truthy(val['$end_with?']("@"))))) { + $d = [val.$chop(), true], (val = $d[0]), (verdict = $d[1]); + } attrs['$[]='](key, val); + } else { + + attrs.$delete(key); + verdict = val['$=='](false); + } return verdict;}); + if ($truthy(parent_doc)) { + + self.backend = attrs['$[]']("backend"); + if (!$eqeq((self.doctype = ($c = ["doctype", parent_doctype], $send(attrs, '[]=', $c), $c[$c.length - 1])), $$('DEFAULT_DOCTYPE'))) { + self.$update_doctype_attributes($$('DEFAULT_DOCTYPE')); + } self.reader = $$('Reader').$new(data, options['$[]']("cursor")); + if ($truthy(self.sourcemap)) { + self.source_location = self.reader.$cursor(); + } $$('Parser').$parse(self.reader, self); + self.$restore_attributes(); + return (self.parsed = true); + } else { + + self.backend = nil; + if ($eqeq((initial_backend = ($truthy(($ret_or_1 = attrs['$[]']("backend"))) ? ($ret_or_1) : ($$('DEFAULT_BACKEND')))), "manpage")) { + self.doctype = ($c = ["doctype", ($d = ["doctype", "manpage"], $send(attr_overrides, '[]=', $d), $d[$d.length - 1])], $send(attrs, '[]=', $c), $c[$c.length - 1]); + } else { + self.doctype = ($truthy(($ret_or_1 = attrs['$[]']("doctype"))) ? ($ret_or_1) : (($c = ["doctype", $$('DEFAULT_DOCTYPE')], $send(attrs, '[]=', $c), $c[$c.length - 1]))); + } self.$update_backend_attributes(initial_backend, true); + if ($truthy(($ret_or_1 = attrs['$[]']("stylesdir")))) ; else { + attrs['$[]=']("stylesdir", "."); + } if ($truthy(($ret_or_1 = attrs['$[]']("iconsdir")))) ; else { + attrs['$[]=']("iconsdir", "" + (attrs.$fetch("imagesdir", "./images")) + "/icons"); + } self.$fill_datetime_attributes(attrs, input_mtime); + if ($truthy(initialize_extensions)) { + if ($truthy((ext_registry = options['$[]']("extension_registry")))) { + if (($eqeqeq($$$($$('Extensions'), 'Registry'), ext_registry) || (($truthy((($e = $$$('::', 'AsciidoctorJ', 'skip_raise')) && ($d = $$$($e, 'Extensions', 'skip_raise')) && ($c = $$$($d, 'ExtensionRegistry', 'skip_raise')) ? 'constant' : nil)) && ($eqeqeq($$$($$$($$$('AsciidoctorJ'), 'Extensions'), 'ExtensionRegistry'), ext_registry)))))) { + self.extensions = ext_registry.$activate(self); + } + } else if ($truthy((ext_block = options['$[]']("extensions"))['$nil?']())) { + if (!$truthy($$('Extensions').$groups()['$empty?']())) { + self.extensions = $$$($$('Extensions'), 'Registry').$new().$activate(self); + } + } else if ($eqeqeq($$$('Proc'), ext_block)) { + self.extensions = $send($$('Extensions'), 'create', [], ext_block.$to_proc()).$activate(self); + } + } self.reader = $$('PreprocessorReader').$new(self, data, $$$($$('Reader'), 'Cursor').$new(attrs['$[]']("docfile"), self.base_dir), $hash2(["normalize"], {"normalize": true})); + if ($truthy(self.sourcemap)) { + return (self.source_location = self.reader.$cursor()) + } else { + return nil + } } }, -1); - if ($truthy(path['$respond_to?']("path"))) { - path = path.$path()}; - return $$$($$($nesting, 'File'), 'Stat').$new(path); - }, $File_stat$11.$$arity = 1); - Opal.defs(self, '$mtime', $File_mtime$12 = function $$mtime(path) { - var self = this; + $def(self, '$parse', function $$parse(data) { + var self = this, doc = nil, exts = nil; - return executeIOAction(function(){return __fs__.statSync(path).mtime}) - }, $File_mtime$12.$$arity = 1); - Opal.defs(self, '$symlink?', $File_symlink$ques$13 = function(path) { - var self = this; + + if (data == null) data = nil; + if ($truthy(self.parsed)) { + return self + } else { + + doc = self; + if ($truthy(data)) { + + self.reader = $$('PreprocessorReader').$new(doc, data, $$$($$('Reader'), 'Cursor').$new(self.attributes['$[]']("docfile"), self.base_dir), $hash2(["normalize"], {"normalize": true})); + if ($truthy(self.sourcemap)) { + self.source_location = self.reader.$cursor(); + } } if (($truthy((exts = ($truthy(self.parent_document) ? (nil) : (self.extensions)))) && ($truthy(exts['$preprocessors?']())))) { + $send(exts.$preprocessors(), 'each', [], function $$5(ext){var self = $$5.$$s == null ? this : $$5.$$s, $ret_or_1 = nil; + if (self.reader == null) self.reader = nil; - return executeIOAction(function(){return __fs__.lstatSync(path).isSymbolicLink()}) - }, $File_symlink$ques$13.$$arity = 1); - Opal.defs(self, '$absolute_path', $File_absolute_path$14 = function $$absolute_path(path, basedir) { - var $a, self = this; + + if (ext == null) ext = nil; + return (self.reader = ($truthy(($ret_or_1 = ext.$process_method()['$[]'](doc, self.reader))) ? ($ret_or_1) : (self.reader)));}, {$$s: self}); + } $$('Parser').$parse(self.reader, doc, $hash2(["header_only"], {"header_only": self.options['$[]']("parse_header_only")})); + self.$restore_attributes(); + if (($truthy(exts) && ($truthy(exts['$tree_processors?']())))) { + $send(exts.$tree_processors(), 'each', [], function $$6(ext){var result = nil; + + if (ext == null) ext = nil; + if ((($truthy((result = ext.$process_method()['$[]'](doc))) && ($eqeqeq($$('Document'), result))) && ($neqeq(result, doc)))) { + return (doc = result) + } else { + return nil + }}); + } self.parsed = true; + return doc; + } }, -1); + $def(self, '$parsed?', $return_ivar("parsed")); - if (basedir == null) { - basedir = nil; - }; - path = (function() {if ($truthy(path['$respond_to?']("to_path"))) { - return path.$to_path() - } else { - return path - }; return nil; })(); - basedir = ($truthy($a = basedir) ? $a : $$($nesting, 'Dir').$pwd()); - return __path__.normalize(__path__.resolve(basedir.$to_str(), path.$to_str())).split(__path__.sep).join(__path__.posix.sep); - }, $File_absolute_path$14.$$arity = -2); - - Opal.def(self, '$initialize', $File_initialize$15 = function $$initialize(path, flags) { - var self = this, encoding_option_rx = nil; + $def(self, '$counter', function $$counter(name, seed) { + var $a, self = this, curr_val = nil, locked = nil, next_val = nil; + + if (seed == null) seed = nil; + if ($truthy(self.parent_document)) { + return self.parent_document.$counter(name, seed) + } if ((($truthy((locked = self['$attribute_locked?'](name))) && ($truthy((curr_val = self.counters['$[]'](name))))) || ($not((curr_val = self.attributes['$[]'](name))['$nil_or_empty?']())))) { + next_val = ($a = [name, $$('Helpers').$nextval(curr_val)], $send(self.counters, '[]=', $a), $a[$a.length - 1]); + } else if ($truthy(seed)) { + next_val = ($a = [name, ($eqeq(seed, seed.$to_i().$to_s()) ? (seed.$to_i()) : (seed))], $send(self.counters, '[]=', $a), $a[$a.length - 1]); + } else { + next_val = ($a = [name, 1], $send(self.counters, '[]=', $a), $a[$a.length - 1]); + } if (!$truthy(locked)) { + self.attributes['$[]='](name, next_val); + } return next_val; + }, -2); + $def(self, '$increment_and_store_counter', function $$increment_and_store_counter(counter_name, block) { + var self = this; + + return $$('AttributeEntry').$new(counter_name, self.$counter(counter_name)).$save_to(block.$attributes()).$value() + }); + $alias(self, "counter_increment", "increment_and_store_counter"); - if (flags == null) { - flags = "r"; - }; - self.binary_flag = flags['$include?']("b"); - flags = flags.$delete("b"); - encoding_option_rx = /:(.*)/; - if ($truthy(encoding_option_rx['$match?'](flags))) { - - handle_unsupported_feature("Encoding option (:encoding) is unsupported by Node.js openSync method and will be removed."); - flags = flags.$sub(encoding_option_rx, "");}; - self.path = path; - self.flags = flags; - return (self.fd = executeIOAction(function(){return __fs__.openSync(path, flags)})); - }, $File_initialize$15.$$arity = -2); - self.$attr_reader("path"); - - Opal.def(self, '$read', $File_read$16 = function $$read() { - var self = this, res = nil; + $def(self, '$register', function $$register(type, value) { + var self = this, id = nil, $logical_op_recvr_tmp_1 = nil, ref = nil; - if ($truthy(self.eof)) { - return "" - } else { - if ($truthy(self.binary_flag)) { - - - var buf = executeIOAction(function(){return __fs__.readFileSync(self.path)}) - var content - if (is_utf8(buf)) { - content = buf.toString('utf8') - } else { - // coerce to utf8 - content = __utf8TextDecoder__.decode(__textEncoder__.encode(buf.toString('binary'))) - } - ; - res = content; + switch (type) { + case "ids": + return self.$register("refs", [(id = value['$[]'](0)), $$('Inline').$new(self, "anchor", value['$[]'](1), $hash2(["type", "id"], {"type": "ref", "id": id}))]) + case "refs": + + + $logical_op_recvr_tmp_1 = self.catalog['$[]']("refs"); + if ($truthy(($logical_op_recvr_tmp_1['$[]'](value['$[]'](0))))) ; else { + $logical_op_recvr_tmp_1['$[]='](value['$[]'](0), (ref = value['$[]'](1))); + } return ref; + case "footnotes": + return self.catalog['$[]'](type)['$<<'](value) + default: + if ($truthy(self.options['$[]']("catalog_assets"))) { + return self.catalog['$[]'](type)['$<<'](($eqeq(type, "images") ? ($$('ImageReference').$new(value, self.attributes['$[]']("imagesdir"))) : (value))) + } else { + return nil + } + } + }); + + $def(self, '$resolve_id', function $$resolve_id(text) { + var self = this, resolved_id = nil, accum = nil; + + if ($truthy(self.reftexts)) { + return self.reftexts['$[]'](text) + } else if ($truthy(self.parsed)) { + return $send((self.reftexts = $hash2([], {})), 'tap', [], function $$7(accum){var self = $$7.$$s == null ? this : $$7.$$s; + if (self.catalog == null) self.catalog = nil; + + + if (accum == null) accum = nil; + return $send(self.catalog['$[]']("refs"), 'each', [], function $$8(id, ref){var $a, $ret_or_1 = nil; + + + if (id == null) id = nil; + if (ref == null) ref = nil; + if ($truthy(($ret_or_1 = accum['$[]'](ref.$xreftext())))) { + return $ret_or_1 + } else { + return ($a = [ref.$xreftext(), id], $send(accum, '[]=', $a), $a[$a.length - 1]) + }});}, {$$s: self})['$[]'](text) } else { - res = executeIOAction(function(){return __fs__.readFileSync(self.path).toString('utf8')}) - }; - self.eof = true; - self.lineno = res.$size(); - return res; - } - }, $File_read$16.$$arity = 0); - - Opal.def(self, '$readlines', $File_readlines$17 = function $$readlines(separator) { - var self = this; - if ($gvars["/"] == null) $gvars["/"] = nil; + + resolved_id = nil; + self.reftexts = (accum = $hash2([], {})); + (function(){try { var $t_break = $thrower('break'); return $send(self.catalog['$[]']("refs"), 'each', [], function $$9(id, ref){var $a, xreftext = nil, $ret_or_1 = nil; + + if (id == null) id = nil; + if (ref == null) ref = nil; + if ($eqeq((xreftext = ref.$xreftext()), text)) { + + resolved_id = id; + $t_break.$throw(); + }; + if ($truthy(($ret_or_1 = accum['$[]'](xreftext)))) { + return $ret_or_1 + } else { + return ($a = [xreftext, id], $send(accum, '[]=', $a), $a[$a.length - 1]) + };})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + self.reftexts = nil; + return resolved_id; + } + }); - - if (separator == null) { - separator = $gvars["/"]; - }; - return self.$each_line(separator).$to_a(); - }, $File_readlines$17.$$arity = -1); - - Opal.def(self, '$each_line', $File_each_line$18 = function $$each_line(separator) { - var $iter = $File_each_line$18.$$p, block = $iter || nil, self = this, lines = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; + $def(self, '$sections?', function $Document_sections$ques$10() { + var self = this; - if ($iter) $File_each_line$18.$$p = null; - - - if ($iter) $File_each_line$18.$$p = null;; + return $rb_gt(self.next_section_index, 0) + }); - if (separator == null) { - separator = $gvars["/"]; - }; - if ($truthy(self.eof)) { - return (function() {if ((block !== nil)) { - return self + $def(self, '$footnotes?', function $Document_footnotes$ques$11() { + var self = this; + + if ($truthy(self.catalog['$[]']("footnotes")['$empty?']())) { + return false } else { - return [].$to_enum() - }; return nil; })()}; - if ((block !== nil)) { - - lines = $$($nesting, 'File').$read(self.path); - - self.eof = false; - self.lineno = 0; - var chomped = lines.$chomp(), - trailing = lines.length != chomped.length, - splitted = chomped.split(separator); - for (var i = 0, length = splitted.length; i < length; i++) { - self.lineno += 1; - if (i < length - 1 || trailing) { - Opal.yield1(block, splitted[i] + separator); - } - else { - Opal.yield1(block, splitted[i]); - } + return true } - self.eof = true; - ; - return self; - } else { - return self.$read().$each_line(separator) - }; - }, $File_each_line$18.$$arity = -1); - - Opal.def(self, '$write', $File_write$19 = function $$write(string) { - var self = this; - - return executeIOAction(function(){return __fs__.writeSync(self.fd, string)}) - }, $File_write$19.$$arity = 1); - - Opal.def(self, '$flush', $File_flush$20 = function $$flush() { - var self = this; - - return executeIOAction(function(){return __fs__.fsyncSync(self.fd)}) - }, $File_flush$20.$$arity = 0); - - Opal.def(self, '$close', $File_close$21 = function $$close() { - var self = this; + }); + + $def(self, '$footnotes', function $$footnotes() { + var self = this; - return executeIOAction(function(){return __fs__.closeSync(self.fd)}) - }, $File_close$21.$$arity = 0); - return (Opal.def(self, '$mtime', $File_mtime$22 = function $$mtime() { - var self = this; + return self.catalog['$[]']("footnotes") + }); + + $def(self, '$callouts', function $$callouts() { + var self = this; - return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) - }, $File_mtime$22.$$arity = 0), nil) && 'mtime'; - })($nesting[0], $$($nesting, 'IO'), $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Stat'); + return self.catalog['$[]']("callouts") + }); + + $def(self, '$nested?', function $Document_nested$ques$12() { + var self = this; - var $nesting = [self].concat($parent_nesting), $Stat_initialize$23, $Stat_file$ques$24, $Stat_mtime$25; - if (self.__fs__ == null) self.__fs__ = nil; + if ($truthy(self.parent_document)) { + return true + } else { + return false + } + }); + + $def(self, '$embedded?', function $Document_embedded$ques$13() { + var self = this; - self.$$prototype.path = nil; - - self.__fs__ = __nccwpck_require__(7147); - var __fs__ = self.__fs__; - - Opal.def(self, '$initialize', $Stat_initialize$23 = function $$initialize(path) { - var self = this; + return self.attributes['$key?']("embedded") + }); + + $def(self, '$extensions?', function $Document_extensions$ques$14() { + var self = this; - return (self.path = path) - }, $Stat_initialize$23.$$arity = 1); - - Opal.def(self, '$file?', $Stat_file$ques$24 = function() { - var self = this; + if ($truthy(self.extensions)) { + return true + } else { + return false + } + }); + + $def(self, '$source', function $$source() { + var self = this; - return executeIOAction(function(){return __fs__.statSync(self.path).isFile()}) - }, $Stat_file$ques$24.$$arity = 0); - return (Opal.def(self, '$mtime', $Stat_mtime$25 = function $$mtime() { - var self = this; + if ($truthy(self.reader)) { + return self.reader.$source() + } else { + return nil + } + }); + + $def(self, '$source_lines', function $$source_lines() { + var self = this; - return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) - }, $Stat_mtime$25.$$arity = 0), nil) && 'mtime'; - })($$($nesting, 'File'), null, $nesting); -}; + if ($truthy(self.reader)) { + return self.reader.$source_lines() + } else { + return nil + } + }); + + $def(self, '$basebackend?', function $Document_basebackend$ques$15(base) { + var self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/dir"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send; + return self.attributes['$[]']("basebackend")['$=='](base) + }); + + $def(self, '$title', function $$title() { + var self = this; - Opal.add_stubs(['$respond_to?', '$flat_map', '$to_path', '$coerce_to!']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Dir'); + return self.$doctitle() + }); + + $def(self, '$title=', function $Document_title$eq$16(title) { + var $a, self = this, sect = nil; - var $nesting = [self].concat($parent_nesting); - if (self.__glob__ == null) self.__glob__ = nil; - if (self.__fs__ == null) self.__fs__ = nil; - if (self.__path__ == null) self.__path__ = nil; - if (self.__os__ == null) self.__os__ = nil; + + if (!$truthy((sect = self.header))) { + (sect = (self.header = $$('Section').$new(self, 0)))['$sectname=']("header"); + } return ($a = [title], $send(sect, 'title=', $a), $a[$a.length - 1]); + }); + + $def(self, '$doctitle', function $$doctitle(opts) { + var self = this, val = nil, sect = nil, $ret_or_1 = nil, separator = nil; - - self.__glob__ = __nccwpck_require__(1957); - self.__fs__ = __nccwpck_require__(7147); - self.__path__ = __nccwpck_require__(1017); - self.__os__ = __nccwpck_require__(2037); - var __glob__ = self.__glob__; - var __fs__ = self.__fs__; - var __path__ = self.__path__; - var __os__ = self.__os__; - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $$$1, $pwd$2, $home$3, $chdir$4, $mkdir$5, $entries$6, $glob$7; + + if (opts == null) opts = $hash2([], {}); + if (!$truthy((val = self.attributes['$[]']("title")))) { + if ($truthy((sect = self.$first_section()))) { + val = sect.$title(); + } else if ($not(($truthy(($ret_or_1 = opts['$[]']("use_fallback"))) ? ((val = self.attributes['$[]']("untitled-label"))) : ($ret_or_1)))) { + return nil + } + } if ($truthy((separator = opts['$[]']("partition")))) { + return $$('Title').$new(val, opts.$merge($hash2(["separator"], {"separator": ($eqeq(separator, true) ? (self.attributes['$[]']("title-separator")) : (separator))}))) + } else if (($truthy(opts['$[]']("sanitize")) && ($truthy(val['$include?']("<"))))) { + return val.$gsub($$('XmlSanitizeRx'), "").$squeeze(" ").$strip() + } else { + return val + } }, -1); + $alias(self, "name", "doctitle"); + + $def(self, '$xreftext', function $$xreftext(xrefstyle) { + var self = this, val = nil; + if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) { + return val + } else { + return self.$title() + } }, -1); + + $def(self, '$author', function $$author() { + var self = this; + return self.attributes['$[]']("author") + }); + $def(self, '$authors', function $$authors() { + var self = this, attrs = nil, authors = nil, num_authors = nil, $ret_or_1 = nil, idx = nil; + + if ($truthy((attrs = self.attributes)['$key?']("author"))) { + + authors = [$$('Author').$new(attrs['$[]']("author"), attrs['$[]']("firstname"), attrs['$[]']("middlename"), attrs['$[]']("lastname"), attrs['$[]']("authorinitials"), attrs['$[]']("email"))]; + if ($truthy($rb_gt((num_authors = ($truthy(($ret_or_1 = attrs['$[]']("authorcount"))) ? ($ret_or_1) : (0))), 1))) { + + idx = 1; + while ($truthy($rb_lt(idx, num_authors))) { + + idx = $rb_plus(idx, 1); + authors['$<<']($$('Author').$new(attrs['$[]']("author_" + (idx)), attrs['$[]']("firstname_" + (idx)), attrs['$[]']("middlename_" + (idx)), attrs['$[]']("lastname_" + (idx)), attrs['$[]']("authorinitials_" + (idx)), attrs['$[]']("email_" + (idx)))); + } } return authors; + } else { + return [] + } + }); - Opal.def(self, '$[]', $$$1 = function(glob) { + $def(self, '$revdate', function $$revdate() { var self = this; - return __glob__.sync(glob) - }, $$$1.$$arity = 1); + return self.attributes['$[]']("revdate") + }); - Opal.def(self, '$pwd', $pwd$2 = function $$pwd() { + $def(self, '$notitle', function $$notitle() { var self = this; - return process.cwd().split(__path__.sep).join(__path__.posix.sep); - }, $pwd$2.$$arity = 0); + return self.attributes['$key?']("notitle") + }); - Opal.def(self, '$home', $home$3 = function $$home() { + $def(self, '$noheader', function $$noheader() { var self = this; - return __os__.homedir(); - }, $home$3.$$arity = 0); + return self.attributes['$key?']("noheader") + }); - Opal.def(self, '$chdir', $chdir$4 = function $$chdir(path) { + $def(self, '$nofooter', function $$nofooter() { var self = this; - return process.chdir(path) - }, $chdir$4.$$arity = 1); + return self.attributes['$key?']("nofooter") + }); + + $def(self, '$first_section', function $$first_section() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.header))) { + return $ret_or_1 + } else { + return $send(self.blocks, 'find', [], function $$17(e){ + + if (e == null) e = nil; + return e.$context()['$==']("section");}) + } + }); - Opal.def(self, '$mkdir', $mkdir$5 = function $$mkdir(path) { + $def(self, '$header?', function $Document_header$ques$18() { var self = this; - return __fs__.mkdirSync(path) - }, $mkdir$5.$$arity = 1); + if ($truthy(self.header)) { + return true + } else { + return false + } + }); + $alias(self, "has_header?", "header?"); - Opal.def(self, '$entries', $entries$6 = function $$entries(dirname) { + $def(self, '$<<', function $Document_$lt$lt$19(block) { + var $yield = $Document_$lt$lt$19.$$p || nil, self = this; + + $Document_$lt$lt$19.$$p = null; + + if ($eqeq(block.$context(), "section")) { + self.$assign_numeral(block); + } return $send2(self, $find_super(self, '<<', $Document_$lt$lt$19, false, true), '<<', [block], $yield); + }); + + $def(self, '$finalize_header', function $$finalize_header(unrooted_attributes, header_valid) { var self = this; - var result = []; - var entries = __fs__.readdirSync(dirname); - for (var i = 0, ii = entries.length; i < ii; i++) { - result.push(entries[i]); + if (header_valid == null) header_valid = true; + self.$clear_playback_attributes(unrooted_attributes); + self.$save_attributes(); + if (!$truthy(header_valid)) { + unrooted_attributes['$[]=']("invalid-header", true); + } return unrooted_attributes; + }, -2); + + $def(self, '$playback_attributes', function $$playback_attributes(block_attributes) { + var self = this; + + if ($truthy(block_attributes['$key?']("attribute_entries"))) { + return $send(block_attributes['$[]']("attribute_entries"), 'each', [], function $$20(entry){var self = $$20.$$s == null ? this : $$20.$$s, name = nil; + if (self.attributes == null) self.attributes = nil; + + + if (entry == null) entry = nil; + name = entry.$name(); + if ($truthy(entry.$negate())) { + + self.attributes.$delete(name); + if ($eqeq(name, "compat-mode")) { + return (self.compat_mode = false) + } else { + return nil + } } else { + + self.attributes['$[]='](name, entry.$value()); + if ($eqeq(name, "compat-mode")) { + return (self.compat_mode = true) + } else { + return nil + } }}, {$$s: self}) + } else { + return nil } - return result; + }); - }, $entries$6.$$arity = 1); + $def(self, '$restore_attributes', function $$restore_attributes() { + var self = this; + + + if (!$truthy(self.parent_document)) { + self.catalog['$[]']("callouts").$rewind(); + } return self.attributes.$replace(self.header_attributes); + }); - Opal.def(self, '$glob', $glob$7 = function $$glob(pattern) { - var $$8, self = this; + $def(self, '$set_attribute', function $$set_attribute(name, value) { + var self = this, $ret_or_2 = nil; - if ($truthy(pattern['$respond_to?']("each"))) { + if (value == null) value = ""; + if ($truthy(self['$attribute_locked?'](name))) { + return nil } else { - pattern = [pattern] - }; - return $send(pattern, 'flat_map', [], ($$8 = function(subpattern){var self = $$8.$$s || this; + + if (!$truthy(value['$empty?']())) { + value = self.$apply_attribute_value_subs(value); + } if ($truthy(self.header_attributes)) { + self.attributes['$[]='](name, value); + } else { + + + switch (name) { + case "backend": + self.$update_backend_attributes(value, ($truthy(($ret_or_2 = self.attributes_modified['$delete?']("htmlsyntax"))) ? (value['$=='](self.backend)) : ($ret_or_2))); + break; + case "doctype": + self.$update_doctype_attributes(value); + break; + default: + self.attributes['$[]='](name, value); + } self.attributes_modified['$<<'](name); + } return value; + } }, -2); + + $def(self, '$delete_attribute', function $$delete_attribute(name) { + var self = this; - + if ($truthy(self['$attribute_locked?'](name))) { + return false + } else { - if (subpattern == null) { - subpattern = nil; - }; - if ($truthy(subpattern['$respond_to?']("to_path"))) { - subpattern = subpattern.$to_path()}; - subpattern = $$($nesting, 'Opal')['$coerce_to!'](subpattern, $$($nesting, 'String'), "to_str"); - return __glob__.sync(subpattern);;}, $$8.$$s = self, $$8.$$arity = 1, $$8)); - }, $glob$7.$$arity = 1); - return Opal.alias(self, "getwd", "pwd"); - })(Opal.get_singleton_class(self), $nesting); - })($nesting[0], null, $nesting) -}; + self.attributes.$delete(name); + self.attributes_modified['$<<'](name); + return true; + } + }); + + $def(self, '$attribute_locked?', function $Document_attribute_locked$ques$21(name) { + var self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/io"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var $$5, $$6, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $lambda = Opal.lambda, $send = Opal.send, $writer = nil; + return self.attribute_overrides['$key?'](name) + }); + + $def(self, '$set_header_attribute', function $$set_header_attribute(name, value, overwrite) { + var self = this, attrs = nil, $ret_or_1 = nil; - Opal.add_stubs(['$attr_reader', '$write', '$read', '$write_proc=', '$-', '$tty=']); - - - function executeIOAction(action) { - try { - return action(); - } catch (error) { - if (error.code === 'EACCES' || - error.code === 'EISDIR' || - error.code === 'EMFILE' || - error.code === 'ENOENT' || - error.code === 'EPERM') { - throw Opal.IOError.$new(error.message) - } - throw error; - } - } -; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IO'); + + if (value == null) value = ""; + if (overwrite == null) overwrite = true; + attrs = ($truthy(($ret_or_1 = self.header_attributes)) ? ($ret_or_1) : (self.attributes)); + if (($eqeq(overwrite, false) && ($truthy(attrs['$key?'](name))))) { + return false + } else { + + attrs['$[]='](name, value); + return true; + } }, -2); + + $def(self, '$convert', function $$convert(opts) { + var $a, self = this, block = nil, $ret_or_1 = nil, output = nil, transform = nil, exts = nil; - var $nesting = [self].concat($parent_nesting), $IO_initialize$1, $IO_write$2, $IO_read$3, $IO_binread$4; - if (self.__fs__ == null) self.__fs__ = nil; + + if (opts == null) opts = $hash2([], {}); + if ($truthy(self.timings)) { + self.timings.$start("convert"); + } if (!$truthy(self.parsed)) { + self.$parse(); + } if (!($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SERVER'))) || ($truthy(opts['$empty?']())))) { + + if (!$truthy(($a = ["outfile", opts['$[]']("outfile")], $send(self.attributes, '[]=', $a), $a[$a.length - 1]))) { + self.attributes.$delete("outfile"); + } if (!$truthy(($a = ["outdir", opts['$[]']("outdir")], $send(self.attributes, '[]=', $a), $a[$a.length - 1]))) { + self.attributes.$delete("outdir"); + } } if ($eqeq(self.$doctype(), "inline")) { + if ($truthy((block = ($truthy(($ret_or_1 = self.blocks['$[]'](0))) ? ($ret_or_1) : (self.header))))) { + if (($eqeq(block.$content_model(), "compound") || ($eqeq(block.$content_model(), "empty")))) { + self.$logger().$warn("no inline candidate; use the inline doctype to convert a single paragragh, verbatim, or raw block"); + } else { + output = block.$content(); + } + } + } else { + + if ($truthy(opts['$key?']("standalone"))) { + transform = ($truthy(opts['$[]']("standalone")) ? ("document") : ("embedded")); + } else if ($truthy(opts['$key?']("header_footer"))) { + transform = ($truthy(opts['$[]']("header_footer")) ? ("document") : ("embedded")); + } else { + transform = ($truthy(self.options['$[]']("standalone")) ? ("document") : ("embedded")); + } output = self.converter.$convert(self, transform); + } if (!$truthy(self.parent_document)) { + if (($truthy((exts = self.extensions)) && ($truthy(exts['$postprocessors?']())))) { + $send(exts.$postprocessors(), 'each', [], function $$22(ext){var self = $$22.$$s == null ? this : $$22.$$s; - - self.__fs__ = __nccwpck_require__(7147); - var __fs__ = self.__fs__; - self.$attr_reader("eof"); - self.$attr_reader("lineno"); - - Opal.def(self, '$initialize', $IO_initialize$1 = function $$initialize() { - var self = this; + + if (ext == null) ext = nil; + return (output = ext.$process_method()['$[]'](self, output));}, {$$s: self}); + } + } if ($truthy(self.timings)) { + self.timings.$record("convert"); + } return output; + }, -1); + $alias(self, "render", "convert"); + + $def(self, '$write', function $$write(output, target) { + var self = this; + + if ($truthy(self.timings)) { + self.timings.$start("write"); + } if ($eqeqeq($$('Writer'), self.converter)) { + self.converter.$write(output, target); + } else { + + if ($truthy(target['$respond_to?']("write"))) { + if (!$truthy(output['$nil_or_empty?']())) { + + target.$write(output.$chomp()); + target.$write($$('LF')); + } + } else { + $$$('File').$write(target, output, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + } if ((($eqeq(self.backend, "manpage") && ($eqeqeq($$$('String'), target))) && ($truthy(self.converter.$class()['$respond_to?']("write_alternate_pages"))))) { + self.converter.$class().$write_alternate_pages(self.attributes['$[]']("mannames"), self.attributes['$[]']("manvolnum"), target); + } } if ($truthy(self.timings)) { + self.timings.$record("write"); + } return nil; + }); - self.eof = false; - return (self.lineno = 0); - }, $IO_initialize$1.$$arity = 0); - Opal.defs(self, '$write', $IO_write$2 = function $$write(path, data) { - var self = this; + $def(self, '$content', function $$content() { + var $yield = $$content.$$p || nil, self = this; - return $$($nesting, 'File').$write(path, data) - }, $IO_write$2.$$arity = 2); - Opal.defs(self, '$read', $IO_read$3 = function $$read(path) { - var self = this; + $$content.$$p = null; + + self.attributes.$delete("title"); + return $send2(self, $find_super(self, 'content', $$content, false, true), 'content', [], $yield); + }); + + $def(self, '$docinfo', function $$docinfo(location, suffix) { + var $a, self = this, qualifier = nil, $ret_or_1 = nil, docinfo = nil, content = nil, docinfo_file = nil, docinfo_dir = nil, docinfo_subs = nil, docinfo_path = nil, shared_docinfo = nil, private_docinfo = nil; - return $$($nesting, 'File').$read(path) - }, $IO_read$3.$$arity = 1); - return (Opal.defs(self, '$binread', $IO_binread$4 = function $$binread(path) { - var self = this; + + if (location == null) location = "head"; + if (suffix == null) suffix = nil; + if ($truthy($rb_lt(self.$safe(), $$$($$('SafeMode'), 'SECURE')))) { + + if (!$eqeq(location, "head")) { + qualifier = "-" + (location); + } suffix = ($truthy(($ret_or_1 = suffix)) ? ($ret_or_1) : (self.outfilesuffix)); + if ($truthy((docinfo = self.attributes['$[]']("docinfo"))['$nil_or_empty?']())) { + if ($truthy(self.attributes['$key?']("docinfo2"))) { + docinfo = ["private", "shared"]; + } else if ($truthy(self.attributes['$key?']("docinfo1"))) { + docinfo = ["shared"]; + } else { + docinfo = ($truthy(docinfo) ? (["private"]) : (nil)); + } + } else { + docinfo = $send(docinfo.$split(","), 'map', [], function $$23(it){ + + if (it == null) it = nil; + return it.$strip();}); + } if ($truthy(docinfo)) { + + content = []; + $a = ["docinfo" + (qualifier) + (suffix), self.attributes['$[]']("docinfodir"), self.$resolve_docinfo_subs()], (docinfo_file = $a[0]), (docinfo_dir = $a[1]), (docinfo_subs = $a[2]); + if (!$truthy(docinfo['$&'](["shared", "shared-" + (location)])['$empty?']())) { + + docinfo_path = self.$normalize_system_path(docinfo_file, docinfo_dir); + if ($truthy((shared_docinfo = self.$read_asset(docinfo_path, $hash2(["normalize"], {"normalize": true}))))) { + content['$<<'](self.$apply_subs(shared_docinfo, docinfo_subs)); + } } if (!($truthy(self.attributes['$[]']("docname")['$nil_or_empty?']()) || ($truthy(docinfo['$&'](["private", "private-" + (location)])['$empty?']())))) { + + docinfo_path = self.$normalize_system_path("" + (self.attributes['$[]']("docname")) + "-" + (docinfo_file), docinfo_dir); + if ($truthy((private_docinfo = self.$read_asset(docinfo_path, $hash2(["normalize"], {"normalize": true}))))) { + content['$<<'](self.$apply_subs(private_docinfo, docinfo_subs)); + } } } } if (($truthy(self.extensions) && ($truthy(self['$docinfo_processors?'](location))))) { + return ($truthy(($ret_or_1 = content)) ? ($ret_or_1) : ([])).$concat($send(self.docinfo_processor_extensions['$[]'](location), 'map', [], function $$24(ext){var self = $$24.$$s == null ? this : $$24.$$s; - return executeIOAction(function(){return __fs__.readFileSync(path).toString('binary')}) - }, $IO_binread$4.$$arity = 1), nil) && 'binread'; - })($nesting[0], null, $nesting); - - $writer = [$lambda(($$5 = function(string){var self = $$5.$$s || this; + + if (ext == null) ext = nil; + return ext.$process_method()['$[]'](self);}, {$$s: self}).$compact()).$join($$('LF')) + } else if ($truthy(content)) { + return content.$join($$('LF')) + } else { + return "" + } }, -1); + + $def(self, '$docinfo_processors?', function $Document_docinfo_processors$ques$25(location) { + var $a, self = this; - - - if (string == null) { - string = nil; - }; - return process.stdout.write(string);;}, $$5.$$s = self, $$5.$$arity = 1, $$5))]; - $send($$($nesting, 'STDOUT'), 'write_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [$lambda(($$6 = function(string){var self = $$6.$$s || this; + + if (location == null) location = "head"; + if ($truthy(self.docinfo_processor_extensions['$key?'](location))) { + return self.docinfo_processor_extensions['$[]'](location)['$!='](false) + } else if (($truthy(self.extensions) && ($truthy(self.document.$extensions()['$docinfo_processors?'](location))))) { + return ($a = [location, self.document.$extensions().$docinfo_processors(location)], $send(self.docinfo_processor_extensions, '[]=', $a), $a[$a.length - 1])['$!']()['$!']() + } else { + return ($a = [location, false], $send(self.docinfo_processor_extensions, '[]=', $a), $a[$a.length - 1]) + } }, -1); + + $def(self, '$to_s', function $$to_s() { + var self = this, $ret_or_1 = nil; - - - if (string == null) { - string = nil; - }; - return process.stderr.write(string);;}, $$6.$$s = self, $$6.$$arity = 1, $$6))]; - $send($$($nesting, 'STDERR'), 'write_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [true]; - $send($$($nesting, 'STDOUT'), 'tty=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [true]; - $send($$($nesting, 'STDERR'), 'tty=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];; -}; + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {doctype: " + (self.$doctype().$inspect()) + ", doctitle: " + (($truthy(($ret_or_1 = self.header)) ? (self.header.$title()) : ($ret_or_1)).$inspect()) + ", blocks: " + (self.blocks.$size()) + "}>" + }); + self.$private(); + + $def(self, '$apply_attribute_value_subs', function $$apply_attribute_value_subs(value) { + var $a, self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/open-uri"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; + + if ($truthy($$('AttributeEntryPassMacroRx')['$=~'](value))) { + + value = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)); + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + value = self.$apply_subs(value, self.$resolve_pass_subs((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))); + } } else { + value = self.$apply_header_subs(value); + } if ($truthy(self.max_attribute_value_size)) { + + return self.$limit_bytesize(value, self.max_attribute_value_size); + } else { + return value + } }); + + $def(self, '$limit_bytesize', function $$limit_bytesize(str, max) { + + + if ($truthy($rb_gt(str.$bytesize(), max))) { + while (!($truthy((str = str.$byteslice(0, max))['$valid_encoding?']()))) { + max = $rb_minus(max, 1); + } + } return str; + }); + + $def(self, '$resolve_docinfo_subs', function $$resolve_docinfo_subs() { + var self = this; - return (function($base, $parent_nesting) { - var self = $module($base, 'OpenURI'); + if ($truthy(self.attributes['$key?']("docinfosubs"))) { + + return self.$resolve_subs(self.attributes['$[]']("docinfosubs"), "block", nil, "docinfo"); + } else { + return ["attributes"] + } + }); + + $def(self, '$create_converter', function $$create_converter(backend, delegate_backend) { + var self = this, converter_opts = nil, template_dirs = nil, $ret_or_1 = nil, opts = nil, converter = nil; - var $nesting = [self].concat($parent_nesting), $OpenURI_request$1, $OpenURI_data$2; - if (self.__xmlhttprequest__ == null) self.__xmlhttprequest__ = nil; + + converter_opts = $hash2(["document", "htmlsyntax"], {"document": self, "htmlsyntax": self.attributes['$[]']("htmlsyntax")}); + if ($truthy((template_dirs = ($truthy(($ret_or_1 = (opts = self.options)['$[]']("template_dirs"))) ? ($ret_or_1) : (opts['$[]']("template_dir")))))) { + + converter_opts['$[]=']("template_dirs", [].concat($to_a(template_dirs))); + converter_opts['$[]=']("template_cache", opts.$fetch("template_cache", true)); + converter_opts['$[]=']("template_engine", opts['$[]']("template_engine")); + converter_opts['$[]=']("template_engine_options", opts['$[]']("template_engine_options")); + converter_opts['$[]=']("eruby", opts['$[]']("eruby")); + converter_opts['$[]=']("safe", self.safe); + if ($truthy(delegate_backend)) { + converter_opts['$[]=']("delegate_backend", delegate_backend); + } } if ($truthy((converter = opts['$[]']("converter")))) { + return $$$($$('Converter'), 'CustomFactory').$new($hash(backend, converter)).$create(backend, converter_opts) + } else { + return opts.$fetch("converter_factory", $$('Converter')).$create(backend, converter_opts) + } }); + + $def(self, '$clear_playback_attributes', function $$clear_playback_attributes(attributes) { + + return attributes.$delete("attribute_entries") + }); + + $def(self, '$save_attributes', function $$save_attributes() { + var self = this, doctitle_val = nil, attrs = nil, $ret_or_1 = nil, toc_val = nil, toc_position_val = nil, toc_placement_val = nil, default_toc_position = nil, default_toc_class = nil, position = nil, icons_val = nil, basebackend = nil, syntax_hl_name = nil, syntax_hl_factory = nil, syntax_hls = nil; - - self.__xmlhttprequest__ = __nccwpck_require__(4315); - var __XMLHttpRequest__ = self.__xmlhttprequest__.XMLHttpRequest; - Opal.defs(self, '$request', $OpenURI_request$1 = function $$request(uri) { - var self = this; + + if (!($truthy((attrs = self.attributes)['$key?']("doctitle")) || ($not((doctitle_val = self.$doctitle()))))) { + attrs['$[]=']("doctitle", doctitle_val); + } self.id = ($truthy(($ret_or_1 = self.id)) ? ($ret_or_1) : (attrs['$[]']("css-signature"))); + if ($truthy((toc_val = ($truthy(attrs.$delete("toc2")) ? ("left") : (attrs['$[]']("toc")))))) { + + toc_position_val = (($truthy((toc_placement_val = attrs.$fetch("toc-placement", "macro"))) && ($neqeq(toc_placement_val, "auto"))) ? (toc_placement_val) : (attrs['$[]']("toc-position"))); + if (!($truthy(toc_val['$empty?']()) && ($truthy(toc_position_val['$nil_or_empty?']())))) { + + default_toc_position = "left"; + default_toc_class = "toc2"; + position = ($truthy(toc_position_val['$nil_or_empty?']()) ? (($truthy(toc_val['$empty?']()) ? (default_toc_position) : (toc_val))) : (toc_position_val)); + attrs['$[]=']("toc", ""); + attrs['$[]=']("toc-placement", "auto"); + + switch (position) { + case "left": + case "<": + case "<": + attrs['$[]=']("toc-position", "left"); + break; + case "right": + case ">": + case ">": + attrs['$[]=']("toc-position", "right"); + break; + case "top": + case "^": + attrs['$[]=']("toc-position", "top"); + break; + case "bottom": + case "v": + attrs['$[]=']("toc-position", "bottom"); + break; + case "preamble": + case "macro": + + attrs['$[]=']("toc-position", "content"); + attrs['$[]=']("toc-placement", position); + default_toc_class = nil; + break; + default: + + attrs.$delete("toc-position"); + default_toc_class = nil; + } if ($truthy(default_toc_class)) { + if ($truthy(($ret_or_1 = attrs['$[]']("toc-class")))) ; else { + attrs['$[]=']("toc-class", default_toc_class); + } + } } } if (($truthy((icons_val = attrs['$[]']("icons"))) && ($not(attrs['$key?']("icontype"))))) { + + switch (icons_val) { + case "": + case "font": + + break; + default: + + attrs['$[]=']("icons", ""); + if (!$eqeq(icons_val, "image")) { + attrs['$[]=']("icontype", icons_val); + } } + } if (($truthy((self.compat_mode = attrs['$key?']("compat-mode"))) && ($truthy(attrs['$key?']("language"))))) { + attrs['$[]=']("source-language", attrs['$[]']("language")); + } if (!$truthy(self.parent_document)) { + + if ($eqeq((basebackend = attrs['$[]']("basebackend")), "html")) { + if (($truthy((syntax_hl_name = attrs['$[]']("source-highlighter"))) && ($not(attrs['$[]']("" + (syntax_hl_name) + "-unavailable"))))) { + if ($truthy((syntax_hl_factory = self.options['$[]']("syntax_highlighter_factory")))) { + self.syntax_highlighter = syntax_hl_factory.$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self})); + } else if ($truthy((syntax_hls = self.options['$[]']("syntax_highlighters")))) { + self.syntax_highlighter = $$$($$('SyntaxHighlighter'), 'DefaultFactoryProxy').$new(syntax_hls).$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self})); + } else { + self.syntax_highlighter = $$('SyntaxHighlighter').$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self})); + } + } + } else if ($eqeq(basebackend, "docbook")) { + + if (!($truthy(self['$attribute_locked?']("toc")) || ($truthy(self.attributes_modified['$include?']("toc"))))) { + attrs['$[]=']("toc", ""); + } if (!($truthy(self['$attribute_locked?']("sectnums")) || ($truthy(self.attributes_modified['$include?']("sectnums"))))) { + attrs['$[]=']("sectnums", ""); + } } self.outfilesuffix = attrs['$[]']("outfilesuffix"); + $send($$('FLEXIBLE_ATTRIBUTES'), 'each', [], function $$26(name){var self = $$26.$$s == null ? this : $$26.$$s; + if (self.attribute_overrides == null) self.attribute_overrides = nil; + + if (name == null) name = nil; + if (($truthy(self.attribute_overrides['$key?'](name)) && ($truthy(self.attribute_overrides['$[]'](name))))) { + return self.attribute_overrides.$delete(name) + } else { + return nil + }}, {$$s: self}); + } return (self.header_attributes = attrs.$merge()); + }); - var xhr = new __XMLHttpRequest__(); - xhr.open('GET', uri, false); - xhr.responseType = 'arraybuffer'; - xhr.send(); - return xhr; - - }, $OpenURI_request$1.$$arity = 1); - Opal.defs(self, '$data', $OpenURI_data$2 = function $$data(req) { - var self = this; + $def(self, '$fill_datetime_attributes', function $$fill_datetime_attributes(attrs, input_mtime) { + var $a, self = this, now = nil, source_date_epoch = nil, localdate = nil, $ret_or_1 = nil, localtime = nil, $ret_or_2 = nil, docdate = nil, doctime = nil; + + now = ($truthy($$$('ENV')['$key?']("SOURCE_DATE_EPOCH")) ? ((source_date_epoch = $$$('Time').$at(self.$Integer($$$('ENV')['$[]']("SOURCE_DATE_EPOCH"))).$utc())) : ($$$('Time').$now())); + if ($truthy((localdate = attrs['$[]']("localdate")))) { + if ($truthy(($ret_or_1 = attrs['$[]']("localyear")))) ; else { + attrs['$[]=']("localyear", ($eqeq(localdate.$index("-"), 4) ? (localdate.$slice(0, 4)) : (nil))); + } + } else { + + localdate = ($a = ["localdate", now.$strftime("%F")], $send(attrs, '[]=', $a), $a[$a.length - 1]); + if ($truthy(($ret_or_1 = attrs['$[]']("localyear")))) ; else { + attrs['$[]=']("localyear", now.$year().$to_s()); + } } localtime = ($truthy(($ret_or_1 = attrs['$[]']("localtime"))) ? ($ret_or_1) : (($a = ["localtime", now.$strftime("%T " + (($eqeq(now.$utc_offset(), 0) ? ("UTC") : ("%z"))))], $send(attrs, '[]=', $a), $a[$a.length - 1]))); + if ($truthy(($ret_or_1 = attrs['$[]']("localdatetime")))) ; else { + attrs['$[]=']("localdatetime", "" + (localdate) + " " + (localtime)); + } input_mtime = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = source_date_epoch)) ? ($ret_or_2) : (input_mtime)))) ? ($ret_or_1) : (now)); + if ($truthy((docdate = attrs['$[]']("docdate")))) { + if ($truthy(($ret_or_1 = attrs['$[]']("docyear")))) ; else { + attrs['$[]=']("docyear", ($eqeq(docdate.$index("-"), 4) ? (docdate.$slice(0, 4)) : (nil))); + } + } else { + + docdate = ($a = ["docdate", input_mtime.$strftime("%F")], $send(attrs, '[]=', $a), $a[$a.length - 1]); + if ($truthy(($ret_or_1 = attrs['$[]']("docyear")))) ; else { + attrs['$[]=']("docyear", input_mtime.$year().$to_s()); + } } doctime = ($truthy(($ret_or_1 = attrs['$[]']("doctime"))) ? ($ret_or_1) : (($a = ["doctime", input_mtime.$strftime("%T " + (($eqeq(input_mtime.$utc_offset(), 0) ? ("UTC") : ("%z"))))], $send(attrs, '[]=', $a), $a[$a.length - 1]))); + if ($truthy(($ret_or_1 = attrs['$[]']("docdatetime")))) ; else { + attrs['$[]=']("docdatetime", "" + (docdate) + " " + (doctime)); + } return nil; + }); - var arrayBuffer = req.response; - var byteArray = new Uint8Array(arrayBuffer); - var result = [] - for (var i = 0; i < byteArray.byteLength; i++) { - result.push(byteArray[i]); - } - return result; - - }, $OpenURI_data$2.$$arity = 1); + $def(self, '$update_backend_attributes', function $$update_backend_attributes(new_backend, init) { + var $a, $b, self = this, current_backend = nil, current_basebackend = nil, attrs = nil, current_doctype = nil, actual_backend = nil, $ret_or_1 = nil, delegate_backend = nil, converter = nil, new_basebackend = nil, new_filetype = nil, htmlsyntax = nil, backend_traits = nil, current_filetype = nil, page_width = nil; + + + if (init == null) init = nil; + if (($truthy(init) || ($neqeq(new_backend, self.backend)))) { + + current_backend = self.backend; + current_basebackend = (attrs = self.attributes)['$[]']("basebackend"); + current_doctype = self.doctype; + if ($truthy(new_backend['$include?'](":"))) { + $b = new_backend.$partition(":"), $a = $to_ary($b), (actual_backend = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (new_backend = ($a[2] == null ? nil : $a[2])); + } if ($truthy(new_backend['$start_with?']("xhtml"))) { + + attrs['$[]=']("htmlsyntax", "xml"); + new_backend = new_backend.$slice(1, new_backend.$length()); + } else if ($truthy(new_backend['$start_with?']("html"))) { + if ($truthy(($ret_or_1 = attrs['$[]']("htmlsyntax")))) ; else { + attrs['$[]=']("htmlsyntax", "html"); + } + } new_backend = ($truthy(($ret_or_1 = $$('BACKEND_ALIASES')['$[]'](new_backend))) ? ($ret_or_1) : (new_backend)); + if ($truthy(actual_backend)) { + $a = [actual_backend, new_backend], (new_backend = $a[0]), (delegate_backend = $a[1]); + } if ($truthy(current_doctype)) { + + if ($truthy(current_backend)) { + + attrs.$delete("backend-" + (current_backend)); + attrs.$delete("backend-" + (current_backend) + "-doctype-" + (current_doctype)); + } attrs['$[]=']("backend-" + (new_backend) + "-doctype-" + (current_doctype), ""); + attrs['$[]=']("doctype-" + (current_doctype), ""); + } else if ($truthy(current_backend)) { + attrs.$delete("backend-" + (current_backend)); + } attrs['$[]=']("backend-" + (new_backend), ""); + self.backend = ($a = ["backend", new_backend], $send(attrs, '[]=', $a), $a[$a.length - 1]); + if ($eqeqeq($$$($$('Converter'), 'BackendTraits'), (converter = self.$create_converter(new_backend, delegate_backend)))) { + + new_basebackend = converter.$basebackend(); + new_filetype = converter.$filetype(); + if ($truthy((htmlsyntax = converter.$htmlsyntax()))) { + attrs['$[]=']("htmlsyntax", htmlsyntax); + } if ($truthy(init)) { + if ($truthy(($ret_or_1 = attrs['$[]']("outfilesuffix")))) ; else { + attrs['$[]=']("outfilesuffix", converter.$outfilesuffix()); + } + } else if (!$truthy(self['$attribute_locked?']("outfilesuffix"))) { + attrs['$[]=']("outfilesuffix", converter.$outfilesuffix()); + } } else if ($truthy(converter)) { + + backend_traits = $$('Converter').$derive_backend_traits(new_backend); + new_basebackend = backend_traits['$[]']("basebackend"); + new_filetype = backend_traits['$[]']("filetype"); + if ($truthy(init)) { + if ($truthy(($ret_or_1 = attrs['$[]']("outfilesuffix")))) ; else { + attrs['$[]=']("outfilesuffix", backend_traits['$[]']("outfilesuffix")); + } + } else if (!$truthy(self['$attribute_locked?']("outfilesuffix"))) { + attrs['$[]=']("outfilesuffix", backend_traits['$[]']("outfilesuffix")); + } } else { + self.$raise($$$('NotImplementedError'), "asciidoctor: FAILED: missing converter for backend '" + (new_backend) + "'. Processing aborted."); + } self.converter = converter; + if ($truthy((current_filetype = attrs['$[]']("filetype")))) { + attrs.$delete("filetype-" + (current_filetype)); + } attrs['$[]=']("filetype", new_filetype); + attrs['$[]=']("filetype-" + (new_filetype), ""); + if ($truthy((page_width = $$('DEFAULT_PAGE_WIDTHS')['$[]'](new_basebackend)))) { + attrs['$[]=']("pagewidth", page_width); + } else { + attrs.$delete("pagewidth"); + } if ($neqeq(new_basebackend, current_basebackend)) { + + if ($truthy(current_doctype)) { + + if ($truthy(current_basebackend)) { + + attrs.$delete("basebackend-" + (current_basebackend)); + attrs.$delete("basebackend-" + (current_basebackend) + "-doctype-" + (current_doctype)); + } attrs['$[]=']("basebackend-" + (new_basebackend) + "-doctype-" + (current_doctype), ""); + } else if ($truthy(current_basebackend)) { + attrs.$delete("basebackend-" + (current_basebackend)); + } attrs['$[]=']("basebackend-" + (new_basebackend), ""); + attrs['$[]=']("basebackend", new_basebackend); + } return new_backend; + } else { + return nil + } }, -2); + return $def(self, '$update_doctype_attributes', function $$update_doctype_attributes(new_doctype) { + var $a, self = this, attrs = nil, current_backend = nil, current_basebackend = nil, current_doctype = nil; + + if (($truthy(new_doctype) && ($neqeq(new_doctype, self.doctype)))) { + + $a = [self.backend, (attrs = self.attributes)['$[]']("basebackend"), self.doctype], (current_backend = $a[0]), (current_basebackend = $a[1]), (current_doctype = $a[2]); + if ($truthy(current_doctype)) { + + attrs.$delete("doctype-" + (current_doctype)); + if ($truthy(current_backend)) { + + attrs.$delete("backend-" + (current_backend) + "-doctype-" + (current_doctype)); + attrs['$[]=']("backend-" + (current_backend) + "-doctype-" + (new_doctype), ""); + } if ($truthy(current_basebackend)) { + + attrs.$delete("basebackend-" + (current_basebackend) + "-doctype-" + (current_doctype)); + attrs['$[]=']("basebackend-" + (current_basebackend) + "-doctype-" + (new_doctype), ""); + } } else { + + if ($truthy(current_backend)) { + attrs['$[]=']("backend-" + (current_backend) + "-doctype-" + (new_doctype), ""); + } if ($truthy(current_basebackend)) { + attrs['$[]=']("basebackend-" + (current_basebackend) + "-doctype-" + (new_doctype), ""); + } } attrs['$[]=']("doctype-" + (new_doctype), ""); + return (self.doctype = ($a = ["doctype", new_doctype], $send(attrs, '[]=', $a), $a[$a.length - 1])); + } else { + return nil + } + }); + })($nesting[0], $$('AbstractBlock'), $nesting) })($nesting[0], $nesting) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/comparable"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy; +Opal.modules["asciidoctor/inline"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $return_val = Opal.return_val, $alias = Opal.alias, $truthy = Opal.truthy, $nesting = [], nil = Opal.nil; - Opal.add_stubs(['$===', '$>', '$<', '$equal?', '$<=>', '$normalize', '$raise', '$class']); + Opal.add_stubs('attr_accessor,attr_reader,[],convert,converter,attr,==,apply_reftext_subs,reftext'); return (function($base, $parent_nesting) { - var self = $module($base, 'Comparable'); + var self = $module($base, 'Asciidoctor'); - var $nesting = [self].concat($parent_nesting), $Comparable_normalize$1, $Comparable_$eq_eq$2, $Comparable_$gt$3, $Comparable_$gt_eq$4, $Comparable_$lt$5, $Comparable_$lt_eq$6, $Comparable_between$ques$7, $Comparable_clamp$8; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - Opal.defs(self, '$normalize', $Comparable_normalize$1 = function $$normalize(what) { - var self = this; + return (function($base, $super) { + var self = $klass($base, $super, 'Inline'); + + var $proto = self.$$prototype; + $proto.text = $proto.type = nil; - if ($truthy($$($nesting, 'Integer')['$==='](what))) { - return what}; - if ($truthy($rb_gt(what, 0))) { - return 1}; - if ($truthy($rb_lt(what, 0))) { - return -1}; - return 0; - }, $Comparable_normalize$1.$$arity = 1); - - Opal.def(self, '$==', $Comparable_$eq_eq$2 = function(other) { - var self = this, cmp = nil; + self.$attr_accessor("text"); + self.$attr_reader("type"); + self.$attr_accessor("target"); + + $def(self, '$initialize', function $$initialize(parent, context, text, opts) { + $$initialize.$$p || nil; var self = this; - try { + $$initialize.$$p = null; - if ($truthy(self['$equal?'](other))) { - return true}; - - if (self["$<=>"] == Opal.Kernel["$<=>"]) { - return false; - } + if (text == null) text = nil; + if (opts == null) opts = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], null); + self.node_name = "inline_" + (context); + self.text = text; + self.id = opts['$[]']("id"); + self.type = opts['$[]']("type"); + return (self.target = opts['$[]']("target")); + }, -3); + + $def(self, '$block?', $return_val(false)); + + $def(self, '$inline?', $return_val(true)); + + $def(self, '$convert', function $$convert() { + var self = this; - // check for infinite recursion - if (self.$$comparable) { - delete self.$$comparable; - return false; - } - ; - if ($truthy((cmp = self['$<=>'](other)))) { + return self.$converter().$convert(self) + }); + $alias(self, "render", "convert"); + + $def(self, '$alt', function $$alt() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.$attr("alt")))) { + return $ret_or_1 } else { - return false - }; - return $$($nesting, 'Comparable').$normalize(cmp) == 0; - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'StandardError')])) { - try { - return false - } finally { Opal.pop_exception() } - } else { throw $err; } - } - }, $Comparable_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$>', $Comparable_$gt$3 = function(other) { - var self = this, cmp = nil; + return "" + } + }); + + $def(self, '$reftext?', function $Inline_reftext$ques$1() { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; + if ($truthy(($ret_or_1 = self.text))) { + + if ($truthy(($ret_or_2 = self.type['$==']("ref")))) { + return $ret_or_2 + } else { + return self.type['$==']("bibref") + } } else { + return $ret_or_1 + } + }); - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) > 0; - }, $Comparable_$gt$3.$$arity = 1); - - Opal.def(self, '$>=', $Comparable_$gt_eq$4 = function(other) { - var self = this, cmp = nil; + $def(self, '$reftext', function $$reftext() { + var self = this, val = nil; + + if ($truthy((val = self.text))) { + + return self.$apply_reftext_subs(val); + } else { + return nil + } + }); + return $def(self, '$xreftext', function $$xreftext(xrefstyle) { + var self = this; + return self.$reftext(); + }, -1); + })($nesting[0], $$('AbstractNode')) + })($nesting[0], $nesting) +}; + +Opal.modules["asciidoctor/list"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $alias = Opal.alias, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil; + + Opal.add_stubs('blocks,blocks?,==,next_list,callouts,convert,class,object_id,inspect,size,items,parent,attr_accessor,level,drop,nil_or_empty?,apply_subs,attr_writer,empty?,===,[],outline?,!,simple?,source,shift,context'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) >= 0; - }, $Comparable_$gt_eq$4.$$arity = 1); - Opal.def(self, '$<', $Comparable_$lt$5 = function(other) { - var self = this, cmp = nil; + (function($base, $super) { + var self = $klass($base, $super, 'List'); - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) < 0; - }, $Comparable_$lt$5.$$arity = 1); - - Opal.def(self, '$<=', $Comparable_$lt_eq$6 = function(other) { - var self = this, cmp = nil; + var $proto = self.$$prototype; + $proto.context = $proto.document = $proto.style = nil; - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) <= 0; - }, $Comparable_$lt_eq$6.$$arity = 1); - - Opal.def(self, '$between?', $Comparable_between$ques$7 = function(min, max) { - var self = this; + $alias(self, "items", "blocks"); + $alias(self, "content", "blocks"); + $alias(self, "items?", "blocks?"); + + $def(self, '$initialize', function $$initialize(parent, context, opts) { + var $yield = $$initialize.$$p || nil, self = this; + $$initialize.$$p = null; + + if (opts == null) opts = $hash2([], {}); + return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield); + }, -3); - if ($rb_lt(self, min)) { - return false}; - if ($rb_gt(self, max)) { - return false}; - return true; - }, $Comparable_between$ques$7.$$arity = 2); - - Opal.def(self, '$clamp', $Comparable_clamp$8 = function $$clamp(min, max) { - var self = this, cmp = nil; + $def(self, '$outline?', function $List_outline$ques$1() { + var self = this, $ret_or_1 = nil; + if ($truthy(($ret_or_1 = self.context['$==']("ulist")))) { + return $ret_or_1 + } else { + return self.context['$==']("olist") + } + }); - cmp = min['$<=>'](max); - if ($truthy(cmp)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (min.$class()) + " with " + (max.$class()) + " failed") - }; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(cmp), 0))) { - self.$raise($$($nesting, 'ArgumentError'), "min argument must be smaller than max argument")}; - if ($truthy($rb_lt($$($nesting, 'Comparable').$normalize(self['$<=>'](min)), 0))) { - return min}; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(self['$<=>'](max)), 0))) { - return max}; - return self; - }, $Comparable_clamp$8.$$arity = 2); - })($nesting[0], $nesting) -}; + $def(self, '$convert', function $$convert() { + var $yield = $$convert.$$p || nil, self = this, result = nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["pathname"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send, $module = Opal.module; + $$convert.$$p = null; + if ($eqeq(self.context, "colist")) { + + result = $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [], $yield); + self.document.$callouts().$next_list(); + return result; + } else { + return $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [], $yield) + } + }); + $alias(self, "render", "convert"); + return $def(self, '$to_s', function $$to_s() { + var self = this; - Opal.add_stubs(['$require', '$include', '$quote', '$===', '$to_s', '$path', '$respond_to?', '$to_path', '$is_a?', '$nil?', '$raise', '$class', '$==', '$attr_reader', '$!', '$relative?', '$chop_basename', '$basename', '$=~', '$new', '$source', '$[]', '$rindex', '$sub', '$absolute?', '$expand_path', '$plus', '$unshift', '$length', '$!=', '$empty?', '$first', '$shift', '$+', '$join', '$dirname', '$pop', '$reverse_each', '$directory?', '$extname', '$<=>', '$nonzero?', '$proc', '$casecmp', '$cleanpath', '$inspect', '$include?', '$fill', '$map', '$entries']); - - self.$require("corelib/comparable"); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Pathname'); + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {context: " + (self.context.$inspect()) + ", style: " + (self.style.$inspect()) + ", items: " + (self.$items().$size()) + "}>" + }); + })($nesting[0], $$('AbstractBlock')); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'ListItem'); - var $nesting = [self].concat($parent_nesting), $Pathname_initialize$1, $Pathname_$eq_eq$2, $Pathname_absolute$ques$3, $Pathname_relative$ques$4, $Pathname_chop_basename$5, $Pathname_root$ques$6, $Pathname_parent$7, $Pathname_sub$8, $Pathname_cleanpath$9, $Pathname_to_path$10, $Pathname_hash$11, $Pathname_expand_path$12, $Pathname_$plus$13, $Pathname_plus$14, $Pathname_join$15, $Pathname_split$17, $Pathname_dirname$18, $Pathname_basename$19, $Pathname_directory$ques$20, $Pathname_extname$21, $Pathname_$lt_eq_gt$22, $Pathname$23, $Pathname$24, $Pathname_relative_path_from$25, $Pathname_entries$26; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - self.$$prototype.path = nil; - - self.$include($$($nesting, 'Comparable')); - Opal.const_set($nesting[0], 'SEPARATOR_PAT', new RegExp($$($nesting, 'Regexp').$quote($$$($$($nesting, 'File'), 'SEPARATOR')))); - - Opal.def(self, '$initialize', $Pathname_initialize$1 = function $$initialize(path) { - var self = this; + $proto.text = $proto.subs = $proto.blocks = nil; + + $alias(self, "list", "parent"); + self.$attr_accessor("marker"); + + $def(self, '$initialize', function $$initialize(parent, text) { + $$initialize.$$p || nil; var self = this; + $$initialize.$$p = null; + + if (text == null) text = nil; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "list_item"], null); + self.text = text; + self.level = parent.$level(); + return (self.subs = $$('NORMAL_SUBS').$drop(0)); + }, -2); - if ($truthy($$($nesting, 'Pathname')['$==='](path))) { - self.path = path.$path().$to_s() - } else if ($truthy(path['$respond_to?']("to_path"))) { - self.path = path.$to_path() - } else if ($truthy(path['$is_a?']($$($nesting, 'String')))) { - self.path = path - } else if ($truthy(path['$nil?']())) { - self.$raise($$($nesting, 'TypeError'), "no implicit conversion of nil into String") - } else { - self.$raise($$($nesting, 'TypeError'), "" + "no implicit conversion of " + (path.$class()) + " into String") - }; - if (self.path['$==']("\u0000")) { - return self.$raise($$($nesting, 'ArgumentError')) - } else { - return nil - }; - }, $Pathname_initialize$1.$$arity = 1); - self.$attr_reader("path"); - - Opal.def(self, '$==', $Pathname_$eq_eq$2 = function(other) { - var self = this; + $def(self, '$text?', function $ListItem_text$ques$2() { + var self = this; - return other.$path()['$=='](self.path) - }, $Pathname_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$absolute?', $Pathname_absolute$ques$3 = function() { - var self = this; + if ($truthy(self.text['$nil_or_empty?']())) { + return false + } else { + return true + } + }); + + $def(self, '$text', function $$text() { + var self = this, $ret_or_1 = nil; - return self['$relative?']()['$!']() - }, $Pathname_absolute$ques$3.$$arity = 0); - - Opal.def(self, '$relative?', $Pathname_relative$ques$4 = function() { - var $a, $b, $c, self = this, path = nil, r = nil; + if ($truthy(($ret_or_1 = self.text))) { + + return self.$apply_subs(self.text, self.subs); + } else { + return $ret_or_1 + } + }); + self.$attr_writer("text"); + + $def(self, '$simple?', function $ListItem_simple$ques$3() { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, blk = nil; + if ($truthy(($ret_or_1 = self.blocks['$empty?']()))) { + return $ret_or_1 + } else { + + if ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.blocks.$size()['$=='](1))) ? ($$('List')['$===']((blk = self.blocks['$[]'](0)))) : ($ret_or_3))))) { + return blk['$outline?']() + } else { + return $ret_or_2 + } } + }); - path = self.path; - while ($truthy((r = self.$chop_basename(path)))) { - $c = r, $b = Opal.to_ary($c), (path = ($b[0] == null ? nil : $b[0])), $c - }; - return path['$=='](""); - }, $Pathname_relative$ques$4.$$arity = 0); - - Opal.def(self, '$chop_basename', $Pathname_chop_basename$5 = function $$chop_basename(path) { - var self = this, base = nil; + $def(self, '$compound?', function $ListItem_compound$ques$4() { + var self = this; + return self['$simple?']()['$!']() + }); - base = $$($nesting, 'File').$basename(path); - if ($truthy($$($nesting, 'Regexp').$new("" + "^" + ($$$($$($nesting, 'Pathname'), 'SEPARATOR_PAT').$source()) + "?$")['$=~'](base))) { - return nil - } else { - return [path['$[]'](0, path.$rindex(base)), base] - }; - }, $Pathname_chop_basename$5.$$arity = 1); - - Opal.def(self, '$root?', $Pathname_root$ques$6 = function() { - var self = this; + $def(self, '$fold_first', function $$fold_first() { + var self = this; - return self.path['$==']("/") - }, $Pathname_root$ques$6.$$arity = 0); - - Opal.def(self, '$parent', $Pathname_parent$7 = function $$parent() { - var self = this, new_path = nil; + + self.text = ($truthy(self.text['$nil_or_empty?']()) ? (self.blocks.$shift().$source()) : ("" + (self.text) + ($$('LF')) + (self.blocks.$shift().$source()))); + return nil; + }); + return $def(self, '$to_s', function $$to_s() { + var self = this, $ret_or_1 = nil; - - new_path = self.path.$sub(/\/([^\/]+\/?$)/, ""); - if (new_path['$==']("")) { - new_path = (function() {if ($truthy(self['$absolute?']())) { - return "/" - } else { - return "." - }; return nil; })()}; - return $$($nesting, 'Pathname').$new(new_path); - }, $Pathname_parent$7.$$arity = 0); - - Opal.def(self, '$sub', $Pathname_sub$8 = function $$sub($a) { - var $post_args, args, self = this; + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {list_context: " + (self.$parent().$context().$inspect()) + ", text: " + (self.text.$inspect()) + ", blocks: " + (($truthy(($ret_or_1 = self.blocks)) ? ($ret_or_1) : ([])).$size()) + "}>" + }); + })($nesting[0], $$('AbstractBlock'), $nesting); + })($nesting[0], $nesting) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $$($nesting, 'Pathname').$new($send(self.path, 'sub', Opal.to_a(args))); - }, $Pathname_sub$8.$$arity = -1); - - Opal.def(self, '$cleanpath', $Pathname_cleanpath$9 = function $$cleanpath() { - var self = this; +Opal.modules["asciidoctor/parser"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, $truthy = Opal.truthy, $hash2 = Opal.hash2, $to_ary = Opal.to_ary, $defs = Opal.defs, $eqeq = Opal.eqeq, $not = Opal.not, $gvars = Opal.gvars, $neqeq = Opal.neqeq, $rb_plus = Opal.rb_plus, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - return Opal.normalize(self.path) - }, $Pathname_cleanpath$9.$$arity = 0); - - Opal.def(self, '$to_path', $Pathname_to_path$10 = function $$to_path() { - var self = this; + Opal.add_stubs('include,new,proc,start_with?,match?,is_delimited_block?,private_class_method,parse_document_header,[],has_more_lines?,next_section,assign_numeral,<<,blocks,skip_blank_lines,parse_block_metadata_lines,attributes,is_next_line_doctitle?,[]=,finalize_header,nil_or_empty?,title=,sourcemap,cursor,parse_section_title,id=,include?,sub_specialchars,sub_attributes,source_location=,header,attribute_locked?,id,clear,delete,instance_variable_get,parse_header_metadata,==,!,register,process_authors,update,doctype,parse_manpage_header,=~,downcase,error,logger,message_with_context,cursor_at_line,backend,save,is_next_line_section?,initialize_section,join,map,read_lines_until,lstrip,split,title,restore_save,discard_save,header?,empty?,context,!=,attr?,attr,key?,document,+,level,special,sectname,to_i,<,>,warn,next_block,blocks?,style,style=,parent=,content_model,content_model=,lines,subs,size,context=,shift,unwrap_standalone_preamble,source_location,merge,fetch,parse_block_metadata_line,extensions,block_macros?,mark,read_line,terminator,to_s,masq,to_sym,registered_for_block?,debug?,debug,cursor_at_mark,strict_verbatim_paragraphs,unshift_line,markdown_syntax,keys,chr,uniform?,length,end_with?,parse_attributes,attribute_missing,tr,basename,assign_caption,registered_for_block_macro?,config,process_method,replace,parse_callout_list,callouts,===,parse_list,parse_description_list,underline_style_section_titles,is_section_title?,peek_line,atx_section_title?,generate_id,level=,read_paragraph_lines,adjust_indentation!,map!,slice,pop,build_block,apply_subs,chop,catalog_inline_anchors,rekey,index,strip,-,parse_table,each,raise,title?,update_attributes,commit_subs,sub?,catalog_callouts,source,remove_sub,block_terminates_paragraph,to_proc,nil?,parse_blocks,parse_list_item,items,scan,gsub,count,advance,dup,match,callout_ids,next_list,catalog_inline_anchor,marker=,catalog_inline_biblio_anchor,set_option,text=,resolve_ordered_list_marker,read_lines_for_list_item,skip_line_comments,unshift_lines,fold_first,text?,is_sibling_list_item?,concat,find,casecmp,sectname=,special=,numbered=,numbered,lineno,peek_lines,setext_section_title?,abs,cursor_at_prev_line,process_attribute_entries,next_line_empty?,apply_header_subs,rstrip,each_with_index,compact,to_h,squeeze,to_a,parse_style_attribute,process_attribute_entry,skip_comment_lines,store_attribute,sanitize_attribute_name,set_attribute,save_to,delete_attribute,ord,int_to_roman,resolve_list_marker,parse_colspecs,create_columns,has_header_option=,format,starts_with_delimiter?,close_open_cell,parse_cellspec,delimiter,match_delimiter,pre_match,post_match,buffer_has_unclosed_quotes?,skip_past_delimiter,buffer=,buffer,skip_past_escaped_delimiter,keep_cell_open,push_cellspec,close_cell,cell_open?,columns,assign_column_widths,partition_header_footer,upto,partition,shorthand_property_syntax,each_char,yield_buffered_attribute,any?,*,each_byte,%'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - return self.path - }, $Pathname_to_path$10.$$arity = 0); - - Opal.def(self, '$hash', $Pathname_hash$11 = function $$hash() { - var self = this; + var $nesting = [self].concat($parent_nesting); - return self.path - }, $Pathname_hash$11.$$arity = 0); - - Opal.def(self, '$expand_path', $Pathname_expand_path$12 = function $$expand_path() { - var self = this; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Parser'); - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$expand_path(self.path)) - }, $Pathname_expand_path$12.$$arity = 0); - - Opal.def(self, '$+', $Pathname_$plus$13 = function(other) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if ($truthy($$($nesting, 'Pathname')['$==='](other))) { - } else { - other = $$($nesting, 'Pathname').$new(other) - }; - return $$($nesting, 'Pathname').$new(self.$plus(self.path, other.$to_s())); - }, $Pathname_$plus$13.$$arity = 1); - - Opal.def(self, '$plus', $Pathname_plus$14 = function $$plus(path1, path2) { - var $a, $b, $c, self = this, prefix2 = nil, index_list2 = nil, basename_list2 = nil, r2 = nil, basename2 = nil, prefix1 = nil, r1 = nil, basename1 = nil, suffix2 = nil; + self.$include($$('Logging')); + $const_set($nesting[0], 'BlockMatchData', $$('Struct').$new("context", "masq", "tip", "terminator")); + $const_set($nesting[0], 'TAB', "\t"); + $const_set($nesting[0], 'TabIndentRx', /^\t+/); + $const_set($nesting[0], 'StartOfBlockProc', $send(self, 'proc', [], function $Parser$1(l){var self = $Parser$1.$$s == null ? this : $Parser$1.$$s, $ret_or_1 = nil, $ret_or_2 = nil; - - prefix2 = path2; - index_list2 = []; - basename_list2 = []; - while ($truthy((r2 = self.$chop_basename(prefix2)))) { - - $c = r2, $b = Opal.to_ary($c), (prefix2 = ($b[0] == null ? nil : $b[0])), (basename2 = ($b[1] == null ? nil : $b[1])), $c; - index_list2.$unshift(prefix2.$length()); - basename_list2.$unshift(basename2); - }; - if ($truthy(prefix2['$!='](""))) { - return path2}; - prefix1 = path1; - while ($truthy(true)) { - while ($truthy(($truthy($c = basename_list2['$empty?']()['$!']()) ? basename_list2.$first()['$=='](".") : $c))) { - - index_list2.$shift(); - basename_list2.$shift(); - }; - if ($truthy((r1 = self.$chop_basename(prefix1)))) { + if (l == null) l = nil; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = l['$start_with?']("["))) ? ($$('BlockAttributeLineRx')['$match?'](l)) : ($ret_or_2))))) { + return $ret_or_1 } else { - break; - }; - $c = r1, $b = Opal.to_ary($c), (prefix1 = ($b[0] == null ? nil : $b[0])), (basename1 = ($b[1] == null ? nil : $b[1])), $c; - if (basename1['$=='](".")) { - continue;}; - if ($truthy(($truthy($b = ($truthy($c = basename1['$==']("..")) ? $c : basename_list2['$empty?']())) ? $b : basename_list2.$first()['$!=']("..")))) { - prefix1 = $rb_plus(prefix1, basename1); - break;;}; - index_list2.$shift(); - basename_list2.$shift(); - }; - r1 = self.$chop_basename(prefix1); - if ($truthy(($truthy($a = r1['$!']()) ? new RegExp($$($nesting, 'SEPARATOR_PAT'))['$=~']($$($nesting, 'File').$basename(prefix1)) : $a))) { - while ($truthy(($truthy($b = basename_list2['$empty?']()['$!']()) ? basename_list2.$first()['$==']("..") : $b))) { - - index_list2.$shift(); - basename_list2.$shift(); - }}; - if ($truthy(basename_list2['$empty?']()['$!']())) { + return self['$is_delimited_block?'](l); + }}, {$$s: self})); + $const_set($nesting[0], 'StartOfListProc', $send(self, 'proc', [], function $Parser$2(l){ - suffix2 = path2['$[]'](Opal.Range.$new(index_list2.$first(), -1, false)); - if ($truthy(r1)) { - return $$($nesting, 'File').$join(prefix1, suffix2) - } else { - return $rb_plus(prefix1, suffix2) - }; - } else if ($truthy(r1)) { - return prefix1 - } else { - return $$($nesting, 'File').$dirname(prefix1) - }; - }, $Pathname_plus$14.$$arity = 2); - - Opal.def(self, '$join', $Pathname_join$15 = function $$join($a) {try { + if (l == null) l = nil; + return $$('AnyListRx')['$match?'](l);})); + $const_set($nesting[0], 'StartOfBlockOrListProc', $send(self, 'proc', [], function $Parser$3(l){var self = $Parser$3.$$s == null ? this : $Parser$3.$$s, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil; - var $post_args, args, $$16, self = this, result = nil; + + if (l == null) l = nil; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self['$is_delimited_block?'](l))) ? ($ret_or_2) : (($truthy(($ret_or_3 = l['$start_with?']("["))) ? ($$('BlockAttributeLineRx')['$match?'](l)) : ($ret_or_3))))))) { + return $ret_or_1 + } else { + + return $$('AnyListRx')['$match?'](l); + }}, {$$s: self})); + $const_set($nesting[0], 'NoOp', nil); + $const_set($nesting[0], 'AuthorKeys', ["author", "authorinitials", "firstname", "middlename", "lastname", "email"]); + $const_set($nesting[0], 'TableCellHorzAlignments', $hash2(["<", ">", "^"], {"<": "left", ">": "right", "^": "center"})); + $const_set($nesting[0], 'TableCellVertAlignments', $hash2(["<", ">", "^"], {"<": "top", ">": "bottom", "^": "middle"})); + $const_set($nesting[0], 'TableCellStyles', $hash2(["d", "s", "e", "m", "h", "l", "a"], {"d": "none", "s": "strong", "e": "emphasis", "m": "monospaced", "h": "header", "l": "literal", "a": "asciidoc"})); + self.$private_class_method("new"); + $defs(self, '$parse', function $$parse(reader, document, options) { + var $a, $b, self = this, block_attributes = nil, header_only = nil, new_section = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(args['$empty?']())) { - return self}; - result = args.$pop(); - if ($truthy($$($nesting, 'Pathname')['$==='](result))) { - } else { - result = $$($nesting, 'Pathname').$new(result) - }; - if ($truthy(result['$absolute?']())) { - return result}; - $send(args, 'reverse_each', [], ($$16 = function(arg){var self = $$16.$$s || this; + + if (options == null) options = $hash2([], {}); + block_attributes = self.$parse_document_header(reader, document, (header_only = options['$[]']("header_only"))); + if (!$truthy(header_only)) { + while ($truthy(reader['$has_more_lines?']())) { + + $b = self.$next_section(reader, document, block_attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (block_attributes = ($a[1] == null ? nil : $a[1])); + if ($truthy(new_section)) { + + document.$assign_numeral(new_section); + document.$blocks()['$<<'](new_section); + } } + } return document; + }, -3); + $defs(self, '$parse_document_header', function $$parse_document_header(reader, document, header_only) { + var $a, $b, $c, self = this, block_attrs = nil, doc_attrs = nil, implicit_doctitle = nil, val = nil, doctitle_attr_val = nil, source_location = nil, l0_section_title = nil, atx = nil, separator = nil, doc_id = nil, role = nil, reftext = nil, modified_attrs = nil, author = nil, author_metadata = nil; - - if (arg == null) { - arg = nil; - }; - if ($truthy($$($nesting, 'Pathname')['$==='](arg))) { - } else { - arg = $$($nesting, 'Pathname').$new(arg) - }; - result = $rb_plus(arg, result); - if ($truthy(result['$absolute?']())) { - Opal.ret(result) + if (header_only == null) header_only = false; + block_attrs = ($truthy(reader.$skip_blank_lines()) ? (self.$parse_block_metadata_lines(reader, document)) : ($hash2([], {}))); + doc_attrs = document.$attributes(); + if (($truthy((implicit_doctitle = self['$is_next_line_doctitle?'](reader, block_attrs, doc_attrs['$[]']("leveloffset")))) && ($truthy(block_attrs['$[]']("title"))))) { + + doc_attrs['$[]=']("authorcount", 0); + return document.$finalize_header(block_attrs, false); + } if (!$truthy((val = doc_attrs['$[]']("doctitle"))['$nil_or_empty?']())) { + document['$title=']((doctitle_attr_val = val)); + } if ($truthy(implicit_doctitle)) { + + if ($truthy(document.$sourcemap())) { + source_location = reader.$cursor(); + } $b = self.$parse_section_title(reader, document), $a = $to_ary($b), ($c = [($a[0] == null ? nil : $a[0])], $send(document, 'id=', $c), $c[$c.length - 1]), (($a[1] == null ? nil : $a[1])), (l0_section_title = ($a[2] == null ? nil : $a[2])), (($a[3] == null ? nil : $a[3])), (atx = ($a[4] == null ? nil : $a[4])); + if ($truthy(doctitle_attr_val)) { + l0_section_title = nil; + } else { + + document['$title='](l0_section_title); + if ($truthy(($a = ["doctitle", (doctitle_attr_val = document.$sub_specialchars(l0_section_title))], $send(doc_attrs, '[]=', $a), $a[$a.length - 1])['$include?']($$('ATTR_REF_HEAD')))) { + doc_attrs['$[]=']("doctitle", (doctitle_attr_val = document.$sub_attributes(doctitle_attr_val, $hash2(["attribute_missing"], {"attribute_missing": "skip"})))); + } } if ($truthy(source_location)) { + document.$header()['$source_location='](source_location); + } if (!($truthy(atx) || ($truthy(document['$attribute_locked?']("compat-mode"))))) { + doc_attrs['$[]=']("compat-mode", ""); + } if ($truthy((separator = block_attrs['$[]']("separator")))) { + if (!$truthy(document['$attribute_locked?']("title-separator"))) { + doc_attrs['$[]=']("title-separator", separator); + } + } if ($truthy((doc_id = block_attrs['$[]']("id")))) { + document['$id='](doc_id); + } else { + doc_id = document.$id(); + } if ($truthy((role = block_attrs['$[]']("role")))) { + doc_attrs['$[]=']("role", role); + } if ($truthy((reftext = block_attrs['$[]']("reftext")))) { + doc_attrs['$[]=']("reftext", reftext); + } block_attrs.$clear(); + (modified_attrs = document.$instance_variable_get("@attributes_modified")).$delete("doctitle"); + self.$parse_header_metadata(reader, document, nil); + if ($truthy(modified_attrs['$include?']("doctitle"))) { + if (($truthy((val = doc_attrs['$[]']("doctitle"))['$nil_or_empty?']()) || ($eqeq(val, doctitle_attr_val)))) { + doc_attrs['$[]=']("doctitle", doctitle_attr_val); + } else { + document['$title='](val); + } + } else if ($not(l0_section_title)) { + modified_attrs['$<<']("doctitle"); + } if ($truthy(doc_id)) { + document.$register("refs", [doc_id, document]); + } } else if ($truthy((author = doc_attrs['$[]']("author")))) { + + author_metadata = self.$process_authors(author, true, false); + if ($truthy(doc_attrs['$[]']("authorinitials"))) { + author_metadata.$delete("authorinitials"); + } doc_attrs.$update(author_metadata); + } else if ($truthy((author = doc_attrs['$[]']("authors")))) { + + author_metadata = self.$process_authors(author, true); + doc_attrs.$update(author_metadata); } else { - return nil - };}, $$16.$$s = self, $$16.$$arity = 1, $$16)); - return $rb_plus(self, result); - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Pathname_join$15.$$arity = -1); - - Opal.def(self, '$split', $Pathname_split$17 = function $$split() { - var self = this; + doc_attrs['$[]=']("authorcount", 0); + } if ($eqeq(document.$doctype(), "manpage")) { + self.$parse_manpage_header(reader, document, block_attrs, header_only); + } return document.$finalize_header(block_attrs); + }, -3); + $defs(self, '$parse_manpage_header', function $$parse_manpage_header(reader, document, block_attributes, header_only) { + var $a, self = this, doc_attrs = nil, manvolnum = nil, mantitle = nil, $ret_or_1 = nil, $ret_or_2 = nil, manname = nil, name_section_level = nil, name_section = nil, name_section_buffer = nil, mannames = nil, manpurpose = nil, error_msg = nil; - return [self.$dirname(), self.$basename()] - }, $Pathname_split$17.$$arity = 0); - - Opal.def(self, '$dirname', $Pathname_dirname$18 = function $$dirname() { - var self = this; + + if (header_only == null) header_only = false; + if ($truthy($$('ManpageTitleVolnumRx')['$=~']((doc_attrs = document.$attributes())['$[]']("doctitle")))) { + + doc_attrs['$[]=']("manvolnum", (manvolnum = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))); + doc_attrs['$[]=']("mantitle", ($truthy((mantitle = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))['$include?']($$('ATTR_REF_HEAD'))) ? (document.$sub_attributes(mantitle)) : (mantitle)).$downcase()); + } else { + + self.$logger().$error(self.$message_with_context("non-conforming manpage title", $hash2(["source_location"], {"source_location": reader.$cursor_at_line(1)}))); + doc_attrs['$[]=']("mantitle", ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = doc_attrs['$[]']("doctitle"))) ? ($ret_or_2) : (doc_attrs['$[]']("docname"))))) ? ($ret_or_1) : ("command"))); + doc_attrs['$[]=']("manvolnum", (manvolnum = "1")); + } if (($truthy((manname = doc_attrs['$[]']("manname"))) && ($truthy(doc_attrs['$[]']("manpurpose"))))) { + + if ($truthy(($ret_or_1 = doc_attrs['$[]']("manname-title")))) ; else { + doc_attrs['$[]=']("manname-title", "Name"); + } doc_attrs['$[]=']("mannames", [manname]); + if ($eqeq(document.$backend(), "manpage")) { + + doc_attrs['$[]=']("docname", manname); + doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum)); + } } else if (!$truthy(header_only)) { + + reader.$skip_blank_lines(); + reader.$save(); + block_attributes.$update(self.$parse_block_metadata_lines(reader, document)); + if ($truthy((name_section_level = self['$is_next_line_section?'](reader, $hash2([], {}))))) { + if ($eqeq(name_section_level, 1)) { + + name_section = self.$initialize_section(reader, document, $hash2([], {})); + name_section_buffer = $send(reader.$read_lines_until($hash2(["break_on_blank_lines", "skip_line_comments"], {"break_on_blank_lines": true, "skip_line_comments": true})), 'map', [], function $$4(l){ + + if (l == null) l = nil; + return l.$lstrip();}).$join(" "); + if ($truthy($$('ManpageNamePurposeRx')['$=~'](name_section_buffer))) { + + if ($truthy((manname = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))['$include?']($$('ATTR_REF_HEAD')))) { + manname = document.$sub_attributes(manname); + } if ($truthy(manname['$include?'](","))) { + manname = (mannames = $send(manname.$split(","), 'map', [], function $$5(n){ + + if (n == null) n = nil; + return n.$lstrip();}))['$[]'](0); + } else { + mannames = [manname]; + } if ($truthy((manpurpose = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))['$include?']($$('ATTR_REF_HEAD')))) { + manpurpose = document.$sub_attributes(manpurpose); + } if ($truthy(($ret_or_1 = doc_attrs['$[]']("manname-title")))) ; else { + doc_attrs['$[]=']("manname-title", name_section.$title()); + } if ($truthy(name_section.$id())) { + doc_attrs['$[]=']("manname-id", name_section.$id()); + } doc_attrs['$[]=']("manname", manname); + doc_attrs['$[]=']("mannames", mannames); + doc_attrs['$[]=']("manpurpose", manpurpose); + if ($eqeq(document.$backend(), "manpage")) { + + doc_attrs['$[]=']("docname", manname); + doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum)); + } } else { + error_msg = "non-conforming name section body"; + } } else { + error_msg = "name section must be at level 1"; + } + } else { + error_msg = "name section expected"; + } if ($truthy(error_msg)) { + + reader.$restore_save(); + self.$logger().$error(self.$message_with_context(error_msg, $hash2(["source_location"], {"source_location": reader.$cursor()}))); + doc_attrs['$[]=']("manname", (manname = ($truthy(($ret_or_1 = doc_attrs['$[]']("docname"))) ? ($ret_or_1) : ("command")))); + doc_attrs['$[]=']("mannames", [manname]); + if ($eqeq(document.$backend(), "manpage")) { + + doc_attrs['$[]=']("docname", manname); + doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum)); + } } else { + reader.$discard_save(); + } } return nil; + }, -4); + $defs(self, '$next_section', function $$next_section(reader, parent, attributes) { + var $a, $b, self = this, preamble = nil, intro = nil, part = nil, has_header = nil, book = nil, document = nil, section = nil, current_level = nil, expected_next_level = nil, expected_next_level_alt = nil, title = nil, sectname = nil, next_level = nil, expected_condition = nil, new_section = nil, block_cursor = nil, new_block = nil, $ret_or_1 = nil, first_block = nil, child_block = nil; - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$dirname(self.path)) - }, $Pathname_dirname$18.$$arity = 0); - - Opal.def(self, '$basename', $Pathname_basename$19 = function $$basename() { - var self = this; + + if (attributes == null) attributes = $hash2([], {}); + preamble = (intro = (part = false)); + if ((($eqeq(parent.$context(), "document") && ($truthy(parent.$blocks()['$empty?']()))) && ((($truthy((has_header = parent['$header?']())) || ($truthy(attributes.$delete("invalid-header")))) || ($not(self['$is_next_line_section?'](reader, attributes))))))) { + + book = (document = parent).$doctype()['$==']("book"); + if (($truthy(has_header) || (($truthy(book) && ($neqeq(attributes['$[]'](1), "abstract")))))) { + + preamble = (intro = $$('Block').$new(parent, "preamble", $hash2(["content_model"], {"content_model": "compound"}))); + if (($truthy(book) && ($truthy(parent['$attr?']("preface-title"))))) { + preamble['$title='](parent.$attr("preface-title")); + } parent.$blocks()['$<<'](preamble); + } section = parent; + current_level = 0; + if ($truthy(parent.$attributes()['$key?']("fragment"))) { + expected_next_level = -1; + } else if ($truthy(book)) { + $a = [1, 0], (expected_next_level = $a[0]), (expected_next_level_alt = $a[1]); + } else { + expected_next_level = 1; + } } else { + + book = (document = parent.$document()).$doctype()['$==']("book"); + section = self.$initialize_section(reader, parent, attributes); + attributes = ($truthy((title = attributes['$[]']("title"))) ? ($hash2(["title"], {"title": title})) : ($hash2([], {}))); + expected_next_level = $rb_plus((current_level = section.$level()), 1); + if ($eqeq(current_level, 0)) { + part = book; + } else if (($eqeq(current_level, 1) && ($truthy(section.$special())))) { + if (!(($eqeq((sectname = section.$sectname()), "appendix") || ($eqeq(sectname, "preface"))) || ($eqeq(sectname, "abstract")))) { + expected_next_level = nil; + } + } } reader.$skip_blank_lines(); + while ($truthy(reader['$has_more_lines?']())) { + + self.$parse_block_metadata_lines(reader, document, attributes); + if ($truthy((next_level = self['$is_next_line_section?'](reader, attributes)))) { + + if ($truthy(document['$attr?']("leveloffset"))) { + + next_level = $rb_plus(next_level, document.$attr("leveloffset").$to_i()); + if ($truthy($rb_lt(next_level, 0))) { + next_level = 0; + } } if ($truthy($rb_gt(next_level, current_level))) { + + if ($truthy(expected_next_level)) { + if (!(($eqeq(next_level, expected_next_level) || (($truthy(expected_next_level_alt) && ($eqeq(next_level, expected_next_level_alt))))) || ($truthy($rb_lt(expected_next_level, 0))))) { + + expected_condition = ($truthy(expected_next_level_alt) ? ("expected levels " + (expected_next_level_alt) + " or " + (expected_next_level)) : ("expected level " + (expected_next_level))); + self.$logger().$warn(self.$message_with_context("section title out of sequence: " + (expected_condition) + ", got level " + (next_level), $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } + } else { + self.$logger().$error(self.$message_with_context("" + (sectname) + " sections do not support nested sections", $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } $b = self.$next_section(reader, section, attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (attributes = ($a[1] == null ? nil : $a[1])); + section.$assign_numeral(new_section); + section.$blocks()['$<<'](new_section); + } else if (($eqeq(next_level, 0) && ($eqeq(section, document)))) { + + if (!$truthy(book)) { + self.$logger().$error(self.$message_with_context("level 0 sections can only be used when doctype is book", $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } $b = self.$next_section(reader, section, attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (attributes = ($a[1] == null ? nil : $a[1])); + section.$assign_numeral(new_section); + section.$blocks()['$<<'](new_section); + } else { + break + } } else { + + block_cursor = reader.$cursor(); + if ($truthy((new_block = self.$next_block(reader, ($truthy(($ret_or_1 = intro)) ? ($ret_or_1) : (section)), attributes, $hash2(["parse_metadata"], {"parse_metadata": false}))))) { + + if ($truthy(part)) { + if ($not(section['$blocks?']())) { + if ($neqeq(new_block.$style(), "partintro")) { + if (($eqeq(new_block.$style(), "open") && ($eqeq(new_block.$context(), "open")))) { + new_block['$style=']("partintro"); + } else { + + new_block['$parent=']((intro = $$('Block').$new(section, "open", $hash2(["content_model"], {"content_model": "compound"})))); + intro['$style=']("partintro"); + section.$blocks()['$<<'](intro); + } + } else if ($eqeq(new_block.$content_model(), "simple")) { + + new_block['$content_model=']("compound"); + new_block['$<<']($$('Block').$new(new_block, "paragraph", $hash2(["source", "subs"], {"source": new_block.$lines(), "subs": new_block.$subs()}))); + new_block.$lines().$clear(); + new_block.$subs().$clear(); + } + } else if ($eqeq(section.$blocks().$size(), 1)) { + + first_block = section.$blocks()['$[]'](0); + if (($not(intro) && ($eqeq(first_block.$content_model(), "compound")))) { + self.$logger().$error(self.$message_with_context("illegal block content outside of partintro block", $hash2(["source_location"], {"source_location": block_cursor}))); + } else if ($neqeq(first_block.$content_model(), "compound")) { + + new_block['$parent=']((intro = $$('Block').$new(section, "open", $hash2(["content_model"], {"content_model": "compound"})))); + if ($eqeq(first_block.$style(), ($a = ["partintro"], $send(intro, 'style=', $a), $a[$a.length - 1]))) { + + first_block['$context=']("paragraph"); + first_block['$style='](nil); + } section.$blocks().$shift(); + intro['$<<'](first_block); + section.$blocks()['$<<'](intro); + } } + } ($truthy(($ret_or_1 = intro)) ? ($ret_or_1) : (section)).$blocks()['$<<'](new_block); + attributes.$clear(); + } } if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) ; else { + break + } } if ($truthy(part)) { + if (!($truthy(section['$blocks?']()) && ($eqeq(section.$blocks()['$[]'](-1).$context(), "section")))) { + self.$logger().$error(self.$message_with_context("invalid part, must have at least one section (e.g., chapter, appendix, etc.)", $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } + } else if ($truthy(preamble)) { + if ($truthy(preamble['$blocks?']())) { + if ((($truthy(book) || ($truthy(document.$blocks()['$[]'](1)))) || ($not($$('Compliance').$unwrap_standalone_preamble())))) { + if ($truthy(document.$sourcemap())) { + preamble['$source_location='](preamble.$blocks()['$[]'](0).$source_location()); + } + } else { + + document.$blocks().$shift(); + while ($truthy((child_block = preamble.$blocks().$shift()))) { + document['$<<'](child_block); + } } + } else { + document.$blocks().$shift(); + } + } return [($eqeq(section, parent) ? (nil) : (section)), attributes.$merge()]; + }, -3); + $defs(self, '$next_block', function $$next_block(reader, parent, attributes, options) { + var $a, $b, self = this, skipped = nil, text_only = nil, document = nil, $ret_or_1 = nil, extensions = nil, block_extensions = nil, block_macro_extensions = nil, this_line = nil, doc_attrs = nil, style = nil, block = nil, block_context = nil, cloaked_context = nil, terminator = nil, delimited_block = nil, indented = nil, md_syntax = nil, ch0 = nil, layout_break_chars = nil, ll = nil, blk_ctx = nil, target = nil, blk_attrs = nil, posattrs = nil, expanded_target = nil, $ret_or_2 = nil, scaledwidth = nil, block_title = nil, extension = nil, report_unknown_block_macro = nil, content = nil, ext_config = nil, default_attrs = nil, float_id = nil, float_reftext = nil, float_level = nil, lines = nil, content_adjacent = nil, admonition_name = nil, credit_line = nil, attribution = nil, citetitle = nil, language = nil, comma_idx = nil, block_cursor = nil, block_reader = nil, content_model = nil, positional_attrs = nil, block_id = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$basename(self.path)) - }, $Pathname_basename$19.$$arity = 0); - - Opal.def(self, '$directory?', $Pathname_directory$ques$20 = function() { - var self = this; + + if (attributes == null) attributes = $hash2([], {}); + if (options == null) options = $hash2([], {}); + if (!$truthy((skipped = reader.$skip_blank_lines()))) { + return nil + } if (($truthy((text_only = options['$[]']("text_only"))) && ($truthy($rb_gt(skipped, 0))))) { + + options.$delete("text_only"); + text_only = nil; + } document = parent.$document(); + if ($truthy(options.$fetch("parse_metadata", true))) { + while ($truthy(self.$parse_block_metadata_line(reader, document, attributes, options))) { + + reader.$shift(); + if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) ; else { + return nil + } } + } if ($truthy((extensions = document.$extensions()))) { + $a = [extensions['$blocks?'](), extensions['$block_macros?']()], (block_extensions = $a[0]), (block_macro_extensions = $a[1]); + } reader.$mark(); + $a = [reader.$read_line(), document.$attributes(), attributes['$[]'](1)], (this_line = $a[0]), (doc_attrs = $a[1]), (style = $a[2]); + block = (block_context = (cloaked_context = (terminator = nil))); + if ($truthy((delimited_block = self['$is_delimited_block?'](this_line, true)))) { + + block_context = (cloaked_context = delimited_block.$context()); + terminator = delimited_block.$terminator(); + if ($truthy(style)) { + if (!$eqeq(style, block_context.$to_s())) { + if ($truthy(delimited_block.$masq()['$include?'](style))) { + block_context = style.$to_sym(); + } else if (($truthy(delimited_block.$masq()['$include?']("admonition")) && ($truthy($$('ADMONITION_STYLES')['$include?'](style))))) { + block_context = "admonition"; + } else if (($truthy(block_extensions) && ($truthy(extensions['$registered_for_block?'](style, block_context))))) { + block_context = style.$to_sym(); + } else { + + if ($truthy(self.$logger()['$debug?']())) { + self.$logger().$debug(self.$message_with_context("unknown style for " + (block_context) + " block: " + (style), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } style = block_context.$to_s(); + } + } + } else { + style = ($a = ["style", block_context.$to_s()], $send(attributes, '[]=', $a), $a[$a.length - 1]); + } } if (!$truthy(delimited_block)) { + while ($truthy(true)) { + + if ((($truthy(style) && ($truthy($$('Compliance').$strict_verbatim_paragraphs()))) && ($truthy($$('VERBATIM_STYLES')['$include?'](style))))) { + + block_context = style.$to_sym(); + reader.$unshift_line(this_line); + break; + } if ($truthy(text_only)) { + indented = this_line['$start_with?'](" ", $$('TAB')); + } else { + + md_syntax = $$('Compliance').$markdown_syntax(); + if ($truthy(this_line['$start_with?'](" "))) { + + $a = [true, " "], (indented = $a[0]), (ch0 = $a[1]); + if ((($truthy(md_syntax) && ($truthy($send(this_line.$lstrip(), 'start_with?', $to_a($$('MARKDOWN_THEMATIC_BREAK_CHARS').$keys()))))) && ($truthy($$('MarkdownThematicBreakRx')['$match?'](this_line))))) { + + block = $$('Block').$new(parent, "thematic_break", $hash2(["content_model"], {"content_model": "empty"})); + break; + } } else if ($truthy(this_line['$start_with?']($$('TAB')))) { + $a = [true, $$('TAB')], (indented = $a[0]), (ch0 = $a[1]); + } else { + + $a = [false, this_line.$chr()], (indented = $a[0]), (ch0 = $a[1]); + layout_break_chars = ($truthy(md_syntax) ? ($$('HYBRID_LAYOUT_BREAK_CHARS')) : ($$('LAYOUT_BREAK_CHARS'))); + if (($truthy(layout_break_chars['$key?'](ch0)) && ($truthy(($truthy(md_syntax) ? ($$('ExtLayoutBreakRx')['$match?'](this_line)) : ($truthy(($ret_or_1 = self['$uniform?'](this_line, ch0, (ll = this_line.$length())))) ? ($rb_gt(ll, 2)) : ($ret_or_1))))))) { + + block = $$('Block').$new(parent, layout_break_chars['$[]'](ch0), $hash2(["content_model"], {"content_model": "empty"})); + break; + } else if (($truthy(this_line['$end_with?']("]")) && ($truthy(this_line['$include?']("::"))))) { + if ((($eqeq(ch0, "i") || ($truthy(this_line['$start_with?']("video:", "audio:")))) && ($truthy($$('BlockMediaMacroRx')['$=~'](this_line))))) { + + $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)).$to_sym(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (blk_ctx = $a[0]), (target = $a[1]), (blk_attrs = $a[2]); + block = $$('Block').$new(parent, blk_ctx, $hash2(["content_model"], {"content_model": "empty"})); + if ($truthy(blk_attrs)) { + + + switch (blk_ctx) { + case "video": + posattrs = ["poster", "width", "height"]; + break; + case "audio": + posattrs = []; + break; + default: + posattrs = ["alt", "width", "height"]; + } block.$parse_attributes(blk_attrs, posattrs, $hash2(["sub_input", "into"], {"sub_input": true, "into": attributes})); + } if ($truthy(attributes['$key?']("style"))) { + attributes.$delete("style"); + } if ($truthy(target['$include?']($$('ATTR_REF_HEAD')))) { + if ((($truthy((expanded_target = block.$sub_attributes(target))['$empty?']()) && ($eqeq(($truthy(($ret_or_1 = doc_attrs['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing())), "drop-line"))) && ($truthy(block.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) { + + attributes.$clear(); + return nil; + } else { + target = expanded_target; + } + } if ($eqeq(blk_ctx, "image")) { + + document.$register("images", target); + attributes['$[]=']("imagesdir", doc_attrs['$[]']("imagesdir")); + if ($truthy(($ret_or_1 = attributes['$[]']("alt")))) ; else { + attributes['$[]=']("alt", ($truthy(($ret_or_2 = style)) ? ($ret_or_2) : (($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attributes, '[]=', $a), $a[$a.length - 1])))); + } if (!$truthy((scaledwidth = attributes.$delete("scaledwidth"))['$nil_or_empty?']())) { + attributes['$[]=']("scaledwidth", ($truthy($$('TrailingDigitsRx')['$match?'](scaledwidth)) ? ("" + (scaledwidth) + "%") : (scaledwidth))); + } if ($truthy(attributes['$[]']("title"))) { + + block['$title=']((block_title = attributes.$delete("title"))); + block.$assign_caption(attributes.$delete("caption"), "figure"); + } } attributes['$[]=']("target", target); + break; + } else if ((($eqeq(ch0, "t") && ($truthy(this_line['$start_with?']("toc:")))) && ($truthy($$('BlockTocMacroRx')['$=~'](this_line))))) { + + block = $$('Block').$new(parent, "toc", $hash2(["content_model"], {"content_model": "empty"})); + if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) { + block.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), [], $hash2(["into"], {"into": attributes})); + } break; + } else if ($truthy(($truthy(block_macro_extensions) ? (($truthy(($ret_or_1 = ($truthy(($ret_or_2 = $$('CustomBlockMacroRx')['$=~'](this_line))) ? ((extension = extensions['$registered_for_block_macro?']((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) : ($ret_or_2)))) ? ($ret_or_1) : ((report_unknown_block_macro = self.$logger()['$debug?']())))) : (($truthy(($ret_or_1 = self.$logger()['$debug?']())) ? ((report_unknown_block_macro = $$('CustomBlockMacroRx')['$=~'](this_line))) : ($ret_or_1)))))) { + if ($truthy(report_unknown_block_macro)) { + self.$logger().$debug(self.$message_with_context("unknown name for block macro: " + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } else { + + content = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + if ($truthy((target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))['$include?']($$('ATTR_REF_HEAD')))) { + if ((($truthy((expanded_target = parent.$sub_attributes(target))['$empty?']()) && ($eqeq(($truthy(($ret_or_1 = doc_attrs['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing())), "drop-line"))) && ($truthy(parent.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) { + + attributes.$clear(); + return nil; + } else { + target = expanded_target; + } + } if ($eqeq((ext_config = extension.$config())['$[]']("content_model"), "attributes")) { + if ($truthy(content)) { + document.$parse_attributes(content, ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))) ? ($ret_or_1) : ([])), $hash2(["sub_input", "into"], {"sub_input": true, "into": attributes})); + } + } else { + attributes['$[]=']("text", ($truthy(($ret_or_1 = content)) ? ($ret_or_1) : (""))); + } if ($truthy((default_attrs = ext_config['$[]']("default_attrs")))) { + $send(attributes, 'update', [default_attrs], function $$6(_, old_v){ + if (old_v == null) old_v = nil; + return old_v;}); + } if (($truthy((block = extension.$process_method()['$[]'](parent, target, attributes))) && ($neqeq(block, parent)))) { + + attributes.$replace(block.$attributes()); + break; + } else { + + attributes.$clear(); + return nil; + } } + } + } } } if ((($not(indented) && ($eqeq((ch0 = ($truthy(($ret_or_1 = ch0)) ? ($ret_or_1) : (this_line.$chr()))), "<"))) && ($truthy($$('CalloutListRx')['$=~'](this_line))))) { + + reader.$unshift_line(this_line); + block = self.$parse_callout_list(reader, $gvars["~"], parent, document.$callouts()); + attributes['$[]=']("style", "arabic"); + break; + } else if ($truthy($$('UnorderedListRx')['$match?'](this_line))) { + + reader.$unshift_line(this_line); + if ((($not(style) && ($eqeqeq($$('Section'), parent))) && ($eqeq(parent.$sectname(), "bibliography")))) { + attributes['$[]=']("style", (style = "bibliography")); + } block = self.$parse_list(reader, "ulist", parent, style); + break; + } else if ($truthy($$('OrderedListRx')['$match?'](this_line))) { + + reader.$unshift_line(this_line); + block = self.$parse_list(reader, "olist", parent, style); + if ($truthy(block.$style())) { + attributes['$[]=']("style", block.$style()); + } break; + } else if ((($truthy(this_line['$include?']("::")) || ($truthy(this_line['$include?'](";;")))) && ($truthy($$('DescriptionListRx')['$=~'](this_line))))) { + + reader.$unshift_line(this_line); + block = self.$parse_description_list(reader, $gvars["~"], parent); + break; + } else if ((($eqeq(style, "float") || ($eqeq(style, "discrete"))) && ($truthy(($truthy($$('Compliance').$underline_style_section_titles()) ? (self['$is_section_title?'](this_line, reader.$peek_line())) : ($truthy(($ret_or_1 = indented['$!']())) ? (self['$atx_section_title?'](this_line)) : ($ret_or_1))))))) { + + reader.$unshift_line(this_line); + $b = self.$parse_section_title(reader, document, attributes['$[]']("id")), $a = $to_ary($b), (float_id = ($a[0] == null ? nil : $a[0])), (float_reftext = ($a[1] == null ? nil : $a[1])), (block_title = ($a[2] == null ? nil : $a[2])), (float_level = ($a[3] == null ? nil : $a[3])); + if ($truthy(float_reftext)) { + attributes['$[]=']("reftext", float_reftext); + } block = $$('Block').$new(parent, "floating_title", $hash2(["content_model"], {"content_model": "empty"})); + block['$title='](block_title); + attributes.$delete("title"); + block['$id='](($truthy(($ret_or_1 = float_id)) ? ($ret_or_1) : (($truthy(doc_attrs['$key?']("sectids")) ? ($$('Section').$generate_id(block.$title(), document)) : (nil))))); + block['$level='](float_level); + break; + } else if (($truthy(style) && ($neqeq(style, "normal")))) { + if ($truthy($$('PARAGRAPH_STYLES')['$include?'](style))) { + + block_context = style.$to_sym(); + cloaked_context = "paragraph"; + reader.$unshift_line(this_line); + break; + } else if ($truthy($$('ADMONITION_STYLES')['$include?'](style))) { + + block_context = "admonition"; + cloaked_context = "paragraph"; + reader.$unshift_line(this_line); + break; + } else if (($truthy(block_extensions) && ($truthy(extensions['$registered_for_block?'](style, "paragraph"))))) { + + block_context = style.$to_sym(); + cloaked_context = "paragraph"; + reader.$unshift_line(this_line); + break; + } else { + + if ($truthy(self.$logger()['$debug?']())) { + self.$logger().$debug(self.$message_with_context("unknown style for paragraph: " + (style), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } style = nil; + } + } reader.$unshift_line(this_line); + if (($truthy(indented) && ($not(style)))) { + + lines = self.$read_paragraph_lines(reader, (content_adjacent = ($eqeq(skipped, 0) ? (options['$[]']("list_type")) : (nil))), $hash2(["skip_line_comments"], {"skip_line_comments": text_only})); + self['$adjust_indentation!'](lines); + if (($truthy(text_only) || ($eqeq(content_adjacent, "dlist")))) { + block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes})); + } else { + block = $$('Block').$new(parent, "literal", $hash2(["content_model", "source", "attributes"], {"content_model": "verbatim", "source": lines, "attributes": attributes})); + } } else { + + lines = self.$read_paragraph_lines(reader, ($truthy(($ret_or_1 = skipped['$=='](0))) ? (options['$[]']("list_type")) : ($ret_or_1)), $hash2(["skip_line_comments"], {"skip_line_comments": true})); + if ($truthy(text_only)) { + + if (($truthy(indented) && ($eqeq(style, "normal")))) { + self['$adjust_indentation!'](lines); + } block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes})); + } else if ((($truthy($$('ADMONITION_STYLE_HEADS')['$include?'](ch0)) && ($truthy(this_line['$include?'](":")))) && ($truthy($$('AdmonitionParagraphRx')['$=~'](this_line))))) { + + lines['$[]='](0, (($a = $gvars['~']) === nil ? nil : $a.$post_match())); + attributes['$[]=']("name", (admonition_name = ($a = ["style", (($b = $gvars['~']) === nil ? nil : $b['$[]'](1))], $send(attributes, '[]=', $a), $a[$a.length - 1]).$downcase())); + attributes['$[]=']("textlabel", ($truthy(($ret_or_1 = attributes.$delete("caption"))) ? ($ret_or_1) : (doc_attrs['$[]']("" + (admonition_name) + "-caption")))); + block = $$('Block').$new(parent, "admonition", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes})); + } else if ((($truthy(md_syntax) && ($eqeq(ch0, ">"))) && ($truthy(this_line['$start_with?']("> "))))) { + + $send(lines, 'map!', [], function $$7(line){ + + if (line == null) line = nil; + if ($eqeq(line, ">")) { + + return line.$slice(1, line.$length()); + } else { + + if ($truthy(line['$start_with?']("> "))) { + + return line.$slice(2, line.$length()); + } else { + return line + } }}); + if ($truthy(lines['$[]'](-1)['$start_with?']("-- "))) { + + credit_line = (credit_line = lines.$pop()).$slice(3, credit_line.$length()); + if (!$truthy(lines['$empty?']())) { + while ($truthy(lines['$[]'](-1)['$empty?']())) { + lines.$pop(); + } + } } attributes['$[]=']("style", "quote"); + block = self.$build_block("quote", "compound", false, parent, $$('Reader').$new(lines), attributes); + if ($truthy(credit_line)) { + + $b = block.$apply_subs(credit_line).$split(", ", 2), $a = $to_ary($b), (attribution = ($a[0] == null ? nil : $a[0])), (citetitle = ($a[1] == null ? nil : $a[1])); + if ($truthy(attribution)) { + attributes['$[]=']("attribution", attribution); + } if ($truthy(citetitle)) { + attributes['$[]=']("citetitle", citetitle); + } } } else if (((($eqeq(ch0, "\"") && ($truthy($rb_gt(lines.$size(), 1)))) && ($truthy(lines['$[]'](-1)['$start_with?']("-- ")))) && ($truthy(lines['$[]'](-2)['$end_with?']("\""))))) { + + lines['$[]='](0, this_line.$slice(1, this_line.$length())); + credit_line = (credit_line = lines.$pop()).$slice(3, credit_line.$length()); + while ($truthy(lines['$[]'](-1)['$empty?']())) { + lines.$pop(); + } lines['$<<'](lines.$pop().$chop()); + attributes['$[]=']("style", "quote"); + block = $$('Block').$new(parent, "quote", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes})); + $b = block.$apply_subs(credit_line).$split(", ", 2), $a = $to_ary($b), (attribution = ($a[0] == null ? nil : $a[0])), (citetitle = ($a[1] == null ? nil : $a[1])); + if ($truthy(attribution)) { + attributes['$[]=']("attribution", attribution); + } if ($truthy(citetitle)) { + attributes['$[]=']("citetitle", citetitle); + } } else { + + if (($truthy(indented) && ($eqeq(style, "normal")))) { + self['$adjust_indentation!'](lines); + } block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes})); + } self.$catalog_inline_anchors(lines.$join($$('LF')), block, document, reader); + } break; + } + } if (!$truthy(block)) { + + switch (block_context) { + case "listing": + case "source": + + if (($eqeq(block_context, "source") || (($not(attributes['$[]'](1)) && ($truthy((language = ($truthy(($ret_or_2 = attributes['$[]'](2))) ? ($ret_or_2) : (doc_attrs['$[]']("source-language")))))))))) { + + if ($truthy(language)) { + + attributes['$[]=']("style", "source"); + attributes['$[]=']("language", language); + $$('AttributeList').$rekey(attributes, [nil, nil, "linenums"]); + } else { + + $$('AttributeList').$rekey(attributes, [nil, "language", "linenums"]); + if (!$truthy(attributes['$key?']("language"))) { + if ($truthy(doc_attrs['$key?']("source-language"))) { + attributes['$[]=']("language", doc_attrs['$[]']("source-language")); + } + } } if (!$truthy(attributes['$key?']("linenums"))) { + if (($truthy(attributes['$[]']("linenums-option")) || ($truthy(doc_attrs['$[]']("source-linenums-option"))))) { + attributes['$[]=']("linenums", ""); + } + } if (!$truthy(attributes['$key?']("indent"))) { + if ($truthy(doc_attrs['$key?']("source-indent"))) { + attributes['$[]=']("indent", doc_attrs['$[]']("source-indent")); + } + } } block = self.$build_block("listing", "verbatim", terminator, parent, reader, attributes); + break; + case "fenced_code": + + attributes['$[]=']("style", "source"); + if ($truthy($rb_gt((ll = this_line.$length()), 3))) { + if ($truthy((comma_idx = (language = this_line.$slice(3, ll)).$index(",")))) { + if ($truthy($rb_gt(comma_idx, 0))) { + + language = language.$slice(0, comma_idx).$strip(); + if ($truthy($rb_lt(comma_idx, $rb_minus(ll, 4)))) { + attributes['$[]=']("linenums", ""); + } } else if ($truthy($rb_gt(ll, 4))) { + attributes['$[]=']("linenums", ""); + } + } else { + language = language.$lstrip(); + } + } if ($truthy(language['$nil_or_empty?']())) { + if ($truthy(doc_attrs['$key?']("source-language"))) { + attributes['$[]=']("language", doc_attrs['$[]']("source-language")); + } + } else { + attributes['$[]=']("language", language); + } if (!$truthy(attributes['$key?']("linenums"))) { + if (($truthy(attributes['$[]']("linenums-option")) || ($truthy(doc_attrs['$[]']("source-linenums-option"))))) { + attributes['$[]=']("linenums", ""); + } + } if (!$truthy(attributes['$key?']("indent"))) { + if ($truthy(doc_attrs['$key?']("source-indent"))) { + attributes['$[]=']("indent", doc_attrs['$[]']("source-indent")); + } + } terminator = terminator.$slice(0, 3); + block = self.$build_block("listing", "verbatim", terminator, parent, reader, attributes); + break; + case "table": + + block_cursor = reader.$cursor(); + block_reader = $$('Reader').$new(reader.$read_lines_until($hash2(["terminator", "skip_line_comments", "context", "cursor"], {"terminator": terminator, "skip_line_comments": true, "context": "table", "cursor": "at_mark"})), block_cursor); + if (!$truthy(terminator['$start_with?']("|", "!"))) { + if ($truthy(($ret_or_2 = attributes['$[]']("format")))) ; else { + attributes['$[]=']("format", ($truthy(terminator['$start_with?'](",")) ? ("csv") : ("dsv"))); + } + } block = self.$parse_table(block_reader, parent, attributes); + break; + case "sidebar": + block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes); + break; + case "admonition": + + attributes['$[]=']("name", (admonition_name = style.$downcase())); + attributes['$[]=']("textlabel", ($truthy(($ret_or_2 = attributes.$delete("caption"))) ? ($ret_or_2) : (doc_attrs['$[]']("" + (admonition_name) + "-caption")))); + block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes); + break; + case "open": + case "abstract": + case "partintro": + block = self.$build_block("open", "compound", terminator, parent, reader, attributes); + break; + case "literal": + block = self.$build_block(block_context, "verbatim", terminator, parent, reader, attributes); + break; + case "example": + + if ($truthy(attributes['$[]']("collapsible-option"))) { + attributes['$[]=']("caption", ""); + } block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes); + break; + case "quote": + case "verse": + + $$('AttributeList').$rekey(attributes, [nil, "attribution", "citetitle"]); + block = self.$build_block(block_context, ($eqeq(block_context, "verse") ? ("verbatim") : ("compound")), terminator, parent, reader, attributes); + break; + case "stem": + case "latexmath": + case "asciimath": + + if ($eqeq(block_context, "stem")) { + attributes['$[]=']("style", $$('STEM_TYPE_ALIASES')['$[]'](($truthy(($ret_or_2 = attributes['$[]'](2))) ? ($ret_or_2) : (doc_attrs['$[]']("stem"))))); + } block = self.$build_block("stem", "raw", terminator, parent, reader, attributes); + break; + case "pass": + block = self.$build_block(block_context, "raw", terminator, parent, reader, attributes); + break; + case "comment": + + self.$build_block(block_context, "skip", terminator, parent, reader, attributes); + attributes.$clear(); + return nil; + default: + if (($truthy(block_extensions) && ($truthy((extension = extensions['$registered_for_block?'](block_context, cloaked_context)))))) { + + if (!$eqeq((content_model = (ext_config = extension.$config())['$[]']("content_model")), "skip")) { + + if (!$truthy((positional_attrs = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))['$nil_or_empty?']())) { + $$('AttributeList').$rekey(attributes, $rb_plus([nil], positional_attrs)); + } if ($truthy((default_attrs = ext_config['$[]']("default_attrs")))) { + $send(default_attrs, 'each', [], function $$8(k, v){var $c; - return $$($nesting, 'File')['$directory?'](self.path) - }, $Pathname_directory$ques$20.$$arity = 0); - - Opal.def(self, '$extname', $Pathname_extname$21 = function $$extname() { - var self = this; + + if (k == null) k = nil; + if (v == null) v = nil; + if ($truthy(($ret_or_2 = attributes['$[]'](k)))) { + return $ret_or_2 + } else { + return ($c = [k, v], $send(attributes, '[]=', $c), $c[$c.length - 1]) + }}); + } attributes['$[]=']("cloaked-context", cloaked_context); + } if (!$truthy((block = self.$build_block(block_context, content_model, terminator, parent, reader, attributes, $hash2(["extension"], {"extension": extension}))))) { + + attributes.$clear(); + return nil; + } } else { + self.$raise("Unsupported block type " + (block_context) + " at " + (reader.$cursor())); + } + } + } if ($truthy(document.$sourcemap())) { + block['$source_location='](reader.$cursor_at_mark()); + } if ($truthy(attributes['$[]']("title"))) { + + block['$title=']((block_title = attributes.$delete("title"))); + if ($truthy($$('CAPTION_ATTRIBUTE_NAMES')['$[]'](block.$context()))) { + block.$assign_caption(attributes.$delete("caption")); + } } block['$style='](attributes['$[]']("style")); + if ($truthy((block_id = ($truthy(($ret_or_1 = block.$id())) ? ($ret_or_1) : (($a = [attributes['$[]']("id")], $send(block, 'id=', $a), $a[$a.length - 1])))))) { + + if ($truthy(($truthy(block_title) ? (block_title['$include?']($$('ATTR_REF_HEAD'))) : (block['$title?']())))) { + block.$title(); + } if (!$truthy(document.$register("refs", [block_id, block]))) { + self.$logger().$warn(self.$message_with_context("id assigned to block already in use: " + (block_id), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } } if (!$truthy(attributes['$empty?']())) { + block.$update_attributes(attributes); + } block.$commit_subs(); + if ($truthy(block['$sub?']("callouts"))) { + if (!$truthy(self.$catalog_callouts(block.$source(), document))) { + block.$remove_sub("callouts"); + } + } return block; + }, -3); + $defs(self, '$read_paragraph_lines', function $$read_paragraph_lines(reader, break_at_list, opts) { + var break_condition = nil; - return $$($nesting, 'File').$extname(self.path) - }, $Pathname_extname$21.$$arity = 0); - - Opal.def(self, '$<=>', $Pathname_$lt_eq_gt$22 = function(other) { - var self = this; + + if (opts == null) opts = $hash2([], {}); + opts['$[]=']("break_on_blank_lines", true); + opts['$[]=']("break_on_list_continuation", true); + opts['$[]=']("preserve_last_line", true); + break_condition = ($truthy(break_at_list) ? (($truthy($$('Compliance').$block_terminates_paragraph()) ? ($$('StartOfBlockOrListProc')) : ($$('StartOfListProc')))) : (($truthy($$('Compliance').$block_terminates_paragraph()) ? ($$('StartOfBlockProc')) : ($$('NoOp'))))); + return $send(reader, 'read_lines_until', [opts], break_condition.$to_proc()); + }, -3); + $defs(self, '$is_delimited_block?', function $Parser_is_delimited_block$ques$9(line, return_match_data) { + var $a, $b, self = this, line_len = nil, tip = nil, tip_len = nil, context = nil, masq = nil; - return self.$path()['$<=>'](other.$path()) - }, $Pathname_$lt_eq_gt$22.$$arity = 1); - Opal.alias(self, "eql?", "=="); - Opal.alias(self, "===", "=="); - Opal.alias(self, "to_str", "to_path"); - Opal.alias(self, "to_s", "to_path"); - Opal.const_set($nesting[0], 'SAME_PATHS', (function() {if ($truthy($$$($$($nesting, 'File'), 'FNM_SYSCASE')['$nonzero?']())) { - return $send(self, 'proc', [], ($Pathname$23 = function(a, b){var self = $Pathname$23.$$s || this; + + if (return_match_data == null) return_match_data = nil; + if (!($truthy($rb_gt((line_len = line.$length()), 1)) && ($truthy($$('DELIMITED_BLOCK_HEADS')['$[]'](line.$slice(0, 2)))))) { + return nil + } if ($eqeq(line_len, 2)) { + + tip = line; + tip_len = 2; + } else { + + if ($truthy($rb_lt(line_len, 5))) { + + tip = line; + tip_len = line_len; + } else { + tip = line.$slice(0, (tip_len = 4)); + } if (($truthy($$('Compliance').$markdown_syntax()) && ($truthy(tip['$start_with?']("`"))))) { + if ($eqeq(tip_len, 4)) { + + if (($eqeq(tip, "````") || ($neqeq((tip = tip.$chop()), "```")))) { + return nil + } line = tip; + line_len = (tip_len = 3); + } else if ($neqeq(tip, "```")) { + return nil + } + } else if ($eqeq(tip_len, 3)) { + return nil + } } $b = $$('DELIMITED_BLOCKS')['$[]'](tip), $a = $to_ary($b), (context = ($a[0] == null ? nil : $a[0])), (masq = ($a[1] == null ? nil : $a[1])); + if (($truthy(context) && (($eqeq(line_len, tip_len) || ($truthy(self['$uniform?'](line.$slice(1, line_len), $$('DELIMITED_BLOCK_TAILS')['$[]'](tip), $rb_minus(line_len, 1)))))))) { + if ($truthy(return_match_data)) { + + return $$('BlockMatchData').$new(context, masq, tip, line); + } else { + return true + } + } else { + return nil + } }, -2); + $defs(self, '$build_block', function $$build_block(block_context, content_model, terminator, parent, reader, attributes, options) { + var $a, self = this, skip_processing = nil, parse_as_content_model = nil, lines = nil, block_reader = nil, block_cursor = nil, tab_size = nil, $ret_or_2 = nil, indent = nil, extension = nil, block = nil, $ret_or_1 = nil; - - if (a == null) { - a = nil; - }; + if (options == null) options = $hash2([], {}); - if (b == null) { - b = nil; - }; - return a.$casecmp(b)['$=='](0);}, $Pathname$23.$$s = self, $Pathname$23.$$arity = 2, $Pathname$23)) - } else { - return $send(self, 'proc', [], ($Pathname$24 = function(a, b){var self = $Pathname$24.$$s || this; + switch (content_model) { + case "skip": + $a = [true, "simple"], (skip_processing = $a[0]), (parse_as_content_model = $a[1]); + break; + case "raw": + $a = [false, "simple"], (skip_processing = $a[0]), (parse_as_content_model = $a[1]); + break; + default: + $a = [false, content_model], (skip_processing = $a[0]), (parse_as_content_model = $a[1]); + } if ($truthy(terminator['$nil?']())) { + + if ($eqeq(parse_as_content_model, "verbatim")) { + lines = reader.$read_lines_until($hash2(["break_on_blank_lines", "break_on_list_continuation"], {"break_on_blank_lines": true, "break_on_list_continuation": true})); + } else { + + if ($eqeq(content_model, "compound")) { + content_model = "simple"; + } lines = self.$read_paragraph_lines(reader, false, $hash2(["skip_line_comments", "skip_processing"], {"skip_line_comments": true, "skip_processing": skip_processing})); + } block_reader = nil; + } else if ($neqeq(parse_as_content_model, "compound")) { + + lines = reader.$read_lines_until($hash2(["terminator", "skip_processing", "context", "cursor"], {"terminator": terminator, "skip_processing": skip_processing, "context": block_context, "cursor": "at_mark"})); + block_reader = nil; + } else if ($eqeq(terminator, false)) { + + lines = nil; + block_reader = reader; + } else { + + lines = nil; + block_cursor = reader.$cursor(); + block_reader = $$('Reader').$new(reader.$read_lines_until($hash2(["terminator", "skip_processing", "context", "cursor"], {"terminator": terminator, "skip_processing": skip_processing, "context": block_context, "cursor": "at_mark"})), block_cursor); + } + switch (content_model) { + case "verbatim": + + tab_size = ($truthy(($ret_or_2 = attributes['$[]']("tabsize"))) ? ($ret_or_2) : (parent.$document().$attributes()['$[]']("tabsize"))).$to_i(); + if ($truthy((indent = attributes['$[]']("indent")))) { + self['$adjust_indentation!'](lines, indent.$to_i(), tab_size); + } else if ($truthy($rb_gt(tab_size, 0))) { + self['$adjust_indentation!'](lines, -1, tab_size); + } break; + case "skip": + return nil + } if ($truthy((extension = options['$[]']("extension")))) { + + attributes.$delete("style"); + if (($truthy((block = extension.$process_method()['$[]'](parent, ($truthy(($ret_or_1 = block_reader)) ? ($ret_or_1) : ($$('Reader').$new(lines))), attributes.$merge()))) && ($neqeq(block, parent)))) { + + attributes.$replace(block.$attributes()); + if ((($eqeq(block.$content_model(), "compound") && ($eqeqeq($$('Block'), block))) && ($not((lines = block.$lines())['$empty?']())))) { + + content_model = "compound"; + block_reader = $$('Reader').$new(lines); + } } else { + return nil + } } else { + block = $$('Block').$new(parent, block_context, $hash2(["content_model", "source", "attributes"], {"content_model": content_model, "source": lines, "attributes": attributes})); + } if ($eqeq(content_model, "compound")) { + self.$parse_blocks(block_reader, block); + } return block; + }, -7); + $defs(self, '$parse_blocks', function $$parse_blocks(reader, parent, attributes) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, block = nil; - - - if (a == null) { - a = nil; - }; - if (b == null) { - b = nil; - }; - return a['$=='](b);}, $Pathname$24.$$s = self, $Pathname$24.$$arity = 2, $Pathname$24)) - }; return nil; })()); - - Opal.def(self, '$relative_path_from', $Pathname_relative_path_from$25 = function $$relative_path_from(base_directory) { - var $a, $b, $c, self = this, dest_directory = nil, dest_prefix = nil, dest_names = nil, r = nil, basename = nil, base_prefix = nil, base_names = nil, relpath_names = nil; + if (attributes == null) attributes = nil; + if ($truthy(attributes)) { + while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = (block = self.$next_block(reader, parent, attributes.$merge())))) ? (parent.$blocks()['$<<'](block)) : ($ret_or_2)))) ? ($ret_or_1) : (reader['$has_more_lines?']())))) { + + } + } else { + while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = (block = self.$next_block(reader, parent)))) ? (parent.$blocks()['$<<'](block)) : ($ret_or_2)))) ? ($ret_or_1) : (reader['$has_more_lines?']())))) { + + } + } return nil; + }, -3); + $defs(self, '$parse_list', function $$parse_list(reader, list_type, parent, style) { + var $a, self = this, list_block = nil, list_rx = nil, $ret_or_1 = nil, list_item = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; - - dest_directory = self.$cleanpath().$to_s(); - base_directory = base_directory.$cleanpath().$to_s(); - dest_prefix = dest_directory; - dest_names = []; - while ($truthy((r = self.$chop_basename(dest_prefix)))) { - - $c = r, $b = Opal.to_ary($c), (dest_prefix = ($b[0] == null ? nil : $b[0])), (basename = ($b[1] == null ? nil : $b[1])), $c; - if ($truthy(basename['$!=']("."))) { - dest_names.$unshift(basename)}; - }; - base_prefix = base_directory; - base_names = []; - while ($truthy((r = self.$chop_basename(base_prefix)))) { - $c = r, $b = Opal.to_ary($c), (base_prefix = ($b[0] == null ? nil : $b[0])), (basename = ($b[1] == null ? nil : $b[1])), $c; - if ($truthy(basename['$!=']("."))) { - base_names.$unshift(basename)}; - }; - if ($truthy($$($nesting, 'SAME_PATHS')['$[]'](dest_prefix, base_prefix))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "different prefix: " + (dest_prefix.$inspect()) + " and " + (base_directory.$inspect())) - }; - while ($truthy(($truthy($b = ($truthy($c = dest_names['$empty?']()['$!']()) ? base_names['$empty?']()['$!']() : $c)) ? $$($nesting, 'SAME_PATHS')['$[]'](dest_names.$first(), base_names.$first()) : $b))) { + list_block = $$('List').$new(parent, list_type); + list_rx = $$('ListRxMap')['$[]'](list_type); + while ($truthy(($truthy(($ret_or_1 = reader['$has_more_lines?']())) ? (list_rx['$=~'](reader.$peek_line())) : ($ret_or_1)))) { - dest_names.$shift(); - base_names.$shift(); - }; - if ($truthy(base_names['$include?'](".."))) { - self.$raise($$($nesting, 'ArgumentError'), "" + "base_directory has ..: " + (base_directory.$inspect()))}; - base_names.$fill(".."); - relpath_names = $rb_plus(base_names, dest_names); - if ($truthy(relpath_names['$empty?']())) { - return $$($nesting, 'Pathname').$new(".") - } else { - return $$($nesting, 'Pathname').$new($send($$($nesting, 'File'), 'join', Opal.to_a(relpath_names))) - }; - }, $Pathname_relative_path_from$25.$$arity = 1); - return (Opal.def(self, '$entries', $Pathname_entries$26 = function $$entries() { - var $$27, self = this; - - return $send($$($nesting, 'Dir').$entries(self.path), 'map', [], ($$27 = function(f){var self = $$27.$$s || this; + if ($truthy((list_item = self.$parse_list_item(reader, list_block, $gvars["~"], (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), style)))) { + list_block.$items()['$<<'](list_item); + } if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) ; else { + break + } } return list_block; + }); + $defs(self, '$catalog_callouts', function $$catalog_callouts(text, document) { + var found = nil, autonum = nil; - - if (f == null) { - f = nil; - }; - return self.$class().$new(f);}, $$27.$$s = self, $$27.$$arity = 1, $$27)) - }, $Pathname_entries$26.$$arity = 0), nil) && 'entries'; - })($nesting[0], null, $nesting); - return (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); - - var $nesting = [self].concat($parent_nesting), $Kernel_Pathname$28; - - - Opal.def(self, '$Pathname', $Kernel_Pathname$28 = function $$Pathname(path) { - var self = this; - - return $$($nesting, 'Pathname').$new(path) - }, $Kernel_Pathname$28.$$arity = 1) - })($nesting[0], $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/pathname"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass; - - Opal.add_stubs(['$require', '$include', '$to_str', '$!', '$absolute?']); - - self.$require("pathname"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Pathname'); - - var $nesting = [self].concat($parent_nesting), $Pathname_absolute$ques$1, $Pathname_relative$ques$2, $Pathname_to_path$3; - if (self.__path__ == null) self.__path__ = nil; - - self.$$prototype.path = nil; - - self.$include($$($nesting, 'Comparable')); - self.__path__ = __nccwpck_require__(1017); - var __path__ = self.__path__; - - Opal.def(self, '$absolute?', $Pathname_absolute$ques$1 = function() { - var self = this; - - return __path__.isAbsolute(self.path.$to_str()) - }, $Pathname_absolute$ques$1.$$arity = 0); - - Opal.def(self, '$relative?', $Pathname_relative$ques$2 = function() { - var self = this; - - return self['$absolute?']()['$!']() - }, $Pathname_relative$ques$2.$$arity = 0); - return (Opal.def(self, '$to_path', $Pathname_to_path$3 = function $$to_path() { - var self = this; - - return self.path - }, $Pathname_to_path$3.$$arity = 0), nil) && 'to_path'; - })($nesting[0], null, $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs/env"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; - - Opal.add_stubs(['$new', '$to_s']); - - Opal.const_set($nesting[0], 'ENV', $$($nesting, 'Object').$new()); - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $$$1, $$$eq$2, $key$ques$3, $empty$ques$4, $keys$5, $delete$6, $to_s$7; - - - - Opal.def(self, '$[]', $$$1 = function(name) { - var self = this; - - return process.env[name] || nil - }, $$$1.$$arity = 1); - - Opal.def(self, '$[]=', $$$eq$2 = function(name, value) { - var self = this; - - return process.env[name.$to_s()] = value.$to_s() - }, $$$eq$2.$$arity = 2); - - Opal.def(self, '$key?', $key$ques$3 = function(name) { - var self = this; - - return process.env.hasOwnProperty(name) - }, $key$ques$3.$$arity = 1); - Opal.alias(self, "has_key?", "key?"); - Opal.alias(self, "include?", "key?"); - Opal.alias(self, "member?", "key?"); - - Opal.def(self, '$empty?', $empty$ques$4 = function() { - var self = this; - - return Object.keys(process.env).length === 0; - }, $empty$ques$4.$$arity = 0); - - Opal.def(self, '$keys', $keys$5 = function $$keys() { - var self = this; - - return Object.keys(process.env); - }, $keys$5.$$arity = 0); - - Opal.def(self, '$delete', $delete$6 = function(name) { - var self = this; - - - var value = process.env[name] || nil; - delete process.env[name]; - return value; - - }, $delete$6.$$arity = 1); - return (Opal.def(self, '$to_s', $to_s$7 = function $$to_s() { - var self = this; - - return "ENV" - }, $to_s$7.$$arity = 0), nil) && 'to_s'; - })(Opal.get_singleton_class($$($nesting, 'ENV')), $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["nodejs"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; - - Opal.add_stubs(['$require']); - - (function($base, $parent_nesting) { - var self = $module($base, 'NodeJS'); - - var $nesting = [self].concat($parent_nesting); - - nil - })($nesting[0], $nesting); - self.$require("nodejs/kernel"); - self.$require("nodejs/file"); - self.$require("nodejs/dir"); - self.$require("nodejs/io"); - self.$require("nodejs/open-uri"); - self.$require("nodejs/pathname"); - return self.$require("nodejs/env"); -}; - - -/***/ }), - -/***/ 4274: -/***/ (function() { - -(function(undefined) { - // @note - // A few conventions for the documentation of this file: - // 1. Always use "//" (in contrast with "/**/") - // 2. The syntax used is Yardoc (yardoc.org), which is intended for Ruby (se below) - // 3. `@param` and `@return` types should be preceded by `JS.` when referring to - // JavaScript constructors (e.g. `JS.Function`) otherwise Ruby is assumed. - // 4. `nil` and `null` being unambiguous refer to the respective - // objects/values in Ruby and JavaScript - // 5. This is still WIP :) so please give feedback and suggestions on how - // to improve or for alternative solutions - // - // The way the code is digested before going through Yardoc is a secret kept - // in the docs repo (https://github.com/opal/docs/tree/master). - - var global_object = this, console; - - // Detect the global object - if (typeof(global) !== 'undefined') { global_object = global; } - if (typeof(window) !== 'undefined') { global_object = window; } - - // Setup a dummy console object if missing - if (typeof(global_object.console) === 'object') { - console = global_object.console; - } else if (global_object.console == null) { - console = global_object.console = {}; - } else { - console = {}; - } - - if (!('log' in console)) { console.log = function () {}; } - if (!('warn' in console)) { console.warn = console.log; } - - if (typeof(global_object.Opal) !== 'undefined') { - console.warn('Opal already loaded. Loading twice can cause troubles, please fix your setup.'); - return global_object.Opal; - } - - var nil; - - // The actual class for BasicObject - var BasicObject; - - // The actual Object class. - // The leading underscore is to avoid confusion with window.Object() - var _Object; - - // The actual Module class - var Module; - - // The actual Class class - var Class; - - // The Opal object that is exposed globally - var Opal = this.Opal = {}; - - // This is a useful reference to global object inside ruby files - Opal.global = global_object; - global_object.Opal = Opal; - - // Configure runtime behavior with regards to require and unsupported fearures - Opal.config = { - missing_require_severity: 'error', // error, warning, ignore - unsupported_features_severity: 'warning', // error, warning, ignore - enable_stack_trace: true // true, false - } - - // Minify common function calls - var $hasOwn = Object.hasOwnProperty; - var $bind = Function.prototype.bind; - var $setPrototype = Object.setPrototypeOf; - var $slice = Array.prototype.slice; - var $splice = Array.prototype.splice; - - // Nil object id is always 4 - var nil_id = 4; - - // Generates even sequential numbers greater than 4 - // (nil_id) to serve as unique ids for ruby objects - var unique_id = nil_id; - - // Return next unique id - Opal.uid = function() { - unique_id += 2; - return unique_id; - }; - - // Retrieve or assign the id of an object - Opal.id = function(obj) { - if (obj.$$is_number) return (obj * 2)+1; - if (obj.$$id != null) { - return obj.$$id; - }; - $defineProperty(obj, '$$id', Opal.uid()); - return obj.$$id; - }; - - // Globals table - Opal.gvars = {}; - - // Exit function, this should be replaced by platform specific implementation - // (See nodejs and chrome for examples) - Opal.exit = function(status) { if (Opal.gvars.DEBUG) console.log('Exited with status '+status); }; - - // keeps track of exceptions for $! - Opal.exceptions = []; - - // @private - // Pops an exception from the stack and updates `$!`. - Opal.pop_exception = function() { - Opal.gvars["!"] = Opal.exceptions.pop() || nil; - } - - // Inspect any kind of object, including non Ruby ones - Opal.inspect = function(obj) { - if (obj === undefined) { - return "undefined"; - } - else if (obj === null) { - return "null"; - } - else if (!obj.$$class) { - return obj.toString(); - } - else { - return obj.$inspect(); - } - } + found = false; + autonum = 0; + if ($truthy(text['$include?']("<"))) { + $send(text, 'scan', [$$('CalloutScanRx')], function $$10(){var $a; - function $defineProperty(object, name, initialValue) { - if (typeof(object) === "string") { - // Special case for: - // s = "string" - // def s.m; end - // String class is the only class that: - // + compiles to JS primitive - // + allows method definition directly on instances - // numbers, true, false and nil do not support it. - object[name] = initialValue; - } else { - Object.defineProperty(object, name, { - value: initialValue, - enumerable: false, - configurable: true, - writable: true + + if (!$truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']("\\"))) { + document.$callouts().$register(($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))); + } return (found = true);}); + } return found; }); - } - } - - Opal.defineProperty = $defineProperty; - - Opal.slice = $slice; - - - // Truth - // ----- - - Opal.truthy = function(val) { - return (val !== nil && val != null && (!val.$$is_boolean || val == true)); - }; - - Opal.falsy = function(val) { - return (val === nil || val == null || (val.$$is_boolean && val == false)) - }; - - - // Constants - // --------- - // - // For future reference: - // - The Rails autoloading guide (http://guides.rubyonrails.org/v5.0/autoloading_and_reloading_constants.html) - // - @ConradIrwin's 2012 post on “Everything you ever wanted to know about constant lookup in Ruby” (http://cirw.in/blog/constant-lookup.html) - // - // Legend of MRI concepts/names: - // - constant reference (cref): the module/class that acts as a namespace - // - nesting: the namespaces wrapping the current scope, e.g. nesting inside - // `module A; module B::C; end; end` is `[B::C, A]` - - // Get the constant in the scope of the current cref - function const_get_name(cref, name) { - if (cref) return cref.$$const[name]; - } - - // Walk up the nesting array looking for the constant - function const_lookup_nesting(nesting, name) { - var i, ii, result, constant; - - if (nesting.length === 0) return; - - // If the nesting is not empty the constant is looked up in its elements - // and in order. The ancestors of those elements are ignored. - for (i = 0, ii = nesting.length; i < ii; i++) { - constant = nesting[i].$$const[name]; - if (constant != null) return constant; - } - } - - // Walk up the ancestors chain looking for the constant - function const_lookup_ancestors(cref, name) { - var i, ii, result, ancestors; - - if (cref == null) return; - - ancestors = Opal.ancestors(cref); - - for (i = 0, ii = ancestors.length; i < ii; i++) { - if (ancestors[i].$$const && $hasOwn.call(ancestors[i].$$const, name)) { - return ancestors[i].$$const[name]; - } - } - } - - // Walk up Object's ancestors chain looking for the constant, - // but only if cref is missing or a module. - function const_lookup_Object(cref, name) { - if (cref == null || cref.$$is_module) { - return const_lookup_ancestors(_Object, name); - } - } - - // Call const_missing if nothing else worked - function const_missing(cref, name, skip_missing) { - if (!skip_missing) { - return (cref || _Object).$const_missing(name); - } - } - - // Look for the constant just in the current cref or call `#const_missing` - Opal.const_get_local = function(cref, name, skip_missing) { - var result; - - if (cref == null) return; - - if (cref === '::') cref = _Object; - - if (!cref.$$is_module && !cref.$$is_class) { - throw new Opal.TypeError(cref.toString() + " is not a class/module"); - } - - result = const_get_name(cref, name); if (result != null) return result; - result = const_missing(cref, name, skip_missing); if (result != null) return result; - } + $defs(self, '$catalog_inline_anchor', function $$catalog_inline_anchor(id, reftext, node, location, doc) { + var self = this; - // Look for the constant relative to a cref or call `#const_missing` (when the - // constant is prefixed by `::`). - Opal.const_get_qualified = function(cref, name, skip_missing) { - var result, cache, cached, current_version = Opal.const_cache_version; + + if (doc == null) doc = node.$document(); + if (($truthy(reftext) && ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))))) { + reftext = doc.$sub_attributes(reftext); + } if (!$truthy(doc.$register("refs", [id, $$('Inline').$new(node, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id}))]))) { + + if ($eqeqeq($$('Reader'), location)) { + location = location.$cursor(); + } self.$logger().$warn(self.$message_with_context("id assigned to anchor already in use: " + (id), $hash2(["source_location"], {"source_location": location}))); + } return nil; + }, -5); + $defs(self, '$catalog_inline_anchors', function $$catalog_inline_anchors(text, block, document, reader) { + var self = this; - if (cref == null) return; + + if (($truthy(text['$include?']("[[")) || ($truthy(text['$include?']("or:"))))) { + $send(text, 'scan', [$$('InlineAnchorScanRx')], function $$11(){var $a, self = $$11.$$s == null ? this : $$11.$$s, id = nil, reftext = nil, location = nil, offset = nil; - if (cref === '::') cref = _Object; + + if ($truthy((id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) { + if ((($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) && ($truthy(reftext['$include?']($$('ATTR_REF_HEAD'))))) && ($truthy((reftext = document.$sub_attributes(reftext))['$empty?']())))) { + return nil + } + } else { + + id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + if ($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))) { + if ($truthy(reftext['$include?']("]"))) { + + reftext = reftext.$gsub("\\]", "]"); + if ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))) { + reftext = document.$sub_attributes(reftext); + } } else if ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))) { + if ($truthy((reftext = document.$sub_attributes(reftext))['$empty?']())) { + reftext = nil; + } + } + } } if ($truthy(document.$register("refs", [id, $$('Inline').$new(block, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id}))]))) { + return nil + } else { + + location = reader.$cursor_at_mark(); + if ($truthy($rb_gt((offset = $rb_plus((($a = $gvars['~']) === nil ? nil : $a.$pre_match()).$count($$('LF')), ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('LF'))) ? (1) : (0)))), 0))) { + (location = location.$dup()).$advance(offset); + } return self.$logger().$warn(self.$message_with_context("id assigned to anchor already in use: " + (id), $hash2(["source_location"], {"source_location": location}))); + }}, {$$s: self}); + } return nil; + }); + $defs(self, '$catalog_inline_biblio_anchor', function $$catalog_inline_biblio_anchor(id, reftext, node, reader) { + var self = this, $ret_or_1 = nil; - if (!cref.$$is_module && !cref.$$is_class) { - throw new Opal.TypeError(cref.toString() + " is not a class/module"); - } + + if (!$truthy(node.$document().$register("refs", [id, $$('Inline').$new(node, "anchor", ($truthy(($ret_or_1 = reftext)) ? ("[" + (reftext) + "]") : ($ret_or_1)), $hash2(["type", "id"], {"type": "bibref", "id": id}))]))) { + self.$logger().$warn(self.$message_with_context("id assigned to bibliography anchor already in use: " + (id), $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } return nil; + }); + $defs(self, '$parse_description_list', function $$parse_description_list(reader, match, parent) { + var self = this, list_block = nil, sibling_pattern = nil, current_pair = nil, $ret_or_1 = nil, next_pair = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; - if ((cache = cref.$$const_cache) == null) { - $defineProperty(cref, '$$const_cache', Object.create(null)); - cache = cref.$$const_cache; - } - cached = cache[name]; + + list_block = $$('List').$new(parent, "dlist"); + sibling_pattern = $$('DescriptionListSiblingRx')['$[]'](match['$[]'](2)); + list_block.$items()['$<<']((current_pair = self.$parse_list_item(reader, list_block, match, sibling_pattern))); + while ($truthy(($truthy(($ret_or_1 = reader['$has_more_lines?']())) ? (sibling_pattern['$=~'](reader.$peek_line())) : ($ret_or_1)))) { + + next_pair = self.$parse_list_item(reader, list_block, $gvars["~"], sibling_pattern); + if ($truthy(current_pair['$[]'](1))) { + list_block.$items()['$<<']((current_pair = next_pair)); + } else { + + current_pair['$[]'](0)['$<<'](next_pair['$[]'](0)['$[]'](0)); + current_pair['$[]='](1, next_pair['$[]'](1)); + } } return list_block; + }); + $defs(self, '$parse_callout_list', function $$parse_callout_list(reader, match, parent, callouts) { + var self = this, list_block = nil, next_index = nil, autonum = nil, $ret_or_1 = nil, $ret_or_2 = nil, num = nil, list_item = nil, coids = nil; - if (cached == null || cached[0] !== current_version) { - ((result = const_get_name(cref, name)) != null) || - ((result = const_lookup_ancestors(cref, name)) != null); - cache[name] = [current_version, result]; - } else { - result = cached[1]; - } + + list_block = $$('List').$new(parent, "colist"); + next_index = 1; + autonum = 0; + while ($truthy(($truthy(($ret_or_1 = match)) ? ($ret_or_1) : (($truthy(($ret_or_2 = (match = $$('CalloutListRx').$match(reader.$peek_line())))) ? (reader.$mark()) : ($ret_or_2)))))) { + + if ($eqeq((num = match['$[]'](1)), ".")) { + num = (autonum = $rb_plus(autonum, 1)).$to_s(); + } if (!$eqeq(num, next_index.$to_s())) { + self.$logger().$warn(self.$message_with_context("callout list item index: expected " + (next_index) + ", got " + (num), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } if ($truthy((list_item = self.$parse_list_item(reader, list_block, match, "<1>")))) { + + list_block.$items()['$<<'](list_item); + if ($truthy((coids = callouts.$callout_ids(list_block.$items().$size()))['$empty?']())) { + self.$logger().$warn(self.$message_with_context("no callout found for <" + (list_block.$items().$size()) + ">", $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()}))); + } else { + list_item.$attributes()['$[]=']("coids", coids); + } } next_index = $rb_plus(next_index, 1); + match = nil; + } callouts.$next_list(); + return list_block; + }); + $defs(self, '$parse_list_item', function $$parse_list_item(reader, list_block, match, sibling_trait, style) { + var $a, $b, self = this, list_type = nil, dlist = nil, list_term = nil, term_text = nil, $ret_or_1 = nil, item_text = nil, has_text = nil, list_item = nil, sourcemap_assignment_deferred = nil, ordinal = nil, implicit_style = nil, $ret_or_2 = nil, $ret_or_3 = nil, block_cursor = nil, list_item_reader = nil, comment_lines = nil, subsequent_line = nil, content_adjacent = nil, block = nil, first_block = nil; - return result != null ? result : const_missing(cref, name, skip_missing); - }; + + if (style == null) style = nil; + if ($eqeq((list_type = list_block.$context()), "dlist")) { + + dlist = true; + list_term = $$('ListItem').$new(list_block, (term_text = match['$[]'](1))); + if (($truthy(term_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](term_text))))) { + self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) ? ($ret_or_1) : ((($a = $gvars['~']) === nil ? nil : $a.$post_match()).$lstrip())), list_term, reader); + } if ($truthy((item_text = match['$[]'](3)))) { + has_text = true; + } list_item = $$('ListItem').$new(list_block, item_text); + if ($truthy(list_block.$document().$sourcemap())) { + + list_term['$source_location='](reader.$cursor()); + if ($truthy(has_text)) { + list_item['$source_location='](list_term.$source_location()); + } else { + sourcemap_assignment_deferred = true; + } } } else { + + has_text = true; + list_item = $$('ListItem').$new(list_block, (item_text = match['$[]'](2))); + if ($truthy(list_block.$document().$sourcemap())) { + list_item['$source_location='](reader.$cursor()); + } + switch (list_type) { + case "ulist": + + list_item['$marker='](sibling_trait); + if ($truthy(item_text['$start_with?']("["))) { + if (($truthy(style) && ($eqeq(style, "bibliography")))) { + if ($truthy($$('InlineBiblioAnchorRx')['$=~'](item_text))) { + self.$catalog_inline_biblio_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader); + } + } else if ($truthy(item_text['$start_with?']("[["))) { + if ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))) { + self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader); + } + } else if ($truthy(item_text['$start_with?']("[ ] ", "[x] ", "[*] "))) { + + list_block.$set_option("checklist"); + list_item.$attributes()['$[]=']("checkbox", ""); + if (!$truthy(item_text['$start_with?']("[ "))) { + list_item.$attributes()['$[]=']("checked", ""); + } list_item['$text='](item_text.$slice(4, item_text.$length())); + } + } break; + case "olist": + + $b = self.$resolve_ordered_list_marker(sibling_trait, (ordinal = list_block.$items().$size()), true, reader), $a = $to_ary($b), (sibling_trait = ($a[0] == null ? nil : $a[0])), (implicit_style = ($a[1] == null ? nil : $a[1])); + list_item['$marker='](sibling_trait); + if (($eqeq(ordinal, 0) && ($not(style)))) { + list_block['$style='](($truthy(($ret_or_2 = implicit_style)) ? ($ret_or_2) : (($truthy(($ret_or_3 = $$('ORDERED_LIST_STYLES')['$[]']($rb_minus(sibling_trait.$length(), 1)))) ? ($ret_or_3) : ("arabic")).$to_s()))); + } if (($truthy(item_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))))) { + self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader); + } break; + default: + + list_item['$marker='](sibling_trait); + if (($truthy(item_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))))) { + self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader); + } } } reader.$shift(); + block_cursor = reader.$cursor(); + list_item_reader = $$('Reader').$new(self.$read_lines_for_list_item(reader, list_type, sibling_trait, has_text), block_cursor); + if ($truthy(list_item_reader['$has_more_lines?']())) { + + if ($truthy(sourcemap_assignment_deferred)) { + list_item['$source_location='](block_cursor); + } comment_lines = list_item_reader.$skip_line_comments(); + if ($truthy((subsequent_line = list_item_reader.$peek_line()))) { + + if (!$truthy(comment_lines['$empty?']())) { + list_item_reader.$unshift_lines(comment_lines); + } if (!$truthy(subsequent_line['$empty?']())) { + + content_adjacent = true; + if (!$truthy(dlist)) { + has_text = nil; + } } } if ($truthy((block = self.$next_block(list_item_reader, list_item, $hash2([], {}), $hash2(["text_only", "list_type"], {"text_only": ($truthy(has_text) ? (nil) : (true)), "list_type": list_type}))))) { + list_item.$blocks()['$<<'](block); + } while ($truthy(list_item_reader['$has_more_lines?']())) { + if ($truthy((block = self.$next_block(list_item_reader, list_item, $hash2([], {}), $hash2(["list_type"], {"list_type": list_type}))))) { + list_item.$blocks()['$<<'](block); + } + } if ((($truthy(content_adjacent) && ($truthy((first_block = list_item.$blocks()['$[]'](0))))) && ($eqeq(first_block.$context(), "paragraph")))) { + list_item.$fold_first(); + } } if ($truthy(dlist)) { + return [[list_term], (($truthy(list_item['$text?']()) || ($truthy(list_item['$blocks?']()))) ? (list_item) : (nil))] + } else { + return list_item + } }, -5); + $defs(self, '$read_lines_for_list_item', function $$read_lines_for_list_item(reader, list_type, sibling_trait, has_text) { + var $a, self = this, buffer = nil, continuation = nil, within_nested_list = nil, detached_continuation = nil, dlist = nil, this_line = nil, prev_line = nil, match = nil, block_attribute_lines = nil, next_line = nil, interrupt = nil, ch0 = nil, nested_list_type = nil, $ret_or_1 = nil, last_line = nil; - // Initialize the top level constant cache generation counter - Opal.const_cache_version = 1; + + if (sibling_trait == null) sibling_trait = nil; + if (has_text == null) has_text = true; + buffer = []; + continuation = "inactive"; + within_nested_list = false; + detached_continuation = nil; + dlist = list_type['$==']("dlist"); + while ($truthy(reader['$has_more_lines?']())) { + + this_line = reader.$read_line(); + if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) { + break + } prev_line = ($truthy(buffer['$empty?']()) ? (nil) : (buffer['$[]'](-1))); + if ($eqeq(prev_line, $$('LIST_CONTINUATION'))) { + + if ($eqeq(continuation, "inactive")) { + + continuation = "active"; + has_text = true; + if (!$truthy(within_nested_list)) { + buffer['$[]='](-1, ""); + } } if ($eqeq(this_line, $$('LIST_CONTINUATION'))) { + + if ($neqeq(continuation, "frozen")) { + + continuation = "frozen"; + buffer['$<<'](this_line); + } this_line = nil; + continue; + } } if ($truthy((match = self['$is_delimited_block?'](this_line, true)))) { + + if (!$eqeq(continuation, "active")) { + break + } buffer['$<<'](this_line); + buffer.$concat(reader.$read_lines_until($hash2(["terminator", "read_last_line", "context"], {"terminator": match.$terminator(), "read_last_line": true, "context": nil}))); + continuation = "inactive"; + } else if (((($truthy(dlist) && ($neqeq(continuation, "active"))) && ($truthy(this_line['$start_with?']("[")))) && ($truthy($$('BlockAttributeLineRx')['$match?'](this_line))))) { + + block_attribute_lines = [this_line]; + while ($truthy((next_line = reader.$peek_line()))) { + + if ($truthy(self['$is_delimited_block?'](next_line))) { + interrupt = true; + } else if (($truthy(next_line['$empty?']()) || (($truthy(next_line['$start_with?']("[")) && ($truthy($$('BlockAttributeLineRx')['$match?'](next_line))))))) { + + block_attribute_lines['$<<'](reader.$read_line()); + continue; + } else if (($truthy($$('AnyListRx')['$match?'](next_line)) && ($not(self['$is_sibling_list_item?'](next_line, list_type, sibling_trait))))) { + buffer.$concat(block_attribute_lines); + } else { + interrupt = true; + } break; + } if ($truthy(interrupt)) { + + reader.$unshift_lines(block_attribute_lines); + break; + } } else if (($eqeq(continuation, "active") && ($not(this_line['$empty?']())))) { + if ($truthy($$('LiteralParagraphRx')['$match?'](this_line))) { + + reader.$unshift_line(this_line); + if ($truthy(dlist)) { + buffer.$concat($send(reader, 'read_lines_until', [$hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})], function $$12(line){var self = $$12.$$s == null ? this : $$12.$$s; - // Look for the constant in the open using the current nesting and the nearest - // cref ancestors or call `#const_missing` (when the constant has no :: prefix). - Opal.const_get_relative = function(nesting, name, skip_missing) { - var cref = nesting[0], result, current_version = Opal.const_cache_version, cache, cached; + + if (line == null) line = nil; + return self['$is_sibling_list_item?'](line, list_type, sibling_trait);}, {$$s: self})); + } else { + buffer.$concat(reader.$read_lines_until($hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true}))); + } continuation = "inactive"; + } else if (((($eqeq((ch0 = this_line.$chr()), ".") && ($truthy($$('BlockTitleRx')['$match?'](this_line)))) || (($eqeq(ch0, "[") && ($truthy($$('BlockAttributeLineRx')['$match?'](this_line)))))) || (($eqeq(ch0, ":") && ($truthy($$('AttributeEntryRx')['$match?'](this_line))))))) { + buffer['$<<'](this_line); + } else { + + if ($truthy((nested_list_type = $send(($truthy(within_nested_list) ? (["dlist"]) : ($$('NESTABLE_LIST_CONTEXTS'))), 'find', [], function $$13(ctx){ + + if (ctx == null) ctx = nil; + return $$('ListRxMap')['$[]'](ctx)['$match?'](this_line);})))) { + + within_nested_list = true; + if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) { + has_text = false; + } } buffer['$<<'](this_line); + continuation = "inactive"; + } + } else if (($truthy(prev_line) && ($truthy(prev_line['$empty?']())))) { + + if ($truthy(this_line['$empty?']())) { + + if (!$truthy((this_line = ($truthy(($ret_or_1 = reader.$skip_blank_lines())) ? (reader.$read_line()) : ($ret_or_1))))) { + break + } if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) { + break + } } if ($eqeq(this_line, $$('LIST_CONTINUATION'))) { + + detached_continuation = buffer.$size(); + buffer['$<<'](this_line); + } else if ($truthy(has_text)) { + if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) { + break + } else if ($truthy((nested_list_type = $send($$('NESTABLE_LIST_CONTEXTS'), 'find', [], function $$14(ctx){ + + if (ctx == null) ctx = nil; + return $$('ListRxMap')['$[]'](ctx)['$=~'](this_line);})))) { + + buffer['$<<'](this_line); + within_nested_list = true; + if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) { + has_text = false; + } } else if ($truthy($$('LiteralParagraphRx')['$match?'](this_line))) { + + reader.$unshift_line(this_line); + if ($truthy(dlist)) { + buffer.$concat($send(reader, 'read_lines_until', [$hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})], function $$15(line){var self = $$15.$$s == null ? this : $$15.$$s; - if ((cache = nesting.$$const_cache) == null) { - $defineProperty(nesting, '$$const_cache', Object.create(null)); - cache = nesting.$$const_cache; - } - cached = cache[name]; + + if (line == null) line = nil; + return self['$is_sibling_list_item?'](line, list_type, sibling_trait);}, {$$s: self})); + } else { + buffer.$concat(reader.$read_lines_until($hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true}))); + } } else { + break + } + } else { + + if (!$truthy(within_nested_list)) { + buffer.$pop(); + } buffer['$<<'](this_line); + has_text = true; + } } else { + + if (!$truthy(this_line['$empty?']())) { + has_text = true; + } if ($truthy((nested_list_type = $send(($truthy(within_nested_list) ? (["dlist"]) : ($$('NESTABLE_LIST_CONTEXTS'))), 'find', [], function $$16(ctx){ + + if (ctx == null) ctx = nil; + return $$('ListRxMap')['$[]'](ctx)['$=~'](this_line);})))) { + + within_nested_list = true; + if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) { + has_text = false; + } } buffer['$<<'](this_line); + } this_line = nil; + } if ($truthy(this_line)) { + reader.$unshift_line(this_line); + } if ($truthy(detached_continuation)) { + buffer['$[]='](detached_continuation, ""); + } while (!($truthy(buffer['$empty?']()))) { + if ($truthy((last_line = buffer['$[]'](-1))['$empty?']())) { + buffer.$pop(); + } else { + + if ($eqeq(last_line, $$('LIST_CONTINUATION'))) { + buffer.$pop(); + } break; + } + } return buffer; + }, -3); + $defs(self, '$initialize_section', function $$initialize_section(reader, parent, attributes) { + var $a, $b, self = this, document = nil, book = nil, doctype = nil, source_location = nil, sect_style = nil, sect_id = nil, sect_reftext = nil, sect_title = nil, sect_level = nil, sect_atx = nil, sect_name = nil, sect_special = nil, sect_numbered = nil, section = nil, $ret_or_1 = nil, id = nil, generated_id = nil; + + + if (attributes == null) attributes = $hash2([], {}); + document = parent.$document(); + book = (doctype = document.$doctype())['$==']("book"); + if ($truthy(document.$sourcemap())) { + source_location = reader.$cursor(); + } sect_style = attributes['$[]'](1); + $b = self.$parse_section_title(reader, document, attributes['$[]']("id")), $a = $to_ary($b), (sect_id = ($a[0] == null ? nil : $a[0])), (sect_reftext = ($a[1] == null ? nil : $a[1])), (sect_title = ($a[2] == null ? nil : $a[2])), (sect_level = ($a[3] == null ? nil : $a[3])), (sect_atx = ($a[4] == null ? nil : $a[4])); + if ($truthy(sect_style)) { + if (($truthy(book) && ($eqeq(sect_style, "abstract")))) { + $a = ["chapter", 1], (sect_name = $a[0]), (sect_level = $a[1]); + } else if (($truthy(sect_style['$start_with?']("sect")) && ($truthy($$('SectionLevelStyleRx')['$match?'](sect_style))))) { + sect_name = "section"; + } else { + + $a = [sect_style, true], (sect_name = $a[0]), (sect_special = $a[1]); + if ($eqeq(sect_level, 0)) { + sect_level = 1; + } sect_numbered = sect_name['$==']("appendix"); + } + } else if ($truthy(book)) { + sect_name = ($eqeq(sect_level, 0) ? ("part") : (($truthy($rb_gt(sect_level, 1)) ? ("section") : ("chapter")))); + } else if (($eqeq(doctype, "manpage") && ($eqeq(sect_title.$casecmp("synopsis"), 0)))) { + $a = ["synopsis", true], (sect_name = $a[0]), (sect_special = $a[1]); + } else { + sect_name = "section"; + } if ($truthy(sect_reftext)) { + attributes['$[]=']("reftext", sect_reftext); + } section = $$('Section').$new(parent, sect_level); + $a = [sect_id, sect_title, sect_name, source_location], ($b = [$a[0]], $send(section, 'id=', $b), $b[$b.length - 1]), ($b = [$a[1]], $send(section, 'title=', $b), $b[$b.length - 1]), ($b = [$a[2]], $send(section, 'sectname=', $b), $b[$b.length - 1]), ($b = [$a[3]], $send(section, 'source_location=', $b), $b[$b.length - 1]); + if ($truthy(sect_special)) { + + section['$special='](true); + if ($truthy(sect_numbered)) { + section['$numbered='](true); + } else if ($eqeq(document.$attributes()['$[]']("sectnums"), "all")) { + section['$numbered=']((($truthy(book) && ($eqeq(sect_level, 1))) ? ("chapter") : (true))); + } } else if (($truthy(document.$attributes()['$[]']("sectnums")) && ($truthy($rb_gt(sect_level, 0))))) { + section['$numbered='](($truthy(section.$special()) ? (($truthy(($ret_or_1 = parent.$numbered())) || ($ret_or_1))) : (true))); + } else if ((($truthy(book) && ($eqeq(sect_level, 0))) && ($truthy(document.$attributes()['$[]']("partnums"))))) { + section['$numbered='](true); + } if ($truthy((id = ($truthy(($ret_or_1 = section.$id())) ? ($ret_or_1) : (($a = [($truthy(document.$attributes()['$key?']("sectids")) ? ((generated_id = $$('Section').$generate_id(section.$title(), document))) : (nil))], $send(section, 'id=', $a), $a[$a.length - 1])))))) { + + if (!($truthy(generated_id) || ($not(sect_title['$include?']($$('ATTR_REF_HEAD')))))) { + section.$title(); + } if (!$truthy(document.$register("refs", [id, section]))) { + self.$logger().$warn(self.$message_with_context("id assigned to section already in use: " + (id), $hash2(["source_location"], {"source_location": reader.$cursor_at_line($rb_minus(reader.$lineno(), ($truthy(sect_atx) ? (1) : (2))))}))); + } } section.$update_attributes(attributes); + reader.$skip_blank_lines(); + return section; + }, -3); + $defs(self, '$is_next_line_section?', function $Parser_is_next_line_section$ques$17(reader, attributes) { + var self = this, style = nil, next_lines = nil, $ret_or_1 = nil; - if (cached == null || cached[0] !== current_version) { - ((result = const_get_name(cref, name)) != null) || - ((result = const_lookup_nesting(nesting, name)) != null) || - ((result = const_lookup_ancestors(cref, name)) != null) || - ((result = const_lookup_Object(cref, name)) != null); + + if (($truthy((style = attributes['$[]'](1))) && (($eqeq(style, "discrete") || ($eqeq(style, "float")))))) { + return nil + } if ($truthy($$('Compliance').$underline_style_section_titles())) { + + next_lines = reader.$peek_lines(2, ($truthy(($ret_or_1 = style)) ? (style['$==']("comment")) : ($ret_or_1))); + return self['$is_section_title?'](($truthy(($ret_or_1 = next_lines['$[]'](0))) ? ($ret_or_1) : ("")), next_lines['$[]'](1)); + } else { + return self['$atx_section_title?'](($truthy(($ret_or_1 = reader.$peek_line())) ? ($ret_or_1) : (""))) + } }); + $defs(self, '$is_next_line_doctitle?', function $Parser_is_next_line_doctitle$ques$18(reader, attributes, leveloffset) { + var self = this, $ret_or_1 = nil, sect_level = nil; - cache[name] = [current_version, result]; - } else { - result = cached[1]; - } + if ($truthy(leveloffset)) { + if ($truthy(($ret_or_1 = (sect_level = self['$is_next_line_section?'](reader, attributes))))) { + + return $rb_plus(sect_level, leveloffset.$to_i())['$=='](0); + } else { + return $ret_or_1 + } + } else { + return self['$is_next_line_section?'](reader, attributes)['$=='](0) + } + }); + $defs(self, '$is_section_title?', function $Parser_is_section_title$ques$19(line1, line2) { + var self = this, $ret_or_1 = nil; - return result != null ? result : const_missing(cref, name, skip_missing); - }; + + if (line2 == null) line2 = nil; + if ($truthy(($ret_or_1 = self['$atx_section_title?'](line1)))) { + return $ret_or_1 + } else { + + if ($truthy(line2['$nil_or_empty?']())) { + return nil + } else { + return self['$setext_section_title?'](line1, line2) + } } }, -2); + $defs(self, '$atx_section_title?', function $Parser_atx_section_title$ques$20(line) { + var $a, $ret_or_1 = nil; - // Register the constant on a cref and opportunistically set the name of - // unnamed classes/modules. - Opal.const_set = function(cref, name, value) { - if (cref == null || cref === '::') cref = _Object; + if ($truthy(($truthy($$('Compliance').$markdown_syntax()) ? (($truthy(($ret_or_1 = line['$start_with?']("=", "#"))) ? ($$('ExtAtxSectionTitleRx')['$=~'](line)) : ($ret_or_1))) : (($truthy(($ret_or_1 = line['$start_with?']("="))) ? ($$('AtxSectionTitleRx')['$=~'](line)) : ($ret_or_1)))))) { + return $rb_minus((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$length(), 1) + } else { + return nil + } + }); + $defs(self, '$setext_section_title?', function $Parser_setext_section_title$ques$21(line1, line2) { + var self = this, line2_len = nil, level = nil, line2_ch0 = nil; - if (value.$$is_a_module) { - if (value.$$name == null || value.$$name === nil) value.$$name = name; - if (value.$$base_module == null) value.$$base_module = cref; - } + if (((($truthy((level = $$('SETEXT_SECTION_LEVELS')['$[]']((line2_ch0 = line2.$chr())))) && ($truthy(self['$uniform?'](line2, line2_ch0, (line2_len = line2.$length()))))) && ($truthy($$('SetextSectionTitleRx')['$match?'](line1)))) && ($truthy($rb_lt($rb_minus(line1.$length(), line2_len).$abs(), 2))))) { + return level + } else { + return nil + } + }); + $defs(self, '$parse_section_title', function $$parse_section_title(reader, document, sect_id) { + var $a, $b, self = this, sect_reftext = nil, line1 = nil, $ret_or_1 = nil, sect_level = nil, sect_title = nil, atx = nil, line2_len = nil, line2_ch0 = nil, line2 = nil; - cref.$$const = (cref.$$const || Object.create(null)); - cref.$$const[name] = value; + + if (sect_id == null) sect_id = nil; + sect_reftext = nil; + line1 = reader.$read_line(); + if ($truthy(($truthy($$('Compliance').$markdown_syntax()) ? (($truthy(($ret_or_1 = line1['$start_with?']("=", "#"))) ? ($$('ExtAtxSectionTitleRx')['$=~'](line1)) : ($ret_or_1))) : (($truthy(($ret_or_1 = line1['$start_with?']("="))) ? ($$('AtxSectionTitleRx')['$=~'](line1)) : ($ret_or_1)))))) { + + $a = [$rb_minus((($b = $gvars['~']) === nil ? nil : $b['$[]'](1)).$length(), 1), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), true], (sect_level = $a[0]), (sect_title = $a[1]), (atx = $a[2]); + if (!$truthy(sect_id)) { + if ((($truthy(sect_title['$end_with?']("]]")) && ($truthy($$('InlineSectionAnchorRx')['$=~'](sect_title)))) && ($not((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))))) { + $a = [sect_title.$slice(0, $rb_minus(sect_title.$length(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](0)).$length())), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (sect_title = $a[0]), (sect_id = $a[1]), (sect_reftext = $a[2]); + } + } } else if (((((($truthy($$('Compliance').$underline_style_section_titles()) && ($truthy((line2 = reader.$peek_line(true))))) && ($truthy((sect_level = $$('SETEXT_SECTION_LEVELS')['$[]']((line2_ch0 = line2.$chr())))))) && ($truthy(self['$uniform?'](line2, line2_ch0, (line2_len = line2.$length()))))) && ($truthy((sect_title = ($truthy(($ret_or_1 = $$('SetextSectionTitleRx')['$=~'](line1))) ? ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) : ($ret_or_1)))))) && ($truthy($rb_lt($rb_minus(line1.$length(), line2_len).$abs(), 2))))) { + + atx = false; + if (!$truthy(sect_id)) { + if ((($truthy(sect_title['$end_with?']("]]")) && ($truthy($$('InlineSectionAnchorRx')['$=~'](sect_title)))) && ($not((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))))) { + $a = [sect_title.$slice(0, $rb_minus(sect_title.$length(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](0)).$length())), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (sect_title = $a[0]), (sect_id = $a[1]), (sect_reftext = $a[2]); + } + } reader.$shift(); + } else { + self.$raise("Unrecognized section at " + (reader.$cursor_at_prev_line())); + } if ($truthy(document['$attr?']("leveloffset"))) { + + sect_level = $rb_plus(sect_level, document.$attr("leveloffset").$to_i()); + if ($truthy($rb_lt(sect_level, 0))) { + sect_level = 0; + } } return [sect_id, sect_reftext, sect_title, sect_level, atx]; + }, -3); + $defs(self, '$parse_header_metadata', function $$parse_header_metadata(reader, document, retrieve) { + var $a, self = this, doc_attrs = nil, $ret_or_1 = nil, authorcount = nil, implicit_author_metadata = nil, implicit_author = nil, implicit_authorinitials = nil, implicit_authors = nil, rev_line = nil, match = nil, rev_metadata = nil, component = nil, author_line = nil, author_metadata = nil, authors = nil, author_idx = nil, author_key = nil, explicit = nil, sparse = nil, author_override = nil; - // Add a short helper to navigate constants manually. - // @example - // Opal.$$.Regexp.$$.IGNORECASE - cref.$$ = cref.$$const; + + if (document == null) document = nil; + if (retrieve == null) retrieve = true; + doc_attrs = ($truthy(($ret_or_1 = document)) ? (document.$attributes()) : ($ret_or_1)); + self.$process_attribute_entries(reader, document); + if (($truthy(reader['$has_more_lines?']()) && ($not(reader['$next_line_empty?']())))) { + + authorcount = (implicit_author_metadata = self.$process_authors(reader.$read_line())).$delete("authorcount"); + if (($truthy(document) && ($truthy($rb_gt(($a = ["authorcount", authorcount], $send(doc_attrs, '[]=', $a), $a[$a.length - 1]), 0))))) { + + $send(implicit_author_metadata, 'each', [], function $$22(key, val){var $b; - Opal.const_cache_version++; + + if (key == null) key = nil; + if (val == null) val = nil; + if ($truthy(doc_attrs['$key?'](key))) { + return nil + } else { + return ($b = [key, document.$apply_header_subs(val)], $send(doc_attrs, '[]=', $b), $b[$b.length - 1]) + }}); + implicit_author = doc_attrs['$[]']("author"); + implicit_authorinitials = doc_attrs['$[]']("authorinitials"); + implicit_authors = doc_attrs['$[]']("authors"); + } implicit_author_metadata['$[]=']("authorcount", authorcount); + self.$process_attribute_entries(reader, document); + if (($truthy(reader['$has_more_lines?']()) && ($not(reader['$next_line_empty?']())))) { + + rev_line = reader.$read_line(); + if ($truthy((match = $$('RevisionInfoLineRx').$match(rev_line)))) { + + rev_metadata = $hash2([], {}); + if ($truthy(match['$[]'](1))) { + rev_metadata['$[]=']("revnumber", match['$[]'](1).$rstrip()); + } if (!$truthy((component = match['$[]'](2).$strip())['$empty?']())) { + if (($not(match['$[]'](1)) && ($truthy(component['$start_with?']("v"))))) { + rev_metadata['$[]=']("revnumber", component.$slice(1, component.$length())); + } else { + rev_metadata['$[]=']("revdate", component); + } + } if ($truthy(match['$[]'](3))) { + rev_metadata['$[]=']("revremark", match['$[]'](3).$rstrip()); + } if (($truthy(document) && ($not(rev_metadata['$empty?']())))) { + $send(rev_metadata, 'each', [], function $$23(key, val){var $b; - // Expose top level constants onto the Opal object - if (cref === _Object) Opal[name] = value; + + if (key == null) key = nil; + if (val == null) val = nil; + if ($truthy(doc_attrs['$key?'](key))) { + return nil + } else { + return ($b = [key, document.$apply_header_subs(val)], $send(doc_attrs, '[]=', $b), $b[$b.length - 1]) + }}); + } } else { + reader.$unshift_line(rev_line); + } } self.$process_attribute_entries(reader, document); + reader.$skip_blank_lines(); + } else { + implicit_author_metadata = $hash2([], {}); + } if ($truthy(document)) { + + if (($truthy(doc_attrs['$key?']("author")) && ($neqeq((author_line = doc_attrs['$[]']("author")), implicit_author)))) { + + author_metadata = self.$process_authors(author_line, true, false); + if ($neqeq(doc_attrs['$[]']("authorinitials"), implicit_authorinitials)) { + author_metadata.$delete("authorinitials"); + } } else if (($truthy(doc_attrs['$key?']("authors")) && ($neqeq((author_line = doc_attrs['$[]']("authors")), implicit_authors)))) { + author_metadata = self.$process_authors(author_line, true); + } else { + + $a = [[], 1, "author_1", false, false], (authors = $a[0]), (author_idx = $a[1]), (author_key = $a[2]), (explicit = $a[3]), (sparse = $a[4]); + while ($truthy(doc_attrs['$key?'](author_key))) { + + if ($eqeq((author_override = doc_attrs['$[]'](author_key)), implicit_author_metadata['$[]'](author_key))) { + + authors['$<<'](nil); + sparse = true; + } else { + + authors['$<<'](author_override); + explicit = true; + } author_key = "author_" + ((author_idx = $rb_plus(author_idx, 1))); + } if ($truthy(explicit)) { + + if ($truthy(sparse)) { + $send(authors, 'each_with_index', [], function $$24(author, idx){var $b, name_idx = nil; - // Name new class directly onto current scope (Opal.Foo.Baz = klass) - $defineProperty(cref, name, value); + + if (author == null) author = nil; + if (idx == null) idx = nil; + if ($truthy(author)) { + return nil + } return ($b = [idx, $send([implicit_author_metadata['$[]']("firstname_" + ((name_idx = $rb_plus(idx, 1)))), implicit_author_metadata['$[]']("middlename_" + (name_idx)), implicit_author_metadata['$[]']("lastname_" + (name_idx))].$compact(), 'map', [], function $$25(it){ + + if (it == null) it = nil; + return it.$tr(" ", "_");}).$join(" ")], $send(authors, '[]=', $b), $b[$b.length - 1]);}); + } author_metadata = self.$process_authors(authors, true, false); + } else { + author_metadata = $hash2(["authorcount"], {"authorcount": 0}); + } } if ($eqeq(author_metadata['$[]']("authorcount"), 0)) { + if ($truthy(authorcount)) { + author_metadata = nil; + } else { + doc_attrs['$[]=']("authorcount", 0); + } + } else { + + doc_attrs.$update(author_metadata); + if (($not(doc_attrs['$key?']("email")) && ($truthy(doc_attrs['$key?']("email_1"))))) { + doc_attrs['$[]=']("email", doc_attrs['$[]']("email_1")); + } } } if ($truthy(retrieve)) { + return implicit_author_metadata.$merge(rev_metadata.$to_h(), author_metadata.$to_h()) + } else { + return nil + } }, -2); + $defs(self, '$process_authors', function $$process_authors(author_line, names_only, multiple) { + var author_metadata = nil, author_idx = nil; - return value; - }; + + if (names_only == null) names_only = false; + if (multiple == null) multiple = true; + author_metadata = $hash2([], {}); + author_idx = 0; + $send((($truthy(multiple) && ($truthy(author_line['$include?'](";")))) ? (author_line.$split($$('AuthorDelimiterRx'))) : ([].concat($to_a(author_line)))), 'each', [], function $$26(author_entry){var $a, key_map = nil, segments = nil, match = nil, author = nil, fname = nil, mname = nil, lname = nil; - // Get all the constants reachable from a given cref, by default will include - // inherited constants. - Opal.constants = function(cref, inherit) { - if (inherit == null) inherit = true; + + if (author_entry == null) author_entry = nil; + if ($truthy(author_entry['$empty?']())) { + return nil + } key_map = $hash2([], {}); + if ($eqeq((author_idx = $rb_plus(author_idx, 1)), 1)) { + $send($$('AuthorKeys'), 'each', [], function $$27(key){var $a; - var module, modules = [cref], module_constants, i, ii, constants = {}, constant; + + if (key == null) key = nil; + return ($a = [key.$to_sym(), key], $send(key_map, '[]=', $a), $a[$a.length - 1]);}); + } else { + $send($$('AuthorKeys'), 'each', [], function $$28(key){var $a; - if (inherit) modules = modules.concat(Opal.ancestors(cref)); - if (inherit && cref.$$is_module) modules = modules.concat([Opal.Object]).concat(Opal.ancestors(Opal.Object)); + + if (key == null) key = nil; + return ($a = [key.$to_sym(), "" + (key) + "_" + (author_idx)], $send(key_map, '[]=', $a), $a[$a.length - 1]);}); + } if ($truthy(names_only)) { + + if ($truthy(author_entry['$include?']("<"))) { + + author_metadata['$[]='](key_map['$[]']("author"), author_entry.$tr("_", " ")); + author_entry = author_entry.$gsub($$('XmlSanitizeRx'), ""); + } if ($eqeq((segments = author_entry.$split(nil, 3)).$size(), 3)) { + segments['$<<'](segments.$pop().$squeeze(" ")); + } } else if ($truthy((match = $$('AuthorInfoLineRx').$match(author_entry)))) { + (segments = match.$to_a()).$shift(); + } if ($truthy(segments)) { + + author = ($a = [key_map['$[]']("firstname"), (fname = segments['$[]'](0).$tr("_", " "))], $send(author_metadata, '[]=', $a), $a[$a.length - 1]); + author_metadata['$[]='](key_map['$[]']("authorinitials"), fname.$chr()); + if ($truthy(segments['$[]'](1))) { + if ($truthy(segments['$[]'](2))) { + + author_metadata['$[]='](key_map['$[]']("middlename"), (mname = segments['$[]'](1).$tr("_", " "))); + author_metadata['$[]='](key_map['$[]']("lastname"), (lname = segments['$[]'](2).$tr("_", " "))); + author = $rb_plus($rb_plus($rb_plus($rb_plus(fname, " "), mname), " "), lname); + author_metadata['$[]='](key_map['$[]']("authorinitials"), "" + (fname.$chr()) + (mname.$chr()) + (lname.$chr())); + } else { + + author_metadata['$[]='](key_map['$[]']("lastname"), (lname = segments['$[]'](1).$tr("_", " "))); + author = $rb_plus($rb_plus(fname, " "), lname); + author_metadata['$[]='](key_map['$[]']("authorinitials"), "" + (fname.$chr()) + (lname.$chr())); + } + } if ($truthy((author_metadata['$[]'](key_map['$[]']("author"))))) ; else { + author_metadata['$[]='](key_map['$[]']("author"), author); + } if (!($truthy(names_only) || ($not(segments['$[]'](3))))) { + author_metadata['$[]='](key_map['$[]']("email"), segments['$[]'](3)); + } } else { + + author_metadata['$[]='](key_map['$[]']("author"), ($a = [key_map['$[]']("firstname"), (fname = author_entry.$squeeze(" ").$strip())], $send(author_metadata, '[]=', $a), $a[$a.length - 1])); + author_metadata['$[]='](key_map['$[]']("authorinitials"), fname.$chr()); + } if ($eqeq(author_idx, 1)) { + return ($a = ["authors", author_metadata['$[]'](key_map['$[]']("author"))], $send(author_metadata, '[]=', $a), $a[$a.length - 1]) + } else { + + if ($eqeq(author_idx, 2)) { + $send($$('AuthorKeys'), 'each', [], function $$29(key){var $b; - for (i = 0, ii = modules.length; i < ii; i++) { - module = modules[i]; + + if (key == null) key = nil; + if ($truthy(author_metadata['$key?'](key))) { + return ($b = ["" + (key) + "_1", author_metadata['$[]'](key)], $send(author_metadata, '[]=', $b), $b[$b.length - 1]) + } else { + return nil + }}); + } return ($a = ["authors", "" + (author_metadata['$[]']("authors")) + ", " + (author_metadata['$[]'](key_map['$[]']("author")))], $send(author_metadata, '[]=', $a), $a[$a.length - 1]); + }}); + author_metadata['$[]=']("authorcount", author_idx); + return author_metadata; + }, -2); + $defs(self, '$parse_block_metadata_lines', function $$parse_block_metadata_lines(reader, document, attributes, options) { + var self = this; - // Don not show Objects constants unless we're querying Object itself - if (cref !== _Object && module == _Object) break; + + if (attributes == null) attributes = $hash2([], {}); + if (options == null) options = $hash2([], {}); + while ($truthy(self.$parse_block_metadata_line(reader, document, attributes, options))) { + + reader.$shift(); + if ($truthy((reader.$skip_blank_lines()))) ; else { + break + } } return attributes; + }, -3); + $defs(self, '$parse_block_metadata_line', function $$parse_block_metadata_line(reader, document, attributes, options) { + var $a, self = this, normal = nil, next_line = nil, reftext = nil, current_style = nil, $ret_or_1 = nil, ll = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; - for (constant in module.$$const) { - constants[constant] = true; - } - } + + if (options == null) options = $hash2([], {}); + if (($truthy((next_line = reader.$peek_line())) && ($truthy(($truthy(options['$[]']("text_only")) ? (next_line['$start_with?']("[", "/")) : ((normal = next_line['$start_with?']("[", ".", "/", ":")))))))) { + if ($truthy(next_line['$start_with?']("["))) { + if ($truthy(next_line['$start_with?']("[["))) { + if (($truthy(next_line['$end_with?']("]]")) && ($truthy($$('BlockAnchorRx')['$=~'](next_line))))) { + + attributes['$[]=']("id", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))); + if ($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) { + attributes['$[]=']("reftext", ($truthy(reftext['$include?']($$('ATTR_REF_HEAD'))) ? (document.$sub_attributes(reftext)) : (reftext))); + } return true; + } + } else if (($truthy(next_line['$end_with?']("]")) && ($truthy($$('BlockAttributeListRx')['$=~'](next_line))))) { + + current_style = attributes['$[]'](1); + if ($truthy(document.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), [], $hash2(["sub_input", "sub_result", "into"], {"sub_input": true, "sub_result": true, "into": attributes}))['$[]'](1))) { + attributes['$[]='](1, ($truthy(($ret_or_1 = self.$parse_style_attribute(attributes, reader))) ? ($ret_or_1) : (current_style))); + } return true; + } + } else if (($truthy(normal) && ($truthy(next_line['$start_with?']("."))))) { + if ($truthy($$('BlockTitleRx')['$=~'](next_line))) { + + attributes['$[]=']("title", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))); + return true; + } + } else if (($not(normal) || ($truthy(next_line['$start_with?']("/"))))) { + if ($truthy(next_line['$start_with?']("//"))) { + if ($eqeq(next_line, "//")) { + return true + } else if (($truthy(normal) && ($truthy(self['$uniform?'](next_line, "/", (ll = next_line.$length())))))) { + if (!$eqeq(ll, 3)) { + + reader.$read_lines_until($hash2(["terminator", "skip_first_line", "preserve_last_line", "skip_processing", "context"], {"terminator": next_line, "skip_first_line": true, "preserve_last_line": true, "skip_processing": true, "context": "comment"})); + return true; + } + } else if (!$truthy(next_line['$start_with?']("///"))) { + return true + } + } + } else if ((($truthy(normal) && ($truthy(next_line['$start_with?'](":")))) && ($truthy($$('AttributeEntryRx')['$=~'](next_line))))) { + + self.$process_attribute_entry(reader, document, attributes, $gvars["~"]); + return true; + } + } return nil; + }, -4); + $defs(self, '$process_attribute_entries', function $$process_attribute_entries(reader, document, attributes) { + var self = this; - return Object.keys(constants); - }; + + if (attributes == null) attributes = nil; + reader.$skip_comment_lines(); + while ($truthy(self.$process_attribute_entry(reader, document, attributes))) { + + reader.$shift(); + reader.$skip_comment_lines(); + } }, -3); + $defs(self, '$process_attribute_entry', function $$process_attribute_entry(reader, document, attributes, match) { + var $a, self = this, value = nil, con = nil, $ret_or_1 = nil, next_line = nil, $ret_or_2 = nil, keep_open = nil; - // Remove a constant from a cref. - Opal.const_remove = function(cref, name) { - Opal.const_cache_version++; + + if (attributes == null) attributes = nil; + if (match == null) match = nil; + if (($truthy(match) || ($truthy((match = ($truthy(reader['$has_more_lines?']()) ? ($$('AttributeEntryRx').$match(reader.$peek_line())) : (nil))))))) { + + if ($truthy((value = match['$[]'](2))['$nil_or_empty?']())) { + value = ""; + } else if ($truthy(value['$end_with?']($$('LINE_CONTINUATION'), $$('LINE_CONTINUATION_LEGACY')))) { + + $a = [value.$slice($rb_minus(value.$length(), 2), 2), value.$slice(0, $rb_minus(value.$length(), 2)).$rstrip()], (con = $a[0]), (value = $a[1]); + while ($truthy(($truthy(($ret_or_1 = reader.$advance())) ? ((next_line = ($truthy(($ret_or_2 = reader.$peek_line())) ? ($ret_or_2) : ("")))['$empty?']()['$!']()) : ($ret_or_1)))) { + + next_line = next_line.$lstrip(); + if ($truthy((keep_open = next_line['$end_with?'](con)))) { + next_line = next_line.$slice(0, $rb_minus(next_line.$length(), 2)).$rstrip(); + } value = "" + (value) + (($truthy(value['$end_with?']($$('HARD_LINE_BREAK'))) ? ($$('LF')) : (" "))) + (next_line); + if (!$truthy(keep_open)) { + break + } } } self.$store_attribute(match['$[]'](1), value, document, attributes); + return true; + } else { + return nil + } }, -3); + $defs(self, '$store_attribute', function $$store_attribute(name, value, doc, attrs) { + var self = this, resolved_value = nil; - if (cref.$$const[name] != null) { - var old = cref.$$const[name]; - delete cref.$$const[name]; - return old; - } + + if (doc == null) doc = nil; + if (attrs == null) attrs = nil; + if ($truthy(name['$end_with?']("!"))) { + + name = name.$chop(); + value = nil; + } else if ($truthy(name['$start_with?']("!"))) { + + name = name.$slice(1, name.$length()); + value = nil; + } if ($eqeq((name = self.$sanitize_attribute_name(name)), "numbered")) { + name = "sectnums"; + } else if ($eqeq(name, "hardbreaks")) { + name = "hardbreaks-option"; + } else if ($eqeq(name, "showtitle")) { + self.$store_attribute("notitle", ($truthy(value) ? (nil) : ("")), doc, attrs); + } if ($truthy(doc)) { + if ($truthy(value)) { + + if ($eqeq(name, "leveloffset")) { + if ($truthy(value['$start_with?']("+"))) { + value = $rb_plus(doc.$attr("leveloffset", 0).$to_i(), value.$slice(1, value.$length()).$to_i()).$to_s(); + } else if ($truthy(value['$start_with?']("-"))) { + value = $rb_minus(doc.$attr("leveloffset", 0).$to_i(), value.$slice(1, value.$length()).$to_i()).$to_s(); + } + } if ($truthy((resolved_value = doc.$set_attribute(name, value)))) { + + value = resolved_value; + if ($truthy(attrs)) { + $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs); + } } } else if (($truthy(doc.$delete_attribute(name)) && ($truthy(attrs)))) { + $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs); + } + } else if ($truthy(attrs)) { + $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs); + } return [name, value]; + }, -3); + $defs(self, '$resolve_list_marker', function $$resolve_list_marker(list_type, marker, ordinal, validate, reader) { + var self = this; - if (cref.$$autoload != null && cref.$$autoload[name] != null) { - delete cref.$$autoload[name]; - return nil; - } + + if (ordinal == null) ordinal = 0; + if (validate == null) validate = false; + if (reader == null) reader = nil; + + switch (list_type) { + case "ulist": + return marker + case "olist": + return self.$resolve_ordered_list_marker(marker, ordinal, validate, reader)['$[]'](0) + default: + return "<1>" + } }, -3); + $defs(self, '$resolve_ordered_list_marker', function $$resolve_ordered_list_marker(marker, ordinal, validate, reader) { + var self = this, style = nil, expected = nil, actual = nil; - throw Opal.NameError.$new("constant "+cref+"::"+cref.$name()+" not defined"); - }; + + if (ordinal == null) ordinal = 0; + if (validate == null) validate = false; + if (reader == null) reader = nil; + if ($truthy(marker['$start_with?']("."))) { + return [marker] + } + switch ((style = $send($$('ORDERED_LIST_STYLES'), 'find', [], function $$30(s){ + + if (s == null) s = nil; + return $$('OrderedListMarkerRxMap')['$[]'](s)['$match?'](marker);}))) { + case "arabic": + + if ($truthy(validate)) { + + expected = $rb_plus(ordinal, 1); + actual = marker.$to_i(); + } marker = "1."; + break; + case "loweralpha": + + if ($truthy(validate)) { + + expected = $rb_plus("a"['$[]'](0).$ord(), ordinal).$chr(); + actual = marker.$chop(); + } marker = "a."; + break; + case "upperalpha": + + if ($truthy(validate)) { + + expected = $rb_plus("A"['$[]'](0).$ord(), ordinal).$chr(); + actual = marker.$chop(); + } marker = "A."; + break; + case "lowerroman": + + if ($truthy(validate)) { + + expected = $$('Helpers').$int_to_roman($rb_plus(ordinal, 1)).$downcase(); + actual = marker.$chop(); + } marker = "i)"; + break; + case "upperroman": + + if ($truthy(validate)) { + + expected = $$('Helpers').$int_to_roman($rb_plus(ordinal, 1)); + actual = marker.$chop(); + } marker = "I)"; + break; + } if (($truthy(validate) && ($neqeq(expected, actual)))) { + self.$logger().$warn(self.$message_with_context("list item index: expected " + (expected) + ", got " + (actual), $hash2(["source_location"], {"source_location": reader.$cursor()}))); + } return [marker, style]; + }, -2); + $defs(self, '$is_sibling_list_item?', function $Parser_is_sibling_list_item$ques$31(line, list_type, sibling_trait) { + var $a, self = this, $ret_or_1 = nil; + + if ($eqeqeq($$$('Regexp'), sibling_trait)) { + return sibling_trait['$match?'](line) + } else if ($truthy(($ret_or_1 = $$('ListRxMap')['$[]'](list_type)['$=~'](line)))) { + return sibling_trait['$=='](self.$resolve_list_marker(list_type, (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) + } else { + return $ret_or_1 + } + }); + $defs(self, '$parse_table', function $$parse_table(table_reader, parent, attributes) { + var $a, $b, $c, self = this, table = nil, colspecs = nil, explicit_colspecs = nil, skipped = nil, $ret_or_1 = nil, implicit_header = nil, parser_ctx = nil, format = nil, loop_idx = nil, implicit_header_boundary = nil, line = nil, beyond_first = nil, next_cellspec = nil, m = nil, pre_match = nil, post_match = nil, cell_text = nil, $logical_op_recvr_tmp_2 = nil; + + table = $$('Table').$new(parent, attributes); + if (($truthy(attributes['$key?']("cols")) && ($not((colspecs = self.$parse_colspecs(attributes['$[]']("cols")))['$empty?']())))) { + + table.$create_columns(colspecs); + explicit_colspecs = true; + } skipped = ($truthy(($ret_or_1 = table_reader.$skip_blank_lines())) ? ($ret_or_1) : (0)); + if ($truthy(attributes['$[]']("header-option"))) { + table['$has_header_option='](true); + } else if (($eqeq(skipped, 0) && ($not(attributes['$[]']("noheader-option"))))) { + + table['$has_header_option=']("implicit"); + implicit_header = true; + } parser_ctx = $$$($$('Table'), 'ParserContext').$new(table_reader, table, attributes); + $a = [parser_ctx.$format(), -1, nil], (format = $a[0]), (loop_idx = $a[1]), (implicit_header_boundary = $a[2]); + while ($truthy((line = table_reader.$read_line()))) { + + if (($truthy((beyond_first = $rb_gt((loop_idx = $rb_plus(loop_idx, 1)), 0))) && ($truthy(line['$empty?']())))) { + + line = nil; + if ($truthy(implicit_header_boundary)) { + implicit_header_boundary = $rb_plus(implicit_header_boundary, 1); + } } else if ($eqeq(format, "psv")) { + if ($truthy(parser_ctx['$starts_with_delimiter?'](line))) { + + line = line.$slice(1, line.$length()); + parser_ctx.$close_open_cell(); + if ($truthy(implicit_header_boundary)) { + implicit_header_boundary = nil; + } } else { + + $b = self.$parse_cellspec(line, "start", parser_ctx.$delimiter()), $a = $to_ary($b), (next_cellspec = ($a[0] == null ? nil : $a[0])), (line = ($a[1] == null ? nil : $a[1])); + if ($truthy(next_cellspec)) { + + parser_ctx.$close_open_cell(next_cellspec); + if ($truthy(implicit_header_boundary)) { + implicit_header_boundary = nil; + } } else if (($truthy(implicit_header_boundary) && ($eqeq(implicit_header_boundary, loop_idx)))) { + table['$has_header_option=']((implicit_header = (implicit_header_boundary = nil))); + } } + } if (!$truthy(beyond_first)) { + + table_reader.$mark(); + if ($truthy(implicit_header)) { + if (($truthy(table_reader['$has_more_lines?']()) && ($truthy(table_reader.$peek_line()['$empty?']())))) { + implicit_header_boundary = 1; + } else { + table['$has_header_option=']((implicit_header = nil)); + } + } } $a = false;while ($a || $truthy(true)) {$a = false; + if (($truthy(line) && ($truthy((m = parser_ctx.$match_delimiter(line)))))) { + + $b = [m.$pre_match(), m.$post_match()], (pre_match = $b[0]), (post_match = $b[1]); + if ($eqeqeq("csv", ($ret_or_1 = format))) { + + if ($truthy(parser_ctx['$buffer_has_unclosed_quotes?'](pre_match))) { + + parser_ctx.$skip_past_delimiter(pre_match); + if ($truthy((line = post_match)['$empty?']())) { + break + } $a = true;continue; + } parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (pre_match)); + } else if ($eqeqeq("dsv", $ret_or_1)) { + + if ($truthy(pre_match['$end_with?']("\\"))) { + + parser_ctx.$skip_past_escaped_delimiter(pre_match); + if ($truthy((line = post_match)['$empty?']())) { + + parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + ($$('LF'))); + parser_ctx.$keep_cell_open(); + break; + } $a = true;continue; + } parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (pre_match)); + } else { + + if ($truthy(pre_match['$end_with?']("\\"))) { + + parser_ctx.$skip_past_escaped_delimiter(pre_match); + if ($truthy((line = post_match)['$empty?']())) { + + parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + ($$('LF'))); + parser_ctx.$keep_cell_open(); + break; + } $a = true;continue; + } $c = self.$parse_cellspec(pre_match), $b = $to_ary($c), (next_cellspec = ($b[0] == null ? nil : $b[0])), (cell_text = ($b[1] == null ? nil : $b[1])); + parser_ctx.$push_cellspec(next_cellspec); + parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (cell_text)); + } if ($truthy((line = post_match)['$empty?']())) { + line = nil; + } parser_ctx.$close_cell(); + } else { + + parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (line) + ($$('LF'))); + + switch (format) { + case "csv": + if ($truthy(parser_ctx['$buffer_has_unclosed_quotes?']())) { + + if (($truthy(implicit_header_boundary) && ($eqeq(loop_idx, 0)))) { + table['$has_header_option=']((implicit_header = (implicit_header_boundary = nil))); + } parser_ctx.$keep_cell_open(); + } else { + parser_ctx.$close_cell(true); + } + break; + case "dsv": + parser_ctx.$close_cell(true); + break; + default: + parser_ctx.$keep_cell_open(); + } break; + } + } if ($truthy(parser_ctx['$cell_open?']())) { + if (!$truthy(table_reader['$has_more_lines?']())) { + parser_ctx.$close_cell(true); + } + } else if ($truthy(($ret_or_1 = table_reader.$skip_blank_lines()))) ; else { + break + } } if (!($eqeq((($logical_op_recvr_tmp_2 = table.$attributes()), ($truthy(($ret_or_1 = $logical_op_recvr_tmp_2['$[]']("colcount"))) ? ($ret_or_1) : (($a = ["colcount", table.$columns().$size()], $send($logical_op_recvr_tmp_2, '[]=', $a), $a[$a.length - 1])))), 0) || ($truthy(explicit_colspecs)))) { + table.$assign_column_widths(); + } if ($truthy(implicit_header)) { + table['$has_header_option='](true); + } table.$partition_header_footer(attributes); + return table; + }); + $defs(self, '$parse_colspecs', function $$parse_colspecs(records) { + var specs = nil; - // Modules & Classes - // ----------------- + + if ($truthy(records['$include?'](" "))) { + records = records.$delete(" "); + } if ($eqeq(records, records.$to_i().$to_s())) { + return $send($$$('Array'), 'new', [records.$to_i()], function $$32(){ + return $hash2(["width"], {"width": 1})}) + } specs = []; + $send(($truthy(records['$include?'](",")) ? (records.$split(",", -1)) : (records.$split(";", -1))), 'each', [], function $$33(record){var $a, $b, m = nil, spec = nil, colspec = nil, rowspec = nil, width = nil; - // A `class Foo; end` expression in ruby is compiled to call this runtime - // method which either returns an existing class of the given name, or creates - // a new class in the given `base` scope. - // - // If a constant with the given name exists, then we check to make sure that - // it is a class and also that the superclasses match. If either of these - // fail, then we raise a `TypeError`. Note, `superclass` may be null if one - // was not specified in the ruby code. - // - // We pass a constructor to this method of the form `function ClassName() {}` - // simply so that classes show up with nicely formatted names inside debuggers - // in the web browser (or node/sprockets). - // - // The `scope` is the current `self` value where the class is being created - // from. We use this to get the scope for where the class should be created. - // If `scope` is an object (not a class/module), we simple get its class and - // use that as the scope instead. - // - // @param scope [Object] where the class is being created - // @param superclass [Class,null] superclass of the new class (may be null) - // @param id [String] the name of the class to be created - // @param constructor [JS.Function] function to use as constructor - // - // @return new [Class] or existing ruby class - // - Opal.allocate_class = function(name, superclass) { - var klass, constructor; + + if (record == null) record = nil; + if ($truthy(record['$empty?']())) { + return specs['$<<']($hash2(["width"], {"width": 1})) + } else if ($truthy((m = $$('ColumnSpecRx').$match(record)))) { + + spec = $hash2([], {}); + if ($truthy(m['$[]'](2))) { + + $b = m['$[]'](2).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])); + if (($not(colspec['$nil_or_empty?']()) && ($truthy($$('TableCellHorzAlignments')['$key?'](colspec))))) { + spec['$[]=']("halign", $$('TableCellHorzAlignments')['$[]'](colspec)); + } if (($not(rowspec['$nil_or_empty?']()) && ($truthy($$('TableCellVertAlignments')['$key?'](rowspec))))) { + spec['$[]=']("valign", $$('TableCellVertAlignments')['$[]'](rowspec)); + } } if ($truthy((width = m['$[]'](3)))) { + spec['$[]=']("width", ($eqeq(width, "~") ? (-1) : (width.$to_i()))); + } else { + spec['$[]=']("width", 1); + } if (($truthy(m['$[]'](4)) && ($truthy($$('TableCellStyles')['$key?'](m['$[]'](4)))))) { + spec['$[]=']("style", $$('TableCellStyles')['$[]'](m['$[]'](4))); + } if ($truthy(m['$[]'](1))) { + return $send((1), 'upto', [m['$[]'](1).$to_i()], function $$34(){ + return specs['$<<'](spec.$merge())}) + } else { + return specs['$<<'](spec) + } } else { + return nil + }}); + return specs; + }); + $defs(self, '$parse_cellspec', function $$parse_cellspec(line, pos, delimiter) { + var $a, $b, m = nil, rest = nil, spec_part = nil, spec = nil, colspec = nil, rowspec = nil; - if (superclass != null && superclass.$$bridge) { - // Inheritance from bridged classes requires - // calling original JS constructors - constructor = function() { - var args = $slice.call(arguments), - self = new ($bind.apply(superclass.$$constructor, [null].concat(args)))(); + + if (pos == null) pos = "end"; + if (delimiter == null) delimiter = nil; + $a = [nil, ""], (m = $a[0]), (rest = $a[1]); + if ($eqeq(pos, "start")) { + if ($truthy(line['$include?'](delimiter))) { + + $b = line.$partition(delimiter), $a = $to_ary($b), (spec_part = ($a[0] == null ? nil : $a[0])), (($a[1] == null ? nil : $a[1])), (rest = ($a[2] == null ? nil : $a[2])); + if ($truthy((m = $$('CellSpecStartRx').$match(spec_part)))) { + if ($truthy(m['$[]'](0)['$empty?']())) { + return [$hash2([], {}), rest] + } + } else { + return [nil, line] + } } else { + return [nil, line] + } + } else if ($truthy((m = $$('CellSpecEndRx').$match(line)))) { + + if ($truthy(m['$[]'](0).$lstrip()['$empty?']())) { + return [$hash2([], {}), line.$rstrip()] + } rest = m.$pre_match(); + } else { + return [$hash2([], {}), line] + } spec = $hash2([], {}); + if ($truthy(m['$[]'](1))) { + + $b = m['$[]'](1).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])); + colspec = ($truthy(colspec['$nil_or_empty?']()) ? (1) : (colspec.$to_i())); + rowspec = ($truthy(rowspec['$nil_or_empty?']()) ? (1) : (rowspec.$to_i())); + + switch (m['$[]'](2)) { + case "+": + + if (!$eqeq(colspec, 1)) { + spec['$[]=']("colspan", colspec); + } if (!$eqeq(rowspec, 1)) { + spec['$[]=']("rowspan", rowspec); + } break; + case "*": + if (!$eqeq(colspec, 1)) { + spec['$[]=']("repeatcol", colspec); + } + break; + } } if ($truthy(m['$[]'](3))) { + + $b = m['$[]'](3).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])); + if (($not(colspec['$nil_or_empty?']()) && ($truthy($$('TableCellHorzAlignments')['$key?'](colspec))))) { + spec['$[]=']("halign", $$('TableCellHorzAlignments')['$[]'](colspec)); + } if (($not(rowspec['$nil_or_empty?']()) && ($truthy($$('TableCellVertAlignments')['$key?'](rowspec))))) { + spec['$[]=']("valign", $$('TableCellVertAlignments')['$[]'](rowspec)); + } } if (($truthy(m['$[]'](4)) && ($truthy($$('TableCellStyles')['$key?'](m['$[]'](4)))))) { + spec['$[]=']("style", $$('TableCellStyles')['$[]'](m['$[]'](4))); + } return [spec, rest]; + }, -2); + $defs(self, '$parse_style_attribute', function $$parse_style_attribute(attributes, reader) { + var $a, self = this, raw_style = nil, name = nil, accum = nil, parsed_attrs = nil, parsed_style = nil, existing_role = nil; - // and replacing a __proto__ manually - $setPrototype(self, klass.$$prototype); - return self; - } - } else { - constructor = function(){}; - } + + if (reader == null) reader = nil; + if ((($truthy((raw_style = attributes['$[]'](1))) && ($not(raw_style['$include?'](" ")))) && ($truthy($$('Compliance').$shorthand_property_syntax())))) { + + name = nil; + accum = ""; + parsed_attrs = $hash2([], {}); + $send(raw_style, 'each_char', [], function $$35(c){var self = $$35.$$s == null ? this : $$35.$$s; - if (name) { - $defineProperty(constructor, 'displayName', '::'+name); - } + + if (c == null) c = nil; + + switch (c) { + case ".": + + self.$yield_buffered_attribute(parsed_attrs, name, accum, reader); + accum = ""; + return (name = "role"); + case "#": + + self.$yield_buffered_attribute(parsed_attrs, name, accum, reader); + accum = ""; + return (name = "id"); + case "%": + + self.$yield_buffered_attribute(parsed_attrs, name, accum, reader); + accum = ""; + return (name = "option"); + default: + return (accum = $rb_plus(accum, c)) + }}, {$$s: self}); + if ($truthy(name)) { + + self.$yield_buffered_attribute(parsed_attrs, name, accum, reader); + if ($truthy((parsed_style = parsed_attrs['$[]']("style")))) { + attributes['$[]=']("style", parsed_style); + } if ($truthy(parsed_attrs['$key?']("id"))) { + attributes['$[]=']("id", parsed_attrs['$[]']("id")); + } if ($truthy(parsed_attrs['$key?']("role"))) { + attributes['$[]=']("role", ($truthy((existing_role = attributes['$[]']("role"))['$nil_or_empty?']()) ? (parsed_attrs['$[]']("role").$join(" ")) : ("" + (existing_role) + " " + (parsed_attrs['$[]']("role").$join(" "))))); + } if ($truthy(parsed_attrs['$key?']("option"))) { + $send(parsed_attrs['$[]']("option"), 'each', [], function $$36(opt){var $a; - klass = constructor; + + if (opt == null) opt = nil; + return ($a = ["" + (opt) + "-option", ""], $send(attributes, '[]=', $a), $a[$a.length - 1]);}); + } return parsed_style; + } else { + return ($a = ["style", raw_style], $send(attributes, '[]=', $a), $a[$a.length - 1]) + } } else { + return ($a = ["style", raw_style], $send(attributes, '[]=', $a), $a[$a.length - 1]) + } }, -2); + $defs(self, '$yield_buffered_attribute', function $$yield_buffered_attribute(attrs, name, value, reader) { + var $a, self = this, $ret_or_1 = nil; - $defineProperty(klass, '$$name', name); - $defineProperty(klass, '$$constructor', constructor); - $defineProperty(klass, '$$prototype', constructor.prototype); - $defineProperty(klass, '$$const', {}); - $defineProperty(klass, '$$is_class', true); - $defineProperty(klass, '$$is_a_module', true); - $defineProperty(klass, '$$super', superclass); - $defineProperty(klass, '$$cvars', {}); - $defineProperty(klass, '$$own_included_modules', []); - $defineProperty(klass, '$$own_prepended_modules', []); - $defineProperty(klass, '$$ancestors', []); - $defineProperty(klass, '$$ancestors_cache_version', null); + + if ($truthy(name)) { + if ($truthy(value['$empty?']())) { + if ($truthy(reader)) { + self.$logger().$warn(self.$message_with_context("invalid empty " + (name) + " detected in style attribute", $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()}))); + } else { + self.$logger().$warn("invalid empty " + (name) + " detected in style attribute"); + } + } else if ($eqeq(name, "id")) { + + if ($truthy(attrs['$key?']("id"))) { + if ($truthy(reader)) { + self.$logger().$warn(self.$message_with_context("multiple ids detected in style attribute", $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()}))); + } else { + self.$logger().$warn("multiple ids detected in style attribute"); + } + } attrs['$[]='](name, value); + } else { + ($truthy(($ret_or_1 = attrs['$[]'](name))) ? ($ret_or_1) : (($a = [name, []], $send(attrs, '[]=', $a), $a[$a.length - 1])))['$<<'](value); + } + } else if (!$truthy(value['$empty?']())) { + attrs['$[]=']("style", value); + } return nil; + }); + $defs(self, '$adjust_indentation!', function $Parser_adjust_indentation$excl$37(lines, indent_size, tab_size) { + var full_tab_space = nil, block_indent = nil, new_block_indent = nil; - $defineProperty(klass.$$prototype, '$$class', klass); + + if (indent_size == null) indent_size = 0; + if (tab_size == null) tab_size = 0; + if ($truthy(lines['$empty?']())) { + return nil + } if (($truthy($rb_gt(tab_size, 0)) && ($truthy($send(lines, 'any?', [], function $$38(line){ + + if (line == null) line = nil; + return line['$include?']($$('TAB'));}))))) { + + full_tab_space = $rb_times(" ", tab_size); + $send(lines, 'map!', [], function $$39(line){var tab_idx = nil, leading_tabs = nil, spaces_added = nil, idx = nil, result = nil; - // By default if there are no singleton class methods - // __proto__ is Class.prototype - // Later singleton methods generate a singleton_class - // and inject it into ancestors chain - if (Opal.Class) { - $setPrototype(klass, Opal.Class.prototype); - } + + if (line == null) line = nil; + if (($truthy(line['$empty?']()) || ($truthy((tab_idx = line.$index($$('TAB')))['$nil?']())))) { + return line + } else { + + if ($eqeq(tab_idx, 0)) { + + leading_tabs = 0; + (function(){try { var $t_break = $thrower('break'); return $send(line, 'each_byte', [], function $$40(b){ + + if (b == null) b = nil; + if (!$eqeq(b, 9)) { + $t_break.$throw(); + }; + return (leading_tabs = $rb_plus(leading_tabs, 1));})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + line = "" + ($rb_times(full_tab_space, leading_tabs)) + (line.$slice(leading_tabs, line.$length())); + if (!$truthy(line['$include?']($$('TAB')))) { + return line + } } spaces_added = 0; + idx = 0; + result = ""; + $send(line, 'each_char', [], function $$41(c){var offset = nil, spaces = nil; - if (superclass != null) { - $setPrototype(klass.$$prototype, superclass.$$prototype); + + if (c == null) c = nil; + if ($eqeq(c, $$('TAB'))) { + if ($eqeq((offset = $rb_plus(idx, spaces_added))['$%'](tab_size), 0)) { + + spaces_added = $rb_plus(spaces_added, $rb_minus(tab_size, 1)); + result = $rb_plus(result, full_tab_space); + } else { + + if (!$eqeq((spaces = $rb_minus(tab_size, offset['$%'](tab_size))), 1)) { + spaces_added = $rb_plus(spaces_added, $rb_minus(spaces, 1)); + } result = $rb_plus(result, $rb_times(" ", spaces)); + } + } else { + result = $rb_plus(result, c); + } return (idx = $rb_plus(idx, 1));}); + return result; + }}); + } if ($truthy($rb_lt(indent_size, 0))) { + return nil + } block_indent = nil; + (function(){try { var $t_break = $thrower('break'); return $send(lines, 'each', [], function $$42(line){var line_indent = nil; - if (superclass.$$meta) { - // If superclass has metaclass then we have explicitely inherit it. - Opal.build_class_singleton_class(klass); - } - }; + + if (line == null) line = nil; + if ($truthy(line['$empty?']())) { + return nil + }; + if ($eqeq((line_indent = $rb_minus(line.$length(), line.$lstrip().$length())), 0)) { + + block_indent = nil; + $t_break.$throw(); + }; + if (($truthy(block_indent) && ($truthy($rb_lt(block_indent, line_indent))))) { + return nil + } else { + return (block_indent = line_indent) + };})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + if ($eqeq(indent_size, 0)) { + if ($truthy(block_indent)) { + $send(lines, 'map!', [], function $$43(line){ + + if (line == null) line = nil; + if ($truthy(line['$empty?']())) { + return line + } else { + + return line.$slice(block_indent, line.$length()); + }}); + } + } else { + + new_block_indent = $rb_times(" ", indent_size); + if ($truthy(block_indent)) { + $send(lines, 'map!', [], function $$44(line){ + + if (line == null) line = nil; + if ($truthy(line['$empty?']())) { + return line + } else { + return $rb_plus(new_block_indent, line.$slice(block_indent, line.$length())) + }}); + } else { + $send(lines, 'map!', [], function $$45(line){ + + if (line == null) line = nil; + if ($truthy(line['$empty?']())) { + return line + } else { + return $rb_plus(new_block_indent, line) + }}); + } } return nil; + }, -2); + $defs(self, '$uniform?', function $Parser_uniform$ques$46(str, chr, len) { + + return str.$count(chr)['$=='](len) + }); + return $defs(self, '$sanitize_attribute_name', function $$sanitize_attribute_name(name) { + + return name.$gsub($$('InvalidAttributeNameCharsRx'), "").$downcase() + }); + })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; - return klass; - } +Opal.modules["asciidoctor/path_resolver"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $truthy = Opal.truthy, $hash2 = Opal.hash2, $def = Opal.def, $eqeq = Opal.eqeq, $alias = Opal.alias, $rb_plus = Opal.rb_plus, $to_ary = Opal.to_ary, $send = Opal.send, $not = Opal.not, $neqeq = Opal.neqeq, $rb_gt = Opal.rb_gt, $gvars = Opal.gvars, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + Opal.add_stubs('include,attr_accessor,root?,posixify,expand_path,pwd,start_with?,==,match?,absolute_path?,+,length,descends_from?,slice,to_s,relative_path_from,new,include?,tr,partition_path,each,pop,<<,join_path,[],web_root?,unc?,index,split,delete,[]=,join,raise,!,fetch,warn,logger,empty?,nil_or_empty?,chomp,!=,>,size,extract_uri_prefix,end_with?,gsub,private,=~'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - function find_existing_class(scope, name) { - // Try to find the class in the current scope - var klass = const_get_name(scope, name); + var $nesting = [self].concat($parent_nesting); - // If the class exists in the scope, then we must use that - if (klass) { - // Make sure the existing constant is a class, or raise error - if (!klass.$$is_class) { - throw Opal.TypeError.$new(name + " is not a class"); - } + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'PathResolver'); - return klass; - } - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - function ensureSuperclassMatch(klass, superclass) { - if (klass.$$super !== superclass) { - throw Opal.TypeError.$new("superclass mismatch for class " + klass.$$name); - } - } + $proto.file_separator = $proto._partition_path_web = $proto._partition_path_sys = $proto.working_dir = nil; + + self.$include($$('Logging')); + $const_set($nesting[0], 'DOT', "."); + $const_set($nesting[0], 'DOT_DOT', ".."); + $const_set($nesting[0], 'DOT_SLASH', "./"); + $const_set($nesting[0], 'SLASH', "/"); + $const_set($nesting[0], 'BACKSLASH', "\\"); + $const_set($nesting[0], 'DOUBLE_SLASH', "//"); + $const_set($nesting[0], 'URI_CLASSLOADER', "uri:classloader:"); + $const_set($nesting[0], 'WindowsRootRx', /^(?:[a-zA-Z]:)?[\\\/]/); + self.$attr_accessor("file_separator"); + self.$attr_accessor("working_dir"); + + $def(self, '$initialize', function $$initialize(file_separator, working_dir) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; - Opal.klass = function(scope, superclass, name) { - var bridged; + + if (file_separator == null) file_separator = nil; + if (working_dir == null) working_dir = nil; + self.file_separator = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = file_separator)) ? ($ret_or_2) : ($$$($$$('File'), 'ALT_SEPARATOR'))))) ? ($ret_or_1) : ($$$($$$('File'), 'SEPARATOR'))); + self.working_dir = ($truthy(working_dir) ? (($truthy(self['$root?'](working_dir)) ? (self.$posixify(working_dir)) : ($$$('File').$expand_path(working_dir)))) : ($$$('Dir').$pwd())); + self._partition_path_sys = $hash2([], {}); + return (self._partition_path_web = $hash2([], {})); + }, -1); + + $def(self, '$absolute_path?', function $PathResolver_absolute_path$ques$1(path) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; - if (scope == null) { - // Global scope - scope = _Object; - } else if (!scope.$$is_class && !scope.$$is_module) { - // Scope is an object, use its class - scope = scope.$$class; - } + if ($truthy(($ret_or_1 = path['$start_with?']($$('SLASH'))))) { + return $ret_or_1 + } else { + + if ($truthy(($ret_or_2 = self.file_separator['$==']($$('BACKSLASH'))))) { + + return $$('WindowsRootRx')['$match?'](path); + } else { + return $ret_or_2 + } } + }); + if (($eqeq($$('RUBY_ENGINE'), "opal") && ($eqeq($$$('JAVASCRIPT_IO_MODULE'), "xmlhttprequest")))) { + + $def(self, '$root?', function $PathResolver_root$ques$2(path) { + var self = this, $ret_or_1 = nil; - // If the superclass is not an Opal-generated class then we're bridging a native JS class - if (superclass != null && !superclass.hasOwnProperty('$$is_class')) { - bridged = superclass; - superclass = _Object; - } + if ($truthy(($ret_or_1 = self['$absolute_path?'](path)))) { + return $ret_or_1 + } else { + + return path['$start_with?']("file://", "http://", "https://"); + } + }); + } else if ($eqeq($$$('RUBY_ENGINE'), "jruby")) { + + $def(self, '$root?', function $PathResolver_root$ques$3(path) { + var self = this, $ret_or_1 = nil; - var klass = find_existing_class(scope, name); + if ($truthy(($ret_or_1 = self['$absolute_path?'](path)))) { + return $ret_or_1 + } else { + + return path['$start_with?']($$('URI_CLASSLOADER')); + } + }); + } else { + $alias(self, "root?", "absolute_path?"); + } + $def(self, '$unc?', function $PathResolver_unc$ques$4(path) { + + return path['$start_with?']($$('DOUBLE_SLASH')) + }); + + $def(self, '$web_root?', function $PathResolver_web_root$ques$5(path) { + + return path['$start_with?']($$('SLASH')) + }); + + $def(self, '$descends_from?', function $PathResolver_descends_from$ques$6(path, base) { + var $ret_or_1 = nil; - if (klass) { - if (superclass) { - // Make sure existing class has same superclass - ensureSuperclassMatch(klass, superclass); - } - return klass; - } + if ($eqeq(base, path)) { + return 0 + } else if ($eqeq(base, $$('SLASH'))) { + if ($truthy(($ret_or_1 = path['$start_with?']($$('SLASH'))))) { + return 1 + } else { + return $ret_or_1 + } + } else if ($truthy(($ret_or_1 = path['$start_with?']($rb_plus(base, $$('SLASH')))))) { + + return $rb_plus(base.$length(), 1); + } else { + return $ret_or_1 + } + }); + + $def(self, '$relative_path', function $$relative_path(path, base) { + var self = this, offset = nil; - // Class doesn't exist, create a new one with given superclass... + if ($truthy(self['$root?'](path))) { + if ($truthy((offset = self['$descends_from?'](path, base)))) { + return path.$slice(offset, path.$length()) + } else { + + try { + return $$('Pathname').$new(path).$relative_path_from($$('Pathname').$new(base)).$to_s() + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return path + } finally { Opal.pop_exception(); } + } else { throw $err; } + } } + } else { + return path + } + }); + + $def(self, '$posixify', function $$posixify(path) { + var self = this; - // Not specifying a superclass means we can assume it to be Object - if (superclass == null) { - superclass = _Object; - } + if ($truthy(path)) { + if (($eqeq(self.file_separator, $$('BACKSLASH')) && ($truthy(path['$include?']($$('BACKSLASH')))))) { + + return path.$tr($$('BACKSLASH'), $$('SLASH')); + } else { + return path + } + } else { + return "" + } + }); + $alias(self, "posixfy", "posixify"); + + $def(self, '$expand_path', function $$expand_path(path) { + var $a, $b, self = this, path_segments = nil, path_root = nil, resolved_segments = nil; - // Create the class object (instance of Class) - klass = Opal.allocate_class(name, superclass); - Opal.const_set(scope, name, klass); + + $b = self.$partition_path(path), $a = $to_ary($b), (path_segments = ($a[0] == null ? nil : $a[0])), (path_root = ($a[1] == null ? nil : $a[1])); + if ($truthy(path['$include?']($$('DOT_DOT')))) { + + resolved_segments = []; + $send(path_segments, 'each', [], function $$7(segment){ + + if (segment == null) segment = nil; + if ($eqeq(segment, $$('DOT_DOT'))) { + return resolved_segments.$pop() + } else { + return resolved_segments['$<<'](segment) + }}); + return self.$join_path(resolved_segments, path_root); + } else { + return self.$join_path(path_segments, path_root) + } }); + + $def(self, '$partition_path', function $$partition_path(path, web) { + var $a, self = this, result = nil, cache = nil, posix_path = nil, root = nil, path_segments = nil; - // Call .inherited() hook with new class on the superclass - if (superclass.$inherited) { - superclass.$inherited(klass); - } + + if (web == null) web = nil; + if ($truthy((result = (cache = ($truthy(web) ? (self._partition_path_web) : (self._partition_path_sys)))['$[]'](path)))) { + return result + } posix_path = self.$posixify(path); + if ($truthy(web)) { + if ($truthy(self['$web_root?'](posix_path))) { + root = $$('SLASH'); + } else if ($truthy(posix_path['$start_with?']($$('DOT_SLASH')))) { + root = $$('DOT_SLASH'); + } + } else if ($truthy(self['$root?'](posix_path))) { + if ($truthy(self['$unc?'](posix_path))) { + root = $$('DOUBLE_SLASH'); + } else if ($truthy(posix_path['$start_with?']($$('SLASH')))) { + root = $$('SLASH'); + } else if ($truthy(posix_path['$start_with?']($$('URI_CLASSLOADER')))) { + root = posix_path.$slice(0, $$('URI_CLASSLOADER').$length()); + } else { + root = posix_path.$slice(0, $rb_plus(posix_path.$index($$('SLASH')), 1)); + } + } else if ($truthy(posix_path['$start_with?']($$('DOT_SLASH')))) { + root = $$('DOT_SLASH'); + } path_segments = ($truthy(root) ? (posix_path.$slice(root.$length(), posix_path.$length())) : (posix_path)).$split($$('SLASH')); + path_segments.$delete($$('DOT')); + return ($a = [path, [path_segments, root]], $send(cache, '[]=', $a), $a[$a.length - 1]); + }, -2); + + $def(self, '$join_path', function $$join_path(segments, root) { + + + if (root == null) root = nil; + if ($truthy(root)) { + return "" + (root) + (segments.$join($$('SLASH'))) + } else { + + return segments.$join($$('SLASH')); + } }, -2); + + $def(self, '$system_path', function $$system_path(target, start, jail, opts) { + var $a, $b, self = this, target_path = nil, $ret_or_1 = nil, target_segments = nil, jail_segments = nil, jail_root = nil, recheck = nil, start_segments = nil, start_root = nil, resolved_segments = nil, unresolved_segments = nil, warned = nil; - if (bridged) { - Opal.bridge(bridged, klass); - } + + if (start == null) start = nil; + if (jail == null) jail = nil; + if (opts == null) opts = $hash2([], {}); + if ($truthy(jail)) { + + if (!$truthy(self['$root?'](jail))) { + self.$raise($$$('SecurityError'), "Jail is not an absolute path: " + (jail)); + } jail = self.$posixify(jail); + } if ($truthy(target)) { + if ($truthy(self['$root?'](target))) { + + target_path = self.$expand_path(target); + if (($truthy(jail) && ($not(self['$descends_from?'](target_path, jail))))) { + if ($truthy(opts.$fetch("recover", true))) { + + self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail; recovering automatically"); + $b = self.$partition_path(target_path), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])); + $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])); + return self.$join_path($rb_plus(jail_segments, target_segments), jail_root); + } else { + self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " is outside of jail: " + (jail) + " (disallowed in safe mode)"); + } + } return target_path; + } else { + $b = self.$partition_path(target), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])); + } + } else { + target_segments = []; + } if ($truthy(target_segments['$empty?']())) { + if ($truthy(start['$nil_or_empty?']())) { + return ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir)) + } else if ($truthy(self['$root?'](start))) { + if ($truthy(jail)) { + start = self.$posixify(start); + } else { + return self.$expand_path(start) + } + } else { + + $b = self.$partition_path(start), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])); + start = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir)); + } + } else if ($truthy(start['$nil_or_empty?']())) { + start = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir)); + } else if ($truthy(self['$root?'](start))) { + if ($truthy(jail)) { + start = self.$posixify(start); + } + } else { + start = "" + (($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir)).$chomp("/")) + "/" + (start); + } if ((($truthy(jail) && ($truthy((recheck = self['$descends_from?'](start, jail)['$!']())))) && ($eqeq(self.file_separator, $$('BACKSLASH'))))) { + + $b = self.$partition_path(start), $a = $to_ary($b), (start_segments = ($a[0] == null ? nil : $a[0])), (start_root = ($a[1] == null ? nil : $a[1])); + $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])); + if ($neqeq(start_root, jail_root)) { + if ($truthy(opts.$fetch("recover", true))) { + + self.$logger().$warn("start path for " + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail root; recovering automatically"); + start_segments = jail_segments; + recheck = false; + } else { + self.$raise($$$('SecurityError'), "start path for " + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (start) + " refers to location outside jail root: " + (jail) + " (disallowed in safe mode)"); + } + } } else { + $b = self.$partition_path(start), $a = $to_ary($b), (start_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])); + } if ($truthy((resolved_segments = $rb_plus(start_segments, target_segments))['$include?']($$('DOT_DOT')))) { + + $a = [resolved_segments, []], (unresolved_segments = $a[0]), (resolved_segments = $a[1]); + if ($truthy(jail)) { + + if (!$truthy(jail_segments)) { + $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])); + } warned = false; + $send(unresolved_segments, 'each', [], function $$8(segment){var self = $$8.$$s == null ? this : $$8.$$s; - return klass; - } + + if (segment == null) segment = nil; + if ($eqeq(segment, $$('DOT_DOT'))) { + if ($truthy($rb_gt(resolved_segments.$size(), jail_segments.$size()))) { + return resolved_segments.$pop() + } else if ($truthy(opts.$fetch("recover", true))) { + if ($truthy(warned)) { + return nil + } else { + + self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " has illegal reference to ancestor of jail; recovering automatically"); + return (warned = true); + } + } else { + return self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " refers to location outside jail: " + (jail) + " (disallowed in safe mode)") + } + } else { + return resolved_segments['$<<'](segment) + }}, {$$s: self}); + } else { + $send(unresolved_segments, 'each', [], function $$9(segment){ + + if (segment == null) segment = nil; + if ($eqeq(segment, $$('DOT_DOT'))) { + return resolved_segments.$pop() + } else { + return resolved_segments['$<<'](segment) + }}); + } } if ($truthy(recheck)) { + + target_path = self.$join_path(resolved_segments, jail_root); + if ($truthy(self['$descends_from?'](target_path, jail))) { + return target_path + } else if ($truthy(opts.$fetch("recover", true))) { + + self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail; recovering automatically"); + if (!$truthy(jail_segments)) { + $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])); + } return self.$join_path($rb_plus(jail_segments, target_segments), jail_root); + } else { + return self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " is outside of jail: " + (jail) + " (disallowed in safe mode)") + } } else { + return self.$join_path(resolved_segments, jail_root) + } }, -2); + + $def(self, '$web_path', function $$web_path(target, start) { + var $a, $b, self = this, uri_prefix = nil, target_segments = nil, target_root = nil, resolved_segments = nil, resolved_path = nil; - // Define new module (or return existing module). The given `scope` is basically - // the current `self` value the `module` statement was defined in. If this is - // a ruby module or class, then it is used, otherwise if the scope is a ruby - // object then that objects real ruby class is used (e.g. if the scope is the - // main object, then the top level `Object` class is used as the scope). - // - // If a module of the given name is already defined in the scope, then that - // instance is just returned. - // - // If there is a class of the given name in the scope, then an error is - // generated instead (cannot have a class and module of same name in same scope). - // - // Otherwise, a new module is created in the scope with the given name, and that - // new instance is returned back (to be referenced at runtime). - // - // @param scope [Module, Class] class or module this definition is inside - // @param id [String] the name of the new (or existing) module - // - // @return [Module] - Opal.allocate_module = function(name) { - var constructor = function(){}; - if (name) { - $defineProperty(constructor, 'displayName', name+'.$$constructor'); - } + + if (start == null) start = nil; + target = self.$posixify(target); + start = self.$posixify(start); + if (!($truthy(start['$nil_or_empty?']()) || ($truthy(self['$web_root?'](target))))) { + $b = self.$extract_uri_prefix("" + (start) + (($truthy(start['$end_with?']($$('SLASH'))) ? ("") : ($$('SLASH')))) + (target)), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (uri_prefix = ($a[1] == null ? nil : $a[1])); + } $b = self.$partition_path(target, true), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])), (target_root = ($a[1] == null ? nil : $a[1])); + resolved_segments = []; + $send(target_segments, 'each', [], function $$10(segment){ + + if (segment == null) segment = nil; + if ($eqeq(segment, $$('DOT_DOT'))) { + if ($truthy(resolved_segments['$empty?']())) { + if (($truthy(target_root) && ($neqeq(target_root, $$('DOT_SLASH'))))) { + return nil + } else { + return resolved_segments['$<<'](segment) + } + } else if ($eqeq(resolved_segments['$[]'](-1), $$('DOT_DOT'))) { + return resolved_segments['$<<'](segment) + } else { + return resolved_segments.$pop() + } + } else { + return resolved_segments['$<<'](segment) + }}); + if ($truthy((resolved_path = self.$join_path(resolved_segments, target_root))['$include?'](" "))) { + resolved_path = resolved_path.$gsub(" ", "%20"); + } if ($truthy(uri_prefix)) { + return "" + (uri_prefix) + (resolved_path) + } else { + return resolved_path + } }, -2); + self.$private(); + return $def(self, '$extract_uri_prefix', function $$extract_uri_prefix(str) { + var $a; - var module = constructor; + if (($truthy(str['$include?'](":")) && ($truthy($$('UriSniffRx')['$=~'](str))))) { + return [str.$slice((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length(), str.$length()), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))] + } else { + return str + } + }); + })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; - if (name) - $defineProperty(constructor, 'displayName', name+'.constructor'); - - $defineProperty(module, '$$name', name); - $defineProperty(module, '$$prototype', constructor.prototype); - $defineProperty(module, '$$const', {}); - $defineProperty(module, '$$is_module', true); - $defineProperty(module, '$$is_a_module', true); - $defineProperty(module, '$$cvars', {}); - $defineProperty(module, '$$iclasses', []); - $defineProperty(module, '$$own_included_modules', []); - $defineProperty(module, '$$own_prepended_modules', []); - $defineProperty(module, '$$ancestors', [module]); - $defineProperty(module, '$$ancestors_cache_version', null); - - $setPrototype(module, Opal.Module.prototype); +Opal.modules["asciidoctor/reader"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $rb_plus = Opal.rb_plus, $alias = Opal.alias, $hash2 = Opal.hash2, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $to_ary = Opal.to_ary, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $send = Opal.send, $rb_minus = Opal.rb_minus, $thrower = Opal.thrower, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $neqeq = Opal.neqeq, $to_a = Opal.to_a, $assign_ivar_val = Opal.assign_ivar_val, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_ge = Opal.rb_ge, $gvars = Opal.gvars, $rb_lt = Opal.rb_lt, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - return module; - } + Opal.add_stubs('include,attr_reader,+,line_info,attr_accessor,!,===,split,file,dir,dirname,path,basename,lineno,reverse,prepare_lines,empty?,nil_or_empty?,peek_line,[],>,slice,length,process_line,times,shift,read_line,<<,-,unshift_all,has_more_lines?,read_lines,join,unshift,unshift_line,unshift_lines,replace_next_line,start_with?,==,*,read_lines_until,size,clear,cursor,[]=,fetch,!=,cursor_at_mark,warn,logger,message_with_context,pop,push,respond_to?,reverse_each,new,tap,each,instance_variables,instance_variable_get,drop,instance_variable_set,class,object_id,inspect,private,prepare_source_array,prepare_source_string,chomp,valid_encoding?,to_s,raise,to_i,attributes,catalog,pop_include,parse,path=,dup,end_with?,keys,rindex,rootname,key?,attr,reverse!,>=,exceeds_max_depth?,nil?,include_processors?,extensions,extensions?,include_processors,map,skip_front_matter!,adjust_indentation!,include?,=~,preprocess_conditional_directive,preprocess_include_directive,downcase,error,none?,any?,all?,strip,send,resolve_expr_val,rstrip,sub_attributes,attribute_missing,info,parse_attributes,find,handles?,instance,process_method,safe,resolve_include_path,method,split_delimited_value,partition,<,to_a,uniq,sort,call,each_line,infinite?,push_include,delete,first,values,value?,create_include_cursor,delete_at,keep_if,read,uriish?,attr?,require_library,normalize_system_path,file?,relative_path,path_resolver,base_dir,to_f'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - function find_existing_module(scope, name) { - var module = const_get_name(scope, name); - if (module == null && scope === _Object) module = const_lookup_ancestors(_Object, name); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (module) { - if (!module.$$is_module && module !== _Object) { - throw Opal.TypeError.$new(name + " is not a module"); - } - } + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Reader'); - return module; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - Opal.module = function(scope, name) { - var module; + $proto.file = $proto.lines = $proto.look_ahead = $proto.unescape_next_line = $proto.lineno = $proto.process_lines = $proto.dir = $proto.path = $proto.mark = $proto.source_lines = $proto.saved = nil; + + self.$include($$('Logging')); + (function($base, $super) { + var self = $klass($base, $super, 'Cursor'); - if (scope == null) { - // Global scope - scope = _Object; - } else if (!scope.$$is_class && !scope.$$is_module) { - // Scope is an object, use its class - scope = scope.$$class; - } + var $proto = self.$$prototype; - module = find_existing_module(scope, name); + $proto.lineno = $proto.path = nil; + + self.$attr_reader("file", "dir", "path", "lineno"); + + $def(self, '$initialize', function $$initialize(file, dir, path, lineno) { + var $a, self = this; - if (module) { - return module; - } + + if (dir == null) dir = nil; + if (path == null) path = nil; + if (lineno == null) lineno = 1; + return $a = [file, dir, path, lineno], (self.file = $a[0]), (self.dir = $a[1]), (self.path = $a[2]), (self.lineno = $a[3]), $a; + }, -2); + + $def(self, '$advance', function $$advance(num) { + var self = this; - // Module doesnt exist, create a new one... - module = Opal.allocate_module(name); - Opal.const_set(scope, name, module); + return (self.lineno = $rb_plus(self.lineno, num)) + }); + + $def(self, '$line_info', function $$line_info() { + var self = this; - return module; - } + return "" + (self.path) + ": line " + (self.lineno) + }); + return $alias(self, "to_s", "line_info"); + })($nesting[0], null); + self.$attr_reader("file"); + self.$attr_reader("dir"); + self.$attr_reader("path"); + self.$attr_reader("lineno"); + self.$attr_reader("source_lines"); + self.$attr_accessor("process_lines"); + self.$attr_accessor("unterminated"); + + $def(self, '$initialize', function $$initialize(data, cursor, opts) { + var $a, $b, self = this, $ret_or_1 = nil; - // Return the singleton class for the passed object. - // - // If the given object alredy has a singleton class, then it will be stored on - // the object as the `$$meta` property. If this exists, then it is simply - // returned back. - // - // Otherwise, a new singleton object for the class or object is created, set on - // the object at `$$meta` for future use, and then returned. - // - // @param object [Object] the ruby object - // @return [Class] the singleton class for object - Opal.get_singleton_class = function(object) { - if (object.$$meta) { - return object.$$meta; - } + + if (data == null) data = nil; + if (cursor == null) cursor = nil; + if (opts == null) opts = $hash2([], {}); + if ($not(cursor)) { + + self.file = nil; + self.dir = "."; + self.path = "<stdin>"; + self.lineno = 1; + } else if ($eqeqeq($$$('String'), cursor)) { + + self.file = cursor; + $b = $$$('File').$split(self.file), $a = $to_ary($b), (self.dir = ($a[0] == null ? nil : $a[0])), (self.path = ($a[1] == null ? nil : $a[1])); + self.lineno = 1; + } else { + + if ($truthy((self.file = cursor.$file()))) { + + self.dir = ($truthy(($ret_or_1 = cursor.$dir())) ? ($ret_or_1) : ($$$('File').$dirname(self.file))); + self.path = ($truthy(($ret_or_1 = cursor.$path())) ? ($ret_or_1) : ($$$('File').$basename(self.file))); + } else { + + self.dir = ($truthy(($ret_or_1 = cursor.$dir())) ? ($ret_or_1) : (".")); + self.path = ($truthy(($ret_or_1 = cursor.$path())) ? ($ret_or_1) : ("<stdin>")); + } self.lineno = ($truthy(($ret_or_1 = cursor.$lineno())) ? ($ret_or_1) : (1)); + } self.lines = (self.source_lines = self.$prepare_lines(data, opts)).$reverse(); + self.mark = nil; + self.look_ahead = 0; + self.process_lines = true; + self.unescape_next_line = false; + self.unterminated = nil; + return (self.saved = nil); + }, -1); + + $def(self, '$has_more_lines?', function $Reader_has_more_lines$ques$1() { + var self = this; - if (object.hasOwnProperty('$$is_class')) { - return Opal.build_class_singleton_class(object); - } else if (object.hasOwnProperty('$$is_module')) { - return Opal.build_module_singletin_class(object); - } else { - return Opal.build_object_singleton_class(object); - } - }; + if ($truthy(self.lines['$empty?']())) { + + self.look_ahead = 0; + return false; + } else { + return true + } + }); + + $def(self, '$empty?', function $Reader_empty$ques$2() { + var self = this; - // Build the singleton class for an existing class. Class object are built - // with their singleton class already in the prototype chain and inheriting - // from their superclass object (up to `Class` itself). - // - // NOTE: Actually in MRI a class' singleton class inherits from its - // superclass' singleton class which in turn inherits from Class. - // - // @param klass [Class] - // @return [Class] - Opal.build_class_singleton_class = function(klass) { - var superclass, meta; + if ($truthy(self.lines['$empty?']())) { + + self.look_ahead = 0; + return true; + } else { + return false + } + }); + $alias(self, "eof?", "empty?"); + + $def(self, '$next_line_empty?', function $Reader_next_line_empty$ques$3() { + var self = this; - if (klass.$$meta) { - return klass.$$meta; - } + return self.$peek_line()['$nil_or_empty?']() + }); + + $def(self, '$peek_line', function $$peek_line(direct) { + var self = this, next_line = nil, line = nil; - // The singleton_class superclass is the singleton_class of its superclass; - // but BasicObject has no superclass (its `$$super` is null), thus we - // fallback on `Class`. - superclass = klass === BasicObject ? Class : Opal.get_singleton_class(klass.$$super); + + if (direct == null) direct = false; + while ($truthy(true)) { + + next_line = self.lines['$[]'](-1); + if (($truthy(direct) || ($truthy($rb_gt(self.look_ahead, 0))))) { + return ($truthy(self.unescape_next_line) ? (next_line.$slice(1, next_line.$length())) : (next_line)) + } else if ($truthy(next_line)) { + if ($truthy((line = self.$process_line(next_line)))) { + return line + } + } else { + + self.look_ahead = 0; + return nil; + } } }, -1); + + $def(self, '$peek_lines', function $$peek_lines(num, direct) { + var self = this, old_look_ahead = nil, result = nil, $ret_or_1 = nil; - meta = Opal.allocate_class(null, superclass, function(){}); + + if (num == null) num = nil; + if (direct == null) direct = false; + old_look_ahead = self.look_ahead; + result = []; + (function(){try { var $t_break = $thrower('break'); return $send(($truthy(($ret_or_1 = num)) ? ($ret_or_1) : ($$('MAX_INT'))), 'times', [], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s, line = nil; + if (self.lineno == null) self.lineno = nil; - $defineProperty(meta, '$$is_singleton', true); - $defineProperty(meta, '$$singleton_of', klass); - $defineProperty(klass, '$$meta', meta); - $setPrototype(klass, meta.$$prototype); - // Restoring ClassName.class - $defineProperty(klass, '$$class', Opal.Class); + if ($truthy((line = ($truthy(direct) ? (self.$shift()) : (self.$read_line()))))) { + return result['$<<'](line) + } else { + + if ($truthy(direct)) { + self.lineno = $rb_minus(self.lineno, 1); + }; + $t_break.$throw(); + }}, {$$s: self})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + if (!$truthy(result['$empty?']())) { + + self.$unshift_all(result); + if ($truthy(direct)) { + self.look_ahead = old_look_ahead; + } } return result; + }, -1); + + $def(self, '$read_line', function $$read_line() { + var self = this; - return meta; - }; + if (($truthy($rb_gt(self.look_ahead, 0)) || ($truthy(self['$has_more_lines?']())))) { + return self.$shift() + } else { + return nil + } + }); + + $def(self, '$read_lines', function $$read_lines() { + var self = this, lines = nil; - Opal.build_module_singletin_class = function(mod) { - if (mod.$$meta) { - return mod.$$meta; - } + + lines = []; + while ($truthy(self['$has_more_lines?']())) { + lines['$<<'](self.$shift()); + } return lines; + }); + $alias(self, "readlines", "read_lines"); + + $def(self, '$read', function $$read() { + var self = this; - var meta = Opal.allocate_class(null, Opal.Module, function(){}); + return self.$read_lines().$join($$('LF')) + }); + + $def(self, '$advance', function $$advance() { + var self = this; - $defineProperty(meta, '$$is_singleton', true); - $defineProperty(meta, '$$singleton_of', mod); - $defineProperty(mod, '$$meta', meta); - $setPrototype(mod, meta.$$prototype); - // Restoring ModuleName.class - $defineProperty(mod, '$$class', Opal.Module); + if ($truthy(self.$shift())) { + return true + } else { + return false + } + }); + + $def(self, '$unshift_line', function $$unshift_line(line_to_restore) { + var self = this; - return meta; - } + + self.$unshift(line_to_restore); + return nil; + }); + $alias(self, "restore_line", "unshift_line"); + + $def(self, '$unshift_lines', function $$unshift_lines(lines_to_restore) { + var self = this; - // Build the singleton class for a Ruby (non class) Object. - // - // @param object [Object] - // @return [Class] - Opal.build_object_singleton_class = function(object) { - var superclass = object.$$class, - klass = Opal.allocate_class(nil, superclass, function(){}); + return self.$unshift_all(lines_to_restore) + }); + $alias(self, "restore_lines", "unshift_lines"); + + $def(self, '$replace_next_line', function $$replace_next_line(replacement) { + var self = this; - $defineProperty(klass, '$$is_singleton', true); - $defineProperty(klass, '$$singleton_of', object); + + self.$shift(); + self.$unshift(replacement); + return true; + }); + $alias(self, "replace_line", "replace_next_line"); + + $def(self, '$skip_blank_lines', function $$skip_blank_lines() { + var self = this, num_skipped = nil, next_line = nil; - delete klass.$$prototype.$$class; + + if ($truthy(self['$empty?']())) { + return nil + } num_skipped = 0; + while ($truthy((next_line = self.$peek_line()))) { + if ($truthy(next_line['$empty?']())) { + + self.$shift(); + num_skipped = $rb_plus(num_skipped, 1); + } else { + return num_skipped + } + } }); + + $def(self, '$skip_comment_lines', function $$skip_comment_lines() { + var self = this, $ret_or_1 = nil, next_line = nil, ll = nil; - $defineProperty(object, '$$meta', klass); + + if ($truthy(self['$empty?']())) { + return nil + } while ($truthy(($truthy(($ret_or_1 = (next_line = self.$peek_line()))) ? (next_line['$empty?']()['$!']()) : ($ret_or_1)))) { + if ($truthy(next_line['$start_with?']("//"))) { + if ($truthy(next_line['$start_with?']("///"))) { + if (($truthy($rb_gt((ll = next_line.$length()), 3)) && ($eqeq(next_line, $rb_times("/", ll))))) { + self.$read_lines_until($hash2(["terminator", "skip_first_line", "read_last_line", "skip_processing", "context"], {"terminator": next_line, "skip_first_line": true, "read_last_line": true, "skip_processing": true, "context": "comment"})); + } else { + break + } + } else { + self.$shift(); + } + } else { + break + } + } return nil; + }); + + $def(self, '$skip_line_comments', function $$skip_line_comments() { + var self = this, comment_lines = nil, $ret_or_1 = nil, next_line = nil; - $setPrototype(object, object.$$meta.$$prototype); + + if ($truthy(self['$empty?']())) { + return [] + } comment_lines = []; + while ($truthy(($truthy(($ret_or_1 = (next_line = self.$peek_line()))) ? (next_line['$empty?']()['$!']()) : ($ret_or_1)))) { + if ($truthy(next_line['$start_with?']("//"))) { + comment_lines['$<<'](self.$shift()); + } else { + break + } + } return comment_lines; + }); + + $def(self, '$terminate', function $$terminate() { + var self = this; - return klass; - }; + + self.lineno = $rb_plus(self.lineno, self.lines.$size()); + self.lines.$clear(); + self.look_ahead = 0; + return nil; + }); + + $def(self, '$read_lines_until', function $$read_lines_until(options) { + var $a, $yield = $$read_lines_until.$$p || nil, self = this, result = nil, restore_process_lines = nil, terminator = nil, start_cursor = nil, $ret_or_1 = nil, break_on_blank_lines = nil, break_on_list_continuation = nil, skip_comments = nil, line_read = nil, line_restored = nil, line = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil, $ret_or_5 = nil, context = nil; - Opal.is_method = function(prop) { - return (prop[0] === '$' && prop[1] !== '$'); - } + $$read_lines_until.$$p = null; + + if (options == null) options = $hash2([], {}); + result = []; + if (($truthy(self.process_lines) && ($truthy(options['$[]']("skip_processing"))))) { + + self.process_lines = false; + restore_process_lines = true; + } if ($truthy((terminator = options['$[]']("terminator")))) { + + start_cursor = ($truthy(($ret_or_1 = options['$[]']("cursor"))) ? ($ret_or_1) : (self.$cursor())); + break_on_blank_lines = false; + break_on_list_continuation = false; + } else { + + break_on_blank_lines = options['$[]']("break_on_blank_lines"); + break_on_list_continuation = options['$[]']("break_on_list_continuation"); + } skip_comments = options['$[]']("skip_line_comments"); + line_read = (line_restored = nil); + if ($truthy(options['$[]']("skip_first_line"))) { + self.$shift(); + } while ($truthy((line = self.$read_line()))) { + + if ($truthy(($truthy(terminator) ? (line['$=='](terminator)) : (($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = break_on_blank_lines)) ? (line['$empty?']()) : ($ret_or_3)))) ? ($ret_or_2) : (($truthy(($ret_or_3 = ($truthy(($ret_or_4 = ($truthy(($ret_or_5 = break_on_list_continuation)) ? (line_read) : ($ret_or_5)))) ? (line['$==']($$('LIST_CONTINUATION'))) : ($ret_or_4)))) ? (($a = ["preserve_last_line", true], $send(options, '[]=', $a), $a[$a.length - 1])) : ($ret_or_3)))))) ? ($ret_or_1) : (($truthy(($ret_or_2 = ($yield !== nil))) ? (Opal.yield1($yield, line)) : ($ret_or_2)))))))) { + + if ($truthy(options['$[]']("read_last_line"))) { + result['$<<'](line); + } if ($truthy(options['$[]']("preserve_last_line"))) { + + self.$unshift(line); + line_restored = true; + } break; + } if (!(($truthy(skip_comments) && ($truthy(line['$start_with?']("//")))) && ($not(line['$start_with?']("///"))))) { + + result['$<<'](line); + line_read = true; + } } if ($truthy(restore_process_lines)) { + + self.process_lines = true; + if (($truthy(line_restored) && ($not(terminator)))) { + self.look_ahead = $rb_minus(self.look_ahead, 1); + } } if ((($truthy(terminator) && ($neqeq(terminator, line))) && ($truthy((context = options.$fetch("context", terminator)))))) { + + if ($eqeq(start_cursor, "at_mark")) { + start_cursor = self.$cursor_at_mark(); + } self.$logger().$warn(self.$message_with_context("unterminated " + (context) + " block", $hash2(["source_location"], {"source_location": start_cursor}))); + self.unterminated = true; + } return result; + }, -1); + + $def(self, '$shift', function $$shift() { + var self = this; - Opal.instance_methods = function(mod) { - var exclude = [], results = [], ancestors = Opal.ancestors(mod); + + self.lineno = $rb_plus(self.lineno, 1); + if (!$eqeq(self.look_ahead, 0)) { + self.look_ahead = $rb_minus(self.look_ahead, 1); + } return self.lines.$pop(); + }); + + $def(self, '$unshift', function $$unshift(line) { + var self = this; - for (var i = 0, l = ancestors.length; i < l; i++) { - var ancestor = ancestors[i], - proto = ancestor.$$prototype; + + self.lineno = $rb_minus(self.lineno, 1); + self.look_ahead = $rb_plus(self.look_ahead, 1); + self.lines.$push(line); + return nil; + }); + if ($eqeq($$$('RUBY_ENGINE'), "jruby")) { + + $def(self, '$unshift_all', function $$unshift_all(lines_to_restore) { + var self = this; - if (proto.hasOwnProperty('$$dummy')) { - proto = proto.$$define_methods_on; - } + + self.lineno = $rb_minus(self.lineno, lines_to_restore.$size()); + self.look_ahead = $rb_plus(self.look_ahead, lines_to_restore.$size()); + if ($truthy(lines_to_restore['$respond_to?']("reverse"))) { + $send(self.lines, 'push', $to_a(lines_to_restore.$reverse())); + } else { + $send(lines_to_restore, 'reverse_each', [], function $$5(it){var self = $$5.$$s == null ? this : $$5.$$s; + if (self.lines == null) self.lines = nil; - var props = Object.getOwnPropertyNames(proto); + + if (it == null) it = nil; + return self.lines.$push(it);}, {$$s: self}); + } return nil; + }); + } else { + + $def(self, '$unshift_all', function $$unshift_all(lines_to_restore) { + var self = this; - for (var j = 0, ll = props.length; j < ll; j++) { - var prop = props[j]; + + self.lineno = $rb_minus(self.lineno, lines_to_restore.$size()); + self.look_ahead = $rb_plus(self.look_ahead, lines_to_restore.$size()); + $send(self.lines, 'push', $to_a(lines_to_restore.$reverse())); + return nil; + }); + } + $def(self, '$cursor', function $$cursor() { + var self = this; - if (Opal.is_method(prop)) { - var method_name = prop.slice(1), - method = proto[prop]; + return $$('Cursor').$new(self.file, self.dir, self.path, self.lineno) + }); + + $def(self, '$cursor_at_line', function $$cursor_at_line(lineno) { + var self = this; - if (method.$$stub && exclude.indexOf(method_name) === -1) { - exclude.push(method_name); - } + return $$('Cursor').$new(self.file, self.dir, self.path, lineno) + }); + + $def(self, '$cursor_at_mark', function $$cursor_at_mark() { + var self = this; - if (!method.$$stub && results.indexOf(method_name) === -1 && exclude.indexOf(method_name) === -1) { - results.push(method_name); - } + if ($truthy(self.mark)) { + return $send($$('Cursor'), 'new', $to_a(self.mark)) + } else { + return self.$cursor() } - } - } - - return results; - } - - Opal.own_instance_methods = function(mod) { - var results = [], - proto = mod.$$prototype; + }); + + $def(self, '$cursor_before_mark', function $$cursor_before_mark() { + var $a, $b, self = this, m_file = nil, m_dir = nil, m_path = nil, m_lineno = nil; - if (proto.hasOwnProperty('$$dummy')) { - proto = proto.$$define_methods_on; - } + if ($truthy(self.mark)) { + + $b = self.mark, $a = $to_ary($b), (m_file = ($a[0] == null ? nil : $a[0])), (m_dir = ($a[1] == null ? nil : $a[1])), (m_path = ($a[2] == null ? nil : $a[2])), (m_lineno = ($a[3] == null ? nil : $a[3])); + return $$('Cursor').$new(m_file, m_dir, m_path, $rb_minus(m_lineno, 1)); + } else { + return $$('Cursor').$new(self.file, self.dir, self.path, $rb_minus(self.lineno, 1)) + } + }); + + $def(self, '$cursor_at_prev_line', function $$cursor_at_prev_line() { + var self = this; - var props = Object.getOwnPropertyNames(proto); + return $$('Cursor').$new(self.file, self.dir, self.path, $rb_minus(self.lineno, 1)) + }); + + $def(self, '$mark', function $$mark() { + var self = this; - for (var i = 0, length = props.length; i < length; i++) { - var prop = props[i]; + return (self.mark = [self.file, self.dir, self.path, self.lineno]) + }); + + $def(self, '$line_info', function $$line_info() { + var self = this; - if (Opal.is_method(prop)) { - var method = proto[prop]; + return "" + (self.path) + ": line " + (self.lineno) + }); + + $def(self, '$lines', function $$lines() { + var self = this; - if (!method.$$stub) { - var method_name = prop.slice(1); - results.push(method_name); - } - } - } + return self.lines.$reverse() + }); + + $def(self, '$string', function $$string() { + var self = this; - return results; - } + return self.lines.$reverse().$join($$('LF')) + }); + + $def(self, '$source', function $$source() { + var self = this; - Opal.methods = function(obj) { - return Opal.instance_methods(Opal.get_singleton_class(obj)); - } + return self.source_lines.$join($$('LF')) + }); + + $def(self, '$save', function $$save() { + var self = this; - Opal.own_methods = function(obj) { - return Opal.own_instance_methods(Opal.get_singleton_class(obj)); - } + + self.saved = $send($hash2([], {}), 'tap', [], function $$6(accum){var self = $$6.$$s == null ? this : $$6.$$s; - Opal.receiver_methods = function(obj) { - var mod = Opal.get_singleton_class(obj); - var singleton_methods = Opal.own_instance_methods(mod); - var instance_methods = Opal.own_instance_methods(mod.$$super); - return singleton_methods.concat(instance_methods); - } + + if (accum == null) accum = nil; + return $send(self.$instance_variables(), 'each', [], function $$7(name){var $a, self = $$7.$$s == null ? this : $$7.$$s, val = nil; - // Returns an object containing all pairs of names/values - // for all class variables defined in provided +module+ - // and its ancestors. - // - // @param module [Module] - // @return [Object] - Opal.class_variables = function(module) { - var ancestors = Opal.ancestors(module), - i, length = ancestors.length, - result = {}; + + if (name == null) name = nil; + if (($eqeq(name, "@saved") || ($eqeq(name, "@source_lines")))) { + return nil + } else { + return ($a = [name, ($eqeqeq($$$('Array'), (val = self.$instance_variable_get(name))) ? (val.$drop(0)) : (val))], $send(accum, '[]=', $a), $a[$a.length - 1]) + }}, {$$s: self});}, {$$s: self}); + return nil; + }); + + $def(self, '$restore_save', function $$restore_save() { + var self = this; - for (i = length - 1; i >= 0; i--) { - var ancestor = ancestors[i]; + if ($truthy(self.saved)) { + + $send(self.saved, 'each', [], function $$8(name, val){var self = $$8.$$s == null ? this : $$8.$$s; - for (var cvar in ancestor.$$cvars) { - result[cvar] = ancestor.$$cvars[cvar]; - } - } + + if (name == null) name = nil; + if (val == null) val = nil; + return self.$instance_variable_set(name, val);}, {$$s: self}); + return (self.saved = nil); + } else { + return nil + } + }); + + $def(self, '$discard_save', $assign_ivar_val("saved", nil)); + + $def(self, '$to_s', function $$to_s() { + var self = this; - return result; - } + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {path: " + (self.path.$inspect()) + ", line: " + (self.lineno) + "}>" + }); + self.$private(); + + $def(self, '$prepare_lines', function $$prepare_lines(data, opts) { + var self = this, normalize = nil; - // Sets class variable with specified +name+ to +value+ - // in provided +module+ - // - // @param module [Module] - // @param name [String] - // @param value [Object] - Opal.class_variable_set = function(module, name, value) { - var ancestors = Opal.ancestors(module), - i, length = ancestors.length; + + if (opts == null) opts = $hash2([], {}); + try { + if ($truthy((normalize = opts['$[]']("normalize")))) { + if ($eqeqeq($$$('Array'), data)) { + + return $$('Helpers').$prepare_source_array(data, normalize['$!=']("chomp")); + } else { + + return $$('Helpers').$prepare_source_string(data, normalize['$!=']("chomp")); + } + } else if ($eqeqeq($$$('Array'), data)) { + return data.$drop(0) + } else if ($truthy(data)) { + return data.$chomp().$split($$('LF'), -1) + } else { + return [] + } + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + if ($truthy(($eqeqeq($$$('Array'), data) ? (data.$join()) : (data.$to_s()))['$valid_encoding?']())) { + return self.$raise() + } else { + return self.$raise($$$('ArgumentError'), "source is either binary or contains invalid Unicode data") + } + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -2); + return $def(self, '$process_line', function $$process_line(line) { + var self = this; - for (i = length - 2; i >= 0; i--) { - var ancestor = ancestors[i]; + + if ($truthy(self.process_lines)) { + self.look_ahead = $rb_plus(self.look_ahead, 1); + } return line; + }); + })($nesting[0], null, $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'PreprocessorReader'); - if ($hasOwn.call(ancestor.$$cvars, name)) { - ancestor.$$cvars[name] = value; - return value; - } - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - module.$$cvars[name] = value; + $proto.include_stack = $proto.lines = $proto.file = $proto.dir = $proto.path = $proto.lineno = $proto.maxdepth = $proto.process_lines = $proto.includes = $proto.document = $proto.unescape_next_line = $proto.include_processor_extensions = $proto.look_ahead = $proto.skipping = $proto.conditional_stack = nil; + + self.$attr_reader("include_stack"); + + $def(self, '$initialize', function $$initialize(document, data, cursor, opts) { + $$initialize.$$p || nil; var self = this, default_include_depth = nil, $ret_or_1 = nil; - return value; - } + $$initialize.$$p = null; + + if (data == null) data = nil; + if (cursor == null) cursor = nil; + if (opts == null) opts = $hash2([], {}); + self.document = document; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [data, cursor, opts], null); + if ($truthy($rb_gt((default_include_depth = ($truthy(($ret_or_1 = document.$attributes()['$[]']("max-include-depth"))) ? ($ret_or_1) : (64)).$to_i()), 0))) { + self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": default_include_depth, "curr": default_include_depth, "rel": default_include_depth}); + } else { + self.maxdepth = nil; + } self.include_stack = []; + self.includes = document.$catalog()['$[]']("includes"); + self.skipping = false; + self.conditional_stack = []; + return (self.include_processor_extensions = nil); + }, -2); + + $def(self, '$has_more_lines?', function $PreprocessorReader_has_more_lines$ques$9() { + var self = this; - function isRoot(proto) { - return proto.hasOwnProperty('$$iclass') && proto.hasOwnProperty('$$root'); - } + if ($truthy(self.$peek_line())) { + return true + } else { + return false + } + }); + + $def(self, '$empty?', function $PreprocessorReader_empty$ques$10() { + var self = this; - function own_included_modules(module) { - var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype); + if ($truthy(self.$peek_line())) { + return false + } else { + return true + } + }); + $alias(self, "eof?", "empty?"); + + $def(self, '$peek_line', function $$peek_line(direct) { + var $yield = $$peek_line.$$p || nil, self = this, line = nil; - while (proto) { - if (proto.hasOwnProperty('$$class')) { - // superclass - break; - } - mod = protoToModule(proto); - if (mod) { - result.push(mod); - } - proto = Object.getPrototypeOf(proto); - } + $$peek_line.$$p = null; + + if (direct == null) direct = false; + if ($truthy((line = $send2(self, $find_super(self, 'peek_line', $$peek_line, false, true), 'peek_line', [direct], $yield)))) { + return line + } else if ($truthy(self.include_stack['$empty?']())) { + return nil + } else { + + self.$pop_include(); + return self.$peek_line(direct); + } }, -1); + + $def(self, '$push_include', function $$push_include(data, file, path, lineno, attributes) { + var self = this, dir = nil, $ret_or_1 = nil, rel_maxdepth = nil, curr_maxdepth = nil, abs_maxdepth = nil, leveloffset = nil; - return result; - } + + if (file == null) file = nil; + if (path == null) path = nil; + if (lineno == null) lineno = 1; + if (attributes == null) attributes = $hash2([], {}); + self.include_stack['$<<']([self.lines, self.file, self.dir, self.path, self.lineno, self.maxdepth, self.process_lines]); + if ($truthy((self.file = file))) { + + if ($eqeqeq($$$('String'), file)) { + self.dir = $$$('File').$dirname(file); + } else if ($truthy($$('RUBY_ENGINE_OPAL'))) { + self.dir = $$$('URI').$parse($$$('File').$dirname((file = file.$to_s()))); + } else { + + (self.dir = file.$dup())['$path='](($eqeq((dir = $$$('File').$dirname(file.$path())), "/") ? ("") : (dir))); + file = file.$to_s(); + } self.path = (path = ($truthy(($ret_or_1 = path)) ? ($ret_or_1) : ($$$('File').$basename(file)))); + if ($truthy((self.process_lines = $send(file, 'end_with?', $to_a($$('ASCIIDOC_EXTENSIONS').$keys()))))) { + if ($truthy(($ret_or_1 = self.includes['$[]'](path.$slice(0, path.$rindex(".")))))) ; else { + self.includes['$[]='](path.$slice(0, path.$rindex(".")), ($truthy(attributes['$[]']("partial-option")) ? (nil) : (true))); + } + } } else { + + self.dir = "."; + self.process_lines = true; + if ($truthy((self.path = path))) { + if ($truthy(($ret_or_1 = self.includes['$[]']($$('Helpers').$rootname(path))))) ; else { + self.includes['$[]=']($$('Helpers').$rootname(path), ($truthy(attributes['$[]']("partial-option")) ? (nil) : (true))); + } + } else { + self.path = "<stdin>"; + } } self.lineno = lineno; + if (($truthy(self.maxdepth) && ($truthy(attributes['$key?']("depth"))))) { + if ($truthy($rb_gt((rel_maxdepth = attributes['$[]']("depth").$to_i()), 0))) { + + if ($truthy($rb_gt((curr_maxdepth = $rb_plus(self.include_stack.$size(), rel_maxdepth)), (abs_maxdepth = self.maxdepth['$[]']("abs"))))) { + curr_maxdepth = (rel_maxdepth = abs_maxdepth); + } self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": abs_maxdepth, "curr": curr_maxdepth, "rel": rel_maxdepth}); + } else { + self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": self.maxdepth['$[]']("abs"), "curr": self.include_stack.$size(), "rel": 0}); + } + } if ($truthy((self.lines = self.$prepare_lines(data, $hash2(["normalize", "condense", "indent"], {"normalize": ($truthy(($ret_or_1 = self.process_lines)) ? ($ret_or_1) : ("chomp")), "condense": false, "indent": attributes['$[]']("indent")})))['$empty?']())) { + self.$pop_include(); + } else { + + if ($truthy(attributes['$key?']("leveloffset"))) { + + self.lines = $rb_plus($rb_plus([($truthy((leveloffset = self.document.$attr("leveloffset"))) ? (":leveloffset: " + (leveloffset)) : (":leveloffset!:")), ""], self.lines.$reverse()), ["", ":leveloffset: " + (attributes['$[]']("leveloffset"))]); + self.lineno = $rb_minus(self.lineno, 2); + } else { + self.lines['$reverse!'](); + } self.look_ahead = 0; + } return self; + }, -2); + + $def(self, '$include_depth', function $$include_depth() { + var self = this; - function own_prepended_modules(module) { - var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype); + return self.include_stack.$size() + }); + + $def(self, '$exceeds_max_depth?', function $PreprocessorReader_exceeds_max_depth$ques$11() { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; - if (module.$$prototype.hasOwnProperty('$$dummy')) { - while (proto) { - if (proto === module.$$prototype.$$define_methods_on) { - break; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.maxdepth)) ? ($rb_ge(self.include_stack.$size(), self.maxdepth['$[]']("curr"))) : ($ret_or_2))))) { + return self.maxdepth['$[]']("rel") + } else { + return $ret_or_1 } + }); + $alias(self, "exceeded_max_depth?", "exceeds_max_depth?"); + + $def(self, '$shift', function $$shift() { + var $yield = $$shift.$$p || nil, self = this, line = nil; - mod = protoToModule(proto); - if (mod) { - result.push(mod); + $$shift.$$p = null; + if ($truthy(self.unescape_next_line)) { + + self.unescape_next_line = false; + return (line = $send2(self, $find_super(self, 'shift', $$shift, false, true), 'shift', [], $yield)).$slice(1, line.$length()); + } else { + return $send2(self, $find_super(self, 'shift', $$shift, false, true), 'shift', [], $yield) } + }); + + $def(self, '$include_processors?', function $PreprocessorReader_include_processors$ques$12() { + var self = this; - proto = Object.getPrototypeOf(proto); - } - } - - return result; - } - + if ($truthy(self.include_processor_extensions['$nil?']())) { + if (($truthy(self.document['$extensions?']()) && ($truthy(self.document.$extensions()['$include_processors?']())))) { + return (self.include_processor_extensions = self.document.$extensions().$include_processors())['$!']()['$!']() + } else { + return (self.include_processor_extensions = false) + } + } else { + return self.include_processor_extensions['$!='](false) + } + }); + + $def(self, '$create_include_cursor', function $$create_include_cursor(file, path, lineno) { + var dir = nil; - // The actual inclusion of a module into a class. - // - // ## Class `$$parent` and `iclass` - // - // To handle `super` calls, every class has a `$$parent`. This parent is - // used to resolve the next class for a super call. A normal class would - // have this point to its superclass. However, if a class includes a module - // then this would need to take into account the module. The module would - // also have to then point its `$$parent` to the actual superclass. We - // cannot modify modules like this, because it might be included in more - // then one class. To fix this, we actually insert an `iclass` as the class' - // `$$parent` which can then point to the superclass. The `iclass` acts as - // a proxy to the actual module, so the `super` chain can then search it for - // the required method. - // - // @param module [Module] the module to include - // @param includer [Module] the target class to include module into - // @return [null] - Opal.append_features = function(module, includer) { - var module_ancestors = Opal.ancestors(module); - var iclasses = []; + + if ($eqeqeq($$$('String'), file)) { + dir = $$$('File').$dirname(file); + } else if ($truthy($$('RUBY_ENGINE_OPAL'))) { + dir = $$$('File').$dirname((file = file.$to_s())); + } else { + + dir = ($eqeq((dir = $$$('File').$dirname(file.$path())), "") ? ("/") : (dir)); + file = file.$to_s(); + } return $$('Cursor').$new(file, dir, path, lineno); + }); + + $def(self, '$to_s', function $$to_s() { + var self = this; - if (module_ancestors.indexOf(includer) !== -1) { - throw Opal.ArgumentError.$new('cyclic include detected'); - } + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {path: " + (self.path.$inspect()) + ", line: " + (self.lineno) + ", include depth: " + (self.include_stack.$size()) + ", include stack: [" + ($send(self.include_stack, 'map', [], function $$13(inc){ + + if (inc == null) inc = nil; + return inc.$to_s();}).$join(", ")) + "]}>" + }); + self.$private(); + + $def(self, '$prepare_lines', function $$prepare_lines(data, opts) { + var $yield = $$prepare_lines.$$p || nil, self = this, result = nil, front_matter = nil, $ret_or_1 = nil, last = nil; - for (var i = 0, length = module_ancestors.length; i < length; i++) { - var ancestor = module_ancestors[i], iclass = create_iclass(ancestor); - $defineProperty(iclass, '$$included', true); - iclasses.push(iclass); - } - var includer_ancestors = Opal.ancestors(includer), - chain = chain_iclasses(iclasses), - start_chain_after, - end_chain_on; + $$prepare_lines.$$p = null; + + if (opts == null) opts = $hash2([], {}); + result = $send2(self, $find_super(self, 'prepare_lines', $$prepare_lines, false, true), 'prepare_lines', [data, opts], $yield); + if ((($truthy(self.document) && ($truthy(self.document.$attributes()['$[]']("skip-front-matter")))) && ($truthy((front_matter = self['$skip_front_matter!'](result)))))) { + self.document.$attributes()['$[]=']("front-matter", front_matter.$join($$('LF'))); + } if ($truthy(opts.$fetch("condense", true))) { + while ($truthy(($truthy(($ret_or_1 = (last = result['$[]'](-1)))) ? (last['$empty?']()) : ($ret_or_1)))) { + result.$pop(); + } + } if ($truthy(opts['$[]']("indent"))) { + $$('Parser')['$adjust_indentation!'](result, opts['$[]']("indent").$to_i(), self.document.$attr("tabsize").$to_i()); + } return result; + }, -2); + + $def(self, '$process_line', function $$process_line(line) { + var $a, self = this; - if (includer_ancestors.indexOf(module) === -1) { - // first time include + + if (!$truthy(self.process_lines)) { + return line + } if ($truthy(line['$empty?']())) { + + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line; + } if ((($truthy(line['$end_with?']("]")) && ($not(line['$start_with?']("[")))) && ($truthy(line['$include?']("::"))))) { + if (($truthy(line['$include?']("if")) && ($truthy($$('ConditionalDirectiveRx')['$=~'](line))))) { + if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), "\\")) { + + self.unescape_next_line = true; + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line.$slice(1, line.$length()); + } else if ($truthy(self.$preprocess_conditional_directive((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](5))))) { + + self.$shift(); + return nil; + } else { + + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line; + } + } else if ($truthy(self.skipping)) { + + self.$shift(); + return nil; + } else if (($truthy(line['$start_with?']("inc", "\\inc")) && ($truthy($$('IncludeDirectiveRx')['$=~'](line))))) { + if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), "\\")) { + + self.unescape_next_line = true; + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line.$slice(1, line.$length()); + } else if ($truthy(self.$preprocess_include_directive((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](3))))) { + return nil + } else { + + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line; + } + } else { + + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line; + } + } else if ($truthy(self.skipping)) { + + self.$shift(); + return nil; + } else { + + self.look_ahead = $rb_plus(self.look_ahead, 1); + return line; + } }); + + $def(self, '$preprocess_conditional_directive', function $$preprocess_conditional_directive(keyword, target, delimiter, text) { + var $a, self = this, no_target = nil, pair = nil, skip = nil, lhs = nil, op = nil, rhs = nil; - // includer -> chain.first -> ...chain... -> chain.last -> includer.parent - start_chain_after = includer.$$prototype; - end_chain_on = Object.getPrototypeOf(includer.$$prototype); - } else { - // The module has been already included, - // we don't need to put it into the ancestors chain again, - // but this module may have new included modules. - // If it's true we need to copy them. - // - // The simplest way is to replace ancestors chain from - // parent - // | - // `module` iclass (has a $$root flag) - // | - // ...previos chain of module.included_modules ... - // | - // "next ancestor" (has a $$root flag or is a real class) - // - // to - // parent - // | - // `module` iclass (has a $$root flag) - // | - // ...regenerated chain of module.included_modules - // | - // "next ancestor" (has a $$root flag or is a real class) - // - // because there are no intermediate classes between `parent` and `next ancestor`. - // It doesn't break any prototypes of other objects as we don't change class references. + + if (!$truthy((no_target = target['$empty?']()))) { + target = target.$downcase(); + } if ($eqeq(keyword, "endif")) { + + if ($truthy(text)) { + self.$logger().$error(self.$message_with_context("malformed preprocessor directive - text not permitted: endif::" + (target) + "[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + } else if ($truthy(self.conditional_stack['$empty?']())) { + self.$logger().$error(self.$message_with_context("unmatched preprocessor directive: endif::" + (target) + "[]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + } else if (($truthy(no_target) || ($eqeq(target, (pair = self.conditional_stack['$[]'](-1))['$[]']("target"))))) { + + self.conditional_stack.$pop(); + self.skipping = ($truthy(self.conditional_stack['$empty?']()) ? (false) : (self.conditional_stack['$[]'](-1)['$[]']("skipping"))); + } else { + self.$logger().$error(self.$message_with_context("mismatched preprocessor directive: endif::" + (target) + "[], expected endif::" + (pair['$[]']("target")) + "[]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + } return true; + } else if ($truthy(self.skipping)) { + skip = false; + } else + switch (keyword) { + case "ifdef": + + if ($truthy(no_target)) { + + self.$logger().$error(self.$message_with_context("malformed preprocessor directive - missing target: ifdef::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return true; + } + switch (delimiter) { + case ",": + skip = $send(target.$split(",", -1), 'none?', [], function $$14(name){var self = $$14.$$s == null ? this : $$14.$$s; + if (self.document == null) self.document = nil; - var proto = includer.$$prototype, parent = proto, module_iclass = Object.getPrototypeOf(parent); + + if (name == null) name = nil; + return self.document.$attributes()['$key?'](name);}, {$$s: self}); + break; + case "+": + skip = $send(target.$split("+", -1), 'any?', [], function $$15(name){var self = $$15.$$s == null ? this : $$15.$$s; + if (self.document == null) self.document = nil; - while (module_iclass != null) { - if (isRoot(module_iclass) && module_iclass.$$module === module) { - break; - } + + if (name == null) name = nil; + return self.document.$attributes()['$key?'](name)['$!']();}, {$$s: self}); + break; + default: + skip = self.document.$attributes()['$key?'](target)['$!'](); + } break; + case "ifndef": + + if ($truthy(no_target)) { + + self.$logger().$error(self.$message_with_context("malformed preprocessor directive - missing target: ifndef::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return true; + } + switch (delimiter) { + case ",": + skip = $send(target.$split(",", -1), 'any?', [], function $$16(name){var self = $$16.$$s == null ? this : $$16.$$s; + if (self.document == null) self.document = nil; - parent = module_iclass; - module_iclass = Object.getPrototypeOf(module_iclass); - } + + if (name == null) name = nil; + return self.document.$attributes()['$key?'](name);}, {$$s: self}); + break; + case "+": + skip = $send(target.$split("+", -1), 'all?', [], function $$17(name){var self = $$17.$$s == null ? this : $$17.$$s; + if (self.document == null) self.document = nil; - var next_ancestor = Object.getPrototypeOf(module_iclass); + + if (name == null) name = nil; + return self.document.$attributes()['$key?'](name);}, {$$s: self}); + break; + default: + skip = self.document.$attributes()['$key?'](target); + } break; + case "ifeval": + if ($truthy(no_target)) { + if (($truthy(text) && ($truthy($$('EvalExpressionRx')['$=~'](text.$strip()))))) { + + lhs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)); + op = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)); + rhs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)); + skip = (function() { try { + if ($truthy(self.$resolve_expr_val(lhs).$send(op, self.$resolve_expr_val(rhs)))) { + return false + } else { + return true + } + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return true + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})(); + } else { + + self.$logger().$error(self.$message_with_context("malformed preprocessor directive - " + (($truthy(text) ? ("invalid expression") : ("missing expression"))) + ": ifeval::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return true; + } + } else { + + self.$logger().$error(self.$message_with_context("malformed preprocessor directive - target not permitted: ifeval::" + (target) + "[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return true; + } + break; + } if (($eqeq(keyword, "ifeval") || ($not(text)))) { + + if ($truthy(skip)) { + self.skipping = true; + } self.conditional_stack['$<<']($hash2(["target", "skip", "skipping"], {"target": target, "skip": skip, "skipping": self.skipping})); + } else if (!($truthy(self.skipping) || ($truthy(skip)))) { + + self.$replace_next_line(text.$rstrip()); + self.$unshift(""); + if ($truthy(text['$start_with?']("include::"))) { + self.look_ahead = $rb_minus(self.look_ahead, 1); + } } return true; + }); + + $def(self, '$preprocess_include_directive', function $$preprocess_include_directive(target, attrlist) { + var $a, $b, self = this, doc = nil, expanded_target = nil, attr_missing = nil, $ret_or_1 = nil, ext = nil, parsed_attrs = nil, inc_path = nil, target_type = nil, relpath = nil, reader = nil, read_mode = nil, enc = nil, read_mode_params = nil, inc_linenos = nil, inc_tags = nil, tag = nil, inc_lines = nil, inc_offset = nil, inc_lineno = nil, tag_stack = nil, tags_selected = nil, active_tag = nil, select = nil, base_select = nil, wildcard = nil, missing_tags = nil, inc_content = nil; - // skip non-root iclasses (that were recursively included) - while (next_ancestor.hasOwnProperty('$$iclass') && !isRoot(next_ancestor)) { - next_ancestor = Object.getPrototypeOf(next_ancestor); - } + + doc = self.document; + if (($truthy((expanded_target = target)['$include?']($$('ATTR_REF_HEAD'))) && ($truthy((expanded_target = doc.$sub_attributes(target, $hash2(["attribute_missing"], {"attribute_missing": ($eqeq((attr_missing = ($truthy(($ret_or_1 = doc.$attributes()['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing()))), "warn") ? ("drop-line") : (attr_missing))})))['$empty?']())))) { + if (($eqeq(attr_missing, "drop-line") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) { + + $send(self.$logger(), 'info', [], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s; - start_chain_after = parent; - end_chain_on = next_ancestor; - } + return self.$message_with_context("include dropped due to missing attribute: include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self}); + self.$shift(); + return true; + } else if ($truthy(doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true}))['$[]']("optional-option"))) { + + $send(self.$logger(), 'info', [], function $$19(){var self = $$19.$$s == null ? this : $$19.$$s; - $setPrototype(start_chain_after, chain.first); - $setPrototype(chain.last, end_chain_on); + return self.$message_with_context("optional include dropped " + ((($eqeq(attr_missing, "warn") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']()))) ? ("due to missing attribute") : ("because resolved target is blank"))) + ": include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self}); + self.$shift(); + return true; + } else { + + self.$logger().$warn(self.$message_with_context("include dropped " + ((($eqeq(attr_missing, "warn") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']()))) ? ("due to missing attribute") : ("because resolved target is blank"))) + ": include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (target) + "[" + (attrlist) + "]"); + } + } else if (($truthy(self['$include_processors?']()) && ($truthy((ext = $send(self.include_processor_extensions, 'find', [], function $$20(candidate){ + + if (candidate == null) candidate = nil; + return candidate.$instance()['$handles?'](expanded_target);})))))) { + + self.$shift(); + ext.$process_method()['$[]'](doc, self, expanded_target, doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true}))); + return true; + } else if ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SECURE')))) { + return self.$replace_next_line("link:" + (expanded_target) + "[role=include]") + } else if ($truthy(self.maxdepth)) { + + if ($truthy($rb_ge(self.include_stack.$size(), self.maxdepth['$[]']("curr")))) { + + self.$logger().$error(self.$message_with_context("maximum include depth of " + (self.maxdepth['$[]']("rel")) + " exceeded", $hash2(["source_location"], {"source_location": self.$cursor()}))); + return nil; + } parsed_attrs = doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true})); + $b = self.$resolve_include_path(expanded_target, attrlist, parsed_attrs), $a = $to_ary($b), (inc_path = ($a[0] == null ? nil : $a[0])), (target_type = ($a[1] == null ? nil : $a[1])), (relpath = ($a[2] == null ? nil : $a[2])); + + switch (target_type) { + case "file": + + reader = $$$('File').$method("open"); + read_mode = $$('FILE_READ_MODE'); + break; + case "uri": + + reader = $$$('OpenURI').$method("open_uri"); + read_mode = $$('URI_READ_MODE'); + break; + default: + return inc_path + } if (!$truthy($$('RUBY_ENGINE_OPAL'))) { + if (($truthy((enc = parsed_attrs['$[]']("encoding"))) && ($truthy((function() { try { + return $$$('Encoding').$find(enc) + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})())))) { + + (read_mode_params = read_mode.$split(":"))['$[]='](1, enc); + read_mode = read_mode_params.$join(":"); + } + } inc_linenos = (inc_tags = nil); + if ($truthy(attrlist)) { + if ($truthy(parsed_attrs['$key?']("lines"))) { + + inc_linenos = []; + $send(self.$split_delimited_value(parsed_attrs['$[]']("lines")), 'each', [], function $$21(linedef){var $c, $d, from = nil, to = nil; - // recalculate own_included_modules cache - includer.$$own_included_modules = own_included_modules(includer); + + if (linedef == null) linedef = nil; + if ($truthy(linedef['$include?'](".."))) { + + $d = linedef.$partition(".."), $c = $to_ary($d), (from = ($c[0] == null ? nil : $c[0])), (($c[1] == null ? nil : $c[1])), (to = ($c[2] == null ? nil : $c[2])); + return (inc_linenos = $rb_plus(inc_linenos, (($truthy(to['$empty?']()) || ($truthy($rb_lt((to = to.$to_i()), 0)))) ? ([from.$to_i(), $$$($$$('Float'), 'INFINITY')]) : (Opal.Range.$new(from.$to_i(), to, false).$to_a())))); + } else { + return inc_linenos['$<<'](linedef.$to_i()) + }}); + inc_linenos = ($truthy(inc_linenos['$empty?']()) ? (nil) : (inc_linenos.$sort().$uniq())); + } else if ($truthy(parsed_attrs['$key?']("tag"))) { + if (!($truthy((tag = parsed_attrs['$[]']("tag"))['$empty?']()) || ($eqeq(tag, "!")))) { + inc_tags = ($truthy(tag['$start_with?']("!")) ? ($hash(tag.$slice(1, tag.$length()), false)) : ($hash(tag, true))); + } + } else if ($truthy(parsed_attrs['$key?']("tags"))) { + + inc_tags = $hash2([], {}); + $send(self.$split_delimited_value(parsed_attrs['$[]']("tags")), 'each', [], function $$22(tagdef){var $c; - Opal.const_cache_version++; - } + + if (tagdef == null) tagdef = nil; + if (($truthy(tagdef['$empty?']()) || ($eqeq(tagdef, "!")))) { + return nil + } else if ($truthy(tagdef['$start_with?']("!"))) { + return ($c = [tagdef.$slice(1, tagdef.$length()), false], $send(inc_tags, '[]=', $c), $c[$c.length - 1]) + } else { + return ($c = [tagdef, true], $send(inc_tags, '[]=', $c), $c[$c.length - 1]) + }}); + if ($truthy(inc_tags['$empty?']())) { + inc_tags = nil; + } } + } if ($truthy(inc_linenos)) { + + $a = [[], nil, 0], (inc_lines = $a[0]), (inc_offset = $a[1]), (inc_lineno = $a[2]); + + try { + $send(reader, 'call', [inc_path, read_mode], function $$23(f){var select_remaining = nil; - Opal.prepend_features = function(module, prepender) { - // Here we change the ancestors chain from - // - // prepender - // | - // parent - // - // to: - // - // dummy(prepender) - // | - // iclass(module) - // | - // iclass(prepender) - // | - // parent - var module_ancestors = Opal.ancestors(module); - var iclasses = []; + + if (f == null) f = nil; + select_remaining = nil; + return (function(){try { var $t_break = $thrower('break'); return $send(f, 'each_line', [], function $$24(l){var select = nil; - if (module_ancestors.indexOf(prepender) !== -1) { - throw Opal.ArgumentError.$new('cyclic prepend detected'); - } + + if (l == null) l = nil; + inc_lineno = $rb_plus(inc_lineno, 1); + if (($truthy(select_remaining) || (($eqeqeq($$$('Float'), (select = inc_linenos['$[]'](0))) && ($truthy((select_remaining = select['$infinite?']()))))))) { + + inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno)); + return inc_lines['$<<'](l); + } else { + + if ($eqeq(select, inc_lineno)) { + + inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno)); + inc_lines['$<<'](l); + inc_linenos.$shift(); + }; + if ($truthy(inc_linenos['$empty?']())) { + $t_break.$throw(); + } else { + return nil + }; + };})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})();}); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))); + return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]"); + } finally { Opal.pop_exception(); } + } else { throw $err; } + } self.$shift(); + if ($truthy(inc_offset)) { + + parsed_attrs['$[]=']("partial-option", ""); + self.$push_include(inc_lines, inc_path, relpath, inc_offset, parsed_attrs); + } } else if ($truthy(inc_tags)) { + + $a = [[], nil, 0, [], $$$('Set').$new(), nil], (inc_lines = $a[0]), (inc_offset = $a[1]), (inc_lineno = $a[2]), (tag_stack = $a[3]), (tags_selected = $a[4]), (active_tag = $a[5]); + if ($truthy(inc_tags['$key?']("**"))) { + + select = (base_select = inc_tags.$delete("**")); + if ($truthy(inc_tags['$key?']("*"))) { + wildcard = inc_tags.$delete("*"); + } else if (($not(select) && ($eqeq(inc_tags.$values().$first(), false)))) { + wildcard = true; + } } else if ($truthy(inc_tags['$key?']("*"))) { + if ($eqeq(inc_tags.$keys().$first(), "*")) { + select = (base_select = (wildcard = inc_tags.$delete("*"))['$!']()); + } else { + + select = (base_select = false); + wildcard = inc_tags.$delete("*"); + } + } else { + select = (base_select = inc_tags['$value?'](true)['$!']()); + } + try { + $send(reader, 'call', [inc_path, read_mode], function $$25(f){var $c, self = $$25.$$s == null ? this : $$25.$$s, dbl_co = nil, dbl_sb = nil; - for (var i = 0, length = module_ancestors.length; i < length; i++) { - var ancestor = module_ancestors[i], iclass = create_iclass(ancestor); - $defineProperty(iclass, '$$prepended', true); - iclasses.push(iclass); - } + + if (f == null) f = nil; + $c = ["::", "[]"], (dbl_co = $c[0]), (dbl_sb = $c[1]), $c; + return $send(f, 'each_line', [], function $$26(l){var $d, $e, self = $$26.$$s == null ? this : $$26.$$s, this_tag = nil, include_cursor = nil, idx = nil; - var chain = chain_iclasses(iclasses), - dummy_prepender = prepender.$$prototype, - previous_parent = Object.getPrototypeOf(dummy_prepender), - prepender_iclass, - start_chain_after, - end_chain_on; + + if (l == null) l = nil; + inc_lineno = $rb_plus(inc_lineno, 1); + if ((($truthy(l['$include?'](dbl_co)) && ($truthy(l['$include?'](dbl_sb)))) && ($truthy($$('TagDirectiveRx')['$=~'](l))))) { + + this_tag = (($d = $gvars['~']) === nil ? nil : $d['$[]'](2)); + if ($truthy((($d = $gvars['~']) === nil ? nil : $d['$[]'](1)))) { + if ($eqeq(this_tag, active_tag)) { + + tag_stack.$pop(); + return $e = ($truthy(tag_stack['$empty?']()) ? ([nil, base_select]) : (tag_stack['$[]'](-1))), $d = $to_ary($e), (active_tag = ($d[0] == null ? nil : $d[0])), (select = ($d[1] == null ? nil : $d[1])), $e; + } else if ($truthy(inc_tags['$key?'](this_tag))) { + + include_cursor = self.$create_include_cursor(inc_path, expanded_target, inc_lineno); + if ($truthy((idx = $send(tag_stack, 'rindex', [], function $$27(key){ + + if (key == null) key = nil; + return key['$=='](this_tag);}, {$$has_trailing_comma_in_args: true})))) { + + if ($eqeq(idx, 0)) { + tag_stack.$shift(); + } else { + + tag_stack.$delete_at(idx); + }; + return self.$logger().$warn(self.$message_with_context("mismatched end tag (expected '" + (active_tag) + "' but found '" + (this_tag) + "') at line " + (inc_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": include_cursor}))); + } else { + return self.$logger().$warn(self.$message_with_context("unexpected end tag '" + (this_tag) + "' at line " + (inc_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": include_cursor}))) + }; + } else { + return nil + } + } else if ($truthy(inc_tags['$key?'](this_tag))) { + + if ($truthy((select = inc_tags['$[]'](this_tag)))) { + tags_selected['$<<'](this_tag); + }; + return tag_stack['$<<']([(active_tag = this_tag), select, inc_lineno]); + } else if ($not(wildcard['$nil?']())) { + + select = (($truthy(active_tag) && ($not(select))) ? (false) : (wildcard)); + return tag_stack['$<<']([(active_tag = this_tag), select, inc_lineno]); + } else { + return nil + }; + } else if ($truthy(select)) { + + inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno)); + return inc_lines['$<<'](l); + } else { + return nil + };}, {$$s: self});}, {$$s: self}); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))); + return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]"); + } finally { Opal.pop_exception(); } + } else { throw $err; } + } if (!$truthy(tag_stack['$empty?']())) { + $send(tag_stack, 'each', [], function $$28(tag_name, _, tag_lineno){var self = $$28.$$s == null ? this : $$28.$$s; - if (dummy_prepender.hasOwnProperty('$$dummy')) { - // The module already has some prepended modules - // which means that we don't need to make it "dummy" - prepender_iclass = dummy_prepender.$$define_methods_on; - } else { - // Making the module "dummy" - prepender_iclass = create_dummy_iclass(prepender); - flush_methods_in(prepender); - $defineProperty(dummy_prepender, '$$dummy', true); - $defineProperty(dummy_prepender, '$$define_methods_on', prepender_iclass); + + if (tag_name == null) tag_name = nil; + if (tag_lineno == null) tag_lineno = nil; + return self.$logger().$warn(self.$message_with_context("detected unclosed tag '" + (tag_name) + "' starting at line " + (tag_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": self.$create_include_cursor(inc_path, expanded_target, tag_lineno)})));}, {$$s: self}); + } if (!$truthy((missing_tags = $rb_minus($send(inc_tags, 'keep_if', [], function $$29(_, v){ + if (v == null) v = nil; + return v;}).$keys(), tags_selected.$to_a()))['$empty?']())) { + self.$logger().$warn(self.$message_with_context("tag" + (($truthy($rb_gt(missing_tags.$size(), 1)) ? ("s") : (""))) + " '" + (missing_tags.$join(", ")) + "' not found in include " + (target_type) + ": " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))); + } self.$shift(); + if ($truthy(inc_offset)) { + + if (!(($truthy(base_select) && ($neqeq(wildcard, false))) && ($truthy(inc_tags['$empty?']())))) { + parsed_attrs['$[]=']("partial-option", ""); + } self.$push_include(inc_lines, inc_path, relpath, inc_offset, parsed_attrs); + } } else { + + inc_content = nil; + + try { + + inc_content = $send(reader, 'call', [inc_path, read_mode], function $$30(f){ + + if (f == null) f = nil; + return f.$read();}); + self.$shift(); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))); + return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]"); + } finally { Opal.pop_exception(); } + } else { throw $err; } + } self.$push_include(inc_content, inc_path, relpath, 1, parsed_attrs); + } return true; + } else { + return nil + } }); + + $def(self, '$resolve_include_path', function $$resolve_include_path(target, attrlist, attributes) { + var $b, self = this, doc = nil, inc_path = nil, relpath = nil; - // Converting - // dummy(prepender) -> previous_parent - // to - // dummy(prepender) -> iclass(prepender) -> previous_parent - $setPrototype(dummy_prepender, prepender_iclass); - $setPrototype(prepender_iclass, previous_parent); - } + + doc = self.document; + if (($truthy($$('Helpers')['$uriish?'](target)) || ($truthy(($eqeqeq($$$('String'), self.dir) ? (nil) : ((target = "" + (self.dir) + "/" + (target)))))))) { + + if (!$truthy(doc['$attr?']("allow-uri-read"))) { + return self.$replace_next_line("link:" + (target) + "[role=include]") + } if ($truthy(doc['$attr?']("cache-uri"))) { + if (!$truthy((($b = $$$('::', 'OpenURI', 'skip_raise')) && ($$$($b, 'Cache', 'skip_raise')) ? 'constant' : nil))) { + $$('Helpers').$require_library("open-uri/cached", "open-uri-cached"); + } + } else if ($not($$('RUBY_ENGINE_OPAL'))) { + $$$('OpenURI'); + } return [$$$('URI').$parse(target), "uri", target]; + } else { + + inc_path = doc.$normalize_system_path(target, self.dir, nil, $hash2(["target_name"], {"target_name": "include file"})); + if (!$truthy($$$('File')['$file?'](inc_path))) { + if ($truthy(attributes['$[]']("optional-option"))) { + + $send(self.$logger(), 'info', [], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s; - var prepender_ancestors = Opal.ancestors(prepender); + return self.$message_with_context("optional include dropped because include file not found: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self}); + self.$shift(); + return true; + } else { + + self.$logger().$error(self.$message_with_context("include file not found: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))); + return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (target) + "[" + (attrlist) + "]"); + } + } relpath = doc.$path_resolver().$relative_path(inc_path, doc.$base_dir()); + return [inc_path, "file", relpath]; + } }); + + $def(self, '$pop_include', function $$pop_include() { + var $a, $b, self = this; - if (prepender_ancestors.indexOf(module) === -1) { - // first time prepend + if ($truthy(self.include_stack['$empty?']())) { + return nil + } else { + + $b = self.include_stack.$pop(), $a = $to_ary($b), (self.lines = ($a[0] == null ? nil : $a[0])), (self.file = ($a[1] == null ? nil : $a[1])), (self.dir = ($a[2] == null ? nil : $a[2])), (self.path = ($a[3] == null ? nil : $a[3])), (self.lineno = ($a[4] == null ? nil : $a[4])), (self.maxdepth = ($a[5] == null ? nil : $a[5])), (self.process_lines = ($a[6] == null ? nil : $a[6])); + self.look_ahead = 0; + return nil; + } + }); + + $def(self, '$split_delimited_value', function $$split_delimited_value(val) { + + if ($truthy(val['$include?'](","))) { + + return val.$split(","); + } else { + + return val.$split(";"); + } + }); + + $def(self, '$skip_front_matter!', function $PreprocessorReader_skip_front_matter$excl$32(data, increment_linenos) { + var self = this, delim = nil, original_data = nil, front_matter = nil, $ret_or_1 = nil, eof = nil; - start_chain_after = dummy_prepender; + + if (increment_linenos == null) increment_linenos = true; + if (!$eqeq((delim = data['$[]'](0)), "---")) { + return nil + } original_data = data.$drop(0); + data.$shift(); + front_matter = []; + if ($truthy(increment_linenos)) { + self.lineno = $rb_plus(self.lineno, 1); + } while (!($truthy(($truthy(($ret_or_1 = (eof = data['$empty?']()))) ? ($ret_or_1) : (data['$[]'](0)['$=='](delim)))))) { + + front_matter['$<<'](data.$shift()); + if ($truthy(increment_linenos)) { + self.lineno = $rb_plus(self.lineno, 1); + } } if ($truthy(eof)) { + + $send(data, 'unshift', $to_a(original_data)); + if ($truthy(increment_linenos)) { + self.lineno = $rb_minus(self.lineno, original_data.$size()); + } return nil; + } data.$shift(); + if ($truthy(increment_linenos)) { + self.lineno = $rb_plus(self.lineno, 1); + } return front_matter; + }, -2); + return $def(self, '$resolve_expr_val', function $$resolve_expr_val(val) { + var self = this, quoted = nil; - // next $$root or prepender_iclass or non-$$iclass - end_chain_on = Object.getPrototypeOf(dummy_prepender); - while (end_chain_on != null) { - if ( - end_chain_on.hasOwnProperty('$$root') || - end_chain_on === prepender_iclass || - !end_chain_on.hasOwnProperty('$$iclass') - ) { - break; - } + + if ((($truthy(val['$start_with?']("\"")) && ($truthy(val['$end_with?']("\"")))) || (($truthy(val['$start_with?']("'")) && ($truthy(val['$end_with?']("'"))))))) { + + quoted = true; + val = val.$slice(1, $rb_minus(val.$length(), 1)); + } else { + quoted = false; + } if ($truthy(val['$include?']($$('ATTR_REF_HEAD')))) { + val = self.document.$sub_attributes(val, $hash2(["attribute_missing"], {"attribute_missing": "drop"})); + } if ($truthy(quoted)) { + return val + } else if ($truthy(val['$empty?']())) { + return nil + } else if ($eqeq(val, "true")) { + return true + } else if ($eqeq(val, "false")) { + return false + } else if ($truthy(val.$rstrip()['$empty?']())) { + return " " + } else if ($truthy(val['$include?']("."))) { + return val.$to_f() + } else { + return val.$to_i() + } }); + })($nesting[0], $$('Reader'), $nesting); + })($nesting[0], $nesting) +}; - end_chain_on = Object.getPrototypeOf(end_chain_on); - } - } else { - throw Opal.RuntimeError.$new("Prepending a module multiple times is not supported"); - } +Opal.modules["asciidoctor/section"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $def = Opal.def, $alias = Opal.alias, $rb_gt = Opal.rb_gt, $eqeq = Opal.eqeq, $not = Opal.not, $send = Opal.send, $defs = Opal.defs, $nesting = [], nil = Opal.nil; - $setPrototype(start_chain_after, chain.first); - $setPrototype(chain.last, end_chain_on); + Opal.add_stubs('attr_accessor,attr_reader,===,+,level,special,title,generate_id,>,==,sectnum,!,empty?,reftext,sub_placeholder,sub_quotes,compat_mode,[],attributes,context,assign_numeral,class,object_id,inspect,size,[]=,chr,length,gsub,downcase,delete,tr_s,end_with?,chop,start_with?,slice,key?,catalog,unique_id_start_index'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - // recalculate own_prepended_modules cache - prepender.$$own_prepended_modules = own_prepended_modules(prepender); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.const_cache_version++; - } + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Section'); - function flush_methods_in(module) { - var proto = module.$$prototype, - props = Object.getOwnPropertyNames(proto); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - for (var i = 0; i < props.length; i++) { - var prop = props[i]; - if (Opal.is_method(prop)) { - delete proto[prop]; - } - } - } + $proto.document = $proto.next_section_index = $proto.parent = $proto.level = $proto.numeral = $proto.numbered = $proto.sectname = $proto.title = $proto.blocks = nil; + + self.$attr_accessor("index"); + self.$attr_accessor("sectname"); + self.$attr_accessor("special"); + self.$attr_accessor("numbered"); + self.$attr_reader("caption"); + + $def(self, '$initialize', function $$initialize(parent, level, numbered, opts) { + var $a; $$initialize.$$p || nil; var self = this, $ret_or_1 = nil; - function create_iclass(module) { - var iclass = create_dummy_iclass(module); + $$initialize.$$p = null; + + if (parent == null) parent = nil; + if (level == null) level = nil; + if (numbered == null) numbered = false; + if (opts == null) opts = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "section", opts], null); + if ($eqeqeq($$('Section'), parent)) { + $a = [($truthy(($ret_or_1 = level)) ? ($ret_or_1) : ($rb_plus(parent.$level(), 1))), parent.$special()], (self.level = $a[0]), (self.special = $a[1]); + } else { + $a = [($truthy(($ret_or_1 = level)) ? ($ret_or_1) : (1)), false], (self.level = $a[0]), (self.special = $a[1]); + } self.numbered = numbered; + return (self.index = 0); + }, -1); + $alias(self, "name", "title"); + + $def(self, '$generate_id', function $$generate_id() { + var self = this; - if (module.$$is_module) { - module.$$iclasses.push(iclass); - } + return $$('Section').$generate_id(self.$title(), self.document) + }); + + $def(self, '$sections?', function $Section_sections$ques$1() { + var self = this; - return iclass; - } + return $rb_gt(self.next_section_index, 0) + }); + + $def(self, '$sectnum', function $$sectnum(delimiter, append) { + var self = this, $ret_or_1 = nil; - // Dummy iclass doesn't receive updates when the module gets a new method. - function create_dummy_iclass(module) { - var iclass = {}, - proto = module.$$prototype; + + if (delimiter == null) delimiter = "."; + if (append == null) append = nil; + append = ($truthy(($ret_or_1 = append)) ? ($ret_or_1) : (($eqeq(append, false) ? ("") : (delimiter)))); + if (($truthy($rb_gt(self.level, 1)) && ($eqeqeq($$('Section'), self.parent)))) { + return "" + (self.parent.$sectnum(delimiter, delimiter)) + (self.numeral) + (append) + } else { + return "" + (self.numeral) + (append) + } }, -1); + + $def(self, '$xreftext', function $$xreftext(xrefstyle) { + var self = this, val = nil, type = nil, quoted_title = nil, signifier = nil; - if (proto.hasOwnProperty('$$dummy')) { - proto = proto.$$define_methods_on; - } + + if (xrefstyle == null) xrefstyle = nil; + if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) { + return val + } else if ($truthy(xrefstyle)) { + if ($truthy(self.numbered)) { + + switch (xrefstyle) { + case "full": + + if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) { + quoted_title = self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title()); + } else { + quoted_title = self.$sub_placeholder(self.$sub_quotes(($truthy(self.document.$compat_mode()) ? ("``%s''") : ("\"`%s`\""))), self.$title()); + } if ($truthy((signifier = self.document.$attributes()['$[]']("" + (type) + "-refsig")))) { + return "" + (signifier) + " " + (self.$sectnum(".", ",")) + " " + (quoted_title) + } else { + return "" + (self.$sectnum(".", ",")) + " " + (quoted_title) + } case "short": + if ($truthy((signifier = self.document.$attributes()['$[]']("" + (self.sectname) + "-refsig")))) { + return "" + (signifier) + " " + (self.$sectnum(".", "")) + } else { + return self.$sectnum(".", "") + } + default: + if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) { + + return self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title()); + } else { + return self.$title() + } + } + } else if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) { + + return self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title()); + } else { + return self.$title() + } + } else { + return self.$title() + } }, -1); + + $def(self, '$<<', function $Section_$lt$lt$2(block) { + var $yield = $Section_$lt$lt$2.$$p || nil, self = this; - var props = Object.getOwnPropertyNames(proto), - length = props.length, i; + $Section_$lt$lt$2.$$p = null; + + if ($eqeq(block.$context(), "section")) { + self.$assign_numeral(block); + } return $send2(self, $find_super(self, '<<', $Section_$lt$lt$2, false, true), '<<', [block], $yield); + }); + + $def(self, '$to_s', function $$to_s() { + var $yield = $$to_s.$$p || nil, self = this, formal_title = nil; - for (i = 0; i < length; i++) { - var prop = props[i]; - $defineProperty(iclass, prop, proto[prop]); - } + $$to_s.$$p = null; + if ($truthy(self.title)) { + + formal_title = ($truthy(self.numbered) ? ("" + (self.$sectnum()) + " " + (self.title)) : (self.title)); + return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {level: " + (self.level) + ", title: " + (formal_title.$inspect()) + ", blocks: " + (self.blocks.$size()) + "}>"; + } else { + return $send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], $yield) + } + }); + return $defs(self, '$generate_id', function $$generate_id(title, document) { + var $a, attrs = nil, pre = nil, $ret_or_1 = nil, sep = nil, no_sep = nil, sep_sub = nil, gen_id = nil, ids = nil, cnt = nil, candidate_id = nil; - $defineProperty(iclass, '$$iclass', true); - $defineProperty(iclass, '$$module', module); + + attrs = document.$attributes(); + pre = ($truthy(($ret_or_1 = attrs['$[]']("idprefix"))) ? ($ret_or_1) : ("_")); + if ($truthy((sep = attrs['$[]']("idseparator")))) { + if (($eqeq(sep.$length(), 1) || (($not((no_sep = sep['$empty?']())) && ($truthy((sep = ($a = ["idseparator", sep.$chr()], $send(attrs, '[]=', $a), $a[$a.length - 1])))))))) { + sep_sub = (($eqeq(sep, "-") || ($eqeq(sep, "."))) ? (" .-") : (" " + (sep) + ".-")); + } + } else { + $a = ["_", " _.-"], (sep = $a[0]), (sep_sub = $a[1]); + } gen_id = "" + (pre) + (title.$downcase().$gsub($$('InvalidSectionIdCharsRx'), "")); + if ($truthy(no_sep)) { + gen_id = gen_id.$delete(" "); + } else { + + gen_id = gen_id.$tr_s(sep_sub, sep); + if ($truthy(gen_id['$end_with?'](sep))) { + gen_id = gen_id.$chop(); + } if (($truthy(pre['$empty?']()) && ($truthy(gen_id['$start_with?'](sep))))) { + gen_id = gen_id.$slice(1, gen_id.$length()); + } } if ($truthy(document.$catalog()['$[]']("refs")['$key?'](gen_id))) { + + ids = document.$catalog()['$[]']("refs"); + cnt = $$('Compliance').$unique_id_start_index(); + while ($truthy(ids['$[]']((candidate_id = "" + (gen_id) + (sep) + (cnt))))) { + cnt = $rb_plus(cnt, 1); + } return candidate_id; + } else { + return gen_id + } }); + })($nesting[0], $$('AbstractBlock'), $nesting) + })($nesting[0], $nesting) +}; - return iclass; - } +Opal.modules["asciidoctor/stylesheets"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $return_ivar = Opal.return_ivar, $defs = Opal.defs, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - function chain_iclasses(iclasses) { - var length = iclasses.length, first = iclasses[0]; + Opal.add_stubs('join,new,rstrip,read,primary_stylesheet_data,write,primary_stylesheet_name,stylesheet_basename,for,read_stylesheet,coderay_stylesheet_data,coderay_stylesheet_name,pygments_stylesheet_data,pygments_stylesheet_name'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - $defineProperty(first, '$$root', true); + var $nesting = [self].concat($parent_nesting); - if (length === 1) { - return { first: first, last: first }; - } + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Stylesheets'); - var previous = first; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - for (var i = 1; i < length; i++) { - var current = iclasses[i]; - $setPrototype(previous, current); - previous = current; - } + $proto.primary_stylesheet_data = nil; + + $const_set($nesting[0], 'DEFAULT_STYLESHEET_NAME', "asciidoctor.css"); + $const_set($nesting[0], 'STYLESHEETS_DIR', $$$('File').$join($$('DATA_DIR'), "stylesheets")); + self.__instance__ = self.$new(); + $defs(self, '$instance', $return_ivar("__instance__")); + + $def(self, '$primary_stylesheet_name', function $$primary_stylesheet_name() { + + return $$('DEFAULT_STYLESHEET_NAME') + }); + + $def(self, '$primary_stylesheet_data', function $$primary_stylesheet_data() { + var self = this, $ret_or_1 = nil; + return (self.primary_stylesheet_data = ($truthy(($ret_or_1 = self.primary_stylesheet_data)) ? ($ret_or_1) : ($$$('File').$read($$$('File').$join($$('STYLESHEETS_DIR'), "asciidoctor-default.css"), $hash2(["mode"], {"mode": $$('FILE_READ_MODE')})).$rstrip()))) + }); + + $def(self, '$embed_primary_stylesheet', function $$embed_primary_stylesheet() { + var self = this; - return { first: iclasses[0], last: iclasses[length - 1] }; - } + return "<style>\n" + (self.$primary_stylesheet_data()) + "\n" + "</style>" + }); + + $def(self, '$write_primary_stylesheet', function $$write_primary_stylesheet(target_dir) { + var self = this; - // For performance, some core Ruby classes are toll-free bridged to their - // native JavaScript counterparts (e.g. a Ruby Array is a JavaScript Array). - // - // This method is used to setup a native constructor (e.g. Array), to have - // its prototype act like a normal Ruby class. Firstly, a new Ruby class is - // created using the native constructor so that its prototype is set as the - // target for the new class. Note: all bridged classes are set to inherit - // from Object. - // - // Example: - // - // Opal.bridge(self, Function); - // - // @param klass [Class] the Ruby class to bridge - // @param constructor [JS.Function] native JavaScript constructor to use - // @return [Class] returns the passed Ruby class - // - Opal.bridge = function(native_klass, klass) { - if (native_klass.hasOwnProperty('$$bridge')) { - throw Opal.ArgumentError.$new("already bridged"); - } + + if (target_dir == null) target_dir = "."; + return $$$('File').$write($$$('File').$join(target_dir, self.$primary_stylesheet_name()), self.$primary_stylesheet_data(), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + }, -1); + + $def(self, '$coderay_stylesheet_name', function $$coderay_stylesheet_name() { + + return $$('SyntaxHighlighter').$for("coderay").$stylesheet_basename() + }); + + $def(self, '$coderay_stylesheet_data', function $$coderay_stylesheet_data() { + + return $$('SyntaxHighlighter').$for("coderay").$read_stylesheet() + }); + + $def(self, '$embed_coderay_stylesheet', function $$embed_coderay_stylesheet() { + var self = this; - var klass_to_inject, klass_reference; + return "<style>\n" + (self.$coderay_stylesheet_data()) + "\n" + "</style>" + }); + + $def(self, '$write_coderay_stylesheet', function $$write_coderay_stylesheet(target_dir) { + var self = this; - klass_to_inject = klass.$$super || Opal.Object; - klass_reference = klass; - var original_prototype = klass.$$prototype; + + if (target_dir == null) target_dir = "."; + return $$$('File').$write($$$('File').$join(target_dir, self.$coderay_stylesheet_name()), self.$coderay_stylesheet_data(), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + }, -1); + + $def(self, '$pygments_stylesheet_name', function $$pygments_stylesheet_name(style) { + + + if (style == null) style = nil; + return $$('SyntaxHighlighter').$for("pygments").$stylesheet_basename(style); + }, -1); + + $def(self, '$pygments_stylesheet_data', function $$pygments_stylesheet_data(style) { + + + if (style == null) style = nil; + return $$('SyntaxHighlighter').$for("pygments").$read_stylesheet(style); + }, -1); + + $def(self, '$embed_pygments_stylesheet', function $$embed_pygments_stylesheet(style) { + var self = this; - // constructor is a JS function with a prototype chain like: - // - constructor - // - super - // - // What we need to do is to inject our class (with its prototype chain) - // between constructor and super. For example, after injecting ::Object - // into JS String we get: - // - // - constructor (window.String) - // - Opal.Object - // - Opal.Kernel - // - Opal.BasicObject - // - super (window.Object) - // - null - // - $defineProperty(native_klass, '$$bridge', klass); - $setPrototype(native_klass.prototype, (klass.$$super || Opal.Object).$$prototype); - $defineProperty(klass, '$$prototype', native_klass.prototype); + + if (style == null) style = nil; + return "<style>\n" + (self.$pygments_stylesheet_data(style)) + "\n" + "</style>"; + }, -1); + return $def(self, '$write_pygments_stylesheet', function $$write_pygments_stylesheet(target_dir, style) { + var self = this; - $defineProperty(klass.$$prototype, '$$class', klass); - $defineProperty(klass, '$$constructor', native_klass); - $defineProperty(klass, '$$bridge', true); - }; + + if (target_dir == null) target_dir = "."; + if (style == null) style = nil; + return $$$('File').$write($$$('File').$join(target_dir, self.$pygments_stylesheet_name(style)), self.$pygments_stylesheet_data(style), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + }, -1); + })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; - function protoToModule(proto) { - if (proto.hasOwnProperty('$$dummy')) { - return; - } else if (proto.hasOwnProperty('$$iclass')) { - return proto.$$module; - } else if (proto.hasOwnProperty('$$class')) { - return proto.$$class; - } - } +Opal.modules["asciidoctor/table"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $def = Opal.def, $alias = Opal.alias, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $rb_divide = Opal.rb_divide, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $return_val = Opal.return_val, $to_a = Opal.to_a, $gvars = Opal.gvars, $neqeq = Opal.neqeq, $return_ivar = Opal.return_ivar, $to_ary = Opal.to_ary, $regexp = Opal.regexp, $not = Opal.not, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - function own_ancestors(module) { - return module.$$own_prepended_modules.concat([module]).concat(module.$$own_included_modules); - } + Opal.add_stubs('attr_accessor,send,attr_reader,new,[],<,>,to_i,==,[]=,attributes,truncate,*,/,to_f,empty?,body,each,<<,size,+,assign_column_widths,warn,logger,-,update_attributes,assign_width,round,head=,map,shift,reinitialize,nil?,unshift,foot=,pop,parent,sourcemap,dup,header_row?,table,style,merge,delete,start_with?,rstrip,slice,length,advance,lstrip,strip,split,include?,readlines,catalog_inline_anchor,=~,apply_subs,attr_writer,convert,text,!=,file,lineno,include,to_set,mark,key?,nested?,document,error,message_with_context,cursor_at_prev_line,nil_or_empty?,escape,columns,match,chop,end_with?,gsub,!,push_cellspec,cell_open?,close_cell,take_cellspec,squeeze,upto,times,cursor_before_mark,rowspan,activate_rowspan,colspan,end_of_row?,close_row,private,rows,effective_column_visits'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - // The Array of ancestors for a given module/class - Opal.ancestors = function(module) { - if (!module) { return []; } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (module.$$ancestors_cache_version === Opal.const_cache_version) { - return module.$$ancestors; - } + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Table'); - var result = [], i, mods, length; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - for (i = 0, mods = own_ancestors(module), length = mods.length; i < length; i++) { - result.push(mods[i]); - } + $proto.attributes = $proto.document = $proto.rows = $proto.has_header_option = $proto.columns = nil; + + $const_set($nesting[0], 'DEFAULT_PRECISION', 4); + (function($base, $super) { + var self = $klass($base, $super, 'Rows'); - if (module.$$super) { - for (i = 0, mods = Opal.ancestors(module.$$super), length = mods.length; i < length; i++) { - result.push(mods[i]); - } - } + var $proto = self.$$prototype; - module.$$ancestors_cache_version = Opal.const_cache_version; - module.$$ancestors = result; + $proto.head = $proto.body = $proto.foot = nil; + + self.$attr_accessor("head", "foot", "body"); + + $def(self, '$initialize', function $$initialize(head, foot, body) { + var self = this; - return result; - } + + if (head == null) head = []; + if (foot == null) foot = []; + if (body == null) body = []; + self.head = head; + self.foot = foot; + return (self.body = body); + }, -1); + $alias(self, "[]", "send"); + + $def(self, '$by_section', function $$by_section() { + var self = this; - Opal.included_modules = function(module) { - var result = [], mod = null, proto = Object.getPrototypeOf(module.$$prototype); + return [["head", self.head], ["body", self.body], ["foot", self.foot]] + }); + return $def(self, '$to_h', function $$to_h() { + var self = this; - for (; proto && Object.getPrototypeOf(proto); proto = Object.getPrototypeOf(proto)) { - mod = protoToModule(proto); - if (mod && mod.$$is_module && proto.$$iclass && proto.$$included) { - result.push(mod); - } - } + return $hash2(["head", "body", "foot"], {"head": self.head, "body": self.body, "foot": self.foot}) + }); + })($nesting[0], null); + self.$attr_accessor("columns"); + self.$attr_accessor("rows"); + self.$attr_accessor("has_header_option"); + self.$attr_reader("caption"); + + $def(self, '$initialize', function $$initialize(parent, attributes) { + var $a; $$initialize.$$p || nil; var self = this, pcwidth = nil, pcwidth_intval = nil, abswidth_val = nil; - return result; - } + $$initialize.$$p = null; + + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "table"], null); + self.rows = $$('Rows').$new(); + self.columns = []; + self.has_header_option = false; + if ($truthy((pcwidth = attributes['$[]']("width")))) { + if (($truthy($rb_gt((pcwidth_intval = pcwidth.$to_i()), 100)) || ($truthy($rb_lt(pcwidth_intval, 1))))) { + if (!($eqeq(pcwidth_intval, 0) && (($eqeq(pcwidth, "0") || ($eqeq(pcwidth, "0%")))))) { + pcwidth_intval = 100; + } + } + } else { + pcwidth_intval = 100; + } self.attributes['$[]=']("tablepcwidth", pcwidth_intval); + if ($truthy(self.document.$attributes()['$[]']("pagewidth"))) { + self.attributes['$[]=']("tableabswidth", ($eqeq((abswidth_val = $rb_times($rb_divide(pcwidth_intval, 100), self.document.$attributes()['$[]']("pagewidth").$to_f()).$truncate($$('DEFAULT_PRECISION'))), abswidth_val.$to_i()) ? (abswidth_val.$to_i()) : (abswidth_val))); + } if ($truthy(attributes['$[]']("rotate-option"))) { + return ($a = ["orientation", "landscape"], $send(self.attributes, '[]=', $a), $a[$a.length - 1]) + } else { + return nil + } }); + + $def(self, '$header_row?', function $Table_header_row$ques$1() { + var self = this, val = nil; + if (($truthy((val = self.has_header_option)) && ($truthy(self.rows.$body()['$empty?']())))) { + return val + } else { + return nil + } + }); + + $def(self, '$create_columns', function $$create_columns(colspecs) { + var self = this, cols = nil, autowidth_cols = nil, width_base = nil, num_cols = nil; - // Method Missing - // -------------- + + cols = []; + autowidth_cols = nil; + width_base = 0; + $send(colspecs, 'each', [], function $$2(colspec){var self = $$2.$$s == null ? this : $$2.$$s, colwidth = nil, $ret_or_1 = nil; - // Methods stubs are used to facilitate method_missing in opal. A stub is a - // placeholder function which just calls `method_missing` on the receiver. - // If no method with the given name is actually defined on an object, then it - // is obvious to say that the stub will be called instead, and then in turn - // method_missing will be called. - // - // When a file in ruby gets compiled to javascript, it includes a call to - // this function which adds stubs for every method name in the compiled file. - // It should then be safe to assume that method_missing will work for any - // method call detected. - // - // Method stubs are added to the BasicObject prototype, which every other - // ruby object inherits, so all objects should handle method missing. A stub - // is only added if the given property name (method name) is not already - // defined. - // - // Note: all ruby methods have a `$` prefix in javascript, so all stubs will - // have this prefix as well (to make this method more performant). - // - // Opal.add_stubs(["$foo", "$bar", "$baz="]); - // - // All stub functions will have a private `$$stub` property set to true so - // that other internal methods can detect if a method is just a stub or not. - // `Kernel#respond_to?` uses this property to detect a methods presence. - // - // @param stubs [Array] an array of method stubs to add - // @return [undefined] - Opal.add_stubs = function(stubs) { - var proto = Opal.BasicObject.$$prototype; + + if (colspec == null) colspec = nil; + colwidth = colspec['$[]']("width"); + cols['$<<']($$('Column').$new(self, cols.$size(), colspec)); + if ($truthy($rb_lt(colwidth, 0))) { + return (autowidth_cols = ($truthy(($ret_or_1 = autowidth_cols)) ? ($ret_or_1) : ([])))['$<<'](cols['$[]'](-1)) + } else { + return (width_base = $rb_plus(width_base, colwidth)) + }}, {$$s: self}); + if ($truthy($rb_gt((num_cols = (self.columns = cols).$size()), 0))) { + + self.attributes['$[]=']("colcount", num_cols); + if (!($truthy($rb_gt(width_base, 0)) || ($truthy(autowidth_cols)))) { + width_base = nil; + } self.$assign_column_widths(width_base, autowidth_cols); + } return nil; + }); + + $def(self, '$assign_column_widths', function $$assign_column_widths(width_base, autowidth_cols) { + var self = this, precision = nil, total_width = nil, col_pcwidth = nil, autowidth = nil, autowidth_attrs = nil; - for (var i = 0, length = stubs.length; i < length; i++) { - var stub = stubs[i], existing_method = proto[stub]; + + if (width_base == null) width_base = nil; + if (autowidth_cols == null) autowidth_cols = nil; + precision = $$('DEFAULT_PRECISION'); + total_width = (col_pcwidth = 0); + if ($truthy(width_base)) { + + if ($truthy(autowidth_cols)) { + + if ($truthy($rb_gt(width_base, 100))) { + + autowidth = 0; + self.$logger().$warn("total column width must not exceed 100% when using autowidth columns; got " + (width_base) + "%"); + } else { + + autowidth = $rb_divide($rb_minus(100, width_base), autowidth_cols.$size()).$truncate(precision); + if ($eqeq(autowidth.$to_i(), autowidth)) { + autowidth = autowidth.$to_i(); + } width_base = 100; + } autowidth_attrs = $hash2(["width", "autowidth-option"], {"width": autowidth, "autowidth-option": ""}); + $send(autowidth_cols, 'each', [], function $$3(col){ + + if (col == null) col = nil; + return col.$update_attributes(autowidth_attrs);}); + } $send(self.columns, 'each', [], function $$4(col){ + + if (col == null) col = nil; + return (total_width = $rb_plus(total_width, (col_pcwidth = col.$assign_width(nil, width_base, precision))));}); + } else { + + col_pcwidth = $rb_divide(100, self.columns.$size()).$truncate(precision); + if ($eqeq(col_pcwidth.$to_i(), col_pcwidth)) { + col_pcwidth = col_pcwidth.$to_i(); + } $send(self.columns, 'each', [], function $$5(col){ + + if (col == null) col = nil; + return (total_width = $rb_plus(total_width, col.$assign_width(col_pcwidth, nil, precision)));}); + } if (!$eqeq(total_width, 100)) { + self.columns['$[]'](-1).$assign_width($rb_plus($rb_minus(100, total_width), col_pcwidth).$round(precision), nil, precision); + } return nil; + }, -1); + return $def(self, '$partition_header_footer', function $$partition_header_footer(attrs) { + var $a, self = this, num_body_rows = nil, body = nil; - if (existing_method == null || existing_method.$$stub) { - Opal.add_stub_for(proto, stub); - } - } - }; + + num_body_rows = ($a = ["rowcount", (body = self.rows.$body()).$size()], $send(self.attributes, '[]=', $a), $a[$a.length - 1]); + if ($truthy($rb_gt(num_body_rows, 0))) { + if ($truthy(self.has_header_option)) { + + self.rows['$head=']([$send(body.$shift(), 'map', [], function $$6(cell){ + + if (cell == null) cell = nil; + return cell.$reinitialize(true);})]); + num_body_rows = $rb_minus(num_body_rows, 1); + } else if ($truthy(self.has_header_option['$nil?']())) { + + self.has_header_option = false; + body.$unshift($send(body.$shift(), 'map', [], function $$7(cell){ + + if (cell == null) cell = nil; + return cell.$reinitialize(false);})); + } + } if (($truthy($rb_gt(num_body_rows, 0)) && ($truthy(attrs['$[]']("footer-option"))))) { + self.rows['$foot=']([body.$pop()]); + } return nil; + }); + })($nesting[0], $$('AbstractBlock'), $nesting); + (function($base, $super) { + var self = $klass($base, $super, 'Column'); - // Add a method_missing stub function to the given prototype for the - // given name. - // - // @param prototype [Prototype] the target prototype - // @param stub [String] stub name to add (e.g. "$foo") - // @return [undefined] - Opal.add_stub_for = function(prototype, stub) { - var method_missing_stub = Opal.stub_for(stub); - $defineProperty(prototype, stub, method_missing_stub); - }; + var $proto = self.$$prototype; - // Generate the method_missing stub for a given method name. - // - // @param method_name [String] The js-name of the method to stub (e.g. "$foo") - // @return [undefined] - Opal.stub_for = function(method_name) { - function method_missing_stub() { - // Copy any given block onto the method_missing dispatcher - this.$method_missing.$$p = method_missing_stub.$$p; + $proto.attributes = nil; + + self.$attr_accessor("style"); + + $def(self, '$initialize', function $$initialize(table, index, attributes) { + $$initialize.$$p || nil; var self = this; - // Set block property to null ready for the next call (stop false-positives) - method_missing_stub.$$p = null; + $$initialize.$$p = null; + + if (attributes == null) attributes = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [table, "table_column"], null); + self.style = attributes['$[]']("style"); + attributes['$[]=']("colnumber", $rb_plus(index, 1)); + if ($truthy((attributes['$[]']("width")))) ; else { + attributes['$[]=']("width", 1); + } if ($truthy((attributes['$[]']("halign")))) ; else { + attributes['$[]=']("halign", "left"); + } if ($truthy((attributes['$[]']("valign")))) ; else { + attributes['$[]=']("valign", "top"); + } return self.$update_attributes(attributes); + }, -3); + $alias(self, "table", "parent"); + + $def(self, '$assign_width', function $$assign_width(col_pcwidth, width_base, precision) { + var $a, self = this, col_abswidth = nil; - // call method missing with correct args (remove '$' prefix on method name) - var args_ary = new Array(arguments.length); - for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i]; } + + if ($truthy(width_base)) { + + col_pcwidth = $rb_divide($rb_times(self.attributes['$[]']("width").$to_f(), 100), width_base).$truncate(precision); + if ($eqeq(col_pcwidth.$to_i(), col_pcwidth)) { + col_pcwidth = col_pcwidth.$to_i(); + } } if ($truthy(self.$parent().$attributes()['$[]']("tableabswidth"))) { + self.attributes['$[]=']("colabswidth", ($eqeq((col_abswidth = $rb_times($rb_divide(col_pcwidth, 100), self.$parent().$attributes()['$[]']("tableabswidth")).$truncate(precision)), col_abswidth.$to_i()) ? (col_abswidth.$to_i()) : (col_abswidth))); + } return ($a = ["colpcwidth", col_pcwidth], $send(self.attributes, '[]=', $a), $a[$a.length - 1]); + }); + + $def(self, '$block?', $return_val(false)); + return $def(self, '$inline?', $return_val(false)); + })($$('Table'), $$('AbstractNode')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Cell'); - return this.$method_missing.apply(this, [method_name.slice(1)].concat(args_ary)); - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - method_missing_stub.$$stub = true; + $proto.document = $proto.reinitialize_args = $proto.attributes = $proto.cursor = $proto.text = $proto.subs = $proto.style = $proto.inner_document = $proto.source_location = $proto.colspan = $proto.rowspan = nil; + + $const_set($nesting[0], 'DOUBLE_LF', $rb_times($$('LF'), 2)); + self.$attr_accessor("colspan"); + self.$attr_accessor("rowspan"); + $alias(self, "column", "parent"); + self.$attr_reader("inner_document"); + + $def(self, '$initialize', function $$initialize(column, cell_text, attributes, opts) { + var $a; $$initialize.$$p || nil; var self = this, in_header_row = nil, cell_style = nil, $ret_or_1 = nil, $ret_or_2 = nil, asciidoc = nil, inner_document_cursor = nil, lines_advanced = nil, literal = nil, normal_psv = nil, parent_doctitle = nil, inner_document_lines = nil, unprocessed_line1 = nil, preprocessed_lines = nil; - return method_missing_stub; - }; + $$initialize.$$p = null; + + if (attributes == null) attributes = $hash2([], {}); + if (opts == null) opts = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [column, "table_cell"], null); + self.cursor = (self.reinitialize_args = nil); + if ($truthy(self.document.$sourcemap())) { + self.source_location = opts['$[]']("cursor").$dup(); + } if ($truthy(column)) { + + if ($truthy((in_header_row = column.$table()['$header_row?']()))) { + if (($eqeq(in_header_row, "implicit") && ($truthy((cell_style = ($truthy(($ret_or_1 = column.$style())) ? ($ret_or_1) : (($truthy(($ret_or_2 = attributes)) ? (attributes['$[]']("style")) : ($ret_or_2))))))))) { + + if (($eqeq(cell_style, "asciidoc") || ($eqeq(cell_style, "literal")))) { + self.reinitialize_args = [column, cell_text, ($truthy(($ret_or_1 = attributes)) ? (attributes.$merge()) : ($ret_or_1)), opts]; + } cell_style = nil; + } + } else { + cell_style = column.$style(); + } self.$update_attributes(column.$attributes()); + } if ($truthy(attributes)) { + + if ($truthy(attributes['$empty?']())) { + self.colspan = (self.rowspan = nil); + } else { + + $a = [attributes.$delete("colspan"), attributes.$delete("rowspan")], (self.colspan = $a[0]), (self.rowspan = $a[1]); + if (!$truthy(in_header_row)) { + cell_style = ($truthy(($ret_or_1 = attributes['$[]']("style"))) ? ($ret_or_1) : (cell_style)); + } self.$update_attributes(attributes); + } + switch (cell_style) { + case "asciidoc": + + asciidoc = true; + inner_document_cursor = opts['$[]']("cursor"); + if ($truthy((cell_text = cell_text.$rstrip())['$start_with?']($$('LF')))) { + + lines_advanced = 1; + while ($truthy((cell_text = cell_text.$slice(1, cell_text.$length()))['$start_with?']($$('LF')))) { + lines_advanced = $rb_plus(lines_advanced, 1); + } inner_document_cursor.$advance(lines_advanced); + } else { + cell_text = cell_text.$lstrip(); + } break; + case "literal": + + literal = true; + cell_text = cell_text.$rstrip(); + while ($truthy(cell_text['$start_with?']($$('LF')))) { + cell_text = cell_text.$slice(1, cell_text.$length()); + } break; + default: + + normal_psv = true; + cell_text = ($truthy(cell_text) ? (cell_text.$strip()) : ("")); + } } else { + + self.colspan = (self.rowspan = nil); + if ($eqeq(cell_style, "asciidoc")) { + + asciidoc = true; + inner_document_cursor = opts['$[]']("cursor"); + } } if ($truthy(asciidoc)) { + + parent_doctitle = self.document.$attributes().$delete("doctitle"); + inner_document_lines = cell_text.$split($$('LF'), -1); + if (!$truthy(inner_document_lines['$empty?']())) { + if ($truthy((unprocessed_line1 = inner_document_lines['$[]'](0))['$include?']("::"))) { + + preprocessed_lines = $$('PreprocessorReader').$new(self.document, [unprocessed_line1]).$readlines(); + if (!($eqeq(unprocessed_line1, preprocessed_lines['$[]'](0)) && ($truthy($rb_lt(preprocessed_lines.$size(), 2))))) { + + inner_document_lines.$shift(); + if (!$truthy(preprocessed_lines['$empty?']())) { + $send(inner_document_lines, 'unshift', $to_a(preprocessed_lines)); + } } } + } self.inner_document = $$('Document').$new(inner_document_lines, $hash2(["standalone", "parent", "cursor"], {"standalone": false, "parent": self.document, "cursor": inner_document_cursor})); + if (!$truthy(parent_doctitle['$nil?']())) { + self.document.$attributes()['$[]=']("doctitle", parent_doctitle); + } self.subs = nil; + } else if ($truthy(literal)) { + + self.content_model = "verbatim"; + self.subs = $$('BASIC_SUBS'); + } else { + + if ($truthy(normal_psv)) { + if ($truthy(in_header_row)) { + self.cursor = opts['$[]']("cursor"); + } else { + self.$catalog_inline_anchor(cell_text, opts['$[]']("cursor")); + } + } self.content_model = "simple"; + self.subs = $$('NORMAL_SUBS'); + } self.text = cell_text; + return (self.style = cell_style); + }, -3); + + $def(self, '$reinitialize', function $$reinitialize(has_header) { + var self = this; + + + if ($truthy(has_header)) { + self.reinitialize_args = nil; + } else if ($truthy(self.reinitialize_args)) { + return $send($$$($$('Table'), 'Cell'), 'new', $to_a(self.reinitialize_args)) + } else { + self.style = self.attributes['$[]']("style"); + } if ($truthy(self.cursor)) { + self.$catalog_inline_anchor(); + } return self; + }); + + $def(self, '$catalog_inline_anchor', function $$catalog_inline_anchor(cell_text, cursor) { + var $a, self = this; + + if (cell_text == null) cell_text = self.text; + if (cursor == null) cursor = nil; + if (!$truthy(cursor)) { + $a = [self.cursor, nil], (cursor = $a[0]), (self.cursor = $a[1]); + } if (($truthy(cell_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](cell_text))))) { + return $$('Parser').$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), self, cursor, self.document) + } else { + return nil + } }, -1); + + $def(self, '$text', function $$text() { + var self = this; - // Methods - // ------- + return self.$apply_subs(self.text, self.subs) + }); + self.$attr_writer("text"); + + $def(self, '$content', function $$content() { + var self = this, cell_style = nil, subbed_text = nil; - // Arity count error dispatcher for methods - // - // @param actual [Fixnum] number of arguments given to method - // @param expected [Fixnum] expected number of arguments - // @param object [Object] owner of the method +meth+ - // @param meth [String] method name that got wrong number of arguments - // @raise [ArgumentError] - Opal.ac = function(actual, expected, object, meth) { - var inspect = ''; - if (object.$$is_a_module) { - inspect += object.$$name + '.'; - } - else { - inspect += object.$$class.$$name + '#'; - } - inspect += meth; + if ($eqeq((cell_style = self.style), "asciidoc")) { + return self.inner_document.$convert() + } else if ($truthy(self.text['$include?']($$('DOUBLE_LF')))) { + return $send(self.$text().$split($$('BlankLineRx')), 'map', [], function $$8(para){var self = $$8.$$s == null ? this : $$8.$$s; - throw Opal.ArgumentError.$new('[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')'); - }; + + if (para == null) para = nil; + if (($truthy(cell_style) && ($neqeq(cell_style, "header")))) { + return $$('Inline').$new(self.$parent(), "quoted", para, $hash2(["type"], {"type": cell_style})).$convert() + } else { + return para + }}, {$$s: self}) + } else if ($truthy((subbed_text = self.$text())['$empty?']())) { + return [] + } else if (($truthy(cell_style) && ($neqeq(cell_style, "header")))) { + return [$$('Inline').$new(self.$parent(), "quoted", subbed_text, $hash2(["type"], {"type": cell_style})).$convert()] + } else { + return [subbed_text] + } + }); + + $def(self, '$lines', function $$lines() { + var self = this; - // Arity count error dispatcher for blocks - // - // @param actual [Fixnum] number of arguments given to block - // @param expected [Fixnum] expected number of arguments - // @param context [Object] context of the block definition - // @raise [ArgumentError] - Opal.block_ac = function(actual, expected, context) { - var inspect = "`block in " + context + "'"; + return self.text.$split($$('LF')) + }); + + $def(self, '$source', $return_ivar("text")); + + $def(self, '$file', function $$file() { + var self = this, $ret_or_1 = nil; - throw Opal.ArgumentError.$new(inspect + ': wrong number of arguments (' + actual + ' for ' + expected + ')'); - }; + if ($truthy(($ret_or_1 = self.source_location))) { + return self.source_location.$file() + } else { + return $ret_or_1 + } + }); + + $def(self, '$lineno', function $$lineno() { + var self = this, $ret_or_1 = nil; - // Super dispatcher - Opal.find_super_dispatcher = function(obj, mid, current_func, defcheck, defs) { - var jsid = '$' + mid, ancestors, super_method; + if ($truthy(($ret_or_1 = self.source_location))) { + return self.source_location.$lineno() + } else { + return $ret_or_1 + } + }); + return $def(self, '$to_s', function $$to_s() { + var $yield = $$to_s.$$p || nil, self = this, $ret_or_1 = nil; - if (obj.hasOwnProperty('$$meta')) { - ancestors = Opal.ancestors(obj.$$meta); - } else { - ancestors = Opal.ancestors(obj.$$class); - } + $$to_s.$$p = null; + return "" + ($send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], $yield)) + " - [text: " + (self.text) + ", colspan: " + (($truthy(($ret_or_1 = self.colspan)) ? ($ret_or_1) : (1))) + ", rowspan: " + (($truthy(($ret_or_1 = self.rowspan)) ? ($ret_or_1) : (1))) + ", attributes: " + (self.attributes) + "]" + }); + })($$('Table'), $$('AbstractBlock'), $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'ParserContext'); - var current_index = ancestors.indexOf(current_func.$$owner); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - for (var i = current_index + 1; i < ancestors.length; i++) { - var ancestor = ancestors[i], - proto = ancestor.$$prototype; + $proto.delimiter = $proto.delimiter_rx = $proto.buffer = $proto.cellspecs = $proto.cell_open = $proto.format = $proto.start_cursor_data = $proto.reader = $proto.table = $proto.current_row = $proto.colcount = $proto.column_visits = $proto.active_rowspans = $proto.linenum = nil; + + self.$include($$('Logging')); + $const_set($nesting[0], 'FORMATS', ["psv", "csv", "dsv", "tsv"].$to_set()); + $const_set($nesting[0], 'DELIMITERS', $hash2(["psv", "csv", "dsv", "tsv", "!sv"], {"psv": ["|", /\|/], "csv": [",", /,/], "dsv": [":", /:/], "tsv": ["\t", /\t/], "!sv": ["!", /!/]})); + self.$attr_accessor("table"); + self.$attr_accessor("format"); + self.$attr_reader("colcount"); + self.$attr_accessor("buffer"); + self.$attr_reader("delimiter"); + self.$attr_reader("delimiter_re"); + + $def(self, '$initialize', function $$initialize(reader, table, attributes) { + var $a, $b, self = this, xsv = nil, sep = nil; - if (proto.hasOwnProperty('$$dummy')) { - proto = proto.$$define_methods_on; - } + + if (attributes == null) attributes = $hash2([], {}); + self.start_cursor_data = (self.reader = reader).$mark(); + self.table = table; + if ($truthy(attributes['$key?']("format"))) { + if ($truthy($$('FORMATS')['$include?']((xsv = attributes['$[]']("format"))))) { + if ($eqeq(xsv, "tsv")) { + self.format = "csv"; + } else if (($eqeq((self.format = xsv), "psv") && ($truthy(table.$document()['$nested?']())))) { + xsv = "!sv"; + } + } else { + + self.$logger().$error(self.$message_with_context("illegal table format: " + (xsv), $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()}))); + $a = ["psv", ($truthy(table.$document()['$nested?']()) ? ("!sv") : ("psv"))], (self.format = $a[0]), (xsv = $a[1]); + } + } else { + $a = ["psv", ($truthy(table.$document()['$nested?']()) ? ("!sv") : ("psv"))], (self.format = $a[0]), (xsv = $a[1]); + } if ($truthy(attributes['$key?']("separator"))) { + if ($truthy((sep = attributes['$[]']("separator"))['$nil_or_empty?']())) { + $b = $$('DELIMITERS')['$[]'](xsv), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])); + } else if ($eqeq(sep, "\\t")) { + $b = $$('DELIMITERS')['$[]']("tsv"), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])); + } else { + $a = [sep, $regexp([$$$('Regexp').$escape(sep)])], (self.delimiter = $a[0]), (self.delimiter_rx = $a[1]); + } + } else { + $b = $$('DELIMITERS')['$[]'](xsv), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])); + } self.colcount = ($truthy(table.$columns()['$empty?']()) ? (-1) : (table.$columns().$size())); + self.buffer = ""; + self.cellspecs = []; + self.cell_open = false; + self.active_rowspans = [0]; + self.column_visits = 0; + self.current_row = []; + return (self.linenum = -1); + }, -3); + + $def(self, '$starts_with_delimiter?', function $ParserContext_starts_with_delimiter$ques$9(line) { + var self = this; - if (proto.hasOwnProperty(jsid)) { - var method = proto[jsid]; + return line['$start_with?'](self.delimiter) + }); + + $def(self, '$match_delimiter', function $$match_delimiter(line) { + var self = this; - if (!method.$$stub) { - super_method = method; - } - break; - } - } + return self.delimiter_rx.$match(line) + }); + + $def(self, '$skip_past_delimiter', function $$skip_past_delimiter(pre) { + var self = this; - if (!defcheck && super_method == null && Opal.Kernel.$method_missing === obj.$method_missing) { - // method_missing hasn't been explicitly defined - throw Opal.NoMethodError.$new('super: no superclass method `'+mid+"' for "+obj, mid); - } + + self.buffer = "" + (self.buffer) + (pre) + (self.delimiter); + return nil; + }); + + $def(self, '$skip_past_escaped_delimiter', function $$skip_past_escaped_delimiter(pre) { + var self = this; - return super_method; - }; + + self.buffer = "" + (self.buffer) + (pre.$chop()) + (self.delimiter); + return nil; + }); + + $def(self, '$buffer_has_unclosed_quotes?', function $ParserContext_buffer_has_unclosed_quotes$ques$10(append, q) { + var self = this, record = nil, qq = nil, trailing_quote = nil, $ret_or_1 = nil; - // Iter dispatcher for super in a block - Opal.find_iter_super_dispatcher = function(obj, jsid, current_func, defcheck, implicit) { - var call_jsid = jsid; + + if (append == null) append = nil; + if (q == null) q = "\""; + if ($eqeq((record = ($truthy(append) ? ($rb_plus(self.buffer, append).$strip()) : (self.buffer.$strip()))), q)) { + return true + } else if ($truthy(record['$start_with?'](q))) { + + qq = $rb_plus(q, q); + if ((($truthy((trailing_quote = record['$end_with?'](q))) && ($truthy(record['$end_with?'](qq)))) || ($truthy(record['$start_with?'](qq))))) { + if ($truthy(($ret_or_1 = (record = record.$gsub(qq, ""))['$start_with?'](q)))) { + return record['$end_with?'](q)['$!']() + } else { + return $ret_or_1 + } + } else { + return trailing_quote['$!']() + } } else { + return false + } }, -1); + + $def(self, '$take_cellspec', function $$take_cellspec() { + var self = this; - if (!current_func) { - throw Opal.RuntimeError.$new("super called outside of method"); - } + return self.cellspecs.$shift() + }); + + $def(self, '$push_cellspec', function $$push_cellspec(cellspec) { + var self = this, $ret_or_1 = nil; - if (implicit && current_func.$$define_meth) { - throw Opal.RuntimeError.$new("implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly"); - } + + if (cellspec == null) cellspec = $hash2([], {}); + self.cellspecs['$<<'](($truthy(($ret_or_1 = cellspec)) ? ($ret_or_1) : ($hash2([], {})))); + return nil; + }, -1); + + $def(self, '$keep_cell_open', function $$keep_cell_open() { + var self = this; - if (current_func.$$def) { - call_jsid = current_func.$$jsid; - } + + self.cell_open = true; + return nil; + }); + + $def(self, '$mark_cell_closed', function $$mark_cell_closed() { + var self = this; - return Opal.find_super_dispatcher(obj, call_jsid, current_func, defcheck); - }; + + self.cell_open = false; + return nil; + }); + + $def(self, '$cell_open?', $return_ivar("cell_open")); + + $def(self, '$cell_closed?', function $ParserContext_cell_closed$ques$11() { + var self = this; - // Used to return as an expression. Sometimes, we can't simply return from - // a javascript function as if we were a method, as the return is used as - // an expression, or even inside a block which must "return" to the outer - // method. This helper simply throws an error which is then caught by the - // method. This approach is expensive, so it is only used when absolutely - // needed. - // - Opal.ret = function(val) { - Opal.returner.$v = val; - throw Opal.returner; - }; + return self.cell_open['$!']() + }); + + $def(self, '$close_open_cell', function $$close_open_cell(next_cellspec) { + var self = this; - // Used to break out of a block. - Opal.brk = function(val, breaker) { - breaker.$v = val; - throw breaker; - }; + + if (next_cellspec == null) next_cellspec = $hash2([], {}); + self.$push_cellspec(next_cellspec); + if ($truthy(self['$cell_open?']())) { + self.$close_cell(true); + } self.$advance(); + return nil; + }, -1); + + $def(self, '$close_cell', function $$close_cell(eol) {try { var $t_return = $thrower('return'); + var self = this, cell_text = nil, cellspec = nil, repeat = nil, $ret_or_1 = nil, q = nil; - // Builds a new unique breaker, this is to avoid multiple nested breaks to get - // in the way of each other. - Opal.new_brk = function() { - return new Error('unexpected break'); - }; + + if (eol == null) eol = false; + if ($eqeq(self.format, "psv")) { + + cell_text = self.buffer; + self.buffer = ""; + if ($truthy((cellspec = self.$take_cellspec()))) { + repeat = ($truthy(($ret_or_1 = cellspec.$delete("repeatcol"))) ? ($ret_or_1) : (1)); + } else { + + self.$logger().$error(self.$message_with_context("table missing leading separator; recovering automatically", $hash2(["source_location"], {"source_location": $send($$$($$('Reader'), 'Cursor'), 'new', $to_a(self.start_cursor_data))}))); + cellspec = $hash2([], {}); + repeat = 1; + }; + } else { + + cell_text = self.buffer.$strip(); + self.buffer = ""; + cellspec = nil; + repeat = 1; + if ((($eqeq(self.format, "csv") && ($not(cell_text['$empty?']()))) && ($truthy(cell_text['$include?']((q = "\"")))))) { + if (($truthy(cell_text['$start_with?'](q)) && ($truthy(cell_text['$end_with?'](q))))) { + if ($truthy((cell_text = cell_text.$slice(1, $rb_minus(cell_text.$length(), 2))))) { + cell_text = cell_text.$strip().$squeeze(q); + } else { + + self.$logger().$error(self.$message_with_context("unclosed quote in CSV data; setting cell to empty", $hash2(["source_location"], {"source_location": self.reader.$cursor_at_prev_line()}))); + cell_text = ""; + } + } else { + cell_text = cell_text.$squeeze(q); + } + }; + }; + $send((1), 'upto', [repeat], function $$12(i){var self = $$12.$$s == null ? this : $$12.$$s, column = nil, extra_cols = nil, offset = nil, cell = nil; + if (self.colcount == null) self.colcount = nil; + if (self.table == null) self.table = nil; + if (self.current_row == null) self.current_row = nil; + if (self.reader == null) self.reader = nil; + if (self.column_visits == null) self.column_visits = nil; + if (self.linenum == null) self.linenum = nil; - // handles yield calls for 1 yielded arg - Opal.yield1 = function(block, arg) { - if (typeof(block) !== "function") { - throw Opal.LocalJumpError.$new("no block given"); - } + + if (i == null) i = nil; + if ($eqeq(self.colcount, -1)) { + + self.table.$columns()['$<<']((column = $$$($$('Table'), 'Column').$new(self.table, $rb_minus($rb_plus(self.table.$columns().$size(), i), 1)))); + if ((($truthy(cellspec) && ($truthy(cellspec['$key?']("colspan")))) && ($truthy($rb_gt((extra_cols = $rb_minus(cellspec['$[]']("colspan").$to_i(), 1)), 0))))) { + + offset = self.table.$columns().$size(); + $send(extra_cols, 'times', [], function $$13(j){var self = $$13.$$s == null ? this : $$13.$$s; + if (self.table == null) self.table = nil; - var has_mlhs = block.$$has_top_level_mlhs_arg, - has_trailing_comma = block.$$has_trailing_comma_in_args; + + if (j == null) j = nil; + return self.table.$columns()['$<<']($$$($$('Table'), 'Column').$new(self.table, $rb_plus(offset, j)));}, {$$s: self}); + }; + } else if (!$truthy((column = self.table.$columns()['$[]'](self.current_row.$size())))) { + + self.$logger().$error(self.$message_with_context("dropping cell because it exceeds specified number of columns", $hash2(["source_location"], {"source_location": self.reader.$cursor_before_mark()}))); + $t_return.$throw(); + }; + cell = $$$($$('Table'), 'Cell').$new(column, cell_text, cellspec, $hash2(["cursor"], {"cursor": self.reader.$cursor_before_mark()})); + self.reader.$mark(); + if (!($not(cell.$rowspan()) || ($eqeq(cell.$rowspan(), 1)))) { + self.$activate_rowspan(cell.$rowspan(), ($truthy(($ret_or_1 = cell.$colspan())) ? ($ret_or_1) : (1))); + }; + self.column_visits = $rb_plus(self.column_visits, ($truthy(($ret_or_1 = cell.$colspan())) ? ($ret_or_1) : (1))); + self.current_row['$<<'](cell); + if (($truthy(self['$end_of_row?']()) && ((($neqeq(self.colcount, -1) || ($truthy($rb_gt(self.linenum, 0)))) || (($truthy(eol) && ($eqeq(i, repeat)))))))) { + return self.$close_row() + } else { + return nil + };}, {$$s: self, $$ret: $t_return}); + self.cell_open = false; + return nil;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + self.$private(); + + $def(self, '$close_row', function $$close_row() { + var self = this; - if (block.length > 1 || ((has_mlhs || has_trailing_comma) && block.length === 1)) { - arg = Opal.to_ary(arg); - } + + self.table.$rows().$body()['$<<'](self.current_row); + if ($eqeq(self.colcount, -1)) { + self.colcount = self.column_visits; + } self.column_visits = 0; + self.current_row = []; + self.active_rowspans.$shift(); + if ($truthy((self.active_rowspans['$[]'](0)))) ; else { + self.active_rowspans['$[]='](0, 0); + } return nil; + }); + + $def(self, '$activate_rowspan', function $$activate_rowspan(rowspan, colspan) { + var self = this; - if ((block.length > 1 || (has_trailing_comma && block.length === 1)) && arg.$$is_array) { - return block.apply(null, arg); - } - else { - return block(arg); - } - }; + + $send((1), 'upto', [$rb_minus(rowspan, 1)], function $$14(i){var $a, self = $$14.$$s == null ? this : $$14.$$s, $ret_or_1 = nil; + if (self.active_rowspans == null) self.active_rowspans = nil; - // handles yield for > 1 yielded arg - Opal.yieldX = function(block, args) { - if (typeof(block) !== "function") { - throw Opal.LocalJumpError.$new("no block given"); - } + + if (i == null) i = nil; + return ($a = [i, $rb_plus(($truthy(($ret_or_1 = self.active_rowspans['$[]'](i))) ? ($ret_or_1) : (0)), colspan)], $send(self.active_rowspans, '[]=', $a), $a[$a.length - 1]);}, {$$s: self}); + return nil; + }); + + $def(self, '$end_of_row?', function $ParserContext_end_of_row$ques$15() { + var self = this, $ret_or_1 = nil; - if (block.length > 1 && args.length === 1) { - if (args[0].$$is_array) { - return block.apply(null, args[0]); - } - } + if ($truthy(($ret_or_1 = self.colcount['$=='](-1)))) { + return $ret_or_1 + } else { + return self.$effective_column_visits()['$=='](self.colcount) + } + }); + + $def(self, '$effective_column_visits', function $$effective_column_visits() { + var self = this; - if (!args.$$is_array) { - var args_ary = new Array(args.length); - for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; } + return $rb_plus(self.column_visits, self.active_rowspans['$[]'](0)) + }); + return $def(self, '$advance', function $$advance() { + var self = this; - return block.apply(null, args_ary); - } + return (self.linenum = $rb_plus(self.linenum, 1)) + }); + })($$('Table'), null, $nesting); + })($nesting[0], $nesting) +}; - return block.apply(null, args); - }; +Opal.modules["asciidoctor/writer"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // Finds the corresponding exception match in candidates. Each candidate can - // be a value, or an array of values. Returns null if not found. - Opal.rescue = function(exception, candidates) { - for (var i = 0; i < candidates.length; i++) { - var candidate = candidates[i]; + Opal.add_stubs('respond_to?,write,+,chomp,include'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - if (candidate.$$is_array) { - var result = Opal.rescue(exception, candidate); + var $nesting = [self].concat($parent_nesting); - if (result) { - return result; - } - } - else if (candidate === Opal.JS.Error) { - return candidate; - } - else if (candidate['$==='](exception)) { - return candidate; - } - } + + (function($base, $parent_nesting) { + var self = $module($base, 'Writer'); - return null; - }; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.is_a = function(object, klass) { - if (klass != null && object.$$meta === klass || object.$$class === klass) { - return true; - } + return $def(self, '$write', function $$write(output, target) { + + + if ($truthy(target['$respond_to?']("write"))) { + target.$write($rb_plus(output.$chomp(), $$('LF'))); + } else { + $$$('File').$write(target, output, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + } return nil; + }) + })($nesting[0], $nesting); + return (function($base, $parent_nesting) { + var self = $module($base, 'VoidWriter'); - if (object.$$is_number && klass.$$is_number_class) { - return true; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - var i, length, ancestors = Opal.ancestors(object.$$is_class ? Opal.get_singleton_class(object) : (object.$$meta || object.$$class)); + + self.$include($$('Writer')); + return $def(self, '$write', $return_val(nil)); + })($nesting[0], $nesting); + })($nesting[0], $nesting) +}; - for (i = 0, length = ancestors.length; i < length; i++) { - if (ancestors[i] === klass) { - return true; - } - } +Opal.modules["asciidoctor/load"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $hash2 = Opal.hash2, $truthy = Opal.truthy, $neqeq = Opal.neqeq, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $send = Opal.send, $to_ary = Opal.to_ary, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - return false; - }; + Opal.add_stubs('merge,[],start,!=,logger,key?,logger=,new,!,===,dup,tap,each,partition,[]=,split,gsub,+,respond_to?,keys,raise,join,ancestors,class,==,at,to_i,mtime,absolute_path,path,dirname,basename,extname,read,rewind,drop,record,parse,exception,message,set_backtrace,backtrace,stack_trace=,stack_trace,open,load'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - // Helpers for extracting kwsplats - // Used for: { **h } - Opal.to_hash = function(value) { - if (value.$$is_hash) { - return value; - } - else if (value['$respond_to?']('to_hash', true)) { - var hash = value.$to_hash(); - if (hash.$$is_hash) { - return hash; - } - else { - throw Opal.TypeError.$new("Can't convert " + value.$$class + - " to Hash (" + value.$$class + "#to_hash gives " + hash.$$class + ")"); - } - } - else { - throw Opal.TypeError.$new("no implicit conversion of " + value.$$class + " into Hash"); - } - }; + var $nesting = [self].concat($parent_nesting); - // Helpers for implementing multiple assignment - // Our code for extracting the values and assigning them only works if the - // return value is a JS array. - // So if we get an Array subclass, extract the wrapped JS array from it + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Used for: a, b = something (no splat) - Opal.to_ary = function(value) { - if (value.$$is_array) { - return value; - } - else if (value['$respond_to?']('to_ary', true)) { - var ary = value.$to_ary(); - if (ary === nil) { - return [value]; - } - else if (ary.$$is_array) { - return ary; - } - else { - throw Opal.TypeError.$new("Can't convert " + value.$$class + - " to Array (" + value.$$class + "#to_ary gives " + ary.$$class + ")"); - } - } - else { - return [value]; - } - }; + + + $def(self, '$load', function $$load(input, options) { + var $a, $b, $c, $d, self = this, timings = nil, logger = nil, $ret_or_1 = nil, attrs = nil, input_path = nil, source = nil, doc = nil, e = nil, context = nil, wrapped_e = nil; - // Used for: a, b = *something (with splat) - Opal.to_a = function(value) { - if (value.$$is_array) { - // A splatted array must be copied - return value.slice(); - } - else if (value['$respond_to?']('to_a', true)) { - var ary = value.$to_a(); - if (ary === nil) { - return [value]; - } - else if (ary.$$is_array) { - return ary; - } - else { - throw Opal.TypeError.$new("Can't convert " + value.$$class + - " to Array (" + value.$$class + "#to_a gives " + ary.$$class + ")"); - } - } - else { - return [value]; - } - }; + + if (options == null) options = $hash2([], {}); + try { + + options = options.$merge(); + if ($truthy((timings = options['$[]']("timings")))) { + timings.$start("read"); + }; + if (($truthy(options['$key?']("logger")) && ($neqeq((logger = options['$[]']("logger")), $$('LoggerManager').$logger())))) { + $$('LoggerManager')['$logger='](($truthy(($ret_or_1 = logger)) ? ($ret_or_1) : ($$('NullLogger').$new()))); + }; + if ($not((attrs = options['$[]']("attributes")))) { + attrs = $hash2([], {}); + } else if ($eqeqeq($$$('Hash'), attrs)) { + attrs = attrs.$merge(); + } else if (($truthy((($c = $$$('::', 'Java', 'skip_raise')) && ($b = $$$($c, 'JavaUtil', 'skip_raise')) && ($a = $$$($b, 'Map', 'skip_raise')) ? 'constant' : nil)) && ($eqeqeq($$$($$$($$$('Java'), 'JavaUtil'), 'Map'), attrs)))) { + attrs = attrs.$dup(); + } else if ($eqeqeq($$$('Array'), attrs)) { + attrs = $send($hash2([], {}), 'tap', [], function $$1(accum){ + + if (accum == null) accum = nil; + return $send(attrs, 'each', [], function $$2(entry){var $d, $e, k = nil, _ = nil, v = nil; - // Used for extracting keyword arguments from arguments passed to - // JS function. If provided +arguments+ list doesn't have a Hash - // as a last item, returns a blank Hash. - // - // @param parameters [Array] - // @return [Hash] - // - Opal.extract_kwargs = function(parameters) { - var kwargs = parameters[parameters.length - 1]; - if (kwargs != null && kwargs['$respond_to?']('to_hash', true)) { - $splice.call(parameters, parameters.length - 1, 1); - return kwargs.$to_hash(); - } - else { - return Opal.hash2([], {}); - } - } + + if (entry == null) entry = nil; + $e = entry.$partition("="), $d = $to_ary($e), (k = ($d[0] == null ? nil : $d[0])), (_ = ($d[1] == null ? nil : $d[1])), (v = ($d[2] == null ? nil : $d[2])), $e; + return ($d = [k, v], $send(accum, '[]=', $d), $d[$d.length - 1]);});}); + } else if ($eqeqeq($$$('String'), attrs)) { + attrs = $send($hash2([], {}), 'tap', [], function $$3(accum){ + + if (accum == null) accum = nil; + return $send(attrs.$gsub($$('SpaceDelimiterRx'), $rb_plus("\\1", $$('NULL'))).$gsub($$('EscapedSpaceRx'), "\\1").$split($$('NULL')), 'each', [], function $$4(entry){var $d, $e, k = nil, _ = nil, v = nil; - // Used to get a list of rest keyword arguments. Method takes the given - // keyword args, i.e. the hash literal passed to the method containing all - // keyword arguemnts passed to method, as well as the used args which are - // the names of required and optional arguments defined. This method then - // just returns all key/value pairs which have not been used, in a new - // hash literal. - // - // @param given_args [Hash] all kwargs given to method - // @param used_args [Object<String: true>] all keys used as named kwargs - // @return [Hash] - // - Opal.kwrestargs = function(given_args, used_args) { - var keys = [], - map = {}, - key = null, - given_map = given_args.$$smap; + + if (entry == null) entry = nil; + $e = entry.$partition("="), $d = $to_ary($e), (k = ($d[0] == null ? nil : $d[0])), (_ = ($d[1] == null ? nil : $d[1])), (v = ($d[2] == null ? nil : $d[2])), $e; + return ($d = [k, v], $send(accum, '[]=', $d), $d[$d.length - 1]);});}); + } else if (($truthy(attrs['$respond_to?']("keys")) && ($truthy(attrs['$respond_to?']("[]"))))) { + attrs = $send($hash2([], {}), 'tap', [], function $$5(accum){ + + if (accum == null) accum = nil; + return $send(attrs.$keys(), 'each', [], function $$6(k){var $d; - for (key in given_map) { - if (!used_args[key]) { - keys.push(key); - map[key] = given_map[key]; - } - } + + if (k == null) k = nil; + return ($d = [k, attrs['$[]'](k)], $send(accum, '[]=', $d), $d[$d.length - 1]);});}); + } else { + self.$raise($$$('ArgumentError'), "illegal type for attributes option: " + (attrs.$class().$ancestors().$join(" < "))); + }; + if ($eqeqeq($$$('File'), input)) { + + options['$[]=']("input_mtime", ($eqeq($$('RUBY_ENGINE'), "jruby") ? ($$$('Time').$at(input.$mtime().$to_i())) : (input.$mtime()))); + attrs['$[]=']("docfile", (input_path = $$$('File').$absolute_path(input.$path()))); + attrs['$[]=']("docdir", $$$('File').$dirname(input_path)); + attrs['$[]=']("docname", $$('Helpers').$basename(input_path, ($d = ["docfilesuffix", $$('Helpers').$extname(input_path)], $send(attrs, '[]=', $d), $d[$d.length - 1]))); + source = input.$read(); + } else if ($truthy(input['$respond_to?']("read"))) { + + try { + input.$rewind(); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + nil; + } finally { Opal.pop_exception(); } + } else { throw $err; } + }; + source = input.$read(); + } else if ($eqeqeq($$$('String'), input)) { + source = input; + } else if ($eqeqeq($$$('Array'), input)) { + source = input.$drop(0); + } else if ($truthy(input)) { + self.$raise($$$('ArgumentError'), "unsupported input type: " + (input.$class())); + }; + if ($truthy(timings)) { + + timings.$record("read"); + timings.$start("parse"); + }; + options['$[]=']("attributes", attrs); + doc = ($eqeq(options['$[]']("parse"), false) ? ($$('Document').$new(source, options)) : ($$('Document').$new(source, options).$parse())); + if ($truthy(timings)) { + timings.$record("parse"); + }; + return doc; + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) {(e = $err); + try { + + + try { + + context = "asciidoctor: FAILED: " + (($truthy(($ret_or_1 = attrs['$[]']("docfile"))) ? ($ret_or_1) : ("<stdin>"))) + ": Failed to load AsciiDoc document"; + if ($truthy(e['$respond_to?']("exception"))) { + + wrapped_e = e.$exception("" + (context) + " - " + (e.$message())); + wrapped_e.$set_backtrace(e.$backtrace()); + } else { + + wrapped_e = e.$class().$new(context, e); + wrapped_e['$stack_trace='](e.$stack_trace()); + }; + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + wrapped_e = e; + } finally { Opal.pop_exception(); } + } else { throw $err; } + };; + return self.$raise(wrapped_e); + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -2); + return $def(self, '$load_file', function $$load_file(filename, options) { + var self = this; - return Opal.hash2(keys, map); - }; + + if (options == null) options = $hash2([], {}); + return $send($$$('File'), 'open', [filename, $$('FILE_READ_MODE')], function $$7(file){var self = $$7.$$s == null ? this : $$7.$$s; - // Calls passed method on a ruby object with arguments and block: - // - // Can take a method or a method name. - // - // 1. When method name gets passed it invokes it by its name - // and calls 'method_missing' when object doesn't have this method. - // Used internally by Opal to invoke method that takes a block or a splat. - // 2. When method (i.e. method body) gets passed, it doesn't trigger 'method_missing' - // because it doesn't know the name of the actual method. - // Used internally by Opal to invoke 'super'. - // - // @example - // var my_array = [1, 2, 3, 4] - // Opal.send(my_array, 'length') # => 4 - // Opal.send(my_array, my_array.$length) # => 4 - // - // Opal.send(my_array, 'reverse!') # => [4, 3, 2, 1] - // Opal.send(my_array, my_array['$reverse!']') # => [4, 3, 2, 1] - // - // @param recv [Object] ruby object - // @param method [Function, String] method body or name of the method - // @param args [Array] arguments that will be passed to the method call - // @param block [Function] ruby block - // @return [Object] returning value of the method call - Opal.send = function(recv, method, args, block) { - var body = (typeof(method) === 'string') ? recv['$'+method] : method; + + if (file == null) file = nil; + return self.$load(file, options);}, {$$s: self}); + }, -2); + })(Opal.get_singleton_class(self), $nesting) + })($nesting[0], $nesting) +}; - if (body != null) { - if (typeof block === 'function') { - body.$$p = block; - } - return body.apply(recv, args); - } +Opal.modules["asciidoctor/convert"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $hash2 = Opal.hash2, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $rb_ge = Opal.rb_ge, $not = Opal.not, $rb_lt = Opal.rb_lt, $neqeq = Opal.neqeq, $def = Opal.def, $send = Opal.send, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - return recv.$method_missing.apply(recv, [method].concat(args)); - } + Opal.add_stubs('delete,merge,===,absolute_path,path,load,respond_to?,[]=,key?,fetch,[],dirname,expand_path,join,attributes,outfilesuffix,==,raise,pwd,>=,safe,normalize_system_path,mkdir_p,directory?,!,convert,write,attr,uriish?,basebackend?,attr?,<,include?,syntax_highlighter,write_stylesheet?,write_primary_stylesheet,instance,to_s,read_asset,file?,!=,write_stylesheet,open,convert_file'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - Opal.lambda = function(block) { - block.$$is_lambda = true; - return block; - } + var $nesting = [self].concat($parent_nesting); - // Used to define methods on an object. This is a helper method, used by the - // compiled source to define methods on special case objects when the compiler - // can not determine the destination object, or the object is a Module - // instance. This can get called by `Module#define_method` as well. - // - // ## Modules - // - // Any method defined on a module will come through this runtime helper. - // The method is added to the module body, and the owner of the method is - // set to be the module itself. This is used later when choosing which - // method should show on a class if more than 1 included modules define - // the same method. Finally, if the module is in `module_function` mode, - // then the method is also defined onto the module itself. - // - // ## Classes - // - // This helper will only be called for classes when a method is being - // defined indirectly; either through `Module#define_method`, or by a - // literal `def` method inside an `instance_eval` or `class_eval` body. In - // either case, the method is simply added to the class' prototype. A special - // exception exists for `BasicObject` and `Object`. These two classes are - // special because they are used in toll-free bridged classes. In each of - // these two cases, extra work is required to define the methods on toll-free - // bridged class' prototypes as well. - // - // ## Objects - // - // If a simple ruby object is the object, then the method is simply just - // defined on the object as a singleton method. This would be the case when - // a method is defined inside an `instance_eval` block. - // - // @param obj [Object, Class] the actual obj to define method for - // @param jsid [String] the JavaScript friendly method name (e.g. '$foo') - // @param body [JS.Function] the literal JavaScript function used as method - // @return [null] - // - Opal.def = function(obj, jsid, body) { - // Special case for a method definition in the - // top-level namespace - if (obj === Opal.top) { - Opal.defn(Opal.Object, jsid, body) - } - // if instance_eval is invoked on a module/class, it sets inst_eval_mod - else if (!obj.$$eval && obj.$$is_a_module) { - Opal.defn(obj, jsid, body); - } - else { - Opal.defs(obj, jsid, body); - } - }; + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Define method on a module or class (see Opal.def). - Opal.defn = function(module, jsid, body) { - body.displayName = jsid; - body.$$owner = module; + + + $def(self, '$convert', function $$convert(input, options) { + var self = this, to_dir = nil, mkdirs = nil, $ret_or_1 = nil, to_file = nil, write_to_target = nil, sibling_path = nil, stream_output = nil, outdir = nil, doc = nil, outfile = nil, working_dir = nil, jail = nil, output = nil, stylesdir = nil, stylesheet = nil, copy_asciidoctor_stylesheet = nil, copy_user_stylesheet = nil, copy_syntax_hl_stylesheet = nil, syntax_hl = nil, stylesoutdir = nil, stylesheet_src = nil, stylesheet_dest = nil, stylesheet_data = nil, stylesheet_outdir = nil; - var proto = module.$$prototype; - if (proto.hasOwnProperty('$$dummy')) { - proto = proto.$$define_methods_on; - } - $defineProperty(proto, jsid, body); + + if (options == null) options = $hash2([], {}); + (options = options.$merge()).$delete("parse"); + to_dir = options.$delete("to_dir"); + mkdirs = options.$delete("mkdirs"); + if (($eqeqeq(true, ($ret_or_1 = (to_file = options.$delete("to_file")))) || ($eqeqeq(nil, $ret_or_1)))) { + + if (!$truthy((write_to_target = to_dir))) { + if ($eqeqeq($$$('File'), input)) { + sibling_path = $$$('File').$absolute_path(input.$path()); + } + } to_file = nil; + } else if ($eqeqeq(false, $ret_or_1)) { + to_file = nil; + } else if ($eqeqeq("/dev/null", $ret_or_1)) { + return self.$load(input, options) + } else if (!$truthy((stream_output = to_file['$respond_to?']("write")))) { + options['$[]=']("to_file", (write_to_target = to_file)); + } if (!$truthy(options['$key?']("standalone"))) { + if (($truthy(sibling_path) || ($truthy(write_to_target)))) { + options['$[]=']("standalone", options.$fetch("header_footer", true)); + } else if ($truthy(options['$key?']("header_footer"))) { + options['$[]=']("standalone", options['$[]']("header_footer")); + } + } if ($truthy(sibling_path)) { + options['$[]=']("to_dir", (outdir = $$$('File').$dirname(sibling_path))); + } else if ($truthy(write_to_target)) { + if ($truthy(to_dir)) { + if ($truthy(to_file)) { + options['$[]=']("to_dir", $$$('File').$dirname($$$('File').$expand_path(to_file, to_dir))); + } else { + options['$[]=']("to_dir", $$$('File').$expand_path(to_dir)); + } + } else if ($truthy(to_file)) { + options['$[]=']("to_dir", $$$('File').$dirname($$$('File').$expand_path(to_file))); + } + } doc = self.$load(input, options); + if ($truthy(sibling_path)) { + + outfile = $$$('File').$join(outdir, "" + (doc.$attributes()['$[]']("docname")) + (doc.$outfilesuffix())); + if ($eqeq(outfile, sibling_path)) { + self.$raise($$$('IOError'), "input file and output file cannot be the same: " + (outfile)); + } } else if ($truthy(write_to_target)) { + + working_dir = ($truthy(options['$key?']("base_dir")) ? ($$$('File').$expand_path(options['$[]']("base_dir"))) : ($$$('Dir').$pwd())); + jail = ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (working_dir) : (nil)); + if ($truthy(to_dir)) { + + outdir = doc.$normalize_system_path(to_dir, working_dir, jail, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false})); + if ($truthy(to_file)) { + + outfile = doc.$normalize_system_path(to_file, outdir, nil, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false})); + outdir = $$$('File').$dirname(outfile); + } else { + outfile = $$$('File').$join(outdir, "" + (doc.$attributes()['$[]']("docname")) + (doc.$outfilesuffix())); + } } else if ($truthy(to_file)) { + + outfile = doc.$normalize_system_path(to_file, working_dir, jail, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false})); + outdir = $$$('File').$dirname(outfile); + } if (($eqeqeq($$$('File'), input) && ($eqeq(outfile, $$$('File').$absolute_path(input.$path()))))) { + self.$raise($$$('IOError'), "input file and output file cannot be the same: " + (outfile)); + } if ($truthy(mkdirs)) { + $$('Helpers').$mkdir_p(outdir); + } else if (!$truthy($$$('File')['$directory?'](outdir))) { + self.$raise($$$('IOError'), "target directory does not exist: " + (to_dir) + " (hint: set :mkdirs option)"); + } } else { + + outfile = to_file; + outdir = nil; + } if (($truthy(outfile) && ($not(stream_output)))) { + output = doc.$convert($hash2(["outfile", "outdir"], {"outfile": outfile, "outdir": outdir})); + } else { + output = doc.$convert(); + } if ($truthy(outfile)) { + + doc.$write(output, outfile); + if (((((($not(stream_output) && ($truthy($rb_lt(doc.$safe(), $$$($$('SafeMode'), 'SECURE'))))) && ($truthy(doc['$attr?']("linkcss")))) && ($truthy(doc['$attr?']("copycss")))) && ($truthy(doc['$basebackend?']("html")))) && ($not(($truthy(($ret_or_1 = (stylesdir = doc.$attr("stylesdir")))) ? ($$('Helpers')['$uriish?'](stylesdir)) : ($ret_or_1)))))) { + + if ($truthy((stylesheet = doc.$attr("stylesheet")))) { + if ($truthy($$('DEFAULT_STYLESHEET_KEYS')['$include?'](stylesheet))) { + copy_asciidoctor_stylesheet = true; + } else if ($not($$('Helpers')['$uriish?'](stylesheet))) { + copy_user_stylesheet = true; + } + } copy_syntax_hl_stylesheet = ($truthy(($ret_or_1 = (syntax_hl = doc.$syntax_highlighter()))) ? (syntax_hl['$write_stylesheet?'](doc)) : ($ret_or_1)); + if ((($truthy(copy_asciidoctor_stylesheet) || ($truthy(copy_user_stylesheet))) || ($truthy(copy_syntax_hl_stylesheet)))) { + + stylesoutdir = doc.$normalize_system_path(stylesdir, outdir, ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (outdir) : (nil))); + if ($truthy(mkdirs)) { + $$('Helpers').$mkdir_p(stylesoutdir); + } else if (!$truthy($$$('File')['$directory?'](stylesoutdir))) { + self.$raise($$$('IOError'), "target stylesheet directory does not exist: " + (stylesoutdir) + " (hint: set :mkdirs option)"); + } if ($truthy(copy_asciidoctor_stylesheet)) { + $$('Stylesheets').$instance().$write_primary_stylesheet(stylesoutdir); + } else if ($truthy(copy_user_stylesheet)) { + + if (($eqeq((stylesheet_src = doc.$attr("copycss")), "") || ($eqeq(stylesheet_src, true)))) { + stylesheet_src = doc.$normalize_system_path(stylesheet); + } else { + stylesheet_src = doc.$normalize_system_path(stylesheet_src.$to_s()); + } stylesheet_dest = doc.$normalize_system_path(stylesheet, stylesoutdir, ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (outdir) : (nil))); + if (($neqeq(stylesheet_src, stylesheet_dest) && ($truthy((stylesheet_data = doc.$read_asset(stylesheet_src, $hash2(["warn_on_failure", "label"], {"warn_on_failure": $$$('File')['$file?'](stylesheet_dest)['$!'](), "label": "stylesheet"}))))))) { + + if (($neqeq((stylesheet_outdir = $$$('File').$dirname(stylesheet_dest)), stylesoutdir) && ($not($$$('File')['$directory?'](stylesheet_outdir))))) { + if ($truthy(mkdirs)) { + $$('Helpers').$mkdir_p(stylesheet_outdir); + } else { + self.$raise($$$('IOError'), "target stylesheet directory does not exist: " + (stylesheet_outdir) + " (hint: set :mkdirs option)"); + } + } $$$('File').$write(stylesheet_dest, stylesheet_data, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')})); + } } if ($truthy(copy_syntax_hl_stylesheet)) { + syntax_hl.$write_stylesheet(doc, stylesoutdir); + } } } return doc; + } else { + return output + } }, -2); + + $def(self, '$convert_file', function $$convert_file(filename, options) { + var self = this; - if (module.$$is_module) { - if (module.$$module_function) { - Opal.defs(module, jsid, body) - } + + if (options == null) options = $hash2([], {}); + return $send($$$('File'), 'open', [filename, $$('FILE_READ_MODE')], function $$1(file){var self = $$1.$$s == null ? this : $$1.$$s; - for (var i = 0, iclasses = module.$$iclasses, length = iclasses.length; i < length; i++) { - var iclass = iclasses[i]; - $defineProperty(iclass, jsid, body); - } - } + + if (file == null) file = nil; + return self.$convert(file, options);}, {$$s: self}); + }, -2); + $alias(self, "render", "convert"); + return $alias(self, "render_file", "convert_file"); + })(Opal.get_singleton_class(self), $nesting) + })($nesting[0], $nesting) +}; - var singleton_of = module.$$singleton_of; - if (module.$method_added && !module.$method_added.$$stub && !singleton_of) { - module.$method_added(jsid.substr(1)); - } - else if (singleton_of && singleton_of.$singleton_method_added && !singleton_of.$singleton_method_added.$$stub) { - singleton_of.$singleton_method_added(jsid.substr(1)); - } - } +Opal.modules["asciidoctor/syntax_highlighter/highlightjs"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $def = Opal.def, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $return_val = Opal.return_val, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // Define a singleton method on the given object (see Opal.def). - Opal.defs = function(obj, jsid, body) { - if (obj.$$is_string || obj.$$is_number) { - throw Opal.TypeError.$new("can't define singleton"); - } - Opal.defn(Opal.get_singleton_class(obj), jsid, body) - }; + Opal.add_stubs('register_for,merge,proc,[]=,attr,[],==,attr?,join,map,split,lstrip'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - // Called from #remove_method. - Opal.rdef = function(obj, jsid) { - if (!$hasOwn.call(obj.$$prototype, jsid)) { - throw Opal.NameError.$new("method '" + jsid.substr(1) + "' not defined in " + obj.$name()); - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - delete obj.$$prototype[jsid]; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'HighlightJsAdapter'); - if (obj.$$is_singleton) { - if (obj.$$prototype.$singleton_method_removed && !obj.$$prototype.$singleton_method_removed.$$stub) { - obj.$$prototype.$singleton_method_removed(jsid.substr(1)); - } - } - else { - if (obj.$method_removed && !obj.$method_removed.$$stub) { - obj.$method_removed(jsid.substr(1)); - } - } - }; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Called from #undef_method. - Opal.udef = function(obj, jsid) { - if (!obj.$$prototype[jsid] || obj.$$prototype[jsid].$$stub) { - throw Opal.NameError.$new("method '" + jsid.substr(1) + "' not defined in " + obj.$name()); - } + + self.$register_for("highlightjs", "highlight.js"); + + $def(self, '$initialize', function $$initialize($a) { + var $post_args, args, $yield = $$initialize.$$p || nil, self = this; - Opal.add_stub_for(obj.$$prototype, jsid); + $$initialize.$$p = null; + + $post_args = $slice(arguments); + args = $post_args; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', $to_a(args), $yield); + return (self.name = (self.pre_class = "highlightjs")); + }, -1); + + $def(self, '$format', function $$format(node, lang, opts) { + $$format.$$p || nil; var self = this; - if (obj.$$is_singleton) { - if (obj.$$prototype.$singleton_method_undefined && !obj.$$prototype.$singleton_method_undefined.$$stub) { - obj.$$prototype.$singleton_method_undefined(jsid.substr(1)); - } - } - else { - if (obj.$method_undefined && !obj.$method_undefined.$$stub) { - obj.$method_undefined(jsid.substr(1)); - } - } - }; + $$format.$$p = null; + return $send2(self, $find_super(self, 'format', $$format, false, true), 'format', [node, lang, opts.$merge($hash2(["transform"], {"transform": $send(self, 'proc', [], function $$1(_, code){var $a, $ret_or_1 = nil; + if (code == null) code = nil; + return ($a = ["class", "language-" + (($truthy(($ret_or_1 = lang)) ? ($ret_or_1) : ("none"))) + " hljs"], $send(code, '[]=', $a), $a[$a.length - 1]);})}))], null) + }); + + $def(self, '$docinfo?', $return_val(true)); + return $def(self, '$docinfo', function $$docinfo(location, doc, opts) { + var base_url = nil; - function is_method_body(body) { - return (typeof(body) === "function" && !body.$$stub); - } + + base_url = doc.$attr("highlightjsdir", "" + (opts['$[]']("cdn_base_url")) + "/highlight.js/" + ($$('HIGHLIGHT_JS_VERSION'))); + if ($eqeq(location, "head")) { + return "<link rel=\"stylesheet\" href=\"" + (base_url) + "/styles/" + (doc.$attr("highlightjs-theme", "github")) + ".min.css\"" + (opts['$[]']("self_closing_tag_slash")) + ">" + } else { + return "<script src=\"" + (base_url) + "/highlight.min.js\"></script>\n" + (($truthy(doc['$attr?']("highlightjs-languages")) ? ($send(doc.$attr("highlightjs-languages").$split(","), 'map', [], function $$2(lang){ + + if (lang == null) lang = nil; + return "<script src=\"" + (base_url) + "/languages/" + (lang.$lstrip()) + ".min.js\"></script>\n";}).$join()) : (""))) + "<script>\n" + "if (!hljs.initHighlighting.called) {\n" + " hljs.initHighlighting.called = true\n" + " ;[].slice.call(document.querySelectorAll('pre.highlight > code[data-lang]')).forEach(function (el) { hljs.highlightBlock(el) })\n" + "}\n" + "</script>" + } }); + })($$('SyntaxHighlighter'), $$$($$('SyntaxHighlighter'), 'Base'), $nesting) + })($nesting[0], $nesting) +}; - Opal.alias = function(obj, name, old) { - var id = '$' + name, - old_id = '$' + old, - body = obj.$$prototype['$' + old], - alias; +Opal.modules["asciidoctor/syntax_highlighter"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $defs = Opal.defs, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Class = Opal.Class, $klass = Opal.klass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // When running inside #instance_eval the alias refers to class methods. - if (obj.$$eval) { - return Opal.alias(Opal.get_singleton_class(obj), name, old); - } + Opal.add_stubs('attr_reader,raise,class,extend,private_class_method,register,map,to_s,each,[]=,registry,[],for,===,new,name,private,include,delete,join,content'); + + (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - if (!is_method_body(body)) { - var ancestor = obj.$$super; + var $nesting = [self].concat($parent_nesting); - while (typeof(body) !== "function" && ancestor) { - body = ancestor[old_id]; - ancestor = ancestor.$$super; - } + return (function($base, $parent_nesting) { + var self = $module($base, 'SyntaxHighlighter'); - if (!is_method_body(body) && obj.$$is_module) { - // try to look into Object - body = Opal.Object.$$prototype[old_id] - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (!is_method_body(body)) { - throw Opal.NameError.$new("undefined method `" + old + "' for class `" + obj.$name() + "'") - } - } + + self.$attr_reader("name"); + + $def(self, '$initialize', function $$initialize(name, backend, opts) { + var self = this; + if (opts == null) opts = $hash2([], {}); + return (self.name = (self.pre_class = name)); + }, -2); + + $def(self, '$docinfo?', $return_val(nil)); + + $def(self, '$docinfo', function $$docinfo(location, doc, opts) { + var self = this; - // If the body is itself an alias use the original body - // to keep the max depth at 1. - if (body.$$alias_of) body = body.$$alias_of; + return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("docinfo") + " method since #docinfo? returns true") + }); + + $def(self, '$highlight?', $return_val(nil)); + + $def(self, '$highlight', function $$highlight(node, source, lang, opts) { + var self = this; - // We need a wrapper because otherwise properties - // would be ovrewritten on the original body. - alias = function() { - var block = alias.$$p, args, i, ii; + return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("highlight") + " method since #highlight? returns true") + }); + + $def(self, '$format', function $$format(node, lang, opts) { + var self = this; - args = new Array(arguments.length); - for(i = 0, ii = arguments.length; i < ii; i++) { - args[i] = arguments[i]; - } + return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("format") + " method") + }); + + $def(self, '$write_stylesheet?', $return_val(nil)); + + $def(self, '$write_stylesheet', function $$write_stylesheet(doc, to_dir) { + var self = this; - if (block != null) { alias.$$p = null } + return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("write_stylesheet") + " method since #write_stylesheet? returns true") + }); + $defs(self, '$included', function $$included(into) { + + return into.$extend($$('Config')) + }); + self.$private_class_method("included"); + (function($base, $parent_nesting) { + var self = $module($base, 'Config'); - return Opal.send(this, body, args, block); - }; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Try to make the browser pick the right name - alias.displayName = name; - alias.length = body.length; - alias.$$arity = body.$$arity; - alias.$$parameters = body.$$parameters; - alias.$$source_location = body.$$source_location; - alias.$$alias_of = body; - alias.$$alias_name = name; + return $def(self, '$register_for', function $$register_for($a) { + var $post_args, names, self = this; - Opal.defn(obj, id, alias); + + $post_args = $slice(arguments); + names = $post_args; + return $send($$('SyntaxHighlighter'), 'register', [self].concat($to_a($send(names, 'map', [], function $$1(name){ + + if (name == null) name = nil; + return name.$to_s();})))); + }, -1) + })($nesting[0], $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'Factory'); - return obj; - }; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.alias_native = function(obj, name, native_name) { - var id = '$' + name, - body = obj.$$prototype[native_name]; + + + $def(self, '$register', function $$register(syntax_highlighter, $a) { + var $post_args, names, self = this; - if (typeof(body) !== "function" || body.$$stub) { - throw Opal.NameError.$new("undefined native method `" + native_name + "' for class `" + obj.$name() + "'") - } + + $post_args = $slice(arguments, 1); + names = $post_args; + return $send(names, 'each', [], function $$2(name){var $b, self = $$2.$$s == null ? this : $$2.$$s; - Opal.defn(obj, id, body); + + if (name == null) name = nil; + return ($b = [name, syntax_highlighter], $send(self.$registry(), '[]=', $b), $b[$b.length - 1]);}, {$$s: self}); + }, -2); + + $def(self, '$for', function $Factory_for$3(name) { + var self = this; - return obj; - }; + return self.$registry()['$[]'](name) + }); + + $def(self, '$create', function $$create(name, backend, opts) { + var self = this, syntax_hl = nil; + + if (backend == null) backend = "html5"; + if (opts == null) opts = $hash2([], {}); + if ($truthy((syntax_hl = self.$for(name)))) { + + if ($eqeqeq($Class, syntax_hl)) { + syntax_hl = syntax_hl.$new(name, backend, opts); + } if (!$truthy(syntax_hl.$name())) { + self.$raise($$$('NameError'), "" + (syntax_hl.$class()) + " must specify a value for `name'"); + } return syntax_hl; + } else { + return nil + } }, -2); + self.$private(); + return $def(self, '$registry', function $$registry() { + var self = this; - // Hashes - // ------ + return self.$raise($$$('NotImplementedError'), "" + ($$('Factory')) + " subclass " + (self.$class()) + " must implement the #" + ("registry") + " method") + }); + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'CustomFactory'); - Opal.hash_init = function(hash) { - hash.$$smap = Object.create(null); - hash.$$map = Object.create(null); - hash.$$keys = []; - }; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.hash_clone = function(from_hash, to_hash) { - to_hash.$$none = from_hash.$$none; - to_hash.$$proc = from_hash.$$proc; + + self.$include($$('Factory')); + + $def(self, '$initialize', function $$initialize(seed_registry) { + var self = this, $ret_or_1 = nil; - for (var i = 0, keys = from_hash.$$keys, smap = from_hash.$$smap, len = keys.length, key, value; i < len; i++) { - key = keys[i]; + + if (seed_registry == null) seed_registry = nil; + return (self.registry = ($truthy(($ret_or_1 = seed_registry)) ? ($ret_or_1) : ($hash2([], {})))); + }, -1); + self.$private(); + return self.$attr_reader("registry"); + })($nesting[0], null, $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'DefaultFactory'); - if (key.$$is_string) { - value = smap[key]; - } else { - value = key.value; - key = key.key; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.hash_put(to_hash, key, value); - } - }; + + self.$include($$('Factory')); + $class_variable_set($nesting[0], '@@registry', $hash2([], {})); + self.$private(); + + $def(self, '$registry', function $$registry() { + + return $class_variable_get($nesting[0], '@@registry', false) + }); + return nil; + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'DefaultFactoryProxy'); - Opal.hash_put = function(hash, key, value) { - if (key.$$is_string) { - if (!$hasOwn.call(hash.$$smap, key)) { - hash.$$keys.push(key); - } - hash.$$smap[key] = value; - return; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - var key_hash, bucket, last_bucket; - key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash(); + + self.$include($$('DefaultFactory')); + return nil; + })($nesting[0], $$('CustomFactory'), $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Base'); - if (!$hasOwn.call(hash.$$map, key_hash)) { - bucket = {key: key, key_hash: key_hash, value: value}; - hash.$$keys.push(bucket); - hash.$$map[key_hash] = bucket; - return; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - bucket = hash.$$map[key_hash]; + $proto.pre_class = nil; + + self.$include($$('SyntaxHighlighter')); + return $def(self, '$format', function $$format(node, lang, opts) { + var self = this, class_attr_val = nil, transform = nil, pre = nil, code = nil; - while (bucket) { - if (key === bucket.key || key['$eql?'](bucket.key)) { - last_bucket = undefined; - bucket.value = value; - break; - } - last_bucket = bucket; - bucket = bucket.next; - } + + class_attr_val = ($truthy(opts['$[]']("nowrap")) ? ("" + (self.pre_class) + " highlight nowrap") : ("" + (self.pre_class) + " highlight")); + if ($truthy((transform = opts['$[]']("transform")))) { + + transform['$[]']((pre = $hash2(["class"], {"class": class_attr_val})), (code = ($truthy(lang) ? ($hash2(["data-lang"], {"data-lang": lang})) : ($hash2([], {}))))); + if ($truthy((lang = code.$delete("data-lang")))) { + code['$[]=']("data-lang", lang); + } return "<pre" + ($send(pre, 'map', [], function $$4(k, v){ + + if (k == null) k = nil; + if (v == null) v = nil; + return " " + (k) + "=\"" + (v) + "\"";}).$join()) + "><code" + ($send(code, 'map', [], function $$5(k, v){ + + if (k == null) k = nil; + if (v == null) v = nil; + return " " + (k) + "=\"" + (v) + "\"";}).$join()) + ">" + (node.$content()) + "</code></pre>"; + } else { + return "<pre class=\"" + (class_attr_val) + "\"><code" + (($truthy(lang) ? (" data-lang=\"" + (lang) + "\"") : (""))) + ">" + (node.$content()) + "</code></pre>" + } }); + })($nesting[0], null, $nesting); + return self.$extend($$('DefaultFactory')); + })($nesting[0], $nesting) + })($nesting[0], $nesting); + self.$require("asciidoctor/syntax_highlighter.rb"+ '/../' + "syntax_highlighter/highlightjs"); + return nil; +}; - if (last_bucket) { - bucket = {key: key, key_hash: key_hash, value: value}; - hash.$$keys.push(bucket); - last_bucket.next = bucket; - } - }; +Opal.modules["asciidoctor/timings"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $def = Opal.def, $send = Opal.send, $rb_minus = Opal.rb_minus, $slice = Opal.slice, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $gvars = Opal.gvars, $eqeq = Opal.eqeq, $const_set = Opal.const_set, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - Opal.hash_get = function(hash, key) { - if (key.$$is_string) { - if ($hasOwn.call(hash.$$smap, key)) { - return hash.$$smap[key]; - } - return; - } + Opal.add_stubs('[]=,now,-,delete,reduce,+,[],>,time,puts,sprintf,to_f,read_parse,convert,read_parse_convert,private,==,const_defined?,clock_gettime'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - var key_hash, bucket; - key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash(); + var $nesting = [self].concat($parent_nesting); - if ($hasOwn.call(hash.$$map, key_hash)) { - bucket = hash.$$map[key_hash]; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Timings'); - while (bucket) { - if (key === bucket.key || key['$eql?'](bucket.key)) { - return bucket.value; - } - bucket = bucket.next; - } - } - }; + var $a, $b, $c, $d, $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - Opal.hash_delete = function(hash, key) { - var i, keys = hash.$$keys, length = keys.length, value; + $proto.timers = $proto.log = nil; + + + $def(self, '$initialize', function $$initialize() { + var self = this; - if (key.$$is_string) { - if (!$hasOwn.call(hash.$$smap, key)) { - return; - } + + self.log = $hash2([], {}); + return (self.timers = $hash2([], {})); + }); + + $def(self, '$start', function $$start(key) { + var $a, self = this; - for (i = 0; i < length; i++) { - if (keys[i] === key) { - keys.splice(i, 1); - break; - } - } + return ($a = [key, self.$now()], $send(self.timers, '[]=', $a), $a[$a.length - 1]) + }); + + $def(self, '$record', function $$record(key) { + var $a, self = this; - value = hash.$$smap[key]; - delete hash.$$smap[key]; - return value; - } + return ($a = [key, $rb_minus(self.$now(), self.timers.$delete(key))], $send(self.log, '[]=', $a), $a[$a.length - 1]) + }); + + $def(self, '$time', function $$time($a) { + var $post_args, keys, self = this, time = nil; - var key_hash = key.$hash(); + + $post_args = $slice(arguments); + keys = $post_args; + time = $send(keys, 'reduce', [0], function $$1(sum, key){var self = $$1.$$s == null ? this : $$1.$$s, $ret_or_1 = nil; + if (self.log == null) self.log = nil; - if (!$hasOwn.call(hash.$$map, key_hash)) { - return; - } + + if (sum == null) sum = nil; + if (key == null) key = nil; + return $rb_plus(sum, ($truthy(($ret_or_1 = self.log['$[]'](key))) ? ($ret_or_1) : (0)));}, {$$s: self}); + if ($truthy($rb_gt(time, 0))) { + return time + } else { + return nil + } }, -1); + + $def(self, '$read', function $$read() { + var self = this; - var bucket = hash.$$map[key_hash], last_bucket; + return self.$time("read") + }); + + $def(self, '$parse', function $$parse() { + var self = this; - while (bucket) { - if (key === bucket.key || key['$eql?'](bucket.key)) { - value = bucket.value; + return self.$time("parse") + }); + + $def(self, '$read_parse', function $$read_parse() { + var self = this; - for (i = 0; i < length; i++) { - if (keys[i] === bucket) { - keys.splice(i, 1); - break; - } - } + return self.$time("read", "parse") + }); + + $def(self, '$convert', function $$convert() { + var self = this; - if (last_bucket && bucket.next) { - last_bucket.next = bucket.next; - } - else if (last_bucket) { - delete last_bucket.next; - } - else if (bucket.next) { - hash.$$map[key_hash] = bucket.next; - } - else { - delete hash.$$map[key_hash]; - } + return self.$time("convert") + }); + + $def(self, '$read_parse_convert', function $$read_parse_convert() { + var self = this; - return value; - } - last_bucket = bucket; - bucket = bucket.next; - } - }; + return self.$time("read", "parse", "convert") + }); + + $def(self, '$write', function $$write() { + var self = this; - Opal.hash_rehash = function(hash) { - for (var i = 0, length = hash.$$keys.length, key_hash, bucket, last_bucket; i < length; i++) { + return self.$time("write") + }); + + $def(self, '$total', function $$total() { + var self = this; - if (hash.$$keys[i].$$is_string) { - continue; - } + return self.$time("read", "parse", "convert", "write") + }); + + $def(self, '$print_report', function $$print_report(to, subject) { + var self = this; + if ($gvars.stdout == null) $gvars.stdout = nil; - key_hash = hash.$$keys[i].key.$hash(); + + if (to == null) to = $gvars.stdout; + if (subject == null) subject = nil; + if ($truthy(subject)) { + to.$puts("Input file: " + (subject)); + } to.$puts(" Time to read and parse source: " + (self.$sprintf("%05.5f", self.$read_parse().$to_f()))); + to.$puts(" Time to convert document: " + (self.$sprintf("%05.5f", self.$convert().$to_f()))); + return to.$puts(" Total time (read, parse and convert): " + (self.$sprintf("%05.5f", self.$read_parse_convert().$to_f()))); + }, -1); + self.$private(); + if (($truthy($$$('Process')['$const_defined?']("CLOCK_MONOTONIC", false)) && ($eqeq(((($a = $$$('::', 'Process', 'skip_raise')) && ($b = $a, $b) && ($c = $b) && ((($d = $c.$clock_gettime) && !$d.$$stub) || $c['$respond_to_missing?']('clock_gettime'))) ? 'method' : nil), "method")))) { + + $const_set($nesting[0], 'CLOCK_ID', $$$($$$('Process'), 'CLOCK_MONOTONIC')); + return $def(self, '$now', function $$now() { + + return $$$('Process').$clock_gettime($$('CLOCK_ID')) + }); + } else { + return $def(self, '$now', function $$now() { + + return $$$('Time').$now() + }) + } })($nesting[0], null, $nesting) + })($nesting[0], $nesting) +}; - if (key_hash === hash.$$keys[i].key_hash) { - continue; - } +Opal.modules["asciidoctor/converter/html5"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash2 = Opal.hash2, $regexp = Opal.regexp, $eqeq = Opal.eqeq, $def = Opal.def, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $send = Opal.send, $rb_gt = Opal.rb_gt, $rb_plus = Opal.rb_plus, $not = Opal.not, $neqeq = Opal.neqeq, $rb_le = Opal.rb_le, $rb_lt = Opal.rb_lt, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $rb_minus = Opal.rb_minus, $gvars = Opal.gvars, $return_val = Opal.return_val, $alias = Opal.alias, $eqeqeq = Opal.eqeqeq, $slice = Opal.slice, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - bucket = hash.$$map[hash.$$keys[i].key_hash]; - last_bucket = undefined; + Opal.add_stubs('register_for,default=,==,[],init_backend_traits,node_name,convert_inline_quoted,convert_paragraph,convert_inline_anchor,convert_section,convert_listing,convert_literal,convert_ulist,convert_olist,convert_dlist,convert_admonition,convert_colist,convert_embedded,convert_example,convert_floating_title,convert_image,convert_inline_break,convert_inline_button,convert_inline_callout,convert_inline_footnote,convert_inline_image,convert_inline_indexterm,convert_inline_kbd,convert_inline_menu,convert_open,convert_page_break,convert_preamble,convert_quote,convert_sidebar,convert_stem,convert_table,convert_thematic_break,convert_verse,convert_video,convert_document,convert_toc,convert_pass,convert_audio,empty?,attr,attr?,<<,include?,sub_replacements,gsub,extname,slice,length,doctitle,normalize_web_path,primary_stylesheet_data,instance,read_contents,syntax_highlighter,size,docinfo,id,sections?,doctype,role?,role,join,noheader,convert,converter,generate_manname_section,header?,notitle,title,header,each,authors,>,name,email,sub_macros,+,downcase,concat,content,!,footnotes?,footnotes,index,text,nofooter,docinfo?,[]=,delete_at,inspect,!=,to_i,attributes,document,sections,level,caption,captioned_title,<=,numbered,<,sectname,sectnum,convert_outline,title?,icon_uri,compact,media_uri,option?,append_boolean_attribute,style,items,blocks?,text?,chomp,safe,read_svg_contents,alt,image_uri,encode_attribute_value,append_link_constraint_attrs,highlight?,to_sym,format,*,-,count,end_with?,start_with?,list_marker_keyword,parent,warn,logger,context,error,content_only,new,columns,to_h,rows,colspan,rowspan,unshift,shift,split,pop,nil_or_empty?,type,===,catalog,get_root_document,xreftext,target,reftext,chop,sub,match,private,upcase,nested?,parent_document,handles?,to_s,send'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - while (bucket) { - if (bucket === hash.$$keys[i]) { - if (last_bucket && bucket.next) { - last_bucket.next = bucket.next; - } - else if (last_bucket) { - delete last_bucket.next; - } - else if (bucket.next) { - hash.$$map[hash.$$keys[i].key_hash] = bucket.next; - } - else { - delete hash.$$map[hash.$$keys[i].key_hash]; - } - break; - } - last_bucket = bucket; - bucket = bucket.next; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - hash.$$keys[i].key_hash = key_hash; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Html5Converter'); - if (!$hasOwn.call(hash.$$map, key_hash)) { - hash.$$map[key_hash] = hash.$$keys[i]; - continue; - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - bucket = hash.$$map[key_hash]; - last_bucket = undefined; + $proto.void_element_slash = $proto.xml_mode = $proto.refs = $proto.resolving_xref = nil; + + self.$register_for("html5"); + $const_set($nesting[0], 'QUOTE_TAGS', $hash2(["monospaced", "emphasis", "strong", "double", "single", "mark", "superscript", "subscript", "asciimath", "latexmath"], {"monospaced": ["<code>", "</code>", true], "emphasis": ["<em>", "</em>", true], "strong": ["<strong>", "</strong>", true], "double": ["“", "”"], "single": ["‘", "’"], "mark": ["<mark>", "</mark>", true], "superscript": ["<sup>", "</sup>", true], "subscript": ["<sub>", "</sub>", true], "asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]}))['$default='](["", ""]); + $const_set($nesting[0], 'DropAnchorRx', /<(?:a\b[^>]*|\/a)>/); + $const_set($nesting[0], 'StemBreakRx', / *\\\n(?:\\?\n)*|\n\n+/); + + $const_set($nesting[0], 'SvgPreambleRx', $regexp(["^", $$('CC_ALL'), "*?(?=<svg[\\s>])"])); + $const_set($nesting[0], 'SvgStartTagRx', /^<svg(?:\s[^>]*)?>/); $const_set($nesting[0], 'DimensionAttributeRx', $regexp(["\\s(?:width|height|style)=([\"'])", $$('CC_ANY'), "*?\\1"])); + + $def(self, '$initialize', function $$initialize(backend, opts) { + var self = this, syntax = nil; - while (bucket) { - if (bucket === hash.$$keys[i]) { - last_bucket = undefined; - break; - } - last_bucket = bucket; - bucket = bucket.next; - } + + if (opts == null) opts = $hash2([], {}); + self.backend = backend; + if ($eqeq(opts['$[]']("htmlsyntax"), "xml")) { + + syntax = "xml"; + self.xml_mode = true; + self.void_element_slash = "/"; + } else { + + syntax = "html"; + self.xml_mode = nil; + self.void_element_slash = ""; + } return self.$init_backend_traits($hash2(["basebackend", "filetype", "htmlsyntax", "outfilesuffix", "supports_templates"], {"basebackend": "html", "filetype": "html", "htmlsyntax": syntax, "outfilesuffix": ".html", "supports_templates": true})); + }, -2); + + $def(self, '$convert', function $$convert(node, transform, opts) { + var $yield = $$convert.$$p || nil, self = this; + + $$convert.$$p = null; + + if (transform == null) transform = node.$node_name(); + if (opts == null) opts = nil; + + switch (transform) { + case "inline_quoted": + return self.$convert_inline_quoted(node) + case "paragraph": + return self.$convert_paragraph(node) + case "inline_anchor": + return self.$convert_inline_anchor(node) + case "section": + return self.$convert_section(node) + case "listing": + return self.$convert_listing(node) + case "literal": + return self.$convert_literal(node) + case "ulist": + return self.$convert_ulist(node) + case "olist": + return self.$convert_olist(node) + case "dlist": + return self.$convert_dlist(node) + case "admonition": + return self.$convert_admonition(node) + case "colist": + return self.$convert_colist(node) + case "embedded": + return self.$convert_embedded(node) + case "example": + return self.$convert_example(node) + case "floating_title": + return self.$convert_floating_title(node) + case "image": + return self.$convert_image(node) + case "inline_break": + return self.$convert_inline_break(node) + case "inline_button": + return self.$convert_inline_button(node) + case "inline_callout": + return self.$convert_inline_callout(node) + case "inline_footnote": + return self.$convert_inline_footnote(node) + case "inline_image": + return self.$convert_inline_image(node) + case "inline_indexterm": + return self.$convert_inline_indexterm(node) + case "inline_kbd": + return self.$convert_inline_kbd(node) + case "inline_menu": + return self.$convert_inline_menu(node) + case "open": + return self.$convert_open(node) + case "page_break": + return self.$convert_page_break(node) + case "preamble": + return self.$convert_preamble(node) + case "quote": + return self.$convert_quote(node) + case "sidebar": + return self.$convert_sidebar(node) + case "stem": + return self.$convert_stem(node) + case "table": + return self.$convert_table(node) + case "thematic_break": + return self.$convert_thematic_break(node) + case "verse": + return self.$convert_verse(node) + case "video": + return self.$convert_video(node) + case "document": + return self.$convert_document(node) + case "toc": + return self.$convert_toc(node) + case "pass": + return self.$convert_pass(node) + case "audio": + return self.$convert_audio(node) + default: + return $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [node, transform, opts], $yield) + } }, -2); + + $def(self, '$convert_document', function $$convert_document(node) { + var self = this, br = nil, slash = nil, asset_uri_scheme = nil, cdn_base_url = nil, linkcss = nil, max_width_attr = nil, result = nil, lang_attribute = nil, authors = nil, icon_href = nil, icon_type = nil, icon_ext = nil, webfonts = nil, iconfont_stylesheet = nil, syntax_hl = nil, syntax_hl_docinfo_head_idx = nil, docinfo_content = nil, id_attr = nil, sectioned = nil, classes = nil, details = nil, idx = nil, $ret_or_1 = nil, eqnums_val = nil, eqnums_opt = nil; - if (last_bucket) { - last_bucket.next = hash.$$keys[i]; - } - } - }; + + br = "<br" + ((slash = self.void_element_slash)) + ">"; + if (!$truthy((asset_uri_scheme = node.$attr("asset-uri-scheme", "https"))['$empty?']())) { + asset_uri_scheme = "" + (asset_uri_scheme) + ":"; + } cdn_base_url = "" + (asset_uri_scheme) + "//cdnjs.cloudflare.com/ajax/libs"; + linkcss = node['$attr?']("linkcss"); + max_width_attr = ($truthy(node['$attr?']("max-width")) ? (" style=\"max-width: " + (node.$attr("max-width")) + ";\"") : ("")); + result = ["<!DOCTYPE html>"]; + lang_attribute = ($truthy(node['$attr?']("nolang")) ? ("") : (" lang=\"" + (node.$attr("lang", "en")) + "\"")); + result['$<<']("<html" + (($truthy(self.xml_mode) ? (" xmlns=\"http://www.w3.org/1999/xhtml\"") : (""))) + (lang_attribute) + ">"); + result['$<<']("<head>\n" + "<meta charset=\"" + (node.$attr("encoding", "UTF-8")) + "\"" + (slash) + ">\n" + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"" + (slash) + ">\n" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"" + (slash) + ">\n" + "<meta name=\"generator\" content=\"Asciidoctor " + (node.$attr("asciidoctor-version")) + "\"" + (slash) + ">"); + if ($truthy(node['$attr?']("app-name"))) { + result['$<<']("<meta name=\"application-name\" content=\"" + (node.$attr("app-name")) + "\"" + (slash) + ">"); + } if ($truthy(node['$attr?']("description"))) { + result['$<<']("<meta name=\"description\" content=\"" + (node.$attr("description")) + "\"" + (slash) + ">"); + } if ($truthy(node['$attr?']("keywords"))) { + result['$<<']("<meta name=\"keywords\" content=\"" + (node.$attr("keywords")) + "\"" + (slash) + ">"); + } if ($truthy(node['$attr?']("authors"))) { + result['$<<']("<meta name=\"author\" content=\"" + (($truthy((authors = node.$sub_replacements(node.$attr("authors")))['$include?']("<")) ? (authors.$gsub($$('XmlSanitizeRx'), "")) : (authors))) + "\"" + (slash) + ">"); + } if ($truthy(node['$attr?']("copyright"))) { + result['$<<']("<meta name=\"copyright\" content=\"" + (node.$attr("copyright")) + "\"" + (slash) + ">"); + } if ($truthy(node['$attr?']("favicon"))) { + + if ($truthy((icon_href = node.$attr("favicon"))['$empty?']())) { + + icon_href = "favicon.ico"; + icon_type = "image/x-icon"; + } else if ($truthy((icon_ext = $$('Helpers').$extname(icon_href, nil)))) { + icon_type = ($eqeq(icon_ext, ".ico") ? ("image/x-icon") : ("image/" + (icon_ext.$slice(1, icon_ext.$length())))); + } else { + icon_type = "image/x-icon"; + } result['$<<']("<link rel=\"icon\" type=\"" + (icon_type) + "\" href=\"" + (icon_href) + "\"" + (slash) + ">"); + } result['$<<']("<title>" + (node.$doctitle($hash2(["sanitize", "use_fallback"], {"sanitize": true, "use_fallback": true}))) + ""); + if ($truthy($$('DEFAULT_STYLESHEET_KEYS')['$include?'](node.$attr("stylesheet")))) { + + if ($truthy((webfonts = node.$attr("webfonts")))) { + result['$<<'](""); + } if ($truthy(linkcss)) { + result['$<<'](""); + } else { + result['$<<'](""); + } } else if ($truthy(node['$attr?']("stylesheet"))) { + if ($truthy(linkcss)) { + result['$<<'](""); + } else { + result['$<<'](""); + } + } if ($truthy(node['$attr?']("icons", "font"))) { + if ($truthy(node['$attr?']("iconfont-remote"))) { + result['$<<'](""); + } else { + + iconfont_stylesheet = "" + (node.$attr("iconfont-name", "font-awesome")) + ".css"; + result['$<<'](""); + } + } if ($truthy((syntax_hl = node.$syntax_highlighter()))) { + result['$<<']((syntax_hl_docinfo_head_idx = result.$size())); + } if (!$truthy((docinfo_content = node.$docinfo())['$empty?']())) { + result['$<<'](docinfo_content); + } result['$<<'](""); + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + if (((($truthy((sectioned = node['$sections?']())) && ($truthy(node['$attr?']("toc-class")))) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) { + classes = [node.$doctype(), node.$attr("toc-class"), "toc-" + (node.$attr("toc-position", "header"))]; + } else { + classes = [node.$doctype()]; + } if ($truthy(node['$role?']())) { + classes['$<<'](node.$role()); + } result['$<<'](""); + if (!$truthy((docinfo_content = node.$docinfo("header"))['$empty?']())) { + result['$<<'](docinfo_content); + } if (!$truthy(node.$noheader())) { + + result['$<<']("
"); + if ($eqeq(node.$doctype(), "manpage")) { + + result['$<<']("

" + (node.$doctitle()) + " Manual Page

"); + if ((($truthy(sectioned) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) { + result['$<<']("
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
"); + } if ($truthy(node['$attr?']("manpurpose"))) { + result['$<<'](self.$generate_manname_section(node)); + } } else { + + if ($truthy(node['$header?']())) { + + if (!$truthy(node.$notitle())) { + result['$<<']("

" + (node.$header().$title()) + "

"); + } details = []; + idx = 1; + $send(node.$authors(), 'each', [], function $$1(author){ + + if (author == null) author = nil; + details['$<<']("" + (node.$sub_replacements(author.$name())) + "" + (br)); + if ($truthy(author.$email())) { + details['$<<']("" + (node.$sub_macros(author.$email())) + "" + (br)); + } return (idx = $rb_plus(idx, 1));}); + if ($truthy(node['$attr?']("revnumber"))) { + details['$<<']("" + (($truthy(($ret_or_1 = node.$attr("version-label"))) ? ($ret_or_1) : ("")).$downcase()) + " " + (node.$attr("revnumber")) + (($truthy(node['$attr?']("revdate")) ? (",") : (""))) + ""); + } if ($truthy(node['$attr?']("revdate"))) { + details['$<<']("" + (node.$attr("revdate")) + ""); + } if ($truthy(node['$attr?']("revremark"))) { + details['$<<']("" + (br) + "" + (node.$attr("revremark")) + ""); + } if (!$truthy(details['$empty?']())) { + + result['$<<']("
"); + result.$concat(details); + result['$<<']("
"); + } } if ((($truthy(sectioned) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) { + result['$<<']("
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
"); + } } result['$<<']("
"); + } result['$<<']("
\n" + (node.$content()) + "\n" + "
"); + if (($truthy(node['$footnotes?']()) && ($not(node['$attr?']("nofootnotes"))))) { + + result['$<<']("
\n" + ""); + $send(node.$footnotes(), 'each', [], function $$2(footnote){ + + if (footnote == null) footnote = nil; + return result['$<<']("
\n" + "" + (footnote.$index()) + ". " + (footnote.$text()) + "\n" + "
");}); + result['$<<']("
"); + } if (!$truthy(node.$nofooter())) { + + result['$<<']("
"); + result['$<<']("
"); + if ($truthy(node['$attr?']("revnumber"))) { + result['$<<']("" + (node.$attr("version-label")) + " " + (node.$attr("revnumber")) + (br)); + } if (($truthy(node['$attr?']("last-update-label")) && ($not(node['$attr?']("reproducible"))))) { + result['$<<']("" + (node.$attr("last-update-label")) + " " + (node.$attr("docdatetime"))); + } result['$<<']("
"); + result['$<<']("
"); + } if ($truthy(syntax_hl)) { + + if ($truthy(syntax_hl['$docinfo?']("head"))) { + result['$[]='](syntax_hl_docinfo_head_idx, syntax_hl.$docinfo("head", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_closing_tag_slash": slash}))); + } else { + result.$delete_at(syntax_hl_docinfo_head_idx); + } if ($truthy(syntax_hl['$docinfo?']("footer"))) { + result['$<<'](syntax_hl.$docinfo("footer", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_closing_tag_slash": slash}))); + } } if ($truthy(node['$attr?']("stem"))) { + + eqnums_val = node.$attr("eqnums", "none"); + if ($truthy(eqnums_val['$empty?']())) { + eqnums_val = "AMS"; + } eqnums_opt = " equationNumbers: { autoNumber: \"" + (eqnums_val) + "\" } "; + result['$<<']("\n" + ""); + } if (!$truthy((docinfo_content = node.$docinfo("footer"))['$empty?']())) { + result['$<<'](docinfo_content); + } result['$<<'](""); + result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_embedded', function $$convert_embedded(node) { + var self = this, result = nil, id_attr = nil, toc_p = nil; - Opal.hash = function() { - var arguments_length = arguments.length, args, hash, i, length, key, value; + + result = []; + if ($eqeq(node.$doctype(), "manpage")) { + + if (!$truthy(node.$notitle())) { + + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + result['$<<']("" + (node.$doctitle()) + " Manual Page"); + } if ($truthy(node['$attr?']("manpurpose"))) { + result['$<<'](self.$generate_manname_section(node)); + } } else if (($truthy(node['$header?']()) && ($not(node.$notitle())))) { + + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + result['$<<']("" + (node.$header().$title()) + ""); + } if (((($truthy(node['$sections?']()) && ($truthy(node['$attr?']("toc")))) && ($neqeq((toc_p = node.$attr("toc-placement")), "macro"))) && ($neqeq(toc_p, "preamble")))) { + result['$<<']("
\n" + "
" + (node.$attr("toc-title")) + "
\n" + (node.$converter().$convert(node, "outline")) + "\n" + "
"); + } result['$<<'](node.$content()); + if (($truthy(node['$footnotes?']()) && ($not(node['$attr?']("nofootnotes"))))) { + + result['$<<']("
\n" + ""); + $send(node.$footnotes(), 'each', [], function $$3(footnote){ + + if (footnote == null) footnote = nil; + return result['$<<']("
\n" + "" + (footnote.$index()) + ". " + (footnote.$text()) + "\n" + "
");}); + result['$<<']("
"); + } return result.$join($$('LF')); + }); + + $def(self, '$convert_outline', function $$convert_outline(node, opts) { + var self = this, sectnumlevels = nil, $ret_or_1 = nil, $ret_or_2 = nil, toclevels = nil, sections = nil, result = nil; - if (arguments_length === 1 && arguments[0].$$is_hash) { - return arguments[0]; - } + + if (opts == null) opts = $hash2([], {}); + if (!$truthy(node['$sections?']())) { + return nil + } sectnumlevels = ($truthy(($ret_or_1 = opts['$[]']("sectnumlevels"))) ? ($ret_or_1) : (($truthy(($ret_or_2 = node.$document().$attributes()['$[]']("sectnumlevels"))) ? ($ret_or_2) : (3)).$to_i())); + toclevels = ($truthy(($ret_or_1 = opts['$[]']("toclevels"))) ? ($ret_or_1) : (($truthy(($ret_or_2 = node.$document().$attributes()['$[]']("toclevels"))) ? ($ret_or_2) : (2)).$to_i())); + sections = node.$sections(); + result = ["
    "]; + $send(sections, 'each', [], function $$4(section){var self = $$4.$$s == null ? this : $$4.$$s, slevel = nil, stitle = nil, signifier = nil, child_toc_level = nil; - hash = new Opal.Hash(); - Opal.hash_init(hash); + + if (section == null) section = nil; + slevel = section.$level(); + if ($truthy(section.$caption())) { + stitle = section.$captioned_title(); + } else if (($truthy(section.$numbered()) && ($truthy($rb_le(slevel, sectnumlevels))))) { + if (($truthy($rb_lt(slevel, 2)) && ($eqeq(node.$document().$doctype(), "book")))) { + + switch (section.$sectname()) { + case "chapter": + stitle = "" + (($truthy((signifier = node.$document().$attributes()['$[]']("chapter-signifier"))) ? ("" + (signifier) + " ") : (""))) + (section.$sectnum()) + " " + (section.$title()); + break; + case "part": + stitle = "" + (($truthy((signifier = node.$document().$attributes()['$[]']("part-signifier"))) ? ("" + (signifier) + " ") : (""))) + (section.$sectnum(nil, ":")) + " " + (section.$title()); + break; + default: + stitle = "" + (section.$sectnum()) + " " + (section.$title()); + } + } else { + stitle = "" + (section.$sectnum()) + " " + (section.$title()); + } + } else { + stitle = section.$title(); + } if ($truthy(stitle['$include?']("" + (stitle) + ""); + result['$<<'](child_toc_level); + return result['$<<'](""); + } else { + return result['$<<']("
  • " + (stitle) + "
  • ") + }}, {$$s: self}); + result['$<<']("
"); + return result.$join($$('LF')); + }, -2); + + $def(self, '$convert_section', function $$convert_section(node) { + var doc_attrs = nil, level = nil, title = nil, $ret_or_1 = nil, signifier = nil, id_attr = nil, id = nil, role = nil; - if (arguments_length === 1 && arguments[0].$$is_array) { - args = arguments[0]; - length = args.length; + + doc_attrs = node.$document().$attributes(); + level = node.$level(); + if ($truthy(node.$caption())) { + title = node.$captioned_title(); + } else if (($truthy(node.$numbered()) && ($truthy($rb_le(level, ($truthy(($ret_or_1 = doc_attrs['$[]']("sectnumlevels"))) ? ($ret_or_1) : (3)).$to_i()))))) { + if (($truthy($rb_lt(level, 2)) && ($eqeq(node.$document().$doctype(), "book")))) { + + switch (node.$sectname()) { + case "chapter": + title = "" + (($truthy((signifier = doc_attrs['$[]']("chapter-signifier"))) ? ("" + (signifier) + " ") : (""))) + (node.$sectnum()) + " " + (node.$title()); + break; + case "part": + title = "" + (($truthy((signifier = doc_attrs['$[]']("part-signifier"))) ? ("" + (signifier) + " ") : (""))) + (node.$sectnum(nil, ":")) + " " + (node.$title()); + break; + default: + title = "" + (node.$sectnum()) + " " + (node.$title()); + } + } else { + title = "" + (node.$sectnum()) + " " + (node.$title()); + } + } else { + title = node.$title(); + } if ($truthy(node.$id())) { + + id_attr = " id=\"" + ((id = node.$id())) + "\""; + if ($truthy(doc_attrs['$[]']("sectlinks"))) { + title = "" + (title) + ""; + } if ($truthy(doc_attrs['$[]']("sectanchors"))) { + if ($eqeq(doc_attrs['$[]']("sectanchors"), "after")) { + title = "" + (title) + ""; + } else { + title = "" + (title); + } + } } else { + id_attr = ""; + } if ($eqeq(level, 0)) { + return "" + (title) + "\n" + (node.$content()) + } else { + return "
\n" + "" + (title) + "\n" + (($eqeq(level, 1) ? ("
\n" + (node.$content()) + "\n" + "
") : (node.$content()))) + "\n" + "
" + } }); + + $def(self, '$convert_admonition', function $$convert_admonition(node) { + var self = this, id_attr = nil, name = nil, title_element = nil, label = nil, role = nil; - for (i = 0; i < length; i++) { - if (args[i].length !== 2) { - throw Opal.ArgumentError.$new("value not of length 2: " + args[i].$inspect()); - } + + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + name = node.$attr("name"); + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + if ($truthy(node.$document()['$attr?']("icons"))) { + if (($truthy(node.$document()['$attr?']("icons", "font")) && ($not(node['$attr?']("icon"))))) { + label = ""; + } else { + label = "\"""; + } + } else { + label = "
" + (node.$attr("textlabel")) + "
"; + } return "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + (label) + "\n" + "\n" + (title_element) + (node.$content()) + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_audio', function $$convert_audio(node) { + var self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, start_t = nil, end_t = nil, time_anchor = nil, $ret_or_1 = nil; - key = args[i][0]; - value = args[i][1]; + + xml = self.xml_mode; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["audioblock", node.$role()].$compact(); + class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + start_t = node.$attr("start"); + end_t = node.$attr("end"); + time_anchor = (($truthy(start_t) || ($truthy(end_t))) ? ("#t=" + (($truthy(($ret_or_1 = start_t)) ? ($ret_or_1) : (""))) + (($truthy(end_t) ? ("," + (end_t)) : ("")))) : ("")); + return "\n" + (title_element) + "
\n" + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_colist', function $$convert_colist(node) { + var $a, self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, font_icons = nil, num = nil; - Opal.hash_put(hash, key, value); - } + + result = []; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["colist", node.$style(), node.$role()].$compact(); + class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + result['$<<'](""); + if ($truthy(node['$title?']())) { + result['$<<']("
" + (node.$title()) + "
"); + } if ($truthy(node.$document()['$attr?']("icons"))) { + + result['$<<'](""); + $a = [node.$document()['$attr?']("icons", "font"), 0], (font_icons = $a[0]), (num = $a[1]); + $send(node.$items(), 'each', [], function $$5(item){var self = $$5.$$s == null ? this : $$5.$$s, num_label = nil; + if (self.void_element_slash == null) self.void_element_slash = nil; - return hash; - } + + if (item == null) item = nil; + num = $rb_plus(num, 1); + if ($truthy(font_icons)) { + num_label = "" + (num) + ""; + } else { + num_label = "\"""; + } return result['$<<']("\n" + "\n" + "\n" + "");}, {$$s: self}); + result['$<<']("
" + (num_label) + "" + (item.$text()) + (($truthy(item['$blocks?']()) ? ($rb_plus($$('LF'), item.$content())) : (""))) + "
"); + } else { + + result['$<<']("
    "); + $send(node.$items(), 'each', [], function $$6(item){ + + if (item == null) item = nil; + return result['$<<']("
  1. \n" + "

    " + (item.$text()) + "

    " + (($truthy(item['$blocks?']()) ? ($rb_plus($$('LF'), item.$content())) : (""))) + "\n" + "
  2. ");}); + result['$<<']("
"); + } result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_dlist', function $$convert_dlist(node) { + var self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, slash = nil, col_style_attribute = nil, dt_style_attribute = nil; - if (arguments_length === 1) { - args = arguments[0]; - for (key in args) { - if ($hasOwn.call(args, key)) { - value = args[key]; + + result = []; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + + switch (node.$style()) { + case "qanda": + classes = ["qlist", "qanda", node.$role()]; + break; + case "horizontal": + classes = ["hdlist", node.$role()]; + break; + default: + classes = ["dlist", node.$style(), node.$role()]; + } class_attribute = " class=\"" + (classes.$compact().$join(" ")) + "\""; + result['$<<'](""); + if ($truthy(node['$title?']())) { + result['$<<']("
" + (node.$title()) + "
"); + } + switch (node.$style()) { + case "qanda": + + result['$<<']("
    "); + $send(node.$items(), 'each', [], function $$7(terms, dd){ + + if (terms == null) terms = nil; + if (dd == null) dd = nil; + result['$<<']("
  1. "); + $send(terms, 'each', [], function $$8(dt){ + + if (dt == null) dt = nil; + return result['$<<']("

    " + (dt.$text()) + "

    ");}); + if ($truthy(dd)) { + + if ($truthy(dd['$text?']())) { + result['$<<']("

    " + (dd.$text()) + "

    "); + } if ($truthy(dd['$blocks?']())) { + result['$<<'](dd.$content()); + } } return result['$<<']("
  2. ");}); + result['$<<']("
"); + break; + case "horizontal": + + slash = self.void_element_slash; + result['$<<'](""); + if (($truthy(node['$attr?']("labelwidth")) || ($truthy(node['$attr?']("itemwidth"))))) { + + result['$<<'](""); + col_style_attribute = ($truthy(node['$attr?']("labelwidth")) ? (" style=\"width: " + (node.$attr("labelwidth").$chomp("%")) + "%;\"") : ("")); + result['$<<'](""); + col_style_attribute = ($truthy(node['$attr?']("itemwidth")) ? (" style=\"width: " + (node.$attr("itemwidth").$chomp("%")) + "%;\"") : ("")); + result['$<<'](""); + result['$<<'](""); + } $send(node.$items(), 'each', [], function $$9(terms, dd){var first_term = nil; - Opal.hash_put(hash, key, value); - } - } + + if (terms == null) terms = nil; + if (dd == null) dd = nil; + result['$<<'](""); + result['$<<'](""); + result['$<<'](""); + return result['$<<']("");}); + result['$<<']("
"); + first_term = true; + $send(terms, 'each', [], function $$10(dt){ + + if (dt == null) dt = nil; + if (!$truthy(first_term)) { + result['$<<'](""); + } result['$<<'](dt.$text()); + return (first_term = nil);}); + result['$<<'](""); + if ($truthy(dd)) { + + if ($truthy(dd['$text?']())) { + result['$<<']("

" + (dd.$text()) + "

"); + } if ($truthy(dd['$blocks?']())) { + result['$<<'](dd.$content()); + } } result['$<<']("
"); + break; + default: + + result['$<<']("
"); + dt_style_attribute = ($truthy(node.$style()) ? ("") : (" class=\"hdlist1\"")); + $send(node.$items(), 'each', [], function $$11(terms, dd){ + + if (terms == null) terms = nil; + if (dd == null) dd = nil; + $send(terms, 'each', [], function $$12(dt){ + + if (dt == null) dt = nil; + return result['$<<']("" + (dt.$text()) + "");}); + if (!$truthy(dd)) { + return nil + } result['$<<']("
"); + if ($truthy(dd['$text?']())) { + result['$<<']("

" + (dd.$text()) + "

"); + } if ($truthy(dd['$blocks?']())) { + result['$<<'](dd.$content()); + } return result['$<<']("
");}); + result['$<<']("
"); + } result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_example', function $$convert_example(node) { + var id_attribute = nil, class_attribute = nil, summary_element = nil, title_element = nil, role = nil; - return hash; - } + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + if ($truthy(node['$option?']("collapsible"))) { + + class_attribute = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : ("")); + summary_element = ($truthy(node['$title?']()) ? ("" + (node.$title()) + "") : ("Details")); + return "\n" + (summary_element) + "\n" + "
\n" + (node.$content()) + "\n" + "
\n" + ""; + } else { + + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$captioned_title()) + "
\n") : ("")); + return "\n" + (title_element) + "
\n" + (node.$content()) + "\n" + "
\n" + ""; + } }); + + $def(self, '$convert_floating_title', function $$convert_floating_title(node) { + var tag_name = nil, id_attribute = nil, classes = nil; - if (arguments_length % 2 !== 0) { - throw Opal.ArgumentError.$new("odd number of arguments for Hash"); - } + + tag_name = "h" + ($rb_plus(node.$level(), 1)); + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = [node.$style(), node.$role()].$compact(); + return "<" + (tag_name) + (id_attribute) + " class=\"" + (classes.$join(" ")) + "\">" + (node.$title()) + ""; + }); + + $def(self, '$convert_image', function $$convert_image(node) { + var self = this, target = nil, width_attr = nil, height_attr = nil, img = nil, $ret_or_1 = nil, fallback = nil, id_attr = nil, classes = nil, class_attr = nil, title_el = nil; - for (i = 0; i < arguments_length; i += 2) { - key = arguments[i]; - value = arguments[i + 1]; + + target = node.$attr("target"); + width_attr = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : ("")); + height_attr = ($truthy(node['$attr?']("height")) ? (" height=\"" + (node.$attr("height")) + "\"") : ("")); + if ((($truthy(node['$attr?']("format", "svg")) || ($truthy(target['$include?'](".svg")))) && ($truthy($rb_lt(node.$document().$safe(), $$$($$('SafeMode'), 'SECURE')))))) { + if ($truthy(node['$option?']("inline"))) { + img = ($truthy(($ret_or_1 = self.$read_svg_contents(node, target))) ? ($ret_or_1) : ("" + (node.$alt()) + "")); + } else if ($truthy(node['$option?']("interactive"))) { + + fallback = ($truthy(node['$attr?']("fallback")) ? ("\""") : ("" + (node.$alt()) + "")); + img = "" + (fallback) + ""; + } else { + img = "\"""; + } + } else { + img = "\"""; + } if ($truthy(node['$attr?']("link"))) { + img = "" + (img) + ""; + } id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["imageblock"]; + if ($truthy(node['$attr?']("float"))) { + classes['$<<'](node.$attr("float")); + } if ($truthy(node['$attr?']("align"))) { + classes['$<<']("text-" + (node.$attr("align"))); + } if ($truthy(node.$role())) { + classes['$<<'](node.$role()); + } class_attr = " class=\"" + (classes.$join(" ")) + "\""; + title_el = ($truthy(node['$title?']()) ? ("\n
" + (node.$captioned_title()) + "
") : ("")); + return "\n" + "
\n" + (img) + "\n" + "
" + (title_el) + "\n" + ""; + }); + + $def(self, '$convert_listing', function $$convert_listing(node) { + var nowrap = nil, $ret_or_1 = nil, lang = nil, syntax_hl = nil, opts = nil, doc_attrs = nil, pre_open = nil, pre_close = nil, id_attribute = nil, title_element = nil, role = nil; - Opal.hash_put(hash, key, value); - } + + nowrap = ($truthy(($ret_or_1 = node['$option?']("nowrap"))) ? ($ret_or_1) : (node.$document()['$attr?']("prewrap")['$!']())); + if ($eqeq(node.$style(), "source")) { + + lang = node.$attr("language"); + if ($truthy((syntax_hl = node.$document().$syntax_highlighter()))) { + + opts = ($truthy(syntax_hl['$highlight?']()) ? ($hash2(["css_mode", "style"], {"css_mode": ($truthy(($ret_or_1 = (doc_attrs = node.$document().$attributes())['$[]']("" + (syntax_hl.$name()) + "-css"))) ? ($ret_or_1) : ("class")).$to_sym(), "style": doc_attrs['$[]']("" + (syntax_hl.$name()) + "-style")})) : ($hash2([], {}))); + opts['$[]=']("nowrap", nowrap); + } else { + + pre_open = "
";
+            pre_close = "
"; + } } else { + + pre_open = ""; + pre_close = ""; + } id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$captioned_title()) + "
\n") : ("")); + return "\n" + (title_element) + "
\n" + (($truthy(syntax_hl) ? (syntax_hl.$format(node, lang, opts)) : ($rb_plus($rb_plus(pre_open, node.$content()), pre_close)))) + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_literal', function $$convert_literal(node) { + var id_attribute = nil, title_element = nil, nowrap = nil, $ret_or_1 = nil, role = nil; - return hash; - }; + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + nowrap = ($truthy(($ret_or_1 = node.$document()['$attr?']("prewrap")['$!']())) ? ($ret_or_1) : (node['$option?']("nowrap"))); + return "\n" + (title_element) + "
\n" + "" + (node.$content()) + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_stem', function $$convert_stem(node) { + var $a, $b, self = this, id_attribute = nil, title_element = nil, style = nil, open = nil, close = nil, equation = nil, br = nil, role = nil; - // A faster Hash creator for hashes that just use symbols and - // strings as keys. The map and keys array can be constructed at - // compile time, so they are just added here by the constructor - // function. - // - Opal.hash2 = function(keys, smap) { - var hash = new Opal.Hash(); + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + $b = $$('BLOCK_MATH_DELIMITERS')['$[]']((style = node.$style().$to_sym())), $a = $to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])); + if ($truthy((equation = node.$content()))) { + + if (($eqeq(style, "asciimath") && ($truthy(equation['$include?']($$('LF')))))) { + + br = "" + ($$('LF')) + ""; + equation = $send(equation, 'gsub', [$$('StemBreakRx')], function $$13(){var $c; - hash.$$smap = smap; - hash.$$map = Object.create(null); - hash.$$keys = keys; + return "" + (close) + ($rb_times(br, $rb_minus((($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$count($$('LF')), 1))) + ($$('LF')) + (open)}); + } if (!($truthy(equation['$start_with?'](open)) && ($truthy(equation['$end_with?'](close))))) { + equation = "" + (open) + (equation) + (close); + } } else { + equation = ""; + } return "\n" + (title_element) + "
\n" + (equation) + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_olist', function $$convert_olist(node) { + var self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, type_attribute = nil, keyword = nil, start_attribute = nil, reversed_attribute = nil; - return hash; - }; + + result = []; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["olist", node.$style(), node.$role()].$compact(); + class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + result['$<<'](""); + if ($truthy(node['$title?']())) { + result['$<<']("
" + (node.$title()) + "
"); + } type_attribute = ($truthy((keyword = node.$list_marker_keyword())) ? (" type=\"" + (keyword) + "\"") : ("")); + start_attribute = ($truthy(node['$attr?']("start")) ? (" start=\"" + (node.$attr("start")) + "\"") : ("")); + reversed_attribute = ($truthy(node['$option?']("reversed")) ? (self.$append_boolean_attribute("reversed", self.xml_mode)) : ("")); + result['$<<']("
    "); + $send(node.$items(), 'each', [], function $$14(item){ + + if (item == null) item = nil; + if ($truthy(item.$id())) { + result['$<<']("
  1. "); + } else if ($truthy(item.$role())) { + result['$<<']("
  2. "); + } else { + result['$<<']("
  3. "); + } result['$<<']("

    " + (item.$text()) + "

    "); + if ($truthy(item['$blocks?']())) { + result['$<<'](item.$content()); + } return result['$<<']("
  4. ");}); + result['$<<']("
"); + result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_open', function $$convert_open(node) { + var self = this, style = nil, id_attr = nil, title_el = nil, role = nil; - // Create a new range instance with first and last values, and whether the - // range excludes the last value. - // - Opal.range = function(first, last, exc) { - var range = new Opal.Range(); - range.begin = first; - range.end = last; - range.excl = exc; + if ($eqeq((style = node.$style()), "abstract")) { + if (($eqeq(node.$parent(), node.$document()) && ($eqeq(node.$document().$doctype(), "book")))) { + + self.$logger().$warn("abstract block cannot be used in a document without a title when doctype is book. Excluding block content."); + return ""; + } else { + + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_el = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + return "\n" + (title_el) + "
\n" + (node.$content()) + "\n" + "
\n" + ""; + } + } else if (($eqeq(style, "partintro") && ((($truthy($rb_gt(node.$level(), 0)) || ($neqeq(node.$parent().$context(), "section"))) || ($neqeq(node.$document().$doctype(), "book")))))) { + + self.$logger().$error("partintro block can only be used when doctype is book and must be a child of a book part. Excluding block content."); + return ""; + } else { + + id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_el = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + return "\n" + (title_el) + "
\n" + (node.$content()) + "\n" + "
\n" + ""; + } + }); + + $def(self, '$convert_page_break', $return_val("
")); + + $def(self, '$convert_paragraph', function $$convert_paragraph(node) { + var attributes = nil; - return range; - }; + + if ($truthy(node.$role())) { + attributes = "" + (($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""))) + " class=\"paragraph " + (node.$role()) + "\""; + } else if ($truthy(node.$id())) { + attributes = " id=\"" + (node.$id()) + "\" class=\"paragraph\""; + } else { + attributes = " class=\"paragraph\""; + } if ($truthy(node['$title?']())) { + return "\n" + "
" + (node.$title()) + "
\n" + "

" + (node.$content()) + "

\n" + "" + } else { + return "\n" + "

" + (node.$content()) + "

\n" + "" + } }); + $alias(self, "convert_pass", "content_only"); + + $def(self, '$convert_preamble', function $$convert_preamble(node) { + var doc = nil, toc = nil; - // Get the ivar name for a given name. - // Mostly adds a trailing $ to reserved names. - // - Opal.ivar = function(name) { - if ( - // properties - name === "constructor" || - name === "displayName" || - name === "__count__" || - name === "__noSuchMethod__" || - name === "__parent__" || - name === "__proto__" || - - // methods - name === "hasOwnProperty" || - name === "valueOf" - ) - { - return name + "$"; - } + + if ((($truthy((doc = node.$document())['$attr?']("toc-placement", "preamble")) && ($truthy(doc['$sections?']()))) && ($truthy(doc['$attr?']("toc"))))) { + toc = "\n" + "
\n" + "
" + (doc.$attr("toc-title")) + "
\n" + (doc.$converter().$convert(doc, "outline")) + "\n" + "
"; + } else { + toc = ""; + } return "
\n" + "
\n" + (node.$content()) + "\n" + "
" + (toc) + "\n" + "
"; + }); + + $def(self, '$convert_quote', function $$convert_quote(node) { + var self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil; - return name; - }; + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["quoteblock", node.$role()].$compact(); + class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + title_element = ($truthy(node['$title?']()) ? ("\n
" + (node.$title()) + "
") : ("")); + attribution = ($truthy(node['$attr?']("attribution")) ? (node.$attr("attribution")) : (nil)); + citetitle = ($truthy(node['$attr?']("citetitle")) ? (node.$attr("citetitle")) : (nil)); + if (($truthy(attribution) || ($truthy(citetitle)))) { + + cite_element = ($truthy(citetitle) ? ("" + (citetitle) + "") : ("")); + attribution_text = ($truthy(attribution) ? ("— " + (attribution) + (($truthy(citetitle) ? ("\n") : ("")))) : ("")); + attribution_element = "\n
\n" + (attribution_text) + (cite_element) + "\n
"; + } else { + attribution_element = ""; + } return "" + (title_element) + "\n" + "
\n" + (node.$content()) + "\n" + "
" + (attribution_element) + "\n" + ""; + }); + + $def(self, '$convert_thematic_break', function $$convert_thematic_break(node) { + var self = this; + return "" + }); + + $def(self, '$convert_sidebar', function $$convert_sidebar(node) { + var id_attribute = nil, title_element = nil, role = nil; - // Regexps - // ------- + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + title_element = ($truthy(node['$title?']()) ? ("
" + (node.$title()) + "
\n") : ("")); + return "\n" + "
\n" + (title_element) + (node.$content()) + "\n" + "
\n" + ""; + }); + + $def(self, '$convert_table', function $$convert_table(node) { + var self = this, result = nil, id_attribute = nil, frame = nil, classes = nil, stripes = nil, style_attribute = nil, autowidth = nil, tablewidth = nil, role = nil, class_attribute = nil, slash = nil; - // Escape Regexp special chars letting the resulting string be used to build - // a new Regexp. - // - Opal.escape_regexp = function(str) { - return str.replace(/([-[\]\/{}()*+?.^$\\| ])/g, '\\$1') - .replace(/[\n]/g, '\\n') - .replace(/[\r]/g, '\\r') - .replace(/[\f]/g, '\\f') - .replace(/[\t]/g, '\\t'); - }; + + result = []; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + if ($eqeq((frame = node.$attr("frame", "all", "table-frame")), "topbot")) { + frame = "ends"; + } classes = ["tableblock", "frame-" + (frame), "grid-" + (node.$attr("grid", "all", "table-grid"))]; + if ($truthy((stripes = node.$attr("stripes", nil, "table-stripes")))) { + classes['$<<']("stripes-" + (stripes)); + } style_attribute = ""; + if (($truthy((autowidth = node['$option?']("autowidth"))) && ($not(node['$attr?']("width"))))) { + classes['$<<']("fit-content"); + } else if ($eqeq((tablewidth = node.$attr("tablepcwidth")), 100)) { + classes['$<<']("stretch"); + } else { + style_attribute = " style=\"width: " + (tablewidth) + "%;\""; + } if ($truthy(node['$attr?']("float"))) { + classes['$<<'](node.$attr("float")); + } if ($truthy((role = node.$role()))) { + classes['$<<'](role); + } class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + result['$<<'](""); + if ($truthy(node['$title?']())) { + result['$<<']("" + (node.$captioned_title()) + ""); + } if ($truthy($rb_gt(node.$attr("rowcount"), 0))) { + + slash = self.void_element_slash; + result['$<<'](""); + if ($truthy(autowidth)) { + result = $rb_plus(result, $$('Array').$new(node.$columns().$size(), "")); + } else { + $send(node.$columns(), 'each', [], function $$15(col){ + + if (col == null) col = nil; + return result['$<<'](($truthy(col['$option?']("autowidth")) ? ("") : ("")));}); + } result['$<<'](""); + $send(node.$rows().$to_h(), 'each', [], function $$16(tsec, rows){ + + if (tsec == null) tsec = nil; + if (rows == null) rows = nil; + if ($truthy(rows['$empty?']())) { + return nil + } result['$<<'](""); + $send(rows, 'each', [], function $$17(row){ + + if (row == null) row = nil; + result['$<<'](""); + $send(row, 'each', [], function $$18(cell){var cell_content = nil, cell_tag_name = nil, cell_class_attribute = nil, cell_colspan_attribute = nil, cell_rowspan_attribute = nil, cell_style_attribute = nil; - // Create a global Regexp from a RegExp object and cache the result - // on the object itself ($$g attribute). - // - Opal.global_regexp = function(pattern) { - if (pattern.global) { - return pattern; // RegExp already has the global flag - } - if (pattern.$$g == null) { - pattern.$$g = new RegExp(pattern.source, (pattern.multiline ? 'gm' : 'g') + (pattern.ignoreCase ? 'i' : '')); - } else { - pattern.$$g.lastIndex = null; // reset lastIndex property - } - return pattern.$$g; - }; + + if (cell == null) cell = nil; + if ($eqeq(tsec, "head")) { + cell_content = cell.$text(); + } else + switch (cell.$style()) { + case "asciidoc": + cell_content = "
" + (cell.$content()) + "
"; + break; + case "literal": + cell_content = "
" + (cell.$text()) + "
"; + break; + default: + cell_content = ($truthy((cell_content = cell.$content())['$empty?']()) ? ("") : ("

" + (cell_content.$join("

\n" + "

")) + "

")); + } cell_tag_name = (($eqeq(tsec, "head") || ($eqeq(cell.$style(), "header"))) ? ("th") : ("td")); + cell_class_attribute = " class=\"tableblock halign-" + (cell.$attr("halign")) + " valign-" + (cell.$attr("valign")) + "\""; + cell_colspan_attribute = ($truthy(cell.$colspan()) ? (" colspan=\"" + (cell.$colspan()) + "\"") : ("")); + cell_rowspan_attribute = ($truthy(cell.$rowspan()) ? (" rowspan=\"" + (cell.$rowspan()) + "\"") : ("")); + cell_style_attribute = ($truthy(node.$document()['$attr?']("cellbgcolor")) ? (" style=\"background-color: " + (node.$document().$attr("cellbgcolor")) + ";\"") : ("")); + return result['$<<']("<" + (cell_tag_name) + (cell_class_attribute) + (cell_colspan_attribute) + (cell_rowspan_attribute) + (cell_style_attribute) + ">" + (cell_content) + "");}); + return result['$<<']("");}); + return result['$<<']("
");}); + } result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_toc', function $$convert_toc(node) { + var doc = nil, id_attr = nil, title_id_attr = nil, title = nil, levels = nil, role = nil; - // Create a global multiline Regexp from a RegExp object and cache the result - // on the object itself ($$gm or $$g attribute). - // - Opal.global_multiline_regexp = function(pattern) { - var result; - if (pattern.multiline) { - if (pattern.global) { - return pattern; // RegExp already has the global and multiline flag - } - // we are using the $$g attribute because the Regexp is already multiline - if (pattern.$$g != null) { - result = pattern.$$g; - } else { - result = pattern.$$g = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : '')); - } - } else if (pattern.$$gm != null) { - result = pattern.$$gm; - } else { - result = pattern.$$gm = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : '')); - } - result.lastIndex = null; // reset lastIndex property - return result; - }; + + if (!(($truthy((doc = node.$document())['$attr?']("toc-placement", "macro")) && ($truthy(doc['$sections?']()))) && ($truthy(doc['$attr?']("toc"))))) { + return "" + } if ($truthy(node.$id())) { + + id_attr = " id=\"" + (node.$id()) + "\""; + title_id_attr = " id=\"" + (node.$id()) + "title\""; + } else { + + id_attr = " id=\"toc\""; + title_id_attr = " id=\"toctitle\""; + } title = ($truthy(node['$title?']()) ? (node.$title()) : (doc.$attr("toc-title"))); + levels = ($truthy(node['$attr?']("levels")) ? (node.$attr("levels").$to_i()) : (nil)); + role = ($truthy(node['$role?']()) ? (node.$role()) : (doc.$attr("toc-class", "toc"))); + return "\n" + "" + (title) + "\n" + (doc.$converter().$convert(doc, "outline", $hash2(["toclevels"], {"toclevels": levels}))) + "\n" + ""; + }); + + $def(self, '$convert_ulist', function $$convert_ulist(node) { + var self = this, result = nil, id_attribute = nil, div_classes = nil, marker_checked = nil, marker_unchecked = nil, checklist = nil, ul_class_attribute = nil; - // Require system - // -------------- + + result = []; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + div_classes = ["ulist", node.$style(), node.$role()].$compact(); + marker_checked = (marker_unchecked = ""); + if ($truthy((checklist = node['$option?']("checklist")))) { + + div_classes.$unshift(div_classes.$shift(), "checklist"); + ul_class_attribute = " class=\"checklist\""; + if ($truthy(node['$option?']("interactive"))) { + if ($truthy(self.xml_mode)) { + + marker_checked = " "; + marker_unchecked = " "; + } else { + + marker_checked = " "; + marker_unchecked = " "; + } + } else if ($truthy(node.$document()['$attr?']("icons", "font"))) { + + marker_checked = " "; + marker_unchecked = " "; + } else { + + marker_checked = "✓ "; + marker_unchecked = "❏ "; + } } else { + ul_class_attribute = ($truthy(node.$style()) ? (" class=\"" + (node.$style()) + "\"") : ("")); + } result['$<<'](""); + if ($truthy(node['$title?']())) { + result['$<<']("
" + (node.$title()) + "
"); + } result['$<<'](""); + $send(node.$items(), 'each', [], function $$19(item){ + + if (item == null) item = nil; + if ($truthy(item.$id())) { + result['$<<']("
  • "); + } else if ($truthy(item.$role())) { + result['$<<']("
  • "); + } else { + result['$<<']("
  • "); + } if (($truthy(checklist) && ($truthy(item['$attr?']("checkbox"))))) { + result['$<<']("

    " + (($truthy(item['$attr?']("checked")) ? (marker_checked) : (marker_unchecked))) + (item.$text()) + "

    "); + } else { + result['$<<']("

    " + (item.$text()) + "

    "); + } if ($truthy(item['$blocks?']())) { + result['$<<'](item.$content()); + } return result['$<<']("
  • ");}); + result['$<<'](""); + result['$<<'](""); + return result.$join($$('LF')); + }); + + $def(self, '$convert_verse', function $$convert_verse(node) { + var self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil; - Opal.modules = {}; - Opal.loaded_features = ['corelib/runtime']; - Opal.current_dir = '.'; - Opal.require_table = {'corelib/runtime': true}; + + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["verseblock", node.$role()].$compact(); + class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + title_element = ($truthy(node['$title?']()) ? ("\n
    " + (node.$title()) + "
    ") : ("")); + attribution = ($truthy(node['$attr?']("attribution")) ? (node.$attr("attribution")) : (nil)); + citetitle = ($truthy(node['$attr?']("citetitle")) ? (node.$attr("citetitle")) : (nil)); + if (($truthy(attribution) || ($truthy(citetitle)))) { + + cite_element = ($truthy(citetitle) ? ("" + (citetitle) + "") : ("")); + attribution_text = ($truthy(attribution) ? ("— " + (attribution) + (($truthy(citetitle) ? ("\n") : ("")))) : ("")); + attribution_element = "\n
    \n" + (attribution_text) + (cite_element) + "\n
    "; + } else { + attribution_element = ""; + } return "" + (title_element) + "\n" + "
    " + (node.$content()) + "
    " + (attribution_element) + "\n" + ""; + }); + + $def(self, '$convert_video', function $$convert_video(node) { + var $a, $b, self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, width_attribute = nil, height_attribute = nil, asset_uri_scheme = nil, start_anchor = nil, delimiter = nil, target = nil, hash = nil, hash_param = nil, $ret_or_2 = nil, autoplay_param = nil, loop_param = nil, muted_param = nil, rel_param_val = nil, start_param = nil, end_param = nil, has_loop_param = nil, mute_param = nil, controls_param = nil, fs_param = nil, fs_attribute = nil, modest_param = nil, theme_param = nil, hl_param = nil, list = nil, list_param = nil, playlist = nil, poster_attribute = nil, val = nil, preload_attribute = nil, start_t = nil, end_t = nil, time_anchor = nil; - Opal.normalize = function(path) { - var parts, part, new_parts = [], SEPARATOR = '/'; + + xml = self.xml_mode; + id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : ("")); + classes = ["videoblock"]; + if ($truthy(node['$attr?']("float"))) { + classes['$<<'](node.$attr("float")); + } if ($truthy(node['$attr?']("align"))) { + classes['$<<']("text-" + (node.$attr("align"))); + } if ($truthy(node.$role())) { + classes['$<<'](node.$role()); + } class_attribute = " class=\"" + (classes.$join(" ")) + "\""; + title_element = ($truthy(node['$title?']()) ? ("\n
    " + (node.$title()) + "
    ") : ("")); + width_attribute = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : ("")); + height_attribute = ($truthy(node['$attr?']("height")) ? (" height=\"" + (node.$attr("height")) + "\"") : ("")); + + switch (node.$attr("poster")) { + case "vimeo": + + if (!$truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) { + asset_uri_scheme = "" + (asset_uri_scheme) + ":"; + } start_anchor = ($truthy(node['$attr?']("start")) ? ("#at=" + (node.$attr("start"))) : ("")); + delimiter = ["?"]; + $b = node.$attr("target").$split("/", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (hash = ($a[1] == null ? nil : $a[1])); + hash_param = ($truthy((hash = ($truthy(($ret_or_2 = hash)) ? ($ret_or_2) : (node.$attr("hash"))))) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&"))) + "h=" + (hash)) : ("")); + autoplay_param = ($truthy(node['$option?']("autoplay")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&"))) + "autoplay=1") : ("")); + loop_param = ($truthy(node['$option?']("loop")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&"))) + "loop=1") : ("")); + muted_param = ($truthy(node['$option?']("muted")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&"))) + "muted=1") : ("")); + return "" + (title_element) + "\n" + "
    \n" + "\n" + "
    \n" + ""; + case "youtube": + + if (!$truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) { + asset_uri_scheme = "" + (asset_uri_scheme) + ":"; + } rel_param_val = ($truthy(node['$option?']("related")) ? (1) : (0)); + start_param = ($truthy(node['$attr?']("start")) ? ("&start=" + (node.$attr("start"))) : ("")); + end_param = ($truthy(node['$attr?']("end")) ? ("&end=" + (node.$attr("end"))) : ("")); + autoplay_param = ($truthy(node['$option?']("autoplay")) ? ("&autoplay=1") : ("")); + loop_param = ($truthy((has_loop_param = node['$option?']("loop"))) ? ("&loop=1") : ("")); + mute_param = ($truthy(node['$option?']("muted")) ? ("&mute=1") : ("")); + controls_param = ($truthy(node['$option?']("nocontrols")) ? ("&controls=0") : ("")); + if ($truthy(node['$option?']("nofullscreen"))) { + + fs_param = "&fs=0"; + fs_attribute = ""; + } else { + + fs_param = ""; + fs_attribute = self.$append_boolean_attribute("allowfullscreen", xml); + } modest_param = ($truthy(node['$option?']("modest")) ? ("&modestbranding=1") : ("")); + theme_param = ($truthy(node['$attr?']("theme")) ? ("&theme=" + (node.$attr("theme"))) : ("")); + hl_param = ($truthy(node['$attr?']("lang")) ? ("&hl=" + (node.$attr("lang"))) : ("")); + $b = node.$attr("target").$split("/", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (list = ($a[1] == null ? nil : $a[1])); + if ($truthy((list = ($truthy(($ret_or_2 = list)) ? ($ret_or_2) : (node.$attr("list")))))) { + list_param = "&list=" + (list); + } else { + + $b = target.$split(",", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (playlist = ($a[1] == null ? nil : $a[1])); + if ($truthy((playlist = ($truthy(($ret_or_2 = playlist)) ? ($ret_or_2) : (node.$attr("playlist")))))) { + list_param = "&playlist=" + (target) + "," + (playlist); + } else { + list_param = ($truthy(has_loop_param) ? ("&playlist=" + (target)) : ("")); + } } return "" + (title_element) + "\n" + "
    \n" + "\n" + "
    \n" + ""; + default: + + poster_attribute = ($truthy((val = node.$attr("poster"))['$nil_or_empty?']()) ? ("") : (" poster=\"" + (node.$media_uri(val)) + "\"")); + preload_attribute = ($truthy((val = node.$attr("preload"))['$nil_or_empty?']()) ? ("") : (" preload=\"" + (val) + "\"")); + start_t = node.$attr("start"); + end_t = node.$attr("end"); + time_anchor = (($truthy(start_t) || ($truthy(end_t))) ? ("#t=" + (($truthy(($ret_or_2 = start_t)) ? ($ret_or_2) : (""))) + (($truthy(end_t) ? ("," + (end_t)) : ("")))) : ("")); + return "" + (title_element) + "\n" + "
    \n" + "\n" + "
    \n" + ""; + } }); + + $def(self, '$convert_inline_anchor', function $$convert_inline_anchor(node) { + var self = this, path = nil, attrs = nil, text = nil, $ret_or_2 = nil, ref = nil, $ret_or_3 = nil, refid = nil, top = nil, outer = nil; - if (Opal.current_dir !== '.') { - path = Opal.current_dir.replace(/\/*$/, '/') + path; - } + + switch (node.$type()) { + case "xref": + + if ($truthy((path = node.$attributes()['$[]']("path")))) { + + attrs = self.$append_link_constraint_attrs(node, ($truthy(node.$role()) ? ([" class=\"" + (node.$role()) + "\""]) : ([]))).$join(); + text = ($truthy(($ret_or_2 = node.$text())) ? ($ret_or_2) : (path)); + } else { + + attrs = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : ("")); + if (!$truthy((text = node.$text()))) { + if ($eqeqeq($$('AbstractNode'), (ref = ($truthy(($ret_or_2 = (self.refs = ($truthy(($ret_or_3 = self.refs)) ? ($ret_or_3) : (node.$document().$catalog()['$[]']("refs"))))['$[]']((refid = node.$attributes()['$[]']("refid"))))) ? ($ret_or_2) : (($truthy(refid['$nil_or_empty?']()) ? ((top = self.$get_root_document(node))) : (nil))))))) { + if (($truthy((self.resolving_xref = ($truthy(($ret_or_2 = self.resolving_xref)) ? ($ret_or_2) : ((outer = true))))) && ($truthy(outer)))) { + + if ($truthy((text = ref.$xreftext(node.$attr("xrefstyle", nil, true))))) { + if ($truthy(text['$include?']("" + (text) + ""; + case "ref": + return "" + case "link": + + attrs = ($truthy(node.$id()) ? ([" id=\"" + (node.$id()) + "\""]) : ([])); + if ($truthy(node.$role())) { + attrs['$<<'](" class=\"" + (node.$role()) + "\""); + } if ($truthy(node['$attr?']("title"))) { + attrs['$<<'](" title=\"" + (node.$attr("title")) + "\""); + } return "" + (node.$text()) + ""; + case "bibref": + return "[" + (($truthy(($ret_or_2 = node.$reftext())) ? ($ret_or_2) : (node.$id()))) + "]" + default: + + self.$logger().$warn("unknown anchor type: " + (node.$type().$inspect())); + return nil; + } + }); + + $def(self, '$convert_inline_break', function $$convert_inline_break(node) { + var self = this; - path = path.replace(/^\.\//, ''); - path = path.replace(/\.(rb|opal|js)$/, ''); - parts = path.split(SEPARATOR); + return "" + (node.$text()) + "" + }); + + $def(self, '$convert_inline_button', function $$convert_inline_button(node) { + + return "" + (node.$text()) + "" + }); + + $def(self, '$convert_inline_callout', function $$convert_inline_callout(node) { + var self = this, src = nil, guard = nil; - for (var i = 0, ii = parts.length; i < ii; i++) { - part = parts[i]; - if (part === '') continue; - (part === '..') ? new_parts.pop() : new_parts.push(part) - } + if ($truthy(node.$document()['$attr?']("icons", "font"))) { + return "(" + (node.$text()) + ")" + } else if ($truthy(node.$document()['$attr?']("icons"))) { + + src = node.$icon_uri("callouts/" + (node.$text())); + return "\"""; + } else if ($eqeqeq($$$('Array'), (guard = node.$attributes()['$[]']("guard")))) { + return "<!--(" + (node.$text()) + ")-->" + } else { + return "" + (guard) + "(" + (node.$text()) + ")" + } + }); + + $def(self, '$convert_inline_footnote', function $$convert_inline_footnote(node) { + var index = nil, id_attr = nil; - return new_parts.join(SEPARATOR); - }; + if ($truthy((index = node.$attr("index")))) { + if ($eqeq(node.$type(), "xref")) { + return "[" + (index) + "]" + } else { + + id_attr = ($truthy(node.$id()) ? (" id=\"_footnote_" + (node.$id()) + "\"") : ("")); + return "[" + (index) + "]"; + } + } else if ($eqeq(node.$type(), "xref")) { + return "[" + (node.$text()) + "]" + } else { + return nil + } + }); + + $def(self, '$convert_inline_image', function $$convert_inline_image(node) { + var self = this, target = nil, type = nil, $ret_or_1 = nil, icons = nil, i_class_attr_val = nil, attrs = nil, img = nil, fallback = nil, class_attr_val = nil, role = nil; - Opal.loaded = function(paths) { - var i, l, path; + + target = node.$target(); + if ($eqeq((type = ($truthy(($ret_or_1 = node.$type())) ? ($ret_or_1) : ("image"))), "icon")) { + if ($eqeq((icons = node.$document().$attr("icons")), "font")) { + + i_class_attr_val = "fa fa-" + (target); + if ($truthy(node['$attr?']("size"))) { + i_class_attr_val = "" + (i_class_attr_val) + " fa-" + (node.$attr("size")); + } if ($truthy(node['$attr?']("flip"))) { + i_class_attr_val = "" + (i_class_attr_val) + " fa-flip-" + (node.$attr("flip")); + } else if ($truthy(node['$attr?']("rotate"))) { + i_class_attr_val = "" + (i_class_attr_val) + " fa-rotate-" + (node.$attr("rotate")); + } attrs = ($truthy(node['$attr?']("title")) ? (" title=\"" + (node.$attr("title")) + "\"") : ("")); + img = ""; + } else if ($truthy(icons)) { + + attrs = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : ("")); + if ($truthy(node['$attr?']("height"))) { + attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""; + } if ($truthy(node['$attr?']("title"))) { + attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""; + } img = "\"""; + } else { + img = "[" + (node.$alt()) + "]"; + } + } else { + + attrs = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : ("")); + if ($truthy(node['$attr?']("height"))) { + attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""; + } if ($truthy(node['$attr?']("title"))) { + attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""; + } if ((($truthy(node['$attr?']("format", "svg")) || ($truthy(target['$include?'](".svg")))) && ($truthy($rb_lt(node.$document().$safe(), $$$($$('SafeMode'), 'SECURE')))))) { + if ($truthy(node['$option?']("inline"))) { + img = ($truthy(($ret_or_1 = self.$read_svg_contents(node, target))) ? ($ret_or_1) : ("" + (node.$alt()) + "")); + } else if ($truthy(node['$option?']("interactive"))) { + + fallback = ($truthy(node['$attr?']("fallback")) ? ("\""") : ("" + (node.$alt()) + "")); + img = "" + (fallback) + ""; + } else { + img = "\"""; + } + } else { + img = "\"""; + } } if ($truthy(node['$attr?']("link"))) { + img = "" + (img) + ""; + } class_attr_val = type; + if ($truthy((role = node.$role()))) { + class_attr_val = ($truthy(node['$attr?']("float")) ? ("" + (class_attr_val) + " " + (node.$attr("float")) + " " + (role)) : ("" + (class_attr_val) + " " + (role))); + } else if ($truthy(node['$attr?']("float"))) { + class_attr_val = "" + (class_attr_val) + " " + (node.$attr("float")); + } return "" + (img) + ""; + }); + + $def(self, '$convert_inline_indexterm', function $$convert_inline_indexterm(node) { + + if ($eqeq(node.$type(), "visible")) { + return node.$text() + } else { + return "" + } + }); + + $def(self, '$convert_inline_kbd', function $$convert_inline_kbd(node) { + var keys = nil; - for (i = 0, l = paths.length; i < l; i++) { - path = Opal.normalize(paths[i]); + if ($eqeq((keys = node.$attr("keys")).$size(), 1)) { + return "" + (keys['$[]'](0)) + "" + } else { + return "" + (keys.$join("+")) + "" + } + }); + + $def(self, '$convert_inline_menu', function $$convert_inline_menu(node) { + var caret = nil, submenu_joiner = nil, menu = nil, submenus = nil, menuitem = nil; - if (Opal.require_table[path]) { - continue; - } + + caret = ($truthy(node.$document()['$attr?']("icons", "font")) ? ("  ") : (" › ")); + submenu_joiner = "" + (caret) + ""; + menu = node.$attr("menu"); + if ($truthy((submenus = node.$attr("submenus"))['$empty?']())) { + if ($truthy((menuitem = node.$attr("menuitem")))) { + return "" + (menu) + "" + (caret) + "" + (menuitem) + "" + } else { + return "" + (menu) + "" + } + } else { + return "" + (menu) + "" + (caret) + "" + (submenus.$join(submenu_joiner)) + "" + (caret) + "" + (node.$attr("menuitem")) + "" + } }); + + $def(self, '$convert_inline_quoted', function $$convert_inline_quoted(node) { + var $a, $b, open = nil, close = nil, tag = nil, class_attr = nil; - Opal.loaded_features.push(path); - Opal.require_table[path] = true; - } - }; + + $b = $$('QUOTE_TAGS')['$[]'](node.$type()), $a = $to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])), (tag = ($a[2] == null ? nil : $a[2])); + if ($truthy(node.$id())) { + + class_attr = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : ("")); + if ($truthy(tag)) { + return "" + (open.$chop()) + " id=\"" + (node.$id()) + "\"" + (class_attr) + ">" + (node.$text()) + (close) + } else { + return "" + (open) + (node.$text()) + (close) + "" + } } else if ($truthy(node.$role())) { + if ($truthy(tag)) { + return "" + (open.$chop()) + " class=\"" + (node.$role()) + "\">" + (node.$text()) + (close) + } else { + return "" + (open) + (node.$text()) + (close) + "" + } + } else { + return "" + (open) + (node.$text()) + (close) + } }); + + $def(self, '$read_svg_contents', function $$read_svg_contents(node, target) { + var svg = nil, old_start_tag = nil, new_start_tag = nil, start_tag_match = nil; - Opal.load = function(path) { - path = Opal.normalize(path); + + if ($truthy((svg = node.$read_contents(target, $hash2(["start", "normalize", "label", "warn_if_empty"], {"start": node.$document().$attr("imagesdir"), "normalize": true, "label": "SVG", "warn_if_empty": true}))))) { + + if ($truthy(svg['$empty?']())) { + return nil + } if (!$truthy(svg['$start_with?']("");}); + if ($truthy(new_start_tag)) { + svg = "" + (new_start_tag) + (svg['$[]'](Opal.Range.$new(old_start_tag.$length(), -1, false))); + } } return svg; + }); + self.$private(); + + $def(self, '$append_boolean_attribute', function $$append_boolean_attribute(name, xml) { + + if ($truthy(xml)) { + return " " + (name) + "=\"" + (name) + "\"" + } else { + return " " + (name) + } + }); + + $def(self, '$append_link_constraint_attrs', function $$append_link_constraint_attrs(node, attrs) { + var rel = nil, window = nil; - var module = Opal.modules[path]; + + if (attrs == null) attrs = []; + if ($truthy(node['$option?']("nofollow"))) { + rel = "nofollow"; + } if ($truthy((window = node.$attributes()['$[]']("window")))) { + + attrs['$<<'](" target=\"" + (window) + "\""); + if (($eqeq(window, "_blank") || ($truthy(node['$option?']("noopener"))))) { + attrs['$<<'](($truthy(rel) ? (" rel=\"" + (rel) + " noopener\"") : (" rel=\"noopener\""))); + } } else if ($truthy(rel)) { + attrs['$<<'](" rel=\"" + (rel) + "\""); + } return attrs; + }, -2); + + $def(self, '$encode_attribute_value', function $$encode_attribute_value(val) { + + if ($truthy(val['$include?']("\""))) { + + return val.$gsub("\"", """); + } else { + return val + } + }); + + $def(self, '$generate_manname_section', function $$generate_manname_section(node) { + var manname_title = nil, next_section_title = nil, next_section = nil, manname_id_attr = nil, manname_id = nil; - if (module) { - module(Opal); - } - else { - var severity = Opal.config.missing_require_severity; - var message = 'cannot load such file -- ' + path; + + manname_title = node.$attr("manname-title", "Name"); + if (($truthy((next_section = node.$sections()['$[]'](0))) && ($eqeq((next_section_title = next_section.$title()), next_section_title.$upcase())))) { + manname_title = manname_title.$upcase(); + } manname_id_attr = ($truthy((manname_id = node.$attr("manname-id"))) ? (" id=\"" + (manname_id) + "\"") : ("")); + return "" + (manname_title) + "\n" + "
    \n" + "

    " + (node.$attr("mannames").$join(", ")) + " - " + (node.$attr("manpurpose")) + "

    \n" + "
    "; + }); + + $def(self, '$get_root_document', function $$get_root_document(node) { + + + while ($truthy((node = node.$document())['$nested?']())) { + node = node.$parent_document(); + } return node; + }); + + $def(self, '$method_missing', function $$method_missing(id, $a) { + var $post_args, args, $yield = $$method_missing.$$p || nil, self = this, name = nil; - if (severity === "error") { - if (Opal.LoadError) { - throw Opal.LoadError.$new(message) + $$method_missing.$$p = null; + + $post_args = $slice(arguments, 1); + args = $post_args; + if (($not((name = id.$to_s())['$start_with?']("convert_")) && ($truthy(self['$handles?'](name))))) { + + return $send(self, 'send', ["convert_" + (name)].concat($to_a(args))); } else { - throw message - } - } - else if (severity === "warning") { - console.warn('WARNING: LoadError: ' + message); - } - } + return $send2(self, $find_super(self, 'method_missing', $$method_missing, false, true), 'method_missing', [id].concat($to_a(args)), $yield) + } }, -2); + return $def(self, '$respond_to_missing?', function $Html5Converter_respond_to_missing$ques$21(id, $a) { + var self = this, $ret_or_1 = nil, name = nil; - return true; - }; + + $slice(arguments, 1); + if ($truthy(($ret_or_1 = (name = id.$to_s())['$start_with?']("convert_")['$!']()))) { + + return self['$handles?'](name); + } else { + return $ret_or_1 + } }, -2); + })($$('Converter'), $$$($$('Converter'), 'Base'), $nesting) + })($nesting[0], $nesting) +}; - Opal.require = function(path) { - path = Opal.normalize(path); +Opal.modules["asciidoctor/extensions"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $hash2 = Opal.hash2, $def = Opal.def, $send = Opal.send, $alias = Opal.alias, $slice = Opal.slice, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $rb_gt = Opal.rb_gt, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $to_a = Opal.to_a, $to_ary = Opal.to_ary, $const_set = Opal.const_set, $return_val = Opal.return_val, $send2 = Opal.send2, $find_super = Opal.find_super, $NilClass = Opal.NilClass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, $regexp = Opal.regexp, $Class = Opal.Class, $return_ivar = Opal.return_ivar, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - if (Opal.require_table[path]) { - return false; - } + Opal.add_stubs('[]=,config,const_defined?,singleton_class?,include,const_get,extend,enable_dsl,attr_reader,merge,class,update,raise,document,==,doctype,[],+,level,delete,>,casecmp,new,title=,sectname=,special=,fetch,numbered=,attr?,!,key?,special,numbered,id=,generate_id,title,update_attributes,tr,basename,create_block,assign_caption,===,parse_blocks,empty?,include?,sub_attributes,parse,each,define_method,unshift,shift,send,size,receiver,binding,define_singleton_method,instance_exec,to_proc,call,option,content_model,flatten,positional_attributes,default_attributes,respond_to?,to_s,partition,to_i,<<,compact,inspect,resolve_attributes,attr_accessor,to_set,contexts,match?,resolve_regexp,format,method,register,reset,values,groups,arity,activate,add_document_processor,tree_processor,tree_processors?,tree_processors,any?,select,add_syntax_processor,to_sym,instance_variable_get,kind,private,join,map,split,capitalize,instance_variable_set,resolve_args,singleton_class,process_block_given?,source_location,freeze,resolve_class,<,update_config,as_symbol,name,name=,pop,-,-@,next_auto_id,generate_name,each_with_object'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - return Opal.load(path); - }; + var $nesting = [self].concat($parent_nesting); + return (function($base, $parent_nesting) { + var self = $module($base, 'Extensions'); - // Strings - // ------- + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.encodings = Object.create(null); + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Processor'); - // Sets the encoding on a string, will treat string literals as frozen strings - // raising a FrozenError. - // @param str [String] the string on which the encoding should be set. - // @param name [String] the canonical name of the encoding - Opal.set_encoding = function(str, name) { - if (typeof str === 'string') - throw Opal.FrozenError.$new("can't modify frozen String"); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + + $proto.config = nil; + + (function(self, $parent_nesting) { + + + + $def(self, '$config', function $$config() { + var self = this, $ret_or_1 = nil; + if (self.config == null) self.config = nil; - var encoding = Opal.encodings[name]; + return (self.config = ($truthy(($ret_or_1 = self.config)) ? ($ret_or_1) : ($hash2([], {})))) + }); + + $def(self, '$option', function $$option(key, default_value) { + var $a, self = this; - if (encoding === str.encoding) { return str; } + return ($a = [key, default_value], $send(self.$config(), '[]=', $a), $a[$a.length - 1]) + }); + + $def(self, '$enable_dsl', function $$enable_dsl() { + var self = this; - str.encoding = encoding; + if ($truthy(self['$const_defined?']("DSL"))) { + if ($truthy(self['$singleton_class?']())) { + return self.$include(self.$const_get("DSL")) + } else { + return self.$extend(self.$const_get("DSL")) + } + } else { + return nil + } + }); + return $alias(self, "use_dsl", "enable_dsl"); + })(Opal.get_singleton_class(self)); + self.$attr_reader("config"); + + $def(self, '$initialize', function $$initialize(config) { + var self = this; - return str; - }; + + if (config == null) config = $hash2([], {}); + return (self.config = self.$class().$config().$merge(config)); + }, -1); + + $def(self, '$update_config', function $$update_config(config) { + var self = this; - // @returns a String object with the encoding set from a string literal - Opal.enc = function(str, name) { - var dup = new String(str); - Opal.set_encoding(dup, name); - dup.internal_encoding = dup.encoding; - return dup - } + return self.config.$update(config) + }); + + $def(self, '$process', function $$process($a) { + var self = this; + + $slice(arguments); + return self.$raise($$$('NotImplementedError'), "" + ($$('Processor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method"); + }, -1); + + $def(self, '$create_section', function $$create_section(parent, title, attrs, opts) { + var $a, $b, doc = nil, book = nil, doctype = nil, level = nil, $ret_or_1 = nil, style = nil, sectname = nil, special = nil, sect = nil, id = nil; - // Initialization - // -------------- - function $BasicObject() {}; - function $Object() {}; - function $Module() {}; - function $Class() {}; + + if (opts == null) opts = $hash2([], {}); + doc = parent.$document(); + book = (doctype = doc.$doctype())['$==']("book"); + level = ($truthy(($ret_or_1 = opts['$[]']("level"))) ? ($ret_or_1) : ($rb_plus(parent.$level(), 1))); + if ($truthy((style = attrs.$delete("style")))) { + if (($truthy(book) && ($eqeq(style, "abstract")))) { + $a = ["chapter", 1], (sectname = $a[0]), (level = $a[1]); + } else { + + $a = [style, true], (sectname = $a[0]), (special = $a[1]); + if ($eqeq(level, 0)) { + level = 1; + } } + } else if ($truthy(book)) { + sectname = ($eqeq(level, 0) ? ("part") : (($truthy($rb_gt(level, 1)) ? ("section") : ("chapter")))); + } else if (($eqeq(doctype, "manpage") && ($eqeq(title.$casecmp("synopsis"), 0)))) { + $a = ["synopsis", true], (sectname = $a[0]), (special = $a[1]); + } else { + sectname = "section"; + } sect = $$('Section').$new(parent, level); + $a = [title, sectname], ($b = [$a[0]], $send(sect, 'title=', $b), $b[$b.length - 1]), ($b = [$a[1]], $send(sect, 'sectname=', $b), $b[$b.length - 1]); + if ($truthy(special)) { + + sect['$special='](true); + if ($truthy(opts.$fetch("numbered", style['$==']("appendix")))) { + sect['$numbered='](true); + } else if (($not(opts['$key?']("numbered")) && ($truthy(doc['$attr?']("sectnums", "all"))))) { + sect['$numbered=']((($truthy(book) && ($eqeq(level, 1))) ? ("chapter") : (true))); + } } else if ($truthy($rb_gt(level, 0))) { + if ($truthy(opts.$fetch("numbered", doc['$attr?']("sectnums")))) { + sect['$numbered='](($truthy(sect.$special()) ? (($truthy(($ret_or_1 = parent.$numbered())) || ($ret_or_1))) : (true))); + } + } else if ($truthy(opts.$fetch("numbered", ($truthy(($ret_or_1 = book)) ? (doc['$attr?']("partnums")) : ($ret_or_1))))) { + sect['$numbered='](true); + } if ($eqeq((id = attrs['$[]']("id")), false)) { + attrs.$delete("id"); + } else { + sect['$id='](($a = ["id", ($truthy(($ret_or_1 = id)) ? ($ret_or_1) : (($truthy(doc['$attr?']("sectids")) ? ($$('Section').$generate_id(sect.$title(), doc)) : (nil))))], $send(attrs, '[]=', $a), $a[$a.length - 1])); + } sect.$update_attributes(attrs); + return sect; + }, -4); + + $def(self, '$create_block', function $$create_block(parent, context, source, attrs, opts) { + + + if (opts == null) opts = $hash2([], {}); + return $$('Block').$new(parent, context, $hash2(["source", "attributes"], {"source": source, "attributes": attrs}).$merge(opts)); + }, -5); + + $def(self, '$create_list', function $$create_list(parent, context, attrs) { + var list = nil; - Opal.BasicObject = BasicObject = Opal.allocate_class('BasicObject', null, $BasicObject); - Opal.Object = _Object = Opal.allocate_class('Object', Opal.BasicObject, $Object); - Opal.Module = Module = Opal.allocate_class('Module', Opal.Object, $Module); - Opal.Class = Class = Opal.allocate_class('Class', Opal.Module, $Class); + + if (attrs == null) attrs = nil; + list = $$('List').$new(parent, context); + if ($truthy(attrs)) { + list.$update_attributes(attrs); + } return list; + }, -3); + + $def(self, '$create_list_item', function $$create_list_item(parent, text) { + + + if (text == null) text = nil; + return $$('ListItem').$new(parent, text); + }, -2); + + $def(self, '$create_image_block', function $$create_image_block(parent, attrs, opts) { + var $a, self = this, target = nil, title = nil, block = nil; - $setPrototype(Opal.BasicObject, Opal.Class.$$prototype); - $setPrototype(Opal.Object, Opal.Class.$$prototype); - $setPrototype(Opal.Module, Opal.Class.$$prototype); - $setPrototype(Opal.Class, Opal.Class.$$prototype); + + if (opts == null) opts = $hash2([], {}); + if (!$truthy((target = attrs['$[]']("target")))) { + self.$raise($$$('ArgumentError'), "Unable to create an image block, target attribute is required"); + } if ($truthy((attrs['$[]']("alt")))) ; else { + attrs['$[]=']("alt", ($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attrs, '[]=', $a), $a[$a.length - 1])); + } title = ($truthy(attrs['$key?']("title")) ? (attrs.$delete("title")) : (nil)); + block = self.$create_block(parent, "image", nil, attrs, opts); + if ($truthy(title)) { + + block['$title='](title); + block.$assign_caption(attrs.$delete("caption"), "figure"); + } return block; + }, -3); + + $def(self, '$create_inline', function $$create_inline(parent, context, text, opts) { + + + if (opts == null) opts = $hash2([], {}); + return $$('Inline').$new(parent, context, text, ($eqeq(context, "quoted") ? ($hash2(["type"], {"type": "unquoted"}).$merge(opts)) : (opts))); + }, -4); + + $def(self, '$parse_content', function $$parse_content(parent, content, attributes) { + var reader = nil; - // BasicObject can reach itself, avoid const_set to skip the $$base_module logic - BasicObject.$$const["BasicObject"] = BasicObject; + + if (attributes == null) attributes = nil; + reader = ($eqeqeq($$('Reader'), content) ? (content) : ($$('Reader').$new(content))); + $$('Parser').$parse_blocks(reader, parent, attributes); + return parent; + }, -3); + + $def(self, '$parse_attributes', function $$parse_attributes(block, attrlist, opts) { + var $ret_or_1 = nil; - // Assign basic constants - Opal.const_set(_Object, "BasicObject", BasicObject); - Opal.const_set(_Object, "Object", _Object); - Opal.const_set(_Object, "Module", Module); - Opal.const_set(_Object, "Class", Class); + + if (opts == null) opts = $hash2([], {}); + if ($truthy(($truthy(attrlist) ? (attrlist['$empty?']()) : (true)))) { + return $hash2([], {}) + } if (($truthy(opts['$[]']("sub_attributes")) && ($truthy(attrlist['$include?']($$('ATTR_REF_HEAD')))))) { + attrlist = block.$sub_attributes(attrlist); + } return $$('AttributeList').$new(attrlist).$parse(($truthy(($ret_or_1 = opts['$[]']("positional_attributes"))) ? ($ret_or_1) : ([]))); + }, -3); + return $send([["create_paragraph", "create_block", "paragraph"], ["create_open_block", "create_block", "open"], ["create_example_block", "create_block", "example"], ["create_pass_block", "create_block", "pass"], ["create_listing_block", "create_block", "listing"], ["create_literal_block", "create_block", "literal"], ["create_anchor", "create_inline", "anchor"], ["create_inline_pass", "create_inline", "quoted"]], 'each', [], function $Processor$1(method_name, delegate_method_name, context){var self = $Processor$1.$$s == null ? this : $Processor$1.$$s; - // Fix booted classes to have correct .class value - BasicObject.$$class = Class; - _Object.$$class = Class; - Module.$$class = Class; - Class.$$class = Class; + + if (method_name == null) method_name = nil; + if (delegate_method_name == null) delegate_method_name = nil; + if (context == null) context = nil; + return $send(self, 'define_method', [method_name], function $$2($a){var $post_args, args, self = $$2.$$s == null ? this : $$2.$$s; - // Forward .toString() to #to_s - $defineProperty(_Object.$$prototype, 'toString', function() { - var to_s = this.$to_s(); - if (to_s.$$is_string && typeof(to_s) === 'object') { - // a string created using new String('string') - return to_s.valueOf(); - } else { - return to_s; - } - }); + + $post_args = $slice(arguments); + args = $post_args; + args.$unshift(args.$shift(), context); + return $send(self, 'send', [delegate_method_name].concat($to_a(args)));}, {$$arity: -1, $$s: self});}, {$$s: self}); + })($nesting[0], null, $nesting); + (function($base) { + var self = $module($base, 'ProcessorDsl'); - // Make Kernel#require immediately available as it's needed to require all the - // other corelib files. - $defineProperty(_Object.$$prototype, '$require', Opal.require); + + + + $def(self, '$option', function $$option(key, value) { + var $a, self = this; - // Add a short helper to navigate constants manually. - // @example - // Opal.$$.Regexp.$$.IGNORECASE - Opal.$$ = _Object.$$; + return ($a = [key, value], $send(self.$config(), '[]=', $a), $a[$a.length - 1]) + }); + + $def(self, '$process', function $$process($a) { + var block = $$process.$$p || nil, $post_args, args, $b, self = this, context = nil; + if (self.process_block == null) self.process_block = nil; - // Instantiate the main object - Opal.top = new _Object(); - Opal.top.$to_s = Opal.top.$inspect = function() { return 'main' }; + $$process.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if ((block !== nil)) { + + if (!$truthy(args['$empty?']())) { + self.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$size()) + ", expected 0)"); + } if (!($truthy(block.$binding()) && ($eqeq(self, block.$binding().$receiver())))) { + + context = self; + $send(block, 'define_singleton_method', ["call"], function $$3($b){var $post_args, m_args; + + $post_args = $slice(arguments); + m_args = $post_args; + return $send(context, 'instance_exec', $to_a(m_args), block.$to_proc());}, -1); + } return (self.process_block = block); + } else if ($truthy((($b = self['process_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) { + return $send(self.process_block, 'call', $to_a(args)) + } else { + return self.$raise($$$('NotImplementedError'), "" + (self.$class()) + " #" + ("process") + " method called before being registered") + } }, -1); + return $def(self, '$process_block_given?', function $ProcessorDsl_process_block_given$ques$4() { + var $a, self = this; - // Nil - function $NilClass() {}; - Opal.NilClass = Opal.allocate_class('NilClass', Opal.Object, $NilClass); - Opal.const_set(_Object, 'NilClass', Opal.NilClass); - nil = Opal.nil = new Opal.NilClass(); - nil.$$id = nil_id; - nil.call = nil.apply = function() { throw Opal.LocalJumpError.$new('no block given'); }; + return (($a = self['process_block'], $a != null && $a !== nil) ? 'instance-variable' : nil) + }); + })($nesting[0]); + (function($base, $parent_nesting) { + var self = $module($base, 'DocumentProcessorDsl'); - // Errors - Opal.breaker = new Error('unexpected break (old)'); - Opal.returner = new Error('unexpected return'); - TypeError.$$super = Error; -}).call(this); -Opal.loaded(["corelib/runtime.js"]); -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/helpers"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - Opal.add_stubs(['$new', '$class', '$===', '$respond_to?', '$raise', '$type_error', '$__send__', '$coerce_to', '$nil?', '$<=>', '$coerce_to!', '$!=', '$[]', '$upcase']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Opal'); + + self.$include($$('ProcessorDsl')); + return $def(self, '$prefer', function $$prefer() { + var self = this; - var $nesting = [self].concat($parent_nesting), $Opal_bridge$1, $Opal_type_error$2, $Opal_coerce_to$3, $Opal_coerce_to$excl$4, $Opal_coerce_to$ques$5, $Opal_try_convert$6, $Opal_compare$7, $Opal_destructure$8, $Opal_respond_to$ques$9, $Opal_inspect_obj$10, $Opal_instance_variable_name$excl$11, $Opal_class_variable_name$excl$12, $Opal_const_name$excl$13, $Opal_pristine$14; + return self.$option("position", ">>") + }); + })($nesting[0], $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'SyntaxProcessorDsl'); - - Opal.defs(self, '$bridge', $Opal_bridge$1 = function $$bridge(constructor, klass) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return Opal.bridge(constructor, klass); - }, $Opal_bridge$1.$$arity = 2); - Opal.defs(self, '$type_error', $Opal_type_error$2 = function $$type_error(object, type, method, coerced) { - var $a, self = this; + + self.$include($$('ProcessorDsl')); + + $def(self, '$named', function $$named(value) { + var self = this; - - - if (method == null) { - method = nil; - }; - - if (coerced == null) { - coerced = nil; - }; - if ($truthy(($truthy($a = method) ? coerced : $a))) { - return $$($nesting, 'TypeError').$new("" + "can't convert " + (object.$class()) + " into " + (type) + " (" + (object.$class()) + "#" + (method) + " gives " + (coerced.$class()) + ")") - } else { - return $$($nesting, 'TypeError').$new("" + "no implicit conversion of " + (object.$class()) + " into " + (type)) - }; - }, $Opal_type_error$2.$$arity = -3); - Opal.defs(self, '$coerce_to', $Opal_coerce_to$3 = function $$coerce_to(object, type, method) { - var self = this; + if ($eqeqeq($$('Processor'), self)) { + return (self.name = value) + } else { + return self.$option("name", value) + } + }); + + $def(self, '$content_model', function $$content_model(value) { + var self = this; - - if ($truthy(type['$==='](object))) { - return object}; - if ($truthy(object['$respond_to?'](method))) { - } else { - self.$raise(self.$type_error(object, type)) - }; - return object.$__send__(method); - }, $Opal_coerce_to$3.$$arity = 3); - Opal.defs(self, '$coerce_to!', $Opal_coerce_to$excl$4 = function(object, type, method) { - var self = this, coerced = nil; + return self.$option("content_model", value) + }); + $alias(self, "parse_content_as", "content_model"); + + $def(self, '$positional_attributes', function $$positional_attributes($a) { + var $post_args, value, self = this; - - coerced = self.$coerce_to(object, type, method); - if ($truthy(type['$==='](coerced))) { - } else { - self.$raise(self.$type_error(object, type, method, coerced)) - }; - return coerced; - }, $Opal_coerce_to$excl$4.$$arity = 3); - Opal.defs(self, '$coerce_to?', $Opal_coerce_to$ques$5 = function(object, type, method) { - var self = this, coerced = nil; + + $post_args = $slice(arguments); + value = $post_args; + return self.$option("positional_attrs", value.$flatten()); + }, -1); + $alias(self, "name_positional_attributes", "positional_attributes"); + $alias(self, "positional_attrs", "positional_attributes"); + + $def(self, '$default_attributes', function $$default_attributes(value) { + var self = this; - - if ($truthy(object['$respond_to?'](method))) { - } else { - return nil - }; - coerced = self.$coerce_to(object, type, method); - if ($truthy(coerced['$nil?']())) { - return nil}; - if ($truthy(type['$==='](coerced))) { - } else { - self.$raise(self.$type_error(object, type, method, coerced)) - }; - return coerced; - }, $Opal_coerce_to$ques$5.$$arity = 3); - Opal.defs(self, '$try_convert', $Opal_try_convert$6 = function $$try_convert(object, type, method) { - var self = this; + return self.$option("default_attrs", value) + }); + $alias(self, "default_attrs", "default_attributes"); + + $def(self, '$resolve_attributes', function $$resolve_attributes($a) { + var $post_args, args, $b, self = this, $ret_or_1 = nil, names = nil, defaults = nil; - - if ($truthy(type['$==='](object))) { - return object}; - if ($truthy(object['$respond_to?'](method))) { - return object.$__send__(method) - } else { - return nil - }; - }, $Opal_try_convert$6.$$arity = 3); - Opal.defs(self, '$compare', $Opal_compare$7 = function $$compare(a, b) { - var self = this, compare = nil; + + $post_args = $slice(arguments); + args = $post_args; + if (!$truthy($rb_gt(args.$size(), 1))) { + if ($truthy((args = args.$fetch(0, true))['$respond_to?']("to_sym"))) { + args = [args]; + } + } if ($eqeqeq(true, ($ret_or_1 = args))) { + + self.$option("positional_attrs", []); + return self.$option("default_attrs", $hash2([], {})); + } else if ($eqeqeq($$$('Array'), $ret_or_1)) { + + $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]); + $send(args, 'each', [], function $$5(arg){var $c, $d, name = nil, value = nil, idx = nil; - - compare = a['$<=>'](b); - if ($truthy(compare === nil)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (a.$class()) + " with " + (b.$class()) + " failed")}; - return compare; - }, $Opal_compare$7.$$arity = 2); - Opal.defs(self, '$destructure', $Opal_destructure$8 = function $$destructure(args) { - var self = this; + + if (arg == null) arg = nil; + if ($truthy((arg = arg.$to_s())['$include?']("="))) { + + $d = arg.$partition("="), $c = $to_ary($d), (name = ($c[0] == null ? nil : $c[0])), (($c[1] == null ? nil : $c[1])), (value = ($c[2] == null ? nil : $c[2])); + if ($truthy(name['$include?'](":"))) { + + $d = name.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])); + idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i())); + names['$[]='](idx, name); + } return ($c = [name, value], $send(defaults, '[]=', $c), $c[$c.length - 1]); + } else if ($truthy(arg['$include?'](":"))) { + + $d = arg.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])); + idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i())); + return ($c = [idx, name], $send(names, '[]=', $c), $c[$c.length - 1]); + } else { + return names['$<<'](arg) + }}); + self.$option("positional_attrs", names.$compact()); + return self.$option("default_attrs", defaults); + } else if ($eqeqeq($$$('Hash'), $ret_or_1)) { + + $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]); + $send(args, 'each', [], function $$6(key, val){var $c, $d, name = nil, idx = nil; - - if (args.length == 1) { - return args[0]; - } - else if (args.$$is_array) { - return args; - } - else { - var args_ary = new Array(args.length); - for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; } + + if (key == null) key = nil; + if (val == null) val = nil; + if ($truthy((name = key.$to_s())['$include?'](":"))) { + + $d = name.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])); + idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i())); + names['$[]='](idx, name); + } if ($truthy(val)) { + return ($c = [name, val], $send(defaults, '[]=', $c), $c[$c.length - 1]) + } else { + return nil + }}); + self.$option("positional_attrs", names.$compact()); + return self.$option("default_attrs", defaults); + } else { + return self.$raise($$$('ArgumentError'), "unsupported attributes specification for macro: " + (args.$inspect())) + } }, -1); + return $alias(self, "resolves_attributes", "resolve_attributes"); + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Preprocessor'); - return args_ary; - } - - }, $Opal_destructure$8.$$arity = 1); - Opal.defs(self, '$respond_to?', $Opal_respond_to$ques$9 = function(obj, method, include_all) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - - if (include_all == null) { - include_all = false; - }; - - if (obj == null || !obj.$$class) { - return false; - } - ; - return obj['$respond_to?'](method, include_all); - }, $Opal_respond_to$ques$9.$$arity = -3); - Opal.defs(self, '$inspect_obj', $Opal_inspect_obj$10 = function $$inspect_obj(obj) { - var self = this; + return $def(self, '$process', function $$process(document, reader) { + var self = this; - return Opal.inspect(obj); - }, $Opal_inspect_obj$10.$$arity = 1); - Opal.defs(self, '$instance_variable_name!', $Opal_instance_variable_name$excl$11 = function(name) { - var self = this; + return self.$raise($$$('NotImplementedError'), "" + ($$('Preprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }) + })($nesting[0], $$('Processor'), $nesting); + $const_set($$('Preprocessor'), 'DSL', $$('DocumentProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'TreeProcessor'); - - name = $$($nesting, 'Opal')['$coerce_to!'](name, $$($nesting, 'String'), "to_str"); - if ($truthy(/^@[a-zA-Z_][a-zA-Z0-9_]*?$/.test(name))) { - } else { - self.$raise($$($nesting, 'NameError').$new("" + "'" + (name) + "' is not allowed as an instance variable name", name)) - }; - return name; - }, $Opal_instance_variable_name$excl$11.$$arity = 1); - Opal.defs(self, '$class_variable_name!', $Opal_class_variable_name$excl$12 = function(name) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - name = $$($nesting, 'Opal')['$coerce_to!'](name, $$($nesting, 'String'), "to_str"); - if ($truthy(name.length < 3 || name.slice(0,2) !== '@@')) { - self.$raise($$($nesting, 'NameError').$new("" + "`" + (name) + "' is not allowed as a class variable name", name))}; - return name; - }, $Opal_class_variable_name$excl$12.$$arity = 1); - Opal.defs(self, '$const_name!', $Opal_const_name$excl$13 = function(const_name) { - var self = this; + return $def(self, '$process', function $$process(document) { + var self = this; - - const_name = $$($nesting, 'Opal')['$coerce_to!'](const_name, $$($nesting, 'String'), "to_str"); - if ($truthy(const_name['$[]'](0)['$!='](const_name['$[]'](0).$upcase()))) { - self.$raise($$($nesting, 'NameError'), "" + "wrong constant name " + (const_name))}; - return const_name; - }, $Opal_const_name$excl$13.$$arity = 1); - Opal.defs(self, '$pristine', $Opal_pristine$14 = function $$pristine(owner_class, $a) { - var $post_args, method_names, self = this; + return self.$raise($$$('NotImplementedError'), "" + ($$('TreeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }) + })($nesting[0], $$('Processor'), $nesting); + $const_set($$('TreeProcessor'), 'DSL', $$('DocumentProcessorDsl')); + $const_set($nesting[0], 'Treeprocessor', $$('TreeProcessor')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Postprocessor'); - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - method_names = $post_args;; - - var method_name, method; - for (var i = method_names.length - 1; i >= 0; i--) { - method_name = method_names[i]; - method = owner_class.$$prototype['$'+method_name]; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (method && !method.$$stub) { - method.$$pristine = true; - } - } - ; - return nil; - }, $Opal_pristine$14.$$arity = -2); - })($nesting[0], $nesting) -}; + return $def(self, '$process', function $$process(document, output) { + var self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/module"] = function(Opal) { - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send, $truthy = Opal.truthy, $lambda = Opal.lambda, $range = Opal.range, $hash2 = Opal.hash2; + return self.$raise($$$('NotImplementedError'), "" + ($$('Postprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }) + })($nesting[0], $$('Processor'), $nesting); + $const_set($$('Postprocessor'), 'DSL', $$('DocumentProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'IncludeProcessor'); - Opal.add_stubs(['$module_eval', '$to_proc', '$===', '$raise', '$equal?', '$<', '$>', '$nil?', '$attr_reader', '$attr_writer', '$class_variable_name!', '$new', '$const_name!', '$=~', '$inject', '$split', '$const_get', '$==', '$!~', '$start_with?', '$bind', '$call', '$class', '$append_features', '$included', '$name', '$cover?', '$size', '$merge', '$compile', '$proc', '$any?', '$prepend_features', '$prepended', '$to_s', '$__id__', '$constants', '$include?', '$copy_class_variables', '$copy_constants']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Module'); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - var $nesting = [self].concat($parent_nesting), $Module_allocate$1, $Module_initialize$2, $Module_$eq_eq_eq$3, $Module_$lt$4, $Module_$lt_eq$5, $Module_$gt$6, $Module_$gt_eq$7, $Module_$lt_eq_gt$8, $Module_alias_method$9, $Module_alias_native$10, $Module_ancestors$11, $Module_append_features$12, $Module_attr_accessor$13, $Module_attr_reader$14, $Module_attr_writer$15, $Module_autoload$16, $Module_class_variables$17, $Module_class_variable_get$18, $Module_class_variable_set$19, $Module_class_variable_defined$ques$20, $Module_remove_class_variable$21, $Module_constants$22, $Module_constants$23, $Module_nesting$24, $Module_const_defined$ques$25, $Module_const_get$26, $Module_const_missing$28, $Module_const_set$29, $Module_public_constant$30, $Module_define_method$31, $Module_remove_method$33, $Module_singleton_class$ques$34, $Module_include$35, $Module_included_modules$36, $Module_include$ques$37, $Module_instance_method$38, $Module_instance_methods$39, $Module_included$40, $Module_extended$41, $Module_extend_object$42, $Module_method_added$43, $Module_method_removed$44, $Module_method_undefined$45, $Module_module_eval$46, $Module_module_exec$48, $Module_method_defined$ques$49, $Module_module_function$50, $Module_name$51, $Module_prepend$52, $Module_prepend_features$53, $Module_prepended$54, $Module_remove_const$55, $Module_to_s$56, $Module_undef_method$57, $Module_instance_variables$58, $Module_dup$59, $Module_copy_class_variables$60, $Module_copy_constants$61; + + + $def(self, '$process', function $$process(document, reader, target, attributes) { + var self = this; - - Opal.defs(self, '$allocate', $Module_allocate$1 = function $$allocate() { - var self = this; + return self.$raise($$$('NotImplementedError'), "" + ($$('IncludeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }); + return $def(self, '$handles?', $return_val(true)); + })($nesting[0], $$('Processor'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'IncludeProcessorDsl'); - - var module = Opal.allocate_module(nil, function(){}); - // Link the prototype of Module subclasses - if (self !== Opal.Module) Object.setPrototypeOf(module, self.$$prototype); - return module; - - }, $Module_allocate$1.$$arity = 0); - - Opal.def(self, '$initialize', $Module_initialize$2 = function $$initialize() { - var $iter = $Module_initialize$2.$$p, block = $iter || nil, self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if ($iter) $Module_initialize$2.$$p = null; - - - if ($iter) $Module_initialize$2.$$p = null;; - if ((block !== nil)) { - return $send(self, 'module_eval', [], block.$to_proc()) - } else { - return nil - }; - }, $Module_initialize$2.$$arity = 0); - - Opal.def(self, '$===', $Module_$eq_eq_eq$3 = function(object) { - var self = this; + + self.$include($$('DocumentProcessorDsl')); + return $def(self, '$handles?', function $IncludeProcessorDsl_handles$ques$7($a) { + var block = $IncludeProcessorDsl_handles$ques$7.$$p || nil, $post_args, args, $b, self = this; + if (self.handles_block == null) self.handles_block = nil; - - if ($truthy(object == null)) { - return false}; - return Opal.is_a(object, self);; - }, $Module_$eq_eq_eq$3.$$arity = 1); - - Opal.def(self, '$<', $Module_$lt$4 = function(other) { - var self = this; + $IncludeProcessorDsl_handles$ques$7.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if ((block !== nil)) { + + if (!$truthy(args['$empty?']())) { + self.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$size()) + ", expected 0)"); + } return (self.handles_block = block); + } else if ($truthy((($b = self['handles_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) { + return self.handles_block.$call(args['$[]'](0)) + } else { + return true + } }, -1); + })($nesting[0], $nesting); + $const_set($$('IncludeProcessor'), 'DSL', $$('IncludeProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'DocinfoProcessor'); - - if ($truthy($$($nesting, 'Module')['$==='](other))) { - } else { - self.$raise($$($nesting, 'TypeError'), "compared with non class/module") - }; - - var working = self, - ancestors, - i, length; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - if (working === other) { - return false; - } + $proto.config = nil; + + + $def(self, '$initialize', function $$initialize(config) { + var $a; $$initialize.$$p || nil; var self = this, $ret_or_1 = nil; - for (i = 0, ancestors = Opal.ancestors(self), length = ancestors.length; i < length; i++) { - if (ancestors[i] === other) { - return true; - } - } + $$initialize.$$p = null; + + if (config == null) config = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null); + if ($truthy(($ret_or_1 = self.config['$[]']("location")))) { + return $ret_or_1 + } else { + return ($a = ["location", "head"], $send(self.config, '[]=', $a), $a[$a.length - 1]) + } }, -1); + return $def(self, '$process', function $$process(document) { + var self = this; - for (i = 0, ancestors = Opal.ancestors(other), length = ancestors.length; i < length; i++) { - if (ancestors[i] === self) { - return false; - } - } + return self.$raise($$$('NotImplementedError'), "" + ($$('DocinfoProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }); + })($nesting[0], $$('Processor'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'DocinfoProcessorDsl'); - return nil; - ; - }, $Module_$lt$4.$$arity = 1); - - Opal.def(self, '$<=', $Module_$lt_eq$5 = function(other) { - var $a, self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return ($truthy($a = self['$equal?'](other)) ? $a : $rb_lt(self, other)) - }, $Module_$lt_eq$5.$$arity = 1); - - Opal.def(self, '$>', $Module_$gt$6 = function(other) { - var self = this; + + self.$include($$('DocumentProcessorDsl')); + return $def(self, '$at_location', function $$at_location(value) { + var self = this; - - if ($truthy($$($nesting, 'Module')['$==='](other))) { - } else { - self.$raise($$($nesting, 'TypeError'), "compared with non class/module") - }; - return $rb_lt(other, self); - }, $Module_$gt$6.$$arity = 1); - - Opal.def(self, '$>=', $Module_$gt_eq$7 = function(other) { - var $a, self = this; + return self.$option("location", value) + }); + })($nesting[0], $nesting); + $const_set($$('DocinfoProcessor'), 'DSL', $$('DocinfoProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'BlockProcessor'); - return ($truthy($a = self['$equal?'](other)) ? $a : $rb_gt(self, other)) - }, $Module_$gt_eq$7.$$arity = 1); - - Opal.def(self, '$<=>', $Module_$lt_eq_gt$8 = function(other) { - var self = this, lt = nil; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - - - if (self === other) { - return 0; - } - ; - if ($truthy($$($nesting, 'Module')['$==='](other))) { - } else { - return nil - }; - lt = $rb_lt(self, other); - if ($truthy(lt['$nil?']())) { - return nil}; - if ($truthy(lt)) { - return -1 - } else { - return 1 - }; - }, $Module_$lt_eq_gt$8.$$arity = 1); - - Opal.def(self, '$alias_method', $Module_alias_method$9 = function $$alias_method(newname, oldname) { - var self = this; + $proto.config = nil; + + self.$attr_accessor("name"); + + $def(self, '$initialize', function $$initialize(name, config) { + var $a; $$initialize.$$p || nil; var self = this, $ret_or_1 = nil; - - Opal.alias(self, newname, oldname); - return self; - }, $Module_alias_method$9.$$arity = 2); - - Opal.def(self, '$alias_native', $Module_alias_native$10 = function $$alias_native(mid, jsid) { - var self = this; + $$initialize.$$p = null; + + if (name == null) name = nil; + if (config == null) config = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null); + self.name = ($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.config['$[]']("name"))); + if ($eqeqeq($NilClass, ($ret_or_1 = self.config['$[]']("contexts")))) { + if ($truthy((self.config['$[]']("contexts")))) ; else { + self.config['$[]=']("contexts", ["open", "paragraph"].$to_set()); + } + } else if ($eqeqeq($$$('Symbol'), $ret_or_1)) { + self.config['$[]=']("contexts", [self.config['$[]']("contexts")].$to_set()); + } else { + self.config['$[]=']("contexts", self.config['$[]']("contexts").$to_set()); + } if ($truthy(($ret_or_1 = self.config['$[]']("content_model")))) { + return $ret_or_1 + } else { + return ($a = ["content_model", "compound"], $send(self.config, '[]=', $a), $a[$a.length - 1]) + } }, -1); + return $def(self, '$process', function $$process(parent, reader, attributes) { + var self = this; - - - if (jsid == null) { - jsid = mid; - }; - Opal.alias_native(self, mid, jsid); - return self; - }, $Module_alias_native$10.$$arity = -2); - - Opal.def(self, '$ancestors', $Module_ancestors$11 = function $$ancestors() { - var self = this; + return self.$raise($$$('NotImplementedError'), "" + ($$('BlockProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }); + })($nesting[0], $$('Processor'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'BlockProcessorDsl'); - return Opal.ancestors(self); - }, $Module_ancestors$11.$$arity = 0); - - Opal.def(self, '$append_features', $Module_append_features$12 = function $$append_features(includer) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - Opal.append_features(self, includer); - return self; - }, $Module_append_features$12.$$arity = 1); - - Opal.def(self, '$attr_accessor', $Module_attr_accessor$13 = function $$attr_accessor($a) { - var $post_args, names, self = this; + + self.$include($$('SyntaxProcessorDsl')); + + $def(self, '$contexts', function $$contexts($a) { + var $post_args, value, self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - $send(self, 'attr_reader', Opal.to_a(names)); - return $send(self, 'attr_writer', Opal.to_a(names)); - }, $Module_attr_accessor$13.$$arity = -1); - Opal.alias(self, "attr", "attr_accessor"); - - Opal.def(self, '$attr_reader', $Module_attr_reader$14 = function $$attr_reader($a) { - var $post_args, names, self = this; + + $post_args = $slice(arguments); + value = $post_args; + return self.$option("contexts", value.$flatten().$to_set()); + }, -1); + $alias(self, "on_contexts", "contexts"); + $alias(self, "on_context", "contexts"); + return $alias(self, "bind_to", "contexts"); + })($nesting[0], $nesting); + $const_set($$('BlockProcessor'), 'DSL', $$('BlockProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'MacroProcessor'); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - - var proto = self.$$prototype; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - for (var i = names.length - 1; i >= 0; i--) { - var name = names[i], - id = '$' + name, - ivar = Opal.ivar(name); - - // the closure here is needed because name will change at the next - // cycle, I wish we could use let. - var body = (function(ivar) { - return function() { - if (this[ivar] == null) { - return nil; - } - else { - return this[ivar]; - } - }; - })(ivar); + $proto.config = nil; + + self.$attr_accessor("name"); + + $def(self, '$initialize', function $$initialize(name, config) { + var $a; $$initialize.$$p || nil; var self = this, $ret_or_1 = nil; - // initialize the instance variable as nil - Opal.defineProperty(proto, ivar, nil); + $$initialize.$$p = null; + + if (name == null) name = nil; + if (config == null) config = $hash2([], {}); + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null); + self.name = ($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.config['$[]']("name"))); + if ($truthy(($ret_or_1 = self.config['$[]']("content_model")))) { + return $ret_or_1 + } else { + return ($a = ["content_model", "attributes"], $send(self.config, '[]=', $a), $a[$a.length - 1]) + } }, -1); + return $def(self, '$process', function $$process(parent, target, attributes) { + var self = this; - body.$$parameters = []; - body.$$arity = 0; + return self.$raise($$$('NotImplementedError'), "" + ($$('MacroProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method") + }); + })($nesting[0], $$('Processor'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'MacroProcessorDsl'); - Opal.defn(self, id, body); - } - ; - return nil; - }, $Module_attr_reader$14.$$arity = -1); - - Opal.def(self, '$attr_writer', $Module_attr_writer$15 = function $$attr_writer($a) { - var $post_args, names, self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - - var proto = self.$$prototype; + + self.$include($$('SyntaxProcessorDsl')); + + $def(self, '$resolve_attributes', function $$resolve_attributes($a) { + var $post_args, args, $yield = $$resolve_attributes.$$p || nil, self = this; - for (var i = names.length - 1; i >= 0; i--) { - var name = names[i], - id = '$' + name + '=', - ivar = Opal.ivar(name); + $$resolve_attributes.$$p = null; + + $post_args = $slice(arguments); + args = $post_args; + if (($eqeq(args.$size(), 1) && ($not(args['$[]'](0))))) { + return self.$option("content_model", "text") + } else { + + $send2(self, $find_super(self, 'resolve_attributes', $$resolve_attributes, false, true), 'resolve_attributes', $to_a(args), $yield); + return self.$option("content_model", "attributes"); + } }, -1); + return $alias(self, "resolves_attributes", "resolve_attributes"); + })($nesting[0], $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'BlockMacroProcessor'); - // the closure here is needed because name will change at the next - // cycle, I wish we could use let. - var body = (function(ivar){ - return function(value) { - return this[ivar] = value; - } - })(ivar); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - body.$$parameters = [['req']]; - body.$$arity = 1; + $proto.name = nil; + return $def(self, '$name', function $$name() { + var self = this; - // initialize the instance variable as nil - Opal.defineProperty(proto, ivar, nil); + + if (!$truthy($$('MacroNameRx')['$match?'](self.name.$to_s()))) { + self.$raise($$$('ArgumentError'), "invalid name for block macro: " + (self.name)); + } return self.name; + }) + })($nesting[0], $$('MacroProcessor'), $nesting); + $const_set($$('BlockMacroProcessor'), 'DSL', $$('MacroProcessorDsl')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'InlineMacroProcessor'); - Opal.defn(self, id, body); - } - ; - return nil; - }, $Module_attr_writer$15.$$arity = -1); - - Opal.def(self, '$autoload', $Module_autoload$16 = function $$autoload(const$, path) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - - if (self.$$autoload == null) self.$$autoload = {}; - Opal.const_cache_version++; - self.$$autoload[const$] = path; - return nil; - - }, $Module_autoload$16.$$arity = 2); - - Opal.def(self, '$class_variables', $Module_class_variables$17 = function $$class_variables() { - var self = this; + $proto.config = $proto.name = nil; + + $class_variable_set($nesting[0], '@@rx_cache', $hash2([], {})); + + $def(self, '$regexp', function $$regexp() { + var $a, self = this, $ret_or_1 = nil; - return Object.keys(Opal.class_variables(self)); - }, $Module_class_variables$17.$$arity = 0); - - Opal.def(self, '$class_variable_get', $Module_class_variable_get$18 = function $$class_variable_get(name) { - var self = this; + if ($truthy(($ret_or_1 = self.config['$[]']("regexp")))) { + return $ret_or_1 + } else { + return ($a = ["regexp", self.$resolve_regexp(self.name.$to_s(), self.config['$[]']("format"))], $send(self.config, '[]=', $a), $a[$a.length - 1]) + } + }); + return $def(self, '$resolve_regexp', function $$resolve_regexp(name, format) { + var $a, self = this, $ret_or_1 = nil; - - name = $$($nesting, 'Opal')['$class_variable_name!'](name); - - var value = Opal.class_variables(self)[name]; - if (value == null) { - self.$raise($$($nesting, 'NameError').$new("" + "uninitialized class variable " + (name) + " in " + (self), name)) - } - return value; - ; - }, $Module_class_variable_get$18.$$arity = 1); - - Opal.def(self, '$class_variable_set', $Module_class_variable_set$19 = function $$class_variable_set(name, value) { - var self = this; + + if (!$truthy($$('MacroNameRx')['$match?'](name))) { + self.$raise($$$('ArgumentError'), "invalid name for inline macro: " + (name)); + } if ($truthy(($ret_or_1 = $class_variable_get($nesting[0], '@@rx_cache', false)['$[]']([name, format])))) { + return $ret_or_1 + } else { + return ($a = [[name, format], $regexp(["\\\\?", name, ":", ($eqeq(format, "short") ? ("(){0}") : ("(\\S+?)")), "\\[(|", $$('CC_ANY'), "*?[^\\\\])\\]"])], $send($class_variable_get($nesting[0], '@@rx_cache', false), '[]=', $a), $a[$a.length - 1]) + } }); + })($nesting[0], $$('MacroProcessor'), $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'InlineMacroProcessorDsl'); - - name = $$($nesting, 'Opal')['$class_variable_name!'](name); - return Opal.class_variable_set(self, name, value);; - }, $Module_class_variable_set$19.$$arity = 2); - - Opal.def(self, '$class_variable_defined?', $Module_class_variable_defined$ques$20 = function(name) { - var self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - name = $$($nesting, 'Opal')['$class_variable_name!'](name); - return Opal.class_variables(self).hasOwnProperty(name);; - }, $Module_class_variable_defined$ques$20.$$arity = 1); - - Opal.def(self, '$remove_class_variable', $Module_remove_class_variable$21 = function $$remove_class_variable(name) { - var self = this; + + self.$include($$('MacroProcessorDsl')); + + $def(self, '$format', function $$format(value) { + var self = this; - - name = $$($nesting, 'Opal')['$class_variable_name!'](name); - - if (Opal.hasOwnProperty.call(self.$$cvars, name)) { - var value = self.$$cvars[name]; - delete self.$$cvars[name]; - return value; - } else { - self.$raise($$($nesting, 'NameError'), "" + "cannot remove " + (name) + " for " + (self)) - } - ; - }, $Module_remove_class_variable$21.$$arity = 1); - - Opal.def(self, '$constants', $Module_constants$22 = function $$constants(inherit) { - var self = this; + return self.$option("format", value) + }); + $alias(self, "match_format", "format"); + $alias(self, "using_format", "format"); + return $def(self, '$match', function $$match(value) { + var self = this; - - - if (inherit == null) { - inherit = true; - }; - return Opal.constants(self, inherit);; - }, $Module_constants$22.$$arity = -1); - Opal.defs(self, '$constants', $Module_constants$23 = function $$constants(inherit) { - var self = this; + return self.$option("regexp", value) + }); + })($nesting[0], $nesting); + $const_set($$('InlineMacroProcessor'), 'DSL', $$('InlineMacroProcessorDsl')); + (function($base, $super) { + var self = $klass($base, $super, 'Extension'); + + + + self.$attr_reader("kind"); + self.$attr_reader("config"); + self.$attr_reader("instance"); + return $def(self, '$initialize', function $$initialize(kind, instance, config) { + var self = this; - - ; - - if (inherit == null) { - var nesting = (self.$$nesting || []).concat(Opal.Object), - constant, constants = {}, - i, ii; + + self.kind = kind; + self.instance = instance; + return (self.config = config); + }); + })($nesting[0], null); + (function($base, $super) { + var self = $klass($base, $super, 'ProcessorExtension'); - for(i = 0, ii = nesting.length; i < ii; i++) { - for (constant in nesting[i].$$const) { - constants[constant] = true; - } - } - return Object.keys(constants); - } else { - return Opal.constants(self, inherit) - } - ; - }, $Module_constants$23.$$arity = -1); - Opal.defs(self, '$nesting', $Module_nesting$24 = function $$nesting() { - var self = this; + + + self.$attr_reader("process_method"); + return $def(self, '$initialize', function $$initialize(kind, instance, process_method) { + $$initialize.$$p || nil; var self = this, $ret_or_1 = nil; - return self.$$nesting || []; - }, $Module_nesting$24.$$arity = 0); - - Opal.def(self, '$const_defined?', $Module_const_defined$ques$25 = function(name, inherit) { - var self = this; + $$initialize.$$p = null; + + if (process_method == null) process_method = nil; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [kind, instance, instance.$config()], null); + return (self.process_method = ($truthy(($ret_or_1 = process_method)) ? ($ret_or_1) : (instance.$method("process")))); + }, -3); + })($nesting[0], $$('Extension')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Group'); - - - if (inherit == null) { - inherit = true; - }; - name = $$($nesting, 'Opal')['$const_name!'](name); - if ($truthy(name['$=~']($$$($$($nesting, 'Opal'), 'CONST_NAME_REGEXP')))) { - } else { - self.$raise($$($nesting, 'NameError').$new("" + "wrong constant name " + (name), name)) - }; - - var module, modules = [self], module_constants, i, ii; + var $nesting = [self].concat($parent_nesting); - // Add up ancestors if inherit is true - if (inherit) { - modules = modules.concat(Opal.ancestors(self)); + + (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Add Object's ancestors if it's a module – modules have no ancestors otherwise - if (self.$$is_module) { - modules = modules.concat([Opal.Object]).concat(Opal.ancestors(Opal.Object)); - } - } + return $def(self, '$register', function $$register(name) { + var self = this; - for (i = 0, ii = modules.length; i < ii; i++) { - module = modules[i]; - if (module.$$const[name] != null) { - return true; - } - } + + if (name == null) name = nil; + return $$('Extensions').$register(name, self); + }, -1) + })(Opal.get_singleton_class(self), $nesting); + return $def(self, '$activate', function $$activate(registry) { + var self = this; - return false; - ; - }, $Module_const_defined$ques$25.$$arity = -2); - - Opal.def(self, '$const_get', $Module_const_get$26 = function $$const_get(name, inherit) { - var $$27, self = this; + return self.$raise($$$('NotImplementedError')) + }); + })($nesting[0], null, $nesting); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Registry'); - - - if (inherit == null) { - inherit = true; - }; - name = $$($nesting, 'Opal')['$const_name!'](name); - - if (name.indexOf('::') === 0 && name !== '::'){ - name = name.slice(2); - } - ; - if ($truthy(name.indexOf('::') != -1 && name != '::')) { - return $send(name.$split("::"), 'inject', [self], ($$27 = function(o, c){var self = $$27.$$s || this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.document = $proto.groups = $proto.preprocessor_extensions = $proto.tree_processor_extensions = $proto.postprocessor_extensions = $proto.include_processor_extensions = $proto.docinfo_processor_extensions = $proto.block_extensions = $proto.block_macro_extensions = $proto.inline_macro_extensions = nil; + self.$attr_reader("document"); + self.$attr_reader("groups"); + + $def(self, '$initialize', function $$initialize(groups) { + var self = this; + - if (o == null) { - o = nil; - }; + if (groups == null) groups = $hash2([], {}); + self.groups = groups; + self.$reset(); + self.preprocessor_extensions = (self.tree_processor_extensions = (self.postprocessor_extensions = (self.include_processor_extensions = (self.docinfo_processor_extensions = (self.block_extensions = (self.block_macro_extensions = (self.inline_macro_extensions = nil))))))); + return (self.document = nil); + }, -1); + + $def(self, '$activate', function $$activate(document) { + var self = this, ext_groups = nil; + - if (c == null) { - c = nil; - }; - return o.$const_get(c);}, $$27.$$s = self, $$27.$$arity = 2, $$27))}; - if ($truthy(name['$=~']($$$($$($nesting, 'Opal'), 'CONST_NAME_REGEXP')))) { - } else { - self.$raise($$($nesting, 'NameError').$new("" + "wrong constant name " + (name), name)) - }; - - if (inherit) { - return $$([self], name); - } else { - return Opal.const_get_local(self, name); - } - ; - }, $Module_const_get$26.$$arity = -2); - - Opal.def(self, '$const_missing', $Module_const_missing$28 = function $$const_missing(name) { - var self = this, full_const_name = nil; + if ($truthy(self.document)) { + self.$reset(); + } self.document = document; + if (!$truthy((ext_groups = $rb_plus($$('Extensions').$groups().$values(), self.groups.$values()))['$empty?']())) { + $send(ext_groups, 'each', [], function $$8(group){var self = $$8.$$s == null ? this : $$8.$$s, $ret_or_1 = nil; - - - if (self.$$autoload) { - var file = self.$$autoload[name]; + + if (group == null) group = nil; + if ($eqeqeq($$$('Proc'), ($ret_or_1 = group))) { + + switch (group.$arity()) { + case 0: + case -1: + return $send(self, 'instance_exec', [], group.$to_proc()) + case 1: + return group.$call(self) + default: + return nil + } + } else if ($eqeqeq($Class, $ret_or_1)) { + return group.$new().$activate(self) + } else { + return group.$activate(self) + }}, {$$s: self}); + } return self; + }); + + $def(self, '$preprocessor', function $$preprocessor($a) { + var block = $$preprocessor.$$p || nil, $post_args, args, self = this; - if (file) { - self.$require(file); + $$preprocessor.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_document_processor', ["preprocessor", args], block.$to_proc()); + }, -1); + + $def(self, '$preprocessors?', function $Registry_preprocessors$ques$9() { + var self = this; - return self.$const_get(name); - } - } - ; - full_const_name = (function() {if (self['$==']($$($nesting, 'Object'))) { - return name - } else { - return "" + (self) + "::" + (name) - }; return nil; })(); - return self.$raise($$($nesting, 'NameError').$new("" + "uninitialized constant " + (full_const_name), name)); - }, $Module_const_missing$28.$$arity = 1); - - Opal.def(self, '$const_set', $Module_const_set$29 = function $$const_set(name, value) { - var $a, self = this; + return self.preprocessor_extensions['$!']()['$!']() + }); + + $def(self, '$preprocessors', $return_ivar("preprocessor_extensions")); + + $def(self, '$tree_processor', function $$tree_processor($a) { + var block = $$tree_processor.$$p || nil, $post_args, args, self = this; - - name = $$($nesting, 'Opal')['$const_name!'](name); - if ($truthy(($truthy($a = name['$!~']($$$($$($nesting, 'Opal'), 'CONST_NAME_REGEXP'))) ? $a : name['$start_with?']("::")))) { - self.$raise($$($nesting, 'NameError').$new("" + "wrong constant name " + (name), name))}; - Opal.const_set(self, name, value); - return value; - }, $Module_const_set$29.$$arity = 2); - - Opal.def(self, '$public_constant', $Module_public_constant$30 = function $$public_constant(const_name) { - var self = this; + $$tree_processor.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_document_processor', ["tree_processor", args], block.$to_proc()); + }, -1); + + $def(self, '$tree_processors?', function $Registry_tree_processors$ques$10() { + var self = this; - return nil - }, $Module_public_constant$30.$$arity = 1); - - Opal.def(self, '$define_method', $Module_define_method$31 = function $$define_method(name, method) { - var $iter = $Module_define_method$31.$$p, block = $iter || nil, $a, $$32, self = this, $case = nil; + return self.tree_processor_extensions['$!']()['$!']() + }); + + $def(self, '$tree_processors', $return_ivar("tree_processor_extensions")); + $alias(self, "treeprocessor", "tree_processor"); + $alias(self, "treeprocessors?", "tree_processors?"); + $alias(self, "treeprocessors", "tree_processors"); + + $def(self, '$postprocessor', function $$postprocessor($a) { + var block = $$postprocessor.$$p || nil, $post_args, args, self = this; - if ($iter) $Module_define_method$31.$$p = null; - - - if ($iter) $Module_define_method$31.$$p = null;; - ; - if ($truthy(method === undefined && block === nil)) { - self.$raise($$($nesting, 'ArgumentError'), "tried to create a Proc object without a block")}; - block = ($truthy($a = block) ? $a : (function() {$case = method; - if ($$($nesting, 'Proc')['$===']($case)) {return method} - else if ($$($nesting, 'Method')['$===']($case)) {return method.$to_proc().$$unbound} - else if ($$($nesting, 'UnboundMethod')['$===']($case)) {return $lambda(($$32 = function($b){var self = $$32.$$s || this, $post_args, args, bound = nil; + $$postprocessor.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_document_processor', ["postprocessor", args], block.$to_proc()); + }, -1); + + $def(self, '$postprocessors?', function $Registry_postprocessors$ques$11() { + var self = this; - + return self.postprocessor_extensions['$!']()['$!']() + }); - $post_args = Opal.slice.call(arguments, 0, arguments.length); + $def(self, '$postprocessors', $return_ivar("postprocessor_extensions")); - args = $post_args;; - bound = method.$bind(self); - return $send(bound, 'call', Opal.to_a(args));}, $$32.$$s = self, $$32.$$arity = -1, $$32))} - else {return self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + (block.$class()) + " (expected Proc/Method)")}})()); - - var id = '$' + name; + $def(self, '$include_processor', function $$include_processor($a) { + var block = $$include_processor.$$p || nil, $post_args, args, self = this; - block.$$jsid = name; - block.$$s = null; - block.$$def = block; - block.$$define_meth = true; + $$include_processor.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_document_processor', ["include_processor", args], block.$to_proc()); + }, -1); + + $def(self, '$include_processors?', function $Registry_include_processors$ques$12() { + var self = this; - Opal.defn(self, id, block); + return self.include_processor_extensions['$!']()['$!']() + }); + + $def(self, '$include_processors', $return_ivar("include_processor_extensions")); + + $def(self, '$docinfo_processor', function $$docinfo_processor($a) { + var block = $$docinfo_processor.$$p || nil, $post_args, args, self = this; - return name; - ; - }, $Module_define_method$31.$$arity = -2); - - Opal.def(self, '$remove_method', $Module_remove_method$33 = function $$remove_method($a) { - var $post_args, names, self = this; + $$docinfo_processor.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_document_processor', ["docinfo_processor", args], block.$to_proc()); + }, -1); + + $def(self, '$docinfo_processors?', function $Registry_docinfo_processors$ques$13(location) { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - - for (var i = 0, length = names.length; i < length; i++) { - Opal.rdef(self, "$" + names[i]); - } - ; - return self; - }, $Module_remove_method$33.$$arity = -1); - - Opal.def(self, '$singleton_class?', $Module_singleton_class$ques$34 = function() { - var self = this; + + if (location == null) location = nil; + if ($truthy(self.docinfo_processor_extensions)) { + if ($truthy(location)) { + return $send(self.docinfo_processor_extensions, 'any?', [], function $$14(ext){ + + if (ext == null) ext = nil; + return ext.$config()['$[]']("location")['$=='](location);}) + } else { + return true + } + } else { + return false + } }, -1); + + $def(self, '$docinfo_processors', function $$docinfo_processors(location) { + var self = this; - return !!self.$$is_singleton; - }, $Module_singleton_class$ques$34.$$arity = 0); - - Opal.def(self, '$include', $Module_include$35 = function $$include($a) { - var $post_args, mods, self = this; + + if (location == null) location = nil; + if ($truthy(self.docinfo_processor_extensions)) { + if ($truthy(location)) { + return $send(self.docinfo_processor_extensions, 'select', [], function $$15(ext){ + + if (ext == null) ext = nil; + return ext.$config()['$[]']("location")['$=='](location);}) + } else { + return self.docinfo_processor_extensions + } + } else { + return nil + } }, -1); + + $def(self, '$block', function $$block($a) { + var block = $$block.$$p || nil, $post_args, args, self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - mods = $post_args;; - - for (var i = mods.length - 1; i >= 0; i--) { - var mod = mods[i]; + $$block.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_syntax_processor', ["block", args], block.$to_proc()); + }, -1); + + $def(self, '$blocks?', function $Registry_blocks$ques$16() { + var self = this; - if (!mod.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + ((mod).$class()) + " (expected Module)"); - } + return self.block_extensions['$!']()['$!']() + }); + + $def(self, '$registered_for_block?', function $Registry_registered_for_block$ques$17(name, context) { + var self = this, ext = nil; - (mod).$append_features(self); - (mod).$included(self); - } - ; - return self; - }, $Module_include$35.$$arity = -1); - - Opal.def(self, '$included_modules', $Module_included_modules$36 = function $$included_modules() { - var self = this; + if ($truthy((ext = self.block_extensions['$[]'](name.$to_sym())))) { + if ($truthy(ext.$config()['$[]']("contexts")['$include?'](context))) { + return ext + } else { + return false + } + } else { + return false + } + }); + + $def(self, '$find_block_extension', function $$find_block_extension(name) { + var self = this; - return Opal.included_modules(self); - }, $Module_included_modules$36.$$arity = 0); - - Opal.def(self, '$include?', $Module_include$ques$37 = function(mod) { - var self = this; + return self.block_extensions['$[]'](name.$to_sym()) + }); + + $def(self, '$block_macro', function $$block_macro($a) { + var block = $$block_macro.$$p || nil, $post_args, args, self = this; - - if (!mod.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + ((mod).$class()) + " (expected Module)"); - } + $$block_macro.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_syntax_processor', ["block_macro", args], block.$to_proc()); + }, -1); + + $def(self, '$block_macros?', function $Registry_block_macros$ques$18() { + var self = this; - var i, ii, mod2, ancestors = Opal.ancestors(self); + return self.block_macro_extensions['$!']()['$!']() + }); + + $def(self, '$registered_for_block_macro?', function $Registry_registered_for_block_macro$ques$19(name) { + var self = this, ext = nil; - for (i = 0, ii = ancestors.length; i < ii; i++) { - mod2 = ancestors[i]; - if (mod2 === mod && mod2 !== self) { - return true; - } - } + if ($truthy((ext = self.block_macro_extensions['$[]'](name.$to_sym())))) { + return ext + } else { + return false + } + }); + + $def(self, '$find_block_macro_extension', function $$find_block_macro_extension(name) { + var self = this; - return false; - - }, $Module_include$ques$37.$$arity = 1); - - Opal.def(self, '$instance_method', $Module_instance_method$38 = function $$instance_method(name) { - var self = this; + return self.block_macro_extensions['$[]'](name.$to_sym()) + }); + + $def(self, '$inline_macro', function $$inline_macro($a) { + var block = $$inline_macro.$$p || nil, $post_args, args, self = this; - - var meth = self.$$prototype['$' + name]; + $$inline_macro.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'add_syntax_processor', ["inline_macro", args], block.$to_proc()); + }, -1); + + $def(self, '$inline_macros?', function $Registry_inline_macros$ques$20() { + var self = this; - if (!meth || meth.$$stub) { - self.$raise($$($nesting, 'NameError').$new("" + "undefined method `" + (name) + "' for class `" + (self.$name()) + "'", name)); - } + return self.inline_macro_extensions['$!']()['$!']() + }); + + $def(self, '$registered_for_inline_macro?', function $Registry_registered_for_inline_macro$ques$21(name) { + var self = this, ext = nil; - return $$($nesting, 'UnboundMethod').$new(self, meth.$$owner || self, meth, name); - - }, $Module_instance_method$38.$$arity = 1); - - Opal.def(self, '$instance_methods', $Module_instance_methods$39 = function $$instance_methods(include_super) { - var self = this; + if ($truthy((ext = self.inline_macro_extensions['$[]'](name.$to_sym())))) { + return ext + } else { + return false + } + }); + + $def(self, '$find_inline_macro_extension', function $$find_inline_macro_extension(name) { + var self = this; - - - if (include_super == null) { - include_super = true; - }; - - if ($truthy(include_super)) { - return Opal.instance_methods(self); - } else { - return Opal.own_instance_methods(self); - } - ; - }, $Module_instance_methods$39.$$arity = -1); - - Opal.def(self, '$included', $Module_included$40 = function $$included(mod) { - var self = this; + return self.inline_macro_extensions['$[]'](name.$to_sym()) + }); + + $def(self, '$inline_macros', function $$inline_macros() { + var self = this; - return nil - }, $Module_included$40.$$arity = 1); - - Opal.def(self, '$extended', $Module_extended$41 = function $$extended(mod) { - var self = this; + return self.inline_macro_extensions.$values() + }); + + $def(self, '$prefer', function $$prefer($a) { + var block = $$prefer.$$p || nil, $post_args, args, self = this, extension = nil, arg0 = nil, extensions_store = nil; - return nil - }, $Module_extended$41.$$arity = 1); - - Opal.def(self, '$extend_object', $Module_extend_object$42 = function $$extend_object(object) { - var self = this; + $$prefer.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + extension = ($eqeqeq($$('ProcessorExtension'), (arg0 = args.$shift())) ? (arg0) : ($send(self, 'send', [arg0].concat($to_a(args)), block.$to_proc()))); + extensions_store = self.$instance_variable_get(((("@") + (extension.$kind())) + "_extensions").$to_sym()); + extensions_store.$unshift(extensions_store.$delete(extension)); + return extension; + }, -1); + self.$private(); + + $def(self, '$add_document_processor', function $$add_document_processor(kind, args) { + var block = $$add_document_processor.$$p || nil, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, $ret_or_1 = nil, config = nil, processor = nil, extension = nil, processor_class = nil, processor_instance = nil; - return nil - }, $Module_extend_object$42.$$arity = 1); - - Opal.def(self, '$method_added', $Module_method_added$43 = function $$method_added($a) { - var $post_args, self = this; + $$add_document_processor.$$p = null; + kind_name = kind.$to_s().$tr("_", " "); + kind_class_symbol = $send(kind_name.$split(), 'map', [], function $$22(it){ + + if (it == null) it = nil; + return it.$capitalize();}).$join().$to_sym(); + kind_class = $$('Extensions').$const_get(kind_class_symbol, false); + kind_java_class = ($truthy((($$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil)) ? ($$$($$$('AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false)) : (nil)); + kind_store = ($truthy(($ret_or_1 = self.$instance_variable_get(((("@") + (kind)) + "_extensions").$to_sym()))) ? ($ret_or_1) : (self.$instance_variable_set(((("@") + (kind)) + "_extensions").$to_sym(), []))); + if ((block !== nil)) { + + config = self.$resolve_args(args, 1); + (processor = kind_class.$new(config)).$singleton_class().$enable_dsl(); + if ($eqeq(block.$arity(), 0)) { + $send(processor, 'instance_exec', [], block.$to_proc()); + } else { + Opal.yield1(block, processor); + } if (!$truthy(processor['$process_block_given?']())) { + self.$raise($$$('NoMethodError'), "No block specified to process " + (kind_name) + " extension at " + (block.$source_location().$join(":"))); + } processor.$freeze(); + extension = $$('ProcessorExtension').$new(kind, processor); + } else { + + $c = self.$resolve_args(args, 2), $b = $to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])); + if ($truthy((processor_class = $$('Helpers').$resolve_class(processor)))) { + + if (!($truthy($rb_lt(processor_class, kind_class)) || (($truthy(kind_java_class) && ($truthy($rb_lt(processor_class, kind_java_class))))))) { + self.$raise($$$('ArgumentError'), "Invalid type for " + (kind_name) + " extension: " + (processor)); + } processor_instance = processor_class.$new(config); + processor_instance.$freeze(); + extension = $$('ProcessorExtension').$new(kind, processor_instance); + } else if (($eqeqeq(kind_class, processor) || (($truthy(kind_java_class) && ($eqeqeq(kind_java_class, processor)))))) { + + processor.$update_config(config); + processor.$freeze(); + extension = $$('ProcessorExtension').$new(kind, processor); + } else { + self.$raise($$$('ArgumentError'), "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args)); + } } if ($eqeq(extension.$config()['$[]']("position"), ">>")) { + + kind_store.$unshift(extension); + } else { + + kind_store['$<<'](extension); + } return extension; + }); + + $def(self, '$add_syntax_processor', function $$add_syntax_processor(kind, args) { + var block = $$add_syntax_processor.$$p || nil, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, $ret_or_1 = nil, name = nil, config = nil, processor = nil, processor_class = nil, processor_instance = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $Module_method_added$43.$$arity = -1); - - Opal.def(self, '$method_removed', $Module_method_removed$44 = function $$method_removed($a) { - var $post_args, self = this; + $$add_syntax_processor.$$p = null; + kind_name = kind.$to_s().$tr("_", " "); + kind_class_symbol = $send(kind_name.$split(), 'map', [], function $$23(it){ + + if (it == null) it = nil; + return it.$capitalize();})['$<<']("Processor").$join().$to_sym(); + kind_class = $$('Extensions').$const_get(kind_class_symbol, false); + kind_java_class = ($truthy((($$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil)) ? ($$$($$$('AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false)) : (nil)); + kind_store = ($truthy(($ret_or_1 = self.$instance_variable_get(((("@") + (kind)) + "_extensions").$to_sym()))) ? ($ret_or_1) : (self.$instance_variable_set(((("@") + (kind)) + "_extensions").$to_sym(), $hash2([], {})))); + if ((block !== nil)) { + + $c = self.$resolve_args(args, 2), $b = $to_ary($c), (name = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])); + (processor = kind_class.$new(self.$as_symbol(name), config)).$singleton_class().$enable_dsl(); + if ($eqeq(block.$arity(), 0)) { + $send(processor, 'instance_exec', [], block.$to_proc()); + } else { + Opal.yield1(block, processor); + } if (!$truthy((name = self.$as_symbol(processor.$name())))) { + self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension at " + (block.$source_location().$join(":"))); + } if (!$truthy(processor['$process_block_given?']())) { + self.$raise($$$('NoMethodError'), "No block specified to process " + (kind_name) + " extension at " + (block.$source_location().$join(":"))); + } processor.$freeze(); + return ($b = [name, $$('ProcessorExtension').$new(kind, processor)], $send(kind_store, '[]=', $b), $b[$b.length - 1]); + } else { + + $c = self.$resolve_args(args, 3), $b = $to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (name = ($b[1] == null ? nil : $b[1])), (config = ($b[2] == null ? nil : $b[2])); + if ($truthy((processor_class = $$('Helpers').$resolve_class(processor)))) { + + if (!($truthy($rb_lt(processor_class, kind_class)) || (($truthy(kind_java_class) && ($truthy($rb_lt(processor_class, kind_java_class))))))) { + self.$raise($$$('ArgumentError'), "Class specified for " + (kind_name) + " extension does not inherit from " + (kind_class) + ": " + (processor)); + } processor_instance = processor_class.$new(self.$as_symbol(name), config); + if (!$truthy((name = self.$as_symbol(processor_instance.$name())))) { + self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension: " + (processor)); + } processor_instance.$freeze(); + return ($b = [name, $$('ProcessorExtension').$new(kind, processor_instance)], $send(kind_store, '[]=', $b), $b[$b.length - 1]); + } else if (($eqeqeq(kind_class, processor) || (($truthy(kind_java_class) && ($eqeqeq(kind_java_class, processor)))))) { + + processor.$update_config(config); + if (!$truthy((name = ($truthy(name) ? (($b = [self.$as_symbol(name)], $send(processor, 'name=', $b), $b[$b.length - 1])) : (self.$as_symbol(processor.$name())))))) { + self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension: " + (processor)); + } processor.$freeze(); + return ($b = [name, $$('ProcessorExtension').$new(kind, processor)], $send(kind_store, '[]=', $b), $b[$b.length - 1]); + } else { + return self.$raise($$$('ArgumentError'), "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args)) + } } }); + + $def(self, '$reset', function $$reset() { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $Module_method_removed$44.$$arity = -1); - - Opal.def(self, '$method_undefined', $Module_method_undefined$45 = function $$method_undefined($a) { - var $post_args, self = this; + + self.preprocessor_extensions = (self.tree_processor_extensions = (self.postprocessor_extensions = (self.include_processor_extensions = (self.docinfo_processor_extensions = (self.block_extensions = (self.block_macro_extensions = (self.inline_macro_extensions = nil))))))); + return (self.document = nil); + }); + + $def(self, '$resolve_args', function $$resolve_args(args, expect) { + var opts = nil, missing = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $Module_method_undefined$45.$$arity = -1); - - Opal.def(self, '$module_eval', $Module_module_eval$46 = function $$module_eval($a) { - var $iter = $Module_module_eval$46.$$p, block = $iter || nil, $post_args, args, $b, $$47, self = this, string = nil, file = nil, _lineno = nil, default_eval_options = nil, compiling_options = nil, compiled = nil; + + opts = ($eqeqeq($$$('Hash'), args['$[]'](-1)) ? (args.$pop()) : ($hash2([], {}))); + if ($eqeq(expect, 1)) { + return opts + } if ($truthy($rb_gt((missing = $rb_minus($rb_minus(expect, 1), args.$size())), 0))) { + args = $rb_plus(args, $$$('Array').$new(missing)); + } else if ($truthy($rb_lt(missing, 0))) { + args.$pop(missing['$-@']()); + } args['$<<'](opts); + return args; + }); + return $def(self, '$as_symbol', function $$as_symbol(name) { + + if ($truthy(name)) { + return name.$to_sym() + } else { + return nil + } + }); + })($nesting[0], null, $nesting); + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if ($iter) $Module_module_eval$46.$$p = null; - - - if ($iter) $Module_module_eval$46.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(($truthy($b = block['$nil?']()) ? !!Opal.compile : $b))) { - if ($truthy($range(1, 3, false)['$cover?'](args.$size()))) { - } else { - $$($nesting, 'Kernel').$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (0 for 1..3)") - }; - $b = [].concat(Opal.to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (_lineno = ($b[2] == null ? nil : $b[2])), $b; - default_eval_options = $hash2(["file", "eval"], {"file": ($truthy($b = file) ? $b : "(eval)"), "eval": true}); - compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options); - compiled = $$($nesting, 'Opal').$compile(string, compiling_options); - block = $send($$($nesting, 'Kernel'), 'proc', [], ($$47 = function(){var self = $$47.$$s || this; + + $def(self, '$generate_name', function $$generate_name() { + var self = this; + return "extgrp" + (self.$next_auto_id()) + }); - return (function(self) { - return eval(compiled); - })(self) - }, $$47.$$s = self, $$47.$$arity = 0, $$47)); - } else if ($truthy(args['$any?']())) { - $$($nesting, 'Kernel').$raise($$($nesting, 'ArgumentError'), "" + ("" + "wrong number of arguments (" + (args.$size()) + " for 0)") + "\n\n NOTE:If you want to enable passing a String argument please add \"require 'opal-parser'\" to your script\n")}; - - var old = block.$$s, - result; + $def(self, '$next_auto_id', function $$next_auto_id() { + var self = this, $ret_or_1 = nil; + if (self.auto_id == null) self.auto_id = nil; - block.$$s = null; - result = block.apply(self, [self]); - block.$$s = old; + + self.auto_id = ($truthy(($ret_or_1 = self.auto_id)) ? ($ret_or_1) : (-1)); + return (self.auto_id = $rb_plus(self.auto_id, 1)); + }); + + $def(self, '$groups', function $$groups() { + var self = this, $ret_or_1 = nil; + if (self.groups == null) self.groups = nil; - return result; - ; - }, $Module_module_eval$46.$$arity = -1); - Opal.alias(self, "class_eval", "module_eval"); - - Opal.def(self, '$module_exec', $Module_module_exec$48 = function $$module_exec($a) { - var $iter = $Module_module_exec$48.$$p, block = $iter || nil, $post_args, args, self = this; + return (self.groups = ($truthy(($ret_or_1 = self.groups)) ? ($ret_or_1) : ($hash2([], {})))) + }); + + $def(self, '$create', function $$create(name) { + var block = $$create.$$p || nil, self = this, $ret_or_1 = nil; - if ($iter) $Module_module_exec$48.$$p = null; - - - if ($iter) $Module_module_exec$48.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - if (block === nil) { - self.$raise($$($nesting, 'LocalJumpError'), "no block given") - } + $$create.$$p = null; + if (name == null) name = nil; + if ((block !== nil)) { + return $$('Registry').$new($hash(($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.$generate_name())), block)) + } else { + return $$('Registry').$new() + } }, -1); + + $def(self, '$register', function $$register($a) { + var block = $$register.$$p || nil, $post_args, args, $b, self = this, argc = nil, resolved_group = nil, group = nil, $ret_or_1 = nil, name = nil; - var block_self = block.$$s, result; + $$register.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + argc = args.$size(); + if ((block !== nil)) { + resolved_group = block; + } else if ($truthy((group = args.$pop()))) { + resolved_group = ($truthy(($ret_or_1 = $$('Helpers').$resolve_class(group))) ? ($ret_or_1) : (group)); + } else { + self.$raise($$$('ArgumentError'), "Extension group to register not specified"); + } name = ($truthy(($ret_or_1 = args.$pop())) ? ($ret_or_1) : (self.$generate_name())); + if (!$truthy(args['$empty?']())) { + self.$raise($$$('ArgumentError'), "Wrong number of arguments (" + (argc) + " for 1..2)"); + } return ($b = [name.$to_sym(), resolved_group], $send(self.$groups(), '[]=', $b), $b[$b.length - 1]); + }, -1); + + $def(self, '$unregister_all', function $$unregister_all() { + var self = this; - block.$$s = null; - result = block.apply(self, args); - block.$$s = block_self; + + self.groups = $hash2([], {}); + return nil; + }); + return $def(self, '$unregister', function $$unregister($a) { + var $post_args, names, self = this; - return result; - ; - }, $Module_module_exec$48.$$arity = -1); - Opal.alias(self, "class_exec", "module_exec"); - - Opal.def(self, '$method_defined?', $Module_method_defined$ques$49 = function(method) { - var self = this; + + $post_args = $slice(arguments); + names = $post_args; + $send(names, 'each_with_object', [self.$groups()], function $$24(group, catalog){ + + if (group == null) group = nil; + if (catalog == null) catalog = nil; + return catalog.$delete(group.$to_sym());}); + return nil; + }, -1); + })(Opal.get_singleton_class(self), $nesting); + })($nesting[0], $nesting) + })($nesting[0], $nesting); +}; - - var body = self.$$prototype['$' + method]; - return (!!body) && !body.$$stub; - - }, $Module_method_defined$ques$49.$$arity = 1); - - Opal.def(self, '$module_function', $Module_module_function$50 = function $$module_function($a) { - var $post_args, methods, self = this; +Opal.modules["asciidoctor/js/asciidoctor_ext/stylesheet"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('rstrip,read,join'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); + + var $nesting = [self].concat($parent_nesting); + + return (function($base, $super) { + var self = $klass($base, $super, 'Stylesheets'); + + var $proto = self.$$prototype; + + $proto.primary_stylesheet_data = nil; + return $def(self, '$primary_stylesheet_data', function $$primary_stylesheet_data() { + var self = this, $ret_or_1 = nil; + + return (self.primary_stylesheet_data = ($truthy(($ret_or_1 = self.primary_stylesheet_data)) ? ($ret_or_1) : ($$$('IO').$read($$$('File').$join("css", "asciidoctor.css")).$rstrip()))) + }) + })($nesting[0], null) + })($nesting[0], $nesting) +}; + +Opal.modules["asciidoctor/js/asciidoctor_ext/document"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $nesting = []; Opal.nil; + + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + return (function($base, $super) { + var self = $klass($base, $super, 'Document'); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - methods = $post_args;; - - if (methods.length === 0) { - self.$$module_function = true; - } - else { - for (var i = 0, length = methods.length; i < length; i++) { - var meth = methods[i], - id = '$' + meth, - func = self.$$prototype[id]; + return $def(self, '$fill_datetime_attributes', function $$fill_datetime_attributes(attrs, input_mtime) { + + + var $truthy = Opal.truthy; + var $falsy = Opal.falsy; + var nil = Opal.nil; + var utc_offset; + var source_date_epoch; + var localdate; + var localyear; + var localtime; + var localdatetime; + var docdate; + var doctime; - Opal.defs(self, id, func); + var getYear = function (time, utc_offset) { + return utc_offset === 0 ? time.getUTCFullYear() : time.getFullYear() + }; + var getMonth = function (time, utc_offset) { + return utc_offset === 0 ? time.getUTCMonth() : time.getMonth() + }; + var getDay = function (time, utc_offset) { + return utc_offset === 0 ? time.getUTCDate() : time.getDate() + }; + var getHours = function (time, utc_offset) { + return utc_offset === 0 ? time.getUTCHours() : time.getHours() + }; + + var now = new Date(); + // See https://reproducible-builds.org/specs/source-date-epoch/ + if (Opal.const_get_qualified('::', 'ENV')['$key?']('SOURCE_DATE_EPOCH')) { + now.setTime(parseInt(Opal.const_get_qualified('::', 'ENV')['$[]']('SOURCE_DATE_EPOCH')) * 1000); + source_date_epoch = now; + utc_offset = 0; // utc + } else { + utc_offset = -now.getTimezoneOffset() / 60; // local date + } + // localdate and localyear + if ($truthy((localdate = attrs['$[]']('localdate')))) { + if ($falsy(localyear = attrs['$[]']('localyear'))) { + localyear = localdate.indexOf('-') === 4 ? localdate.substring(0, 4) : nil; + attrs['$[]=']('localyear', localyear); + } + } else { + var now_year = getYear(now, utc_offset).toString(); + var now_month = ('0' + (getMonth(now, utc_offset) + 1)).slice(-2); + var now_day = ('0' + getDay(now, utc_offset)).slice(-2); + localdate = now_year + '-' + now_month + '-' + now_day; + attrs['$[]=']('localdate', localdate); + localyear = now_year; + attrs['$[]=']('localyear', now_year); + } + // localtime + if ($falsy((localtime = attrs['$[]']('localtime')))) { + var hours = ('0' + (getHours(now, utc_offset))).slice(-2); + var minutes = ('0' + (now.getMinutes())).slice(-2); + var seconds = ('0' + (now.getSeconds())).slice(-2); + var utc_offset_format; + if (utc_offset === 0) { + utc_offset_format = 'UTC'; + } else if (utc_offset > 0) { + utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5); + } else { + utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5); } + localtime = hours + ':' + minutes + ':' + seconds + ' ' + utc_offset_format; + attrs['$[]=']('localtime', localtime); } - - return self; - ; - }, $Module_module_function$50.$$arity = -1); - - Opal.def(self, '$name', $Module_name$51 = function $$name() { - var self = this; - - - if (self.$$full_name) { - return self.$$full_name; + // localdatetime + if ($falsy((localdatetime = attrs['$[]']('localdatetime')))) { + localdatetime = localdate + ' ' + localtime; + attrs['$[]=']('localdatetime', localdatetime); } - var result = [], base = self; - - while (base) { - // Give up if any of the ancestors is unnamed - if (base.$$name === nil || base.$$name == null) return nil; - - result.unshift(base.$$name); - - base = base.$$base_module; + // docdate, doctime and docdatetime should default to localdate, localtime and localdatetime if not otherwise set + if ($truthy(source_date_epoch)) { + input_mtime = source_date_epoch; + } else if ($truthy(input_mtime)) { + utc_offset = -input_mtime.getTimezoneOffset() / 60; + } else { + input_mtime = now; + } - if (base === Opal.Object) { - break; + // docdate and docyear + if ($truthy(docdate = attrs['$[]']('docdate'))) { + attrs['$[]=']('docyear', docdate.indexOf('-') === 4 ? docdate.substring(0, 4) : nil); + } else { + var mtime_year = getYear(input_mtime, utc_offset).toString(); + var mtime_month = ('0' + (getMonth(input_mtime, utc_offset) + 1)).slice(-2); + var mtime_day = ('0' + (getDay(input_mtime, utc_offset))).slice(-2); + docdate = mtime_year + '-' + mtime_month + '-' + mtime_day; + attrs['$[]=']('docdate', docdate); + if ($falsy(attrs['$[]']('docyear'))) { + attrs['$[]=']('docyear', mtime_year); } } - - if (result.length === 0) { - return nil; + // doctime + if ($falsy(doctime = attrs['$[]']('doctime'))) { + var mtime_hours = ('0' + (getHours(input_mtime, utc_offset))).slice(-2); + var mtime_minutes = ('0' + (input_mtime.getMinutes())).slice(-2); + var mtime_seconds = ('0' + (input_mtime.getSeconds())).slice(-2); + var utc_offset_format; + if (utc_offset === 0) { + utc_offset_format = 'UTC'; + } else if (utc_offset > 0) { + utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5); + } else { + utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5); + } + doctime = mtime_hours + ':' + mtime_minutes + ':' + mtime_seconds + ' ' + utc_offset_format; + attrs['$[]=']('doctime', doctime); } - - return self.$$full_name = result.join('::'); - - }, $Module_name$51.$$arity = 0); + // docdatetime + if ($falsy(attrs['$[]']('docdatetime'))) { + attrs['$[]=']('docdatetime', docdate + ' ' + doctime); + } + return nil - Opal.def(self, '$prepend', $Module_prepend$52 = function $$prepend($a) { - var $post_args, mods, self = this; + }) + })($nesting[0], $$('AbstractBlock')) + })($nesting[0], $nesting) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - mods = $post_args;; - - if (mods.length === 0) { - self.$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (given 0, expected 1+)") - } +Opal.modules["asciidoctor/js/asciidoctor_ext/substitutors"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $def = Opal.def, $nesting = []; Opal.nil; - for (var i = mods.length - 1; i >= 0; i--) { - var mod = mods[i]; + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - if (!mod.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + ((mod).$class()) + " (expected Module)"); - } + var $nesting = [self].concat($parent_nesting); - (mod).$prepend_features(self); - (mod).$prepended(self); - } - ; - return self; - }, $Module_prepend$52.$$arity = -1); - - Opal.def(self, '$prepend_features', $Module_prepend_features$53 = function $$prepend_features(prepender) { - var self = this; + return (function($base) { + var self = $module($base, 'Substitutors'); - - if (!self.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + (self.$class()) + " (expected Module)"); - } + return $def(self, '$sub_placeholder', function $$sub_placeholder(format_string, replacement) { + + return format_string.replace('%s', replacement); + }) + })($nesting[0]) + })($nesting[0], $nesting) +}; - Opal.prepend_features(self, prepender) - ; - return self; - }, $Module_prepend_features$53.$$arity = 1); - - Opal.def(self, '$prepended', $Module_prepended$54 = function $$prepended(mod) { - var self = this; +Opal.modules["asciidoctor/js/asciidoctor_ext/parser"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $defs = Opal.defs, $nesting = []; Opal.nil; - return nil - }, $Module_prepended$54.$$arity = 1); - - Opal.def(self, '$remove_const', $Module_remove_const$55 = function $$remove_const(name) { - var self = this; + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - return Opal.const_remove(self, name); - }, $Module_remove_const$55.$$arity = 1); - - Opal.def(self, '$to_s', $Module_to_s$56 = function $$to_s() { - var $a, self = this; + var $nesting = [self].concat($parent_nesting); - return ($truthy($a = Opal.Module.$name.call(self)) ? $a : "" + "#<" + (self.$$is_module ? 'Module' : 'Class') + ":0x" + (self.$__id__().$to_s(16)) + ">") - }, $Module_to_s$56.$$arity = 0); - - Opal.def(self, '$undef_method', $Module_undef_method$57 = function $$undef_method($a) { - var $post_args, names, self = this; + return (function($base, $super) { + var self = $klass($base, $super, 'Parser'); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - names = $post_args;; - - for (var i = 0, length = names.length; i < length; i++) { - Opal.udef(self, "$" + names[i]); + if ($truthy(String.prototype.repeat)) { + return $defs(self, '$uniform?', function $Parser_uniform$ques$1(str, chr, len) { + + return chr.repeat(len) === str; + }) + } else { + return $defs(self, '$uniform?', function $Parser_uniform$ques$2(str, chr, len) { + + return Array.apply(null, { length: len }).map(function () { return chr }).join('') === str; + }) } - ; - return self; - }, $Module_undef_method$57.$$arity = -1); - - Opal.def(self, '$instance_variables', $Module_instance_variables$58 = function $$instance_variables() { - var self = this, consts = nil; + })($nesting[0], null) + })($nesting[0], $nesting) +}; - - consts = (Opal.Module.$$nesting = $nesting, self.$constants()); - - var result = []; +Opal.modules["asciidoctor/js/asciidoctor_ext/syntax_highlighter"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil; - for (var name in self) { - if (self.hasOwnProperty(name) && name.charAt(0) !== '$' && name !== 'constructor' && !consts['$include?'](name)) { - result.push('@' + name); - } - } + Opal.add_stubs('key?,registry,[],include?,include,empty?,debug,logger,join,keys'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); - return result; - ; - }, $Module_instance_variables$58.$$arity = 0); - - Opal.def(self, '$dup', $Module_dup$59 = function $$dup() { - var $iter = $Module_dup$59.$$p, $yield = $iter || nil, self = this, copy = nil, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + var $nesting = [self].concat($parent_nesting); - if ($iter) $Module_dup$59.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - copy = $send(self, Opal.find_super_dispatcher(self, 'dup', $Module_dup$59, false), $zuper, $iter); - copy.$copy_class_variables(self); - copy.$copy_constants(self); - return copy; - }, $Module_dup$59.$$arity = 0); - - Opal.def(self, '$copy_class_variables', $Module_copy_class_variables$60 = function $$copy_class_variables(other) { - var self = this; + return (function($base, $parent_nesting) { + var self = $module($base, 'SyntaxHighlighter'); - - for (var name in other.$$cvars) { - self.$$cvars[name] = other.$$cvars[name]; - } - - }, $Module_copy_class_variables$60.$$arity = 1); - return (Opal.def(self, '$copy_constants', $Module_copy_constants$61 = function $$copy_constants(other) { - var self = this; + var $nesting = [self].concat($parent_nesting); - - var name, other_constants = other.$$const; + return (function($base, $parent_nesting) { + var self = $module($base, 'Factory'); - for (name in other_constants) { - Opal.const_set(self, name, other_constants[name]); - } - - }, $Module_copy_constants$61.$$arity = 1), nil) && 'copy_constants'; - })($nesting[0], null, $nesting) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + return $def(self, '$for', function $Factory_for$1(name) { + var self = this; + + if ($truthy(self.$registry()['$key?'](name))) { + return self.$registry()['$[]'](name) + } else { + + if (!$truthy(self['$include?']($$('Logging')))) { + self.$include($$('Logging')); + } if ($truthy(self.$registry()['$empty?']())) { + self.$logger().$debug("no syntax highlighter available, functionality disabled."); + } else { + self.$logger().$debug("syntax highlighter named '" + (name) + "' is not available, must be one of: '" + (self.$registry().$keys().$join("', '")) + "'."); + } return nil; + } + }) + })($nesting[0], $nesting) + })($nesting[0], $nesting) + })($nesting[0], $nesting) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/class"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send; +Opal.modules["asciidoctor/js/asciidoctor_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; - Opal.add_stubs(['$require', '$class_eval', '$to_proc', '$initialize_copy', '$allocate', '$name', '$to_s']); + Opal.add_stubs('require'); - self.$require("corelib/module"); + self.$require("asciidoctor/js/asciidoctor_ext/stylesheet"); + self.$require("asciidoctor/js/asciidoctor_ext/document"); + self.$require("asciidoctor/js/asciidoctor_ext/substitutors"); + self.$require("asciidoctor/js/asciidoctor_ext/parser"); + self.$require("asciidoctor/js/asciidoctor_ext/syntax_highlighter"); + +// Load specific runtime +self.$require("asciidoctor/js/asciidoctor_ext/node"); +}; + +Opal.modules["asciidoctor/js/opal_ext/logger"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil; + + Opal.add_stubs('chr,rjust,message_as_string,<,write,call,[]'); return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Class'); + var self = $klass($base, $super, 'Logger'); - var $nesting = [self].concat($parent_nesting), $Class_new$1, $Class_allocate$2, $Class_inherited$3, $Class_initialize_dup$4, $Class_new$5, $Class_superclass$6, $Class_to_s$7; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.level = $proto.progname = $proto.pipe = $proto.formatter = nil; - Opal.defs(self, '$new', $Class_new$1 = function(superclass) { - var $iter = $Class_new$1.$$p, block = $iter || nil, self = this; + (function($base, $super) { + var self = $klass($base, $super, 'Formatter'); - if ($iter) $Class_new$1.$$p = null; - - if ($iter) $Class_new$1.$$p = null;; - - if (superclass == null) { - superclass = $$($nesting, 'Object'); - }; - - if (!superclass.$$is_class) { - throw Opal.TypeError.$new("superclass must be a Class"); - } + return $def(self, '$call', function $$call(severity, time, progname, msg) { + var self = this, time_format = nil; - var klass = Opal.allocate_class(nil, superclass); - superclass.$inherited(klass); - (function() {if ((block !== nil)) { - return $send((klass), 'class_eval', [], block.$to_proc()) - } else { - return nil - }; return nil; })() - return klass; - ; - }, $Class_new$1.$$arity = -1); - - Opal.def(self, '$allocate', $Class_allocate$2 = function $$allocate() { - var self = this; + + time_format = time.getFullYear() + '-' + ('0'+(time.getMonth()+1)).slice(-2) + '-' + ('0'+time.getDate()).slice(-2) + 'T' + ('0'+time.getHours()).slice(-2) + ':' + ('0'+time.getMinutes()).slice(-2) + ':' + ('0'+time.getSeconds()).slice(-2) + '.' + ('00' + new Date().getMilliseconds() * 1000).slice(-6); + return "" + (severity.$chr()) + ", [" + (time_format) + "] " + (severity.$rjust(5)) + " -- " + (progname) + ": " + (self.$message_as_string(msg)); + }) + })($nesting[0], null); + return $def(self, '$add', function $$add(severity, message, progname) { + var block = $$add.$$p || nil, self = this, $ret_or_1 = nil; + + $$add.$$p = null; + if (message == null) message = nil; + if (progname == null) progname = nil; + if ($truthy($rb_lt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), self.level))) { + return true + } progname = ($truthy(($ret_or_1 = progname)) ? ($ret_or_1) : (self.progname)); + if (!$truthy(message)) { + if ((block !== nil)) { + message = Opal.yieldX(block, []); + } else { + + message = progname; + progname = self.progname; + } + } self.pipe.$write(self.formatter.$call(($truthy(($ret_or_1 = $$('SEVERITY_LABELS')['$[]'](severity))) ? ($ret_or_1) : ("ANY")), new Date(), progname, message)); + return true; + }, -2); + })($nesting[0], null, $nesting) +}; - - var obj = new self.$$constructor(); - obj.$$id = Opal.uid(); - return obj; - - }, $Class_allocate$2.$$arity = 0); - - Opal.def(self, '$inherited', $Class_inherited$3 = function $$inherited(cls) { - var self = this; +Opal.modules["asciidoctor/js/postscript"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; - return nil - }, $Class_inherited$3.$$arity = 1); - - Opal.def(self, '$initialize_dup', $Class_initialize_dup$4 = function $$initialize_dup(original) { - var self = this; + Opal.add_stubs('require'); + + self.$require("asciidoctor/converter/composite"); + self.$require("asciidoctor/converter/html5"); + self.$require("asciidoctor/extensions"); + self.$require("asciidoctor/js/asciidoctor_ext"); + return self.$require("asciidoctor/js/opal_ext/logger"); +}; - - self.$initialize_copy(original); - - self.$$name = null; - self.$$full_name = null; - ; - }, $Class_initialize_dup$4.$$arity = 1); - - Opal.def(self, '$new', $Class_new$5 = function($a) { - var $iter = $Class_new$5.$$p, block = $iter || nil, $post_args, args, self = this; +Opal.queue(function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $to_ary = Opal.to_ary, $defs = Opal.defs, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $regexp = Opal.regexp, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,==,to_h,sort,map,constants,const_get,downcase,to_s,<=>,upcase,[],values,new,attr_reader,instance_variable_set,send,singleton_class,<<,define,dirname,absolute_path,join,home,pwd,to_set,tap,each,chr,each_key,[]=,slice,length,-,merge,default=,drop,insert'); + + self.$require("set"); + self.$require("asciidoctor/js"); + (function($base, $parent_nesting) { + var self = $module($base, 'Asciidoctor'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $ret_or_1 = nil; - if ($iter) $Class_new$5.$$p = null; - - - if ($iter) $Class_new$5.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var object = self.$allocate(); - Opal.send(object, object.$initialize, args, block); - return object; - ; - }, $Class_new$5.$$arity = -1); - Opal.def(self, '$superclass', $Class_superclass$6 = function $$superclass() { - var self = this; + $const_set($nesting[0], 'RUBY_ENGINE_OPAL', $const_set($nesting[0], 'RUBY_ENGINE', $$$('RUBY_ENGINE'))['$==']("opal")); + (function($base, $parent_nesting) { + var self = $module($base, 'SafeMode'); - return self.$$super || nil; - }, $Class_superclass$6.$$arity = 0); - return (Opal.def(self, '$to_s', $Class_to_s$7 = function $$to_s() { - var $iter = $Class_to_s$7.$$p, $yield = $iter || nil, self = this; + var $nesting = [self].concat($parent_nesting); - if ($iter) $Class_to_s$7.$$p = null; - var singleton_of = self.$$singleton_of; + $const_set($nesting[0], 'UNSAFE', 0); + $const_set($nesting[0], 'SAFE', 1); + $const_set($nesting[0], 'SERVER', 10); + $const_set($nesting[0], 'SECURE', 20); + self.names_by_value = $send($send(self.$constants(false), 'map', [], function $SafeMode$1(sym){var self = $SafeMode$1.$$s == null ? this : $SafeMode$1.$$s; - if (singleton_of && (singleton_of.$$is_a_module)) { - return "" + "#"; - } - else if (singleton_of) { - // a singleton class created from an object - return "" + "#>"; - } - return $send(self, Opal.find_super_dispatcher(self, 'to_s', $Class_to_s$7, false), [], null); - - }, $Class_to_s$7.$$arity = 0), nil) && 'to_s'; - })($nesting[0], null, $nesting); -}; + + if (sym == null) sym = nil; + return [self.$const_get(sym), sym.$to_s().$downcase()];}, {$$s: self}), 'sort', [], function $SafeMode$2($mlhs_tmp1, $mlhs_tmp2){var $a, $b, a = nil, b = nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/basic_object"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $range = Opal.range, $hash2 = Opal.hash2, $send = Opal.send; + + if ($mlhs_tmp1 == null) $mlhs_tmp1 = nil; + if ($mlhs_tmp2 == null) $mlhs_tmp2 = nil; + $b = $mlhs_tmp1, $a = $to_ary($b), (a = ($a[0] == null ? nil : $a[0])); + $b = $mlhs_tmp2, $a = $to_ary($b), (b = ($a[0] == null ? nil : $a[0])); + return a['$<=>'](b);}, {$$has_top_level_mlhs_arg: true}).$to_h(); + $defs(self, '$value_for_name', function $$value_for_name(name) { + var self = this; - Opal.add_stubs(['$==', '$!', '$nil?', '$cover?', '$size', '$raise', '$merge', '$compile', '$proc', '$any?', '$inspect', '$new']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'BasicObject'); + return self.$const_get(name.$upcase(), false) + }); + $defs(self, '$name_for_value', function $$name_for_value(value) { + var self = this; + if (self.names_by_value == null) self.names_by_value = nil; - var $nesting = [self].concat($parent_nesting), $BasicObject_initialize$1, $BasicObject_$eq_eq$2, $BasicObject_eql$ques$3, $BasicObject___id__$4, $BasicObject___send__$5, $BasicObject_$excl$6, $BasicObject_$not_eq$7, $BasicObject_instance_eval$8, $BasicObject_instance_exec$10, $BasicObject_singleton_method_added$11, $BasicObject_singleton_method_removed$12, $BasicObject_singleton_method_undefined$13, $BasicObject_class$14, $BasicObject_method_missing$15; + return self.names_by_value['$[]'](value) + }); + return $defs(self, '$names', function $$names() { + var self = this; + if (self.names_by_value == null) self.names_by_value = nil; - - - Opal.def(self, '$initialize', $BasicObject_initialize$1 = function $$initialize($a) { - var $post_args, self = this; + return self.names_by_value.$values() + }); + })($nesting[0], $nesting); + (function($base, $parent_nesting) { + var self = $module($base, 'Compliance'); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $BasicObject_initialize$1.$$arity = -1); - - Opal.def(self, '$==', $BasicObject_$eq_eq$2 = function(other) { - var self = this; - - return self === other; - }, $BasicObject_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$eql?', $BasicObject_eql$ques$3 = function(other) { - var self = this; + self.keys = $$$('Set').$new(); + (function(self, $parent_nesting) { + + + self.$attr_reader("keys"); + return $def(self, '$define', function $$define(key, value) { + var self = this; + if (self.keys == null) self.keys = nil; - return self['$=='](other) - }, $BasicObject_eql$ques$3.$$arity = 1); - Opal.alias(self, "equal?", "=="); - - Opal.def(self, '$__id__', $BasicObject___id__$4 = function $$__id__() { - var self = this; + + self.$instance_variable_set("@" + (key), value); + self.$singleton_class().$send("attr_accessor", key); + self.keys['$<<'](key); + return nil; + }); + })(Opal.get_singleton_class(self)); + self.$define("block_terminates_paragraph", true); + self.$define("strict_verbatim_paragraphs", true); + self.$define("underline_style_section_titles", true); + self.$define("unwrap_standalone_preamble", true); + self.$define("attribute_missing", "skip"); + self.$define("attribute_undefined", "drop-line"); + self.$define("shorthand_property_syntax", true); + self.$define("natural_xrefs", true); + self.$define("unique_id_start_index", 2); + return self.$define("markdown_syntax", true); + })($nesting[0]); + if (!$truthy((($$('ROOT_DIR', 'skip_raise')) ? 'constant' : nil))) { + $const_set($nesting[0], 'ROOT_DIR', $$$('File').$dirname($$$('File').$absolute_path("."))); + } $const_set($nesting[0], 'LIB_DIR', $$$('File').$join($$('ROOT_DIR'), "lib")); + $const_set($nesting[0], 'DATA_DIR', $$$('File').$join($$('ROOT_DIR'), "data")); + $const_set($nesting[0], 'USER_HOME', (function() { try { + return $$$('Dir').$home() + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + + if ($truthy(($ret_or_1 = $$$('ENV')['$[]']("HOME")))) { + return $ret_or_1 + } else { + return $$$('Dir').$pwd() + }; + } finally { Opal.pop_exception(); } + } else { throw $err; } + }})()); + $const_set($nesting[0], 'LF', "\n"); + $const_set($nesting[0], 'NULL', "\x00"); + $const_set($nesting[0], 'TAB', "\t"); + $const_set($nesting[0], 'MAX_INT', 9007199254740991); + $const_set($nesting[0], 'UTF_8', $$$($$$('Encoding'), 'UTF_8')); + $const_set($nesting[0], 'BOM_BYTES_UTF_8', [239, 187, 191]); + $const_set($nesting[0], 'BOM_BYTES_UTF_16LE', [255, 254]); + $const_set($nesting[0], 'BOM_BYTES_UTF_16BE', [254, 255]); + $const_set($nesting[0], 'FILE_READ_MODE', ($truthy($$('RUBY_ENGINE_OPAL')) ? ("r") : ("rb:utf-8:utf-8"))); + $const_set($nesting[0], 'URI_READ_MODE', $$('FILE_READ_MODE')); + $const_set($nesting[0], 'FILE_WRITE_MODE', ($truthy($$('RUBY_ENGINE_OPAL')) ? ("w") : ("w:utf-8"))); + $const_set($nesting[0], 'DEFAULT_DOCTYPE', "article"); + $const_set($nesting[0], 'DEFAULT_BACKEND', "html5"); + $const_set($nesting[0], 'DEFAULT_STYLESHEET_KEYS', ["", "DEFAULT"].$to_set()); + $const_set($nesting[0], 'DEFAULT_STYLESHEET_NAME', "asciidoctor.css"); + $const_set($nesting[0], 'BACKEND_ALIASES', $hash2(["html", "docbook"], {"html": "html5", "docbook": "docbook5"})); + $const_set($nesting[0], 'DEFAULT_PAGE_WIDTHS', $hash2(["docbook"], {"docbook": 425})); + $const_set($nesting[0], 'DEFAULT_EXTENSIONS', $hash2(["html", "docbook", "pdf", "epub", "manpage", "asciidoc"], {"html": ".html", "docbook": ".xml", "pdf": ".pdf", "epub": ".epub", "manpage": ".man", "asciidoc": ".adoc"})); + $const_set($nesting[0], 'ASCIIDOC_EXTENSIONS', $hash2([".adoc", ".asciidoc", ".asc", ".ad", ".txt"], {".adoc": true, ".asciidoc": true, ".asc": true, ".ad": true, ".txt": true})); + $const_set($nesting[0], 'SETEXT_SECTION_LEVELS', $hash2(["=", "-", "~", "^", "+"], {"=": 0, "-": 1, "~": 2, "^": 3, "+": 4})); + $const_set($nesting[0], 'ADMONITION_STYLES', ["NOTE", "TIP", "IMPORTANT", "WARNING", "CAUTION"].$to_set()); + $const_set($nesting[0], 'ADMONITION_STYLE_HEADS', $send($$$('Set').$new(), 'tap', [], function $Asciidoctor$3(accum){ + + if (accum == null) accum = nil; + return $send($$('ADMONITION_STYLES'), 'each', [], function $$4(s){ + + if (s == null) s = nil; + return accum['$<<'](s.$chr());});})); + $const_set($nesting[0], 'PARAGRAPH_STYLES', ["comment", "example", "literal", "listing", "normal", "open", "pass", "quote", "sidebar", "source", "verse", "abstract", "partintro"].$to_set()); + $const_set($nesting[0], 'VERBATIM_STYLES', ["literal", "listing", "source", "verse"].$to_set()); + $const_set($nesting[0], 'DELIMITED_BLOCKS', $hash2(["--", "----", "....", "====", "****", "____", "++++", "|===", ",===", ":===", "!===", "////", "```"], {"--": ["open", ["comment", "example", "literal", "listing", "pass", "quote", "sidebar", "source", "verse", "admonition", "abstract", "partintro"].$to_set()], "----": ["listing", ["literal", "source"].$to_set()], "....": ["literal", ["listing", "source"].$to_set()], "====": ["example", ["admonition"].$to_set()], "****": ["sidebar", $$$('Set').$new()], "____": ["quote", ["verse"].$to_set()], "++++": ["pass", ["stem", "latexmath", "asciimath"].$to_set()], "|===": ["table", $$$('Set').$new()], ",===": ["table", $$$('Set').$new()], ":===": ["table", $$$('Set').$new()], "!===": ["table", $$$('Set').$new()], "////": ["comment", $$$('Set').$new()], "```": ["fenced_code", $$$('Set').$new()]})); + $const_set($nesting[0], 'DELIMITED_BLOCK_HEADS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$5(accum){ + + if (accum == null) accum = nil; + return $send($$('DELIMITED_BLOCKS'), 'each_key', [], function $$6(k){var $b; + + + if (k == null) k = nil; + return ($b = [k.$slice(0, 2), true], $send(accum, '[]=', $b), $b[$b.length - 1]);});})); + $const_set($nesting[0], 'DELIMITED_BLOCK_TAILS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$7(accum){ + + if (accum == null) accum = nil; + return $send($$('DELIMITED_BLOCKS'), 'each_key', [], function $$8(k){var $b; + + + if (k == null) k = nil; + if ($eqeq(k.$length(), 4)) { + return ($b = [k, k['$[]']($rb_minus(k.$length(), 1))], $send(accum, '[]=', $b), $b[$b.length - 1]) + } else { + return nil + }});})); + $const_set($nesting[0], 'CAPTION_ATTRIBUTE_NAMES', $hash2(["example", "figure", "listing", "table"], {"example": "example-caption", "figure": "figure-caption", "listing": "listing-caption", "table": "table-caption"})); + $const_set($nesting[0], 'LAYOUT_BREAK_CHARS', $hash2(["'", "<"], {"'": "thematic_break", "<": "page_break"})); + $const_set($nesting[0], 'MARKDOWN_THEMATIC_BREAK_CHARS', $hash2(["-", "*", "_"], {"-": "thematic_break", "*": "thematic_break", "_": "thematic_break"})); + $const_set($nesting[0], 'HYBRID_LAYOUT_BREAK_CHARS', $$('LAYOUT_BREAK_CHARS').$merge($$('MARKDOWN_THEMATIC_BREAK_CHARS'))); + $const_set($nesting[0], 'NESTABLE_LIST_CONTEXTS', ["ulist", "olist", "dlist"]); + $const_set($nesting[0], 'ORDERED_LIST_STYLES', ["arabic", "loweralpha", "lowerroman", "upperalpha", "upperroman"]); + $const_set($nesting[0], 'ORDERED_LIST_KEYWORDS', $hash2(["loweralpha", "lowerroman", "upperalpha", "upperroman"], {"loweralpha": "a", "lowerroman": "i", "upperalpha": "A", "upperroman": "I"})); + $const_set($nesting[0], 'ATTR_REF_HEAD', "{"); + $const_set($nesting[0], 'LIST_CONTINUATION', "+"); + $const_set($nesting[0], 'HARD_LINE_BREAK', " +"); + $const_set($nesting[0], 'LINE_CONTINUATION', " \\"); + $const_set($nesting[0], 'LINE_CONTINUATION_LEGACY', " +"); + $const_set($nesting[0], 'BLOCK_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\[", "\\]"]})); + $const_set($nesting[0], 'INLINE_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]})); + $const_set($nesting[0], 'STEM_TYPE_ALIASES', $hash2(["latexmath", "latex", "tex"], {"latexmath": "latexmath", "latex": "latexmath", "tex": "latexmath"}))['$default=']("asciimath"); + $const_set($nesting[0], 'FONT_AWESOME_VERSION', "4.7.0"); + $const_set($nesting[0], 'HIGHLIGHT_JS_VERSION', "9.18.3"); + $const_set($nesting[0], 'MATHJAX_VERSION', "2.7.9"); + $const_set($nesting[0], 'DEFAULT_ATTRIBUTES', $hash2(["appendix-caption", "appendix-refsig", "caution-caption", "chapter-refsig", "example-caption", "figure-caption", "important-caption", "last-update-label", "note-caption", "part-refsig", "prewrap", "sectids", "section-refsig", "table-caption", "tip-caption", "toc-placement", "toc-title", "untitled-label", "version-label", "warning-caption"], {"appendix-caption": "Appendix", "appendix-refsig": "Appendix", "caution-caption": "Caution", "chapter-refsig": "Chapter", "example-caption": "Example", "figure-caption": "Figure", "important-caption": "Important", "last-update-label": "Last updated", "note-caption": "Note", "part-refsig": "Part", "prewrap": "", "sectids": "", "section-refsig": "Section", "table-caption": "Table", "tip-caption": "Tip", "toc-placement": "auto", "toc-title": "Table of Contents", "untitled-label": "Untitled", "version-label": "Version", "warning-caption": "Warning"})); + $const_set($nesting[0], 'FLEXIBLE_ATTRIBUTES', ["sectnums"]); + $const_set($nesting[0], 'INTRINSIC_ATTRIBUTES', $hash2(["startsb", "endsb", "vbar", "caret", "asterisk", "tilde", "plus", "backslash", "backtick", "blank", "empty", "sp", "two-colons", "two-semicolons", "nbsp", "deg", "zwsp", "quot", "apos", "lsquo", "rsquo", "ldquo", "rdquo", "wj", "brvbar", "pp", "cpp", "amp", "lt", "gt"], {"startsb": "[", "endsb": "]", "vbar": "|", "caret": "^", "asterisk": "*", "tilde": "~", "plus": "+", "backslash": "\\", "backtick": "`", "blank": "", "empty": "", "sp": " ", "two-colons": "::", "two-semicolons": ";;", "nbsp": " ", "deg": "°", "zwsp": "​", "quot": """, "apos": "'", "lsquo": "‘", "rsquo": "’", "ldquo": "“", "rdquo": "”", "wj": "⁠", "brvbar": "¦", "pp": "++", "cpp": "C++", "amp": "&", "lt": "<", "gt": ">"})); + $const_set($nesting[0], 'QUOTE_SUBS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$9(accum){var normal = nil, compat = nil; + + + if (accum == null) accum = nil; + accum['$[]='](false, (normal = [["strong", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?\\*\\*(", $$('CC_ALL'), "+?)\\*\\*"], 'm')], ["strong", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\\*(\\S|\\S", $$('CC_ALL'), "*?\\S)\\*(?!", $$('CG_WORD'), ")"], 'm')], ["double", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\"`(\\S|\\S", $$('CC_ALL'), "*?\\S)`\"(?!", $$('CG_WORD'), ")"], 'm')], ["single", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:`}])(?:\\[([^\\]]+)\\])?'`(\\S|\\S", $$('CC_ALL'), "*?\\S)`'(?!", $$('CG_WORD'), ")"], 'm')], ["monospaced", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?``(", $$('CC_ALL'), "+?)``"], 'm')], ["monospaced", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:\"'`}])(?:\\[([^\\]]+)\\])?`(\\S|\\S", $$('CC_ALL'), "*?\\S)`(?![", $$('CC_WORD'), "\"'`])"], 'm')], ["emphasis", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?__(", $$('CC_ALL'), "+?)__"], 'm')], ["emphasis", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?_(\\S|\\S", $$('CC_ALL'), "*?\\S)_(?!", $$('CG_WORD'), ")"], 'm')], ["mark", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?##(", $$('CC_ALL'), "+?)##"], 'm')], ["mark", "constrained", $regexp(["(^|[^", $$('CC_WORD'), "&;:}])(?:\\[([^\\]]+)\\])?#(\\S|\\S", $$('CC_ALL'), "*?\\S)#(?!", $$('CG_WORD'), ")"], 'm')], ["superscript", "unconstrained", /\\?(?:\[([^\]]+)\])?\^(\S+?)\^/], ["subscript", "unconstrained", /\\?(?:\[([^\]]+)\])?~(\S+?)~/]])); + accum['$[]='](true, (compat = normal.$drop(0))); + compat['$[]='](2, ["double", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?``(\\S|\\S", $$('CC_ALL'), "*?\\S)''(?!", $$('CG_WORD'), ")"], 'm')]); + compat['$[]='](3, ["single", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?`(\\S|\\S", $$('CC_ALL'), "*?\\S)'(?!", $$('CG_WORD'), ")"], 'm')]); + compat['$[]='](4, ["monospaced", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?\\+\\+(", $$('CC_ALL'), "+?)\\+\\+"], 'm')]); + compat['$[]='](5, ["monospaced", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\\+(\\S|\\S", $$('CC_ALL'), "*?\\S)\\+(?!", $$('CG_WORD'), ")"], 'm')]); + return compat.$insert(3, ["emphasis", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?'(\\S|\\S", $$('CC_ALL'), "*?\\S)'(?!", $$('CG_WORD'), ")"], 'm')]);})); + $const_set($nesting[0], 'REPLACEMENTS', [[/\\?\(C\)/, "©", "none"], [/\\?\(R\)/, "®", "none"], [/\\?\(TM\)/, "™", "none"], [/(?: |\n|^|\\)--(?: |\n|$)/, " — ", "none"], [$regexp(["(", $$('CG_WORD'), ")\\\\?--(?=", $$('CG_WORD'), ")"]), "—​", "leading"], [/\\?\.\.\./, "…​", "none"], [/\\?`'/, "’", "none"], [$regexp(["(", $$('CG_ALNUM'), ")\\\\?'(?=", $$('CG_ALPHA'), ")"]), "’", "leading"], [/\\?->/, "→", "none"], [/\\?=>/, "⇒", "none"], [/\\?<-/, "←", "none"], [/\\?<=/, "⇐", "none"], [/\\?(&)amp;((?:[a-zA-Z][a-zA-Z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-fA-F][\da-fA-F][\da-fA-F]{0,3});)/, "", "bounding"]]); + return nil; + })($nesting[0], $nesting); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/core_ext"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/helpers"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/logging"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/rx"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/substitutors"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/version"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_node"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_block"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/attribute_list"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/block"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/callouts"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/converter"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/document"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/inline"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/list"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/parser"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/path_resolver"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/reader"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/section"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/stylesheets"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/table"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/writer"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/load"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/convert"); + + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/syntax_highlighter"); + self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/timings"); + return self.$require("asciidoctor/js/postscript");}); - - if (self.$$id != null) { - return self.$$id; - } - Opal.defineProperty(self, '$$id', Opal.uid()); - return self.$$id; - - }, $BasicObject___id__$4.$$arity = 0); - - Opal.def(self, '$__send__', $BasicObject___send__$5 = function $$__send__(symbol, $a) { - var $iter = $BasicObject___send__$5.$$p, block = $iter || nil, $post_args, args, self = this; - if ($iter) $BasicObject___send__$5.$$p = null; - - - if ($iter) $BasicObject___send__$5.$$p = null;; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var func = self['$' + symbol] +/* global Opal */ - if (func) { - if (block !== nil) { - func.$$p = block; - } +/** + * Convert a JSON to an (Opal) Hash. + * @private + */ +const toHash = function (object) { + return object && !object.$$is_hash ? Opal.hash2(Object.keys(object), object) : object +}; - return func.apply(self, args); +/** + * Convert an (Opal) Hash to JSON. + * @private + */ +const fromHash = function (hash) { + const object = {}; + if (hash) { + const stringMap = hash.$$smap; + for (const key in stringMap) { + const value = stringMap[key]; + object[key] = value === Opal.nil ? undefined : value; + } + const numericMap = hash.$$map; + if (numericMap) { + const positional = []; + for (const key in numericMap) { + const entry = numericMap[key]; + const value = entry.value; + const index = entry.key - 1; + positional[index] = value === Opal.nil ? undefined : value; } - - if (block !== nil) { - self.$method_missing.$$p = block; + if (positional.length > 0) { + object.$positional = positional; } + } + } + return object +}; - return self.$method_missing.apply(self, [symbol].concat(args)); - ; - }, $BasicObject___send__$5.$$arity = -2); - - Opal.def(self, '$!', $BasicObject_$excl$6 = function() { - var self = this; - - return false - }, $BasicObject_$excl$6.$$arity = 0); - - Opal.def(self, '$!=', $BasicObject_$not_eq$7 = function(other) { - var self = this; - - return self['$=='](other)['$!']() - }, $BasicObject_$not_eq$7.$$arity = 1); - - Opal.def(self, '$instance_eval', $BasicObject_instance_eval$8 = function $$instance_eval($a) { - var $iter = $BasicObject_instance_eval$8.$$p, block = $iter || nil, $post_args, args, $b, $$9, self = this, string = nil, file = nil, _lineno = nil, default_eval_options = nil, compiling_options = nil, compiled = nil; - - if ($iter) $BasicObject_instance_eval$8.$$p = null; - - - if ($iter) $BasicObject_instance_eval$8.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(($truthy($b = block['$nil?']()) ? !!Opal.compile : $b))) { - - if ($truthy($range(1, 3, false)['$cover?'](args.$size()))) { - } else { - $$$('::', 'Kernel').$raise($$$('::', 'ArgumentError'), "wrong number of arguments (0 for 1..3)") - }; - $b = [].concat(Opal.to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (_lineno = ($b[2] == null ? nil : $b[2])), $b; - default_eval_options = $hash2(["file", "eval"], {"file": ($truthy($b = file) ? $b : "(eval)"), "eval": true}); - compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options); - compiled = $$$('::', 'Opal').$compile(string, compiling_options); - block = $send($$$('::', 'Kernel'), 'proc', [], ($$9 = function(){var self = $$9.$$s || this; +const fromHashKeys = function (hash) { + const object = {}; + if (hash) { + const data = hash.$$keys; + for (const key in data) { + const value = data[key].value; + object[key.toString()] = value === Opal.nil ? undefined : value; + } + } + return object +}; - - return (function(self) { - return eval(compiled); - })(self) - }, $$9.$$s = self, $$9.$$arity = 0, $$9)); - } else if ($truthy(args['$any?']())) { - $$$('::', 'Kernel').$raise($$$('::', 'ArgumentError'), "" + "wrong number of arguments (" + (args.$size()) + " for 0)")}; - - var old = block.$$s, - result; +/** + * @private + */ +const prepareOptions = function (options) { + options = toHash(options); + if (options) { + const converter = options['$[]']('converter'); + if (converter && converter !== Opal.nil) { + options['$[]=']('converter', bridgeConverter(converter)); + } + const attrs = options['$[]']('attributes'); + if (attrs && typeof attrs === 'object' && attrs.constructor.name === 'Object') { + options = options.$dup(); + options['$[]=']('attributes', toHash(attrs)); + } + } + return options +}; - block.$$s = null; +const bridgeConverter = function (converter) { + const buildBackendTraitsFromObject = function (obj) { + return Object.assign({}, + obj.basebackend ? { basebackend: obj.basebackend } : {}, + obj.outfilesuffix ? { outfilesuffix: obj.outfilesuffix } : {}, + obj.filetype ? { filetype: obj.filetype } : {}, + obj.htmlsyntax ? { htmlsyntax: obj.htmlsyntax } : {}, + obj.supports_templates ? { supports_templates: obj.supports_templates } : {} + ) + }; + const assignBackendTraitsToInstance = function (obj, instance) { + if (obj.backend_traits) { + instance.backend_traits = toHash(obj.backend_traits); + } else if (obj.backendTraits) { + instance.backend_traits = toHash(obj.backendTraits); + } else if (obj.basebackend || obj.outfilesuffix || obj.filetype || obj.htmlsyntax || obj.supports_templates) { + instance.backend_traits = toHash(buildBackendTraitsFromObject(obj)); + } + }; + const bridgeHandlesMethodToInstance = function (obj, instance) { + bridgeMethodToInstance(obj, instance, '$handles?', 'handles', function () { + return true + }); + }; + const bridgeComposedMethodToInstance = function (obj, instance) { + bridgeMethodToInstance(obj, instance, '$composed', 'composed'); + }; + const bridgeEqEqMethodToInstance = function (obj, instance) { + bridgeMethodToInstance(obj, instance, '$==', '==', function (other) { + return instance === other + }); + }; + const bridgeSendMethodToInstance = function (obj, instance) { + bridgeMethodToInstance(obj, instance, '$send', 'send', function (symbol) { + const [, ...args] = Array.from(arguments); + const func = instance['$' + symbol]; + if (func) { + return func.apply(instance, args) + } + throw new Error(`undefined method \`${symbol}\` for \`${instance.toString()}\``) + }); + }; + const bridgeMethodToInstance = function (obj, instance, methodName, functionName, defaultImplementation) { + if (typeof obj[methodName] === 'undefined') { + if (typeof obj[functionName] === 'function') { + instance[methodName] = obj[functionName]; + } else if (defaultImplementation) { + instance[methodName] = defaultImplementation; + } + } + }; + const addRespondToMethod = function (instance) { + if (typeof instance['$respond_to?'] !== 'function') { + instance['$respond_to?'] = function (name) { + return typeof this[name] === 'function' + }; + } + }; + if (typeof converter === 'function') { + // Class + const object = initializeClass(ConverterBase, converter.constructor.name, { + initialize: function (backend, opts) { + const self = this; + const result = new converter(backend, opts); // eslint-disable-line + Object.assign(this, result); + assignBackendTraitsToInstance(result, self); + const propertyNames = Object.getOwnPropertyNames(converter.prototype); + for (let i = 0; i < propertyNames.length; i++) { + const propertyName = propertyNames[i]; + if (propertyName !== 'constructor') { + self[propertyName] = result[propertyName]; + } + } + if (typeof result.$convert === 'undefined' && typeof result.convert === 'function') { + self.$convert = result.convert; + } + bridgeHandlesMethodToInstance(result, self); + bridgeComposedMethodToInstance(result, self); + addRespondToMethod(self); + self.super(backend, opts); + } + }); + object.$extend(ConverterBackendTraits); + return object + } + if (typeof converter === 'object') { + // Instance + if (typeof converter.$convert === 'undefined' && typeof converter.convert === 'function') { + converter.$convert = converter.convert; + } + assignBackendTraitsToInstance(converter, converter); + if (converter.backend_traits) { + // "extends" ConverterBackendTraits + const converterBackendTraitsFunctionNames = [ + 'basebackend', + 'filetype', + 'htmlsyntax', + 'outfilesuffix', + 'supports_templates', + 'supports_templates?', + 'init_backend_traits', + 'backend_traits' + ]; + for (const functionName of converterBackendTraitsFunctionNames) { + converter['$' + functionName] = ConverterBackendTraits.prototype['$' + functionName]; + } + converter.$$meta = ConverterBackendTraits; + } + bridgeHandlesMethodToInstance(converter, converter); + bridgeComposedMethodToInstance(converter, converter); + bridgeEqEqMethodToInstance(converter, converter); + bridgeSendMethodToInstance(converter, converter); + addRespondToMethod(converter); + return converter + } + return converter +}; - // Need to pass $$eval so that method definitions know if this is - // being done on a class/module. Cannot be compiler driven since - // send(:instance_eval) needs to work. - if (self.$$is_a_module) { - self.$$eval = true; - try { - result = block.call(self, self); +function initializeClass (superClass, className, functions, defaultFunctions, argProxyFunctions) { + const scope = Opal.klass(Opal.Object, superClass, className, function () { }); + let postConstructFunction; + let initializeFunction; + let constructorFunction; + const defaultFunctionsOverridden = {}; + for (const functionName in functions) { + if (Object.prototype.hasOwnProperty.call(functions, functionName)) { + (function (functionName) { + const userFunction = functions[functionName]; + if (functionName === 'postConstruct') { + postConstructFunction = userFunction; + } else if (functionName === 'initialize') { + initializeFunction = userFunction; + } else if (functionName === 'constructor') { + constructorFunction = userFunction; + } else { + if (defaultFunctions && Object.prototype.hasOwnProperty.call(defaultFunctions, functionName)) { + defaultFunctionsOverridden[functionName] = true; + } + let $function; + Opal.def(scope, '$' + functionName, ($function = function () { + let args; + if (argProxyFunctions && Object.prototype.hasOwnProperty.call(argProxyFunctions, functionName)) { + args = argProxyFunctions[functionName](arguments); + } else { + args = arguments; + } + // append Ruby block as the final argument + const $block = $function.$$p; + if ($block) { + args[args.length] = function () { return Opal.yield1($block) }; + args.length += 1; + $function.$$p = null; + } + return userFunction.apply(this, args) + })); } - finally { - self.$$eval = false; + }(functionName)); + } + } + let initialize; + if (typeof constructorFunction === 'function') { + initialize = function () { + const args = Array.from(arguments); + for (let i = 0; i < args.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof args[i] === 'object' && '$$smap' in args[i]) { + args[i] = fromHash(args[i]); } } - else { - result = block.call(self, self); + args.unshift(null); + const result = new (Function.prototype.bind.apply(constructorFunction, args)); // eslint-disable-line + Object.assign(this, result); + if (typeof postConstructFunction === 'function') { + postConstructFunction.bind(this)(); } - - block.$$s = old; - - return result; - ; - }, $BasicObject_instance_eval$8.$$arity = -1); - - Opal.def(self, '$instance_exec', $BasicObject_instance_exec$10 = function $$instance_exec($a) { - var $iter = $BasicObject_instance_exec$10.$$p, block = $iter || nil, $post_args, args, self = this; - - if ($iter) $BasicObject_instance_exec$10.$$p = null; - - - if ($iter) $BasicObject_instance_exec$10.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(block)) { - } else { - $$$('::', 'Kernel').$raise($$$('::', 'ArgumentError'), "no block given") - }; - - var block_self = block.$$s, - result; - - block.$$s = null; - - if (self.$$is_a_module) { - self.$$eval = true; - try { - result = block.apply(self, args); + }; + } else if (typeof initializeFunction === 'function') { + initialize = function () { + const args = Array.from(arguments); + for (let i = 0; i < args.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof args[i] === 'object' && '$$smap' in args[i]) { + args[i] = fromHash(args[i]); } - finally { - self.$$eval = false; + } + initializeFunction.apply(this, args); + if (typeof postConstructFunction === 'function') { + postConstructFunction.bind(this)(); + } + }; + } else { + initialize = function () { + Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize)); + if (typeof postConstructFunction === 'function') { + postConstructFunction.bind(this)(); + } + }; + } + Opal.def(scope, '$initialize', initialize); + let $superFunction; + Opal.def(scope, 'super', ($superFunction = function (func) { + if (typeof func === 'function') { + Opal.send(this, Opal.find_super_dispatcher(this, func.name, func)); + } else { + // Bind the initialize function to super(); + const argumentsList = Array.from(arguments); + for (let i = 0; i < argumentsList.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof argumentsList[i] === 'object') { + argumentsList[i] = toHash(argumentsList[i]); } } - else { - result = block.apply(self, args); + Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), argumentsList); + } + })); + for (const functionName in functions) { + $superFunction[functionName] = function () { + const argumentsList = Array.from(arguments); + for (let i = 0; i < argumentsList.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof argumentsList[i] === 'object' && typeof argumentsList[i].constructor === 'function' && argumentsList[i].constructor.name === 'Object') { + argumentsList[i] = toHash(argumentsList[i]); + } } + const self = scope.$$prototype; + return Opal.send(self, Opal.find_super_dispatcher(self, functionName, self[`$${functionName}`]), argumentsList) + }; + } + if (defaultFunctions) { + for (const defaultFunctionName in defaultFunctions) { + if (Object.prototype.hasOwnProperty.call(defaultFunctions, defaultFunctionName) && !Object.prototype.hasOwnProperty.call(defaultFunctionsOverridden, defaultFunctionName)) { + (function (defaultFunctionName) { + const defaultFunction = defaultFunctions[defaultFunctionName]; + Opal.def(scope, '$' + defaultFunctionName, function () { + return defaultFunction.apply(this, arguments) + }); + }(defaultFunctionName)); + } + } + } + return scope +} - block.$$s = block_self; - - return result; - ; - }, $BasicObject_instance_exec$10.$$arity = -1); - - Opal.def(self, '$singleton_method_added', $BasicObject_singleton_method_added$11 = function $$singleton_method_added($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $BasicObject_singleton_method_added$11.$$arity = -1); - - Opal.def(self, '$singleton_method_removed', $BasicObject_singleton_method_removed$12 = function $$singleton_method_removed($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $BasicObject_singleton_method_removed$12.$$arity = -1); - - Opal.def(self, '$singleton_method_undefined', $BasicObject_singleton_method_undefined$13 = function $$singleton_method_undefined($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $BasicObject_singleton_method_undefined$13.$$arity = -1); - - Opal.def(self, '$class', $BasicObject_class$14 = function() { - var self = this; +// Asciidoctor API - return self.$$class; - }, $BasicObject_class$14.$$arity = 0); - return (Opal.def(self, '$method_missing', $BasicObject_method_missing$15 = function $$method_missing(symbol, $a) { - var $iter = $BasicObject_method_missing$15.$$p, block = $iter || nil, $post_args, args, self = this, message = nil; +/** + * @namespace + * @description + * The main application interface (API) for Asciidoctor. + * This API provides methods to parse AsciiDoc content and convert it to various output formats using built-in or third-party converters. + * + * An AsciiDoc document can be as simple as a single line of content, + * though it more commonly starts with a document header that declares the document title and document attribute definitions. + * The document header is then followed by zero or more section titles, optionally nested, to organize the paragraphs, blocks, lists, etc. of the document. + * + * By default, the processor converts the AsciiDoc document to HTML 5 using a built-in converter. + * However, this behavior can be changed by specifying a different backend (e.g., +docbook+). + * A backend is a keyword for an output format (e.g., DocBook). + * That keyword, in turn, is used to select a converter, which carries out the request to convert the document to that format. + * + * @example + * asciidoctor.convertFile('document.adoc', { 'safe': 'safe' }) // Convert an AsciiDoc file + * + * asciidoctor.convert("I'm using *Asciidoctor* version {asciidoctor-version}.", { 'safe': 'safe' }) // Convert an AsciiDoc string + * + * const doc = asciidoctor.loadFile('document.adoc', { 'safe': 'safe' }) // Parse an AsciiDoc file into a document object + * + * const doc = asciidoctor.load("= Document Title\n\nfirst paragraph\n\nsecond paragraph", { 'safe': 'safe' }) // Parse an AsciiDoc string into a document object + */ +const Asciidoctor = Opal.Asciidoctor.$$class; - if ($iter) $BasicObject_method_missing$15.$$p = null; - - - if ($iter) $BasicObject_method_missing$15.$$p = null;; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - message = (function() {if ($truthy(self.$inspect && !self.$inspect.$$stub)) { - return "" + "undefined method `" + (symbol) + "' for " + (self.$inspect()) + ":" + (self.$$class) - } else { - return "" + "undefined method `" + (symbol) + "' for " + (self.$$class) - }; return nil; })(); - return $$$('::', 'Kernel').$raise($$$('::', 'NoMethodError').$new(message, symbol)); - }, $BasicObject_method_missing$15.$$arity = -2), nil) && 'method_missing'; - })($nesting[0], null, $nesting) +/** + * Get Asciidoctor core version number. + * + * @returns {string} - the version number of Asciidoctor core. + * @memberof Asciidoctor + */ +Asciidoctor.prototype.getCoreVersion = function () { + return this.$$const.VERSION }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/kernel"] = function(Opal) { - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); +/** + * Get Asciidoctor.js runtime environment information. + * + * @returns {Object} - the runtime environment including the ioModule, the platform, the engine and the framework. + * @memberof Asciidoctor + */ +Asciidoctor.prototype.getRuntime = function () { + return { + ioModule: Opal.const_get_qualified('::', 'JAVASCRIPT_IO_MODULE'), + platform: Opal.const_get_qualified('::', 'JAVASCRIPT_PLATFORM'), + engine: Opal.const_get_qualified('::', 'JAVASCRIPT_ENGINE'), + framework: Opal.const_get_qualified('::', 'JAVASCRIPT_FRAMEWORK') } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy, $gvars = Opal.gvars, $hash2 = Opal.hash2, $send = Opal.send, $klass = Opal.klass; - - Opal.add_stubs(['$raise', '$new', '$inspect', '$!', '$=~', '$==', '$object_id', '$class', '$coerce_to?', '$<<', '$allocate', '$copy_instance_variables', '$copy_singleton_methods', '$initialize_clone', '$initialize_copy', '$define_method', '$singleton_class', '$to_proc', '$initialize_dup', '$for', '$empty?', '$pop', '$call', '$coerce_to', '$append_features', '$extend_object', '$extended', '$__id__', '$to_s', '$instance_variable_name!', '$respond_to?', '$to_int', '$coerce_to!', '$Integer', '$nil?', '$===', '$enum_for', '$result', '$any?', '$print', '$format', '$puts', '$each', '$<=', '$length', '$[]', '$exception', '$is_a?', '$rand', '$respond_to_missing?', '$try_convert!', '$expand_path', '$join', '$start_with?', '$new_seed', '$srand', '$sym', '$arg', '$open', '$include']); - - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); - - var $nesting = [self].concat($parent_nesting), $Kernel_method_missing$1, $Kernel_$eq_tilde$2, $Kernel_$excl_tilde$3, $Kernel_$eq_eq_eq$4, $Kernel_$lt_eq_gt$5, $Kernel_method$6, $Kernel_methods$7, $Kernel_public_methods$8, $Kernel_Array$9, $Kernel_at_exit$10, $Kernel_caller$11, $Kernel_class$12, $Kernel_copy_instance_variables$13, $Kernel_copy_singleton_methods$14, $Kernel_clone$15, $Kernel_initialize_clone$16, $Kernel_define_singleton_method$17, $Kernel_dup$18, $Kernel_initialize_dup$19, $Kernel_enum_for$20, $Kernel_equal$ques$21, $Kernel_exit$22, $Kernel_extend$23, $Kernel_hash$24, $Kernel_initialize_copy$25, $Kernel_inspect$26, $Kernel_instance_of$ques$27, $Kernel_instance_variable_defined$ques$28, $Kernel_instance_variable_get$29, $Kernel_instance_variable_set$30, $Kernel_remove_instance_variable$31, $Kernel_instance_variables$32, $Kernel_Integer$33, $Kernel_Float$34, $Kernel_Hash$35, $Kernel_is_a$ques$36, $Kernel_itself$37, $Kernel_lambda$38, $Kernel_load$39, $Kernel_loop$40, $Kernel_nil$ques$42, $Kernel_printf$43, $Kernel_proc$44, $Kernel_puts$45, $Kernel_p$46, $Kernel_print$48, $Kernel_warn$49, $Kernel_raise$50, $Kernel_rand$51, $Kernel_respond_to$ques$52, $Kernel_respond_to_missing$ques$53, $Kernel_require$54, $Kernel_require_relative$55, $Kernel_require_tree$56, $Kernel_singleton_class$57, $Kernel_sleep$58, $Kernel_srand$59, $Kernel_String$60, $Kernel_tap$61, $Kernel_to_proc$62, $Kernel_to_s$63, $Kernel_catch$64, $Kernel_throw$65, $Kernel_open$66, $Kernel_yield_self$67; - - - - Opal.def(self, '$method_missing', $Kernel_method_missing$1 = function $$method_missing(symbol, $a) { - var $iter = $Kernel_method_missing$1.$$p, block = $iter || nil, $post_args, args, self = this; - - if ($iter) $Kernel_method_missing$1.$$p = null; - - - if ($iter) $Kernel_method_missing$1.$$p = null;; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - return self.$raise($$($nesting, 'NoMethodError').$new("" + "undefined method `" + (symbol) + "' for " + (self.$inspect()), symbol, args)); - }, $Kernel_method_missing$1.$$arity = -2); - - Opal.def(self, '$=~', $Kernel_$eq_tilde$2 = function(obj) { - var self = this; - - return false - }, $Kernel_$eq_tilde$2.$$arity = 1); - - Opal.def(self, '$!~', $Kernel_$excl_tilde$3 = function(obj) { - var self = this; - - return self['$=~'](obj)['$!']() - }, $Kernel_$excl_tilde$3.$$arity = 1); - - Opal.def(self, '$===', $Kernel_$eq_eq_eq$4 = function(other) { - var $a, self = this; - - return ($truthy($a = self.$object_id()['$=='](other.$object_id())) ? $a : self['$=='](other)) - }, $Kernel_$eq_eq_eq$4.$$arity = 1); - - Opal.def(self, '$<=>', $Kernel_$lt_eq_gt$5 = function(other) { - var self = this; - - - // set guard for infinite recursion - self.$$comparable = true; - - var x = self['$=='](other); - - if (x && x !== nil) { - return 0; - } - - return nil; - - }, $Kernel_$lt_eq_gt$5.$$arity = 1); - - Opal.def(self, '$method', $Kernel_method$6 = function $$method(name) { - var self = this; +}; - - var meth = self['$' + name]; +/** + * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format. + * + * Accepts input as a Buffer or String. + * + * @param {string|Buffer} input - AsciiDoc input as String or Buffer + * @param {Object} options - a JSON of options to control processing (default: {}) + * @returns {string|Document} - the {@link Document} object if the converted String is written to a file, + * otherwise the converted String + * @example + * const input = `= Hello, AsciiDoc! + * Guillaume Grossetie + * + * An introduction to http://asciidoc.org[AsciiDoc]. + * + * == First Section + * + * * item 1 + * * item 2` + * + * const html = asciidoctor.convert(input) + * @memberof Asciidoctor + */ +Asciidoctor.prototype.convert = function (input, options) { + if (typeof input === 'object' && input.constructor.name === 'Buffer') { + input = input.toString('utf8'); + } + const toFile = options && options.to_file; + if (typeof toFile === 'object' && toFile.constructor.name === 'Writable' && typeof toFile.write === 'function') { + toFile['$respond_to?'] = (name) => name === 'write'; + toFile.$object_id = () => ''; + toFile.$write = function (data) { + this.write(data); + }; + } + const opts = prepareOptions(options); + const result = this.$convert(input, opts); + if (typeof toFile === 'object' && toFile.constructor.name === 'Writable' && typeof toFile.end === 'function') { + toFile.end(); + } + return result === Opal.nil ? '' : result +}; - if (!meth || meth.$$stub) { - self.$raise($$($nesting, 'NameError').$new("" + "undefined method `" + (name) + "' for class `" + (self.$class()) + "'", name)); - } +/** + * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format. + * + * @param {string} filename - source filename + * @param {Object} options - a JSON of options to control processing (default: {}) + * @returns {string|Document} - the {@link Document} object if the converted String is written to a file, + * otherwise the converted String + * @example + * const html = asciidoctor.convertFile('./document.adoc') + * @memberof Asciidoctor + */ +Asciidoctor.prototype.convertFile = function (filename, options) { + return this.$convert_file(filename, prepareOptions(options)) +}; - return $$($nesting, 'Method').$new(self, meth.$$owner || self.$class(), meth, name); - - }, $Kernel_method$6.$$arity = 1); - - Opal.def(self, '$methods', $Kernel_methods$7 = function $$methods(all) { - var self = this; +/** + * Parse the AsciiDoc source input into an {@link Document} + * + * Accepts input as a Buffer or String. + * + * @param {string|Buffer} input - AsciiDoc input as String or Buffer + * @param {Object} options - a JSON of options to control processing (default: {}) + * @returns {Document} - the {@link Document} object + * @memberof Asciidoctor + */ +Asciidoctor.prototype.load = function (input, options) { + if (typeof input === 'object' && input.constructor.name === 'Buffer') { + input = input.toString('utf8'); + } + return this.$load(input, prepareOptions(options)) +}; - - - if (all == null) { - all = true; - }; - - if ($truthy(all)) { - return Opal.methods(self); - } else { - return Opal.own_methods(self); - } - ; - }, $Kernel_methods$7.$$arity = -1); - - Opal.def(self, '$public_methods', $Kernel_public_methods$8 = function $$public_methods(all) { - var self = this; +/** + * Parse the contents of the AsciiDoc source file into an {@link Document} + * + * @param {string} filename - source filename + * @param {Object} options - a JSON of options to control processing (default: {}) + * @returns {Document} - the {@link Document} object + * @memberof Asciidoctor + */ +Asciidoctor.prototype.loadFile = function (filename, options) { + return this.$load_file(filename, prepareOptions(options)) +}; - - - if (all == null) { - all = true; - }; - - if ($truthy(all)) { - return Opal.methods(self); - } else { - return Opal.receiver_methods(self); - } - ; - }, $Kernel_public_methods$8.$$arity = -1); - - Opal.def(self, '$Array', $Kernel_Array$9 = function $$Array(object) { - var self = this; +// AbstractBlock API - - var coerced; +/** + * @namespace + * @extends AbstractNode + */ +const AbstractBlock = Opal.Asciidoctor.AbstractBlock; - if (object === nil) { - return []; - } +/** + * Describes the type of content this block accepts and how it should be converted. + * @returns {string} - the type of content this block accepts. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getContentModel = function () { + const contentModel = this.content_model; + return contentModel === Opal.nil ? undefined : contentModel +}; - if (object.$$is_array) { - return object; - } +/** + * Set the type of content this block accepts. Acceptable values are: + * - compound - this block contains other blocks + * - simple - this block holds a paragraph of prose that receives normal substitutions + * - verbatim - this block holds verbatim text (displayed "as is") that receives verbatim substitutions + * - raw - this block holds unprocessed content passed directly to the output with no substitutions applied + * - empty - this block has no content + * @param {string} contentModel - type of content, one of: compound, simple, verbatim, raw or empty. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.setContentModel = function (contentModel) { + this.content_model = contentModel; +}; - coerced = $$($nesting, 'Opal')['$coerce_to?'](object, $$($nesting, 'Array'), "to_ary"); - if (coerced !== nil) { return coerced; } +/** + * Append a block to this block's list of child blocks. + * @param {AbstractBlock} block - the block to append + * @returns {AbstractBlock} - the parent block to which this block was appended. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.append = function (block) { + this.$append(block); + return this +}; - coerced = $$($nesting, 'Opal')['$coerce_to?'](object, $$($nesting, 'Array'), "to_a"); - if (coerced !== nil) { return coerced; } +/** + * Get the String title of this Block with title substitutions applied + * + * The following substitutions are applied to block and section titles: + * + * specialcharacters, quotes, replacements, macros, attributes and post_replacements + * + * @returns {string} - the converted String title for this Block, or undefined if the title is not set. + * @example + * block.title // "Foo 3^ # {two-colons} Bar(1)" + * block.getTitle(); // "Foo 3^ # :: Bar(1)" + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getTitle = function () { + const title = this.$title(); + return title === Opal.nil ? undefined : title +}; - return [object]; - - }, $Kernel_Array$9.$$arity = 1); - - Opal.def(self, '$at_exit', $Kernel_at_exit$10 = function $$at_exit() { - var $iter = $Kernel_at_exit$10.$$p, block = $iter || nil, $a, self = this; - if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil; +/** + * Set the String block title. + * + * @param {string} title - The block title + * @returns {string} - the new String title assigned to this Block. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.setTitle = function (title) { + title = typeof title === 'undefined' ? Opal.nil : title; + return this['$title='](title) +}; - if ($iter) $Kernel_at_exit$10.$$p = null; - - - if ($iter) $Kernel_at_exit$10.$$p = null;; - $gvars.__at_exit__ = ($truthy($a = $gvars.__at_exit__) ? $a : []); - return $gvars.__at_exit__['$<<'](block); - }, $Kernel_at_exit$10.$$arity = 0); - - Opal.def(self, '$caller', $Kernel_caller$11 = function $$caller($a) { - var $post_args, args, self = this; +/** + * Generate and assign caption to block if not already assigned. + * + * If the block has a title and a caption prefix is available for this block, + * then build a caption from this information, assign it a number and store it + * to the caption attribute on the block. + * + * If a caption has already been assigned to this block, do nothing. + * + * The parts of a complete caption are: ` . ` + * This partial caption represents the part the precedes the title. + * + * @param {string} value - the String caption to assign to this block or nil to use document attribute. + * @param {string} captionContext - the String context to use when resolving caption-related attributes. + * If not provided, the name of the context for this block is used. Only certain contexts allow the caption to be looked up. + * + * @memberof AbstractBlock + */ +AbstractBlock.prototype.assignCaption = function (value, captionContext) { + value = typeof value === 'undefined' ? Opal.nil : value; + captionContext = typeof captionContext === 'undefined' ? null : captionContext; + this.$assign_caption(value, captionContext); +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return []; - }, $Kernel_caller$11.$$arity = -1); - - Opal.def(self, '$class', $Kernel_class$12 = function() { - var self = this; +/** + * Convenience method that returns the interpreted title of the Block + * with the caption prepended. + * Concatenates the value of this Block's caption instance variable and the + * return value of this Block's title method. No space is added between the + * two values. If the Block does not have a caption, the interpreted title is + * returned. + * + * @returns {string} - the converted String title prefixed with the caption, or just the converted String title if no caption is set + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getCaptionedTitle = function () { + return this.$captioned_title() +}; - return self.$$class; - }, $Kernel_class$12.$$arity = 0); - - Opal.def(self, '$copy_instance_variables', $Kernel_copy_instance_variables$13 = function $$copy_instance_variables(other) { - var self = this; +/** + * Get the style (block type qualifier) for this block. + * + * @returns {string} - the style for this block + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getStyle = function () { + const style = this.style; + return style === Opal.nil ? undefined : style +}; - - var keys = Object.keys(other), i, ii, name; - for (i = 0, ii = keys.length; i < ii; i++) { - name = keys[i]; - if (name.charAt(0) !== '$' && other.hasOwnProperty(name)) { - self[name] = other[name]; - } - } - - }, $Kernel_copy_instance_variables$13.$$arity = 1); - - Opal.def(self, '$copy_singleton_methods', $Kernel_copy_singleton_methods$14 = function $$copy_singleton_methods(other) { - var self = this; +/** + * Set the style for this block. + * + * @param {string} style - Style + * @memberof AbstractBlock + */ +AbstractBlock.prototype.setStyle = function (style) { + this.style = style; +}; - - var i, name, names, length; +/** + * Get the location in the AsciiDoc source where this block begins. + * + * @returns {Cursor} - the location in the AsciiDoc source where this block begins + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getSourceLocation = function () { + const sourceLocation = this.source_location; + if (sourceLocation === Opal.nil) { + return undefined + } + sourceLocation.getFile = function () { + const file = this.file; + return file === Opal.nil ? undefined : file + }; + sourceLocation.getDirectory = function () { + const dir = this.dir; + return dir === Opal.nil ? undefined : dir + }; + sourceLocation.getPath = function () { + const path = this.path; + return path === Opal.nil ? undefined : path + }; + sourceLocation.getLineNumber = function () { + const lineno = this.lineno; + return lineno === Opal.nil ? undefined : lineno + }; + return sourceLocation +}; - if (other.hasOwnProperty('$$meta')) { - var other_singleton_class = Opal.get_singleton_class(other); - var self_singleton_class = Opal.get_singleton_class(self); - names = Object.getOwnPropertyNames(other_singleton_class.$$prototype); +/** + * Get the caption for this block. + * + * @returns {string} - the caption for this block + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getCaption = function () { + const caption = this.$caption(); + return caption === Opal.nil ? undefined : caption +}; - for (i = 0, length = names.length; i < length; i++) { - name = names[i]; - if (Opal.is_method(name)) { - self_singleton_class.$$prototype[name] = other_singleton_class.$$prototype[name]; - } - } +/** + * Set the caption for this block. + * + * @param {string} caption - Caption + * @memberof AbstractBlock + */ +AbstractBlock.prototype.setCaption = function (caption) { + this.caption = typeof caption === 'undefined' ? Opal.nil : caption; +}; - self_singleton_class.$$const = Object.assign({}, other_singleton_class.$$const); - Object.setPrototypeOf( - self_singleton_class.$$prototype, - Object.getPrototypeOf(other_singleton_class.$$prototype) - ); - } +/** + * Get the level of this section or the section level in which this block resides. + * + * @returns {number} - the level (Integer) of this section + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getLevel = function () { + const level = this.level; + return level === Opal.nil ? undefined : level +}; - for (i = 0, names = Object.getOwnPropertyNames(other), length = names.length; i < length; i++) { - name = names[i]; - if (name.charAt(0) === '$' && name.charAt(1) !== '$' && other.hasOwnProperty(name)) { - self[name] = other[name]; - } - } - - }, $Kernel_copy_singleton_methods$14.$$arity = 1); - - Opal.def(self, '$clone', $Kernel_clone$15 = function $$clone($kwargs) { - var freeze, self = this, copy = nil; +/** + * Get the substitution keywords to be applied to the contents of this block. + * + * @returns {Array<string>} - the list of {string} substitution keywords associated with this block. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getSubstitutions = function () { + return this.subs +}; - - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - freeze = $kwargs.$$smap["freeze"]; - if (freeze == null) { - freeze = true - }; - copy = self.$class().$allocate(); - copy.$copy_instance_variables(self); - copy.$copy_singleton_methods(self); - copy.$initialize_clone(self); - return copy; - }, $Kernel_clone$15.$$arity = -1); - - Opal.def(self, '$initialize_clone', $Kernel_initialize_clone$16 = function $$initialize_clone(other) { - var self = this; +/** + * Check whether a given substitution keyword is present in the substitutions for this block. + * + * @returns {boolean} - whether the substitution is present on this block. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.hasSubstitution = function (substitution) { + return this['$sub?'](substitution) +}; - return self.$initialize_copy(other) - }, $Kernel_initialize_clone$16.$$arity = 1); - - Opal.def(self, '$define_singleton_method', $Kernel_define_singleton_method$17 = function $$define_singleton_method(name, method) { - var $iter = $Kernel_define_singleton_method$17.$$p, block = $iter || nil, self = this; +/** + * Remove the specified substitution keyword from the list of substitutions for this block. + * + * @memberof AbstractBlock + */ +AbstractBlock.prototype.removeSubstitution = function (substitution) { + this.$remove_sub(substitution); +}; - if ($iter) $Kernel_define_singleton_method$17.$$p = null; - - - if ($iter) $Kernel_define_singleton_method$17.$$p = null;; - ; - return $send(self.$singleton_class(), 'define_method', [name, method], block.$to_proc()); - }, $Kernel_define_singleton_method$17.$$arity = -2); - - Opal.def(self, '$dup', $Kernel_dup$18 = function $$dup() { - var self = this, copy = nil; +/** + * Checks if the {@link AbstractBlock} contains any child blocks. + * + * @returns {boolean} - whether the {@link AbstractBlock} has child blocks. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.hasBlocks = function () { + return this.blocks.length > 0 +}; - - copy = self.$class().$allocate(); - copy.$copy_instance_variables(self); - copy.$initialize_dup(self); - return copy; - }, $Kernel_dup$18.$$arity = 0); - - Opal.def(self, '$initialize_dup', $Kernel_initialize_dup$19 = function $$initialize_dup(other) { - var self = this; +/** + * Get the list of {@link AbstractBlock} sub-blocks for this block. + * + * @returns {Array<AbstractBlock>} - a list of {@link AbstractBlock} sub-blocks + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getBlocks = function () { + return this.blocks +}; - return self.$initialize_copy(other) - }, $Kernel_initialize_dup$19.$$arity = 1); - - Opal.def(self, '$enum_for', $Kernel_enum_for$20 = function $$enum_for($a, $b) { - var $iter = $Kernel_enum_for$20.$$p, block = $iter || nil, $post_args, method, args, self = this; +/** + * Get the converted result of the child blocks by converting the children appropriate to content model that this block supports. + * + * @returns {string} - the converted result of the child blocks + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getContent = function () { + const content = this.$content(); + return content === Opal.nil ? undefined : content +}; - if ($iter) $Kernel_enum_for$20.$$p = null; - - - if ($iter) $Kernel_enum_for$20.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - if ($post_args.length > 0) { - method = $post_args[0]; - $post_args.splice(0, 1); - } - if (method == null) { - method = "each"; - }; - - args = $post_args;; - return $send($$($nesting, 'Enumerator'), 'for', [self, method].concat(Opal.to_a(args)), block.$to_proc()); - }, $Kernel_enum_for$20.$$arity = -1); - Opal.alias(self, "to_enum", "enum_for"); - - Opal.def(self, '$equal?', $Kernel_equal$ques$21 = function(other) { - var self = this; +/** + * Get the converted content for this block. + * If the block has child blocks, the content method should cause them to be converted + * and returned as content that can be included in the parent block's template. + * + * @returns {string} - the converted String content for this block + * @memberof AbstractBlock + */ +AbstractBlock.prototype.convert = function () { + return this.$convert() +}; - return self === other; - }, $Kernel_equal$ques$21.$$arity = 1); - - Opal.def(self, '$exit', $Kernel_exit$22 = function $$exit(status) { - var $a, self = this, block = nil; - if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil; +/** + * Query for all descendant block-level nodes in the document tree + * that match the specified selector (context, style, id, and/or role). + * If a function block is given, it's used as an additional filter. + * If no selector or function block is supplied, all block-level nodes in the tree are returned. + * @param {Object} [selector] + * @param {function} [block] + * @example + * doc.findBy({'context': 'section'}); + * // => { level: 0, title: "Hello, AsciiDoc!", blocks: 0 } + * // => { level: 1, title: "First Section", blocks: 1 } + * + * doc.findBy({'context': 'section'}, function (section) { return section.getLevel() === 1; }); + * // => { level: 1, title: "First Section", blocks: 1 } + * + * doc.findBy({'context': 'listing', 'style': 'source'}); + * // => { context: :listing, content_model: :verbatim, style: "source", lines: 1 } + * + * @returns {Array<AbstractBlock>} - a list of block-level nodes that match the filter or an empty list if no matches are found + * @memberof AbstractBlock + */ +AbstractBlock.prototype.findBy = function (selector, block) { + if (typeof block === 'undefined' && typeof selector === 'function') { + return Opal.send(this, 'find_by', null, selector) + } else if (typeof block === 'function') { + return Opal.send(this, 'find_by', [toHash(selector)], block) + } else { + return this.$find_by(toHash(selector)) + } +}; - - - if (status == null) { - status = true; - }; - $gvars.__at_exit__ = ($truthy($a = $gvars.__at_exit__) ? $a : []); - while (!($truthy($gvars.__at_exit__['$empty?']()))) { - - block = $gvars.__at_exit__.$pop(); - block.$call(); - }; - - if (status.$$is_boolean) { - status = status ? 0 : 1; - } else { - status = $$($nesting, 'Opal').$coerce_to(status, $$($nesting, 'Integer'), "to_int") - } +/** + * Get the source line number where this block started. + * @returns {number} - the source line number where this block started + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getLineNumber = function () { + const lineno = this.$lineno(); + return lineno === Opal.nil ? undefined : lineno +}; - Opal.exit(status); - ; - return nil; - }, $Kernel_exit$22.$$arity = -1); - - Opal.def(self, '$extend', $Kernel_extend$23 = function $$extend($a) { - var $post_args, mods, self = this; +/** + * Check whether this block has any child Section objects. + * Only applies to Document and Section instances. + * @returns {boolean} - true if this block has child Section objects, otherwise false + * @memberof AbstractBlock + */ +AbstractBlock.prototype.hasSections = function () { + // REMIND: call directly the underlying method "$sections?" + // once https://github.com/asciidoctor/asciidoctor/pull/3591 is merged and a new version is released. + // return this['$sections?']() + return this.next_section_index !== Opal.nil && this.next_section_index > 0 +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - mods = $post_args;; - - var singleton = self.$singleton_class(); +/** + * Get the Array of child Section objects. + * Only applies to Document and Section instances. + * @memberof AbstractBlock + * @returns {Array<Section>} - an {Array} of {@link Section} objects + */ +AbstractBlock.prototype.getSections = function () { + return this.$sections() +}; - for (var i = mods.length - 1; i >= 0; i--) { - var mod = mods[i]; +/** + * Get the numeral of this block (if section, relative to parent, otherwise absolute). + * Only assigned to section if automatic section numbering is enabled. + * Only assigned to formal block (block with title) if corresponding caption attribute is present. + * If the section is an appendix, the numeral is a letter (starting with A). + * @returns {string} - the numeral + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getNumeral = function () { + const numeral = this.$numeral(); + return numeral === Opal.nil ? undefined : numeral +}; - if (!mod.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + ((mod).$class()) + " (expected Module)"); - } +/** + * Set the numeral of this block. + * @param {string} value - The numeral value + * @memberof AbstractBlock + */ +AbstractBlock.prototype.setNumeral = function (value) { + this['$numeral='](value); +}; - (mod).$append_features(singleton); - (mod).$extend_object(self); - (mod).$extended(self); - } - ; - return self; - }, $Kernel_extend$23.$$arity = -1); - - Opal.def(self, '$hash', $Kernel_hash$24 = function $$hash() { - var self = this; +/** + * A convenience method that checks whether the title of this block is defined. + * + * @returns {boolean} - a {boolean} indicating whether this block has a title. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.hasTitle = function () { + return this['$title?']() +}; - return self.$__id__() - }, $Kernel_hash$24.$$arity = 0); - - Opal.def(self, '$initialize_copy', $Kernel_initialize_copy$25 = function $$initialize_copy(other) { - var self = this; +/** + * Returns the converted alt text for this block image. + * @returns {string} - the {string} value of the alt attribute with XML special character and replacement substitutions applied. + * @memberof AbstractBlock + */ +AbstractBlock.prototype.getAlt = function () { + return this.$alt() +}; - return nil - }, $Kernel_initialize_copy$25.$$arity = 1); - - Opal.def(self, '$inspect', $Kernel_inspect$26 = function $$inspect() { - var self = this; +// Section API - return self.$to_s() - }, $Kernel_inspect$26.$$arity = 0); - - Opal.def(self, '$instance_of?', $Kernel_instance_of$ques$27 = function(klass) { - var self = this; +/** + * @description + * Methods for managing sections of AsciiDoc content in a document. + * + * @example + * <pre> + * section = asciidoctor.Section.create() + * section.setTitle('Section 1') + * section.setId('sect1') + * section.getBlocks().length // 0 + * section.getId() // "sect1" + * section.append(newBlock) + * section.getBlocks().length // 1 + * </pre> + * @namespace + * @extends AbstractBlock + */ +const Section = Opal.Asciidoctor.Section; - - if (!klass.$$is_class && !klass.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "class or module required"); - } +/** + * Create a {Section} object. + * @param {AbstractBlock} [parent] - The parent AbstractBlock. If set, must be a Document or Section object (default: undefined) + * @param {number} [level] - The Integer level of this section (default: 1 more than parent level or 1 if parent not defined) + * @param {boolean} [numbered] - A Boolean indicating whether numbering is enabled for this Section (default: false) + * @param {Object} [opts] - An optional JSON of options (default: {}) + * @returns {Section} - a new {Section} object + * @memberof Section + */ +Section.create = function (parent, level, numbered, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return this.$new(parent, level, numbered, toHash(opts)) +}; - return self.$$class === klass; - - }, $Kernel_instance_of$ques$27.$$arity = 1); - - Opal.def(self, '$instance_variable_defined?', $Kernel_instance_variable_defined$ques$28 = function(name) { - var self = this; +/** + * Set the level of this section or the section level in which this block resides. + * @param {number} level - Level (Integer) + * @memberof AbstractBlock + */ +Section.prototype.setLevel = function (level) { + this.level = level; +}; - - name = $$($nesting, 'Opal')['$instance_variable_name!'](name); - return Opal.hasOwnProperty.call(self, name.substr(1));; - }, $Kernel_instance_variable_defined$ques$28.$$arity = 1); - - Opal.def(self, '$instance_variable_get', $Kernel_instance_variable_get$29 = function $$instance_variable_get(name) { - var self = this; +/** + * Get the 0-based index order of this section within the parent block. + * @returns {number} + * @memberof Section + */ +Section.prototype.getIndex = function () { + return this.index +}; - - name = $$($nesting, 'Opal')['$instance_variable_name!'](name); - - var ivar = self[Opal.ivar(name.substr(1))]; +/** + * Set the 0-based index order of this section within the parent block. + * @param {string} index - The index order of this section + * @memberof Section + */ +Section.prototype.setIndex = function (index) { + this.index = index; +}; - return ivar == null ? nil : ivar; - ; - }, $Kernel_instance_variable_get$29.$$arity = 1); - - Opal.def(self, '$instance_variable_set', $Kernel_instance_variable_set$30 = function $$instance_variable_set(name, value) { - var self = this; +/** + * Get the section name of this section. + * @returns {string|undefined} + * @memberof Section + */ +Section.prototype.getSectionName = function () { + const sectname = this.sectname; + return sectname === Opal.nil ? undefined : sectname +}; - - name = $$($nesting, 'Opal')['$instance_variable_name!'](name); - return self[Opal.ivar(name.substr(1))] = value;; - }, $Kernel_instance_variable_set$30.$$arity = 2); - - Opal.def(self, '$remove_instance_variable', $Kernel_remove_instance_variable$31 = function $$remove_instance_variable(name) { - var self = this; +/** + * Set the section name of this section. + * @param {string} value - The section name + * @memberof Section + */ +Section.prototype.setSectionName = function (value) { + this.sectname = value; +}; - - name = $$($nesting, 'Opal')['$instance_variable_name!'](name); - - var key = Opal.ivar(name.substr(1)), - val; - if (self.hasOwnProperty(key)) { - val = self[key]; - delete self[key]; - return val; - } - ; - return self.$raise($$($nesting, 'NameError'), "" + "instance variable " + (name) + " not defined"); - }, $Kernel_remove_instance_variable$31.$$arity = 1); - - Opal.def(self, '$instance_variables', $Kernel_instance_variables$32 = function $$instance_variables() { - var self = this; +/** + * Get the section numeral of this section. + * @returns {string} + * @memberof Section + */ +Section.prototype.getSectionNumeral = function () { + return this.$sectnum() +}; - - var result = [], ivar; +Section.prototype.getSectionNumber = Section.prototype.getSectionNumeral; - for (var name in self) { - if (self.hasOwnProperty(name) && name.charAt(0) !== '$') { - if (name.substr(-1) === '$') { - ivar = name.slice(0, name.length - 1); - } else { - ivar = name; - } - result.push('@' + ivar); - } - } +/** + * Get the flag to indicate whether this is a special section or a child of one. + * @returns {boolean} + * @memberof Section + */ +Section.prototype.isSpecial = function () { + return this.special +}; - return result; - - }, $Kernel_instance_variables$32.$$arity = 0); - - Opal.def(self, '$Integer', $Kernel_Integer$33 = function $$Integer(value, base) { - var self = this; +/** + * Set the flag to indicate whether this is a special section or a child of one. + * @param {boolean} value - A flag to indicated if this is a special section + * @memberof Section + */ +Section.prototype.setSpecial = function (value) { + this.special = value; +}; - - ; - - var i, str, base_digits; +/** + * Get the state of the numbered attribute at this section (need to preserve for creating TOC). + * @returns {boolean} + * @memberof Section + */ +Section.prototype.isNumbered = function () { + return this.numbered +}; - if (!value.$$is_string) { - if (base !== undefined) { - self.$raise($$($nesting, 'ArgumentError'), "base specified for non string value") - } - if (value === nil) { - self.$raise($$($nesting, 'TypeError'), "can't convert nil into Integer") - } - if (value.$$is_number) { - if (value === Infinity || value === -Infinity || isNaN(value)) { - self.$raise($$($nesting, 'FloatDomainError'), value) - } - return Math.floor(value); - } - if (value['$respond_to?']("to_int")) { - i = value.$to_int(); - if (i !== nil) { - return i; - } - } - return $$($nesting, 'Opal')['$coerce_to!'](value, $$($nesting, 'Integer'), "to_i"); - } +/** + * Get the caption for this section (only relevant for appendices). + * @returns {string} + * @memberof Section + */ +Section.prototype.getCaption = function () { + const value = this.caption; + return value === Opal.nil ? undefined : value +}; - if (value === "0") { - return 0; - } +/** + * Get the name of the Section (title) + * @returns {string} + * @see {@link AbstractBlock#getTitle} + * @memberof Section + */ +Section.prototype.getName = function () { + return this.getTitle() +}; - if (base === undefined) { - base = 0; - } else { - base = $$($nesting, 'Opal').$coerce_to(base, $$($nesting, 'Integer'), "to_int"); - if (base === 1 || base < 0 || base > 36) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid radix " + (base)) - } - } +/** + * @description + * Methods for managing AsciiDoc content blocks. + * + * @example + * block = asciidoctor.Block.create(parent, 'paragraph', {source: '_This_ is a <test>'}) + * block.getContent() + * // "<em>This</em> is a <test>" + * + * @namespace + * @extends AbstractBlock + */ +const Block = Opal.Asciidoctor.Block; - str = value.toLowerCase(); +/** + * Create a {Block} object. + * @param {AbstractBlock} parent - The parent {AbstractBlock} with a compound content model to which this {Block} will be appended. + * @param {string} context - The context name for the type of content (e.g., "paragraph"). + * @param {Object} [opts] - a JSON of options to customize block initialization: (default: {}) + * @param {string} opts.content_model - indicates whether blocks can be nested in this {Block} ("compound"), + * otherwise how the lines should be processed ("simple", "verbatim", "raw", "empty"). (default: "simple") + * @param {Object} opts.attributes - a JSON of attributes (key/value pairs) to assign to this {Block}. (default: {}) + * @param {string|Array<string>} opts.source - a String or {Array} of raw source for this {Block}. (default: undefined) + * + * IMPORTANT: If you don't specify the `subs` option, you must explicitly call the `commit_subs` method to resolve and assign the substitutions + * to this block (which are resolved from the `subs` attribute, if specified, or the default substitutions based on this block's context). + * If you want to use the default subs for a block, pass the option `subs: "default"`. + * You can override the default subs using the `default_subs` option. + * + * @returns {Block} - a new {Block} object + * @memberof Block + */ +Block.create = function (parent, context, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return this.$new(parent, context, toHash(opts)) +}; - str = str.replace(/(\d)_(?=\d)/g, '$1'); +/** + * Get the source of this block. + * @returns {string} - the String source of this block. + * @memberof Block + */ +Block.prototype.getSource = function () { + return this.$source() +}; - str = str.replace(/^(\s*[+-]?)(0[bodx]?)/, function (_, head, flag) { - switch (flag) { - case '0b': - if (base === 0 || base === 2) { - base = 2; - return head; - } - case '0': - case '0o': - if (base === 0 || base === 8) { - base = 8; - return head; - } - case '0d': - if (base === 0 || base === 10) { - base = 10; - return head; - } - case '0x': - if (base === 0 || base === 16) { - base = 16; - return head; - } - } - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid value for Integer(): \"" + (value) + "\"") - }); +/** + * Get the source lines of this block. + * @returns {Array<string>} - the String {Array} of source lines for this block. + * @memberof Block + */ +Block.prototype.getSourceLines = function () { + return this.lines +}; - base = (base === 0 ? 10 : base); +// AbstractNode API - base_digits = '0-' + (base <= 10 ? base - 1 : '9a-' + String.fromCharCode(97 + (base - 11))); +/** + * @namespace + * @description + * An abstract base class that provides state and methods for managing a node of AsciiDoc content. + * The state and methods on this class are common to all content segments in an AsciiDoc document. + */ +const AbstractNode = Opal.Asciidoctor.AbstractNode; - if (!(new RegExp('^\\s*[+-]?[' + base_digits + ']+\\s*$')).test(str)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid value for Integer(): \"" + (value) + "\"") - } +/** + * Apply the specified substitutions to the text. + * If no substitutions are specified, the following substitutions are applied: + * <code>specialcharacters</code>, <code>quotes</code>, <code>attributes</code>, <code>replacements</code>, <code>macros</code>, and <code>post_replacements</code>. + * + * @param {string|Array<string>} text - The String or String Array of text to process; must not be undefined. + * @param {Array<string>} [subs] - The substitutions to perform; must be an Array or undefined. + * @returns {string|Array<string>} - a String or String Array to match the type of the text argument with substitutions applied. + * @memberof AbstractNode + */ +AbstractNode.prototype.applySubstitutions = function (text, subs) { + return this.$apply_subs(text, subs) +}; - i = parseInt(str, base); +/** + * Resolve the list of comma-delimited subs against the possible options. + * + * @param {string} subs - The comma-delimited String of substitution names or aliases. + * @param {string} [type] - A String representing the context for which the subs are being resolved (default: 'block'). + * @param {Array<string>} [defaults] - An Array of substitutions to start with when computing incremental substitutions (default: undefined). + * @param {string} [subject] - The String to use in log messages to communicate the subject for which subs are being resolved (default: undefined) + * + * @returns {Array<string>} - An Array of Strings representing the substitution operation or nothing if no subs are found. + * @memberof AbstractNode + */ +AbstractNode.prototype.resolveSubstitutions = function (subs, type, defaults, subject) { + if (typeof type === 'undefined') { + type = 'block'; + } + if (typeof defaults === 'undefined') { + defaults = Opal.nil; + } + if (typeof subject === 'undefined') { + subject = Opal.nil; + } + const value = this.$resolve_subs(subs, type, defaults, subject); + return value === Opal.nil ? undefined : value +}; - if (isNaN(i)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid value for Integer(): \"" + (value) + "\"") - } +/** + * Call {@link AbstractNode#resolveSubstitutions} for the 'block' type. + * + * @see {@link AbstractNode#resolveSubstitutions} + */ +AbstractNode.prototype.resolveBlockSubstitutions = function (subs, defaults, subject) { + return this.resolveSubstitutions(subs, 'block', defaults, subject) +}; - return i; - ; - }, $Kernel_Integer$33.$$arity = -2); - - Opal.def(self, '$Float', $Kernel_Float$34 = function $$Float(value) { - var self = this; +/** + * Call {@link AbstractNode#resolveSubstitutions} for the 'inline' type with the subject set as passthrough macro. + * + * @see {@link AbstractNode#resolveSubstitutions} + */ +AbstractNode.prototype.resolvePassSubstitutions = function (subs) { + return this.resolveSubstitutions(subs, 'inline', undefined, 'passthrough macro') +}; - - var str; +/** + * @returns {string} - the String name of this node + * @memberof AbstractNode + */ +AbstractNode.prototype.getNodeName = function () { + return this.node_name +}; - if (value === nil) { - self.$raise($$($nesting, 'TypeError'), "can't convert nil into Float") - } +/** + * @returns {Object} - the JSON of attributes for this node + * @memberof AbstractNode + */ +AbstractNode.prototype.getAttributes = function () { + return fromHash(this.attributes) +}; - if (value.$$is_string) { - str = value.toString(); +/** + * Get the value of the specified attribute. + * If the attribute is not found on this node, fallback_name is set, and this node is not the Document node, get the value of the specified attribute from the Document node. + * + * Look for the specified attribute in the attributes on this node and return the value of the attribute, if found. + * Otherwise, if fallback_name is set (default: same as name) and this node is not the Document node, look for that attribute on the Document node and return its value, if found. + * Otherwise, return the default value (default: undefined). + * + * @param {string} name - The String of the attribute to resolve. + * @param {*} [defaultValue] - The {Object} value to return if the attribute is not found (default: undefined). + * @param {string} [fallbackName] - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name). + * + * @returns {*} - the {Object} value (typically a String) of the attribute or defaultValue if the attribute is not found. + * @memberof AbstractNode + */ +AbstractNode.prototype.getAttribute = function (name, defaultValue, fallbackName) { + const value = this.$attr(name, defaultValue, fallbackName); + return value === Opal.nil ? undefined : value +}; - str = str.replace(/(\d)_(?=\d)/g, '$1'); +/** + * Check whether the specified attribute is present on this node. + * + * @param {string} name - The String of the attribute to resolve. + * @returns {boolean} - true if the attribute is present, otherwise false + * @memberof AbstractNode + */ +AbstractNode.prototype.hasAttribute = function (name) { + return name in this.attributes.$$smap +}; - //Special case for hex strings only: - if (/^\s*[-+]?0[xX][0-9a-fA-F]+\s*$/.test(str)) { - return self.$Integer(str); - } +/** + * Check if the specified attribute is defined using the same logic as {AbstractNode#getAttribute}, optionally performing acomparison with the expected value if specified. + * + * Look for the specified attribute in the attributes on this node. + * If not found, fallback_name is specified (default: same as name), and this node is not the Document node, look for that attribute on the Document node. + * In either case, if the attribute is found, and the comparison value is truthy, return whether the two values match. + * Otherwise, return whether the attribute was found. + * + * @param {string} name - The String name of the attribute to resolve. + * @param {*} [expectedValue] - The expected Object value of the attribute (default: undefined). + * @param {string} fallbackName - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name). + * + * @returns {boolean} - a Boolean indicating whether the attribute exists and, if a truthy comparison value is specified, whether the value of the attribute matches the comparison value. + * @memberof AbstractNode + */ +AbstractNode.prototype.isAttribute = function (name, expectedValue, fallbackName) { + return this['$attr?'](name, expectedValue, fallbackName) +}; - if (!/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/.test(str)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid value for Float(): \"" + (value) + "\"") - } +/** + * Assign the value to the attribute name for the current node. + * + * @param {string} name - The String attribute name to assign + * @param {*} value - The Object value to assign to the attribute (default: '') + * @param {boolean} overwrite - A Boolean indicating whether to assign the attribute if currently present in the attributes JSON (default: true) + * + * @returns {boolean} - a Boolean indicating whether the assignment was performed + * @memberof AbstractNode + */ +AbstractNode.prototype.setAttribute = function (name, value, overwrite) { + if (typeof overwrite === 'undefined') overwrite = true; + return this.$set_attr(name, value, overwrite) +}; - return parseFloat(str); - } +/** + * Remove the attribute from the current node. + * @param {string} name - The String attribute name to remove + * @returns {string} - the previous {string} value, or undefined if the attribute was not present. + * @memberof AbstractNode + */ +AbstractNode.prototype.removeAttribute = function (name) { + const value = this.$remove_attr(name); + return value === Opal.nil ? undefined : value +}; - return $$($nesting, 'Opal')['$coerce_to!'](value, $$($nesting, 'Float'), "to_f"); - - }, $Kernel_Float$34.$$arity = 1); - - Opal.def(self, '$Hash', $Kernel_Hash$35 = function $$Hash(arg) { - var $a, self = this; +/** + * Get the {@link Document} to which this node belongs. + * + * @returns {Document} - the {@link Document} object to which this node belongs. + * @memberof AbstractNode + */ +AbstractNode.prototype.getDocument = function () { + return this.document +}; - - if ($truthy(($truthy($a = arg['$nil?']()) ? $a : arg['$==']([])))) { - return $hash2([], {})}; - if ($truthy($$($nesting, 'Hash')['$==='](arg))) { - return arg}; - return $$($nesting, 'Opal')['$coerce_to!'](arg, $$($nesting, 'Hash'), "to_hash"); - }, $Kernel_Hash$35.$$arity = 1); - - Opal.def(self, '$is_a?', $Kernel_is_a$ques$36 = function(klass) { - var self = this; +/** + * Get the {@link AbstractNode} to which this node is attached. + * + * @memberof AbstractNode + * @returns {AbstractNode} - the {@link AbstractNode} object to which this node is attached, + * or undefined if this node has no parent. + */ +AbstractNode.prototype.getParent = function () { + const parent = this.parent; + return parent === Opal.nil ? undefined : parent +}; - - if (!klass.$$is_class && !klass.$$is_module) { - self.$raise($$($nesting, 'TypeError'), "class or module required"); - } +/** + * @returns {boolean} - true if this {AbstractNode} is an instance of {Inline} + * @memberof AbstractNode + */ +AbstractNode.prototype.isInline = function () { + return this['$inline?']() +}; - return Opal.is_a(self, klass); - - }, $Kernel_is_a$ques$36.$$arity = 1); - - Opal.def(self, '$itself', $Kernel_itself$37 = function $$itself() { - var self = this; +/** + * @returns {boolean} - true if this {AbstractNode} is an instance of {Block} + * @memberof AbstractNode + */ +AbstractNode.prototype.isBlock = function () { + return this['$block?']() +}; - return self - }, $Kernel_itself$37.$$arity = 0); - Opal.alias(self, "kind_of?", "is_a?"); - - Opal.def(self, '$lambda', $Kernel_lambda$38 = function $$lambda() { - var $iter = $Kernel_lambda$38.$$p, block = $iter || nil, self = this; +/** + * Checks if the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value. + * + * @param {string} expectedValue - The expected String value of the role (optional, default: undefined) + * + * @returns {boolean} - a Boolean indicating whether the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value. + * @memberof AbstractNode + */ +AbstractNode.prototype.isRole = function (expectedValue) { + return this['$role?'](expectedValue) +}; - if ($iter) $Kernel_lambda$38.$$p = null; - - - if ($iter) $Kernel_lambda$38.$$p = null;; - return Opal.lambda(block);; - }, $Kernel_lambda$38.$$arity = 0); - - Opal.def(self, '$load', $Kernel_load$39 = function $$load(file) { - var self = this; +/** + * Retrieves the space-separated String role for this node. + * + * @returns {string} - the role as a space-separated String. + * @memberof AbstractNode + */ +AbstractNode.prototype.getRole = function () { + const role = this.$role(); + return role === Opal.nil ? undefined : role +}; - - file = $$($nesting, 'Opal')['$coerce_to!'](file, $$($nesting, 'String'), "to_str"); - return Opal.load(file); - }, $Kernel_load$39.$$arity = 1); - - Opal.def(self, '$loop', $Kernel_loop$40 = function $$loop() { - var $$41, $a, $iter = $Kernel_loop$40.$$p, $yield = $iter || nil, self = this, e = nil; +/** + * Sets the value of the role attribute on this node. + * + * @param {...string|Array<string>} names - A single role name, a space-separated String of role names, an Array of role names or a list of role names + * + * @returns {string} - the value of the role attribute + * @memberof AbstractNode + */ +AbstractNode.prototype.setRole = function (names) { + if (Array.isArray(names) || (typeof names === 'string' && arguments.length === 1)) { + return this['$role='](names) + } + return this['$role='](Array.from(arguments)) +}; - if ($iter) $Kernel_loop$40.$$p = null; - - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["loop"], ($$41 = function(){var self = $$41.$$s || this; +/** + * Checks if the specified role is present in the list of roles for this node. + * + * @param {string} name - The String name of the role to find. + * + * @returns {boolean} - a Boolean indicating whether this node has the specified role. + * @memberof AbstractNode + */ +AbstractNode.prototype.hasRole = function (name) { + return this['$has_role?'](name) +}; - return $$$($$($nesting, 'Float'), 'INFINITY')}, $$41.$$s = self, $$41.$$arity = 0, $$41)) - }; - while ($truthy(true)) { - - try { - Opal.yieldX($yield, []) - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'StopIteration')])) {e = $err; - try { - return e.$result() - } finally { Opal.pop_exception() } - } else { throw $err; } - }; - }; - return self; - }, $Kernel_loop$40.$$arity = 0); - - Opal.def(self, '$nil?', $Kernel_nil$ques$42 = function() { - var self = this; +/** + * Retrieves the String role names for this node as an Array. + * + * @returns {Array<string>} - the role names as a String {Array}, which is empty if the role attribute is absent on this node. + * @memberof AbstractNode + */ +AbstractNode.prototype.getRoles = function () { + return this.$roles() +}; - return false - }, $Kernel_nil$ques$42.$$arity = 0); - Opal.alias(self, "object_id", "__id__"); - - Opal.def(self, '$printf', $Kernel_printf$43 = function $$printf($a) { - var $post_args, args, self = this; +/** + * Adds the given role directly to this node. + * + * @param {string} name - The name of the role to add + * + * @returns {boolean} - a Boolean indicating whether the role was added. + * @memberof AbstractNode + */ +AbstractNode.prototype.addRole = function (name) { + return this.$add_role(name) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(args['$any?']())) { - self.$print($send(self, 'format', Opal.to_a(args)))}; - return nil; - }, $Kernel_printf$43.$$arity = -1); - - Opal.def(self, '$proc', $Kernel_proc$44 = function $$proc() { - var $iter = $Kernel_proc$44.$$p, block = $iter || nil, self = this; +/** + * Public: Removes the given role directly from this node. + * + * @param {string} name - The name of the role to remove + * + * @returns {boolean} - a Boolean indicating whether the role was removed. + * @memberof AbstractNode + */ +AbstractNode.prototype.removeRole = function (name) { + return this.$remove_role(name) +}; - if ($iter) $Kernel_proc$44.$$p = null; - - - if ($iter) $Kernel_proc$44.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to create Proc object without a block") - }; - block.$$is_lambda = false; - return block; - }, $Kernel_proc$44.$$arity = 0); - - Opal.def(self, '$puts', $Kernel_puts$45 = function $$puts($a) { - var $post_args, strs, self = this; - if ($gvars.stdout == null) $gvars.stdout = nil; +/** + * A convenience method that checks if the reftext attribute is defined. + * @returns {boolean} - A Boolean indicating whether the reftext attribute is defined + * @memberof AbstractNode + */ +AbstractNode.prototype.isReftext = function () { + return this['$reftext?']() +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - strs = $post_args;; - return $send($gvars.stdout, 'puts', Opal.to_a(strs)); - }, $Kernel_puts$45.$$arity = -1); - - Opal.def(self, '$p', $Kernel_p$46 = function $$p($a) { - var $post_args, args, $$47, self = this; +/** + * A convenience method that returns the value of the reftext attribute with substitutions applied. + * @returns {string|undefined} - the value of the reftext attribute with substitutions applied. + * @memberof AbstractNode + */ +AbstractNode.prototype.getReftext = function () { + const reftext = this.$reftext(); + return reftext === Opal.nil ? undefined : reftext +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - $send(args, 'each', [], ($$47 = function(obj){var self = $$47.$$s || this; - if ($gvars.stdout == null) $gvars.stdout = nil; +/** + * @returns {string} - Get the context name for this node + * @memberof AbstractNode + */ +AbstractNode.prototype.getContext = function () { + const context = this.context; + // Automatically convert Opal pseudo-symbol to String + return typeof context === 'string' ? context : context.toString() +}; - - - if (obj == null) { - obj = nil; - }; - return $gvars.stdout.$puts(obj.$inspect());}, $$47.$$s = self, $$47.$$arity = 1, $$47)); - if ($truthy($rb_le(args.$length(), 1))) { - return args['$[]'](0) - } else { - return args - }; - }, $Kernel_p$46.$$arity = -1); - - Opal.def(self, '$print', $Kernel_print$48 = function $$print($a) { - var $post_args, strs, self = this; - if ($gvars.stdout == null) $gvars.stdout = nil; +/** + * @returns {string} - the String id of this node + * @memberof AbstractNode + */ +AbstractNode.prototype.getId = function () { + const id = this.id; + return id === Opal.nil ? undefined : id +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - strs = $post_args;; - return $send($gvars.stdout, 'print', Opal.to_a(strs)); - }, $Kernel_print$48.$$arity = -1); - - Opal.def(self, '$warn', $Kernel_warn$49 = function $$warn($a) { - var $post_args, strs, $b, self = this; - if ($gvars.VERBOSE == null) $gvars.VERBOSE = nil; - if ($gvars.stderr == null) $gvars.stderr = nil; +/** + * @param {string} id - the String id of this node + * @memberof AbstractNode + */ +AbstractNode.prototype.setId = function (id) { + this.id = id; +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - strs = $post_args;; - if ($truthy(($truthy($b = $gvars.VERBOSE['$nil?']()) ? $b : strs['$empty?']()))) { - return nil - } else { - return $send($gvars.stderr, 'puts', Opal.to_a(strs)) - }; - }, $Kernel_warn$49.$$arity = -1); - - Opal.def(self, '$raise', $Kernel_raise$50 = function $$raise(exception, string, _backtrace) { - var self = this; - if ($gvars["!"] == null) $gvars["!"] = nil; +/** + * A convenience method to check if the specified option attribute is enabled on the current node. + * Check if the option is enabled. This method simply checks to see if the <name>-option attribute is defined on the current node. + * + * @param {string} name - the String name of the option + * + * @return {boolean} - a Boolean indicating whether the option has been specified + * @memberof AbstractNode + */ +AbstractNode.prototype.isOption = function (name) { + return this['$option?'](name) +}; - - ; - - if (string == null) { - string = nil; - }; - - if (_backtrace == null) { - _backtrace = nil; - }; - - if (exception == null && $gvars["!"] !== nil) { - throw $gvars["!"]; - } - if (exception == null) { - exception = $$($nesting, 'RuntimeError').$new(); - } - else if (exception.$$is_string) { - exception = $$($nesting, 'RuntimeError').$new(exception); - } - // using respond_to? and not an undefined check to avoid method_missing matching as true - else if (exception.$$is_class && exception['$respond_to?']("exception")) { - exception = exception.$exception(string); - } - else if (exception['$is_a?']($$($nesting, 'Exception'))) { - // exception is fine - } - else { - exception = $$($nesting, 'TypeError').$new("exception class/object expected"); - } +/** + * Set the specified option on this node. + * This method sets the specified option on this node by setting the <name>-option attribute. + * + * @param {string} name - the String name of the option + * + * @memberof AbstractNode + */ +AbstractNode.prototype.setOption = function (name) { + return this.$set_option(name) +}; - if ($gvars["!"] !== nil) { - Opal.exceptions.push($gvars["!"]); - } +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.getIconUri = function (name) { + return this.$icon_uri(name) +}; - $gvars["!"] = exception; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.getMediaUri = function (target, assetDirKey) { + return this.$media_uri(target, assetDirKey) +}; - throw exception; - ; - }, $Kernel_raise$50.$$arity = -1); - Opal.alias(self, "fail", "raise"); - - Opal.def(self, '$rand', $Kernel_rand$51 = function $$rand(max) { - var self = this; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.getImageUri = function (targetImage, assetDirKey) { + return this.$image_uri(targetImage, assetDirKey) +}; - - ; - - if (max === undefined) { - return $$$($$($nesting, 'Random'), 'DEFAULT').$rand(); - } +/** + * Get the {Converter} instance being used to convert the current {Document}. + * @returns {Object} + * @memberof AbstractNode + */ +AbstractNode.prototype.getConverter = function () { + return this.$converter() +}; - if (max.$$is_number) { - if (max < 0) { - max = Math.abs(max); - } +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.readContents = function (target, options) { + return this.$read_contents(target, toHash(options)) +}; - if (max % 1 !== 0) { - max = max.$to_i(); - } +/** + * Read the contents of the file at the specified path. + * This method assumes that the path is safe to read. + * It checks that the file is readable before attempting to read it. + * + * @param path - the {string} path from which to read the contents + * @param {Object} options - a JSON {Object} of options to control processing (default: {}) + * @param {boolean} options.warn_on_failure - a {boolean} that controls whether a warning is issued if the file cannot be read (default: false) + * @param {boolean} options.normalize - a {boolean} that controls whether the lines are normalized and coerced to UTF-8 (default: false) + * + * @returns {string} - the String content of the file at the specified path, or undefined if the file does not exist. + * @memberof AbstractNode + */ +AbstractNode.prototype.readAsset = function (path, options) { + const result = this.$read_asset(path, toHash(options)); + return result === Opal.nil ? undefined : result +}; - if (max === 0) { - max = undefined; - } - } - ; - return $$$($$($nesting, 'Random'), 'DEFAULT').$rand(max); - }, $Kernel_rand$51.$$arity = -1); - - Opal.def(self, '$respond_to?', $Kernel_respond_to$ques$52 = function(name, include_all) { - var self = this; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.normalizeWebPath = function (target, start, preserveTargetUri) { + return this.$normalize_web_path(target, start, preserveTargetUri) +}; - - - if (include_all == null) { - include_all = false; - }; - if ($truthy(self['$respond_to_missing?'](name, include_all))) { - return true}; - - var body = self['$' + name]; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.normalizeSystemPath = function (target, start, jail, options) { + return this.$normalize_system_path(target, start, jail, toHash(options)) +}; - if (typeof(body) === "function" && !body.$$stub) { - return true; - } - ; - return false; - }, $Kernel_respond_to$ques$52.$$arity = -2); - - Opal.def(self, '$respond_to_missing?', $Kernel_respond_to_missing$ques$53 = function(method_name, include_all) { - var self = this; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.normalizeAssetPath = function (assetRef, assetName, autoCorrect) { + return this.$normalize_asset_path(assetRef, assetName, autoCorrect) +}; - - - if (include_all == null) { - include_all = false; - }; - return false; - }, $Kernel_respond_to_missing$ques$53.$$arity = -2); - - Opal.def(self, '$require', $Kernel_require$54 = function $$require(file) { - var self = this; +// Document API - - file = $$($nesting, 'Opal')['$coerce_to!'](file, $$($nesting, 'String'), "to_str"); - return Opal.require(file); - }, $Kernel_require$54.$$arity = 1); - - Opal.def(self, '$require_relative', $Kernel_require_relative$55 = function $$require_relative(file) { - var self = this; +/** + * The {@link Document} class represents a parsed AsciiDoc document. + * + * Document is the root node of a parsed AsciiDoc document.<br/> + * It provides an abstract syntax tree (AST) that represents the structure of the AsciiDoc document + * from which the Document object was parsed. + * + * Although the constructor can be used to create an empty document object, + * more commonly, you'll load the document object from AsciiDoc source + * using the primary API methods on {@link Asciidoctor}. + * When using one of these APIs, you almost always want to set the safe mode to 'safe' (or 'unsafe') + * to enable all of Asciidoctor's features. + * + * <pre> + * const doc = Asciidoctor.load('= Hello, AsciiDoc!', { 'safe': 'safe' }) + * // => Asciidoctor::Document { doctype: "article", doctitle: "Hello, AsciiDoc!", blocks: 0 } + * </pre> + * + * Instances of this class can be used to extract information from the document or alter its structure. + * As such, the Document object is most often used in extensions and by integrations. + * + * The most basic usage of the Document object is to retrieve the document's title. + * + * <pre> + * const source = '= Document Title' + * const doc = asciidoctor.load(source, { 'safe': 'safe' }) + * console.log(doc.getTitle()) // 'Document Title' + * </pre> + * + * You can also use the Document object to access document attributes defined in the header, such as the author and doctype. + * @namespace + * @extends AbstractBlock + */ +const Document = Opal.Asciidoctor.Document; - - $$($nesting, 'Opal')['$try_convert!'](file, $$($nesting, 'String'), "to_str"); - file = $$($nesting, 'File').$expand_path($$($nesting, 'File').$join(Opal.current_file, "..", file)); - return Opal.require(file); - }, $Kernel_require_relative$55.$$arity = 1); - - Opal.def(self, '$require_tree', $Kernel_require_tree$56 = function $$require_tree(path) { - var self = this; +/** + * Append a content Block to this Document. + * If the child block is a Section, assign an index to it. + * @param {AbstractBlock} block - the child Block to append to this parent Block + * @returns {AbstractBlock} - the parent block to which this block was appended. + * @memberof Document + */ +Document.prototype.append = function (block) { + this['$<<'](block); + return this +}; - - var result = []; +/** + * Returns the SyntaxHighlighter associated with this document. + * + * @returns {SyntaxHighlighter} - the SyntaxHighlighter associated with this document. + * @memberof Document + */ +Document.prototype.getSyntaxHighlighter = function () { + const syntaxHighlighter = this.syntax_highlighter; + // eslint-disable-next-line no-proto + const prototype = syntaxHighlighter.__proto__; + if (prototype) { + if (typeof prototype['$highlight?'] === 'function') { + prototype.handlesHighlighting = function () { + const value = prototype['$highlight?'](); + return value === Opal.nil ? false : value + }; + } + if (typeof prototype['$docinfo?'] === 'function') { + prototype.hasDocinfo = prototype['$docinfo?']; + } + if (typeof prototype.$format === 'function') { + prototype.format = function (node, lang, opts) { + return this.$format(node, lang, toHash(opts)) + }; + } + if (typeof prototype.$docinfo === 'function') { + prototype.docinfo = function (location, doc, opts) { + return this.$docinfo(location, doc, toHash(opts)) + }; + } + } + return syntaxHighlighter +}; - path = $$($nesting, 'File').$expand_path(path) - path = Opal.normalize(path); - if (path === '.') path = ''; - for (var name in Opal.modules) { - if ((name)['$start_with?'](path)) { - result.push([name, Opal.require(name)]); - } - } +/** + * Returns a JSON {Object} of references captured by the processor. + * + * @returns {Object} - a JSON {Object} of {AbstractNode} in the document. + * @memberof Document + */ +Document.prototype.getRefs = function () { + return fromHash(this.catalog.$$smap.refs) +}; - return result; - - }, $Kernel_require_tree$56.$$arity = 1); - Opal.alias(self, "send", "__send__"); - Opal.alias(self, "public_send", "__send__"); - - Opal.def(self, '$singleton_class', $Kernel_singleton_class$57 = function $$singleton_class() { - var self = this; +/** + * Returns an {Array} of {Document/ImageReference} captured by the processor. + * + * @returns {Array<ImageReference>} - an {Array} of {Document/ImageReference} in the document. + * Will return an empty array if the option "catalog_assets: true" was not defined on the processor. + * @memberof Document + */ +Document.prototype.getImages = function () { + return this.catalog.$$smap.images +}; - return Opal.get_singleton_class(self); - }, $Kernel_singleton_class$57.$$arity = 0); - - Opal.def(self, '$sleep', $Kernel_sleep$58 = function $$sleep(seconds) { - var self = this; +/** + * Returns an {Array} of links captured by the processor. + * + * @returns {Array<string>} - an {Array} of links in the document. + * Will return an empty array if: + * - the function was called before the document was converted + * - the option "catalog_assets: true" was not defined on the processor + * @memberof Document + */ +Document.prototype.getLinks = function () { + return this.catalog.$$smap.links +}; - - - if (seconds == null) { - seconds = nil; - }; - - if (seconds === nil) { - self.$raise($$($nesting, 'TypeError'), "can't convert NilClass into time interval") - } - if (!seconds.$$is_number) { - self.$raise($$($nesting, 'TypeError'), "" + "can't convert " + (seconds.$class()) + " into time interval") - } - if (seconds < 0) { - self.$raise($$($nesting, 'ArgumentError'), "time interval must be positive") - } - var get_time = Opal.global.performance ? - function() {return performance.now()} : - function() {return new Date()} +/** + * @returns {boolean} - true if the document has footnotes otherwise false + * @memberof Document + */ +Document.prototype.hasFootnotes = function () { + return this['$footnotes?']() +}; - var t = get_time(); - while (get_time() - t <= seconds * 1000); - return seconds; - ; - }, $Kernel_sleep$58.$$arity = -1); - - Opal.def(self, '$srand', $Kernel_srand$59 = function $$srand(seed) { - var self = this; +/** + * Returns an {Array} of {Document/Footnote} captured by the processor. + * + * @returns {Array<Footnote>} - an {Array} of {Document/Footnote} in the document. + * Will return an empty array if the function was called before the document was converted. + * @memberof Document + */ +Document.prototype.getFootnotes = function () { + return this.$footnotes() +}; - - - if (seed == null) { - seed = $$($nesting, 'Random').$new_seed(); - }; - return $$($nesting, 'Random').$srand(seed); - }, $Kernel_srand$59.$$arity = -1); - - Opal.def(self, '$String', $Kernel_String$60 = function $$String(str) { - var $a, self = this; +/** + * Returns the level-0 {Section} (i.e. the document title). + * Only stores the title, not the header attributes. + * + * @returns {string} - the level-0 {Section}. + * @memberof Document + */ +Document.prototype.getHeader = function () { + return this.header +}; - return ($truthy($a = $$($nesting, 'Opal')['$coerce_to?'](str, $$($nesting, 'String'), "to_str")) ? $a : $$($nesting, 'Opal')['$coerce_to!'](str, $$($nesting, 'String'), "to_s")) - }, $Kernel_String$60.$$arity = 1); - - Opal.def(self, '$tap', $Kernel_tap$61 = function $$tap() { - var $iter = $Kernel_tap$61.$$p, block = $iter || nil, self = this; +/** + * @memberof Document + */ +Document.prototype.setAttribute = function (name, value) { + return this.$set_attribute(name, value) +}; - if ($iter) $Kernel_tap$61.$$p = null; - - - if ($iter) $Kernel_tap$61.$$p = null;; - Opal.yield1(block, self); - return self; - }, $Kernel_tap$61.$$arity = 0); - - Opal.def(self, '$to_proc', $Kernel_to_proc$62 = function $$to_proc() { - var self = this; +/** - return self - }, $Kernel_to_proc$62.$$arity = 0); - - Opal.def(self, '$to_s', $Kernel_to_s$63 = function $$to_s() { - var self = this; + * @memberof Document + */ +Document.prototype.removeAttribute = function (name) { + this.attributes.$delete(name); + this.attribute_overrides.$delete(name); +}; - return "" + "#<" + (self.$class()) + ":0x" + (self.$__id__().$to_s(16)) + ">" - }, $Kernel_to_s$63.$$arity = 0); - - Opal.def(self, '$catch', $Kernel_catch$64 = function(sym) { - var $iter = $Kernel_catch$64.$$p, $yield = $iter || nil, self = this, e = nil; +/** + * Convert the AsciiDoc document using the templates loaded by the Converter. + * If a "template_dir" is not specified, or a template is missing, the converter will fall back to using the appropriate built-in template. + * + * @param {Object} [options] - a JSON of options to control processing (default: {}) + * + * @returns {string} + * @memberof Document + */ +Document.prototype.convert = function (options) { + const result = this.$convert(toHash(options)); + return result === Opal.nil ? '' : result +}; - if ($iter) $Kernel_catch$64.$$p = null; - try { - return Opal.yieldX($yield, []); - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'UncaughtThrowError')])) {e = $err; - try { - - if (e.$sym()['$=='](sym)) { - return e.$arg()}; - return self.$raise(); - } finally { Opal.pop_exception() } - } else { throw $err; } - } - }, $Kernel_catch$64.$$arity = 1); - - Opal.def(self, '$throw', $Kernel_throw$65 = function($a) { - var $post_args, args, self = this; +/** + * Write the output to the specified file. + * + * If the converter responds to "write", delegate the work of writing the file to that method. + * Otherwise, write the output the specified file. + * + * @param {string} output + * @param {string} target + * + * @memberof Document + */ +Document.prototype.write = function (output, target) { + return this.$write(output, target) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return self.$raise($$($nesting, 'UncaughtThrowError'), args); - }, $Kernel_throw$65.$$arity = -1); - - Opal.def(self, '$open', $Kernel_open$66 = function $$open($a) { - var $iter = $Kernel_open$66.$$p, block = $iter || nil, $post_args, args, self = this; +/** + * @returns {string} - the full name of the author as a String + * @memberof Document + */ +Document.prototype.getAuthor = function () { + return this.$author() +}; - if ($iter) $Kernel_open$66.$$p = null; - - - if ($iter) $Kernel_open$66.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send($$($nesting, 'File'), 'open', Opal.to_a(args), block.$to_proc()); - }, $Kernel_open$66.$$arity = -1); - - Opal.def(self, '$yield_self', $Kernel_yield_self$67 = function $$yield_self() { - var $$68, $iter = $Kernel_yield_self$67.$$p, $yield = $iter || nil, self = this; +/** + * @returns {string} + * @memberof Document + */ +Document.prototype.getSource = function () { + return this.$source() +}; - if ($iter) $Kernel_yield_self$67.$$p = null; - - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["yield_self"], ($$68 = function(){var self = $$68.$$s || this; +/** + * @returns {Array<string>} + * @memberof Document + */ +Document.prototype.getSourceLines = function () { + return this.$source_lines() +}; - return 1}, $$68.$$s = self, $$68.$$arity = 0, $$68)) - }; - return Opal.yield1($yield, self);; - }, $Kernel_yield_self$67.$$arity = 0); - })($nesting[0], $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Object'); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.isNested = function () { + return this['$nested?']() +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.isEmbedded = function () { + return this['$embedded?']() +}; - return self.$include($$($nesting, 'Kernel')) - })($nesting[0], null, $nesting); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.hasExtensions = function () { + return this['$extensions?']() }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/error"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send, $truthy = Opal.truthy, $module = Opal.module, $hash2 = Opal.hash2; +/** + * Get the value of the doctype attribute for this document. + * @returns {string} + * @memberof Document + */ +Document.prototype.getDoctype = function () { + return this.doctype +}; - Opal.add_stubs(['$new', '$clone', '$to_s', '$empty?', '$class', '$raise', '$+', '$attr_reader', '$[]', '$>', '$length', '$inspect']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Exception'); +/** + * Get the value of the backend attribute for this document. + * @returns {string} + * @memberof Document + */ +Document.prototype.getBackend = function () { + return this.backend +}; - var $nesting = [self].concat($parent_nesting), $Exception_new$1, $Exception_exception$2, $Exception_initialize$3, $Exception_backtrace$4, $Exception_exception$5, $Exception_message$6, $Exception_inspect$7, $Exception_set_backtrace$8, $Exception_to_s$9; +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.isBasebackend = function (base) { + return this['$basebackend?'](base) +}; - self.$$prototype.message = nil; - - var stack_trace_limit; - Opal.defs(self, '$new', $Exception_new$1 = function($a) { - var $post_args, args, self = this; +/** + * Get the title explicitly defined in the document attributes. + * @returns {string} + * @see {@link AbstractNode#getAttributes} + * @memberof Document + */ +Document.prototype.getTitle = function () { + const title = this.$title(); + return title === Opal.nil ? undefined : title +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var message = (args.length > 0) ? args[0] : nil; - var error = new self.$$constructor(message); - error.name = self.$$name; - error.message = message; - Opal.send(error, error.$initialize, args); +/** + * Set the title on the document header + * + * Set the title of the document header to the specified value. + * If the header does not exist, it is first created. + * + * @param {string} title - the String title to assign as the title of the document header + * + * @returns {string} - the new String title assigned to the document header + * @memberof Document + */ +Document.prototype.setTitle = function (title) { + return this['$title='](title) +}; - // Error.captureStackTrace() will use .name and .toString to build the - // first line of the stack trace so it must be called after the error - // has been initialized. - // https://nodejs.org/dist/latest-v6.x/docs/api/errors.html - if (Opal.config.enable_stack_trace && Error.captureStackTrace) { - // Passing Kernel.raise will cut the stack trace from that point above - Error.captureStackTrace(error, stack_trace_limit); - } +/** + * @returns {Document/Title} - a {@link Document/Title} + * @memberof Document + */ +Document.prototype.getDocumentTitle = function (options) { + const doctitle = this.$doctitle(toHash(options)); + return doctitle === Opal.nil ? undefined : doctitle +}; - return error; - ; - }, $Exception_new$1.$$arity = -1); - stack_trace_limit = self.$new; - Opal.defs(self, '$exception', $Exception_exception$2 = function $$exception($a) { - var $post_args, args, self = this; +/** + * @see {@link Document#getDocumentTitle} + * @memberof Document + */ +Document.prototype.getDoctitle = Document.prototype.getDocumentTitle; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'new', Opal.to_a(args)); - }, $Exception_exception$2.$$arity = -1); - - Opal.def(self, '$initialize', $Exception_initialize$3 = function $$initialize($a) { - var $post_args, args, self = this; +/** + * Get the document catalog JSON object. + * @returns {Object} + * @memberof Document + */ +Document.prototype.getCatalog = function () { + return fromHash(this.catalog) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return self.message = (args.length > 0) ? args[0] : nil;; - }, $Exception_initialize$3.$$arity = -1); - - Opal.def(self, '$backtrace', $Exception_backtrace$4 = function $$backtrace() { - var self = this; +/** + * + * @returns {Object} + * @see Document#getCatalog + * @memberof Document + */ +Document.prototype.getReferences = Document.prototype.getCatalog; - - if (self.backtrace) { - // nil is a valid backtrace - return self.backtrace; - } +/** + * Get the document revision date from document header (document attribute <code>revdate</code>). + * @returns {string} + * @memberof Document + */ +Document.prototype.getRevisionDate = function () { + return this.getAttribute('revdate') +}; - var backtrace = self.stack; +/** + * @see Document#getRevisionDate + * @returns {string} + * @memberof Document + */ +Document.prototype.getRevdate = function () { + return this.getRevisionDate() +}; - if (typeof(backtrace) === 'string') { - return backtrace.split("\n").slice(0, 15); - } - else if (backtrace) { - return backtrace.slice(0, 15); - } +/** + * Get the document revision number from document header (document attribute <code>revnumber</code>). + * @returns {string} + * @memberof Document + */ +Document.prototype.getRevisionNumber = function () { + return this.getAttribute('revnumber') +}; - return []; - - }, $Exception_backtrace$4.$$arity = 0); - - Opal.def(self, '$exception', $Exception_exception$5 = function $$exception(str) { - var self = this; +/** + * Get the document revision remark from document header (document attribute <code>revremark</code>). + * @returns {string} + * @memberof Document + */ +Document.prototype.getRevisionRemark = function () { + return this.getAttribute('revremark') +}; - - - if (str == null) { - str = nil; - }; - - if (str === nil || self === str) { - return self; - } +/** + * Assign a value to the specified attribute in the document header. + * + * The assignment will be visible when the header attributes are restored, + * typically between processor phases (e.g., between parse and convert). + * + * @param {string} name - The {string} attribute name to assign + * @param {Object} value - The {Object} value to assign to the attribute (default: '') + * @param {boolean} overwrite - A {boolean} indicating whether to assign the attribute + * if already present in the attributes Hash (default: true) + * + * @returns {boolean} - true if the assignment was performed otherwise false + * @memberof Document + */ +Document.prototype.setHeaderAttribute = function (name, value, overwrite) { + if (typeof overwrite === 'undefined') overwrite = true; + if (typeof value === 'undefined') value = ''; + return this.$set_header_attribute(name, value, overwrite) +}; - var cloned = self.$clone(); - cloned.message = str; - return cloned; - ; - }, $Exception_exception$5.$$arity = -1); - - Opal.def(self, '$message', $Exception_message$6 = function $$message() { - var self = this; +/** + * Convenience method to retrieve the authors of this document as an {Array} of {Document/Author} objects. + * + * This method is backed by the author-related attributes on the document. + * + * @returns {Array<Author>} - an {Array} of {Document/Author} objects. + * @memberof Document + */ +Document.prototype.getAuthors = function () { + return this.$authors() +}; - return self.$to_s() - }, $Exception_message$6.$$arity = 0); - - Opal.def(self, '$inspect', $Exception_inspect$7 = function $$inspect() { - var self = this, as_str = nil; +// Document.Footnote API - - as_str = self.$to_s(); - if ($truthy(as_str['$empty?']())) { - return self.$class().$to_s() - } else { - return "" + "#<" + (self.$class().$to_s()) + ": " + (self.$to_s()) + ">" - }; - }, $Exception_inspect$7.$$arity = 0); - - Opal.def(self, '$set_backtrace', $Exception_set_backtrace$8 = function $$set_backtrace(backtrace) { - var self = this; +/** + * @namespace + * @module Document/Footnote + */ +const Footnote = Document.Footnote; - - var valid = true, i, ii; +/** + * @returns {number} - the footnote's index + * @memberof Document/Footnote + */ +Footnote.prototype.getIndex = function () { + const index = this.$$data.index; + return index === Opal.nil ? undefined : index +}; + +/** + * @returns {number} - the footnote's id + * @memberof Document/Footnote + */ +Footnote.prototype.getId = function () { + const id = this.$$data.id; + return id === Opal.nil ? undefined : id +}; - if (backtrace === nil) { - self.backtrace = nil; - } else if (backtrace.$$is_string) { - self.backtrace = [backtrace]; - } else { - if (backtrace.$$is_array) { - for (i = 0, ii = backtrace.length; i < ii; i++) { - if (!backtrace[i].$$is_string) { - valid = false; - break; - } - } - } else { - valid = false; - } +/** + * @returns {string} - the footnote's text + * @memberof Document/Footnote + */ +Footnote.prototype.getText = function () { + const text = this.$$data.text; + return text === Opal.nil ? undefined : text +}; - if (valid === false) { - self.$raise($$($nesting, 'TypeError'), "backtrace must be Array of String") - } +// Document.ImageReference API - self.backtrace = backtrace; - } +/** + * @class + * @module Document/ImageReference + */ +const ImageReference = Document.ImageReference; - return backtrace; - - }, $Exception_set_backtrace$8.$$arity = 1); - return (Opal.def(self, '$to_s', $Exception_to_s$9 = function $$to_s() { - var $a, $b, self = this; +/** + * @returns {string} - the image's target + * @memberof Document/ImageReference + */ +ImageReference.prototype.getTarget = function () { + return this.$$data.target +}; - return ($truthy($a = ($truthy($b = self.message) ? self.message.$to_s() : $b)) ? $a : self.$class().$to_s()) - }, $Exception_to_s$9.$$arity = 0), nil) && 'to_s'; - })($nesting[0], Error, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'ScriptError'); +/** + * @returns {string} - the image's directory (imagesdir attribute) + * @memberof Document/ImageReference + */ +ImageReference.prototype.getImagesDirectory = function () { + const value = this.$$data.imagesdir; + return value === Opal.nil ? undefined : value +}; - var $nesting = [self].concat($parent_nesting); +// Document.Author API - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SyntaxError'); +/** + * The Author class represents information about an author extracted from document attributes. + * @namespace + * @module Document/Author + */ +const Author = Document.Author; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {string} - the author's full name + * @memberof Document/Author + */ +Author.prototype.getName = function () { + const name = this.$$data.name; + return name === Opal.nil ? undefined : name +}; - return nil - })($nesting[0], $$($nesting, 'ScriptError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'LoadError'); +/** + * @returns {string} - the author's first name + * @memberof Document/Author + */ +Author.prototype.getFirstName = function () { + const firstName = this.$$data.firstname; + return firstName === Opal.nil ? undefined : firstName +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {string} - the author's middle name (or undefined if the author has no middle name) + * @memberof Document/Author + */ +Author.prototype.getMiddleName = function () { + const middleName = this.$$data.middlename; + return middleName === Opal.nil ? undefined : middleName +}; - return nil - })($nesting[0], $$($nesting, 'ScriptError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NotImplementedError'); +/** + * @returns {string} - the author's last name + * @memberof Document/Author + */ +Author.prototype.getLastName = function () { + const lastName = this.$$data.lastname; + return lastName === Opal.nil ? undefined : lastName +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {string} - the author's initials (by default based on the author's name) + * @memberof Document/Author + */ +Author.prototype.getInitials = function () { + const initials = this.$$data.initials; + return initials === Opal.nil ? undefined : initials +}; - return nil - })($nesting[0], $$($nesting, 'ScriptError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SystemExit'); +/** + * @returns {string} - the author's email + * @memberof Document/Author + */ +Author.prototype.getEmail = function () { + const email = this.$$data.email; + return email === Opal.nil ? undefined : email +}; - var $nesting = [self].concat($parent_nesting); +// private constructor +Document.RevisionInfo = function (date, number, remark) { + this.date = date; + this.number = number; + this.remark = remark; +}; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NoMemoryError'); +/** + * @class + * @namespace + * @module Document/RevisionInfo + */ +const RevisionInfo = Document.RevisionInfo; - var $nesting = [self].concat($parent_nesting); +/** + * Get the document revision date from document header (document attribute <code>revdate</code>). + * @returns {string} + * @memberof Document/RevisionInfo + */ +RevisionInfo.prototype.getDate = function () { + return this.date +}; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SignalException'); +/** + * Get the document revision number from document header (document attribute <code>revnumber</code>). + * @returns {string} + * @memberof Document/RevisionInfo + */ +RevisionInfo.prototype.getNumber = function () { + return this.number +}; - var $nesting = [self].concat($parent_nesting); +/** + * Get the document revision remark from document header (document attribute <code>revremark</code>). + * A short summary of changes in this document revision. + * @returns {string} + * @memberof Document/RevisionInfo + */ +RevisionInfo.prototype.getRemark = function () { + return this.remark +}; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Interrupt'); +/** + * @returns {boolean} - true if the revision info is empty (ie. not defined), otherwise false + * @memberof Document/RevisionInfo + */ +RevisionInfo.prototype.isEmpty = function () { + return this.date === undefined && this.number === undefined && this.remark === undefined +}; - var $nesting = [self].concat($parent_nesting); +// SafeMode API - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SecurityError'); +/** + * @namespace + */ +const SafeMode = Opal.Asciidoctor.SafeMode; - var $nesting = [self].concat($parent_nesting); +/** + * @param {string} name - the name of the security level + * @returns {number} - the integer value of the corresponding security level + */ +SafeMode.getValueForName = function (name) { + return this.$value_for_name(name) +}; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'StandardError'); +/** + * @param {number} value - the integer value of the security level + * @returns {string} - the name of the corresponding security level + */ +SafeMode.getNameForValue = function (value) { + const name = this.$name_for_value(value); + return name === Opal.nil ? undefined : name +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {Array<string>} - the String {Array} of security levels + */ +SafeMode.getNames = function () { + return this.$names() +}; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'EncodingError'); +// Callouts API - var $nesting = [self].concat($parent_nesting); +/** + * Maintains a catalog of callouts and their associations. + * @namespace + */ +const Callouts = Opal.Asciidoctor.Callouts; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'ZeroDivisionError'); +/** + * Create a new Callouts. + * @returns {Callouts} - a new Callouts + * @memberof Callouts + */ +Callouts.create = function () { + return this.$new() +}; - var $nesting = [self].concat($parent_nesting); +/** + * Register a new callout for the given list item ordinal. + * Generates a unique id for this callout based on the index of the next callout list in the document and the index of this callout since the end of the last callout list. + * + * @param {number} ordinal - the Integer ordinal (1-based) of the list item to which this callout is to be associated + * @returns {string} - The unique String id of this callout + * @example + * callouts = asciidoctor.Callouts.create() + * callouts.register(1) + * // => "CO1-1" + * callouts.nextList() + * callouts.register(2) + * // => "CO2-1" + * @memberof Callouts + */ - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NameError'); +Callouts.prototype.register = function (ordinal) { + return this.$register(ordinal) +}; +/** + * Get the next callout index in the document. + * + * Reads the next callout index in the document and advances the pointer. + * This method is used during conversion to retrieve the unique id of the callout that was generated during parsing. + * + * @returns {string} - The unique String id of the next callout in the document + * @memberof Callouts + */ +Callouts.prototype.readNextId = function () { + return this.$read_next_id() +}; - var $nesting = [self].concat($parent_nesting); +/** + * et a space-separated list of callout ids for the specified list item. + * @param {number} ordinal - the Integer ordinal (1-based) of the list item for which to retrieve the callouts + * @returns {string} - a space-separated String of callout ids associated with the specified list item + * @memberof Callouts + */ +Callouts.prototype.getCalloutIds = function (ordinal) { + return this.$callout_ids(ordinal) +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NoMethodError'); +/** + * @memberof Callouts + */ +Callouts.prototype.getLists = function () { + const lists = this.lists; + if (lists && lists.length > 0) { + for (let i = 0; i < lists.length; i++) { + const list = lists[i]; + if (list && list.length > 0) { + for (let j = 0; j < list.length; j++) { + if (typeof list[j] === 'object' && '$$smap' in list[j]) { + list[j] = fromHash(list[j]); + } + } + } + } + } + return lists +}; - var $nesting = [self].concat($parent_nesting); +/** + * @memberof Callouts + */ +Callouts.prototype.getListIndex = function () { + return this.list_index +}; - return nil - })($nesting[0], $$($nesting, 'NameError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'RuntimeError'); +/** + * The current list for which callouts are being collected. + * @returns {Array} - The Array of callouts at the position of the list index pointer + * @memberof Callouts + */ +Callouts.prototype.getCurrentList = function () { + const currentList = this.$current_list(); + if (currentList && currentList.length > 0) { + for (let i = 0; i < currentList.length; i++) { + if (typeof currentList[i] === 'object' && '$$smap' in currentList[i]) { + currentList[i] = fromHash(currentList[i]); + } + } + } + return currentList +}; - var $nesting = [self].concat($parent_nesting); +/** + * Advance to the next callout list in the document. + * @memberof Callouts + */ +Callouts.prototype.nextList = function () { + return this.$nextList() +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'FrozenError'); +/** + * Rewind the list index pointer, intended to be used when switching from the parsing to conversion phase. + * @memberof Callouts + */ +Callouts.prototype.rewind = function () { + return this.$rewind() +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {Document/RevisionInfo} - a {@link Document/RevisionInfo} + * @memberof Document + */ +Document.prototype.getRevisionInfo = function () { + return new Document.RevisionInfo(this.getRevisionDate(), this.getRevisionNumber(), this.getRevisionRemark()) +}; - return nil - })($nesting[0], $$($nesting, 'RuntimeError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'LocalJumpError'); +/** + * @returns {boolean} - true if the document contains revision info, otherwise false + * @memberof Document + */ +Document.prototype.hasRevisionInfo = function () { + const revisionInfo = this.getRevisionInfo(); + return !revisionInfo.isEmpty() +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.getNotitle = function () { + return this.$notitle() +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'TypeError'); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.getNoheader = function () { + return this.$noheader() +}; - var $nesting = [self].concat($parent_nesting); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.getNofooter = function () { + return this.$nofooter() +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'ArgumentError'); +/** + * @returns {boolean} + * @memberof Document + */ +Document.prototype.hasHeader = function () { + return this['$header?']() +}; - var $nesting = [self].concat($parent_nesting); +/** + * Replay attribute assignments at the block level. + * + * <i>This method belongs to an internal API that deals with how attributes are managed by the processor.</i> + * If you understand why this group of methods are necessary, and what they do, feel free to use them. + * <strong>However, keep in mind they are subject to change at any time.</strong> + * + * @param {Object} blockAttributes - A JSON of attributes + * @memberof Document + */ +Document.prototype.playbackAttributes = function (blockAttributes) { + blockAttributes = toHash(blockAttributes); + if (blockAttributes) { + const attrEntries = blockAttributes['$[]']('attribute_entries'); + if (attrEntries && Array.isArray(attrEntries)) { + const result = []; + for (let i = 0; i < attrEntries.length; i++) { + const attrEntryObject = attrEntries[i]; + if (attrEntryObject && typeof attrEntryObject === 'object' && attrEntryObject.constructor.name === 'Object') { + attrEntryObject.$name = function () { + return this.name + }; + attrEntryObject.$value = function () { + return this.value + }; + attrEntryObject.$negate = function () { + return this.negate + }; + } + result.push(attrEntryObject); + } + blockAttributes['$[]=']('attribute_entries', result); + } + } + this.$playback_attributes(blockAttributes); +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IndexError'); +/** + * Delete the specified attribute from the document if the name is not locked. + * If the attribute is locked, false is returned. + * Otherwise, the attribute is deleted. + * + * @param {string} name - the String attribute name + * + * @returns {boolean} - true if the attribute was deleted, false if it was not because it's locked + * @memberof Document + */ +Document.prototype.deleteAttribute = function (name) { + return this.$delete_attribute(name) +}; - var $nesting = [self].concat($parent_nesting); +/** + * Determine if the attribute has been locked by being assigned in document options. + * + * @param {string} key - The attribute key to check + * + * @returns {boolean} - true if the attribute is locked, false otherwise + * @memberof Document + */ +Document.prototype.isAttributeLocked = function (key) { + return this['$attribute_locked?'](key) +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'StopIteration'); +/** + * Restore the attributes to the previously saved state (attributes in header). + * + * @memberof Document + */ +Document.prototype.restoreAttributes = function () { + return this.$restore_attributes() +}; - var $nesting = [self].concat($parent_nesting); +/** + * Parse the AsciiDoc source stored in the {Reader} into an abstract syntax tree. + * + * If the data parameter is not nil, create a new {PreprocessorReader} and assigned it to the reader property of this object. + * Otherwise, continue with the reader that was created when the {Document} was instantiated. + * Pass the reader to {Parser.parse} to parse the source data into an abstract syntax tree. + * + * If parsing has already been performed, this method returns without performing any processing. + * + * @param {string|Array<string>} [data] - The optional replacement AsciiDoc source data as a String or String Array. (default: undefined) + * + * @returns {Document} - this {Document} + * @memberof Document + */ +Document.prototype.parse = function (data) { + return this.$parse(data) +}; - return nil - })($nesting[0], $$($nesting, 'IndexError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'KeyError'); +/** + * Read the docinfo file(s) for inclusion in the document template + * + * If the docinfo1 attribute is set, read the docinfo.ext file. + * If the docinfo attribute is set, read the doc-name.docinfo.ext file. + * If the docinfo2 attribute is set, read both files in that order. + * + * @param {string} docinfoLocation - The Symbol location of the docinfo (e.g., head, footer, etc). (default: head) + * @param {string|undefined} suffix - The suffix of the docinfo file(s). + * If not set, the extension will be set to the outfilesuffix. (default: undefined) + * + * @returns {string} - the contents of the docinfo file(s) or empty string if no files are found or the safe mode is secure or greater. + * @memberof Document + */ +Document.prototype.getDocinfo = function (docinfoLocation, suffix) { + return this.$docinfo(docinfoLocation, suffix) +}; - var $nesting = [self].concat($parent_nesting); +/** + * @param {string} [docinfoLocation] - A {string} for checking docinfo extensions at a given location (head or footer) (default: head) + * @returns {boolean} + * @memberof Document + */ +Document.prototype.hasDocinfoProcessors = function (docinfoLocation) { + return this['$docinfo_processors?'](docinfoLocation) +}; - return nil - })($nesting[0], $$($nesting, 'IndexError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'RangeError'); +/** + * Increment the specified counter and store it in the block's attributes. + * + * @param {string} counterName - the String name of the counter attribute + * @param {Block} block - the {Block} on which to save the counter + * + * @returns {number} - the next number in the sequence for the specified counter + * @memberof Document + */ +Document.prototype.incrementAndStoreCounter = function (counterName, block) { + return this.$increment_and_store_counter(counterName, block) +}; - var $nesting = [self].concat($parent_nesting); +/** + * @deprecated Please use {Document#incrementAndStoreCounter} method. + * @memberof Document + */ +Document.prototype.counterIncrement = Document.prototype.incrementAndStoreCounter; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'FloatDomainError'); +/** + * Get the named counter and take the next number in the sequence. + * + * @param {string} name - the String name of the counter + * @param {string|number} seed - the initial value as a String or Integer + * + * @returns {number} the next number in the sequence for the specified counter + * @memberof Document + */ +Document.prototype.counter = function (name, seed) { + return this.$counter(name, seed) +}; - var $nesting = [self].concat($parent_nesting); +/** + * A read-only integer value indicating the level of security that should be enforced while processing this document. + * The value must be set in the Document constructor using the "safe" option. + * + * A value of 0 (UNSAFE) disables any of the security features enforced by Asciidoctor. + * + * A value of 1 (SAFE) closely parallels safe mode in AsciiDoc. + * In particular, it prevents access to files which reside outside of the parent directory of the source file and disables any macro other than the include directive. + * + * A value of 10 (SERVER) disallows the document from setting attributes that would affect the conversion of the document, + * in addition to all the security features of SafeMode.SAFE. + * For instance, this level forbids changing the backend or source-highlighter using an attribute defined in the source document header. + * This is the most fundamental level of security for server deployments (hence the name). + * + * A value of 20 (SECURE) disallows the document from attempting to read files from the file system and including the contents of them into the document, + * in addition to all the security features of SafeMode.SECURE. + * In particular, it disallows use of the include::[] directive and the embedding of binary content (data uri), stylesheets and JavaScripts referenced by the document. + * (Asciidoctor and trusted extensions may still be allowed to embed trusted content into the document). + * + * Since Asciidoctor is aiming for wide adoption, 20 (SECURE) is the default value and is recommended for server deployments. + * + * A value of 100 (PARANOID) is planned to disallow the use of passthrough macros and prevents the document from setting any known attributes, + * in addition to all the security features of SafeMode.SECURE. + * Please note that this level is not currently implemented (and therefore not enforced)! + * + * @returns {number} - An integer value indicating the level of security + * @memberof Document + */ +Document.prototype.getSafe = function () { + return this.safe +}; - return nil - })($nesting[0], $$($nesting, 'RangeError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IOError'); +/** + * Get the Boolean AsciiDoc compatibility mode. + * Enabling this attribute activates the following syntax changes: + * + * * single quotes as constrained emphasis formatting marks + * * single backticks parsed as inline literal, formatted as monospace + * * single plus parsed as constrained, monospaced inline formatting + * * double plus parsed as constrained, monospaced inline formatting + * + * @returns {boolean} + * @memberof Document + */ +Document.prototype.getCompatMode = function () { + return this.compat_mode +}; - var $nesting = [self].concat($parent_nesting); +/** + * Get the Boolean flag that indicates whether source map information should be tracked by the parser. + * @returns {boolean} + * @memberof Document + */ +Document.prototype.getSourcemap = function () { + const sourcemap = this.sourcemap; + return sourcemap === Opal.nil ? false : sourcemap +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SystemCallError'); +/** + * Set the Boolean flag that indicates whether source map information should be tracked by the parser. + * @param {boolean} value + * @memberof Document + */ +Document.prototype.setSourcemap = function (value) { + this.sourcemap = value; +}; - var $nesting = [self].concat($parent_nesting); +/** + * Get the JSON of document counters. + * @returns {Object} + * @memberof Document + */ +Document.prototype.getCounters = function () { + return fromHash(this.counters) +}; - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Errno'); +/** + * @returns {Object} + * @memberof Document + */ +Document.prototype.getCallouts = function () { + return this.$callouts() +}; - var $nesting = [self].concat($parent_nesting); +/** + * Get the String base directory for converting this document. + * + * Defaults to directory of the source file. + * If the source is a string, defaults to the current directory. + * @returns {string} + * @memberof Document + */ +Document.prototype.getBaseDir = function () { + return this.base_dir +}; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'EINVAL'); +/** + * Get the JSON of resolved options used to initialize this {Document}. + * @returns {Object} + * @memberof Document + */ +Document.prototype.getOptions = function () { + return fromHash(this.options) +}; - var $nesting = [self].concat($parent_nesting), $EINVAL_new$10; +/** + * Get the outfilesuffix defined at the end of the header. + * @returns {string} + * @memberof Document + */ +Document.prototype.getOutfilesuffix = function () { + return this.outfilesuffix +}; - return (Opal.defs(self, '$new', $EINVAL_new$10 = function(name) { - var $iter = $EINVAL_new$10.$$p, $yield = $iter || nil, self = this, message = nil; +/** + * Get a reference to the parent Document of this nested document. + * @returns {Document|undefined} + * @memberof Document + */ +Document.prototype.getParentDocument = function () { + const parentDocument = this.parent_document; + return parentDocument === Opal.nil ? undefined : parentDocument +}; - if ($iter) $EINVAL_new$10.$$p = null; - - - if (name == null) { - name = nil; - }; - message = "Invalid argument"; - if ($truthy(name)) { - message = $rb_plus(message, "" + " - " + (name))}; - return $send(self, Opal.find_super_dispatcher(self, 'new', $EINVAL_new$10, false, self.$$class.$$prototype), [message], null); - }, $EINVAL_new$10.$$arity = -1), nil) && 'new' - })($nesting[0], $$($nesting, 'SystemCallError'), $nesting) - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'UncaughtThrowError'); +/** + * Get the {Reader} associated with this document. + * @returns {Object} + * @memberof Document + */ +Document.prototype.getReader = function () { + return this.reader +}; - var $nesting = [self].concat($parent_nesting), $UncaughtThrowError_initialize$11; +/** + * Get the {Converter} instance being used to convert the current {Document}. + * @returns {Object} + * @memberof Document + */ +Document.prototype.getConverter = function () { + return this.converter +}; - self.$$prototype.sym = nil; - - self.$attr_reader("sym", "arg"); - return (Opal.def(self, '$initialize', $UncaughtThrowError_initialize$11 = function $$initialize(args) { - var $iter = $UncaughtThrowError_initialize$11.$$p, $yield = $iter || nil, self = this; +/** + * Get the activated {Extensions.Registry} associated with this document. + * @returns {Extensions/Registry} + * @memberof Document + */ +Document.prototype.getExtensions = function () { + const extensions = this.extensions; + return extensions === Opal.nil ? undefined : extensions +}; - if ($iter) $UncaughtThrowError_initialize$11.$$p = null; - - self.sym = args['$[]'](0); - if ($truthy($rb_gt(args.$length(), 1))) { - self.arg = args['$[]'](1)}; - return $send(self, Opal.find_super_dispatcher(self, 'initialize', $UncaughtThrowError_initialize$11, false), ["" + "uncaught throw " + (self.sym.$inspect())], null); - }, $UncaughtThrowError_initialize$11.$$arity = 1), nil) && 'initialize'; - })($nesting[0], $$($nesting, 'ArgumentError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NameError'); +// Document.Title API - var $nesting = [self].concat($parent_nesting), $NameError_initialize$12; +/** + * A partitioned title (i.e., title & subtitle). + * @namespace + * @module Document/Title + */ +const Title = Document.Title; - - self.$attr_reader("name"); - return (Opal.def(self, '$initialize', $NameError_initialize$12 = function $$initialize(message, name) { - var $iter = $NameError_initialize$12.$$p, $yield = $iter || nil, self = this; +/** + * @returns {string} + * @memberof Document/Title + */ +Title.prototype.getMain = function () { + return this.main +}; - if ($iter) $NameError_initialize$12.$$p = null; - - - if (name == null) { - name = nil; - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $NameError_initialize$12, false), [message], null); - return (self.name = name); - }, $NameError_initialize$12.$$arity = -2), nil) && 'initialize'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NoMethodError'); +/** + * @returns {string} + * @memberof Document/Title + */ +Title.prototype.getCombined = function () { + return this.combined +}; - var $nesting = [self].concat($parent_nesting), $NoMethodError_initialize$13; +/** + * @returns {string} + * @memberof Document/Title + */ +Title.prototype.getSubtitle = function () { + const subtitle = this.subtitle; + return subtitle === Opal.nil ? undefined : subtitle +}; - - self.$attr_reader("args"); - return (Opal.def(self, '$initialize', $NoMethodError_initialize$13 = function $$initialize(message, name, args) { - var $iter = $NoMethodError_initialize$13.$$p, $yield = $iter || nil, self = this; +/** + * @returns {boolean} + * @memberof Document/Title + */ +Title.prototype.isSanitized = function () { + const sanitized = this['$sanitized?'](); + return sanitized === Opal.nil ? false : sanitized +}; - if ($iter) $NoMethodError_initialize$13.$$p = null; - - - if (name == null) { - name = nil; - }; - - if (args == null) { - args = []; - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $NoMethodError_initialize$13, false), [message, name], null); - return (self.args = args); - }, $NoMethodError_initialize$13.$$arity = -2), nil) && 'initialize'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'StopIteration'); +/** + * @returns {boolean} + * @memberof Document/Title + */ +Title.prototype.hasSubtitle = function () { + return this['$subtitle?']() +}; - var $nesting = [self].concat($parent_nesting); +// Inline API - return self.$attr_reader("result") - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'KeyError'); +/** + * Methods for managing inline elements in AsciiDoc block. + * @namespace + * @extends AbstractNode + */ +const Inline = Opal.Asciidoctor.Inline; - var $nesting = [self].concat($parent_nesting), $KeyError_initialize$14, $KeyError_receiver$15, $KeyError_key$16; +/** + * Create a new Inline element. + * @param {AbstractBlock} parent + * @param {string} context + * @param {string|undefined} text + * @param {Object|undefined} opts + * @returns {Inline} - a new Inline element + * @memberof Inline + */ +Inline.create = function (parent, context, text, opts) { + return this.$new(parent, context, text, prepareOptions(opts)) +}; - self.$$prototype.receiver = self.$$prototype.key = nil; - - - Opal.def(self, '$initialize', $KeyError_initialize$14 = function $$initialize(message, $kwargs) { - var receiver, key, $iter = $KeyError_initialize$14.$$p, $yield = $iter || nil, self = this; +/** + * Get the converted content for this inline node. + * + * @returns {string} - the converted String content for this inline node + * @memberof Inline + */ +Inline.prototype.convert = function () { + return this.$convert() +}; - if ($iter) $KeyError_initialize$14.$$p = null; - - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - receiver = $kwargs.$$smap["receiver"]; - if (receiver == null) { - receiver = nil - }; - - key = $kwargs.$$smap["key"]; - if (key == null) { - key = nil - }; - $send(self, Opal.find_super_dispatcher(self, 'initialize', $KeyError_initialize$14, false), [message], null); - self.receiver = receiver; - return (self.key = key); - }, $KeyError_initialize$14.$$arity = -2); - - Opal.def(self, '$receiver', $KeyError_receiver$15 = function $$receiver() { - var $a, self = this; +/** + * Get the converted String text of this Inline node, if applicable. + * + * @returns {string|undefined} - the converted String text for this Inline node, or undefined if not applicable for this node. + * @memberof Inline + */ +Inline.prototype.getText = function () { + const text = this.$text(); + return text === Opal.nil ? undefined : text +}; - return ($truthy($a = self.receiver) ? $a : self.$raise($$($nesting, 'ArgumentError'), "no receiver is available")) - }, $KeyError_receiver$15.$$arity = 0); - return (Opal.def(self, '$key', $KeyError_key$16 = function $$key() { - var $a, self = this; +/** + * Get the String sub-type (aka qualifier) of this Inline node. + * + * This value is used to distinguish different variations of the same node + * category, such as different types of anchors. + * + * @returns {string} - the string sub-type of this Inline node. + * @memberof Inline + */ +Inline.prototype.getType = function () { + return this.$type() +}; - return ($truthy($a = self.key) ? $a : self.$raise($$($nesting, 'ArgumentError'), "no key is available")) - }, $KeyError_key$16.$$arity = 0), nil) && 'key'; - })($nesting[0], null, $nesting); - return (function($base, $parent_nesting) { - var self = $module($base, 'JS'); +/** + * Get the primary String target of this Inline node. + * + * @returns {string|undefined} - the string target of this Inline node. + * @memberof Inline + */ +Inline.prototype.getTarget = function () { + const target = this.$target(); + return target === Opal.nil ? undefined : target +}; - var $nesting = [self].concat($parent_nesting); +/** + * Returns the converted alt text for this inline image. + * + * @returns {string} - the String value of the alt attribute. + * @memberof Inline + */ +Inline.prototype.getAlt = function () { + return this.$alt() +}; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Error'); +// List API - var $nesting = [self].concat($parent_nesting); +/** + * Methods for managing AsciiDoc lists (ordered, unordered and description lists). + * @namespace + * @extends AbstractBlock + */ +const List = Opal.Asciidoctor.List; - return nil - })($nesting[0], null, $nesting) - })($nesting[0], $nesting); +/** + * Checks if the {@link List} contains any child {@link ListItem}. + * + * @memberof List + * @returns {boolean} - whether the {@link List} has child {@link ListItem}. + */ +List.prototype.hasItems = function () { + return this['$items?']() }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/constants"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; - - - Opal.const_set($nesting[0], 'RUBY_PLATFORM', "opal"); - Opal.const_set($nesting[0], 'RUBY_ENGINE', "opal"); - Opal.const_set($nesting[0], 'RUBY_VERSION', "2.5.1"); - Opal.const_set($nesting[0], 'RUBY_ENGINE_VERSION', "0.11.99.dev"); - Opal.const_set($nesting[0], 'RUBY_RELEASE_DATE', "2018-12-25"); - Opal.const_set($nesting[0], 'RUBY_PATCHLEVEL', 0); - Opal.const_set($nesting[0], 'RUBY_REVISION', 0); - Opal.const_set($nesting[0], 'RUBY_COPYRIGHT', "opal - Copyright (C) 2013-2018 Adam Beynon and the Opal contributors"); - return Opal.const_set($nesting[0], 'RUBY_DESCRIPTION', "" + "opal " + ($$($nesting, 'RUBY_ENGINE_VERSION')) + " (" + ($$($nesting, 'RUBY_RELEASE_DATE')) + " revision " + ($$($nesting, 'RUBY_REVISION')) + ")"); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["opal/base"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; - - Opal.add_stubs(['$require']); - - self.$require("corelib/runtime"); - self.$require("corelib/helpers"); - self.$require("corelib/module"); - self.$require("corelib/class"); - self.$require("corelib/basic_object"); - self.$require("corelib/kernel"); - self.$require("corelib/error"); - return self.$require("corelib/constants"); +/** + * Get the Array of {@link ListItem} nodes for this {@link List}. + * + * @returns {Array<ListItem>} - an Array of {@link ListItem} nodes. + * @memberof List + */ +List.prototype.getItems = function () { + return this.blocks }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/nil"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy; - - Opal.add_stubs(['$raise', '$name', '$new', '$>', '$length', '$Rational']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'NilClass'); - - var $nesting = [self].concat($parent_nesting), $NilClass_$excl$2, $NilClass_$$3, $NilClass_$$4, $NilClass_$$5, $NilClass_$eq_eq$6, $NilClass_dup$7, $NilClass_clone$8, $NilClass_inspect$9, $NilClass_nil$ques$10, $NilClass_singleton_class$11, $NilClass_to_a$12, $NilClass_to_h$13, $NilClass_to_i$14, $NilClass_to_s$15, $NilClass_to_c$16, $NilClass_rationalize$17, $NilClass_to_r$18, $NilClass_instance_variables$19; - - - self.$$prototype.$$meta = self; - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$1; +// ListItem API - - - Opal.def(self, '$allocate', $allocate$1 = function $$allocate() { - var self = this; +/** + * Methods for managing items for AsciiDoc olists, ulist, and dlists. + * + * In a description list (dlist), each item is a tuple that consists of a 2-item Array of ListItem terms and a ListItem description (i.e., [[term, term, ...], desc]. + * If a description is not set, then the second entry in the tuple is nil. + * @namespace + * @extends AbstractBlock + */ +const ListItem = Opal.Asciidoctor.ListItem; - return self.$raise($$($nesting, 'TypeError'), "" + "allocator undefined for " + (self.$name())) - }, $allocate$1.$$arity = 0); - - - Opal.udef(self, '$' + "new");; - return nil;; - })(Opal.get_singleton_class(self), $nesting); - - Opal.def(self, '$!', $NilClass_$excl$2 = function() { - var self = this; +/** + * Get the converted String text of this {@link ListItem} node. + * + * @returns {string} - the converted String text for this {@link ListItem} node. + * @memberof ListItem + */ +ListItem.prototype.getText = function () { + return this.$text() +}; - return true - }, $NilClass_$excl$2.$$arity = 0); - - Opal.def(self, '$&', $NilClass_$$3 = function(other) { - var self = this; +/** + * Set the String source text of this {@link ListItem} node. + * + * @returns {string} - the new String text assigned to this {@link ListItem} + * @memberof ListItem + */ +ListItem.prototype.setText = function (text) { + return this['$text='](text) +}; - return false - }, $NilClass_$$3.$$arity = 1); - - Opal.def(self, '$|', $NilClass_$$4 = function(other) { - var self = this; +/** + * A convenience method that checks whether the text of this {@link ListItem} is not blank (i.e. not undefined or empty string). + * + * @returns {boolean} - whether the text is not blank + * @memberof ListItem + */ +ListItem.prototype.hasText = function () { + return this['$text?']() +}; - return other !== false && other !== nil; - }, $NilClass_$$4.$$arity = 1); - - Opal.def(self, '$^', $NilClass_$$5 = function(other) { - var self = this; +/** + * Get the {string} used to mark this {@link ListItem}. + * + * @returns {string} + * @memberof ListItem + */ +ListItem.prototype.getMarker = function () { + return this.marker +}; - return other !== false && other !== nil; - }, $NilClass_$$5.$$arity = 1); - - Opal.def(self, '$==', $NilClass_$eq_eq$6 = function(other) { - var self = this; +/** + * Set the {string} used to mark this {@link ListItem}. + * + * @param {string} marker - the {string} used to mark this {@link ListItem} + * @memberof ListItem + */ +ListItem.prototype.setMarker = function (marker) { + this.marker = marker; +}; - return other === nil; - }, $NilClass_$eq_eq$6.$$arity = 1); - - Opal.def(self, '$dup', $NilClass_dup$7 = function $$dup() { - var self = this; +/** + * Get the {@link List} to which this {@link ListItem} is attached. + * + * @returns {List} - the {@link List} object to which this {@link ListItem} is attached, + * or undefined if this node has no parent. + * @memberof ListItem + */ +ListItem.prototype.getList = function () { + return this.$list() +}; - return nil - }, $NilClass_dup$7.$$arity = 0); - - Opal.def(self, '$clone', $NilClass_clone$8 = function $$clone($kwargs) { - var freeze, self = this; +/** + * @see {@link ListItem#getList} + * @memberof ListItem + */ +ListItem.prototype.getParent = ListItem.prototype.getList; - - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - freeze = $kwargs.$$smap["freeze"]; - if (freeze == null) { - freeze = true - }; - return nil; - }, $NilClass_clone$8.$$arity = -1); - - Opal.def(self, '$inspect', $NilClass_inspect$9 = function $$inspect() { - var self = this; +// Reader API - return "nil" - }, $NilClass_inspect$9.$$arity = 0); - - Opal.def(self, '$nil?', $NilClass_nil$ques$10 = function() { - var self = this; +/** @namespace */ +const Reader = Opal.Asciidoctor.Reader; - return true - }, $NilClass_nil$ques$10.$$arity = 0); - - Opal.def(self, '$singleton_class', $NilClass_singleton_class$11 = function $$singleton_class() { - var self = this; +/** + * Push source onto the front of the reader and switch the context based on the file, document-relative path and line information given. + * + * This method is typically used in an IncludeProcessor to add source read from the target specified. + * + * @param {string} data + * @param {string|undefined} file + * @param {string|undefined} path + * @param {number} lineno - The line number + * @param {Object} attributes - a JSON of attributes + * @returns {Reader} - this {Reader} object. + * @memberof Reader + */ +Reader.prototype.pushInclude = function (data, file, path, lineno, attributes) { + return this.$push_include(data, file, path, lineno, toHash(attributes)) +}; - return $$($nesting, 'NilClass') - }, $NilClass_singleton_class$11.$$arity = 0); - - Opal.def(self, '$to_a', $NilClass_to_a$12 = function $$to_a() { - var self = this; +/** + * Get the current location of the reader's cursor, which encapsulates the file, dir, path, and lineno of the file being read. + * + * @returns {Cursor} + * @memberof Reader + */ +Reader.prototype.getCursor = function () { + return this.$cursor() +}; - return [] - }, $NilClass_to_a$12.$$arity = 0); - - Opal.def(self, '$to_h', $NilClass_to_h$13 = function $$to_h() { - var self = this; +/** + * Get the remaining unprocessed lines, without consuming them, as an {Array} of {string}. + * + * Lines will not be consumed from the Reader (ie. you will be able to read these lines again). + * + * @returns {Array<string>} - the remaining unprocessed lines as an {Array} of {string}. + * @memberof Reader + */ +Reader.prototype.getLines = function () { + return this.$lines() +}; - return Opal.hash(); - }, $NilClass_to_h$13.$$arity = 0); - - Opal.def(self, '$to_i', $NilClass_to_i$14 = function $$to_i() { - var self = this; +/** + * Get the remaining unprocessed lines, without consuming them, as a {string}. + * + * Lines will not be consumed from the Reader (ie. you will be able to read these lines again). + * + * @returns {string} - the remaining unprocessed lines as a {string} (joined by linefeed characters). + * @memberof Reader + */ +Reader.prototype.getString = function () { + return this.$string() +}; - return 0 - }, $NilClass_to_i$14.$$arity = 0); - Opal.alias(self, "to_f", "to_i"); - - Opal.def(self, '$to_s', $NilClass_to_s$15 = function $$to_s() { - var self = this; +/** + * Check whether there are any lines left to read. + * If a previous call to this method resulted in a value of false, immediately returned the cached value. + * Otherwise, delegate to peekLine to determine if there is a next line available. + * + * @returns {boolean} - true if there are more lines, false if there are not. + * @memberof Reader + */ +Reader.prototype.hasMoreLines = function () { + return this['$has_more_lines?']() +}; - return "" - }, $NilClass_to_s$15.$$arity = 0); - - Opal.def(self, '$to_c', $NilClass_to_c$16 = function $$to_c() { - var self = this; +/** + * Check whether this reader is empty (contains no lines). + * + * @returns {boolean} - true if there are no more lines to peek, otherwise false. + * @memberof Reader + */ +Reader.prototype.isEmpty = function () { + return this['$empty?']() +}; - return $$($nesting, 'Complex').$new(0, 0) - }, $NilClass_to_c$16.$$arity = 0); - - Opal.def(self, '$rationalize', $NilClass_rationalize$17 = function $$rationalize($a) { - var $post_args, args, self = this; +/** + * Peek at the next line. + * Processes the line if not already marked as processed, but does not consume it (ie. you will be able to read this line again). + * + * This method will probe the reader for more lines. + * If there is a next line that has not previously been visited, the line is passed to the Reader#processLine method to be initialized. + * This call gives sub-classes the opportunity to do preprocessing. + * If the return value of the Reader#processLine is undefined, the data is assumed to be changed and Reader#peekLine is invoked again to perform further processing. + * + * If hasMoreLines is called immediately before peekLine, the direct flag is implicitly true (since the line is flagged as visited). + * + * @param {boolean} direct - A {boolean} flag to bypasses the check for more lines and immediately returns the first element of the internal lines {Array}. (default: false) + * @returns {string} - the next line as a {string} if there are lines remaining. + * @memberof Reader + */ +Reader.prototype.peekLine = function (direct) { + direct = direct || false; + const line = this.$peek_line(direct); + return line === Opal.nil ? undefined : line +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy($rb_gt(args.$length(), 1))) { - self.$raise($$($nesting, 'ArgumentError'))}; - return self.$Rational(0, 1); - }, $NilClass_rationalize$17.$$arity = -1); - - Opal.def(self, '$to_r', $NilClass_to_r$18 = function $$to_r() { - var self = this; +/** + * Consume, preprocess, and return the next line. + * + * Line will be consumed from the Reader (ie. you won't be able to read this line again). + * + * @returns {string} - the next line as a {string} if data is present. + * @memberof Reader + */ +Reader.prototype.readLine = function () { + const line = this.$read_line(); + return line === Opal.nil ? undefined : line +}; - return self.$Rational(0, 1) - }, $NilClass_to_r$18.$$arity = 0); - return (Opal.def(self, '$instance_variables', $NilClass_instance_variables$19 = function $$instance_variables() { - var self = this; +/** + * Consume, preprocess, and return the remaining lines. + * + * This method calls Reader#readLine repeatedly until all lines are consumed and returns the lines as an {Array} of {string}. + * This method differs from Reader#getLines in that it processes each line in turn, hence triggering any preprocessors implemented in sub-classes. + * + * Lines will be consumed from the Reader (ie. you won't be able to read these lines again). + * + * @returns {Array<string>} - the lines read as an {Array} of {string}. + * @memberof Reader + */ +Reader.prototype.readLines = function () { + return this.$read_lines() +}; - return [] - }, $NilClass_instance_variables$19.$$arity = 0), nil) && 'instance_variables'; - })($nesting[0], null, $nesting); - return Opal.const_set($nesting[0], 'NIL', nil); +/** + * Consume, preprocess, and return the remaining lines joined as a {string}. + * + * Delegates to Reader#readLines, then joins the result. + * + * Lines will be consumed from the Reader (ie. you won't be able to read these lines again). + * + * @returns {string} - the lines read joined as a {string} + * @memberof Reader + */ +Reader.prototype.read = function () { + return this.$read() }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/boolean"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2; +/** + * Advance to the next line by discarding the line at the front of the stack. + * + * @returns {boolean} - a Boolean indicating whether there was a line to discard. + * @memberof Reader + */ +Reader.prototype.advance = function () { + return this.$advance() +}; - Opal.add_stubs(['$raise', '$name']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Boolean'); +// Cursor API - var $nesting = [self].concat($parent_nesting), $Boolean___id__$2, $Boolean_$excl$3, $Boolean_$$4, $Boolean_$$5, $Boolean_$$6, $Boolean_$eq_eq$7, $Boolean_singleton_class$8, $Boolean_to_s$9, $Boolean_dup$10, $Boolean_clone$11; +/** @namespace */ +const Cursor = Opal.Asciidoctor.Reader.Cursor; - - Opal.defineProperty(self.$$prototype, '$$is_boolean', true); - Opal.defineProperty(self.$$prototype, '$$meta', self); - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$1; +/** + * Get the file associated to the cursor. + * @returns {string|undefined} + * @memberof Cursor + */ +Cursor.prototype.getFile = function () { + const file = this.file; + return file === Opal.nil ? undefined : file +}; - - - Opal.def(self, '$allocate', $allocate$1 = function $$allocate() { - var self = this; +/** + * Get the directory associated to the cursor. + * @returns {string|undefined} - the directory associated to the cursor + * @memberof Cursor + */ +Cursor.prototype.getDirectory = function () { + const dir = this.dir; + return dir === Opal.nil ? undefined : dir +}; - return self.$raise($$($nesting, 'TypeError'), "" + "allocator undefined for " + (self.$name())) - }, $allocate$1.$$arity = 0); - - - Opal.udef(self, '$' + "new");; - return nil;; - })(Opal.get_singleton_class(self), $nesting); - - Opal.def(self, '$__id__', $Boolean___id__$2 = function $$__id__() { - var self = this; +/** + * Get the path associated to the cursor. + * @returns {string|undefined} - the path associated to the cursor (or '<stdin>') + * @memberof Cursor + */ +Cursor.prototype.getPath = function () { + const path = this.path; + return path === Opal.nil ? undefined : path +}; - return self.valueOf() ? 2 : 0; - }, $Boolean___id__$2.$$arity = 0); - Opal.alias(self, "object_id", "__id__"); - - Opal.def(self, '$!', $Boolean_$excl$3 = function() { - var self = this; +/** + * Get the line number of the cursor. + * @returns {number|undefined} - the line number of the cursor + * @memberof Cursor + */ +Cursor.prototype.getLineNumber = function () { + return this.lineno +}; - return self != true; - }, $Boolean_$excl$3.$$arity = 0); - - Opal.def(self, '$&', $Boolean_$$4 = function(other) { - var self = this; +// Logger API (available in Asciidoctor 1.5.7+) - return (self == true) ? (other !== false && other !== nil) : false; - }, $Boolean_$$4.$$arity = 1); - - Opal.def(self, '$|', $Boolean_$$5 = function(other) { - var self = this; +function initializeLoggerFormatterClass (className, functions) { + const superclass = Opal.const_get_qualified(Opal.Logger, 'Formatter'); + return initializeClass(superclass, className, functions, {}, { + call: function (args) { + for (let i = 0; i < args.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof args[i] === 'object' && '$$smap' in args[i]) { + args[i] = fromHash(args[i]); + } + } + return args + } + }) +} - return (self == true) ? true : (other !== false && other !== nil); - }, $Boolean_$$5.$$arity = 1); - - Opal.def(self, '$^', $Boolean_$$6 = function(other) { - var self = this; +function initializeLoggerClass (className, functions) { + const superClass = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger'); + return initializeClass(superClass, className, functions, {}, { + add: function (args) { + if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) { + const message = args[2]; + const messageObject = fromHash(message); + messageObject.getText = function () { + return this.text + }; + messageObject.getSourceLocation = function () { + return this.source_location + }; + messageObject.$inspect = function () { + const sourceLocation = this.getSourceLocation(); + if (sourceLocation) { + return sourceLocation.getPath() + ': line ' + sourceLocation.getLineNumber() + ': ' + this.getText() + } else { + return this.getText() + } + }; + args[2] = messageObject; + } + if (args.length >= 1) { + args[1] = args[1] === Opal.nil ? undefined : args[1]; + } + return args + } + }) +} - return (self == true) ? (other === false || other === nil) : (other !== false && other !== nil); - }, $Boolean_$$6.$$arity = 1); - - Opal.def(self, '$==', $Boolean_$eq_eq$7 = function(other) { - var self = this; +/** + * @namespace + */ +const LoggerManager = Opal.const_get_qualified(Opal.Asciidoctor, 'LoggerManager', true); - return (self == true) === other.valueOf(); - }, $Boolean_$eq_eq$7.$$arity = 1); - Opal.alias(self, "equal?", "=="); - Opal.alias(self, "eql?", "=="); - - Opal.def(self, '$singleton_class', $Boolean_singleton_class$8 = function $$singleton_class() { - var self = this; +// Alias +Opal.Asciidoctor.LoggerManager = LoggerManager; - return $$($nesting, 'Boolean') - }, $Boolean_singleton_class$8.$$arity = 0); - - Opal.def(self, '$to_s', $Boolean_to_s$9 = function $$to_s() { - var self = this; +/** + * @memberof LoggerManager + */ +LoggerManager.getLogger = function () { + return this.$logger() +}; - return (self == true) ? 'true' : 'false'; - }, $Boolean_to_s$9.$$arity = 0); - - Opal.def(self, '$dup', $Boolean_dup$10 = function $$dup() { - var self = this; +/** + * @memberof LoggerManager + */ +LoggerManager.setLogger = function (logger) { + this['$logger='](logger); +}; - return self - }, $Boolean_dup$10.$$arity = 0); - return (Opal.def(self, '$clone', $Boolean_clone$11 = function $$clone($kwargs) { - var freeze, self = this; +/** + * @memberof LoggerManager + */ +LoggerManager.newLogger = function (name, functions) { + return initializeLoggerClass(name, functions).$new() +}; - - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - freeze = $kwargs.$$smap["freeze"]; - if (freeze == null) { - freeze = true - }; - return self; - }, $Boolean_clone$11.$$arity = -1), nil) && 'clone'; - })($nesting[0], Boolean, $nesting); - Opal.const_set($nesting[0], 'TrueClass', $$($nesting, 'Boolean')); - Opal.const_set($nesting[0], 'FalseClass', $$($nesting, 'Boolean')); - Opal.const_set($nesting[0], 'TRUE', true); - return Opal.const_set($nesting[0], 'FALSE', false); +/** + * @memberof LoggerManager + */ +LoggerManager.newFormatter = function (name, functions) { + return initializeLoggerFormatterClass(name, functions).$new() }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/comparable"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy; +/** + * @namespace + */ +const LoggerSeverity = Opal.const_get_qualified(Opal.Logger, 'Severity', true); - Opal.add_stubs(['$===', '$>', '$<', '$equal?', '$<=>', '$normalize', '$raise', '$class']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Comparable'); +// Alias +Opal.Asciidoctor.LoggerSeverity = LoggerSeverity; - var $nesting = [self].concat($parent_nesting), $Comparable_normalize$1, $Comparable_$eq_eq$2, $Comparable_$gt$3, $Comparable_$gt_eq$4, $Comparable_$lt$5, $Comparable_$lt_eq$6, $Comparable_between$ques$7, $Comparable_clamp$8; +/** + * @memberof LoggerSeverity + */ +LoggerSeverity.get = function (severity) { + return LoggerSeverity.$constants()[severity] +}; - - Opal.defs(self, '$normalize', $Comparable_normalize$1 = function $$normalize(what) { - var self = this; +/** + * @namespace + */ +const LoggerFormatter = Opal.const_get_qualified(Opal.Logger, 'Formatter', true); - - if ($truthy($$($nesting, 'Integer')['$==='](what))) { - return what}; - if ($truthy($rb_gt(what, 0))) { - return 1}; - if ($truthy($rb_lt(what, 0))) { - return -1}; - return 0; - }, $Comparable_normalize$1.$$arity = 1); - - Opal.def(self, '$==', $Comparable_$eq_eq$2 = function(other) { - var self = this, cmp = nil; +// Alias +Opal.Asciidoctor.LoggerFormatter = LoggerFormatter; - try { - - if ($truthy(self['$equal?'](other))) { - return true}; - - if (self["$<=>"] == Opal.Kernel["$<=>"]) { - return false; - } +/** + * @memberof LoggerFormatter + */ +LoggerFormatter.prototype.call = function (severity, time, programName, message) { + return this.$call(LoggerSeverity.get(severity), time, programName, message) +}; - // check for infinite recursion - if (self.$$comparable) { - delete self.$$comparable; - return false; - } - ; - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - return false - }; - return $$($nesting, 'Comparable').$normalize(cmp) == 0; - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'StandardError')])) { - try { - return false - } finally { Opal.pop_exception() } - } else { throw $err; } - } - }, $Comparable_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$>', $Comparable_$gt$3 = function(other) { - var self = this, cmp = nil; +/** + * @namespace + */ +const MemoryLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'MemoryLogger', true); - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) > 0; - }, $Comparable_$gt$3.$$arity = 1); - - Opal.def(self, '$>=', $Comparable_$gt_eq$4 = function(other) { - var self = this, cmp = nil; +// Alias +Opal.Asciidoctor.MemoryLogger = MemoryLogger; - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) >= 0; - }, $Comparable_$gt_eq$4.$$arity = 1); - - Opal.def(self, '$<', $Comparable_$lt$5 = function(other) { - var self = this, cmp = nil; +/** + * Create a new MemoryLogger. + * @returns {MemoryLogger} - a MemoryLogger + * @memberof MemoryLogger + */ +MemoryLogger.create = function () { + return this.$new() +}; - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") +/** + * @returns {Array<Object>} - a list of messages + * @memberof MemoryLogger + */ +MemoryLogger.prototype.getMessages = function () { + const messages = this.messages; + const result = []; + for (let i = 0; i < messages.length; i++) { + const message = messages[i]; + const messageObject = fromHash(message); + if (typeof messageObject.message === 'string') { + messageObject.getText = function () { + return this.message }; - return $$($nesting, 'Comparable').$normalize(cmp) < 0; - }, $Comparable_$lt$5.$$arity = 1); - - Opal.def(self, '$<=', $Comparable_$lt_eq$6 = function(other) { - var self = this, cmp = nil; - - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") + } else { + // also convert the message attribute + messageObject.message = fromHash(messageObject.message); + messageObject.getText = function () { + return this.message.text }; - return $$($nesting, 'Comparable').$normalize(cmp) <= 0; - }, $Comparable_$lt_eq$6.$$arity = 1); - - Opal.def(self, '$between?', $Comparable_between$ques$7 = function(min, max) { - var self = this; + } + messageObject.getSeverity = function () { + return this.severity.toString() + }; + messageObject.getSourceLocation = function () { + return this.message.source_location + }; + result.push(messageObject); + } + return result +}; - - if ($rb_lt(self, min)) { - return false}; - if ($rb_gt(self, max)) { - return false}; - return true; - }, $Comparable_between$ques$7.$$arity = 2); - - Opal.def(self, '$clamp', $Comparable_clamp$8 = function $$clamp(min, max) { - var self = this, cmp = nil; +const Logging = Opal.const_get_qualified(Opal.Asciidoctor, 'Logging', true); - - cmp = min['$<=>'](max); - if ($truthy(cmp)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (min.$class()) + " with " + (max.$class()) + " failed") - }; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(cmp), 0))) { - self.$raise($$($nesting, 'ArgumentError'), "min argument must be smaller than max argument")}; - if ($truthy($rb_lt($$($nesting, 'Comparable').$normalize(self['$<=>'](min)), 0))) { - return min}; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(self['$<=>'](max)), 0))) { - return max}; - return self; - }, $Comparable_clamp$8.$$arity = 2); - })($nesting[0], $nesting) -}; +Opal.Asciidoctor.Logging = Logging; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/regexp"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send, $truthy = Opal.truthy, $gvars = Opal.gvars; +Logging.getLogger = function () { + return LoggerManager.$logger() +}; - Opal.add_stubs(['$nil?', '$[]', '$raise', '$escape', '$options', '$to_str', '$new', '$join', '$coerce_to!', '$!', '$match', '$coerce_to?', '$begin', '$coerce_to', '$=~', '$attr_reader', '$===', '$inspect', '$to_a']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'RegexpError'); +Logging.createLogMessage = function (text, context) { + return Logging.prototype.$message_with_context(text, toHash(context)) +}; - var $nesting = [self].concat($parent_nesting); +// alias - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Regexp'); +/** + * @memberof Reader + */ +Reader.prototype.getLogger = Logging.getLogger; +/** + * @memberof Reader + */ +Reader.prototype.createLogMessage = Logging.createLogMessage; - var $nesting = [self].concat($parent_nesting), $Regexp_$eq_eq$6, $Regexp_$eq_eq_eq$7, $Regexp_$eq_tilde$8, $Regexp_inspect$9, $Regexp_match$10, $Regexp_match$ques$11, $Regexp_$$12, $Regexp_source$13, $Regexp_options$14, $Regexp_casefold$ques$15; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.getLogger = Logging.getLogger; +/** + * @memberof AbstractNode + */ +AbstractNode.prototype.createLogMessage = Logging.createLogMessage; - - Opal.const_set($nesting[0], 'IGNORECASE', 1); - Opal.const_set($nesting[0], 'EXTENDED', 2); - Opal.const_set($nesting[0], 'MULTILINE', 4); - Opal.defineProperty(self.$$prototype, '$$is_regexp', true); - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$1, $escape$2, $last_match$3, $union$4, $new$5; +/** + * @namespace + */ +const Logger = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger', true); - - - Opal.def(self, '$allocate', $allocate$1 = function $$allocate() { - var $iter = $allocate$1.$$p, $yield = $iter || nil, self = this, allocated = nil, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; +// Alias +Opal.Asciidoctor.Logger = Logger; - if ($iter) $allocate$1.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - allocated = $send(self, Opal.find_super_dispatcher(self, 'allocate', $allocate$1, false), $zuper, $iter); - allocated.uninitialized = true; - return allocated; - }, $allocate$1.$$arity = 0); - - Opal.def(self, '$escape', $escape$2 = function $$escape(string) { - var self = this; +/** + * @returns {number|undefined} - the maximum severity + * @memberof Logger + */ +Logger.prototype.getMaxSeverity = function () { + const result = this.max_severity; + return result === Opal.nil ? undefined : result +}; +/** + * @returns {LoggerFormatter} - the formatter + * @memberof Logger + */ +Logger.prototype.getFormatter = function () { + return this.formatter +}; +/** + * @param {LoggerFormatter} formatter - the formatter + * @memberof Logger + */ +Logger.prototype.setFormatter = function (formatter) { + this.formatter = formatter; +}; +/** + * @returns {number} - the logging severity threshold + * @memberof Logger + */ +Logger.prototype.getLevel = function () { + return this.level +}; +/** + * @param {number} level - the logging severity threshold + * @memberof Logger + */ +Logger.prototype.setLevel = function (level) { + this.level = level; +}; +/** + * @returns {string} - the program name + * @memberof Logger + */ +Logger.prototype.getProgramName = function () { + return this.progname +}; +/** + * @param {string} programName - the program name + * @memberof Logger + */ +Logger.prototype.setProgramName = function (programName) { + this.progname = programName; +}; - return Opal.escape_regexp(string); - }, $escape$2.$$arity = 1); - - Opal.def(self, '$last_match', $last_match$3 = function $$last_match(n) { - var self = this; - if ($gvars["~"] == null) $gvars["~"] = nil; +const RubyLogger = Opal.const_get_qualified('::', 'Logger'); - - - if (n == null) { - n = nil; - }; - if ($truthy(n['$nil?']())) { - return $gvars["~"] - } else { - return $gvars["~"]['$[]'](n) - }; - }, $last_match$3.$$arity = -1); - Opal.alias(self, "quote", "escape"); - - Opal.def(self, '$union', $union$4 = function $$union($a) { - var $post_args, parts, self = this; +const log = function (logger, level, message) { + logger['$' + level](message); +}; +RubyLogger.prototype.add = function (severity, message, programName) { + const severityValue = typeof severity === 'string' ? LoggerSeverity[severity.toUpperCase()] : severity; + this.$add(severityValue, message, programName); +}; +RubyLogger.prototype.log = RubyLogger.prototype.add; +RubyLogger.prototype.debug = function (message) { + log(this, 'debug', message); +}; +RubyLogger.prototype.info = function (message) { + log(this, 'info', message); +}; +RubyLogger.prototype.warn = function (message) { + log(this, 'warn', message); +}; +RubyLogger.prototype.error = function (message) { + log(this, 'error', message); +}; +RubyLogger.prototype.fatal = function (message) { + log(this, 'fatal', message); +}; +RubyLogger.prototype.isDebugEnabled = function () { + return this['$debug?']() +}; +RubyLogger.prototype.isInfoEnabled = function () { + return this['$info?']() +}; +RubyLogger.prototype.isWarnEnabled = function () { + return this['$warn?']() +}; +RubyLogger.prototype.isErrorEnabled = function () { + return this['$error?']() +}; +RubyLogger.prototype.isFatalEnabled = function () { + return this['$fatal?']() +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - parts = $post_args;; - - var is_first_part_array, quoted_validated, part, options, each_part_options; - if (parts.length == 0) { - return /(?!)/; - } - // return fast if there's only one element - if (parts.length == 1 && parts[0].$$is_regexp) { - return parts[0]; - } - // cover the 2 arrays passed as arguments case - is_first_part_array = parts[0].$$is_array; - if (parts.length > 1 && is_first_part_array) { - self.$raise($$($nesting, 'TypeError'), "no implicit conversion of Array into String") - } - // deal with splat issues (related to https://github.com/opal/opal/issues/858) - if (is_first_part_array) { - parts = parts[0]; - } - options = undefined; - quoted_validated = []; - for (var i=0; i < parts.length; i++) { - part = parts[i]; - if (part.$$is_string) { - quoted_validated.push(self.$escape(part)); - } - else if (part.$$is_regexp) { - each_part_options = (part).$options(); - if (options != undefined && options != each_part_options) { - self.$raise($$($nesting, 'TypeError'), "All expressions must use the same options") - } - options = each_part_options; - quoted_validated.push('('+part.source+')'); - } - else { - quoted_validated.push(self.$escape((part).$to_str())); - } - } - ; - return self.$new((quoted_validated).$join("|"), options); - }, $union$4.$$arity = -1); - return (Opal.def(self, '$new', $new$5 = function(regexp, options) { - var self = this; +/** + * @namespace + */ +const NullLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'NullLogger', true); - - ; - - if (regexp.$$is_regexp) { - return new RegExp(regexp); - } +// Alias +Opal.Asciidoctor.NullLogger = NullLogger; - regexp = $$($nesting, 'Opal')['$coerce_to!'](regexp, $$($nesting, 'String'), "to_str"); +/** + * Create a new NullLogger. + * @returns {NullLogger} - a NullLogger + * @memberof NullLogger + */ +NullLogger.create = function () { + return this.$new() +}; - if (regexp.charAt(regexp.length - 1) === '\\' && regexp.charAt(regexp.length - 2) !== '\\') { - self.$raise($$($nesting, 'RegexpError'), "" + "too short escape sequence: /" + (regexp) + "/") - } +/** + * @returns {number|undefined} - the maximum severity + * @memberof NullLogger + */ +NullLogger.prototype.getMaxSeverity = function () { + return this.max_severity +}; - if (options === undefined || options['$!']()) { - return new RegExp(regexp); - } +// Alias +Opal.Asciidoctor.StopIteration = Opal.StopIteration; - if (options.$$is_number) { - var temp = ''; - if ($$($nesting, 'IGNORECASE') & options) { temp += 'i'; } - if ($$($nesting, 'MULTILINE') & options) { temp += 'm'; } - options = temp; - } - else { - options = 'i'; - } +/** + * @namespace + */ +const Timings = Opal.const_get_qualified(Opal.Asciidoctor, 'Timings', true); - return new RegExp(regexp, options); - ; - }, $new$5.$$arity = -2), nil) && 'new'; - })(Opal.get_singleton_class(self), $nesting); - - Opal.def(self, '$==', $Regexp_$eq_eq$6 = function(other) { - var self = this; +// Alias +Opal.Asciidoctor.Timings = Timings; - return other instanceof RegExp && self.toString() === other.toString(); - }, $Regexp_$eq_eq$6.$$arity = 1); - - Opal.def(self, '$===', $Regexp_$eq_eq_eq$7 = function(string) { - var self = this; +/** + * Create a new Timings. + * @returns {Timings} - a Timings + * @memberof Timings + */ +Timings.create = function () { + return this.$new() +}; - return self.$match($$($nesting, 'Opal')['$coerce_to?'](string, $$($nesting, 'String'), "to_str")) !== nil - }, $Regexp_$eq_eq_eq$7.$$arity = 1); - - Opal.def(self, '$=~', $Regexp_$eq_tilde$8 = function(string) { - var $a, self = this; - if ($gvars["~"] == null) $gvars["~"] = nil; +/** + * Print a report to the specified output. + * The report will include: + * - the time to read and parse source + * - the time to convert document + * - the total time (read, parse and convert) + * @param {RubyLogger|console|Object} [to] - an optional output (by default stdout) + * @param {string} [subject] - an optional subject (usually the file name) + * @memberof Timings + */ +Timings.prototype.printReport = function (to, subject) { + let outputFunction; + if (to) { + if (typeof to.$add === 'function') { + outputFunction = function (message) { + to.$add(1, message); + }; + } else if (typeof to.log === 'function') { + outputFunction = to.log; + } else if (typeof to.write === 'function') { + outputFunction = function (message) { + to.write(message, 'utf-8'); + }; + } else { + throw new Error('The output should be a Stream (with a write function), an object with a log function or a Ruby Logger (with a add function)') + } + } else { + outputFunction = function (message) { + Opal.gvars.stdout.$write(message); + }; + } + if (subject) { + outputFunction('Input file: ' + subject); + } + outputFunction(' Time to read and parse source: ' + this.$read_parse().toFixed(2)); + outputFunction(' Time to convert document: ' + this.$convert().toFixed(2)); + outputFunction(' Total time (read, parse and convert): ' + this.$read_parse_convert().toFixed(2)); +}; - return ($truthy($a = self.$match(string)) ? $gvars["~"].$begin(0) : $a) - }, $Regexp_$eq_tilde$8.$$arity = 1); - Opal.alias(self, "eql?", "=="); - - Opal.def(self, '$inspect', $Regexp_inspect$9 = function $$inspect() { - var self = this; +/** + * @namespace + * @description + * This API is experimental and subject to change. + * + * A pluggable adapter for integrating a syntax (aka code) highlighter into AsciiDoc processing. + * + * There are two types of syntax highlighter adapters. The first performs syntax highlighting during the convert phase. + * This adapter type must define a "handlesHighlighting" method that returns true. + * The companion "highlight" method will then be called to handle the "specialcharacters" substitution for source blocks. + * + * The second assumes syntax highlighting is performed on the client (e.g., when the HTML document is loaded). + * This adapter type must define a "hasDocinfo" method that returns true. + * The companion "docinfo" method will then be called to insert markup into the output document. + * The docinfo functionality is available to both adapter types. + * + * Asciidoctor.js provides several a built-in adapter for highlight.js. + * Additional adapters can be registered using SyntaxHighlighter.register. + */ +const SyntaxHighlighter = Opal.const_get_qualified(Opal.Asciidoctor, 'SyntaxHighlighter', true); - - var regexp_format = /^\/(.*)\/([^\/]*)$/; - var value = self.toString(); - var matches = regexp_format.exec(value); - if (matches) { - var regexp_pattern = matches[1]; - var regexp_flags = matches[2]; - var chars = regexp_pattern.split(''); - var chars_length = chars.length; - var char_escaped = false; - var regexp_pattern_escaped = ''; - for (var i = 0; i < chars_length; i++) { - var current_char = chars[i]; - if (!char_escaped && current_char == '/') { - regexp_pattern_escaped = regexp_pattern_escaped.concat('\\'); - } - regexp_pattern_escaped = regexp_pattern_escaped.concat(current_char); - if (current_char == '\\') { - if (char_escaped) { - // does not over escape - char_escaped = false; - } else { - char_escaped = true; +// Alias +Opal.Asciidoctor.SyntaxHighlighter = SyntaxHighlighter; + +/** + * Associates the syntax highlighter class or object with the specified names. + * + * @description This API is experimental and subject to change. + * + * @param {string|Array} names - A {string} name or an {Array} of {string} names + * @param functions - A list of functions representing a {SyntaxHighlighter} or a {SyntaxHighlighter} class to instantiate + * @memberof SyntaxHighlighter + */ +SyntaxHighlighter.register = function (names, functions) { + const name = typeof names === 'string' ? names : names[0]; + if (typeof functions === 'function') { + const classObject = functions; + const prototype = classObject.prototype; + const properties = Object.getOwnPropertyNames(prototype); + functions = {}; + for (const propertyIdx in properties) { + const propertyName = properties[propertyIdx]; + functions[propertyName] = prototype[propertyName]; + } + } + const scope = initializeClass(SyntaxHighlighterBase, name, functions, {}, { + format: function (args) { + if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) { + args[2] = fromHash(args[2]); + } + if (args.length >= 1) { + args[1] = args[1] === Opal.nil ? undefined : args[1]; + } + return args + }, + highlight: function (args) { + if (args.length >= 3 && typeof args[3] === 'object' && '$$smap' in args[3]) { + let opts = args[3]; + opts = fromHash(opts); + for (const key in opts) { + const value = opts[key]; + if (key === 'callouts') { + const callouts = fromHashKeys(value); + for (const idx in callouts) { + const callout = callouts[idx]; + for (let i = 0; i < callout.length; i++) { + const items = callout[i]; + for (let j = 0; j < items.length; j++) { + items[j] = items[j] === Opal.nil ? undefined : items[j]; + } + } } + opts[key] = callouts; } else { - char_escaped = false; + opts[key] = value === Opal.nil ? undefined : value; } } - return '/' + regexp_pattern_escaped + '/' + regexp_flags; - } else { - return value; + args[3] = opts; } - - }, $Regexp_inspect$9.$$arity = 0); - - Opal.def(self, '$match', $Regexp_match$10 = function $$match(string, pos) { - var $iter = $Regexp_match$10.$$p, block = $iter || nil, self = this; - if ($gvars["~"] == null) $gvars["~"] = nil; - - if ($iter) $Regexp_match$10.$$p = null; - - - if ($iter) $Regexp_match$10.$$p = null;; - ; - - if (self.uninitialized) { - self.$raise($$($nesting, 'TypeError'), "uninitialized Regexp") + if (args.length >= 2) { + args[2] = args[2] === Opal.nil ? undefined : args[2]; } - - if (pos === undefined) { - if (string === nil) return ($gvars["~"] = nil); - var m = self.exec($$($nesting, 'Opal').$coerce_to(string, $$($nesting, 'String'), "to_str")); - if (m) { - ($gvars["~"] = $$($nesting, 'MatchData').$new(self, m)); - return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]); - } else { - return ($gvars["~"] = nil); + return args + } + }); + for (const functionName in functions) { + if (Object.prototype.hasOwnProperty.call(functions, functionName)) { + (function (functionName) { + const userFunction = functions[functionName]; + if (functionName === 'handlesHighlighting') { + Opal.def(scope, '$highlight?', function () { + return userFunction.call() + }); + } else if (functionName === 'hasDocinfo') { + Opal.def(scope, '$docinfo?', function (location) { + return userFunction.apply(this, [location]) + }); } - } + }(functionName)); + } + } + Opal.def(scope, '$name', function () { + return name + }); + SyntaxHighlighter.$register(scope, names); + return scope +}; - pos = $$($nesting, 'Opal').$coerce_to(pos, $$($nesting, 'Integer'), "to_int"); +/** + * Retrieves the syntax highlighter class or object registered for the specified name. + * + * @description This API is experimental and subject to change. + * + * @param {string} name - The {string} name of the syntax highlighter to retrieve. + * @returns {SyntaxHighlighter} - the {SyntaxHighlighter} registered for this name. + * @memberof SyntaxHighlighter + */ +SyntaxHighlighter.get = function (name) { + const result = SyntaxHighlighter.$for(name); + return result === Opal.nil ? undefined : result +}; - if (string === nil) { - return ($gvars["~"] = nil); - } +/** + * @deprecated Please use {SyntaxHighlighter#get} method as "for" is a reserved keyword. + */ +SyntaxHighlighter.for = SyntaxHighlighter.get; - string = $$($nesting, 'Opal').$coerce_to(string, $$($nesting, 'String'), "to_str"); +/** + * @namespace + */ +const SyntaxHighlighterBase = Opal.const_get_qualified(SyntaxHighlighter, 'Base', true); - if (pos < 0) { - pos += string.length; - if (pos < 0) { - return ($gvars["~"] = nil); - } - } +// Alias +Opal.Asciidoctor.SyntaxHighlighterBase = SyntaxHighlighterBase; - // global RegExp maintains state, so not using self/this - var md, re = Opal.global_regexp(self); +/** + * Statically register the current class in the registry for the specified names. + * + * @description This API is experimental and subject to change. + * + * @param {string|Array<string>} names - A {string} name or an {Array} of {string} names + * @memberof SyntaxHighlighterBase + */ +SyntaxHighlighterBase.prototype.registerFor = function (names) { + SyntaxHighlighter.$register(this, names); +}; - while (true) { - md = re.exec(string); - if (md === null) { - return ($gvars["~"] = nil); - } - if (md.index >= pos) { - ($gvars["~"] = $$($nesting, 'MatchData').$new(re, md)); - return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]); - } - re.lastIndex = md.index + 1; - } - ; - }, $Regexp_match$10.$$arity = -2); - - Opal.def(self, '$match?', $Regexp_match$ques$11 = function(string, pos) { - var self = this; +// Table API - - ; - - if (self.uninitialized) { - self.$raise($$($nesting, 'TypeError'), "uninitialized Regexp") - } +/** + * Methods for managing AsciiDoc tables. + * @namespace + * @extends AbstractBlock + */ +const Table = Opal.Asciidoctor.Table; - if (pos === undefined) { - return string === nil ? false : self.test($$($nesting, 'Opal').$coerce_to(string, $$($nesting, 'String'), "to_str")); - } +/** + * Create a new Table element. + * @param {AbstractBlock} parent + * @param {Object|undefined} attributes + * @returns {Table} - a new {Table} object + */ +Table.create = function (parent, attributes) { + return this.$new(parent, toHash(attributes)) +}; - pos = $$($nesting, 'Opal').$coerce_to(pos, $$($nesting, 'Integer'), "to_int"); +/** + * Get the caption of the table. + * @returns {string} + * @memberof Table + */ +Table.prototype.getCaption = function () { + return this.caption +}; - if (string === nil) { - return false; - } +/** + * Get the rows of this table. + * @returns {Table.Rows} - an {Table.Rows} object with the members "head", "body" and "foot" + * @memberof Table + */ +Table.prototype.getRows = function () { + return this.rows +}; - string = $$($nesting, 'Opal').$coerce_to(string, $$($nesting, 'String'), "to_str"); +/** + * Get the columns of this table. + * @returns {Array<Column>} + * @memberof Table + */ +Table.prototype.getColumns = function () { + return this.columns +}; - if (pos < 0) { - pos += string.length; - if (pos < 0) { - return false; - } - } +/** + * Get the head rows of this table. + * @returns {Array<Array<Cell>>} - an Array of Array of Cell + * @memberof Table + */ +Table.prototype.getHeadRows = function () { + return this.rows.head +}; - // global RegExp maintains state, so not using self/this - var md, re = Opal.global_regexp(self); +/** + * Check if the table has a head rows. + * @returns {boolean} + * @memberof Table + */ +Table.prototype.hasHeadRows = function () { + return this.rows !== Opal.nil && this.rows.head.length > 0 +}; - md = re.exec(string); - if (md === null || md.index < pos) { - return false; - } else { - return true; - } - ; - }, $Regexp_match$ques$11.$$arity = -2); - - Opal.def(self, '$~', $Regexp_$$12 = function() { - var self = this; - if ($gvars._ == null) $gvars._ = nil; +/** + * Get the body rows of this table. + * @returns {Array<Array<Cell>>} - an Array of Array of Cell + * @memberof Table + */ +Table.prototype.getBodyRows = function () { + return this.rows.body +}; - return self['$=~']($gvars._) - }, $Regexp_$$12.$$arity = 0); - - Opal.def(self, '$source', $Regexp_source$13 = function $$source() { - var self = this; +/** + * Check if the table has a body rows. + * @returns {boolean} + */ +Table.prototype.hasBodyRows = function () { + return this.rows !== Opal.nil && this.rows.body.length > 0 +}; - return self.source; - }, $Regexp_source$13.$$arity = 0); - - Opal.def(self, '$options', $Regexp_options$14 = function $$options() { - var self = this; +/** + * Get the foot rows of this table. + * @returns {Array<Array<Cell>>} - an Array of Array of Cell + * @memberof Table + */ +Table.prototype.getFootRows = function () { + return this.rows.foot +}; - - if (self.uninitialized) { - self.$raise($$($nesting, 'TypeError'), "uninitialized Regexp") - } - var result = 0; - // should be supported in IE6 according to https://msdn.microsoft.com/en-us/library/7f5z26w4(v=vs.94).aspx - if (self.multiline) { - result |= $$($nesting, 'MULTILINE'); - } - if (self.ignoreCase) { - result |= $$($nesting, 'IGNORECASE'); - } - return result; - - }, $Regexp_options$14.$$arity = 0); - - Opal.def(self, '$casefold?', $Regexp_casefold$ques$15 = function() { - var self = this; +/** + * Check if the table has a foot rows. + * @returns {boolean} + */ +Table.prototype.hasFootRows = function () { + return this.rows !== Opal.nil && this.rows.foot.length > 0 +}; - return self.ignoreCase; - }, $Regexp_casefold$ques$15.$$arity = 0); - return Opal.alias(self, "to_s", "source"); - })($nesting[0], RegExp, $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'MatchData'); +/** + * Check if the table has a header option set. + * @returns {boolean} + * @memberof Table + */ +Table.prototype.hasHeaderOption = function () { + return this.has_header_option +}; - var $nesting = [self].concat($parent_nesting), $MatchData_initialize$16, $MatchData_$$$17, $MatchData_offset$18, $MatchData_$eq_eq$19, $MatchData_begin$20, $MatchData_end$21, $MatchData_captures$22, $MatchData_inspect$23, $MatchData_length$24, $MatchData_to_a$25, $MatchData_to_s$26, $MatchData_values_at$27; +/** + * Check if the table has the footer option set. + * @returns {boolean} + * @memberof Table + */ +Table.prototype.hasFooterOption = function () { + return this.isOption('footer') +}; - self.$$prototype.matches = nil; - - self.$attr_reader("post_match", "pre_match", "regexp", "string"); - - Opal.def(self, '$initialize', $MatchData_initialize$16 = function $$initialize(regexp, match_groups) { - var self = this; +/** + * Check if the table has the autowidth option set. + * @returns {boolean} + * @memberof Table + */ +Table.prototype.hasAutowidthOption = function () { + return this.isOption('autowidth') +}; - - $gvars["~"] = self; - self.regexp = regexp; - self.begin = match_groups.index; - self.string = match_groups.input; - self.pre_match = match_groups.input.slice(0, match_groups.index); - self.post_match = match_groups.input.slice(match_groups.index + match_groups[0].length); - self.matches = []; - - for (var i = 0, length = match_groups.length; i < length; i++) { - var group = match_groups[i]; +/** + * Get the number of rows in the table. + * Please note that the header and footer rows are also counted. + * @returns {number|undefined} + * @memberof Table + */ +Table.prototype.getRowCount = function () { + return this.getAttribute('rowcount') +}; - if (group == null) { - self.matches.push(nil); - } - else { - self.matches.push(group); - } - } - ; - }, $MatchData_initialize$16.$$arity = 2); - - Opal.def(self, '$[]', $MatchData_$$$17 = function($a) { - var $post_args, args, self = this; +/** + * Set the number of rows in the table. + * Please note that the header and footer rows are also counted. + * @param {number} value - the value + * @memberof Table + */ +Table.prototype.setRowCount = function (value) { + this.setAttribute('rowcount', value); +}; + +/** + * Get the number of columns in the table. + * @returns {number|undefined} + * @memberof Table + */ +Table.prototype.getColumnCount = function () { + return this.getAttribute('colcount') +}; + +/** + * Set the number of columns in the table. + * @param {number} value - the value + * @memberof Table + */ +Table.prototype.setColumnCount = function (value) { + this.setAttribute('colcount', value); +}; + +// Rows + +/** + * @namespace + */ +const Rows = Opal.Asciidoctor.Table.Rows; + +/** + * Create a new Rows element. + * @param {array<array<Cell>>} head + * @param {array<array<Cell>>} foot + * @param {array<array<Cell>>} body + * @returns Rows + */ +Rows.create = function (head, foot, body) { + return this.$new(head, foot, body) +}; + +/** + * Get head rows. + * @returns {array<array<Cell>>} + */ +Rows.prototype.getHead = function () { + return this.head +}; + +/** + * Get foot rows. + * @returns {array<array<Cell>>} + */ +Rows.prototype.getFoot = function () { + return this.foot +}; + +/** + * Get body rows. + * @returns {array<array<Cell>>} + */ +Rows.prototype.getBody = function () { + return this.body +}; + +/** + * Retrieve the rows grouped by section as a nested Array. + * + * Creates a 2-dimensional array of two element entries. + * The first element is the section name as a string. + * The second element is the Array of rows in that section. + * The entries are in document order (head, foot, body). + * @returns {[[string, array<array<Cell>>], [string, array<array<Cell>>], [string, array<array<Cell>>]]} + */ +Rows.prototype.bySection = function () { + return [['head', this.head], ['body', this.body], ['foot', this.foot]] +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self.matches, '[]', Opal.to_a(args)); - }, $MatchData_$$$17.$$arity = -1); - - Opal.def(self, '$offset', $MatchData_offset$18 = function $$offset(n) { - var self = this; +// Table Column - - if (n !== 0) { - self.$raise($$($nesting, 'ArgumentError'), "MatchData#offset only supports 0th element") - } - return [self.begin, self.begin + self.matches[n].length]; - - }, $MatchData_offset$18.$$arity = 1); - - Opal.def(self, '$==', $MatchData_$eq_eq$19 = function(other) { - var $a, $b, $c, $d, self = this; +/** + * Methods to manage the columns of an AsciiDoc table. + * In particular, it keeps track of the column specs. + * @namespace + * @extends AbstractNode + */ +const Column = Opal.Asciidoctor.Table.Column; - - if ($truthy($$($nesting, 'MatchData')['$==='](other))) { - } else { - return false - }; - return ($truthy($a = ($truthy($b = ($truthy($c = ($truthy($d = self.string == other.string) ? self.regexp.toString() == other.regexp.toString() : $d)) ? self.pre_match == other.pre_match : $c)) ? self.post_match == other.post_match : $b)) ? self.begin == other.begin : $a); - }, $MatchData_$eq_eq$19.$$arity = 1); - Opal.alias(self, "eql?", "=="); - - Opal.def(self, '$begin', $MatchData_begin$20 = function $$begin(n) { - var self = this; +/** + * Create a new Column element. + * @param {Table} table + * @param {number} index + * @param {Object|undefined} attributes + * @returns Column + */ +Column.create = function (table, index, attributes) { + return this.$new(table, index, toHash(attributes)) +}; - - if (n !== 0) { - self.$raise($$($nesting, 'ArgumentError'), "MatchData#begin only supports 0th element") - } - return self.begin; - - }, $MatchData_begin$20.$$arity = 1); - - Opal.def(self, '$end', $MatchData_end$21 = function $$end(n) { - var self = this; +/** + * Get the column number of this cell. + * @returns {number|undefined} + * @memberof Column + */ +Column.prototype.getColumnNumber = function () { + return this.getAttribute('colnumber') +}; - - if (n !== 0) { - self.$raise($$($nesting, 'ArgumentError'), "MatchData#end only supports 0th element") - } - return self.begin + self.matches[n].length; - - }, $MatchData_end$21.$$arity = 1); - - Opal.def(self, '$captures', $MatchData_captures$22 = function $$captures() { - var self = this; +/** + * Get the width of this cell. + * @returns {string|undefined} + * @memberof Column + */ +Column.prototype.getWidth = function () { + return this.getAttribute('width') +}; - return self.matches.slice(1) - }, $MatchData_captures$22.$$arity = 0); - - Opal.def(self, '$inspect', $MatchData_inspect$23 = function $$inspect() { - var self = this; +/** + * Get the horizontal align of this cell. + * @returns {string|undefined} + * @memberof Column + */ +Column.prototype.getHorizontalAlign = function () { + return this.getAttribute('halign') +}; - - var str = "#<MatchData " + (self.matches[0]).$inspect(); +/** + * Get the vertical align of this cell. + * @returns {string|undefined} + * @memberof Column + */ +Column.prototype.getVerticalAlign = function () { + return this.getAttribute('valign') +}; - for (var i = 1, length = self.matches.length; i < length; i++) { - str += " " + i + ":" + (self.matches[i]).$inspect(); - } +/** + * Get the style of this cell. + * @returns {string} + * @memberof Column + */ +Column.prototype.getStyle = function () { + const style = this.style; + return style === Opal.nil ? undefined : style +}; - return str + ">"; - - }, $MatchData_inspect$23.$$arity = 0); - - Opal.def(self, '$length', $MatchData_length$24 = function $$length() { - var self = this; +// Table Cell - return self.matches.length - }, $MatchData_length$24.$$arity = 0); - Opal.alias(self, "size", "length"); - - Opal.def(self, '$to_a', $MatchData_to_a$25 = function $$to_a() { - var self = this; +/** + * Methods for managing the cells in an AsciiDoc table. + * @namespace + * @extends AbstractBlock + */ +const Cell = Opal.Asciidoctor.Table.Cell; - return self.matches - }, $MatchData_to_a$25.$$arity = 0); - - Opal.def(self, '$to_s', $MatchData_to_s$26 = function $$to_s() { - var self = this; +/** + * Create a new Cell element + * @param {Column} column + * @param {string} cellText + * @param {Object|undefined} attributes + * @param {Object|undefined} opts + * @returns {Cell} + */ +Cell.create = function (column, cellText, attributes, opts) { + return this.$new(column, cellText, toHash(attributes), toHash(opts)) +}; - return self.matches[0] - }, $MatchData_to_s$26.$$arity = 0); - return (Opal.def(self, '$values_at', $MatchData_values_at$27 = function $$values_at($a) { - var $post_args, args, self = this; +/** + * Get the column span of this {@link Cell} node. + * @returns {number} - An Integer of the number of columns this cell will span (default: undefined) + * @memberof Cell + */ +Cell.prototype.getColumnSpan = function () { + const colspan = this.colspan; + return colspan === Opal.nil ? undefined : colspan +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var i, a, index, values = []; +/** + * Set the column span of this {@link Cell} node. + * @param {number} value + * @returns {number} - The new colspan value + * @memberof Cell + */ +Cell.prototype.setColumnSpan = function (value) { + return this['$colspan='](value) +}; - for (i = 0; i < args.length; i++) { +/** + * Get the row span of this {@link Cell} node + * @returns {number|undefined} - An Integer of the number of rows this cell will span (default: undefined) + * @memberof Cell + */ +Cell.prototype.getRowSpan = function () { + const rowspan = this.rowspan; + return rowspan === Opal.nil ? undefined : rowspan +}; - if (args[i].$$is_range) { - a = (args[i]).$to_a(); - a.unshift(i, 1); - Array.prototype.splice.apply(args, a); - } +/** + * Set the row span of this {@link Cell} node + * @param {number} value + * @returns {number} - The new rowspan value + * @memberof Cell + */ +Cell.prototype.setRowSpan = function (value) { + return this['$rowspan='](value) +}; - index = $$($nesting, 'Opal')['$coerce_to!'](args[i], $$($nesting, 'Integer'), "to_int"); +/** + * Get the content of the cell. + * This method should not be used for cells in the head row or that have the literal style. + * @returns {string} + * @memberof Cell + */ +Cell.prototype.getContent = function () { + return this.$content() +}; - if (index < 0) { - index += self.matches.length; - if (index < 0) { - values.push(nil); - continue; - } - } +/** + * Get the text of the cell. + * @returns {string} + * @memberof Cell + */ +Cell.prototype.getText = function () { + return this.$text() +}; - values.push(self.matches[index]); - } +/** + * Get the source of the cell. + * @returns {string} + * @memberof Cell + */ +Cell.prototype.getSource = function () { + return this.$source() +}; - return values; - ; - }, $MatchData_values_at$27.$$arity = -1), nil) && 'values_at'; - })($nesting[0], null, $nesting); +/** + * Get the lines of the cell. + * @returns {Array<string>} + * @memberof Cell + */ +Cell.prototype.getLines = function () { + return this.$lines() }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/string"] = function(Opal) { - function $rb_divide(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send, $gvars = Opal.gvars; +/** + * Get the line number of the cell. + * @returns {number|undefined} + * @memberof Cell + */ +Cell.prototype.getLineNumber = function () { + const lineno = this.$lineno(); + return lineno === Opal.nil ? undefined : lineno +}; - Opal.add_stubs(['$require', '$include', '$coerce_to?', '$coerce_to', '$raise', '$===', '$format', '$to_s', '$respond_to?', '$to_str', '$<=>', '$==', '$=~', '$new', '$force_encoding', '$casecmp', '$empty?', '$ljust', '$ceil', '$/', '$+', '$rjust', '$floor', '$to_a', '$each_char', '$to_proc', '$coerce_to!', '$copy_singleton_methods', '$initialize_clone', '$initialize_dup', '$enum_for', '$size', '$chomp', '$[]', '$to_i', '$each_line', '$class', '$match', '$match?', '$captures', '$proc', '$succ', '$escape']); - - self.$require("corelib/comparable"); - self.$require("corelib/regexp"); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'String'); +/** + * Get the source file of the cell. + * @returns {string|undefined} + * @memberof Cell + */ +Cell.prototype.getFile = function () { + const file = this.$file(); + return file === Opal.nil ? undefined : file +}; - var $nesting = [self].concat($parent_nesting), $String___id__$1, $String_try_convert$2, $String_new$3, $String_initialize$4, $String_$percent$5, $String_$$6, $String_$plus$7, $String_$lt_eq_gt$8, $String_$eq_eq$9, $String_$eq_tilde$10, $String_$$$11, $String_b$12, $String_capitalize$13, $String_casecmp$14, $String_casecmp$ques$15, $String_center$16, $String_chars$17, $String_chomp$18, $String_chop$19, $String_chr$20, $String_clone$21, $String_dup$22, $String_count$23, $String_delete$24, $String_delete_prefix$25, $String_delete_suffix$26, $String_downcase$27, $String_each_char$28, $String_each_line$30, $String_empty$ques$31, $String_end_with$ques$32, $String_gsub$33, $String_hash$34, $String_hex$35, $String_include$ques$36, $String_index$37, $String_inspect$38, $String_intern$39, $String_lines$40, $String_length$41, $String_ljust$42, $String_lstrip$43, $String_ascii_only$ques$44, $String_match$45, $String_match$ques$46, $String_next$47, $String_oct$48, $String_ord$49, $String_partition$50, $String_reverse$51, $String_rindex$52, $String_rjust$53, $String_rpartition$54, $String_rstrip$55, $String_scan$56, $String_split$57, $String_squeeze$58, $String_start_with$ques$59, $String_strip$60, $String_sub$61, $String_sum$62, $String_swapcase$63, $String_to_f$64, $String_to_i$65, $String_to_proc$66, $String_to_s$68, $String_tr$69, $String_tr_s$70, $String_upcase$71, $String_upto$72, $String_instance_variables$73, $String__load$74, $String_unicode_normalize$75, $String_unicode_normalized$ques$76, $String_unpack$77, $String_unpack1$78; +/** + * Get the style of the cell. + * @returns {string|undefined} + * @memberof Cell + */ +Cell.prototype.getStyle = function () { + const style = this.$style(); + return style === Opal.nil ? undefined : style +}; - - self.$include($$($nesting, 'Comparable')); - - Opal.defineProperty(self.$$prototype, '$$is_string', true); +/** + * Get the column of this cell. + * @returns {Column|undefined} + * @memberof Cell + */ +Cell.prototype.getColumn = function () { + const column = this.$column(); + return column === Opal.nil ? undefined : column +}; - Opal.defineProperty(self.$$prototype, '$$cast', function(string) { - var klass = this.$$class; - if (klass.$$constructor === String) { - return string; - } else { - return new klass.$$constructor(string); - } - }); - ; - - Opal.def(self, '$__id__', $String___id__$1 = function $$__id__() { - var self = this; +/** + * Get the width of this cell. + * @returns {string|undefined} + * @memberof Cell + */ +Cell.prototype.getWidth = function () { + return this.getAttribute('width') +}; - return self.toString(); - }, $String___id__$1.$$arity = 0); - Opal.alias(self, "object_id", "__id__"); - Opal.defs(self, '$try_convert', $String_try_convert$2 = function $$try_convert(what) { - var self = this; +/** + * Get the column width in percentage of this cell. + * @returns {string|undefined} + * @memberof Cell + */ +Cell.prototype.getColumnPercentageWidth = function () { + return this.getAttribute('colpcwidth') +}; - return $$($nesting, 'Opal')['$coerce_to?'](what, $$($nesting, 'String'), "to_str") - }, $String_try_convert$2.$$arity = 1); - Opal.defs(self, '$new', $String_new$3 = function(str) { - var self = this; +/** + * Get the nested {Document} of this cell when style is 'asciidoc'. + * @returns {Document|undefined} - the nested {Document} + * @memberof Cell + */ +Cell.prototype.getInnerDocument = function () { + const innerDocument = this.inner_document; + return innerDocument === Opal.nil ? undefined : innerDocument +}; - - - if (str == null) { - str = ""; - }; - str = $$($nesting, 'Opal').$coerce_to(str, $$($nesting, 'String'), "to_str"); - return new self.$$constructor(str);; - }, $String_new$3.$$arity = -1); - - Opal.def(self, '$initialize', $String_initialize$4 = function $$initialize(str) { - var self = this; +// Templates - - ; - - if (str === undefined) { - return self; - } - ; - return self.$raise($$($nesting, 'NotImplementedError'), "Mutable strings are not supported in Opal."); - }, $String_initialize$4.$$arity = -1); - - Opal.def(self, '$%', $String_$percent$5 = function(data) { - var self = this; +/** + * @description + * This API is experimental and subject to change. + * + * Please note that this API is currently only available in a Node environment. + * We recommend to use a custom converter if you are running in the browser. + * + * @namespace + * @module Converter/TemplateConverter + */ +const TemplateConverter = Opal.Asciidoctor.Converter.TemplateConverter; - if ($truthy($$($nesting, 'Array')['$==='](data))) { - return $send(self, 'format', [self].concat(Opal.to_a(data))) - } else { - return self.$format(self, data) - } - }, $String_$percent$5.$$arity = 1); - - Opal.def(self, '$*', $String_$$6 = function(count) { - var self = this; +if (TemplateConverter) { + // Alias + Opal.Asciidoctor.TemplateConverter = TemplateConverter; - - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); + /** + * Create a new TemplateConverter. + * @param {string} backend - the backend name + * @param templateDirectories - a list of template directories + * @param {Object} opts - a JSON of options + * @param {string} opts.template_engine - the name of the template engine + * @param {Object} [opts.template_cache] - an optional template cache + * @param {Object} [opts.template_cache.scans] - a JSON of template objects keyed by template name keyed by path patterns + * @param {Object} [opts.template_cache.templates] - a JSON of template objects keyed by file paths + * @returns {TemplateConverter} + * @memberof Converter/TemplateConverter + */ + TemplateConverter.create = function (backend, templateDirectories, opts) { + if (opts && opts.template_cache) { + opts.template_cache = toHash(opts.template_cache); + } + this.$new(backend, templateDirectories, toHash(opts)); + }; - if (count < 0) { - self.$raise($$($nesting, 'ArgumentError'), "negative argument") + /** + * @returns {Object} - The global cache + * @memberof Converter/TemplateConverter + */ + TemplateConverter.getCache = function () { + const caches = fromHash(this.caches); + if (caches) { + if (caches.scans) { + caches.scans = fromHash(caches.scans); + for (const key in caches.scans) { + caches.scans[key] = fromHash(caches.scans[key]); + } } - - if (count === 0) { - return self.$$cast(''); + if (caches.templates) { + caches.templates = fromHash(caches.templates); } + } + return caches + }; - var result = '', - string = self.toString(); + /** + * Clear the global cache. + * @memberof Converter/TemplateConverter + */ + TemplateConverter.clearCache = function () { + this.$clear_caches(); + }; - // All credit for the bit-twiddling magic code below goes to Mozilla - // polyfill implementation of String.prototype.repeat() posted here: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat + /** + * Convert an {AbstractNode} to the backend format using the named template. + * + * Looks for a template that matches the value of the template name or, + * if the template name is not specified, the value of the {@see AbstractNode.getNodeName} function. + * + * @param {AbstractNode} node - the AbstractNode to convert + * @param {string} templateName - the {string} name of the template to use, or the node name of the node if a template name is not specified. (optional, default: undefined) + * @param {Object} opts - an optional JSON that is passed as local variables to the template. (optional, default: undefined) + * @returns {string} - The {string} result from rendering the template + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.convert = function (node, templateName, opts) { + return this.$convert(node, templateName, toHash(opts)) + }; - if (string.length * count >= 1 << 28) { - self.$raise($$($nesting, 'RangeError'), "multiply count must not overflow maximum string size") - } + /** + * Checks whether there is a template registered with the specified name. + * + * @param {string} name - the {string} template name + * @returns {boolean} - a {boolean} that indicates whether a template is registered for the specified template name. + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.handles = function (name) { + return this['$handles?'](name) + }; - for (;;) { - if ((count & 1) === 1) { - result += string; - } - count >>>= 1; - if (count === 0) { - break; - } - string += string; - } + /** + * Converts the {AbstractNode} using only its converted content. + * + * @param {AbstractNode} node + * @returns {string} - the converted {string} content. + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.getContentOnly = function (node) { + return this.$content_only(node) + }; - return self.$$cast(result); - - }, $String_$$6.$$arity = 1); - - Opal.def(self, '$+', $String_$plus$7 = function(other) { - var self = this; + /** + * Skips conversion of the {AbstractNode}. + * + * @param {AbstractNode} node + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.skip = function (node) { + this.$skip(node); + }; - - other = $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'String'), "to_str"); - return self + other.$to_s(); - }, $String_$plus$7.$$arity = 1); - - Opal.def(self, '$<=>', $String_$lt_eq_gt$8 = function(other) { - var self = this; + /** + * Retrieves the templates that this converter manages. + * + * @returns {Object} - a JSON of template objects keyed by template name + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.getTemplates = function () { + return fromHash(this.$templates()) + }; - if ($truthy(other['$respond_to?']("to_str"))) { - - other = other.$to_str().$to_s(); - return self > other ? 1 : (self < other ? -1 : 0);; - } else { - - var cmp = other['$<=>'](self); + /** + * Registers a template with this converter. + * + * @param {string} name - the {string} template name + * @param {Object} template - the template object to register + * @returns {Object} - the template object + * @memberof Converter/TemplateConverter + */ + TemplateConverter.prototype.register = function (name, template) { + return this.$register(name, template) + }; - if (cmp === nil) { - return nil; - } - else { - return cmp > 0 ? -1 : (cmp < 0 ? 1 : 0); - } - - } - }, $String_$lt_eq_gt$8.$$arity = 1); - - Opal.def(self, '$==', $String_$eq_eq$9 = function(other) { - var self = this; + /** + * @namespace + * @description + * This API is experimental and subject to change. + * + * Please note that this API is currently only available in a Node environment. + * We recommend to use a custom converter if you are running in the browser. + * + * A pluggable adapter for integrating a template engine into the built-in template converter. + */ + const TemplateEngine = {}; + TemplateEngine.registry = {}; - - if (other.$$is_string) { - return self.toString() === other.toString(); - } - if ($$($nesting, 'Opal')['$respond_to?'](other, "to_str")) { - return other['$=='](self); - } - return false; - - }, $String_$eq_eq$9.$$arity = 1); - Opal.alias(self, "eql?", "=="); - Opal.alias(self, "===", "=="); - - Opal.def(self, '$=~', $String_$eq_tilde$10 = function(other) { - var self = this; + // Alias + Opal.Asciidoctor.TemplateEngine = TemplateEngine; - - if (other.$$is_string) { - self.$raise($$($nesting, 'TypeError'), "type mismatch: String given"); + /** + * Register a template engine adapter for the given names. + * @param {string|Array} names - a {string} name or an {Array} of {string} names + * @param {Object} templateEngineAdapter - a template engine adapter instance + * @example + * const fs = require('fs') + * class DotTemplateEngineAdapter { + * constructor () { + * this.doT = require('dot') + * } + * compile (file, _) { + * const templateFn = this.doT.template(fs.readFileSync(file, 'utf8')) + * return { + * render: templateFn + * } + * } + * } + * asciidoctor.TemplateEngine.register('dot, new DotTemplateEngineAdapter()) + * @memberof TemplateEngine + */ + TemplateEngine.register = function (names, templateEngineAdapter) { + if (typeof names === 'string') { + this.registry[names] = templateEngineAdapter; + } else { + // array + for (let i = 0; i < names.length; i++) { + const name = names[i]; + this.registry[name] = templateEngineAdapter; } + } + }; +} + +/** + * @namespace + * @module Converter/CompositeConverter + */ +const CompositeConverter = Opal.Asciidoctor.Converter.CompositeConverter; - return other['$=~'](self); - - }, $String_$eq_tilde$10.$$arity = 1); - - Opal.def(self, '$[]', $String_$$$11 = function(index, length) { - var self = this; +if (CompositeConverter) { + // Alias + Opal.Asciidoctor.CompositeConverter = CompositeConverter; - - ; - - var size = self.length, exclude; + /** + * Delegates to the first converter that identifies itself as the handler for the given transform. + * The optional Hash is passed as the last option to the delegate's convert method. + * + * @param node - the AbstractNode to convert + * @param [transform] - the optional {string} transform, or the name of the node if no transform is specified. (optional, default: undefined) + * @param [opts] - an optional JSON that is passed as local variables to the template. (optional, default: undefined) + * @returns The {string} result from the delegate's convert method + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.convert = function (node, transform, opts) { + return this.$convert(node, transform, toHash(opts)) + }; - if (index.$$is_range) { - exclude = index.excl; - length = $$($nesting, 'Opal').$coerce_to(index.end, $$($nesting, 'Integer'), "to_int"); - index = $$($nesting, 'Opal').$coerce_to(index.begin, $$($nesting, 'Integer'), "to_int"); + /** + * Converts the {AbstractNode} using only its converted content. + * + * @param {AbstractNode} node + * @returns {string} - the converted {string} content. + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.getContentOnly = function (node) { + return this.$content_only(node) + }; - if (Math.abs(index) > size) { - return nil; - } + /** + * Skips conversion of the {AbstractNode}. + * + * @param {AbstractNode} node + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.skip = function (node) { + this.$skip(node); + }; - if (index < 0) { - index += size; - } + /** + * Get the Array of Converter objects in the chain. + * @returns {[Converter]} + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.getConverters = function () { + return this.converters + }; - if (length < 0) { - length += size; - } + /** + * Retrieve the converter for the specified transform. + * @param transform + * @returns {Converter|undefined} + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.getConverter = function (transform) { + const converter = this.$converter_for(transform); + return converter === Opal.nil ? undefined : converter + }; - if (!exclude) { - length += 1; - } + /** + * Find the converter for the specified transform. + * Throw an exception if no converter is found. + * + * @param transform + * @returns {Converter} - the matching converter + * @throws Error if no converter is found + * @memberof Converter/CompositeConverter + */ + CompositeConverter.prototype.findConverter = function (transform) { + return this.$find_converter(transform) + }; +} - length = length - index; +// Converter API - if (length < 0) { - length = 0; - } +/** + * @namespace + * @module Converter + */ +const Converter = Opal.const_get_qualified(Opal.Asciidoctor, 'Converter'); - return self.$$cast(self.substr(index, length)); - } +// Alias +Opal.Asciidoctor.Converter = Converter; +/** + * Convert the specified node. + * + * @param {AbstractNode} node - the AbstractNode to convert + * @param {string} transform - an optional String transform that hints at + * which transformation should be applied to this node. + * @param {Object} opts - a JSON of options that provide additional hints about how to convert the node (default: {}) + * @returns the {Object} result of the conversion, typically a {string}. + * @memberof Converter + */ +Converter.prototype.convert = function (node, transform, opts) { + return this.$convert(node, transform, toHash(opts)) +}; - if (index.$$is_string) { - if (length != null) { - self.$raise($$($nesting, 'TypeError')) - } - return self.indexOf(index) !== -1 ? self.$$cast(index) : nil; - } +/** + * Create an instance of the converter bound to the specified backend. + * + * @param {string} backend - look for a converter bound to this keyword. + * @param {Object} opts - a JSON of options to pass to the converter (default: {}) + * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST. + * @memberof Converter + */ +Converter.create = function (backend, opts) { + return this.$create(backend, toHash(opts)) +}; +// Converter Factory API - if (index.$$is_regexp) { - var match = self.match(index); +/** + * @namespace + * @module Converter/Factory + */ +const ConverterFactory = Opal.Asciidoctor.Converter.Factory; - if (match === null) { - ($gvars["~"] = nil) - return nil; - } +const ConverterBase = Opal.Asciidoctor.Converter.Base; - ($gvars["~"] = $$($nesting, 'MatchData').$new(index, match)) +// Alias +Opal.Asciidoctor.ConverterFactory = ConverterFactory; - if (length == null) { - return self.$$cast(match[0]); - } +const ConverterBackendTraits = Opal.Asciidoctor.Converter.BackendTraits; - length = $$($nesting, 'Opal').$coerce_to(length, $$($nesting, 'Integer'), "to_int"); +// Alias +Opal.Asciidoctor.ConverterBackendTraits = ConverterBackendTraits; - if (length < 0 && -length < match.length) { - return self.$$cast(match[length += match.length]); - } +/** + * Register a custom converter in the global converter factory to handle conversion to the specified backends. + * If the backend value is an asterisk, the converter is used to handle any backend that does not have an explicit converter. + * + * @param converter - The Converter instance to register + * @param backends {Array} - A {string} {Array} of backend names that this converter should be registered to handle (optional, default: ['*']) + * @return {*} - Returns nothing + * @memberof Converter/Factory + */ +ConverterFactory.register = function (converter, backends) { + const args = [bridgeConverter(converter)].concat(backends); + return Converter.$register.apply(Converter, args) +}; - if (length >= 0 && length < match.length) { - return self.$$cast(match[length]); - } +/** + * Retrieves the singleton instance of the converter factory. + * + * @param {boolean} initialize - instantiate the singleton if it has not yet + * been instantiated. If this value is false and the singleton has not yet been + * instantiated, this method returns a fresh instance. + * @returns {Converter/Factory} an instance of the converter factory. + * @memberof Converter/Factory + */ +ConverterFactory.getDefault = function (initialize) { + return this.$default(initialize) +}; - return nil; - } +/** + * Create an instance of the converter bound to the specified backend. + * + * @param {string} backend - look for a converter bound to this keyword. + * @param {Object} opts - a JSON of options to pass to the converter (default: {}) + * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST. + * @memberof Converter/Factory + */ +ConverterFactory.prototype.create = function (backend, opts) { + return this.$create(backend, toHash(opts)) +}; +/** + * Get the converter registry. + * @returns the registry of converter instances or classes keyed by backend name + * @memberof Converter/Factory + */ +ConverterFactory.getRegistry = function () { + return fromHash(Converter.$registry()) +}; - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); +/** + * Lookup the custom converter registered with this factory to handle the specified backend. + * + * @param {string} backend - The {string} backend name. + * @returns the {Converter} class or instance registered to convert the specified backend or undefined if no match is found. + * @memberof Converter/Factory + */ +ConverterFactory.for = function (backend) { + const converter = Converter.$for(backend); + return converter === Opal.nil ? undefined : converter +}; - if (index < 0) { - index += size; - } +/* + * Unregister any custom converter classes that are registered with this factory. + * Intended for testing only! + */ +ConverterFactory.unregisterAll = function () { + const internalRegistry = Converter.DefaultFactory.$$cvars['@@registry']; + Converter.DefaultFactory.$$cvars['@@registry'] = toHash({ html5: internalRegistry['$[]']('html5') }); +}; - if (length == null) { - if (index >= size || index < 0) { - return nil; - } - return self.$$cast(self.substr(index, 1)); - } +// Built-in converter - length = $$($nesting, 'Opal').$coerce_to(length, $$($nesting, 'Integer'), "to_int"); +/** + * @namespace + * @module Converter/Html5Converter + */ +const Html5Converter = Opal.Asciidoctor.Converter.Html5Converter; - if (length < 0) { - return nil; - } +// Alias +Opal.Asciidoctor.Html5Converter = Html5Converter; - if (index > size || index < 0) { - return nil; - } +/** + * Create a new Html5Converter. + * @returns {Html5Converter} - a Html5Converter + * @memberof Converter/Html5Converter + */ +Html5Converter.create = function () { + return this.$new() +}; - return self.$$cast(self.substr(index, length)); - ; - }, $String_$$$11.$$arity = -2); - Opal.alias(self, "byteslice", "[]"); - - Opal.def(self, '$b', $String_b$12 = function $$b() { - var self = this; +/** + * Converts an {AbstractNode} using the given transform. + * This method must be implemented by a concrete converter class. + * + * @param {AbstractNode} node - The concrete instance of AbstractNode to convert. + * @param {string} [transform] - An optional String transform that hints at which transformation should be applied to this node. + * If a transform is not given, the transform is often derived from the value of the {AbstractNode#getNodeName} property. (optional, default: undefined) + * @param {Object} [opts]- An optional JSON of options hints about how to convert the node. (optional, default: undefined) + * + * @returns {string} - the String result. + * @memberof Converter/Html5Converter + */ +Html5Converter.prototype.convert = function (node, transform, opts) { + return this.$convert(node, transform, opts) +}; - return self.$force_encoding("binary") - }, $String_b$12.$$arity = 0); - - Opal.def(self, '$capitalize', $String_capitalize$13 = function $$capitalize() { - var self = this; +/* global Opal, fromHash, toHash, initializeClass */ +// Extensions API - return self.$$cast(self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()); - }, $String_capitalize$13.$$arity = 0); - - Opal.def(self, '$casecmp', $String_casecmp$14 = function $$casecmp(other) { - var self = this; +/** + * @private + */ +const toBlock = function (block) { + // arity is a mandatory field + block.$$arity = block.length; + return block +}; - - if ($truthy(other['$respond_to?']("to_str"))) { - } else { - return nil - }; - other = $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'String'), "to_str").$to_s(); - - var ascii_only = /^[\x00-\x7F]*$/; - if (ascii_only.test(self) && ascii_only.test(other)) { - self = self.toLowerCase(); - other = other.toLowerCase(); - } - ; - return self['$<=>'](other); - }, $String_casecmp$14.$$arity = 1); - - Opal.def(self, '$casecmp?', $String_casecmp$ques$15 = function(other) { - var self = this; +const registerExtension = function (registry, type, processor, name) { + if (typeof processor === 'object' || processor.$$is_class) { + // processor is an instance or a class + return registry['$' + type](processor, name) + } else { + // processor is a function/lambda + return Opal.send(registry, type, name && [name], toBlock(processor)) + } +}; - - var cmp = self.$casecmp(other); - if (cmp === nil) { - return nil; - } else { - return cmp === 0; - } - - }, $String_casecmp$ques$15.$$arity = 1); - - Opal.def(self, '$center', $String_center$16 = function $$center(width, padstr) { - var self = this; +/** + * @namespace + * @description + * Extensions provide a way to participate in the parsing and converting + * phases of the AsciiDoc processor or extend the AsciiDoc syntax. + * + * The various extensions participate in AsciiDoc processing as follows: + * + * 1. After the source lines are normalized, {{@link Extensions/Preprocessor}}s modify or replace + * the source lines before parsing begins. {{@link Extensions/IncludeProcessor}}s are used to + * process include directives for targets which they claim to handle. + * 2. The Parser parses the block-level content into an abstract syntax tree. + * Custom blocks and block macros are processed by associated {{@link Extensions/BlockProcessor}}s + * and {{@link Extensions/BlockMacroProcessor}}s, respectively. + * 3. {{@link Extensions/TreeProcessor}}s are run on the abstract syntax tree. + * 4. Conversion of the document begins, at which point inline markup is processed + * and converted. Custom inline macros are processed by associated {InlineMacroProcessor}s. + * 5. {{@link Extensions/Postprocessor}}s modify or replace the converted document. + * 6. The output is written to the output stream. + * + * Extensions may be registered globally using the {Extensions.register} method + * or added to a custom {Registry} instance and passed as an option to a single + * Asciidoctor processor. + * + * @example + * asciidoctor.Extensions.register(function () { + * this.block(function () { + * const self = this + * self.named('shout') + * self.onContext('paragraph') + * self.process(function (parent, reader) { + * const lines = reader.getLines().map(function (l) { return l.toUpperCase(); }) + * return self.createBlock(parent, 'paragraph', lines) + * }) + * }) + * }) + */ +const Extensions = Opal.const_get_qualified(Opal.Asciidoctor, 'Extensions'); - - - if (padstr == null) { - padstr = " "; - }; - width = $$($nesting, 'Opal').$coerce_to(width, $$($nesting, 'Integer'), "to_int"); - padstr = $$($nesting, 'Opal').$coerce_to(padstr, $$($nesting, 'String'), "to_str").$to_s(); - if ($truthy(padstr['$empty?']())) { - self.$raise($$($nesting, 'ArgumentError'), "zero width padding")}; - if ($truthy(width <= self.length)) { - return self}; - - var ljustified = self.$ljust($rb_divide($rb_plus(width, self.length), 2).$ceil(), padstr), - rjustified = self.$rjust($rb_divide($rb_plus(width, self.length), 2).$floor(), padstr); +// Alias +Opal.Asciidoctor.Extensions = Extensions; - return self.$$cast(rjustified + ljustified.slice(self.length)); - ; - }, $String_center$16.$$arity = -2); - - Opal.def(self, '$chars', $String_chars$17 = function $$chars() { - var $iter = $String_chars$17.$$p, block = $iter || nil, self = this; +/** + * Create a new {@link Extensions/Registry}. + * @param {string} name + * @param {function} block + * @memberof Extensions + * @returns {Extensions/Registry} - returns a {@link Extensions/Registry} + */ +Extensions.create = function (name, block) { + if (typeof name === 'function' && typeof block === 'undefined') { + return Opal.send(this, 'create', null, toBlock(name)) + } else if (typeof block === 'function') { + return Opal.send(this, 'create', [name], toBlock(block)) + } else { + return this.$create() + } +}; - if ($iter) $String_chars$17.$$p = null; - - - if ($iter) $String_chars$17.$$p = null;; - if ($truthy(block)) { - } else { - return self.$each_char().$to_a() - }; - return $send(self, 'each_char', [], block.$to_proc()); - }, $String_chars$17.$$arity = 0); - - Opal.def(self, '$chomp', $String_chomp$18 = function $$chomp(separator) { - var self = this; - if ($gvars["/"] == null) $gvars["/"] = nil; +/** + * @memberof Extensions + */ +Extensions.register = function (name, block) { + if (typeof name === 'function' && typeof block === 'undefined') { + return Opal.send(this, 'register', null, toBlock(name)) + } else { + return Opal.send(this, 'register', [name], toBlock(block)) + } +}; - - - if (separator == null) { - separator = $gvars["/"]; - }; - if ($truthy(separator === nil || self.length === 0)) { - return self}; - separator = $$($nesting, 'Opal')['$coerce_to!'](separator, $$($nesting, 'String'), "to_str").$to_s(); - - var result; +/** + * Get statically-registered extension groups. + * @memberof Extensions + */ +Extensions.getGroups = function () { + return fromHash(this.$groups()) +}; - if (separator === "\n") { - result = self.replace(/\r?\n?$/, ''); - } - else if (separator === "") { - result = self.replace(/(\r?\n)+$/, ''); - } - else if (self.length >= separator.length) { - var tail = self.substr(self.length - separator.length, separator.length); +/** + * Unregister all statically-registered extension groups. + * @memberof Extensions + */ +Extensions.unregisterAll = function () { + this.$unregister_all(); +}; - if (tail === separator) { - result = self.substr(0, self.length - separator.length); - } - } +/** + * Unregister the specified statically-registered extension groups. + * + * NOTE Opal cannot delete an entry from a Hash that is indexed by symbol, so + * we have to resort to using low-level operations in this method. + * + * @memberof Extensions + */ +Extensions.unregister = function () { + const names = Array.prototype.concat.apply([], arguments); + const groups = this.$groups(); + const groupNameIdx = {}; + let i = 0; + const groupSymbolNames = groups.$$keys; + for (; i < groupSymbolNames.length; i++) { + const groupSymbolName = groupSymbolNames[i]; + groupNameIdx[groupSymbolName.toString()] = groupSymbolName; + } + for (let j = 0; j < names.length; j++) { + const groupStringName = names[j]; + if (groupStringName in groupNameIdx) Opal.hash_delete(groups, groupNameIdx[groupStringName]); + } +}; - if (result != null) { - return self.$$cast(result); - } - ; - return self; - }, $String_chomp$18.$$arity = -1); - - Opal.def(self, '$chop', $String_chop$19 = function $$chop() { - var self = this; +/** + * @namespace + * @module Extensions/Registry + */ +const Registry = Extensions.Registry; - - var length = self.length, result; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.getGroups = Extensions.getGroups; - if (length <= 1) { - result = ""; - } else if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") { - result = self.substr(0, length - 2); - } else { - result = self.substr(0, length - 1); - } +/** + * @memberof Extensions/Registry + */ +Registry.prototype.unregisterAll = function () { + this.groups = Opal.hash(); +}; - return self.$$cast(result); - - }, $String_chop$19.$$arity = 0); - - Opal.def(self, '$chr', $String_chr$20 = function $$chr() { - var self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.unregister = Extensions.unregister; - return self.charAt(0); - }, $String_chr$20.$$arity = 0); - - Opal.def(self, '$clone', $String_clone$21 = function $$clone() { - var self = this, copy = nil; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.prefer = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + if (typeof processor === 'object' || processor.$$is_class) { + // processor is an instance or a class + return this.$prefer(name, processor) + } else { + // processor is a function/lambda + return Opal.send(this, 'prefer', name && [name], toBlock(processor)) + } +}; - - copy = self.slice(); - copy.$copy_singleton_methods(self); - copy.$initialize_clone(self); - return copy; - }, $String_clone$21.$$arity = 0); - - Opal.def(self, '$dup', $String_dup$22 = function $$dup() { - var self = this, copy = nil; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.block = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'block', processor, name) +}; - - copy = self.slice(); - copy.$initialize_dup(self); - return copy; - }, $String_dup$22.$$arity = 0); - - Opal.def(self, '$count', $String_count$23 = function $$count($a) { - var $post_args, sets, self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.inlineMacro = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'inline_macro', processor, name) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - sets = $post_args;; - - if (sets.length === 0) { - self.$raise($$($nesting, 'ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)") - } - var char_class = char_class_from_char_sets(sets); - if (char_class === null) { - return 0; - } - return self.length - self.replace(new RegExp(char_class, 'g'), '').length; - ; - }, $String_count$23.$$arity = -1); - - Opal.def(self, '$delete', $String_delete$24 = function($a) { - var $post_args, sets, self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.includeProcessor = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'include_processor', processor, name) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - sets = $post_args;; - - if (sets.length === 0) { - self.$raise($$($nesting, 'ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)") - } - var char_class = char_class_from_char_sets(sets); - if (char_class === null) { - return self; - } - return self.$$cast(self.replace(new RegExp(char_class, 'g'), '')); - ; - }, $String_delete$24.$$arity = -1); - - Opal.def(self, '$delete_prefix', $String_delete_prefix$25 = function $$delete_prefix(prefix) { - var self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.blockMacro = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'block_macro', processor, name) +}; - - if (!prefix.$$is_string) { - (prefix = $$($nesting, 'Opal').$coerce_to(prefix, $$($nesting, 'String'), "to_str")) - } +/** + * @memberof Extensions/Registry + */ +Registry.prototype.treeProcessor = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'tree_processor', processor, name) +}; - if (self.slice(0, prefix.length) === prefix) { - return self.$$cast(self.slice(prefix.length)); - } else { - return self; - } - - }, $String_delete_prefix$25.$$arity = 1); - - Opal.def(self, '$delete_suffix', $String_delete_suffix$26 = function $$delete_suffix(suffix) { - var self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.postprocessor = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'postprocessor', processor, name) +}; - - if (!suffix.$$is_string) { - (suffix = $$($nesting, 'Opal').$coerce_to(suffix, $$($nesting, 'String'), "to_str")) - } +/** + * @memberof Extensions/Registry + */ +Registry.prototype.preprocessor = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'preprocessor', processor, name) +}; - if (self.slice(self.length - suffix.length) === suffix) { - return self.$$cast(self.slice(0, self.length - suffix.length)); - } else { - return self; - } - - }, $String_delete_suffix$26.$$arity = 1); - - Opal.def(self, '$downcase', $String_downcase$27 = function $$downcase() { - var self = this; +/** + * @memberof Extensions/Registry + */ +Registry.prototype.docinfoProcessor = function (name, processor) { + if (arguments.length === 1) { + processor = name; + name = null; + } + return registerExtension(this, 'docinfo_processor', processor, name) +}; - return self.$$cast(self.toLowerCase()); - }, $String_downcase$27.$$arity = 0); - - Opal.def(self, '$each_char', $String_each_char$28 = function $$each_char() { - var $iter = $String_each_char$28.$$p, block = $iter || nil, $$29, self = this; +/** + * Checks whether any {{@link Extensions/Preprocessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/Preprocessor}} extensions are registered. + */ +Registry.prototype.hasPreprocessors = function () { + return this['$preprocessors?']() +}; - if ($iter) $String_each_char$28.$$p = null; - - - if ($iter) $String_each_char$28.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["each_char"], ($$29 = function(){var self = $$29.$$s || this; +/** + * Checks whether any {{@link Extensions/TreeProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/TreeProcessor}} extensions are registered. + */ +Registry.prototype.hasTreeProcessors = function () { + return this['$tree_processors?']() +}; - return self.$size()}, $$29.$$s = self, $$29.$$arity = 0, $$29)) - }; - - for (var i = 0, length = self.length; i < length; i++) { - Opal.yield1(block, self.charAt(i)); - } - ; - return self; - }, $String_each_char$28.$$arity = 0); - - Opal.def(self, '$each_line', $String_each_line$30 = function $$each_line(separator) { - var $iter = $String_each_line$30.$$p, block = $iter || nil, self = this; - if ($gvars["/"] == null) $gvars["/"] = nil; +/** + * Checks whether any {{@link Extensions/IncludeProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/IncludeProcessor}} extensions are registered. + */ +Registry.prototype.hasIncludeProcessors = function () { + return this['$include_processors?']() +}; - if ($iter) $String_each_line$30.$$p = null; - - - if ($iter) $String_each_line$30.$$p = null;; - - if (separator == null) { - separator = $gvars["/"]; - }; - if ((block !== nil)) { - } else { - return self.$enum_for("each_line", separator) - }; - - if (separator === nil) { - Opal.yield1(block, self); +/** + * Checks whether any {{@link Extensions/Postprocessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/Postprocessor}} extensions are registered. + */ +Registry.prototype.hasPostprocessors = function () { + return this['$postprocessors?']() +}; - return self; - } +/** + * Checks whether any {{@link Extensions/DocinfoProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined) + * @returns a {boolean} indicating whether any {{@link Extensions/DocinfoProcessor}} extensions are registered. + */ +Registry.prototype.hasDocinfoProcessors = function (location) { + return this['$docinfo_processors?'](location) +}; - separator = $$($nesting, 'Opal').$coerce_to(separator, $$($nesting, 'String'), "to_str") +/** + * Checks whether any {{@link Extensions/BlockProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/BlockProcessor}} extensions are registered. + */ +Registry.prototype.hasBlocks = function () { + return this['$blocks?']() +}; - var a, i, n, length, chomped, trailing, splitted; +/** + * Checks whether any {{@link Extensions/BlockMacroProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/BlockMacroProcessor}} extensions are registered. + */ +Registry.prototype.hasBlockMacros = function () { + return this['$block_macros?']() +}; - if (separator.length === 0) { - for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) { - if (a[i] || a[i + 1]) { - var value = (a[i] || "") + (a[i + 1] || ""); - Opal.yield1(block, self.$$cast(value)); - } - } +/** + * Checks whether any {{@link Extensions/InlineMacroProcessor}} extensions have been registered. + * + * @memberof Extensions/Registry + * @returns a {boolean} indicating whether any {{@link Extensions/InlineMacroProcessor}} extensions are registered. + */ +Registry.prototype.hasInlineMacros = function () { + return this['$inline_macros?']() +}; - return self; - } +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/Preprocessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getPreprocessors = function () { + return this.$preprocessors() +}; - chomped = self.$chomp(separator); - trailing = self.length != chomped.length; - splitted = chomped.split(separator); +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/TreeProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getTreeProcessors = function () { + return this.$tree_processors() +}; - for (i = 0, length = splitted.length; i < length; i++) { - if (i < length - 1 || trailing) { - Opal.yield1(block, self.$$cast(splitted[i] + separator)); - } - else { - Opal.yield1(block, self.$$cast(splitted[i])); - } - } - ; - return self; - }, $String_each_line$30.$$arity = -1); - - Opal.def(self, '$empty?', $String_empty$ques$31 = function() { - var self = this; +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/IncludeProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getIncludeProcessors = function () { + return this.$include_processors() +}; - return self.length === 0; - }, $String_empty$ques$31.$$arity = 0); - - Opal.def(self, '$end_with?', $String_end_with$ques$32 = function($a) { - var $post_args, suffixes, self = this; +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/Postprocessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getPostprocessors = function () { + return this.$postprocessors() +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - suffixes = $post_args;; - - for (var i = 0, length = suffixes.length; i < length; i++) { - var suffix = $$($nesting, 'Opal').$coerce_to(suffixes[i], $$($nesting, 'String'), "to_str").$to_s(); +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/DocinfoProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined) + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getDocinfoProcessors = function (location) { + return this.$docinfo_processors(location) +}; - if (self.length >= suffix.length && - self.substr(self.length - suffix.length, suffix.length) == suffix) { - return true; - } - } - ; - return false; - }, $String_end_with$ques$32.$$arity = -1); - Opal.alias(self, "equal?", "==="); - - Opal.def(self, '$gsub', $String_gsub$33 = function $$gsub(pattern, replacement) { - var $iter = $String_gsub$33.$$p, block = $iter || nil, self = this; +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/BlockProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getBlocks = function () { + return this.block_extensions.$values() +}; - if ($iter) $String_gsub$33.$$p = null; - - - if ($iter) $String_gsub$33.$$p = null;; - ; - - if (replacement === undefined && block === nil) { - return self.$enum_for("gsub", pattern); - } +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/BlockMacroProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getBlockMacros = function () { + return this.block_macro_extensions.$values() +}; - var result = '', match_data = nil, index = 0, match, _replacement; +/** + * Retrieves the Extension proxy objects for all the {{@link Extensions/InlineMacroProcessor}} instances stored in this registry. + * + * @memberof Extensions/Registry + * @returns an {array} of Extension proxy objects. + */ +Registry.prototype.getInlineMacros = function () { + return this.$inline_macros() +}; - if (pattern.$$is_regexp) { - pattern = Opal.global_multiline_regexp(pattern); - } else { - pattern = $$($nesting, 'Opal').$coerce_to(pattern, $$($nesting, 'String'), "to_str"); - pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); - } +/** + * Get any {{@link Extensions/InlineMacroProcessor}} extensions are registered to handle the specified inline macro name. + * + * @param name - the {string} inline macro name + * @memberof Extensions/Registry + * @returns the Extension proxy object for the {{@link Extensions/InlineMacroProcessor}} that matches the inline macro name or undefined if no match is found. + */ +Registry.prototype.getInlineMacroFor = function (name) { + const result = this['$registered_for_inline_macro?'](name); + return result === false ? undefined : result +}; - var lastIndex; - while (true) { - match = pattern.exec(self); +/** + * Get any {{@link Extensions/BlockProcessor}} extensions are registered to handle the specified block name appearing on the specified context. + * @param name - the {string} block name + * @param context - the context of the block: paragraph, open... (optional) + * @memberof Extensions/Registry + * @returns the Extension proxy object for the {{@link Extensions/BlockProcessor}} that matches the block name and context or undefined if no match is found. + */ +Registry.prototype.getBlockFor = function (name, context) { + if (typeof context === 'undefined') { + const ext = this.$find_block_extension(name); + return ext === Opal.nil ? undefined : ext + } + const result = this['$registered_for_block?'](name, context); + return result === false ? undefined : result +}; - if (match === null) { - ($gvars["~"] = nil) - result += self.slice(index); - break; - } +/** + * Get any {{@link Extensions/BlockMacroProcessor}} extensions are registered to handle the specified macro name. + * + * @param name - the {string} macro name + * @memberof Extensions/Registry + * @returns the Extension proxy object for the {{@link Extensions/BlockMacroProcessor}} that matches the macro name or undefined if no match is found. + */ +Registry.prototype.getBlockMacroFor = function (name) { + const result = this['$registered_for_block_macro?'](name); + return result === false ? undefined : result +}; - match_data = $$($nesting, 'MatchData').$new(pattern, match); +/** + * @namespace + * @module Extensions/Processor + */ +const Processor = Extensions.Processor; - if (replacement === undefined) { - lastIndex = pattern.lastIndex; - _replacement = block(match[0]); - pattern.lastIndex = lastIndex; // save and restore lastIndex - } - else if (replacement.$$is_hash) { - _replacement = (replacement)['$[]'](match[0]).$to_s(); - } - else { - if (!replacement.$$is_string) { - replacement = $$($nesting, 'Opal').$coerce_to(replacement, $$($nesting, 'String'), "to_str"); - } - _replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) { - if (slashes.length % 2 === 0) { - return original; - } - switch (command) { - case "+": - for (var i = match.length - 1; i > 0; i--) { - if (match[i] !== undefined) { - return slashes.slice(1) + match[i]; - } - } - return ''; - case "&": return slashes.slice(1) + match[0]; - case "`": return slashes.slice(1) + self.slice(0, match.index); - case "'": return slashes.slice(1) + self.slice(match.index + match[0].length); - default: return slashes.slice(1) + (match[command] || ''); - } - }).replace(/\\\\/g, '\\'); - } +/** + * The extension will be added to the beginning of the list for that extension type. (default is append). + * @memberof Extensions/Processor + * @deprecated Please use the <code>prefer</pre> function on the {@link Extensions/Registry}, + * the {@link Extensions/IncludeProcessor}, + * the {@link Extensions/TreeProcessor}, + * the {@link Extensions/Postprocessor}, + * the {@link Extensions/Preprocessor} + * or the {@link Extensions/DocinfoProcessor} + */ +Processor.prototype.prepend = function () { + this.$option('position', '>>'); +}; - if (pattern.lastIndex === match.index) { - result += (_replacement + self.slice(index, match.index + 1)) - pattern.lastIndex += 1; - } - else { - result += (self.slice(index, match.index) + _replacement) +/** + * @memberof Extensions/Processor + */ +Processor.prototype.process = function (block) { + const handler = { + apply: function (target, thisArg, argumentsList) { + for (let i = 0; i < argumentsList.length; i++) { + // convert all (Opal) Hash arguments to JSON. + if (typeof argumentsList[i] === 'object' && '$$smap' in argumentsList[i]) { + argumentsList[i] = fromHash(argumentsList[i]); } - index = pattern.lastIndex; } + return target.apply(thisArg, argumentsList) + } + }; + const blockProxy = new Proxy(block, handler); + return Opal.send(this, 'process', null, toBlock(blockProxy)) +}; - ($gvars["~"] = match_data) - return self.$$cast(result); - ; - }, $String_gsub$33.$$arity = -2); - - Opal.def(self, '$hash', $String_hash$34 = function $$hash() { - var self = this; +/** + * @param {string} name + * @memberof Extensions/Processor + */ +Processor.prototype.named = function (name) { + return this.$named(name) +}; - return self.toString(); - }, $String_hash$34.$$arity = 0); - - Opal.def(self, '$hex', $String_hex$35 = function $$hex() { - var self = this; +/** + * Creates a block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string} context + * @param {string|Array<string>} source + * @param {Object|undefined} attrs - A JSON of attributes + * @param {Object|undefined} opts - A JSON of options + * @return {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createBlock = function (parent, context, source, attrs, opts) { + return this.$create_block(parent, context, source, toHash(attrs), toHash(opts)) +}; - return self.$to_i(16) - }, $String_hex$35.$$arity = 0); - - Opal.def(self, '$include?', $String_include$ques$36 = function(other) { - var self = this; +/** + * Creates a list block node and links it to the specified parent. + * + * @param parent - The parent Block (Block, Section, or Document) of this new list block. + * @param {string} context - The list context (e.g., ulist, olist, colist, dlist) + * @param {Object} attrs - An object of attributes to set on this list block + * @returns {List} + * @memberof Extensions/Processor + */ +Processor.prototype.createList = function (parent, context, attrs) { + return this.$create_list(parent, context, toHash(attrs)) +}; - - if (!other.$$is_string) { - (other = $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'String'), "to_str")) - } - return self.indexOf(other) !== -1; - - }, $String_include$ques$36.$$arity = 1); - - Opal.def(self, '$index', $String_index$37 = function $$index(search, offset) { - var self = this; +/** + * Creates a list item node and links it to the specified parent. + * + * @param {List} parent - The parent {List} of this new list item block. + * @param {string} text - The text of the list item. + * @returns {ListItem} + * @memberof Extensions/Processor + */ +Processor.prototype.createListItem = function (parent, text) { + return this.$create_list_item(parent, text) +}; - - ; - - var index, - match, - regex; +/** + * Creates an image block node and links it to the specified parent. + * @param {Block|Section|Document} parent - The parent Block of this new image block. + * @param {Object} attrs - A JSON of attributes + * @param {string} attrs.target - the target attribute to set the source of the image. + * @param {string} attrs.alt - the alt attribute to specify an alternative text for the image. + * @param {Object} opts - A JSON of options + * @returns {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createImageBlock = function (parent, attrs, opts) { + return this.$create_image_block(parent, toHash(attrs), toHash(opts)) +}; - if (offset === undefined) { - offset = 0; - } else { - offset = $$($nesting, 'Opal').$coerce_to(offset, $$($nesting, 'Integer'), "to_int"); - if (offset < 0) { - offset += self.length; - if (offset < 0) { - return nil; - } - } - } +/** + * Creates a paragraph block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - a paragraph {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createParagraph = function (parent, source, attrs, opts) { + return this.$create_paragraph(parent, source, toHash(attrs), toHash(opts)) +}; - if (search.$$is_regexp) { - regex = Opal.global_multiline_regexp(search); - while (true) { - match = regex.exec(self); - if (match === null) { - ($gvars["~"] = nil); - index = -1; - break; - } - if (match.index >= offset) { - ($gvars["~"] = $$($nesting, 'MatchData').$new(regex, match)) - index = match.index; - break; - } - regex.lastIndex = match.index + 1; - } - } else { - search = $$($nesting, 'Opal').$coerce_to(search, $$($nesting, 'String'), "to_str"); - if (search.length === 0 && offset > self.length) { - index = -1; - } else { - index = self.indexOf(search, offset); - } - } +/** + * Creates an open block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - an open {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createOpenBlock = function (parent, source, attrs, opts) { + return this.$create_open_block(parent, source, toHash(attrs), toHash(opts)) +}; + +/** + * Creates an example block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - an example {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createExampleBlock = function (parent, source, attrs, opts) { + return this.$create_example_block(parent, source, toHash(attrs), toHash(opts)) +}; + +/** + * Creates a literal block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - a literal {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createPassBlock = function (parent, source, attrs, opts) { + return this.$create_pass_block(parent, source, toHash(attrs), toHash(opts)) +}; - return index === -1 ? nil : index; - ; - }, $String_index$37.$$arity = -2); - - Opal.def(self, '$inspect', $String_inspect$38 = function $$inspect() { - var self = this; +/** + * Creates a listing block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - a listing {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createListingBlock = function (parent, source, attrs, opts) { + return this.$create_listing_block(parent, source, toHash(attrs), toHash(opts)) +}; - - var escapable = /[\\\"\x00-\x1f\u007F-\u009F\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - meta = { - '\u0007': '\\a', - '\u001b': '\\e', - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '\v': '\\v', - '"' : '\\"', - '\\': '\\\\' - }, - escaped = self.replace(escapable, function (chr) { - return meta[chr] || '\\u' + ('0000' + chr.charCodeAt(0).toString(16).toUpperCase()).slice(-4); - }); - return '"' + escaped.replace(/\#[\$\@\{]/g, '\\$&') + '"'; - - }, $String_inspect$38.$$arity = 0); - - Opal.def(self, '$intern', $String_intern$39 = function $$intern() { - var self = this; +/** + * Creates a literal block and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string|Array<string>} source - The source + * @param {Object|undefined} attrs - An object of attributes to set on this block + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Block} - a literal {Block} + * @memberof Extensions/Processor + */ +Processor.prototype.createLiteralBlock = function (parent, source, attrs, opts) { + return this.$create_literal_block(parent, source, toHash(attrs), toHash(opts)) +}; - return self.toString(); - }, $String_intern$39.$$arity = 0); - - Opal.def(self, '$lines', $String_lines$40 = function $$lines(separator) { - var $iter = $String_lines$40.$$p, block = $iter || nil, self = this, e = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; +/** + * Creates an inline anchor and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string} text - The text + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Inline} - an {Inline} anchor + * @memberof Extensions/Processor + */ +Processor.prototype.createAnchor = function (parent, text, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return this.$create_anchor(parent, text, toHash(opts)) +}; - if ($iter) $String_lines$40.$$p = null; - - - if ($iter) $String_lines$40.$$p = null;; - - if (separator == null) { - separator = $gvars["/"]; - }; - e = $send(self, 'each_line', [separator], block.$to_proc()); - if ($truthy(block)) { - return self - } else { - return e.$to_a() - }; - }, $String_lines$40.$$arity = -1); - - Opal.def(self, '$length', $String_length$41 = function $$length() { - var self = this; +/** + * Creates an inline pass and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block. + * @param {string} text - The text + * @param {Object|undefined} opts - An object of options to set on this block + * @returns {Inline} - an {Inline} pass + * @memberof Extensions/Processor + */ +Processor.prototype.createInlinePass = function (parent, text, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return this.$create_inline_pass(parent, text, toHash(opts)) +}; - return self.length; - }, $String_length$41.$$arity = 0); - - Opal.def(self, '$ljust', $String_ljust$42 = function $$ljust(width, padstr) { - var self = this; +/** + * Creates an inline node and links it to the specified parent. + * + * @param {Block|Section|Document} parent - The parent Block of this new inline node. + * @param {string} context - The context name + * @param {string} text - The text + * @param {Object|undefined} opts - A JSON of options + * @returns {Inline} - an {Inline} node + * @memberof Extensions/Processor + */ +Processor.prototype.createInline = function (parent, context, text, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return this.$create_inline(parent, context, text, toHash(opts)) +}; - - - if (padstr == null) { - padstr = " "; - }; - width = $$($nesting, 'Opal').$coerce_to(width, $$($nesting, 'Integer'), "to_int"); - padstr = $$($nesting, 'Opal').$coerce_to(padstr, $$($nesting, 'String'), "to_str").$to_s(); - if ($truthy(padstr['$empty?']())) { - self.$raise($$($nesting, 'ArgumentError'), "zero width padding")}; - if ($truthy(width <= self.length)) { - return self}; - - var index = -1, - result = ""; +/** + * Parses blocks in the content and attaches the block to the parent. + * @param {AbstractBlock} parent - the parent block + * @param {string|Array<string>} content - the content + * @param {Object|undefined} attrs - an object of attributes + * @returns {AbstractNode} - The parent node into which the blocks are parsed. + * @memberof Extensions/Processor + */ +Processor.prototype.parseContent = function (parent, content, attrs) { + return this.$parse_content(parent, content, toHash(attrs)) +}; - width -= self.length; +/** + * Parses the attrlist String into a JSON of attributes + * @param {AbstractBlock} block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs) + * @param {string} attrlist - the list of attributes as a String + * @param {Object|undefined} opts - an optional JSON of options to control processing: + * - positional_attributes: an Array of attribute names to map positional arguments to (optional, default: []) + * - sub_attributes: enables attribute substitution on the attrlist argument (optional, default: false) + * + * @returns - a JSON of parsed attributes + * @memberof Extensions/Processor + */ +Processor.prototype.parseAttributes = function (block, attrlist, opts) { + if (opts && opts.attributes) { + opts.attributes = toHash(opts.attributes); + } + return fromHash(this.$parse_attributes(block, attrlist, toHash(opts))) +}; - while (++index < width) { - result += padstr; - } +/** + * @param {string|Array<string>} value - Name of a positional attribute or an Array of positional attribute names + * @memberof Extensions/Processor + */ +Processor.prototype.positionalAttributes = function (value) { + return this.$positional_attrs(value) +}; - return self.$$cast(self + result.slice(0, width)); - ; - }, $String_ljust$42.$$arity = -2); - - Opal.def(self, '$lstrip', $String_lstrip$43 = function $$lstrip() { - var self = this; +/** + * Specify how to resolve attributes. + * + * @param {string|Array<string>|Object|boolean} [value] - A specification to resolve attributes. + * @memberof Extensions/Processor + */ +Processor.prototype.resolveAttributes = function (value) { + if (typeof value === 'object' && !Array.isArray(value)) { + return this.$resolves_attributes(toHash(value)) + } + if (arguments.length > 1) { + return this.$resolves_attributes(Array.prototype.slice.call(arguments)) + } + if (typeof value === 'undefined') { + // Convert to nil otherwise an exception is thrown at: + // https://github.com/asciidoctor/asciidoctor/blob/0bcb4addc17b307f62975aad203fb556a1bcd8a5/lib/asciidoctor/extensions.rb#L583 + // + // if args.size == 1 && !args[0] + // + // In the above Ruby code, args[0] is undefined and Opal will try to call the function "!" on an undefined object. + return this.$resolves_attributes(Opal.nil) + } + return this.$resolves_attributes(value) +}; - return self.replace(/^\s*/, ''); - }, $String_lstrip$43.$$arity = 0); - - Opal.def(self, '$ascii_only?', $String_ascii_only$ques$44 = function() { - var self = this; +/** + * @deprecated Please use the <code>resolveAttributes</pre> function on the {@link Extensions/Processor}. + * @memberof Extensions/Processor + * @see {Processor#resolveAttributes} + */ +Processor.prototype.resolvesAttributes = Processor.prototype.resolveAttributes; - return self.match(/[ -~\n]*/)[0] === self; - }, $String_ascii_only$ques$44.$$arity = 0); - - Opal.def(self, '$match', $String_match$45 = function $$match(pattern, pos) { - var $iter = $String_match$45.$$p, block = $iter || nil, $a, self = this; +/** + * Get the configuration JSON for this processor instance. + * @memberof Extensions/Processor + */ +Processor.prototype.getConfig = function () { + return fromHash(this.config) +}; - if ($iter) $String_match$45.$$p = null; - - - if ($iter) $String_match$45.$$p = null;; - ; - if ($truthy(($truthy($a = $$($nesting, 'String')['$==='](pattern)) ? $a : pattern['$respond_to?']("to_str")))) { - pattern = $$($nesting, 'Regexp').$new(pattern.$to_str())}; - if ($truthy($$($nesting, 'Regexp')['$==='](pattern))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + (pattern.$class()) + " (expected Regexp)") - }; - return $send(pattern, 'match', [self, pos], block.$to_proc()); - }, $String_match$45.$$arity = -2); - - Opal.def(self, '$match?', $String_match$ques$46 = function(pattern, pos) { - var $a, self = this; +/** + * @memberof Extensions/Processor + */ +Processor.prototype.option = function (key, value) { + this.$option(key, value); +}; - - ; - if ($truthy(($truthy($a = $$($nesting, 'String')['$==='](pattern)) ? $a : pattern['$respond_to?']("to_str")))) { - pattern = $$($nesting, 'Regexp').$new(pattern.$to_str())}; - if ($truthy($$($nesting, 'Regexp')['$==='](pattern))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + (pattern.$class()) + " (expected Regexp)") - }; - return pattern['$match?'](self, pos); - }, $String_match$ques$46.$$arity = -2); - - Opal.def(self, '$next', $String_next$47 = function $$next() { - var self = this; +/** + * @namespace + * @module Extensions/BlockProcessor + */ +const BlockProcessor = Extensions.BlockProcessor; - - var i = self.length; - if (i === 0) { - return self.$$cast(''); - } - var result = self; - var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/); - var carry = false; - var code; - while (i--) { - code = self.charCodeAt(i); - if ((code >= 48 && code <= 57) || - (code >= 65 && code <= 90) || - (code >= 97 && code <= 122)) { - switch (code) { - case 57: - carry = true; - code = 48; - break; - case 90: - carry = true; - code = 65; - break; - case 122: - carry = true; - code = 97; - break; - default: - carry = false; - code += 1; - } - } else { - if (first_alphanum_char_index === -1) { - if (code === 255) { - carry = true; - code = 0; - } else { - carry = false; - code += 1; - } - } else { - carry = true; - } - } - result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i + 1); - if (carry && (i === 0 || i === first_alphanum_char_index)) { - switch (code) { - case 65: - break; - case 97: - break; - default: - code += 1; - } - if (i === 0) { - result = String.fromCharCode(code) + result; - } else { - result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i); - } - carry = false; - } - if (!carry) { - break; - } - } - return self.$$cast(result); - - }, $String_next$47.$$arity = 0); - - Opal.def(self, '$oct', $String_oct$48 = function $$oct() { - var self = this; +/** + * @param {Object} value - a JSON of default values for attributes + * @memberof Extensions/BlockProcessor + */ +BlockProcessor.prototype.defaultAttributes = function (value) { + this.$default_attributes(toHash(value)); +}; - - var result, - string = self, - radix = 8; +/** + * @param {string} context - A context name + * @memberof Extensions/BlockProcessor + */ +BlockProcessor.prototype.onContext = function (context) { + return this.$on_context(context) +}; - if (/^\s*_/.test(string)) { - return 0; - } +/** + * @param {...string} contexts - A list of context names + * @memberof Extensions/BlockProcessor + */ +BlockProcessor.prototype.onContexts = function (contexts) { + return this.$on_contexts(Array.prototype.slice.call(arguments)) +}; - string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/i, function (original, head, flag, tail) { - switch (tail.charAt(0)) { - case '+': - case '-': - return original; - case '0': - if (tail.charAt(1) === 'x' && flag === '0x') { - return original; - } - } - switch (flag) { - case '0b': - radix = 2; - break; - case '0': - case '0o': - radix = 8; - break; - case '0d': - radix = 10; - break; - case '0x': - radix = 16; - break; - } - return head + tail; - }); +/** + * @returns {string} + * @memberof Extensions/BlockProcessor + */ +BlockProcessor.prototype.getName = function () { + const name = this.name; + return name === Opal.nil ? undefined : name +}; - result = parseInt(string.replace(/_(?!_)/g, ''), radix); - return isNaN(result) ? 0 : result; - - }, $String_oct$48.$$arity = 0); - - Opal.def(self, '$ord', $String_ord$49 = function $$ord() { - var self = this; +/** + * @param {string} value + * @memberof Extensions/BlockProcessor + */ +BlockProcessor.prototype.parseContentAs = function (value) { + this.$parse_content_as(value); +}; - return self.charCodeAt(0); - }, $String_ord$49.$$arity = 0); - - Opal.def(self, '$partition', $String_partition$50 = function $$partition(sep) { - var self = this; +/** + * @namespace + * @module Extensions/BlockMacroProcessor + */ +const BlockMacroProcessor = Extensions.BlockMacroProcessor; - - var i, m; +/** + * @param {Object} value - a JSON of default values for attributes + * @memberof Extensions/BlockMacroProcessor + */ +BlockMacroProcessor.prototype.defaultAttributes = function (value) { + this.$default_attributes(toHash(value)); +}; - if (sep.$$is_regexp) { - m = sep.exec(self); - if (m === null) { - i = -1; - } else { - $$($nesting, 'MatchData').$new(sep, m); - sep = m[0]; - i = m.index; - } - } else { - sep = $$($nesting, 'Opal').$coerce_to(sep, $$($nesting, 'String'), "to_str"); - i = self.indexOf(sep); - } +/** + * @returns {string} - the block macro name + * @memberof Extensions/BlockMacroProcessor + */ +BlockMacroProcessor.prototype.getName = function () { + const name = this.name; + return name === Opal.nil ? undefined : name +}; - if (i === -1) { - return [self, '', '']; - } +/** + * @param {string} value + * @memberof Extensions/BlockMacroProcessor + */ +BlockMacroProcessor.prototype.parseContentAs = function (value) { + this.$parse_content_as(value); +}; - return [ - self.slice(0, i), - self.slice(i, i + sep.length), - self.slice(i + sep.length) - ]; - - }, $String_partition$50.$$arity = 1); - - Opal.def(self, '$reverse', $String_reverse$51 = function $$reverse() { - var self = this; +/** + * @namespace + * @module Extensions/InlineMacroProcessor + */ +const InlineMacroProcessor = Extensions.InlineMacroProcessor; - return self.split('').reverse().join(''); - }, $String_reverse$51.$$arity = 0); - - Opal.def(self, '$rindex', $String_rindex$52 = function $$rindex(search, offset) { - var self = this; +/** + * @param {Object} value - a JSON of default values for attributes + * @memberof Extensions/InlineMacroProcessor + */ +InlineMacroProcessor.prototype.defaultAttributes = function (value) { + this.$default_attributes(toHash(value)); +}; - - ; - - var i, m, r, _m; +/** + * @returns {string} - the inline macro name + * @memberof Extensions/InlineMacroProcessor + */ +InlineMacroProcessor.prototype.getName = function () { + const name = this.name; + return name === Opal.nil ? undefined : name +}; - if (offset === undefined) { - offset = self.length; - } else { - offset = $$($nesting, 'Opal').$coerce_to(offset, $$($nesting, 'Integer'), "to_int"); - if (offset < 0) { - offset += self.length; - if (offset < 0) { - return nil; - } - } - } +/** + * @param {string} value + * @memberof Extensions/InlineMacroProcessor + */ +InlineMacroProcessor.prototype.parseContentAs = function (value) { + this.$parse_content_as(value); +}; - if (search.$$is_regexp) { - m = null; - r = Opal.global_multiline_regexp(search); - while (true) { - _m = r.exec(self); - if (_m === null || _m.index > offset) { - break; - } - m = _m; - r.lastIndex = m.index + 1; - } - if (m === null) { - ($gvars["~"] = nil) - i = -1; - } else { - $$($nesting, 'MatchData').$new(r, m); - i = m.index; - } - } else { - search = $$($nesting, 'Opal').$coerce_to(search, $$($nesting, 'String'), "to_str"); - i = self.lastIndexOf(search, offset); - } +/** + * @param {string} value + * @memberof Extensions/InlineMacroProcessor + */ +InlineMacroProcessor.prototype.matchFormat = function (value) { + this.$match_format(value); +}; - return i === -1 ? nil : i; - ; - }, $String_rindex$52.$$arity = -2); - - Opal.def(self, '$rjust', $String_rjust$53 = function $$rjust(width, padstr) { - var self = this; +/** + * @param {RegExp} value + * @memberof Extensions/InlineMacroProcessor + */ +InlineMacroProcessor.prototype.match = function (value) { + this.$match(value); +}; - - - if (padstr == null) { - padstr = " "; - }; - width = $$($nesting, 'Opal').$coerce_to(width, $$($nesting, 'Integer'), "to_int"); - padstr = $$($nesting, 'Opal').$coerce_to(padstr, $$($nesting, 'String'), "to_str").$to_s(); - if ($truthy(padstr['$empty?']())) { - self.$raise($$($nesting, 'ArgumentError'), "zero width padding")}; - if ($truthy(width <= self.length)) { - return self}; - - var chars = Math.floor(width - self.length), - patterns = Math.floor(chars / padstr.length), - result = Array(patterns + 1).join(padstr), - remaining = chars - result.length; +/** + * @namespace + * @module Extensions/IncludeProcessor + */ +const IncludeProcessor = Extensions.IncludeProcessor; - return self.$$cast(result + padstr.slice(0, remaining) + self); - ; - }, $String_rjust$53.$$arity = -2); - - Opal.def(self, '$rpartition', $String_rpartition$54 = function $$rpartition(sep) { - var self = this; +/** + * @memberof Extensions/IncludeProcessor + */ +IncludeProcessor.prototype.handles = function (block) { + return Opal.send(this, 'handles?', null, toBlock(block)) +}; + +/** + * @memberof Extensions/IncludeProcessor + */ +IncludeProcessor.prototype.prefer = function () { + this.$prefer(); +}; + +/** + * @namespace + * @module Extensions/TreeProcessor + */ +const TreeProcessor = Extensions.TreeProcessor; - - var i, m, r, _m; +/** + * @memberof Extensions/TreeProcessor + */ +TreeProcessor.prototype.prefer = function () { + this.$prefer(); +}; - if (sep.$$is_regexp) { - m = null; - r = Opal.global_multiline_regexp(sep); +/** + * @namespace + * @module Extensions/Postprocessor + */ +const Postprocessor = Extensions.Postprocessor; - while (true) { - _m = r.exec(self); - if (_m === null) { - break; - } - m = _m; - r.lastIndex = m.index + 1; - } +/** + * @memberof Extensions/Postprocessor + */ +Postprocessor.prototype.prefer = function () { + this.$prefer(); +}; - if (m === null) { - i = -1; - } else { - $$($nesting, 'MatchData').$new(r, m); - sep = m[0]; - i = m.index; - } +/** + * @namespace + * @module Extensions/Preprocessor + */ +const Preprocessor = Extensions.Preprocessor; - } else { - sep = $$($nesting, 'Opal').$coerce_to(sep, $$($nesting, 'String'), "to_str"); - i = self.lastIndexOf(sep); - } +/** + * @memberof Extensions/Preprocessor + */ +Preprocessor.prototype.prefer = function () { + this.$prefer(); +}; - if (i === -1) { - return ['', '', self]; - } +/** + * @namespace + * @module Extensions/DocinfoProcessor + */ +const DocinfoProcessor = Extensions.DocinfoProcessor; - return [ - self.slice(0, i), - self.slice(i, i + sep.length), - self.slice(i + sep.length) - ]; - - }, $String_rpartition$54.$$arity = 1); - - Opal.def(self, '$rstrip', $String_rstrip$55 = function $$rstrip() { - var self = this; +/** + * @memberof Extensions/DocinfoProcessor + */ +DocinfoProcessor.prototype.prefer = function () { + this.$prefer(); +}; - return self.replace(/[\s\u0000]*$/, ''); - }, $String_rstrip$55.$$arity = 0); - - Opal.def(self, '$scan', $String_scan$56 = function $$scan(pattern) { - var $iter = $String_scan$56.$$p, block = $iter || nil, self = this; +/** + * @param {string} value - The docinfo location ("head", "header" or "footer") + * @memberof Extensions/DocinfoProcessor + */ +DocinfoProcessor.prototype.atLocation = function (value) { + this.$at_location(value); +}; - if ($iter) $String_scan$56.$$p = null; - - - if ($iter) $String_scan$56.$$p = null;; - - var result = [], - match_data = nil, - match; +function initializeProcessorClass (superclassName, className, functions) { + const superClass = Opal.const_get_qualified(Extensions, superclassName); + return initializeClass(superClass, className, functions, { + 'handles?': function () { + return true + } + }) +} - if (pattern.$$is_regexp) { - pattern = Opal.global_multiline_regexp(pattern); - } else { - pattern = $$($nesting, 'Opal').$coerce_to(pattern, $$($nesting, 'String'), "to_str"); - pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); - } +// Postprocessor - while ((match = pattern.exec(self)) != null) { - match_data = $$($nesting, 'MatchData').$new(pattern, match); - if (block === nil) { - match.length == 1 ? result.push(match[0]) : result.push((match_data).$captures()); - } else { - match.length == 1 ? block(match[0]) : block.call(self, (match_data).$captures()); - } - if (pattern.lastIndex === match.index) { - pattern.lastIndex += 1; - } - } +/** + * Create a postprocessor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createPostprocessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('Postprocessor', name, functions) +}; - ($gvars["~"] = match_data) +/** + * Create and instantiate a postprocessor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newPostprocessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createPostprocessor(name, functions).$new() +}; - return (block !== nil ? self : result); - ; - }, $String_scan$56.$$arity = 1); - Opal.alias(self, "size", "length"); - Opal.alias(self, "slice", "[]"); - - Opal.def(self, '$split', $String_split$57 = function $$split(pattern, limit) { - var $a, self = this; - if ($gvars[";"] == null) $gvars[";"] = nil; +// Preprocessor - - ; - ; - - if (self.length === 0) { - return []; - } +/** + * Create a preprocessor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createPreprocessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('Preprocessor', name, functions) +}; - if (limit === undefined) { - limit = 0; - } else { - limit = $$($nesting, 'Opal')['$coerce_to!'](limit, $$($nesting, 'Integer'), "to_int"); - if (limit === 1) { - return [self]; - } - } +/** + * Create and instantiate a preprocessor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newPreprocessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createPreprocessor(name, functions).$new() +}; - if (pattern === undefined || pattern === nil) { - pattern = ($truthy($a = $gvars[";"]) ? $a : " "); - } +// Tree Processor - var result = [], - string = self.toString(), - index = 0, - match, - i, ii; +/** + * Create a tree processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createTreeProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('TreeProcessor', name, functions) +}; - if (pattern.$$is_regexp) { - pattern = Opal.global_multiline_regexp(pattern); - } else { - pattern = $$($nesting, 'Opal').$coerce_to(pattern, $$($nesting, 'String'), "to_str").$to_s(); - if (pattern === ' ') { - pattern = /\s+/gm; - string = string.replace(/^\s+/, ''); - } else { - pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); - } - } +/** + * Create and instantiate a tree processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newTreeProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createTreeProcessor(name, functions).$new() +}; - result = string.split(pattern); +// Include Processor - if (result.length === 1 && result[0] === string) { - return [self.$$cast(result[0])]; - } +/** + * Create an include processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createIncludeProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('IncludeProcessor', name, functions) +}; - while ((i = result.indexOf(undefined)) !== -1) { - result.splice(i, 1); - } +/** + * Create and instantiate an include processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newIncludeProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createIncludeProcessor(name, functions).$new() +}; - function castResult() { - for (i = 0; i < result.length; i++) { - result[i] = self.$$cast(result[i]); - } - } +// Docinfo Processor - if (limit === 0) { - while (result[result.length - 1] === '') { - result.length -= 1; - } - castResult(); - return result; - } +/** + * Create a Docinfo processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createDocinfoProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('DocinfoProcessor', name, functions) +}; - match = pattern.exec(string); +/** + * Create and instantiate a Docinfo processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newDocinfoProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createDocinfoProcessor(name, functions).$new() +}; - if (limit < 0) { - if (match !== null && match[0] === '' && pattern.source.indexOf('(?=') === -1) { - for (i = 0, ii = match.length; i < ii; i++) { - result.push(''); - } - } - castResult(); - return result; - } +// Block Processor - if (match !== null && match[0] === '') { - result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join('')); - castResult(); - return result; - } +/** + * Create a block processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createBlockProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('BlockProcessor', name, functions) +}; - if (limit >= result.length) { - castResult(); - return result; - } +/** + * Create and instantiate a block processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newBlockProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createBlockProcessor(name, functions).$new() +}; - i = 0; - while (match !== null) { - i++; - index = pattern.lastIndex; - if (i + 1 === limit) { - break; - } - match = pattern.exec(string); - } - result.splice(limit - 1, result.length - 1, string.slice(index)); - castResult(); - return result; - ; - }, $String_split$57.$$arity = -1); - - Opal.def(self, '$squeeze', $String_squeeze$58 = function $$squeeze($a) { - var $post_args, sets, self = this; +// Inline Macro Processor - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - sets = $post_args;; - - if (sets.length === 0) { - return self.$$cast(self.replace(/(.)\1+/g, '$1')); - } - var char_class = char_class_from_char_sets(sets); - if (char_class === null) { - return self; - } - return self.$$cast(self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1')); - ; - }, $String_squeeze$58.$$arity = -1); - - Opal.def(self, '$start_with?', $String_start_with$ques$59 = function($a) { - var $post_args, prefixes, self = this; +/** + * Create an inline macro processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createInlineMacroProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('InlineMacroProcessor', name, functions) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - prefixes = $post_args;; - - for (var i = 0, length = prefixes.length; i < length; i++) { - var prefix = $$($nesting, 'Opal').$coerce_to(prefixes[i], $$($nesting, 'String'), "to_str").$to_s(); +/** + * Create and instantiate an inline macro processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newInlineMacroProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createInlineMacroProcessor(name, functions).$new() +}; - if (self.indexOf(prefix) === 0) { - return true; - } - } +// Block Macro Processor - return false; - ; - }, $String_start_with$ques$59.$$arity = -1); - - Opal.def(self, '$strip', $String_strip$60 = function $$strip() { - var self = this; +/** + * Create a block macro processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.createBlockMacroProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return initializeProcessorClass('BlockMacroProcessor', name, functions) +}; - return self.replace(/^\s*/, '').replace(/[\s\u0000]*$/, ''); - }, $String_strip$60.$$arity = 0); - - Opal.def(self, '$sub', $String_sub$61 = function $$sub(pattern, replacement) { - var $iter = $String_sub$61.$$p, block = $iter || nil, self = this; +/** + * Create and instantiate a block macro processor + * @description this API is experimental and subject to change + * @memberof Extensions + */ +Extensions.newBlockMacroProcessor = function (name, functions) { + if (arguments.length === 1) { + functions = name; + name = null; + } + return this.createBlockMacroProcessor(name, functions).$new() +}; - if ($iter) $String_sub$61.$$p = null; - - - if ($iter) $String_sub$61.$$p = null;; - ; - - if (!pattern.$$is_regexp) { - pattern = $$($nesting, 'Opal').$coerce_to(pattern, $$($nesting, 'String'), "to_str"); - pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')); - } - var result, match = pattern.exec(self); +var ASCIIDOCTOR_JS_VERSION = '3.0.4'; - if (match === null) { - ($gvars["~"] = nil) - result = self.toString(); - } else { - $$($nesting, 'MatchData').$new(pattern, match) + /** + * Get Asciidoctor.js version number. + * + * @memberof Asciidoctor + * @returns {string} - returns the version number of Asciidoctor.js. + */ + Asciidoctor.prototype.getVersion = function () { + return ASCIIDOCTOR_JS_VERSION + }; + return Opal.Asciidoctor +} - if (replacement === undefined) { +module.exports = asciidoctorNode; - if (block === nil) { - self.$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (1 for 2)") - } - result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length); - } else if (replacement.$$is_hash) { +/***/ }), - result = self.slice(0, match.index) + (replacement)['$[]'](match[0]).$to_s() + self.slice(match.index + match[0].length); +/***/ 1066: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - } else { +"use strict"; - replacement = $$($nesting, 'Opal').$coerce_to(replacement, $$($nesting, 'String'), "to_str"); - replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) { - if (slashes.length % 2 === 0) { - return original; - } - switch (command) { - case "+": - for (var i = match.length - 1; i > 0; i--) { - if (match[i] !== undefined) { - return slashes.slice(1) + match[i]; - } - } - return ''; - case "&": return slashes.slice(1) + match[0]; - case "`": return slashes.slice(1) + self.slice(0, match.index); - case "'": return slashes.slice(1) + self.slice(match.index + match[0].length); - default: return slashes.slice(1) + (match[command] || ''); - } - }).replace(/\\\\/g, '\\'); +var __fs__ = __nccwpck_require__(9896); +var __path__ = __nccwpck_require__(6928); +var __util__ = __nccwpck_require__(9023); +var __glob__ = __nccwpck_require__(3574); +var __os__ = __nccwpck_require__(857); +var __xmlhttprequest__ = __nccwpck_require__(1833); - result = self.slice(0, match.index) + replacement + self.slice(match.index + match[0].length); - } - } +(function(global_object) { - return self.$$cast(result); - ; - }, $String_sub$61.$$arity = -2); - Opal.alias(self, "succ", "next"); - - Opal.def(self, '$sum', $String_sum$62 = function $$sum(n) { - var self = this; + // @note + // A few conventions for the documentation of this file: + // 1. Always use "//" (in contrast with "/**/") + // 2. The syntax used is Yardoc (yardoc.org), which is intended for Ruby (se below) + // 3. `@param` and `@return` types should be preceded by `JS.` when referring to + // JavaScript constructors (e.g. `JS.Function`) otherwise Ruby is assumed. + // 4. `nil` and `null` being unambiguous refer to the respective + // objects/values in Ruby and JavaScript + // 5. This is still WIP :) so please give feedback and suggestions on how + // to improve or for alternative solutions + // + // The way the code is digested before going through Yardoc is a secret kept + // in the docs repo (https://github.com/opal/docs/tree/master). - - - if (n == null) { - n = 16; - }; - - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); + var console; - var result = 0, - length = self.length, - i = 0; + // Detect the global object + if (typeof(globalThis) !== 'undefined') { global_object = globalThis; } + else if (typeof(global) !== 'undefined') { global_object = global; } + else if (typeof(window) !== 'undefined') { global_object = window; } - for (; i < length; i++) { - result += self.charCodeAt(i); - } + // Setup a dummy console object if missing + if (global_object.console == null) { + global_object.console = {}; + } - if (n <= 0) { - return result; - } + if (typeof(global_object.console) === 'object') { + console = global_object.console; + } else { + console = {}; + } - return result & (Math.pow(2, n) - 1); - ; - }, $String_sum$62.$$arity = -1); - - Opal.def(self, '$swapcase', $String_swapcase$63 = function $$swapcase() { - var self = this; + if (!('log' in console)) { console.log = function () {}; } + if (!('warn' in console)) { console.warn = console.log; } - - var str = self.replace(/([a-z]+)|([A-Z]+)/g, function($0,$1,$2) { - return $1 ? $0.toUpperCase() : $0.toLowerCase(); - }); + if (typeof(global_object.Opal) !== 'undefined') { + console.warn('Opal already loaded. Loading twice can cause troubles, please fix your setup.'); + return global_object.Opal; + } - if (self.constructor === String) { - return str; - } + var nil; - return self.$class().$new(str); - - }, $String_swapcase$63.$$arity = 0); - - Opal.def(self, '$to_f', $String_to_f$64 = function $$to_f() { - var self = this; + // The actual class for BasicObject + var BasicObject; - - if (self.charAt(0) === '_') { - return 0; - } + // The actual Object class. + // The leading underscore is to avoid confusion with window.Object() + var _Object; - var result = parseFloat(self.replace(/_/g, '')); + // The actual Module class + var Module; - if (isNaN(result) || result == Infinity || result == -Infinity) { - return 0; - } - else { - return result; - } - - }, $String_to_f$64.$$arity = 0); - - Opal.def(self, '$to_i', $String_to_i$65 = function $$to_i(base) { - var self = this; + // The actual Class class + var Class; - - - if (base == null) { - base = 10; - }; - - var result, - string = self.toLowerCase(), - radix = $$($nesting, 'Opal').$coerce_to(base, $$($nesting, 'Integer'), "to_int"); + // The Opal.Opal class (helpers etc.) + var _Opal; - if (radix === 1 || radix < 0 || radix > 36) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid radix " + (radix)) - } + // The Kernel module + var Kernel; - if (/^\s*_/.test(string)) { - return 0; - } + // The Opal object that is exposed globally + var Opal = global_object.Opal = {}; - string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/, function (original, head, flag, tail) { - switch (tail.charAt(0)) { - case '+': - case '-': - return original; - case '0': - if (tail.charAt(1) === 'x' && flag === '0x' && (radix === 0 || radix === 16)) { - return original; - } - } - switch (flag) { - case '0b': - if (radix === 0 || radix === 2) { - radix = 2; - return head + tail; - } - break; - case '0': - case '0o': - if (radix === 0 || radix === 8) { - radix = 8; - return head + tail; - } - break; - case '0d': - if (radix === 0 || radix === 10) { - radix = 10; - return head + tail; - } - break; - case '0x': - if (radix === 0 || radix === 16) { - radix = 16; - return head + tail; - } - break; - } - return original - }); + // This is a useful reference to global object inside ruby files + Opal.global = global_object; - result = parseInt(string.replace(/_(?!_)/g, ''), radix); - return isNaN(result) ? 0 : result; - ; - }, $String_to_i$65.$$arity = -1); - - Opal.def(self, '$to_proc', $String_to_proc$66 = function $$to_proc() { - var $$67, $iter = $String_to_proc$66.$$p, $yield = $iter || nil, self = this, method_name = nil; + // Configure runtime behavior with regards to require and unsupported features + Opal.config = { + missing_require_severity: 'error', // error, warning, ignore + unsupported_features_severity: 'warning', // error, warning, ignore + experimental_features_severity: 'warning',// warning, ignore + enable_stack_trace: true // true, false + }; - if ($iter) $String_to_proc$66.$$p = null; - - method_name = $rb_plus("$", self.valueOf()); - return $send(self, 'proc', [], ($$67 = function($a){var self = $$67.$$s || this, $iter = $$67.$$p, block = $iter || nil, $post_args, args; + // Minify common function calls + var $call = Function.prototype.call; + var $bind = Function.prototype.bind; + var $has_own = Object.hasOwn || $call.bind(Object.prototype.hasOwnProperty); + var $set_proto = Object.setPrototypeOf; + var $slice = $call.bind(Array.prototype.slice); + var $splice = $call.bind(Array.prototype.splice); - - - if ($iter) $$67.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - if (args.length === 0) { - self.$raise($$($nesting, 'ArgumentError'), "no receiver given") - } + // Nil object id is always 4 + var nil_id = 4; - var recv = args[0]; + // Generates even sequential numbers greater than 4 + // (nil_id) to serve as unique ids for ruby objects + var unique_id = nil_id; - if (recv == null) recv = nil; + // Return next unique id + function $uid() { + unique_id += 2; + return unique_id; + } Opal.uid = $uid; - var body = recv[method_name]; + // Retrieve or assign the id of an object + Opal.id = function(obj) { + if (obj.$$is_number) return (obj * 2)+1; + if (obj.$$id == null) { + $prop(obj, '$$id', $uid()); + } + return obj.$$id; + }; - if (!body) { - return recv.$method_missing.apply(recv, args); - } + // Globals table + var $gvars = Opal.gvars = {}; - if (typeof block === 'function') { - body.$$p = block; - } + // Exit function, this should be replaced by platform specific implementation + // (See nodejs and chrome for examples) + Opal.exit = function(status) { if ($gvars.DEBUG) console.log('Exited with status '+status); }; - if (args.length === 1) { - return body.call(recv); - } else { - return body.apply(recv, args.slice(1)); - } - ;}, $$67.$$s = self, $$67.$$arity = -1, $$67)); - }, $String_to_proc$66.$$arity = 0); - - Opal.def(self, '$to_s', $String_to_s$68 = function $$to_s() { - var self = this; + // keeps track of exceptions for $! + Opal.exceptions = []; - return self.toString(); - }, $String_to_s$68.$$arity = 0); - Opal.alias(self, "to_str", "to_s"); - Opal.alias(self, "to_sym", "intern"); - - Opal.def(self, '$tr', $String_tr$69 = function $$tr(from, to) { - var self = this; + // @private + // Pops an exception from the stack and updates `$!`. + Opal.pop_exception = function() { + var exception = Opal.exceptions.pop(); + if (exception) { + $gvars["!"] = exception; + $gvars["@"] = exception.$backtrace(); + } + else { + $gvars["!"] = $gvars["@"] = nil; + } + }; - - from = $$($nesting, 'Opal').$coerce_to(from, $$($nesting, 'String'), "to_str").$to_s(); - to = $$($nesting, 'Opal').$coerce_to(to, $$($nesting, 'String'), "to_str").$to_s(); - - if (from.length == 0 || from === to) { - return self; + // A helper function for raising things, that gracefully degrades if necessary + // functionality is not yet loaded. + function $raise(klass, message) { + // Raise Exception, so we can know that something wrong is going on. + if (!klass) klass = Opal.Exception || Error; + + if (Kernel && Kernel.$raise) { + if (arguments.length > 2) { + Kernel.$raise(klass.$new.apply(klass, $slice(arguments, 1))); + } + else { + Kernel.$raise(klass, message); } + } + else if (!klass.$new) { + throw new klass(message); + } + else { + throw klass.$new(message); + } + } - var i, in_range, c, ch, start, end, length; - var subs = {}; - var from_chars = from.split(''); - var from_length = from_chars.length; - var to_chars = to.split(''); - var to_length = to_chars.length; + function $prop(object, name, initialValue) { + if (typeof(object) === "string") { + // Special case for: + // s = "string" + // def s.m; end + // String class is the only class that: + // + compiles to JS primitive + // + allows method definition directly on instances + // numbers, true, false and null do not support it. + object[name] = initialValue; + } else { + Object.defineProperty(object, name, { + value: initialValue, + enumerable: false, + configurable: true, + writable: true + }); + } + } - var inverse = false; - var global_sub = null; - if (from_chars[0] === '^' && from_chars.length > 1) { - inverse = true; - from_chars.shift(); - global_sub = to_chars[to_length - 1] - from_length -= 1; - } + Opal.prop = $prop; - var from_chars_expanded = []; - var last_from = null; - in_range = false; - for (i = 0; i < from_length; i++) { - ch = from_chars[i]; - if (last_from == null) { - last_from = ch; - from_chars_expanded.push(ch); - } - else if (ch === '-') { - if (last_from === '-') { - from_chars_expanded.push('-'); - from_chars_expanded.push('-'); - } - else if (i == from_length - 1) { - from_chars_expanded.push('-'); - } - else { - in_range = true; - } - } - else if (in_range) { - start = last_from.charCodeAt(0); - end = ch.charCodeAt(0); - if (start > end) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration") - } - for (c = start + 1; c < end; c++) { - from_chars_expanded.push(String.fromCharCode(c)); - } - from_chars_expanded.push(ch); - in_range = null; - last_from = null; - } - else { - from_chars_expanded.push(ch); - } - } + // @deprecated + Opal.defineProperty = Opal.prop; - from_chars = from_chars_expanded; - from_length = from_chars.length; + Opal.slice = $slice; - if (inverse) { - for (i = 0; i < from_length; i++) { - subs[from_chars[i]] = true; - } - } - else { - if (to_length > 0) { - var to_chars_expanded = []; - var last_to = null; - in_range = false; - for (i = 0; i < to_length; i++) { - ch = to_chars[i]; - if (last_to == null) { - last_to = ch; - to_chars_expanded.push(ch); - } - else if (ch === '-') { - if (last_to === '-') { - to_chars_expanded.push('-'); - to_chars_expanded.push('-'); - } - else if (i == to_length - 1) { - to_chars_expanded.push('-'); - } - else { - in_range = true; - } - } - else if (in_range) { - start = last_to.charCodeAt(0); - end = ch.charCodeAt(0); - if (start > end) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration") - } - for (c = start + 1; c < end; c++) { - to_chars_expanded.push(String.fromCharCode(c)); - } - to_chars_expanded.push(ch); - in_range = null; - last_to = null; - } - else { - to_chars_expanded.push(ch); - } - } + // Helpers + // ----- - to_chars = to_chars_expanded; - to_length = to_chars.length; - } + var $truthy = Opal.truthy = function(val) { + return false !== val && nil !== val && undefined !== val && null !== val && (!(val instanceof Boolean) || true === val.valueOf()); + }; - var length_diff = from_length - to_length; - if (length_diff > 0) { - var pad_char = (to_length > 0 ? to_chars[to_length - 1] : ''); - for (i = 0; i < length_diff; i++) { - to_chars.push(pad_char); - } - } + Opal.falsy = function(val) { + return !$truthy(val); + }; - for (i = 0; i < from_length; i++) { - subs[from_chars[i]] = to_chars[i]; - } - } + Opal.type_error = function(object, type, method, coerced) { + object = object.$$class; - var new_str = '' - for (i = 0, length = self.length; i < length; i++) { - ch = self.charAt(i); - var sub = subs[ch]; - if (inverse) { - new_str += (sub == null ? global_sub : ch); - } - else { - new_str += (sub != null ? sub : ch); - } - } - return self.$$cast(new_str); - ; - }, $String_tr$69.$$arity = 2); - - Opal.def(self, '$tr_s', $String_tr_s$70 = function $$tr_s(from, to) { - var self = this; + if (coerced && method) { + coerced = coerced.$$class; + $raise(Opal.TypeError, + "can't convert " + object + " into " + type + + " (" + object + "#" + method + " gives " + coerced + ")" + ); + } else { + $raise(Opal.TypeError, + "no implicit conversion of " + object + " into " + type + ); + } + }; - - from = $$($nesting, 'Opal').$coerce_to(from, $$($nesting, 'String'), "to_str").$to_s(); - to = $$($nesting, 'Opal').$coerce_to(to, $$($nesting, 'String'), "to_str").$to_s(); - - if (from.length == 0) { - return self; - } + Opal.coerce_to = function(object, type, method, args) { + var body; - var i, in_range, c, ch, start, end, length; - var subs = {}; - var from_chars = from.split(''); - var from_length = from_chars.length; - var to_chars = to.split(''); - var to_length = to_chars.length; + if (method === 'to_int' && type === Opal.Integer && object.$$is_number) + return object < 0 ? Math.ceil(object) : Math.floor(object); - var inverse = false; - var global_sub = null; - if (from_chars[0] === '^' && from_chars.length > 1) { - inverse = true; - from_chars.shift(); - global_sub = to_chars[to_length - 1] - from_length -= 1; - } + if (method === 'to_str' && type === Opal.String && object.$$is_string) + return object; - var from_chars_expanded = []; - var last_from = null; - in_range = false; - for (i = 0; i < from_length; i++) { - ch = from_chars[i]; - if (last_from == null) { - last_from = ch; - from_chars_expanded.push(ch); - } - else if (ch === '-') { - if (last_from === '-') { - from_chars_expanded.push('-'); - from_chars_expanded.push('-'); - } - else if (i == from_length - 1) { - from_chars_expanded.push('-'); - } - else { - in_range = true; - } - } - else if (in_range) { - start = last_from.charCodeAt(0); - end = ch.charCodeAt(0); - if (start > end) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration") - } - for (c = start + 1; c < end; c++) { - from_chars_expanded.push(String.fromCharCode(c)); - } - from_chars_expanded.push(ch); - in_range = null; - last_from = null; - } - else { - from_chars_expanded.push(ch); - } - } + if (Opal.is_a(object, type)) return object; - from_chars = from_chars_expanded; - from_length = from_chars.length; + // Fast path for the most common situation + if (object['$respond_to?'].$$pristine && object.$method_missing.$$pristine) { + body = object[$jsid(method)]; + if (body == null || body.$$stub) Opal.type_error(object, type); + return body.apply(object, args); + } - if (inverse) { - for (i = 0; i < from_length; i++) { - subs[from_chars[i]] = true; - } - } - else { - if (to_length > 0) { - var to_chars_expanded = []; - var last_to = null; - in_range = false; - for (i = 0; i < to_length; i++) { - ch = to_chars[i]; - if (last_from == null) { - last_from = ch; - to_chars_expanded.push(ch); - } - else if (ch === '-') { - if (last_to === '-') { - to_chars_expanded.push('-'); - to_chars_expanded.push('-'); - } - else if (i == to_length - 1) { - to_chars_expanded.push('-'); - } - else { - in_range = true; - } - } - else if (in_range) { - start = last_from.charCodeAt(0); - end = ch.charCodeAt(0); - if (start > end) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration") - } - for (c = start + 1; c < end; c++) { - to_chars_expanded.push(String.fromCharCode(c)); - } - to_chars_expanded.push(ch); - in_range = null; - last_from = null; - } - else { - to_chars_expanded.push(ch); - } - } + if (!object['$respond_to?'](method)) { + Opal.type_error(object, type); + } - to_chars = to_chars_expanded; - to_length = to_chars.length; - } + if (args == null) args = []; + return Opal.send(object, method, args); + }; - var length_diff = from_length - to_length; - if (length_diff > 0) { - var pad_char = (to_length > 0 ? to_chars[to_length - 1] : ''); - for (i = 0; i < length_diff; i++) { - to_chars.push(pad_char); - } - } + Opal.respond_to = function(obj, jsid, include_all) { + if (obj == null || !obj.$$class) return false; + include_all = !!include_all; + var body = obj[jsid]; - for (i = 0; i < from_length; i++) { - subs[from_chars[i]] = to_chars[i]; - } + if (obj['$respond_to?'].$$pristine) { + if (typeof(body) === "function" && !body.$$stub) { + return true; } - var new_str = '' - var last_substitute = null - for (i = 0, length = self.length; i < length; i++) { - ch = self.charAt(i); - var sub = subs[ch] - if (inverse) { - if (sub == null) { - if (last_substitute == null) { - new_str += global_sub; - last_substitute = true; - } - } - else { - new_str += ch; - last_substitute = null; - } - } - else { - if (sub != null) { - if (last_substitute == null || last_substitute !== sub) { - new_str += sub; - last_substitute = sub; - } - } - else { - new_str += ch; - last_substitute = null; - } - } + if (!obj['$respond_to_missing?'].$$pristine) { + return Opal.send(obj, obj['$respond_to_missing?'], [jsid.substr(1), include_all]); } - return self.$$cast(new_str); - ; - }, $String_tr_s$70.$$arity = 2); - - Opal.def(self, '$upcase', $String_upcase$71 = function $$upcase() { - var self = this; + } else { + return Opal.send(obj, obj['$respond_to?'], [jsid.substr(1), include_all]); + } + }; - return self.$$cast(self.toUpperCase()); - }, $String_upcase$71.$$arity = 0); - - Opal.def(self, '$upto', $String_upto$72 = function $$upto(stop, excl) { - var $iter = $String_upto$72.$$p, block = $iter || nil, self = this; + // TracePoint support + // ------------------ + // + // Support for `TracePoint.trace(:class) do ... end` + Opal.trace_class = false; + Opal.tracers_for_class = []; - if ($iter) $String_upto$72.$$p = null; - - - if ($iter) $String_upto$72.$$p = null;; - - if (excl == null) { - excl = false; - }; - if ((block !== nil)) { - } else { - return self.$enum_for("upto", stop, excl) - }; - stop = $$($nesting, 'Opal').$coerce_to(stop, $$($nesting, 'String'), "to_str"); - - var a, b, s = self.toString(); + function invoke_tracers_for_class(klass_or_module) { + var i, ii, tracer; - if (s.length === 1 && stop.length === 1) { + for(i = 0, ii = Opal.tracers_for_class.length; i < ii; i++) { + tracer = Opal.tracers_for_class[i]; + tracer.trace_object = klass_or_module; + tracer.block.$call(tracer); + } + } - a = s.charCodeAt(0); - b = stop.charCodeAt(0); + function handle_autoload(cref, name) { + if (!cref.$$autoload[name].loaded) { + cref.$$autoload[name].loaded = true; + try { + Opal.Kernel.$require(cref.$$autoload[name].path); + } catch (e) { + cref.$$autoload[name].exception = e; + throw e; + } + cref.$$autoload[name].required = true; + if (cref.$$const[name] != null) { + cref.$$autoload[name].success = true; + return cref.$$const[name]; + } + } else if (cref.$$autoload[name].loaded && !cref.$$autoload[name].required) { + if (cref.$$autoload[name].exception) { throw cref.$$autoload[name].exception; } + } + } - while (a <= b) { - if (excl && a === b) { - break; - } + // Constants + // --------- + // + // For future reference: + // - The Rails autoloading guide (http://guides.rubyonrails.org/v5.0/autoloading_and_reloading_constants.html) + // - @ConradIrwin's 2012 post on “Everything you ever wanted to know about constant lookup in Ruby” (http://cirw.in/blog/constant-lookup.html) + // + // Legend of MRI concepts/names: + // - constant reference (cref): the module/class that acts as a namespace + // - nesting: the namespaces wrapping the current scope, e.g. nesting inside + // `module A; module B::C; end; end` is `[B::C, A]` - block(String.fromCharCode(a)); + // Get the constant in the scope of the current cref + function const_get_name(cref, name) { + if (cref) { + if (cref.$$const[name] != null) { return cref.$$const[name]; } + if (cref.$$autoload && cref.$$autoload[name]) { + return handle_autoload(cref, name); + } + } + } - a += 1; - } + // Walk up the nesting array looking for the constant + function const_lookup_nesting(nesting, name) { + var i, ii, constant; - } else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) { + if (nesting.length === 0) return; - a = parseInt(s, 10); - b = parseInt(stop, 10); + // If the nesting is not empty the constant is looked up in its elements + // and in order. The ancestors of those elements are ignored. + for (i = 0, ii = nesting.length; i < ii; i++) { + constant = nesting[i].$$const[name]; + if (constant != null) { + return constant; + } else if (nesting[i].$$autoload && nesting[i].$$autoload[name]) { + return handle_autoload(nesting[i], name); + } + } + } - while (a <= b) { - if (excl && a === b) { - break; - } + // Walk up the ancestors chain looking for the constant + function const_lookup_ancestors(cref, name) { + var i, ii, ancestors; - block(a.toString()); + if (cref == null) return; - a += 1; - } + ancestors = $ancestors(cref); - } else { + for (i = 0, ii = ancestors.length; i < ii; i++) { + if (ancestors[i].$$const && $has_own(ancestors[i].$$const, name)) { + return ancestors[i].$$const[name]; + } else if (ancestors[i].$$autoload && ancestors[i].$$autoload[name]) { + return handle_autoload(ancestors[i], name); + } + } + } - while (s.length <= stop.length && s <= stop) { - if (excl && s === stop) { - break; - } + // Walk up Object's ancestors chain looking for the constant, + // but only if cref is missing or a module. + function const_lookup_Object(cref, name) { + if (cref == null || cref.$$is_module) { + return const_lookup_ancestors(_Object, name); + } + } + + // Call const_missing if nothing else worked + function const_missing(cref, name) { + return (cref || _Object).$const_missing(name); + } + + // Look for the constant just in the current cref or call `#const_missing` + Opal.const_get_local = function(cref, name, skip_missing) { + var result; - block(s); + if (cref == null) return; - s = (s).$succ(); - } + if (cref === '::') cref = _Object; - } - return self; - ; - }, $String_upto$72.$$arity = -2); - - function char_class_from_char_sets(sets) { - function explode_sequences_in_character_set(set) { - var result = '', - i, len = set.length, - curr_char, - skip_next_dash, - char_code_from, - char_code_upto, - char_code; - for (i = 0; i < len; i++) { - curr_char = set.charAt(i); - if (curr_char === '-' && i > 0 && i < (len - 1) && !skip_next_dash) { - char_code_from = set.charCodeAt(i - 1); - char_code_upto = set.charCodeAt(i + 1); - if (char_code_from > char_code_upto) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid range \"" + (char_code_from) + "-" + (char_code_upto) + "\" in string transliteration") - } - for (char_code = char_code_from + 1; char_code < char_code_upto + 1; char_code++) { - result += String.fromCharCode(char_code); - } - skip_next_dash = true; - i++; - } else { - skip_next_dash = (curr_char === '\\'); - result += curr_char; - } - } - return result; - } + if (!cref.$$is_module && !cref.$$is_class) { + $raise(Opal.TypeError, cref.toString() + " is not a class/module"); + } - function intersection(setA, setB) { - if (setA.length === 0) { - return setB; - } - var result = '', - i, len = setA.length, - chr; - for (i = 0; i < len; i++) { - chr = setA.charAt(i); - if (setB.indexOf(chr) !== -1) { - result += chr; - } - } - return result; - } + result = const_get_name(cref, name); + return result != null || skip_missing ? result : const_missing(cref, name); + }; - var i, len, set, neg, chr, tmp, - pos_intersection = '', - neg_intersection = ''; + // Look for the constant relative to a cref or call `#const_missing` (when the + // constant is prefixed by `::`). + Opal.const_get_qualified = function(cref, name, skip_missing) { + var result, cache, cached, current_version = Opal.const_cache_version; - for (i = 0, len = sets.length; i < len; i++) { - set = $$($nesting, 'Opal').$coerce_to(sets[i], $$($nesting, 'String'), "to_str"); - neg = (set.charAt(0) === '^' && set.length > 1); - set = explode_sequences_in_character_set(neg ? set.slice(1) : set); - if (neg) { - neg_intersection = intersection(neg_intersection, set); - } else { - pos_intersection = intersection(pos_intersection, set); - } - } + if (name == null) { + // A shortpath for calls like ::String => $$$("String") + result = const_get_name(_Object, cref); - if (pos_intersection.length > 0 && neg_intersection.length > 0) { - tmp = ''; - for (i = 0, len = pos_intersection.length; i < len; i++) { - chr = pos_intersection.charAt(i); - if (neg_intersection.indexOf(chr) === -1) { - tmp += chr; - } - } - pos_intersection = tmp; - neg_intersection = ''; - } + if (result != null) return result; + return Opal.const_get_qualified(_Object, cref, skip_missing); + } - if (pos_intersection.length > 0) { - return '[' + $$($nesting, 'Regexp').$escape(pos_intersection) + ']'; - } + if (cref == null) return; - if (neg_intersection.length > 0) { - return '[^' + $$($nesting, 'Regexp').$escape(neg_intersection) + ']'; - } + if (cref === '::') cref = _Object; - return null; + if (!cref.$$is_module && !cref.$$is_class) { + $raise(Opal.TypeError, cref.toString() + " is not a class/module"); } - ; - - Opal.def(self, '$instance_variables', $String_instance_variables$73 = function $$instance_variables() { - var self = this; - return [] - }, $String_instance_variables$73.$$arity = 0); - Opal.defs(self, '$_load', $String__load$74 = function $$_load($a) { - var $post_args, args, self = this; + if ((cache = cref.$$const_cache) == null) { + $prop(cref, '$$const_cache', Object.create(null)); + cache = cref.$$const_cache; + } + cached = cache[name]; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $send(self, 'new', Opal.to_a(args)); - }, $String__load$74.$$arity = -1); - - Opal.def(self, '$unicode_normalize', $String_unicode_normalize$75 = function $$unicode_normalize(form) { - var self = this; + if (cached == null || cached[0] !== current_version) { + ((result = const_get_name(cref, name)) != null) || + ((result = const_lookup_ancestors(cref, name)) != null); + cache[name] = [current_version, result]; + } else { + result = cached[1]; + } - - ; - return self.toString();; - }, $String_unicode_normalize$75.$$arity = -1); - - Opal.def(self, '$unicode_normalized?', $String_unicode_normalized$ques$76 = function(form) { - var self = this; + return result != null || skip_missing ? result : const_missing(cref, name); + }; - - ; - return true; - }, $String_unicode_normalized$ques$76.$$arity = -1); - - Opal.def(self, '$unpack', $String_unpack$77 = function $$unpack(format) { - var self = this; + // Initialize the top level constant cache generation counter + Opal.const_cache_version = 1; - return self.$raise("To use String#unpack, you must first require 'corelib/string/unpack'.") - }, $String_unpack$77.$$arity = 1); - return (Opal.def(self, '$unpack1', $String_unpack1$78 = function $$unpack1(format) { - var self = this; + // Look for the constant in the open using the current nesting and the nearest + // cref ancestors or call `#const_missing` (when the constant has no :: prefix). + Opal.const_get_relative = function(nesting, name, skip_missing) { + var cref = nesting[0], result, current_version = Opal.const_cache_version, cache, cached; - return self.$raise("To use String#unpack1, you must first require 'corelib/string/unpack'.") - }, $String_unpack1$78.$$arity = 1), nil) && 'unpack1'; - })($nesting[0], String, $nesting); - return Opal.const_set($nesting[0], 'Symbol', $$($nesting, 'String')); -}; + if ((cache = nesting.$$const_cache) == null) { + $prop(nesting, '$$const_cache', Object.create(null)); + cache = nesting.$$const_cache; + } + cached = cache[name]; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/enumerable"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_divide(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); - } - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy, $send = Opal.send, $falsy = Opal.falsy, $hash2 = Opal.hash2, $lambda = Opal.lambda; + if (cached == null || cached[0] !== current_version) { + ((result = const_get_name(cref, name)) != null) || + ((result = const_lookup_nesting(nesting, name)) != null) || + ((result = const_lookup_ancestors(cref, name)) != null) || + ((result = const_lookup_Object(cref, name)) != null); - Opal.add_stubs(['$each', '$public_send', '$destructure', '$to_enum', '$enumerator_size', '$new', '$yield', '$raise', '$slice_when', '$!', '$enum_for', '$flatten', '$map', '$warn', '$proc', '$==', '$nil?', '$respond_to?', '$coerce_to!', '$>', '$*', '$coerce_to', '$try_convert', '$<', '$+', '$-', '$ceil', '$/', '$size', '$__send__', '$length', '$<=', '$[]', '$push', '$<<', '$[]=', '$===', '$inspect', '$<=>', '$first', '$reverse', '$sort', '$to_proc', '$compare', '$call', '$dup', '$to_a', '$sort!', '$map!', '$key?', '$values', '$zip']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Enumerable'); + cache[name] = [current_version, result]; + } else { + result = cached[1]; + } - var $nesting = [self].concat($parent_nesting), $Enumerable_all$ques$1, $Enumerable_any$ques$5, $Enumerable_chunk$9, $Enumerable_chunk_while$12, $Enumerable_collect$14, $Enumerable_collect_concat$16, $Enumerable_count$19, $Enumerable_cycle$23, $Enumerable_detect$25, $Enumerable_drop$27, $Enumerable_drop_while$28, $Enumerable_each_cons$29, $Enumerable_each_entry$31, $Enumerable_each_slice$33, $Enumerable_each_with_index$35, $Enumerable_each_with_object$37, $Enumerable_entries$39, $Enumerable_find_all$40, $Enumerable_find_index$42, $Enumerable_first$45, $Enumerable_grep$48, $Enumerable_grep_v$50, $Enumerable_group_by$52, $Enumerable_include$ques$54, $Enumerable_inject$56, $Enumerable_lazy$57, $Enumerable_enumerator_size$59, $Enumerable_max$60, $Enumerable_max_by$61, $Enumerable_min$63, $Enumerable_min_by$64, $Enumerable_minmax$66, $Enumerable_minmax_by$68, $Enumerable_none$ques$69, $Enumerable_one$ques$73, $Enumerable_partition$77, $Enumerable_reject$79, $Enumerable_reverse_each$81, $Enumerable_slice_before$83, $Enumerable_slice_after$85, $Enumerable_slice_when$88, $Enumerable_sort$90, $Enumerable_sort_by$92, $Enumerable_sum$97, $Enumerable_take$99, $Enumerable_take_while$100, $Enumerable_uniq$102, $Enumerable_zip$104; + return result != null || skip_missing ? result : const_missing(cref, name); + }; - - - function comparableForPattern(value) { - if (value.length === 0) { - value = [nil]; - } + // Register the constant on a cref and opportunistically set the name of + // unnamed classes/modules. + function $const_set(cref, name, value) { + var new_const = true; - if (value.length > 1) { - value = [value]; - } + if (cref == null || cref === '::') cref = _Object; - return value; + if (value.$$is_a_module) { + if (value.$$name == null || value.$$name === nil) value.$$name = name; + if (value.$$base_module == null) value.$$base_module = cref; } - ; - - Opal.def(self, '$all?', $Enumerable_all$ques$1 = function(pattern) {try { - var $iter = $Enumerable_all$ques$1.$$p, block = $iter || nil, $$2, $$3, $$4, self = this; + cref.$$const = (cref.$$const || Object.create(null)); - if ($iter) $Enumerable_all$ques$1.$$p = null; - - - if ($iter) $Enumerable_all$ques$1.$$p = null;; - ; - if ($truthy(pattern !== undefined)) { - $send(self, 'each', [], ($$2 = function($a){var self = $$2.$$s || this, $post_args, value, comparable = nil; + if (name in cref.$$const || ("$$autoload" in cref && name in cref.$$autoload)) { + new_const = false; + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - comparable = comparableForPattern(value); - if ($truthy($send(pattern, 'public_send', ["==="].concat(Opal.to_a(comparable))))) { - return nil - } else { - Opal.ret(false) - };}, $$2.$$s = self, $$2.$$arity = -1, $$2)) - } else if ((block !== nil)) { - $send(self, 'each', [], ($$3 = function($a){var self = $$3.$$s || this, $post_args, value; + cref.$$const[name] = value; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy(Opal.yieldX(block, Opal.to_a(value)))) { - return nil - } else { - Opal.ret(false) - };}, $$3.$$s = self, $$3.$$arity = -1, $$3)) - } else { - $send(self, 'each', [], ($$4 = function($a){var self = $$4.$$s || this, $post_args, value; + // Add a short helper to navigate constants manually. + // @example + // Opal.$$.Regexp.$$.IGNORECASE + cref.$$ = cref.$$const; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy($$($nesting, 'Opal').$destructure(value))) { - return nil - } else { - Opal.ret(false) - };}, $$4.$$s = self, $$4.$$arity = -1, $$4)) - }; - return true; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_all$ques$1.$$arity = -1); - - Opal.def(self, '$any?', $Enumerable_any$ques$5 = function(pattern) {try { + Opal.const_cache_version++; - var $iter = $Enumerable_any$ques$5.$$p, block = $iter || nil, $$6, $$7, $$8, self = this; + // Expose top level constants onto the Opal object + if (cref === _Object) Opal[name] = value; - if ($iter) $Enumerable_any$ques$5.$$p = null; - - - if ($iter) $Enumerable_any$ques$5.$$p = null;; - ; - if ($truthy(pattern !== undefined)) { - $send(self, 'each', [], ($$6 = function($a){var self = $$6.$$s || this, $post_args, value, comparable = nil; + // Name new class directly onto current scope (Opal.Foo.Baz = klass) + $prop(cref, name, value); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - comparable = comparableForPattern(value); - if ($truthy($send(pattern, 'public_send', ["==="].concat(Opal.to_a(comparable))))) { - Opal.ret(true) - } else { - return nil - };}, $$6.$$s = self, $$6.$$arity = -1, $$6)) - } else if ((block !== nil)) { - $send(self, 'each', [], ($$7 = function($a){var self = $$7.$$s || this, $post_args, value; + if (new_const && cref.$const_added && !cref.$const_added.$$pristine) { + cref.$const_added(name); + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy(Opal.yieldX(block, Opal.to_a(value)))) { - Opal.ret(true) - } else { - return nil - };}, $$7.$$s = self, $$7.$$arity = -1, $$7)) - } else { - $send(self, 'each', [], ($$8 = function($a){var self = $$8.$$s || this, $post_args, value; + return value; + } + Opal.const_set = $const_set; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy($$($nesting, 'Opal').$destructure(value))) { - Opal.ret(true) - } else { - return nil - };}, $$8.$$s = self, $$8.$$arity = -1, $$8)) - }; - return false; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_any$ques$5.$$arity = -1); - - Opal.def(self, '$chunk', $Enumerable_chunk$9 = function $$chunk() { - var $iter = $Enumerable_chunk$9.$$p, block = $iter || nil, $$10, $$11, self = this; + // Get all the constants reachable from a given cref, by default will include + // inherited constants. + Opal.constants = function(cref, inherit) { + if (inherit == null) inherit = true; - if ($iter) $Enumerable_chunk$9.$$p = null; - - - if ($iter) $Enumerable_chunk$9.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'to_enum', ["chunk"], ($$10 = function(){var self = $$10.$$s || this; + var module, modules = [cref], i, ii, constants = {}, constant; - return self.$enumerator_size()}, $$10.$$s = self, $$10.$$arity = 0, $$10)) - }; - return $send($$$('::', 'Enumerator'), 'new', [], ($$11 = function(yielder){var self = $$11.$$s || this; + if (inherit) modules = modules.concat($ancestors(cref)); + if (inherit && cref.$$is_module) modules = modules.concat([Opal.Object]).concat($ancestors(Opal.Object)); - - - if (yielder == null) { - yielder = nil; - }; - - var previous = nil, accumulate = []; + for (i = 0, ii = modules.length; i < ii; i++) { + module = modules[i]; - function releaseAccumulate() { - if (accumulate.length > 0) { - yielder.$yield(previous, accumulate) - } + // Do not show Objects constants unless we're querying Object itself + if (cref !== _Object && module == _Object) break; + + for (constant in module.$$const) { + constants[constant] = true; + } + if (module.$$autoload) { + for (constant in module.$$autoload) { + constants[constant] = true; } + } + } - self.$each.$$p = function(value) { - var key = Opal.yield1(block, value); + return Object.keys(constants); + }; - if (key === nil) { - releaseAccumulate(); - accumulate = []; - previous = nil; - } else { - if (previous === nil || previous === key) { - accumulate.push(value); - } else { - releaseAccumulate(); - accumulate = [value]; - } + // Remove a constant from a cref. + Opal.const_remove = function(cref, name) { + Opal.const_cache_version++; - previous = key; - } - } + if (cref.$$const[name] != null) { + var old = cref.$$const[name]; + delete cref.$$const[name]; + return old; + } - self.$each(); + if (cref.$$autoload && cref.$$autoload[name]) { + delete cref.$$autoload[name]; + return nil; + } - releaseAccumulate(); - ;}, $$11.$$s = self, $$11.$$arity = 1, $$11)); - }, $Enumerable_chunk$9.$$arity = 0); - - Opal.def(self, '$chunk_while', $Enumerable_chunk_while$12 = function $$chunk_while() { - var $iter = $Enumerable_chunk_while$12.$$p, block = $iter || nil, $$13, self = this; + $raise(Opal.NameError, "constant "+cref+"::"+cref.$name()+" not defined"); + }; - if ($iter) $Enumerable_chunk_while$12.$$p = null; - - - if ($iter) $Enumerable_chunk_while$12.$$p = null;; - if ((block !== nil)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "no block given") - }; - return $send(self, 'slice_when', [], ($$13 = function(before, after){var self = $$13.$$s || this; + // Generates a function that is a curried const_get_relative. + Opal.const_get_relative_factory = function(nesting) { + return function(name, skip_missing) { + return Opal.$$(nesting, name, skip_missing); + } + }; - - - if (before == null) { - before = nil; - }; - - if (after == null) { - after = nil; - }; - return Opal.yieldX(block, [before, after])['$!']();}, $$13.$$s = self, $$13.$$arity = 2, $$13)); - }, $Enumerable_chunk_while$12.$$arity = 0); - - Opal.def(self, '$collect', $Enumerable_collect$14 = function $$collect() { - var $iter = $Enumerable_collect$14.$$p, block = $iter || nil, $$15, self = this; + // Setup some shortcuts to reduce compiled size + Opal.$$ = Opal.const_get_relative; + Opal.$$$ = Opal.const_get_qualified; + Opal.$r = Opal.const_get_relative_factory; - if ($iter) $Enumerable_collect$14.$$p = null; - - - if ($iter) $Enumerable_collect$14.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["collect"], ($$15 = function(){var self = $$15.$$s || this; + // Modules & Classes + // ----------------- - return self.$enumerator_size()}, $$15.$$s = self, $$15.$$arity = 0, $$15)) - }; - - var result = []; + // A `class Foo; end` expression in ruby is compiled to call this runtime + // method which either returns an existing class of the given name, or creates + // a new class in the given `base` scope. + // + // If a constant with the given name exists, then we check to make sure that + // it is a class and also that the superclasses match. If either of these + // fail, then we raise a `TypeError`. Note, `superclass` may be null if one + // was not specified in the ruby code. + // + // We pass a constructor to this method of the form `function ClassName() {}` + // simply so that classes show up with nicely formatted names inside debuggers + // in the web browser (or node/sprockets). + // + // The `scope` is the current `self` value where the class is being created + // from. We use this to get the scope for where the class should be created. + // If `scope` is an object (not a class/module), we simple get its class and + // use that as the scope instead. + // + // @param scope [Object] where the class is being created + // @param superclass [Class,null] superclass of the new class (may be null) + // @param singleton [Boolean,null] a true value denotes we want to allocate + // a singleton + // + // @return new [Class] or existing ruby class + // + function $allocate_class(name, superclass, singleton) { + var klass; - self.$each.$$p = function() { - var value = Opal.yieldX(block, arguments); + if (superclass != null && superclass.$$bridge) { + // Inheritance from bridged classes requires + // calling original JS constructors + klass = function() { + var args = $slice(arguments), + self = new ($bind.apply(superclass.$$constructor, [null].concat(args)))(); - result.push(value); + // and replacing a __proto__ manually + $set_proto(self, klass.$$prototype); + return self; }; + } else { + klass = function(){}; + } - self.$each(); + if (name && name !== nil) { + $prop(klass, 'displayName', '::'+name); + } - return result; - ; - }, $Enumerable_collect$14.$$arity = 0); - - Opal.def(self, '$collect_concat', $Enumerable_collect_concat$16 = function $$collect_concat() { - var $iter = $Enumerable_collect_concat$16.$$p, block = $iter || nil, $$17, $$18, self = this; + $prop(klass, '$$name', name); + $prop(klass, '$$constructor', klass); + $prop(klass, '$$prototype', klass.prototype); + $prop(klass, '$$const', {}); + $prop(klass, '$$is_class', true); + $prop(klass, '$$is_a_module', true); + $prop(klass, '$$super', superclass); + $prop(klass, '$$cvars', {}); + $prop(klass, '$$own_included_modules', []); + $prop(klass, '$$own_prepended_modules', []); + $prop(klass, '$$ancestors', []); + $prop(klass, '$$ancestors_cache_version', null); + $prop(klass, '$$subclasses', []); - if ($iter) $Enumerable_collect_concat$16.$$p = null; - - - if ($iter) $Enumerable_collect_concat$16.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["collect_concat"], ($$17 = function(){var self = $$17.$$s || this; + $prop(klass.$$prototype, '$$class', klass); - return self.$enumerator_size()}, $$17.$$s = self, $$17.$$arity = 0, $$17)) - }; - return $send(self, 'map', [], ($$18 = function(item){var self = $$18.$$s || this; + // By default if there are no singleton class methods + // __proto__ is Class.prototype + // Later singleton methods generate a singleton_class + // and inject it into ancestors chain + if (Opal.Class) { + $set_proto(klass, Opal.Class.prototype); + } - - - if (item == null) { - item = nil; - }; - return Opal.yield1(block, item);;}, $$18.$$s = self, $$18.$$arity = 1, $$18)).$flatten(1); - }, $Enumerable_collect_concat$16.$$arity = 0); - - Opal.def(self, '$count', $Enumerable_count$19 = function $$count(object) { - var $iter = $Enumerable_count$19.$$p, block = $iter || nil, $$20, $$21, $$22, self = this, result = nil; + if (superclass != null) { + $set_proto(klass.$$prototype, superclass.$$prototype); + + if (singleton !== true) { + // Let's not forbid GC from cleaning up our + // subclasses. + if (typeof WeakRef !== 'undefined') { + // First, let's clean up our array from empty objects. + var i, subclass, rebuilt_subclasses = []; + for (i = 0; i < superclass.$$subclasses.length; i++) { + subclass = superclass.$$subclasses[i]; + if (subclass.deref() !== undefined) { + rebuilt_subclasses.push(subclass); + } + } + // Now, let's add our class. + rebuilt_subclasses.push(new WeakRef(klass)); + superclass.$$subclasses = rebuilt_subclasses; + } + else { + superclass.$$subclasses.push(klass); + } + } - if ($iter) $Enumerable_count$19.$$p = null; - - - if ($iter) $Enumerable_count$19.$$p = null;; - ; - result = 0; - - if (object != null && block !== nil) { - self.$warn("warning: given block not used") + if (superclass.$$meta) { + // If superclass has metaclass then we have explicitely inherit it. + Opal.build_class_singleton_class(klass); } - ; - if ($truthy(object != null)) { - block = $send(self, 'proc', [], ($$20 = function($a){var self = $$20.$$s || this, $post_args, args; + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $$($nesting, 'Opal').$destructure(args)['$=='](object);}, $$20.$$s = self, $$20.$$arity = -1, $$20)) - } else if ($truthy(block['$nil?']())) { - block = $send(self, 'proc', [], ($$21 = function(){var self = $$21.$$s || this; + return klass; + } Opal.allocate_class = $allocate_class; - return true}, $$21.$$s = self, $$21.$$arity = 0, $$21))}; - $send(self, 'each', [], ($$22 = function($a){var self = $$22.$$s || this, $post_args, args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(Opal.yieldX(block, args))) { - return result++; - } else { - return nil - };}, $$22.$$s = self, $$22.$$arity = -1, $$22)); - return result; - }, $Enumerable_count$19.$$arity = -1); - - Opal.def(self, '$cycle', $Enumerable_cycle$23 = function $$cycle(n) { - var $iter = $Enumerable_cycle$23.$$p, block = $iter || nil, $$24, self = this; + function find_existing_class(scope, name) { + // Try to find the class in the current scope + var klass = const_get_name(scope, name); - if ($iter) $Enumerable_cycle$23.$$p = null; - - - if ($iter) $Enumerable_cycle$23.$$p = null;; - - if (n == null) { - n = nil; - }; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["cycle", n], ($$24 = function(){var self = $$24.$$s || this; + // If the class exists in the scope, then we must use that + if (klass) { + // Make sure the existing constant is a class, or raise error + if (!klass.$$is_class) { + $raise(Opal.TypeError, name + " is not a class"); + } - if ($truthy(n['$nil?']())) { - if ($truthy(self['$respond_to?']("size"))) { - return $$$($$($nesting, 'Float'), 'INFINITY') - } else { - return nil - } - } else { - - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_gt(n, 0))) { - return $rb_times(self.$enumerator_size(), n) - } else { - return 0 - }; - }}, $$24.$$s = self, $$24.$$arity = 0, $$24)) - }; - if ($truthy(n['$nil?']())) { - } else { - - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if ($truthy(n <= 0)) { - return nil}; - }; - - var result, - all = [], i, length, value; + return klass; + } + } - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + function ensureSuperclassMatch(klass, superclass) { + if (klass.$$super !== superclass) { + $raise(Opal.TypeError, "superclass mismatch for class " + klass.$$name); + } + } - all.push(param); + Opal.klass = function(scope, superclass, name) { + var bridged; + + if (scope == null || scope == '::') { + // Global scope + scope = _Object; + } else if (!scope.$$is_class && !scope.$$is_module) { + // Scope is an object, use its class + scope = scope.$$class; + } + + // If the superclass is not an Opal-generated class then we're bridging a native JS class + if ( + superclass != null && (!superclass.hasOwnProperty || ( + superclass.hasOwnProperty && !superclass.hasOwnProperty('$$is_class') + )) + ) { + if (superclass.constructor && superclass.constructor.name == "Function") { + bridged = superclass; + superclass = _Object; + } else { + $raise(Opal.TypeError, "superclass must be a Class (" + ( + (superclass.constructor && (superclass.constructor.name || superclass.constructor.$$name)) || + typeof(superclass) + ) + " given)"); } + } - self.$each(); + var klass = find_existing_class(scope, name); - if (result !== undefined) { - return result; + if (klass != null) { + if (superclass) { + // Make sure existing class has same superclass + ensureSuperclassMatch(klass, superclass); } + } + else { + // Class doesn't exist, create a new one with given superclass... - if (all.length === 0) { - return nil; + // Not specifying a superclass means we can assume it to be Object + if (superclass == null) { + superclass = _Object; } - if (n === nil) { - while (true) { - for (i = 0, length = all.length; i < length; i++) { - value = Opal.yield1(block, all[i]); - } - } + // Create the class object (instance of Class) + klass = $allocate_class(name, superclass); + $const_set(scope, name, klass); + + // Call .inherited() hook with new class on the superclass + if (superclass.$inherited) { + superclass.$inherited(klass); } - else { - while (n > 1) { - for (i = 0, length = all.length; i < length; i++) { - value = Opal.yield1(block, all[i]); - } - n--; - } + if (bridged) { + Opal.bridge(bridged, klass); } - ; - }, $Enumerable_cycle$23.$$arity = -1); - - Opal.def(self, '$detect', $Enumerable_detect$25 = function $$detect(ifnone) {try { + } + + if (Opal.trace_class) { invoke_tracers_for_class(klass); } + + return klass; + }; + + // Define new module (or return existing module). The given `scope` is basically + // the current `self` value the `module` statement was defined in. If this is + // a ruby module or class, then it is used, otherwise if the scope is a ruby + // object then that objects real ruby class is used (e.g. if the scope is the + // main object, then the top level `Object` class is used as the scope). + // + // If a module of the given name is already defined in the scope, then that + // instance is just returned. + // + // If there is a class of the given name in the scope, then an error is + // generated instead (cannot have a class and module of same name in same scope). + // + // Otherwise, a new module is created in the scope with the given name, and that + // new instance is returned back (to be referenced at runtime). + // + // @param scope [Module, Class] class or module this definition is inside + // @param id [String] the name of the new (or existing) module + // + // @return [Module] + function $allocate_module(name) { + var constructor = function(){}; + var module = constructor; + + if (name) + $prop(constructor, 'displayName', name+'.constructor'); + + $prop(module, '$$name', name); + $prop(module, '$$prototype', constructor.prototype); + $prop(module, '$$const', {}); + $prop(module, '$$is_module', true); + $prop(module, '$$is_a_module', true); + $prop(module, '$$cvars', {}); + $prop(module, '$$iclasses', []); + $prop(module, '$$own_included_modules', []); + $prop(module, '$$own_prepended_modules', []); + $prop(module, '$$ancestors', [module]); + $prop(module, '$$ancestors_cache_version', null); + + $set_proto(module, Opal.Module.prototype); - var $iter = $Enumerable_detect$25.$$p, block = $iter || nil, $$26, self = this; + return module; + } Opal.allocate_module = $allocate_module; - if ($iter) $Enumerable_detect$25.$$p = null; - - - if ($iter) $Enumerable_detect$25.$$p = null;; - ; - if ((block !== nil)) { - } else { - return self.$enum_for("detect", ifnone) - }; - $send(self, 'each', [], ($$26 = function($a){var self = $$26.$$s || this, $post_args, args, value = nil; + function find_existing_module(scope, name) { + var module = const_get_name(scope, name); + if (module == null && scope === _Object) module = const_lookup_ancestors(_Object, name); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - value = $$($nesting, 'Opal').$destructure(args); - if ($truthy(Opal.yield1(block, value))) { - Opal.ret(value) - } else { - return nil - };}, $$26.$$s = self, $$26.$$arity = -1, $$26)); - - if (ifnone !== undefined) { - if (typeof(ifnone) === 'function') { - return ifnone(); - } else { - return ifnone; - } + if (module) { + if (!module.$$is_module && module !== _Object) { + $raise(Opal.TypeError, name + " is not a module"); } - ; - return nil; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_detect$25.$$arity = -1); - - Opal.def(self, '$drop', $Enumerable_drop$27 = function $$drop(number) { - var self = this; - - - number = $$($nesting, 'Opal').$coerce_to(number, $$($nesting, 'Integer'), "to_int"); - if ($truthy(number < 0)) { - self.$raise($$($nesting, 'ArgumentError'), "attempt to drop negative size")}; - - var result = [], - current = 0; - - self.$each.$$p = function() { - if (number <= current) { - result.push($$($nesting, 'Opal').$destructure(arguments)); - } + } - current++; - }; + return module; + } - self.$each() + Opal.module = function(scope, name) { + var module; - return result; - ; - }, $Enumerable_drop$27.$$arity = 1); - - Opal.def(self, '$drop_while', $Enumerable_drop_while$28 = function $$drop_while() { - var $iter = $Enumerable_drop_while$28.$$p, block = $iter || nil, self = this; + if (scope == null || scope == '::') { + // Global scope + scope = _Object; + } else if (!scope.$$is_class && !scope.$$is_module) { + // Scope is an object, use its class + scope = scope.$$class; + } - if ($iter) $Enumerable_drop_while$28.$$p = null; - - - if ($iter) $Enumerable_drop_while$28.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("drop_while") - }; - - var result = [], - dropping = true; + module = find_existing_module(scope, name); - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + if (module == null) { + // Module doesnt exist, create a new one... + module = $allocate_module(name); + $const_set(scope, name, module); + } - if (dropping) { - var value = Opal.yield1(block, param); + if (Opal.trace_class) { invoke_tracers_for_class(module); } - if ($falsy(value)) { - dropping = false; - result.push(param); - } - } - else { - result.push(param); - } - }; + return module; + }; - self.$each(); + // Return the singleton class for the passed object. + // + // If the given object alredy has a singleton class, then it will be stored on + // the object as the `$$meta` property. If this exists, then it is simply + // returned back. + // + // Otherwise, a new singleton object for the class or object is created, set on + // the object at `$$meta` for future use, and then returned. + // + // @param object [Object] the ruby object + // @return [Class] the singleton class for object + Opal.get_singleton_class = function(object) { + if (object.$$is_number) { + $raise(Opal.TypeError, "can't define singleton"); + } + if (object.$$meta) { + return object.$$meta; + } - return result; - ; - }, $Enumerable_drop_while$28.$$arity = 0); - - Opal.def(self, '$each_cons', $Enumerable_each_cons$29 = function $$each_cons(n) { - var $iter = $Enumerable_each_cons$29.$$p, block = $iter || nil, $$30, self = this; + if (object.hasOwnProperty('$$is_class')) { + return Opal.build_class_singleton_class(object); + } else if (object.hasOwnProperty('$$is_module')) { + return Opal.build_module_singleton_class(object); + } else { + return Opal.build_object_singleton_class(object); + } + }; - if ($iter) $Enumerable_each_cons$29.$$p = null; - - - if ($iter) $Enumerable_each_cons$29.$$p = null;; - if ($truthy(arguments.length != 1)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arguments.length) + " for 1)")}; - n = $$($nesting, 'Opal').$try_convert(n, $$($nesting, 'Integer'), "to_int"); - if ($truthy(n <= 0)) { - self.$raise($$($nesting, 'ArgumentError'), "invalid size")}; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["each_cons", n], ($$30 = function(){var self = $$30.$$s || this, $a, enum_size = nil; + // helper to set $$meta on klass, module or instance + function set_meta(obj, meta) { + if (obj.hasOwnProperty('$$meta')) { + obj.$$meta = meta; + } else { + $prop(obj, '$$meta', meta); + } + if (obj.$$frozen) { + // If a object is frozen (sealed), freeze $$meta too. + // No need to inject $$meta.$$prototype in the prototype chain, + // as $$meta cannot be modified anyway. + obj.$$meta.$freeze(); + } else { + $set_proto(obj, meta.$$prototype); + } + } + // Build the singleton class for an existing class. Class object are built + // with their singleton class already in the prototype chain and inheriting + // from their superclass object (up to `Class` itself). + // + // NOTE: Actually in MRI a class' singleton class inherits from its + // superclass' singleton class which in turn inherits from Class. + // + // @param klass [Class] + // @return [Class] + Opal.build_class_singleton_class = function(klass) { + if (klass.$$meta) { + return klass.$$meta; + } - - enum_size = self.$enumerator_size(); - if ($truthy(enum_size['$nil?']())) { - return nil - } else if ($truthy(($truthy($a = enum_size['$=='](0)) ? $a : $rb_lt(enum_size, n)))) { - return 0 - } else { - return $rb_plus($rb_minus(enum_size, n), 1) - };}, $$30.$$s = self, $$30.$$arity = 0, $$30)) - }; - - var buffer = [], result = nil; + // The singleton_class superclass is the singleton_class of its superclass; + // but BasicObject has no superclass (its `$$super` is null), thus we + // fallback on `Class`. + var superclass = klass === BasicObject ? Class : Opal.get_singleton_class(klass.$$super); - self.$each.$$p = function() { - var element = $$($nesting, 'Opal').$destructure(arguments); - buffer.push(element); - if (buffer.length > n) { - buffer.shift(); - } - if (buffer.length == n) { - Opal.yield1(block, buffer.slice(0, n)); - } - } + var meta = $allocate_class(null, superclass, true); - self.$each(); + $prop(meta, '$$is_singleton', true); + $prop(meta, '$$singleton_of', klass); + set_meta(klass, meta); + // Restoring ClassName.class + $prop(klass, '$$class', Opal.Class); - return result; - ; - }, $Enumerable_each_cons$29.$$arity = 1); - - Opal.def(self, '$each_entry', $Enumerable_each_entry$31 = function $$each_entry($a) { - var $iter = $Enumerable_each_entry$31.$$p, block = $iter || nil, $post_args, data, $$32, self = this; + return meta; + }; - if ($iter) $Enumerable_each_entry$31.$$p = null; - - - if ($iter) $Enumerable_each_entry$31.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - data = $post_args;; - if ((block !== nil)) { - } else { - return $send(self, 'to_enum', ["each_entry"].concat(Opal.to_a(data)), ($$32 = function(){var self = $$32.$$s || this; + Opal.build_module_singleton_class = function(mod) { + if (mod.$$meta) { + return mod.$$meta; + } - return self.$enumerator_size()}, $$32.$$s = self, $$32.$$arity = 0, $$32)) - }; - - self.$each.$$p = function() { - var item = $$($nesting, 'Opal').$destructure(arguments); + var meta = $allocate_class(null, Opal.Module, true); - Opal.yield1(block, item); - } + $prop(meta, '$$is_singleton', true); + $prop(meta, '$$singleton_of', mod); + set_meta(mod, meta); + // Restoring ModuleName.class + $prop(mod, '$$class', Opal.Module); - self.$each.apply(self, data); + return meta; + }; - return self; - ; - }, $Enumerable_each_entry$31.$$arity = -1); - - Opal.def(self, '$each_slice', $Enumerable_each_slice$33 = function $$each_slice(n) { - var $iter = $Enumerable_each_slice$33.$$p, block = $iter || nil, $$34, self = this; + // Build the singleton class for a Ruby (non class) Object. + // + // @param object [Object] + // @return [Class] + Opal.build_object_singleton_class = function(object) { + var superclass = object.$$class, + klass = $allocate_class(nil, superclass, true); - if ($iter) $Enumerable_each_slice$33.$$p = null; - - - if ($iter) $Enumerable_each_slice$33.$$p = null;; - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); - if ($truthy(n <= 0)) { - self.$raise($$($nesting, 'ArgumentError'), "invalid slice size")}; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["each_slice", n], ($$34 = function(){var self = $$34.$$s || this; + $prop(klass, '$$is_singleton', true); + $prop(klass, '$$singleton_of', object); - if ($truthy(self['$respond_to?']("size"))) { - return $rb_divide(self.$size(), n).$ceil() - } else { - return nil - }}, $$34.$$s = self, $$34.$$arity = 0, $$34)) - }; - - var result, - slice = [] + delete klass.$$prototype.$$class; - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + set_meta(object, klass); - slice.push(param); + return klass; + }; - if (slice.length === n) { - Opal.yield1(block, slice); - slice = []; - } - }; + Opal.is_method = function(prop) { + return (prop[0] === '$' && prop[1] !== '$'); + }; - self.$each(); + Opal.instance_methods = function(mod) { + var exclude = [], results = [], ancestors = $ancestors(mod); - if (result !== undefined) { - return result; - } + for (var i = 0, l = ancestors.length; i < l; i++) { + var ancestor = ancestors[i], + proto = ancestor.$$prototype; - // our "last" group, if smaller than n then won't have been yielded - if (slice.length > 0) { - Opal.yield1(block, slice); + if (proto.hasOwnProperty('$$dummy')) { + proto = proto.$$define_methods_on; } - ; - return nil; - }, $Enumerable_each_slice$33.$$arity = 1); - - Opal.def(self, '$each_with_index', $Enumerable_each_with_index$35 = function $$each_with_index($a) { - var $iter = $Enumerable_each_with_index$35.$$p, block = $iter || nil, $post_args, args, $$36, self = this; - - if ($iter) $Enumerable_each_with_index$35.$$p = null; - - - if ($iter) $Enumerable_each_with_index$35.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["each_with_index"].concat(Opal.to_a(args)), ($$36 = function(){var self = $$36.$$s || this; - - return self.$enumerator_size()}, $$36.$$s = self, $$36.$$arity = 0, $$36)) - }; - - var result, - index = 0; - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + var props = Object.getOwnPropertyNames(proto); - block(param, index); + for (var j = 0, ll = props.length; j < ll; j++) { + var prop = props[j]; - index++; - }; + if (Opal.is_method(prop)) { + var method_name = prop.slice(1), + method = proto[prop]; - self.$each.apply(self, args); + if (method.$$stub && exclude.indexOf(method_name) === -1) { + exclude.push(method_name); + } - if (result !== undefined) { - return result; + if (!method.$$stub && results.indexOf(method_name) === -1 && exclude.indexOf(method_name) === -1) { + results.push(method_name); + } + } } - ; - return self; - }, $Enumerable_each_with_index$35.$$arity = -1); - - Opal.def(self, '$each_with_object', $Enumerable_each_with_object$37 = function $$each_with_object(object) { - var $iter = $Enumerable_each_with_object$37.$$p, block = $iter || nil, $$38, self = this; + } - if ($iter) $Enumerable_each_with_object$37.$$p = null; - - - if ($iter) $Enumerable_each_with_object$37.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["each_with_object", object], ($$38 = function(){var self = $$38.$$s || this; + return results; + }; - return self.$enumerator_size()}, $$38.$$s = self, $$38.$$arity = 0, $$38)) - }; - - var result; + Opal.own_instance_methods = function(mod) { + var results = [], + proto = mod.$$prototype; - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + if (proto.hasOwnProperty('$$dummy')) { + proto = proto.$$define_methods_on; + } - block(param, object); - }; + var props = Object.getOwnPropertyNames(proto); - self.$each(); + for (var i = 0, length = props.length; i < length; i++) { + var prop = props[i]; - if (result !== undefined) { - return result; - } - ; - return object; - }, $Enumerable_each_with_object$37.$$arity = 1); - - Opal.def(self, '$entries', $Enumerable_entries$39 = function $$entries($a) { - var $post_args, args, self = this; + if (Opal.is_method(prop)) { + var method = proto[prop]; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var result = []; + if (!method.$$stub) { + var method_name = prop.slice(1); + results.push(method_name); + } + } + } - self.$each.$$p = function() { - result.push($$($nesting, 'Opal').$destructure(arguments)); - }; + return results; + }; - self.$each.apply(self, args); + Opal.methods = function(obj) { + return Opal.instance_methods(obj.$$meta || obj.$$class); + }; - return result; - ; - }, $Enumerable_entries$39.$$arity = -1); - Opal.alias(self, "find", "detect"); - - Opal.def(self, '$find_all', $Enumerable_find_all$40 = function $$find_all() { - var $iter = $Enumerable_find_all$40.$$p, block = $iter || nil, $$41, self = this; + Opal.own_methods = function(obj) { + return obj.$$meta ? Opal.own_instance_methods(obj.$$meta) : []; + }; - if ($iter) $Enumerable_find_all$40.$$p = null; - - - if ($iter) $Enumerable_find_all$40.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["find_all"], ($$41 = function(){var self = $$41.$$s || this; + Opal.receiver_methods = function(obj) { + var mod = Opal.get_singleton_class(obj); + var singleton_methods = Opal.own_instance_methods(mod); + var instance_methods = Opal.own_instance_methods(mod.$$super); + return singleton_methods.concat(instance_methods); + }; - return self.$enumerator_size()}, $$41.$$s = self, $$41.$$arity = 0, $$41)) - }; - - var result = []; + // Returns an object containing all pairs of names/values + // for all class variables defined in provided +module+ + // and its ancestors. + // + // @param module [Module] + // @return [Object] + Opal.class_variables = function(module) { + var ancestors = $ancestors(module), + i, length = ancestors.length, + result = {}; - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + for (i = length - 1; i >= 0; i--) { + var ancestor = ancestors[i]; - if ($truthy(value)) { - result.push(param); - } - }; + for (var cvar in ancestor.$$cvars) { + result[cvar] = ancestor.$$cvars[cvar]; + } + } - self.$each(); + return result; + }; - return result; - ; - }, $Enumerable_find_all$40.$$arity = 0); - - Opal.def(self, '$find_index', $Enumerable_find_index$42 = function $$find_index(object) {try { + // Sets class variable with specified +name+ to +value+ + // in provided +module+ + // + // @param module [Module] + // @param name [String] + // @param value [Object] + Opal.class_variable_set = function(module, name, value) { + var ancestors = $ancestors(module), + i, length = ancestors.length; - var $iter = $Enumerable_find_index$42.$$p, block = $iter || nil, $$43, $$44, self = this, index = nil; + for (i = length - 2; i >= 0; i--) { + var ancestor = ancestors[i]; - if ($iter) $Enumerable_find_index$42.$$p = null; - - - if ($iter) $Enumerable_find_index$42.$$p = null;; - ; - if ($truthy(object === undefined && block === nil)) { - return self.$enum_for("find_index")}; - - if (object != null && block !== nil) { - self.$warn("warning: given block not used") + if ($has_own(ancestor.$$cvars, name)) { + ancestor.$$cvars[name] = value; + return value; } - ; - index = 0; - if ($truthy(object != null)) { - $send(self, 'each', [], ($$43 = function($a){var self = $$43.$$s || this, $post_args, value; + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($$($nesting, 'Opal').$destructure(value)['$=='](object)) { - Opal.ret(index)}; - return index += 1;;}, $$43.$$s = self, $$43.$$arity = -1, $$43)) - } else { - $send(self, 'each', [], ($$44 = function($a){var self = $$44.$$s || this, $post_args, value; + module.$$cvars[name] = value; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy(Opal.yieldX(block, Opal.to_a(value)))) { - Opal.ret(index)}; - return index += 1;;}, $$44.$$s = self, $$44.$$arity = -1, $$44)) - }; - return nil; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_find_index$42.$$arity = -1); - - Opal.def(self, '$first', $Enumerable_first$45 = function $$first(number) {try { + return value; + }; - var $$46, $$47, self = this, result = nil, current = nil; + // Gets class variable with specified +name+ from provided +module+ + // + // @param module [Module] + // @param name [String] + Opal.class_variable_get = function(module, name, tolerant) { + if ($has_own(module.$$cvars, name)) + return module.$$cvars[name]; - - ; - if ($truthy(number === undefined)) { - return $send(self, 'each', [], ($$46 = function(value){var self = $$46.$$s || this; + var ancestors = $ancestors(module), + i, length = ancestors.length; - - - if (value == null) { - value = nil; - }; - Opal.ret(value);}, $$46.$$s = self, $$46.$$arity = 1, $$46)) - } else { - - result = []; - number = $$($nesting, 'Opal').$coerce_to(number, $$($nesting, 'Integer'), "to_int"); - if ($truthy(number < 0)) { - self.$raise($$($nesting, 'ArgumentError'), "attempt to take negative size")}; - if ($truthy(number == 0)) { - return []}; - current = 0; - $send(self, 'each', [], ($$47 = function($a){var self = $$47.$$s || this, $post_args, args; + for (i = 0; i < length; i++) { + var ancestor = ancestors[i]; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - result.push($$($nesting, 'Opal').$destructure(args)); - if ($truthy(number <= ++current)) { - Opal.ret(result) - } else { - return nil - };}, $$47.$$s = self, $$47.$$arity = -1, $$47)); - return result; - }; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_first$45.$$arity = -1); - Opal.alias(self, "flat_map", "collect_concat"); - - Opal.def(self, '$grep', $Enumerable_grep$48 = function $$grep(pattern) { - var $iter = $Enumerable_grep$48.$$p, block = $iter || nil, $$49, self = this, result = nil; + if ($has_own(ancestor.$$cvars, name)) { + return ancestor.$$cvars[name]; + } + } - if ($iter) $Enumerable_grep$48.$$p = null; - - - if ($iter) $Enumerable_grep$48.$$p = null;; - result = []; - $send(self, 'each', [], ($$49 = function($a){var self = $$49.$$s || this, $post_args, value, cmp = nil; + if (!tolerant) + $raise(Opal.NameError, 'uninitialized class variable '+name+' in '+module.$name()); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - cmp = comparableForPattern(value); - if ($truthy($send(pattern, '__send__', ["==="].concat(Opal.to_a(cmp))))) { - } else { - return nil; - }; - if ((block !== nil)) { - - if ($truthy($rb_gt(value.$length(), 1))) { - value = [value]}; - value = Opal.yieldX(block, Opal.to_a(value)); - } else if ($truthy($rb_le(value.$length(), 1))) { - value = value['$[]'](0)}; - return result.$push(value);}, $$49.$$s = self, $$49.$$arity = -1, $$49)); - return result; - }, $Enumerable_grep$48.$$arity = 1); - - Opal.def(self, '$grep_v', $Enumerable_grep_v$50 = function $$grep_v(pattern) { - var $iter = $Enumerable_grep_v$50.$$p, block = $iter || nil, $$51, self = this, result = nil; + return nil; + }; - if ($iter) $Enumerable_grep_v$50.$$p = null; - - - if ($iter) $Enumerable_grep_v$50.$$p = null;; - result = []; - $send(self, 'each', [], ($$51 = function($a){var self = $$51.$$s || this, $post_args, value, cmp = nil; + function isRoot(proto) { + return proto.hasOwnProperty('$$iclass') && proto.hasOwnProperty('$$root'); + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - cmp = comparableForPattern(value); - if ($truthy($send(pattern, '__send__', ["==="].concat(Opal.to_a(cmp))))) { - return nil;}; - if ((block !== nil)) { - - if ($truthy($rb_gt(value.$length(), 1))) { - value = [value]}; - value = Opal.yieldX(block, Opal.to_a(value)); - } else if ($truthy($rb_le(value.$length(), 1))) { - value = value['$[]'](0)}; - return result.$push(value);}, $$51.$$s = self, $$51.$$arity = -1, $$51)); - return result; - }, $Enumerable_grep_v$50.$$arity = 1); - - Opal.def(self, '$group_by', $Enumerable_group_by$52 = function $$group_by() { - var $iter = $Enumerable_group_by$52.$$p, block = $iter || nil, $$53, $a, self = this, hash = nil, $writer = nil; + function own_included_modules(module) { + var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype); - if ($iter) $Enumerable_group_by$52.$$p = null; - - - if ($iter) $Enumerable_group_by$52.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["group_by"], ($$53 = function(){var self = $$53.$$s || this; + while (proto) { + if (proto.hasOwnProperty('$$class')) { + // superclass + break; + } + mod = protoToModule(proto); + if (mod) { + result.push(mod); + } + proto = Object.getPrototypeOf(proto); + } - return self.$enumerator_size()}, $$53.$$s = self, $$53.$$arity = 0, $$53)) - }; - hash = $hash2([], {}); - - var result; + return result; + } - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + function own_prepended_modules(module) { + var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype); - ($truthy($a = hash['$[]'](value)) ? $a : (($writer = [value, []]), $send(hash, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)]))['$<<'](param); - } + if (module.$$prototype.hasOwnProperty('$$dummy')) { + while (proto) { + if (proto === module.$$prototype.$$define_methods_on) { + break; + } - self.$each(); + mod = protoToModule(proto); + if (mod) { + result.push(mod); + } - if (result !== undefined) { - return result; + proto = Object.getPrototypeOf(proto); } - ; - return hash; - }, $Enumerable_group_by$52.$$arity = 0); - - Opal.def(self, '$include?', $Enumerable_include$ques$54 = function(obj) {try { + } - var $$55, self = this; + return result; + } - - $send(self, 'each', [], ($$55 = function($a){var self = $$55.$$s || this, $post_args, args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($$($nesting, 'Opal').$destructure(args)['$=='](obj)) { - Opal.ret(true) - } else { - return nil - };}, $$55.$$s = self, $$55.$$arity = -1, $$55)); - return false; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_include$ques$54.$$arity = 1); - - Opal.def(self, '$inject', $Enumerable_inject$56 = function $$inject(object, sym) { - var $iter = $Enumerable_inject$56.$$p, block = $iter || nil, self = this; + // The actual inclusion of a module into a class. + // + // ## Class `$$parent` and `iclass` + // + // To handle `super` calls, every class has a `$$parent`. This parent is + // used to resolve the next class for a super call. A normal class would + // have this point to its superclass. However, if a class includes a module + // then this would need to take into account the module. The module would + // also have to then point its `$$parent` to the actual superclass. We + // cannot modify modules like this, because it might be included in more + // then one class. To fix this, we actually insert an `iclass` as the class' + // `$$parent` which can then point to the superclass. The `iclass` acts as + // a proxy to the actual module, so the `super` chain can then search it for + // the required method. + // + // @param module [Module] the module to include + // @param includer [Module] the target class to include module into + // @return [null] + Opal.append_features = function(module, includer) { + var module_ancestors = $ancestors(module); + var iclasses = []; - if ($iter) $Enumerable_inject$56.$$p = null; - - - if ($iter) $Enumerable_inject$56.$$p = null;; - ; - ; - - var result = object; + if (module_ancestors.indexOf(includer) !== -1) { + $raise(Opal.ArgumentError, 'cyclic include detected'); + } - if (block !== nil && sym === undefined) { - self.$each.$$p = function() { - var value = $$($nesting, 'Opal').$destructure(arguments); + for (var i = 0, length = module_ancestors.length; i < length; i++) { + var ancestor = module_ancestors[i], iclass = create_iclass(ancestor); + $prop(iclass, '$$included', true); + iclasses.push(iclass); + } + var includer_ancestors = $ancestors(includer), + chain = chain_iclasses(iclasses), + start_chain_after, + end_chain_on; - if (result === undefined) { - result = value; - return; - } + if (includer_ancestors.indexOf(module) === -1) { + // first time include - value = Opal.yieldX(block, [result, value]); + // includer -> chain.first -> ...chain... -> chain.last -> includer.parent + start_chain_after = includer.$$prototype; + end_chain_on = Object.getPrototypeOf(includer.$$prototype); + } else { + // The module has been already included, + // we don't need to put it into the ancestors chain again, + // but this module may have new included modules. + // If it's true we need to copy them. + // + // The simplest way is to replace ancestors chain from + // parent + // | + // `module` iclass (has a $$root flag) + // | + // ...previos chain of module.included_modules ... + // | + // "next ancestor" (has a $$root flag or is a real class) + // + // to + // parent + // | + // `module` iclass (has a $$root flag) + // | + // ...regenerated chain of module.included_modules + // | + // "next ancestor" (has a $$root flag or is a real class) + // + // because there are no intermediate classes between `parent` and `next ancestor`. + // It doesn't break any prototypes of other objects as we don't change class references. - result = value; - }; - } - else { - if (sym === undefined) { - if (!$$($nesting, 'Symbol')['$==='](object)) { - self.$raise($$($nesting, 'TypeError'), "" + (object.$inspect()) + " is not a Symbol"); - } + var parent = includer.$$prototype, module_iclass = Object.getPrototypeOf(parent); - sym = object; - result = undefined; + while (module_iclass != null) { + if (module_iclass.$$module === module && isRoot(module_iclass)) { + break; } - self.$each.$$p = function() { - var value = $$($nesting, 'Opal').$destructure(arguments); + parent = module_iclass; + module_iclass = Object.getPrototypeOf(module_iclass); + } - if (result === undefined) { - result = value; - return; - } + if (module_iclass) { + // module has been directly included + var next_ancestor = Object.getPrototypeOf(module_iclass); - result = (result).$__send__(sym, value); - }; + // skip non-root iclasses (that were recursively included) + while (next_ancestor.hasOwnProperty('$$iclass') && !isRoot(next_ancestor)) { + next_ancestor = Object.getPrototypeOf(next_ancestor); + } + + start_chain_after = parent; + end_chain_on = next_ancestor; + } else { + // module has not been directly included but was in ancestor chain because it was included by another module + // include it directly + start_chain_after = includer.$$prototype; + end_chain_on = Object.getPrototypeOf(includer.$$prototype); } + } - self.$each(); + $set_proto(start_chain_after, chain.first); + $set_proto(chain.last, end_chain_on); - return result == undefined ? nil : result; - ; - }, $Enumerable_inject$56.$$arity = -1); - - Opal.def(self, '$lazy', $Enumerable_lazy$57 = function $$lazy() { - var $$58, self = this; + // recalculate own_included_modules cache + includer.$$own_included_modules = own_included_modules(includer); - return $send($$$($$($nesting, 'Enumerator'), 'Lazy'), 'new', [self, self.$enumerator_size()], ($$58 = function(enum$, $a){var self = $$58.$$s || this, $post_args, args; + Opal.const_cache_version++; + }; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - return $send(enum$, 'yield', Opal.to_a(args));}, $$58.$$s = self, $$58.$$arity = -2, $$58)) - }, $Enumerable_lazy$57.$$arity = 0); - - Opal.def(self, '$enumerator_size', $Enumerable_enumerator_size$59 = function $$enumerator_size() { - var self = this; + Opal.prepend_features = function(module, prepender) { + // Here we change the ancestors chain from + // + // prepender + // | + // parent + // + // to: + // + // dummy(prepender) + // | + // iclass(module) + // | + // iclass(prepender) + // | + // parent + var module_ancestors = $ancestors(module); + var iclasses = []; - if ($truthy(self['$respond_to?']("size"))) { - return self.$size() - } else { - return nil - } - }, $Enumerable_enumerator_size$59.$$arity = 0); - Opal.alias(self, "map", "collect"); - - Opal.def(self, '$max', $Enumerable_max$60 = function $$max(n) { - var $iter = $Enumerable_max$60.$$p, block = $iter || nil, self = this; + if (module_ancestors.indexOf(prepender) !== -1) { + $raise(Opal.ArgumentError, 'cyclic prepend detected'); + } - if ($iter) $Enumerable_max$60.$$p = null; - - - if ($iter) $Enumerable_max$60.$$p = null;; - ; - - if (n === undefined || n === nil) { - var result, value; + for (var i = 0, length = module_ancestors.length; i < length; i++) { + var ancestor = module_ancestors[i], iclass = create_iclass(ancestor); + $prop(iclass, '$$prepended', true); + iclasses.push(iclass); + } - self.$each.$$p = function() { - var item = $$($nesting, 'Opal').$destructure(arguments); + var chain = chain_iclasses(iclasses), + dummy_prepender = prepender.$$prototype, + previous_parent = Object.getPrototypeOf(dummy_prepender), + prepender_iclass, + start_chain_after, + end_chain_on; - if (result === undefined) { - result = item; - return; - } + if (dummy_prepender.hasOwnProperty('$$dummy')) { + // The module already has some prepended modules + // which means that we don't need to make it "dummy" + prepender_iclass = dummy_prepender.$$define_methods_on; + } else { + // Making the module "dummy" + prepender_iclass = create_dummy_iclass(prepender); + flush_methods_in(prepender); + $prop(dummy_prepender, '$$dummy', true); + $prop(dummy_prepender, '$$define_methods_on', prepender_iclass); - if (block !== nil) { - value = Opal.yieldX(block, [item, result]); - } else { - value = (item)['$<=>'](result); - } + // Converting + // dummy(prepender) -> previous_parent + // to + // dummy(prepender) -> iclass(prepender) -> previous_parent + $set_proto(dummy_prepender, prepender_iclass); + $set_proto(prepender_iclass, previous_parent); + } - if (value === nil) { - self.$raise($$($nesting, 'ArgumentError'), "comparison failed"); - } + var prepender_ancestors = $ancestors(prepender); - if (value > 0) { - result = item; - } - } + if (prepender_ancestors.indexOf(module) === -1) { + // first time prepend - self.$each(); + start_chain_after = dummy_prepender; - if (result === undefined) { - return nil; - } else { - return result; + // next $$root or prepender_iclass or non-$$iclass + end_chain_on = Object.getPrototypeOf(dummy_prepender); + while (end_chain_on != null) { + if ( + end_chain_on.hasOwnProperty('$$root') || + end_chain_on === prepender_iclass || + !end_chain_on.hasOwnProperty('$$iclass') + ) { + break; } + + end_chain_on = Object.getPrototypeOf(end_chain_on); } - ; - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); - return $send(self, 'sort', [], block.$to_proc()).$reverse().$first(n); - }, $Enumerable_max$60.$$arity = -1); - - Opal.def(self, '$max_by', $Enumerable_max_by$61 = function $$max_by() { - var $iter = $Enumerable_max_by$61.$$p, block = $iter || nil, $$62, self = this; + } else { + $raise(Opal.RuntimeError, "Prepending a module multiple times is not supported"); + } - if ($iter) $Enumerable_max_by$61.$$p = null; - - - if ($iter) $Enumerable_max_by$61.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["max_by"], ($$62 = function(){var self = $$62.$$s || this; + $set_proto(start_chain_after, chain.first); + $set_proto(chain.last, end_chain_on); - return self.$enumerator_size()}, $$62.$$s = self, $$62.$$arity = 0, $$62)) - }; - - var result, - by; + // recalculate own_prepended_modules cache + prepender.$$own_prepended_modules = own_prepended_modules(prepender); - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + Opal.const_cache_version++; + }; - if (result === undefined) { - result = param; - by = value; - return; - } + function flush_methods_in(module) { + var proto = module.$$prototype, + props = Object.getOwnPropertyNames(proto); - if ((value)['$<=>'](by) > 0) { - result = param - by = value; - } - }; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (Opal.is_method(prop)) { + delete proto[prop]; + } + } + } - self.$each(); + function create_iclass(module) { + var iclass = create_dummy_iclass(module); - return result === undefined ? nil : result; - ; - }, $Enumerable_max_by$61.$$arity = 0); - Opal.alias(self, "member?", "include?"); - - Opal.def(self, '$min', $Enumerable_min$63 = function $$min() { - var $iter = $Enumerable_min$63.$$p, block = $iter || nil, self = this; + if (module.$$is_module) { + module.$$iclasses.push(iclass); + } - if ($iter) $Enumerable_min$63.$$p = null; - - - if ($iter) $Enumerable_min$63.$$p = null;; - - var result; + return iclass; + } - if (block !== nil) { - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + // Dummy iclass doesn't receive updates when the module gets a new method. + function create_dummy_iclass(module) { + var iclass = {}, + proto = module.$$prototype; - if (result === undefined) { - result = param; - return; - } + if (proto.hasOwnProperty('$$dummy')) { + proto = proto.$$define_methods_on; + } - var value = block(param, result); + var props = Object.getOwnPropertyNames(proto), + length = props.length, i; - if (value === nil) { - self.$raise($$($nesting, 'ArgumentError'), "comparison failed"); - } + for (i = 0; i < length; i++) { + var prop = props[i]; + $prop(iclass, prop, proto[prop]); + } - if (value < 0) { - result = param; - } - }; - } - else { - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments); + $prop(iclass, '$$iclass', true); + $prop(iclass, '$$module', module); - if (result === undefined) { - result = param; - return; - } + return iclass; + } - if ($$($nesting, 'Opal').$compare(param, result) < 0) { - result = param; - } - }; - } + function chain_iclasses(iclasses) { + var length = iclasses.length, first = iclasses[0]; - self.$each(); + $prop(first, '$$root', true); - return result === undefined ? nil : result; - ; - }, $Enumerable_min$63.$$arity = 0); - - Opal.def(self, '$min_by', $Enumerable_min_by$64 = function $$min_by() { - var $iter = $Enumerable_min_by$64.$$p, block = $iter || nil, $$65, self = this; + if (length === 1) { + return { first: first, last: first }; + } - if ($iter) $Enumerable_min_by$64.$$p = null; - - - if ($iter) $Enumerable_min_by$64.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["min_by"], ($$65 = function(){var self = $$65.$$s || this; + var previous = first; - return self.$enumerator_size()}, $$65.$$s = self, $$65.$$arity = 0, $$65)) - }; - - var result, - by; + for (var i = 1; i < length; i++) { + var current = iclasses[i]; + $set_proto(previous, current); + previous = current; + } - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); - if (result === undefined) { - result = param; - by = value; - return; - } + return { first: iclasses[0], last: iclasses[length - 1] }; + } - if ((value)['$<=>'](by) < 0) { - result = param - by = value; - } - }; + // For performance, some core Ruby classes are toll-free bridged to their + // native JavaScript counterparts (e.g. a Ruby Array is a JavaScript Array). + // + // This method is used to setup a native constructor (e.g. Array), to have + // its prototype act like a normal Ruby class. Firstly, a new Ruby class is + // created using the native constructor so that its prototype is set as the + // target for the new class. Note: all bridged classes are set to inherit + // from Object. + // + // Example: + // + // Opal.bridge(self, Function); + // + // @param klass [Class] the Ruby class to bridge + // @param constructor [JS.Function] native JavaScript constructor to use + // @return [Class] returns the passed Ruby class + // + Opal.bridge = function(native_klass, klass) { + if (native_klass.hasOwnProperty('$$bridge')) { + $raise(Opal.ArgumentError, "already bridged"); + } - self.$each(); + // constructor is a JS function with a prototype chain like: + // - constructor + // - super + // + // What we need to do is to inject our class (with its prototype chain) + // between constructor and super. For example, after injecting ::Object + // into JS String we get: + // + // - constructor (window.String) + // - Opal.Object + // - Opal.Kernel + // - Opal.BasicObject + // - super (window.Object) + // - null + // + $prop(native_klass, '$$bridge', klass); + $set_proto(native_klass.prototype, (klass.$$super || Opal.Object).$$prototype); + $prop(klass, '$$prototype', native_klass.prototype); - return result === undefined ? nil : result; - ; - }, $Enumerable_min_by$64.$$arity = 0); - - Opal.def(self, '$minmax', $Enumerable_minmax$66 = function $$minmax() { - var $iter = $Enumerable_minmax$66.$$p, block = $iter || nil, $a, $$67, self = this; + $prop(klass.$$prototype, '$$class', klass); + $prop(klass, '$$constructor', native_klass); + $prop(klass, '$$bridge', true); + }; - if ($iter) $Enumerable_minmax$66.$$p = null; - - - if ($iter) $Enumerable_minmax$66.$$p = null;; - block = ($truthy($a = block) ? $a : $send(self, 'proc', [], ($$67 = function(a, b){var self = $$67.$$s || this; + function protoToModule(proto) { + if (proto.hasOwnProperty('$$dummy')) { + return; + } else if (proto.hasOwnProperty('$$iclass')) { + return proto.$$module; + } else if (proto.hasOwnProperty('$$class')) { + return proto.$$class; + } + } - - - if (a == null) { - a = nil; - }; - - if (b == null) { - b = nil; - }; - return a['$<=>'](b);}, $$67.$$s = self, $$67.$$arity = 2, $$67))); - - var min = nil, max = nil, first_time = true; + function own_ancestors(module) { + return module.$$own_prepended_modules.concat([module]).concat(module.$$own_included_modules); + } - self.$each.$$p = function() { - var element = $$($nesting, 'Opal').$destructure(arguments); - if (first_time) { - min = max = element; - first_time = false; - } else { - var min_cmp = block.$call(min, element); + // The Array of ancestors for a given module/class + function $ancestors(module) { + if (!module) { return []; } - if (min_cmp === nil) { - self.$raise($$($nesting, 'ArgumentError'), "comparison failed") - } else if (min_cmp > 0) { - min = element; - } + if (module.$$ancestors_cache_version === Opal.const_cache_version) { + return module.$$ancestors; + } - var max_cmp = block.$call(max, element); + var result = [], i, mods, length; - if (max_cmp === nil) { - self.$raise($$($nesting, 'ArgumentError'), "comparison failed") - } else if (max_cmp < 0) { - max = element; - } - } - } + for (i = 0, mods = own_ancestors(module), length = mods.length; i < length; i++) { + result.push(mods[i]); + } - self.$each(); + if (module.$$super) { + for (i = 0, mods = $ancestors(module.$$super), length = mods.length; i < length; i++) { + result.push(mods[i]); + } + } - return [min, max]; - ; - }, $Enumerable_minmax$66.$$arity = 0); - - Opal.def(self, '$minmax_by', $Enumerable_minmax_by$68 = function $$minmax_by() { - var $iter = $Enumerable_minmax_by$68.$$p, block = $iter || nil, self = this; + module.$$ancestors_cache_version = Opal.const_cache_version; + module.$$ancestors = result; - if ($iter) $Enumerable_minmax_by$68.$$p = null; - - - if ($iter) $Enumerable_minmax_by$68.$$p = null;; - return self.$raise($$($nesting, 'NotImplementedError')); - }, $Enumerable_minmax_by$68.$$arity = 0); - - Opal.def(self, '$none?', $Enumerable_none$ques$69 = function(pattern) {try { + return result; + } Opal.ancestors = $ancestors; - var $iter = $Enumerable_none$ques$69.$$p, block = $iter || nil, $$70, $$71, $$72, self = this; + Opal.included_modules = function(module) { + var result = [], mod = null, proto = Object.getPrototypeOf(module.$$prototype); - if ($iter) $Enumerable_none$ques$69.$$p = null; - - - if ($iter) $Enumerable_none$ques$69.$$p = null;; - ; - if ($truthy(pattern !== undefined)) { - $send(self, 'each', [], ($$70 = function($a){var self = $$70.$$s || this, $post_args, value, comparable = nil; + for (; proto && Object.getPrototypeOf(proto); proto = Object.getPrototypeOf(proto)) { + mod = protoToModule(proto); + if (mod && mod.$$is_module && proto.$$iclass && proto.$$included) { + result.push(mod); + } + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - comparable = comparableForPattern(value); - if ($truthy($send(pattern, 'public_send', ["==="].concat(Opal.to_a(comparable))))) { - Opal.ret(false) - } else { - return nil - };}, $$70.$$s = self, $$70.$$arity = -1, $$70)) - } else if ((block !== nil)) { - $send(self, 'each', [], ($$71 = function($a){var self = $$71.$$s || this, $post_args, value; + return result; + }; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy(Opal.yieldX(block, Opal.to_a(value)))) { - Opal.ret(false) - } else { - return nil - };}, $$71.$$s = self, $$71.$$arity = -1, $$71)) - } else { - $send(self, 'each', [], ($$72 = function($a){var self = $$72.$$s || this, $post_args, value, item = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - item = $$($nesting, 'Opal').$destructure(value); - if ($truthy(item)) { - Opal.ret(false) - } else { - return nil - };}, $$72.$$s = self, $$72.$$arity = -1, $$72)) - }; - return true; - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_none$ques$69.$$arity = -1); - - Opal.def(self, '$one?', $Enumerable_one$ques$73 = function(pattern) {try { + // Method Missing + // -------------- - var $iter = $Enumerable_one$ques$73.$$p, block = $iter || nil, $$74, $$75, $$76, self = this, count = nil; + // Methods stubs are used to facilitate method_missing in opal. A stub is a + // placeholder function which just calls `method_missing` on the receiver. + // If no method with the given name is actually defined on an object, then it + // is obvious to say that the stub will be called instead, and then in turn + // method_missing will be called. + // + // When a file in ruby gets compiled to javascript, it includes a call to + // this function which adds stubs for every method name in the compiled file. + // It should then be safe to assume that method_missing will work for any + // method call detected. + // + // Method stubs are added to the BasicObject prototype, which every other + // ruby object inherits, so all objects should handle method missing. A stub + // is only added if the given property name (method name) is not already + // defined. + // + // Note: all ruby methods have a `$` prefix in javascript, so all stubs will + // have this prefix as well (to make this method more performant). + // + // Opal.add_stubs("foo,bar,baz="); + // + // All stub functions will have a private `$$stub` property set to true so + // that other internal methods can detect if a method is just a stub or not. + // `Kernel#respond_to?` uses this property to detect a methods presence. + // + // @param stubs [Array] an array of method stubs to add + // @return [undefined] + Opal.add_stubs = function(stubs) { + var proto = Opal.BasicObject.$$prototype; + var stub, existing_method; + stubs = stubs.split(','); - if ($iter) $Enumerable_one$ques$73.$$p = null; - - - if ($iter) $Enumerable_one$ques$73.$$p = null;; - ; - count = 0; - if ($truthy(pattern !== undefined)) { - $send(self, 'each', [], ($$74 = function($a){var self = $$74.$$s || this, $post_args, value, comparable = nil; + for (var i = 0, length = stubs.length; i < length; i++) { + stub = $jsid(stubs[i]), existing_method = proto[stub]; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - comparable = comparableForPattern(value); - if ($truthy($send(pattern, 'public_send', ["==="].concat(Opal.to_a(comparable))))) { - - count = $rb_plus(count, 1); - if ($truthy($rb_gt(count, 1))) { - Opal.ret(false) - } else { - return nil - }; - } else { - return nil - };}, $$74.$$s = self, $$74.$$arity = -1, $$74)) - } else if ((block !== nil)) { - $send(self, 'each', [], ($$75 = function($a){var self = $$75.$$s || this, $post_args, value; + if (existing_method == null || existing_method.$$stub) { + Opal.add_stub_for(proto, stub); + } + } + }; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy(Opal.yieldX(block, Opal.to_a(value)))) { - } else { - return nil; - }; - count = $rb_plus(count, 1); - if ($truthy($rb_gt(count, 1))) { - Opal.ret(false) - } else { - return nil - };}, $$75.$$s = self, $$75.$$arity = -1, $$75)) - } else { - $send(self, 'each', [], ($$76 = function($a){var self = $$76.$$s || this, $post_args, value; + // Add a method_missing stub function to the given prototype for the + // given name. + // + // @param prototype [Prototype] the target prototype + // @param stub [String] stub name to add (e.g. "$foo") + // @return [undefined] + Opal.add_stub_for = function(prototype, stub) { + // Opal.stub_for(stub) is the method_missing_stub + $prop(prototype, stub, Opal.stub_for(stub)); + }; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - value = $post_args;; - if ($truthy($$($nesting, 'Opal').$destructure(value))) { - } else { - return nil; - }; - count = $rb_plus(count, 1); - if ($truthy($rb_gt(count, 1))) { - Opal.ret(false) - } else { - return nil - };}, $$76.$$s = self, $$76.$$arity = -1, $$76)) - }; - return count['$=='](1); - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_one$ques$73.$$arity = -1); - - Opal.def(self, '$partition', $Enumerable_partition$77 = function $$partition() { - var $iter = $Enumerable_partition$77.$$p, block = $iter || nil, $$78, self = this; + // Generate the method_missing stub for a given method name. + // + // @param method_name [String] The js-name of the method to stub (e.g. "$foo") + // @return [undefined] + Opal.stub_for = function(method_name) { - if ($iter) $Enumerable_partition$77.$$p = null; - - - if ($iter) $Enumerable_partition$77.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["partition"], ($$78 = function(){var self = $$78.$$s || this; + function method_missing_stub() { + // Copy any given block onto the method_missing dispatcher + this.$method_missing.$$p = method_missing_stub.$$p; - return self.$enumerator_size()}, $$78.$$s = self, $$78.$$arity = 0, $$78)) - }; - - var truthy = [], falsy = [], result; + // Set block property to null ready for the next call (stop false-positives) + method_missing_stub.$$p = null; - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + // call method missing with correct args (remove '$' prefix on method name) + var args_ary = new Array(arguments.length); + for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i]; } - if ($truthy(value)) { - truthy.push(param); - } - else { - falsy.push(param); - } - }; + return this.$method_missing.apply(this, [method_name.slice(1)].concat(args_ary)); + } - self.$each(); + method_missing_stub.$$stub = true; - return [truthy, falsy]; - ; - }, $Enumerable_partition$77.$$arity = 0); - Opal.alias(self, "reduce", "inject"); - - Opal.def(self, '$reject', $Enumerable_reject$79 = function $$reject() { - var $iter = $Enumerable_reject$79.$$p, block = $iter || nil, $$80, self = this; + return method_missing_stub; + }; - if ($iter) $Enumerable_reject$79.$$p = null; - - - if ($iter) $Enumerable_reject$79.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["reject"], ($$80 = function(){var self = $$80.$$s || this; - return self.$enumerator_size()}, $$80.$$s = self, $$80.$$arity = 0, $$80)) - }; - - var result = []; + // Methods + // ------- - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + // Arity count error dispatcher for methods + // + // @param actual [Fixnum] number of arguments given to method + // @param expected [Fixnum] expected number of arguments + // @param object [Object] owner of the method +meth+ + // @param meth [String] method name that got wrong number of arguments + // @raise [ArgumentError] + Opal.ac = function(actual, expected, object, meth) { + var inspect = ''; + if (object.$$is_a_module) { + inspect += object.$$name + '.'; + } + else { + inspect += object.$$class.$$name + '#'; + } + inspect += meth; - if ($falsy(value)) { - result.push(param); - } - }; + $raise(Opal.ArgumentError, '[' + inspect + '] wrong number of arguments (given ' + actual + ', expected ' + expected + ')'); + }; - self.$each(); + // Arity count error dispatcher for blocks + // + // @param actual [Fixnum] number of arguments given to block + // @param expected [Fixnum] expected number of arguments + // @param context [Object] context of the block definition + // @raise [ArgumentError] + Opal.block_ac = function(actual, expected, context) { + var inspect = "`block in " + context + "'"; - return result; - ; - }, $Enumerable_reject$79.$$arity = 0); - - Opal.def(self, '$reverse_each', $Enumerable_reverse_each$81 = function $$reverse_each() { - var $iter = $Enumerable_reverse_each$81.$$p, block = $iter || nil, $$82, self = this; + $raise(Opal.ArgumentError, inspect + ': wrong number of arguments (given ' + actual + ', expected ' + expected + ')'); + }; - if ($iter) $Enumerable_reverse_each$81.$$p = null; - - - if ($iter) $Enumerable_reverse_each$81.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["reverse_each"], ($$82 = function(){var self = $$82.$$s || this; + function get_ancestors(obj) { + if (obj.hasOwnProperty('$$meta') && obj.$$meta !== null) { + return $ancestors(obj.$$meta); + } else { + return $ancestors(obj.$$class); + } + } + // Super dispatcher + Opal.find_super = function(obj, mid, current_func, defcheck, allow_stubs) { + var jsid = $jsid(mid), ancestors, super_method; - return self.$enumerator_size()}, $$82.$$s = self, $$82.$$arity = 0, $$82)) - }; - - var result = []; + ancestors = get_ancestors(obj); - self.$each.$$p = function() { - result.push(arguments); - }; + var current_index = ancestors.indexOf(current_func.$$owner); - self.$each(); + for (var i = current_index + 1; i < ancestors.length; i++) { + var ancestor = ancestors[i], + proto = ancestor.$$prototype; - for (var i = result.length - 1; i >= 0; i--) { - Opal.yieldX(block, result[i]); + if (proto.hasOwnProperty('$$dummy')) { + proto = proto.$$define_methods_on; } - return result; - ; - }, $Enumerable_reverse_each$81.$$arity = 0); - Opal.alias(self, "select", "find_all"); - - Opal.def(self, '$slice_before', $Enumerable_slice_before$83 = function $$slice_before(pattern) { - var $iter = $Enumerable_slice_before$83.$$p, block = $iter || nil, $$84, self = this; + if (proto.hasOwnProperty(jsid)) { + super_method = proto[jsid]; + break; + } + } - if ($iter) $Enumerable_slice_before$83.$$p = null; - - - if ($iter) $Enumerable_slice_before$83.$$p = null;; - ; - if ($truthy(pattern === undefined && block === nil)) { - self.$raise($$($nesting, 'ArgumentError'), "both pattern and block are given")}; - if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arguments.length) + " expected 1)")}; - return $send($$($nesting, 'Enumerator'), 'new', [], ($$84 = function(e){var self = $$84.$$s || this; + if (!defcheck && super_method && super_method.$$stub && obj.$method_missing.$$pristine) { + // method_missing hasn't been explicitly defined + $raise(Opal.NoMethodError, 'super: no superclass method `'+mid+"' for "+obj, mid); + } - - - if (e == null) { - e = nil; - }; - - var slice = []; + return (super_method.$$stub && !allow_stubs) ? null : super_method; + }; - if (block !== nil) { - if (pattern === undefined) { - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = Opal.yield1(block, param); + // Iter dispatcher for super in a block + Opal.find_block_super = function(obj, jsid, current_func, defcheck, implicit) { + var call_jsid = jsid; - if ($truthy(value) && slice.length > 0) { - e['$<<'](slice); - slice = []; - } + if (!current_func) { + $raise(Opal.RuntimeError, "super called outside of method"); + } - slice.push(param); - }; - } - else { - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = block(param, pattern.$dup()); + if (implicit && current_func.$$define_meth) { + $raise(Opal.RuntimeError, + "implicit argument passing of super from method defined by define_method() is not supported. " + + "Specify all arguments explicitly" + ); + } - if ($truthy(value) && slice.length > 0) { - e['$<<'](slice); - slice = []; - } + if (current_func.$$def) { + call_jsid = current_func.$$jsid; + } - slice.push(param); - }; - } - } - else { - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = pattern['$==='](param); + return Opal.find_super(obj, call_jsid, current_func, defcheck); + }; - if ($truthy(value) && slice.length > 0) { - e['$<<'](slice); - slice = []; - } + // @deprecated + Opal.find_super_dispatcher = Opal.find_super; - slice.push(param); - }; - } + // @deprecated + Opal.find_iter_super_dispatcher = Opal.find_block_super; - self.$each(); + // handles yield calls for 1 yielded arg + Opal.yield1 = function(block, arg) { + if (typeof(block) !== "function") { + $raise(Opal.LocalJumpError, "no block given"); + } - if (slice.length > 0) { - e['$<<'](slice); - } - ;}, $$84.$$s = self, $$84.$$arity = 1, $$84)); - }, $Enumerable_slice_before$83.$$arity = -1); - - Opal.def(self, '$slice_after', $Enumerable_slice_after$85 = function $$slice_after(pattern) { - var $iter = $Enumerable_slice_after$85.$$p, block = $iter || nil, $$86, $$87, self = this; + var has_mlhs = block.$$has_top_level_mlhs_arg, + has_trailing_comma = block.$$has_trailing_comma_in_args; - if ($iter) $Enumerable_slice_after$85.$$p = null; - - - if ($iter) $Enumerable_slice_after$85.$$p = null;; - ; - if ($truthy(pattern === undefined && block === nil)) { - self.$raise($$($nesting, 'ArgumentError'), "both pattern and block are given")}; - if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arguments.length) + " expected 1)")}; - if ($truthy(pattern !== undefined)) { - block = $send(self, 'proc', [], ($$86 = function(e){var self = $$86.$$s || this; + if (block.length > 1 || ((has_mlhs || has_trailing_comma) && block.length === 1)) { + arg = Opal.to_ary(arg); + } - - - if (e == null) { - e = nil; - }; - return pattern['$==='](e);}, $$86.$$s = self, $$86.$$arity = 1, $$86))}; - return $send($$($nesting, 'Enumerator'), 'new', [], ($$87 = function(yielder){var self = $$87.$$s || this; + if ((block.length > 1 || (has_trailing_comma && block.length === 1)) && arg.$$is_array) { + return block.apply(null, arg); + } + else { + return block(arg); + } + }; - - - if (yielder == null) { - yielder = nil; - }; - - var accumulate; + // handles yield for > 1 yielded arg + Opal.yieldX = function(block, args) { + if (typeof(block) !== "function") { + $raise(Opal.LocalJumpError, "no block given"); + } - self.$each.$$p = function() { - var element = $$($nesting, 'Opal').$destructure(arguments), - end_chunk = Opal.yield1(block, element); + if (block.length > 1 && args.length === 1) { + if (args[0].$$is_array) { + return block.apply(null, args[0]); + } + } - if (accumulate == null) { - accumulate = []; - } + if (!args.$$is_array) { + var args_ary = new Array(args.length); + for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; } - if ($truthy(end_chunk)) { - accumulate.push(element); - yielder.$yield(accumulate); - accumulate = null; - } else { - accumulate.push(element) - } - } + return block.apply(null, args_ary); + } - self.$each(); + return block.apply(null, args); + }; - if (accumulate != null) { - yielder.$yield(accumulate); - } - ;}, $$87.$$s = self, $$87.$$arity = 1, $$87)); - }, $Enumerable_slice_after$85.$$arity = -1); - - Opal.def(self, '$slice_when', $Enumerable_slice_when$88 = function $$slice_when() { - var $iter = $Enumerable_slice_when$88.$$p, block = $iter || nil, $$89, self = this; + // Finds the corresponding exception match in candidates. Each candidate can + // be a value, or an array of values. Returns null if not found. + Opal.rescue = function(exception, candidates) { + for (var i = 0; i < candidates.length; i++) { + var candidate = candidates[i]; - if ($iter) $Enumerable_slice_when$88.$$p = null; - - - if ($iter) $Enumerable_slice_when$88.$$p = null;; - if ((block !== nil)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (0 for 1)") - }; - return $send($$($nesting, 'Enumerator'), 'new', [], ($$89 = function(yielder){var self = $$89.$$s || this; + if (candidate.$$is_array) { + var result = Opal.rescue(exception, candidate); - - - if (yielder == null) { - yielder = nil; - }; - - var slice = nil, last_after = nil; + if (result) { + return result; + } + } + else if (candidate === Opal.JS.Error || candidate['$==='](exception)) { + return candidate; + } + } - self.$each_cons.$$p = function() { - var params = $$($nesting, 'Opal').$destructure(arguments), - before = params[0], - after = params[1], - match = Opal.yieldX(block, [before, after]); + return null; + }; - last_after = after; + Opal.is_a = function(object, klass) { + if (klass != null && object.$$meta === klass || object.$$class === klass) { + return true; + } - if (slice === nil) { - slice = []; - } + if (object.$$is_number && klass.$$is_number_class) { + return (klass.$$is_integer_class) ? (object % 1) === 0 : true; + } - if ($truthy(match)) { - slice.push(before); - yielder.$yield(slice); - slice = []; - } else { - slice.push(before); - } - } + var ancestors = $ancestors(object.$$is_class ? Opal.get_singleton_class(object) : (object.$$meta || object.$$class)); - self.$each_cons(2); + return ancestors.indexOf(klass) !== -1; + }; - if (slice !== nil) { - slice.push(last_after); - yielder.$yield(slice); - } - ;}, $$89.$$s = self, $$89.$$arity = 1, $$89)); - }, $Enumerable_slice_when$88.$$arity = 0); - - Opal.def(self, '$sort', $Enumerable_sort$90 = function $$sort() { - var $iter = $Enumerable_sort$90.$$p, block = $iter || nil, $$91, self = this, ary = nil; + // Helpers for extracting kwsplats + // Used for: { **h } + Opal.to_hash = function(value) { + if (value.$$is_hash) { + return value; + } + else if (value['$respond_to?']('to_hash', true)) { + var hash = value.$to_hash(); + if (hash.$$is_hash) { + return hash; + } + else { + $raise(Opal.TypeError, "Can't convert " + value.$$class + + " to Hash (" + value.$$class + "#to_hash gives " + hash.$$class + ")"); + } + } + else { + $raise(Opal.TypeError, "no implicit conversion of " + value.$$class + " into Hash"); + } + }; - if ($iter) $Enumerable_sort$90.$$p = null; - - - if ($iter) $Enumerable_sort$90.$$p = null;; - ary = self.$to_a(); - if ((block !== nil)) { - } else { - block = $lambda(($$91 = function(a, b){var self = $$91.$$s || this; + // Helpers for implementing multiple assignment + // Our code for extracting the values and assigning them only works if the + // return value is a JS array. + // So if we get an Array subclass, extract the wrapped JS array from it - - - if (a == null) { - a = nil; - }; - - if (b == null) { - b = nil; - }; - return a['$<=>'](b);}, $$91.$$s = self, $$91.$$arity = 2, $$91)) - }; - return $send(ary, 'sort', [], block.$to_proc()); - }, $Enumerable_sort$90.$$arity = 0); - - Opal.def(self, '$sort_by', $Enumerable_sort_by$92 = function $$sort_by() { - var $iter = $Enumerable_sort_by$92.$$p, block = $iter || nil, $$93, $$94, $$95, $$96, self = this, dup = nil; + // Used for: a, b = something (no splat) + Opal.to_ary = function(value) { + if (value.$$is_array) { + return value; + } + else if (value['$respond_to?']('to_ary', true)) { + var ary = value.$to_ary(); + if (ary === nil) { + return [value]; + } + else if (ary.$$is_array) { + return ary; + } + else { + $raise(Opal.TypeError, "Can't convert " + value.$$class + + " to Array (" + value.$$class + "#to_ary gives " + ary.$$class + ")"); + } + } + else { + return [value]; + } + }; - if ($iter) $Enumerable_sort_by$92.$$p = null; - - - if ($iter) $Enumerable_sort_by$92.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["sort_by"], ($$93 = function(){var self = $$93.$$s || this; + // Used for: a, b = *something (with splat) + Opal.to_a = function(value) { + if (value.$$is_array) { + // A splatted array must be copied + return value.slice(); + } + else if (value['$respond_to?']('to_a', true)) { + var ary = value.$to_a(); + if (ary === nil) { + return [value]; + } + else if (ary.$$is_array) { + return ary; + } + else { + $raise(Opal.TypeError, "Can't convert " + value.$$class + + " to Array (" + value.$$class + "#to_a gives " + ary.$$class + ")"); + } + } + else { + return [value]; + } + }; - return self.$enumerator_size()}, $$93.$$s = self, $$93.$$arity = 0, $$93)) - }; - dup = $send(self, 'map', [], ($$94 = function(){var self = $$94.$$s || this, arg = nil; + // Used for extracting keyword arguments from arguments passed to + // JS function. If provided +arguments+ list doesn't have a Hash + // as a last item, returns a blank Hash. + // + // @param parameters [Array] + // @return [Hash] + // + Opal.extract_kwargs = function(parameters) { + var kwargs = parameters[parameters.length - 1]; + if (kwargs != null && Opal.respond_to(kwargs, '$to_hash', true)) { + $splice(parameters, parameters.length - 1); + return kwargs; + } + }; - - arg = $$($nesting, 'Opal').$destructure(arguments); - return [Opal.yield1(block, arg), arg];}, $$94.$$s = self, $$94.$$arity = 0, $$94)); - $send(dup, 'sort!', [], ($$95 = function(a, b){var self = $$95.$$s || this; + // Used to get a list of rest keyword arguments. Method takes the given + // keyword args, i.e. the hash literal passed to the method containing all + // keyword arguemnts passed to method, as well as the used args which are + // the names of required and optional arguments defined. This method then + // just returns all key/value pairs which have not been used, in a new + // hash literal. + // + // @param given_args [Hash] all kwargs given to method + // @param used_args [Object<String: true>] all keys used as named kwargs + // @return [Hash] + // + Opal.kwrestargs = function(given_args, used_args) { + var keys = [], + map = {}, + key , + given_map = given_args.$$smap; - - - if (a == null) { - a = nil; - }; - - if (b == null) { - b = nil; - }; - return (a[0])['$<=>'](b[0]);}, $$95.$$s = self, $$95.$$arity = 2, $$95)); - return $send(dup, 'map!', [], ($$96 = function(i){var self = $$96.$$s || this; + for (key in given_map) { + if (!used_args[key]) { + keys.push(key); + map[key] = given_map[key]; + } + } - - - if (i == null) { - i = nil; - }; - return i[1];;}, $$96.$$s = self, $$96.$$arity = 1, $$96)); - }, $Enumerable_sort_by$92.$$arity = 0); - - Opal.def(self, '$sum', $Enumerable_sum$97 = function $$sum(initial) { - var $$98, $iter = $Enumerable_sum$97.$$p, $yield = $iter || nil, self = this, result = nil; + return Opal.hash2(keys, map); + }; - if ($iter) $Enumerable_sum$97.$$p = null; - - - if (initial == null) { - initial = 0; - }; - result = initial; - $send(self, 'each', [], ($$98 = function($a){var self = $$98.$$s || this, $post_args, args, item = nil; + function apply_blockopts(block, blockopts) { + if (typeof(blockopts) === 'number') { + block.$$arity = blockopts; + } + else if (typeof(blockopts) === 'object') { + Object.assign(block, blockopts); + } + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - item = (function() {if (($yield !== nil)) { - return Opal.yieldX($yield, Opal.to_a(args)); - } else { - return $$($nesting, 'Opal').$destructure(args) - }; return nil; })(); - return (result = $rb_plus(result, item));}, $$98.$$s = self, $$98.$$arity = -1, $$98)); - return result; - }, $Enumerable_sum$97.$$arity = -1); - - Opal.def(self, '$take', $Enumerable_take$99 = function $$take(num) { - var self = this; + // Optimization for a costly operation of prepending '$' to method names + var jsid_cache = {}; + function $jsid(name) { + return jsid_cache[name] || (jsid_cache[name] = '$' + name); + } + Opal.jsid = $jsid; - return self.$first(num) - }, $Enumerable_take$99.$$arity = 1); - - Opal.def(self, '$take_while', $Enumerable_take_while$100 = function $$take_while() {try { + // Calls passed method on a ruby object with arguments and block: + // + // Can take a method or a method name. + // + // 1. When method name gets passed it invokes it by its name + // and calls 'method_missing' when object doesn't have this method. + // Used internally by Opal to invoke method that takes a block or a splat. + // 2. When method (i.e. method body) gets passed, it doesn't trigger 'method_missing' + // because it doesn't know the name of the actual method. + // Used internally by Opal to invoke 'super'. + // + // @example + // var my_array = [1, 2, 3, 4] + // Opal.send(my_array, 'length') # => 4 + // Opal.send(my_array, my_array.$length) # => 4 + // + // Opal.send(my_array, 'reverse!') # => [4, 3, 2, 1] + // Opal.send(my_array, my_array['$reverse!']') # => [4, 3, 2, 1] + // + // @param recv [Object] ruby object + // @param method [Function, String] method body or name of the method + // @param args [Array] arguments that will be passed to the method call + // @param block [Function] ruby block + // @param blockopts [Object, Number] optional properties to set on the block + // @return [Object] returning value of the method call + Opal.send = function(recv, method, args, block, blockopts) { + var body; + + if (typeof(method) === 'function') { + body = method; + method = null; + } else if (typeof(method) === 'string') { + body = recv[$jsid(method)]; + } else { + $raise(Opal.NameError, "Passed method should be a string or a function"); + } - var $iter = $Enumerable_take_while$100.$$p, block = $iter || nil, $$101, self = this, result = nil; + return Opal.send2(recv, body, method, args, block, blockopts); + }; - if ($iter) $Enumerable_take_while$100.$$p = null; - - - if ($iter) $Enumerable_take_while$100.$$p = null;; - if ($truthy(block)) { - } else { - return self.$enum_for("take_while") - }; - result = []; - return $send(self, 'each', [], ($$101 = function($a){var self = $$101.$$s || this, $post_args, args, value = nil; + Opal.send2 = function(recv, body, method, args, block, blockopts) { + if (body == null && method != null && recv.$method_missing) { + body = recv.$method_missing; + args = [method].concat(args); + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - value = $$($nesting, 'Opal').$destructure(args); - if ($truthy(Opal.yield1(block, value))) { - } else { - Opal.ret(result) - }; - return result.push(value);;}, $$101.$$s = self, $$101.$$arity = -1, $$101)); - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Enumerable_take_while$100.$$arity = 0); - - Opal.def(self, '$uniq', $Enumerable_uniq$102 = function $$uniq() { - var $iter = $Enumerable_uniq$102.$$p, block = $iter || nil, $$103, self = this, hash = nil; + apply_blockopts(block, blockopts); - if ($iter) $Enumerable_uniq$102.$$p = null; - - - if ($iter) $Enumerable_uniq$102.$$p = null;; - hash = $hash2([], {}); - $send(self, 'each', [], ($$103 = function($a){var self = $$103.$$s || this, $post_args, args, value = nil, produced = nil, $writer = nil; + if (typeof block === 'function') body.$$p = block; + return body.apply(recv, args); + }; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - value = $$($nesting, 'Opal').$destructure(args); - produced = (function() {if ((block !== nil)) { - return Opal.yield1(block, value); - } else { - return value - }; return nil; })(); - if ($truthy(hash['$key?'](produced))) { - return nil - } else { - - $writer = [produced, value]; - $send(hash, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)]; - };}, $$103.$$s = self, $$103.$$arity = -1, $$103)); - return hash.$values(); - }, $Enumerable_uniq$102.$$arity = 0); - Opal.alias(self, "to_a", "entries"); - - Opal.def(self, '$zip', $Enumerable_zip$104 = function $$zip($a) { - var $iter = $Enumerable_zip$104.$$p, block = $iter || nil, $post_args, others, self = this; + Opal.refined_send = function(refinement_groups, recv, method, args, block, blockopts) { + var i, j, k, ancestors, ancestor, refinements, refinement, refine_modules, refine_module, body; - if ($iter) $Enumerable_zip$104.$$p = null; - - - if ($iter) $Enumerable_zip$104.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - others = $post_args;; - return $send(self.$to_a(), 'zip', Opal.to_a(others)); - }, $Enumerable_zip$104.$$arity = -1); - })($nesting[0], $nesting) -}; + ancestors = get_ancestors(recv); -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/enumerator"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send, $falsy = Opal.falsy; + // For all ancestors that there are, starting from the closest to the furthest... + for (i = 0; i < ancestors.length; i++) { + ancestor = Opal.id(ancestors[i]); - Opal.add_stubs(['$require', '$include', '$allocate', '$new', '$to_proc', '$coerce_to', '$nil?', '$empty?', '$+', '$class', '$__send__', '$===', '$call', '$enum_for', '$size', '$destructure', '$inspect', '$any?', '$[]', '$raise', '$yield', '$each', '$enumerator_size', '$respond_to?', '$try_convert', '$<', '$for']); - - self.$require("corelib/enumerable"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Enumerator'); + // For all refinement groups there are, starting from the closest scope to the furthest... + for (j = 0; j < refinement_groups.length; j++) { + refinements = refinement_groups[j]; - var $nesting = [self].concat($parent_nesting), $Enumerator_for$1, $Enumerator_initialize$2, $Enumerator_each$3, $Enumerator_size$4, $Enumerator_with_index$5, $Enumerator_inspect$7; + // For all refinements there are, starting from the last `using` call to the furthest... + for (k = refinements.length - 1; k >= 0; k--) { + refinement = refinements[k]; + if (typeof refinement.$$refine_modules === 'undefined') continue; - self.$$prototype.size = self.$$prototype.args = self.$$prototype.object = self.$$prototype.method = nil; - - self.$include($$($nesting, 'Enumerable')); - self.$$prototype.$$is_enumerator = true; - Opal.defs(self, '$for', $Enumerator_for$1 = function(object, $a, $b) { - var $iter = $Enumerator_for$1.$$p, block = $iter || nil, $post_args, method, args, self = this; + // A single module being given as an argument of the `using` call contains multiple + // refinement modules + refine_modules = refinement.$$refine_modules; - if ($iter) $Enumerator_for$1.$$p = null; - - - if ($iter) $Enumerator_for$1.$$p = null;; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - if ($post_args.length > 0) { - method = $post_args[0]; - $post_args.splice(0, 1); + // Does this module refine a given call for a given ancestor module? + if (typeof refine_modules[ancestor] === 'undefined') continue; + refine_module = refine_modules[ancestor]; + + // Does this module define a method we want to call? + if (typeof refine_module.$$prototype[$jsid(method)] !== 'undefined') { + body = refine_module.$$prototype[$jsid(method)]; + return Opal.send2(recv, body, method, args, block, blockopts); + } + } } - if (method == null) { - method = "each"; - }; - - args = $post_args;; - - var obj = self.$allocate(); + } - obj.object = object; - obj.size = block; - obj.method = method; - obj.args = args; + return Opal.send(recv, method, args, block, blockopts); + }; - return obj; - ; - }, $Enumerator_for$1.$$arity = -2); - - Opal.def(self, '$initialize', $Enumerator_initialize$2 = function $$initialize($a) { - var $iter = $Enumerator_initialize$2.$$p, block = $iter || nil, $post_args, self = this; + Opal.lambda = function(block, blockopts) { + block.$$is_lambda = true; - if ($iter) $Enumerator_initialize$2.$$p = null; - - - if ($iter) $Enumerator_initialize$2.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - if ($truthy(block)) { - - self.object = $send($$($nesting, 'Generator'), 'new', [], block.$to_proc()); - self.method = "each"; - self.args = []; - self.size = arguments[0] || nil; - if ($truthy(self.size)) { - return (self.size = $$($nesting, 'Opal').$coerce_to(self.size, $$($nesting, 'Integer'), "to_int")) - } else { - return nil - }; - } else { - - self.object = arguments[0]; - self.method = arguments[1] || "each"; - self.args = $slice.call(arguments, 2); - return (self.size = nil); - }; - }, $Enumerator_initialize$2.$$arity = -1); - - Opal.def(self, '$each', $Enumerator_each$3 = function $$each($a) { - var $iter = $Enumerator_each$3.$$p, block = $iter || nil, $post_args, args, $b, self = this; + apply_blockopts(block, blockopts); - if ($iter) $Enumerator_each$3.$$p = null; - - - if ($iter) $Enumerator_each$3.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(($truthy($b = block['$nil?']()) ? args['$empty?']() : $b))) { - return self}; - args = $rb_plus(self.args, args); - if ($truthy(block['$nil?']())) { - return $send(self.$class(), 'new', [self.object, self.method].concat(Opal.to_a(args)))}; - return $send(self.object, '__send__', [self.method].concat(Opal.to_a(args)), block.$to_proc()); - }, $Enumerator_each$3.$$arity = -1); - - Opal.def(self, '$size', $Enumerator_size$4 = function $$size() { - var self = this; + return block; + }; - if ($truthy($$($nesting, 'Proc')['$==='](self.size))) { - return $send(self.size, 'call', Opal.to_a(self.args)) - } else { - return self.size - } - }, $Enumerator_size$4.$$arity = 0); - - Opal.def(self, '$with_index', $Enumerator_with_index$5 = function $$with_index(offset) { - var $iter = $Enumerator_with_index$5.$$p, block = $iter || nil, $$6, self = this; + // Used to define methods on an object. This is a helper method, used by the + // compiled source to define methods on special case objects when the compiler + // can not determine the destination object, or the object is a Module + // instance. This can get called by `Module#define_method` as well. + // + // ## Modules + // + // Any method defined on a module will come through this runtime helper. + // The method is added to the module body, and the owner of the method is + // set to be the module itself. This is used later when choosing which + // method should show on a class if more than 1 included modules define + // the same method. Finally, if the module is in `module_function` mode, + // then the method is also defined onto the module itself. + // + // ## Classes + // + // This helper will only be called for classes when a method is being + // defined indirectly; either through `Module#define_method`, or by a + // literal `def` method inside an `instance_eval` or `class_eval` body. In + // either case, the method is simply added to the class' prototype. A special + // exception exists for `BasicObject` and `Object`. These two classes are + // special because they are used in toll-free bridged classes. In each of + // these two cases, extra work is required to define the methods on toll-free + // bridged class' prototypes as well. + // + // ## Objects + // + // If a simple ruby object is the object, then the method is simply just + // defined on the object as a singleton method. This would be the case when + // a method is defined inside an `instance_eval` block. + // + // @param obj [Object, Class] the actual obj to define method for + // @param jsid [String] the JavaScript friendly method name (e.g. '$foo') + // @param body [JS.Function] the literal JavaScript function used as method + // @param blockopts [Object, Number] optional properties to set on the body + // @return [null] + // + Opal.def = function(obj, jsid, body, blockopts) { + apply_blockopts(body, blockopts); - if ($iter) $Enumerator_with_index$5.$$p = null; - - - if ($iter) $Enumerator_with_index$5.$$p = null;; - - if (offset == null) { - offset = 0; - }; - offset = (function() {if ($truthy(offset)) { - return $$($nesting, 'Opal').$coerce_to(offset, $$($nesting, 'Integer'), "to_int") - } else { - return 0 - }; return nil; })(); - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["with_index", offset], ($$6 = function(){var self = $$6.$$s || this; + // Special case for a method definition in the + // top-level namespace + if (obj === Opal.top) { + return Opal.defn(Opal.Object, jsid, body); + } + // if instance_eval is invoked on a module/class, it sets inst_eval_mod + else if (!obj.$$eval && obj.$$is_a_module) { + return Opal.defn(obj, jsid, body); + } + else { + return Opal.defs(obj, jsid, body); + } + }; - return self.$size()}, $$6.$$s = self, $$6.$$arity = 0, $$6)) - }; - - var result, index = offset; + // Define method on a module or class (see Opal.def). + Opal.defn = function(module, jsid, body) { + $deny_frozen_access(module); - self.$each.$$p = function() { - var param = $$($nesting, 'Opal').$destructure(arguments), - value = block(param, index); + body.displayName = jsid; + body.$$owner = module; - index++; + var name = jsid.substr(1); - return value; + var proto = module.$$prototype; + if (proto.hasOwnProperty('$$dummy')) { + proto = proto.$$define_methods_on; + } + $prop(proto, jsid, body); + + if (module.$$is_module) { + if (module.$$module_function) { + Opal.defs(module, jsid, body); } - return self.$each(); - ; - }, $Enumerator_with_index$5.$$arity = -1); - Opal.alias(self, "with_object", "each_with_object"); - - Opal.def(self, '$inspect', $Enumerator_inspect$7 = function $$inspect() { - var self = this, result = nil; + for (var i = 0, iclasses = module.$$iclasses, length = iclasses.length; i < length; i++) { + var iclass = iclasses[i]; + $prop(iclass, jsid, body); + } + } - - result = "" + "#<" + (self.$class()) + ": " + (self.object.$inspect()) + ":" + (self.method); - if ($truthy(self.args['$any?']())) { - result = $rb_plus(result, "" + "(" + (self.args.$inspect()['$[]']($$($nesting, 'Range').$new(1, -2))) + ")")}; - return $rb_plus(result, ">"); - }, $Enumerator_inspect$7.$$arity = 0); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Generator'); + var singleton_of = module.$$singleton_of; + if (module.$method_added && !module.$method_added.$$stub && !singleton_of) { + module.$method_added(name); + } + else if (singleton_of && singleton_of.$singleton_method_added && !singleton_of.$singleton_method_added.$$stub) { + singleton_of.$singleton_method_added(name); + } - var $nesting = [self].concat($parent_nesting), $Generator_initialize$8, $Generator_each$9; + return name; + }; - self.$$prototype.block = nil; - - self.$include($$($nesting, 'Enumerable')); - - Opal.def(self, '$initialize', $Generator_initialize$8 = function $$initialize() { - var $iter = $Generator_initialize$8.$$p, block = $iter || nil, self = this; + // Define a singleton method on the given object (see Opal.def). + Opal.defs = function(obj, jsid, body, blockopts) { + apply_blockopts(body, blockopts); - if ($iter) $Generator_initialize$8.$$p = null; - - - if ($iter) $Generator_initialize$8.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'LocalJumpError'), "no block given") - }; - return (self.block = block); - }, $Generator_initialize$8.$$arity = 0); - return (Opal.def(self, '$each', $Generator_each$9 = function $$each($a) { - var $iter = $Generator_each$9.$$p, block = $iter || nil, $post_args, args, self = this, yielder = nil; + if (obj.$$is_string || obj.$$is_number) { + $raise(Opal.TypeError, "can't define singleton"); + } + return Opal.defn(Opal.get_singleton_class(obj), jsid, body); + }; - if ($iter) $Generator_each$9.$$p = null; - - - if ($iter) $Generator_each$9.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - yielder = $send($$($nesting, 'Yielder'), 'new', [], block.$to_proc()); - - try { - args.unshift(yielder); + // Called from #remove_method. + Opal.rdef = function(obj, jsid) { + if (!$has_own(obj.$$prototype, jsid)) { + $raise(Opal.NameError, "method '" + jsid.substr(1) + "' not defined in " + obj.$name()); + } - Opal.yieldX(self.block, args); - } - catch (e) { - if (e === $breaker) { - return $breaker.$v; - } - else { - throw e; - } - } - ; - return self; - }, $Generator_each$9.$$arity = -1), nil) && 'each'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Yielder'); + delete obj.$$prototype[jsid]; - var $nesting = [self].concat($parent_nesting), $Yielder_initialize$10, $Yielder_yield$11, $Yielder_$lt$lt$12; + if (obj.$$is_singleton) { + if (obj.$$prototype.$singleton_method_removed && !obj.$$prototype.$singleton_method_removed.$$stub) { + obj.$$prototype.$singleton_method_removed(jsid.substr(1)); + } + } + else { + if (obj.$method_removed && !obj.$method_removed.$$stub) { + obj.$method_removed(jsid.substr(1)); + } + } + }; - self.$$prototype.block = nil; - - - Opal.def(self, '$initialize', $Yielder_initialize$10 = function $$initialize() { - var $iter = $Yielder_initialize$10.$$p, block = $iter || nil, self = this; + // Called from #undef_method. + Opal.udef = function(obj, jsid) { + if (!obj.$$prototype[jsid] || obj.$$prototype[jsid].$$stub) { + $raise(Opal.NameError, "method '" + jsid.substr(1) + "' not defined in " + obj.$name()); + } - if ($iter) $Yielder_initialize$10.$$p = null; - - - if ($iter) $Yielder_initialize$10.$$p = null;; - return (self.block = block); - }, $Yielder_initialize$10.$$arity = 0); - - Opal.def(self, '$yield', $Yielder_yield$11 = function($a) { - var $post_args, values, self = this; + Opal.add_stub_for(obj.$$prototype, jsid); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - values = $post_args;; - - var value = Opal.yieldX(self.block, values); + if (obj.$$is_singleton) { + if (obj.$$prototype.$singleton_method_undefined && !obj.$$prototype.$singleton_method_undefined.$$stub) { + obj.$$prototype.$singleton_method_undefined(jsid.substr(1)); + } + } + else { + if (obj.$method_undefined && !obj.$method_undefined.$$stub) { + obj.$method_undefined(jsid.substr(1)); + } + } + }; - if (value === $breaker) { - throw $breaker; - } + function is_method_body(body) { + return (typeof(body) === "function" && !body.$$stub); + } - return value; - ; - }, $Yielder_yield$11.$$arity = -1); - return (Opal.def(self, '$<<', $Yielder_$lt$lt$12 = function($a) { - var $post_args, values, self = this; + Opal.alias = function(obj, name, old) { + var id = $jsid(name), + old_id = $jsid(old), + body, + alias; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - values = $post_args;; - $send(self, 'yield', Opal.to_a(values)); - return self; - }, $Yielder_$lt$lt$12.$$arity = -1), nil) && '<<'; - })($nesting[0], null, $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Lazy'); + // Aliasing on main means aliasing on Object... + if (typeof obj.$$prototype === 'undefined') { + obj = Opal.Object; + } - var $nesting = [self].concat($parent_nesting), $Lazy_initialize$13, $Lazy_lazy$16, $Lazy_collect$17, $Lazy_collect_concat$19, $Lazy_drop$23, $Lazy_drop_while$25, $Lazy_enum_for$27, $Lazy_find_all$28, $Lazy_grep$30, $Lazy_reject$33, $Lazy_take$35, $Lazy_take_while$37, $Lazy_inspect$39; + body = obj.$$prototype[old_id]; - self.$$prototype.enumerator = nil; - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'StopLazyError'); + // When running inside #instance_eval the alias refers to class methods. + if (obj.$$eval) { + return Opal.alias(Opal.get_singleton_class(obj), name, old); + } - var $nesting = [self].concat($parent_nesting); + if (!is_method_body(body)) { + var ancestor = obj.$$super; - return nil - })($nesting[0], $$($nesting, 'Exception'), $nesting); - - Opal.def(self, '$initialize', $Lazy_initialize$13 = function $$initialize(object, size) { - var $iter = $Lazy_initialize$13.$$p, block = $iter || nil, $$14, self = this; + while (typeof(body) !== "function" && ancestor) { + body = ancestor[old_id]; + ancestor = ancestor.$$super; + } - if ($iter) $Lazy_initialize$13.$$p = null; - - - if ($iter) $Lazy_initialize$13.$$p = null;; - - if (size == null) { - size = nil; - }; - if ((block !== nil)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy new without a block") - }; - self.enumerator = object; - return $send(self, Opal.find_super_dispatcher(self, 'initialize', $Lazy_initialize$13, false), [size], ($$14 = function(yielder, $a){var self = $$14.$$s || this, $post_args, each_args, $$15; + if (!is_method_body(body) && obj.$$is_module) { + // try to look into Object + body = Opal.Object.$$prototype[old_id]; + } - - - if (yielder == null) { - yielder = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - each_args = $post_args;; - try { - return $send(object, 'each', Opal.to_a(each_args), ($$15 = function($b){var self = $$15.$$s || this, $post_args, args; + if (!is_method_body(body)) { + $raise(Opal.NameError, "undefined method `" + old + "' for class `" + obj.$name() + "'"); + } + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - args.unshift(yielder); + // If the body is itself an alias use the original body + // to keep the max depth at 1. + if (body.$$alias_of) body = body.$$alias_of; - Opal.yieldX(block, args); - ;}, $$15.$$s = self, $$15.$$arity = -1, $$15)) - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'Exception')])) { - try { - return nil - } finally { Opal.pop_exception() } - } else { throw $err; } - };}, $$14.$$s = self, $$14.$$arity = -2, $$14)); - }, $Lazy_initialize$13.$$arity = -2); - Opal.alias(self, "force", "to_a"); - - Opal.def(self, '$lazy', $Lazy_lazy$16 = function $$lazy() { - var self = this; + // We need a wrapper because otherwise properties + // would be overwritten on the original body. + alias = function() { + var block = alias.$$p, args, i, ii; - return self - }, $Lazy_lazy$16.$$arity = 0); - - Opal.def(self, '$collect', $Lazy_collect$17 = function $$collect() { - var $iter = $Lazy_collect$17.$$p, block = $iter || nil, $$18, self = this; + args = new Array(arguments.length); + for(i = 0, ii = arguments.length; i < ii; i++) { + args[i] = arguments[i]; + } - if ($iter) $Lazy_collect$17.$$p = null; - - - if ($iter) $Lazy_collect$17.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy map without a block") - }; - return $send($$($nesting, 'Lazy'), 'new', [self, self.$enumerator_size()], ($$18 = function(enum$, $a){var self = $$18.$$s || this, $post_args, args; + alias.$$p = null; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var value = Opal.yieldX(block, args); + return Opal.send(this, body, args, block); + }; - enum$.$yield(value); - ;}, $$18.$$s = self, $$18.$$arity = -2, $$18)); - }, $Lazy_collect$17.$$arity = 0); - - Opal.def(self, '$collect_concat', $Lazy_collect_concat$19 = function $$collect_concat() { - var $iter = $Lazy_collect_concat$19.$$p, block = $iter || nil, $$20, self = this; + // Assign the 'length' value with defineProperty because + // in strict mode the property is not writable. + // It doesn't work in older browsers (like Chrome 38), where + // an exception is thrown breaking Opal altogether. + try { + Object.defineProperty(alias, 'length', { value: body.length }); + } catch (e) {} - if ($iter) $Lazy_collect_concat$19.$$p = null; - - - if ($iter) $Lazy_collect_concat$19.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy map without a block") - }; - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$20 = function(enum$, $a){var self = $$20.$$s || this, $post_args, args, $$21, $$22; + // Try to make the browser pick the right name + alias.displayName = name; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var value = Opal.yieldX(block, args); + alias.$$arity = body.$$arity == null ? body.length : body.$$arity; + alias.$$parameters = body.$$parameters; + alias.$$source_location = body.$$source_location; + alias.$$alias_of = body; + alias.$$alias_name = name; - if ((value)['$respond_to?']("force") && (value)['$respond_to?']("each")) { - $send((value), 'each', [], ($$21 = function(v){var self = $$21.$$s || this; + Opal.defn(obj, id, alias); - - - if (v == null) { - v = nil; - }; - return enum$.$yield(v);}, $$21.$$s = self, $$21.$$arity = 1, $$21)) - } - else { - var array = $$($nesting, 'Opal').$try_convert(value, $$($nesting, 'Array'), "to_ary"); + return obj; + }; - if (array === nil) { - enum$.$yield(value); - } - else { - $send((value), 'each', [], ($$22 = function(v){var self = $$22.$$s || this; + Opal.alias_gvar = function(new_name, old_name) { + Object.defineProperty($gvars, new_name, { + configurable: true, + enumerable: true, + get: function() { + return $gvars[old_name]; + }, + set: function(new_value) { + $gvars[old_name] = new_value; + } + }); + return nil; + }; - - - if (v == null) { - v = nil; - }; - return enum$.$yield(v);}, $$22.$$s = self, $$22.$$arity = 1, $$22)); - } - } - ;}, $$20.$$s = self, $$20.$$arity = -2, $$20)); - }, $Lazy_collect_concat$19.$$arity = 0); - - Opal.def(self, '$drop', $Lazy_drop$23 = function $$drop(n) { - var $$24, self = this, current_size = nil, set_size = nil, dropped = nil; + Opal.alias_native = function(obj, name, native_name) { + var id = $jsid(name), + body = obj.$$prototype[native_name]; - - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_lt(n, 0))) { - self.$raise($$($nesting, 'ArgumentError'), "attempt to drop negative size")}; - current_size = self.$enumerator_size(); - set_size = (function() {if ($truthy($$($nesting, 'Integer')['$==='](current_size))) { - if ($truthy($rb_lt(n, current_size))) { - return n - } else { - return current_size - } - } else { - return current_size - }; return nil; })(); - dropped = 0; - return $send($$($nesting, 'Lazy'), 'new', [self, set_size], ($$24 = function(enum$, $a){var self = $$24.$$s || this, $post_args, args; + if (typeof(body) !== "function" || body.$$stub) { + $raise(Opal.NameError, "undefined native method `" + native_name + "' for class `" + obj.$name() + "'"); + } - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - if ($truthy($rb_lt(dropped, n))) { - return (dropped = $rb_plus(dropped, 1)) - } else { - return $send(enum$, 'yield', Opal.to_a(args)) - };}, $$24.$$s = self, $$24.$$arity = -2, $$24)); - }, $Lazy_drop$23.$$arity = 1); - - Opal.def(self, '$drop_while', $Lazy_drop_while$25 = function $$drop_while() { - var $iter = $Lazy_drop_while$25.$$p, block = $iter || nil, $$26, self = this, succeeding = nil; + Opal.defn(obj, id, body); - if ($iter) $Lazy_drop_while$25.$$p = null; - - - if ($iter) $Lazy_drop_while$25.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy drop_while without a block") - }; - succeeding = true; - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$26 = function(enum$, $a){var self = $$26.$$s || this, $post_args, args; + return obj; + }; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - if ($truthy(succeeding)) { - - var value = Opal.yieldX(block, args); - if ($falsy(value)) { - succeeding = false; + // Hashes + // ------ - $send(enum$, 'yield', Opal.to_a(args)); - } - - } else { - return $send(enum$, 'yield', Opal.to_a(args)) - };}, $$26.$$s = self, $$26.$$arity = -2, $$26)); - }, $Lazy_drop_while$25.$$arity = 0); - - Opal.def(self, '$enum_for', $Lazy_enum_for$27 = function $$enum_for($a, $b) { - var $iter = $Lazy_enum_for$27.$$p, block = $iter || nil, $post_args, method, args, self = this; + Opal.hash_init = function(hash) { + hash.$$smap = Object.create(null); + hash.$$map = Object.create(null); + hash.$$keys = []; + }; - if ($iter) $Lazy_enum_for$27.$$p = null; - - - if ($iter) $Lazy_enum_for$27.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - if ($post_args.length > 0) { - method = $post_args[0]; - $post_args.splice(0, 1); - } - if (method == null) { - method = "each"; - }; - - args = $post_args;; - return $send(self.$class(), 'for', [self, method].concat(Opal.to_a(args)), block.$to_proc()); - }, $Lazy_enum_for$27.$$arity = -1); - - Opal.def(self, '$find_all', $Lazy_find_all$28 = function $$find_all() { - var $iter = $Lazy_find_all$28.$$p, block = $iter || nil, $$29, self = this; + Opal.hash_clone = function(from_hash, to_hash) { + to_hash.$$none = from_hash.$$none; + to_hash.$$proc = from_hash.$$proc; - if ($iter) $Lazy_find_all$28.$$p = null; - - - if ($iter) $Lazy_find_all$28.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy select without a block") - }; - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$29 = function(enum$, $a){var self = $$29.$$s || this, $post_args, args; + for (var i = 0, keys = from_hash.$$keys, smap = from_hash.$$smap, len = keys.length, key, value; i < len; i++) { + key = keys[i]; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var value = Opal.yieldX(block, args); + if (key.$$is_string) { + value = smap[key]; + } else { + value = key.value; + key = key.key; + } - if ($truthy(value)) { - $send(enum$, 'yield', Opal.to_a(args)); - } - ;}, $$29.$$s = self, $$29.$$arity = -2, $$29)); - }, $Lazy_find_all$28.$$arity = 0); - Opal.alias(self, "flat_map", "collect_concat"); - - Opal.def(self, '$grep', $Lazy_grep$30 = function $$grep(pattern) { - var $iter = $Lazy_grep$30.$$p, block = $iter || nil, $$31, $$32, self = this; + Opal.hash_put(to_hash, key, value); + } + }; - if ($iter) $Lazy_grep$30.$$p = null; - - - if ($iter) $Lazy_grep$30.$$p = null;; - if ($truthy(block)) { - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$31 = function(enum$, $a){var self = $$31.$$s || this, $post_args, args; + Opal.hash_put = function(hash, key, value) { + if (key.$$is_string) { + if (!$has_own(hash.$$smap, key)) { + hash.$$keys.push(key); + } + hash.$$smap[key] = value; + return; + } - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var param = $$($nesting, 'Opal').$destructure(args), - value = pattern['$==='](param); + var key_hash, bucket, last_bucket; + key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash(); - if ($truthy(value)) { - value = Opal.yield1(block, param); + if (!$has_own(hash.$$map, key_hash)) { + bucket = {key: key, key_hash: key_hash, value: value}; + hash.$$keys.push(bucket); + hash.$$map[key_hash] = bucket; + return; + } - enum$.$yield(Opal.yield1(block, param)); - } - ;}, $$31.$$s = self, $$31.$$arity = -2, $$31)) - } else { - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$32 = function(enum$, $a){var self = $$32.$$s || this, $post_args, args; + bucket = hash.$$map[key_hash]; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var param = $$($nesting, 'Opal').$destructure(args), - value = pattern['$==='](param); + while (bucket) { + if (key === bucket.key || key['$eql?'](bucket.key)) { + last_bucket = undefined; + bucket.value = value; + break; + } + last_bucket = bucket; + bucket = bucket.next; + } - if ($truthy(value)) { - enum$.$yield(param); - } - ;}, $$32.$$s = self, $$32.$$arity = -2, $$32)) - }; - }, $Lazy_grep$30.$$arity = 1); - Opal.alias(self, "map", "collect"); - Opal.alias(self, "select", "find_all"); - - Opal.def(self, '$reject', $Lazy_reject$33 = function $$reject() { - var $iter = $Lazy_reject$33.$$p, block = $iter || nil, $$34, self = this; + if (last_bucket) { + bucket = {key: key, key_hash: key_hash, value: value}; + hash.$$keys.push(bucket); + last_bucket.next = bucket; + } + }; - if ($iter) $Lazy_reject$33.$$p = null; - - - if ($iter) $Lazy_reject$33.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy reject without a block") - }; - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$34 = function(enum$, $a){var self = $$34.$$s || this, $post_args, args; + Opal.hash_get = function(hash, key) { + if (key.$$is_string) { + if ($has_own(hash.$$smap, key)) { + return hash.$$smap[key]; + } + return; + } - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var value = Opal.yieldX(block, args); + var key_hash, bucket; + key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash(); + + if ($has_own(hash.$$map, key_hash)) { + bucket = hash.$$map[key_hash]; + + while (bucket) { + if (key === bucket.key || key['$eql?'](bucket.key)) { + return bucket.value; + } + bucket = bucket.next; + } + } + }; - if ($falsy(value)) { - $send(enum$, 'yield', Opal.to_a(args)); - } - ;}, $$34.$$s = self, $$34.$$arity = -2, $$34)); - }, $Lazy_reject$33.$$arity = 0); - - Opal.def(self, '$take', $Lazy_take$35 = function $$take(n) { - var $$36, self = this, current_size = nil, set_size = nil, taken = nil; + Opal.hash_delete = function(hash, key) { + var i, keys = hash.$$keys, length = keys.length, value, key_tmp; - - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_lt(n, 0))) { - self.$raise($$($nesting, 'ArgumentError'), "attempt to take negative size")}; - current_size = self.$enumerator_size(); - set_size = (function() {if ($truthy($$($nesting, 'Integer')['$==='](current_size))) { - if ($truthy($rb_lt(n, current_size))) { - return n - } else { - return current_size - } - } else { - return current_size - }; return nil; })(); - taken = 0; - return $send($$($nesting, 'Lazy'), 'new', [self, set_size], ($$36 = function(enum$, $a){var self = $$36.$$s || this, $post_args, args; + if (key.$$is_string) { + if (typeof key !== "string") key = key.valueOf(); - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - if ($truthy($rb_lt(taken, n))) { - - $send(enum$, 'yield', Opal.to_a(args)); - return (taken = $rb_plus(taken, 1)); - } else { - return self.$raise($$($nesting, 'StopLazyError')) - };}, $$36.$$s = self, $$36.$$arity = -2, $$36)); - }, $Lazy_take$35.$$arity = 1); - - Opal.def(self, '$take_while', $Lazy_take_while$37 = function $$take_while() { - var $iter = $Lazy_take_while$37.$$p, block = $iter || nil, $$38, self = this; + if (!$has_own(hash.$$smap, key)) { + return; + } - if ($iter) $Lazy_take_while$37.$$p = null; - - - if ($iter) $Lazy_take_while$37.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to call lazy take_while without a block") - }; - return $send($$($nesting, 'Lazy'), 'new', [self, nil], ($$38 = function(enum$, $a){var self = $$38.$$s || this, $post_args, args; + for (i = 0; i < length; i++) { + key_tmp = keys[i]; - - - if (enum$ == null) { - enum$ = nil; - }; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - args = $post_args;; - - var value = Opal.yieldX(block, args); + if (key_tmp.$$is_string && typeof key_tmp !== "string") { + key_tmp = key_tmp.valueOf(); + } - if ($truthy(value)) { - $send(enum$, 'yield', Opal.to_a(args)); - } - else { - self.$raise($$($nesting, 'StopLazyError')); - } - ;}, $$38.$$s = self, $$38.$$arity = -2, $$38)); - }, $Lazy_take_while$37.$$arity = 0); - Opal.alias(self, "to_enum", "enum_for"); - return (Opal.def(self, '$inspect', $Lazy_inspect$39 = function $$inspect() { - var self = this; + if (key_tmp === key) { + keys.splice(i, 1); + break; + } + } - return "" + "#<" + (self.$class()) + ": " + (self.enumerator.$inspect()) + ">" - }, $Lazy_inspect$39.$$arity = 0), nil) && 'inspect'; - })($nesting[0], self, $nesting); - })($nesting[0], null, $nesting); -}; + value = hash.$$smap[key]; + delete hash.$$smap[key]; + return value; + } -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/numeric"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_divide(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $hash2 = Opal.hash2; + var key_hash = key.$hash(); - Opal.add_stubs(['$require', '$include', '$instance_of?', '$class', '$Float', '$respond_to?', '$coerce', '$__send__', '$===', '$raise', '$equal?', '$-', '$*', '$div', '$<', '$-@', '$ceil', '$to_f', '$denominator', '$to_r', '$==', '$floor', '$/', '$%', '$Complex', '$zero?', '$numerator', '$abs', '$arg', '$coerce_to!', '$round', '$to_i', '$truncate', '$>']); - - self.$require("corelib/comparable"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Numeric'); + if (!$has_own(hash.$$map, key_hash)) { + return; + } - var $nesting = [self].concat($parent_nesting), $Numeric_coerce$1, $Numeric___coerced__$2, $Numeric_$lt_eq_gt$3, $Numeric_$plus$$4, $Numeric_$minus$$5, $Numeric_$percent$6, $Numeric_abs$7, $Numeric_abs2$8, $Numeric_angle$9, $Numeric_ceil$10, $Numeric_conj$11, $Numeric_denominator$12, $Numeric_div$13, $Numeric_divmod$14, $Numeric_fdiv$15, $Numeric_floor$16, $Numeric_i$17, $Numeric_imag$18, $Numeric_integer$ques$19, $Numeric_nonzero$ques$20, $Numeric_numerator$21, $Numeric_polar$22, $Numeric_quo$23, $Numeric_real$24, $Numeric_real$ques$25, $Numeric_rect$26, $Numeric_round$27, $Numeric_to_c$28, $Numeric_to_int$29, $Numeric_truncate$30, $Numeric_zero$ques$31, $Numeric_positive$ques$32, $Numeric_negative$ques$33, $Numeric_dup$34, $Numeric_clone$35, $Numeric_finite$ques$36, $Numeric_infinite$ques$37; + var bucket = hash.$$map[key_hash], last_bucket; - - self.$include($$($nesting, 'Comparable')); - - Opal.def(self, '$coerce', $Numeric_coerce$1 = function $$coerce(other) { - var self = this; + while (bucket) { + if (key === bucket.key || key['$eql?'](bucket.key)) { + value = bucket.value; - - if ($truthy(other['$instance_of?'](self.$class()))) { - return [other, self]}; - return [self.$Float(other), self.$Float(self)]; - }, $Numeric_coerce$1.$$arity = 1); - - Opal.def(self, '$__coerced__', $Numeric___coerced__$2 = function $$__coerced__(method, other) { - var $a, $b, self = this, a = nil, b = nil, $case = nil; + for (i = 0; i < length; i++) { + if (keys[i] === bucket) { + keys.splice(i, 1); + break; + } + } - if ($truthy(other['$respond_to?']("coerce"))) { - - $b = other.$coerce(self), $a = Opal.to_ary($b), (a = ($a[0] == null ? nil : $a[0])), (b = ($a[1] == null ? nil : $a[1])), $b; - return a.$__send__(method, b); - } else { - return (function() {$case = method; - if ("+"['$===']($case) || "-"['$===']($case) || "*"['$===']($case) || "/"['$===']($case) || "%"['$===']($case) || "&"['$===']($case) || "|"['$===']($case) || "^"['$===']($case) || "**"['$===']($case)) {return self.$raise($$($nesting, 'TypeError'), "" + (other.$class()) + " can't be coerced into Numeric")} - else if (">"['$===']($case) || ">="['$===']($case) || "<"['$===']($case) || "<="['$===']($case) || "<=>"['$===']($case)) {return self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed")} - else { return nil }})() - } - }, $Numeric___coerced__$2.$$arity = 2); - - Opal.def(self, '$<=>', $Numeric_$lt_eq_gt$3 = function(other) { - var self = this; + if (last_bucket && bucket.next) { + last_bucket.next = bucket.next; + } + else if (last_bucket) { + delete last_bucket.next; + } + else if (bucket.next) { + hash.$$map[key_hash] = bucket.next; + } + else { + delete hash.$$map[key_hash]; + } - - if ($truthy(self['$equal?'](other))) { - return 0}; - return nil; - }, $Numeric_$lt_eq_gt$3.$$arity = 1); - - Opal.def(self, '$+@', $Numeric_$plus$$4 = function() { - var self = this; + return value; + } + last_bucket = bucket; + bucket = bucket.next; + } + }; - return self - }, $Numeric_$plus$$4.$$arity = 0); - - Opal.def(self, '$-@', $Numeric_$minus$$5 = function() { - var self = this; + Opal.hash_rehash = function(hash) { + for (var i = 0, length = hash.$$keys.length, key_hash, bucket, last_bucket; i < length; i++) { - return $rb_minus(0, self) - }, $Numeric_$minus$$5.$$arity = 0); - - Opal.def(self, '$%', $Numeric_$percent$6 = function(other) { - var self = this; + if (hash.$$keys[i].$$is_string) { + continue; + } - return $rb_minus(self, $rb_times(other, self.$div(other))) - }, $Numeric_$percent$6.$$arity = 1); - - Opal.def(self, '$abs', $Numeric_abs$7 = function $$abs() { - var self = this; + key_hash = hash.$$keys[i].key.$hash(); - if ($rb_lt(self, 0)) { - return self['$-@']() - } else { - return self + if (key_hash === hash.$$keys[i].key_hash) { + continue; } - }, $Numeric_abs$7.$$arity = 0); - - Opal.def(self, '$abs2', $Numeric_abs2$8 = function $$abs2() { - var self = this; - return $rb_times(self, self) - }, $Numeric_abs2$8.$$arity = 0); - - Opal.def(self, '$angle', $Numeric_angle$9 = function $$angle() { - var self = this; + bucket = hash.$$map[hash.$$keys[i].key_hash]; + last_bucket = undefined; - if ($rb_lt(self, 0)) { - return $$$($$($nesting, 'Math'), 'PI') - } else { - return 0 + while (bucket) { + if (bucket === hash.$$keys[i]) { + if (last_bucket && bucket.next) { + last_bucket.next = bucket.next; + } + else if (last_bucket) { + delete last_bucket.next; + } + else if (bucket.next) { + hash.$$map[hash.$$keys[i].key_hash] = bucket.next; + } + else { + delete hash.$$map[hash.$$keys[i].key_hash]; + } + break; + } + last_bucket = bucket; + bucket = bucket.next; } - }, $Numeric_angle$9.$$arity = 0); - Opal.alias(self, "arg", "angle"); - - Opal.def(self, '$ceil', $Numeric_ceil$10 = function $$ceil(ndigits) { - var self = this; - - - if (ndigits == null) { - ndigits = 0; - }; - return self.$to_f().$ceil(ndigits); - }, $Numeric_ceil$10.$$arity = -1); - - Opal.def(self, '$conj', $Numeric_conj$11 = function $$conj() { - var self = this; + hash.$$keys[i].key_hash = key_hash; - return self - }, $Numeric_conj$11.$$arity = 0); - Opal.alias(self, "conjugate", "conj"); - - Opal.def(self, '$denominator', $Numeric_denominator$12 = function $$denominator() { - var self = this; + if (!$has_own(hash.$$map, key_hash)) { + hash.$$map[key_hash] = hash.$$keys[i]; + continue; + } - return self.$to_r().$denominator() - }, $Numeric_denominator$12.$$arity = 0); - - Opal.def(self, '$div', $Numeric_div$13 = function $$div(other) { - var self = this; + bucket = hash.$$map[key_hash]; + last_bucket = undefined; - - if (other['$=='](0)) { - self.$raise($$($nesting, 'ZeroDivisionError'), "divided by o")}; - return $rb_divide(self, other).$floor(); - }, $Numeric_div$13.$$arity = 1); - - Opal.def(self, '$divmod', $Numeric_divmod$14 = function $$divmod(other) { - var self = this; + while (bucket) { + if (bucket === hash.$$keys[i]) { + last_bucket = undefined; + break; + } + last_bucket = bucket; + bucket = bucket.next; + } - return [self.$div(other), self['$%'](other)] - }, $Numeric_divmod$14.$$arity = 1); - - Opal.def(self, '$fdiv', $Numeric_fdiv$15 = function $$fdiv(other) { - var self = this; + if (last_bucket) { + last_bucket.next = hash.$$keys[i]; + } + } + }; - return $rb_divide(self.$to_f(), other) - }, $Numeric_fdiv$15.$$arity = 1); - - Opal.def(self, '$floor', $Numeric_floor$16 = function $$floor(ndigits) { - var self = this; + Opal.hash = function() { + var arguments_length = arguments.length, args, hash, i, length, key, value; - - - if (ndigits == null) { - ndigits = 0; - }; - return self.$to_f().$floor(ndigits); - }, $Numeric_floor$16.$$arity = -1); - - Opal.def(self, '$i', $Numeric_i$17 = function $$i() { - var self = this; + if (arguments_length === 1 && arguments[0].$$is_hash) { + return arguments[0]; + } - return self.$Complex(0, self) - }, $Numeric_i$17.$$arity = 0); - - Opal.def(self, '$imag', $Numeric_imag$18 = function $$imag() { - var self = this; + hash = new Opal.Hash(); + Opal.hash_init(hash); - return 0 - }, $Numeric_imag$18.$$arity = 0); - Opal.alias(self, "imaginary", "imag"); - - Opal.def(self, '$integer?', $Numeric_integer$ques$19 = function() { - var self = this; + if (arguments_length === 1) { + args = arguments[0]; - return false - }, $Numeric_integer$ques$19.$$arity = 0); - Opal.alias(self, "magnitude", "abs"); - Opal.alias(self, "modulo", "%"); - - Opal.def(self, '$nonzero?', $Numeric_nonzero$ques$20 = function() { - var self = this; + if (arguments[0].$$is_array) { + length = args.length; - if ($truthy(self['$zero?']())) { - return nil - } else { - return self - } - }, $Numeric_nonzero$ques$20.$$arity = 0); - - Opal.def(self, '$numerator', $Numeric_numerator$21 = function $$numerator() { - var self = this; + for (i = 0; i < length; i++) { + if (args[i].length !== 2) { + $raise(Opal.ArgumentError, "value not of length 2: " + args[i].$inspect()); + } - return self.$to_r().$numerator() - }, $Numeric_numerator$21.$$arity = 0); - Opal.alias(self, "phase", "arg"); - - Opal.def(self, '$polar', $Numeric_polar$22 = function $$polar() { - var self = this; + key = args[i][0]; + value = args[i][1]; - return [self.$abs(), self.$arg()] - }, $Numeric_polar$22.$$arity = 0); - - Opal.def(self, '$quo', $Numeric_quo$23 = function $$quo(other) { - var self = this; + Opal.hash_put(hash, key, value); + } - return $rb_divide($$($nesting, 'Opal')['$coerce_to!'](self, $$($nesting, 'Rational'), "to_r"), other) - }, $Numeric_quo$23.$$arity = 1); - - Opal.def(self, '$real', $Numeric_real$24 = function $$real() { - var self = this; + return hash; + } + else { + args = arguments[0]; + for (key in args) { + if ($has_own(args, key)) { + value = args[key]; - return self - }, $Numeric_real$24.$$arity = 0); - - Opal.def(self, '$real?', $Numeric_real$ques$25 = function() { - var self = this; + Opal.hash_put(hash, key, value); + } + } - return true - }, $Numeric_real$ques$25.$$arity = 0); - - Opal.def(self, '$rect', $Numeric_rect$26 = function $$rect() { - var self = this; + return hash; + } + } - return [self, 0] - }, $Numeric_rect$26.$$arity = 0); - Opal.alias(self, "rectangular", "rect"); - - Opal.def(self, '$round', $Numeric_round$27 = function $$round(digits) { - var self = this; + if (arguments_length % 2 !== 0) { + $raise(Opal.ArgumentError, "odd number of arguments for Hash"); + } - - ; - return self.$to_f().$round(digits); - }, $Numeric_round$27.$$arity = -1); - - Opal.def(self, '$to_c', $Numeric_to_c$28 = function $$to_c() { - var self = this; + for (i = 0; i < arguments_length; i += 2) { + key = arguments[i]; + value = arguments[i + 1]; - return self.$Complex(self, 0) - }, $Numeric_to_c$28.$$arity = 0); - - Opal.def(self, '$to_int', $Numeric_to_int$29 = function $$to_int() { - var self = this; + Opal.hash_put(hash, key, value); + } - return self.$to_i() - }, $Numeric_to_int$29.$$arity = 0); - - Opal.def(self, '$truncate', $Numeric_truncate$30 = function $$truncate(ndigits) { - var self = this; + return hash; + }; - - - if (ndigits == null) { - ndigits = 0; - }; - return self.$to_f().$truncate(ndigits); - }, $Numeric_truncate$30.$$arity = -1); - - Opal.def(self, '$zero?', $Numeric_zero$ques$31 = function() { - var self = this; + // A faster Hash creator for hashes that just use symbols and + // strings as keys. The map and keys array can be constructed at + // compile time, so they are just added here by the constructor + // function. + // + Opal.hash2 = function(keys, smap) { + var hash = new Opal.Hash(); - return self['$=='](0) - }, $Numeric_zero$ques$31.$$arity = 0); - - Opal.def(self, '$positive?', $Numeric_positive$ques$32 = function() { - var self = this; + hash.$$smap = smap; + hash.$$map = Object.create(null); + hash.$$keys = keys; - return $rb_gt(self, 0) - }, $Numeric_positive$ques$32.$$arity = 0); - - Opal.def(self, '$negative?', $Numeric_negative$ques$33 = function() { - var self = this; + return hash; + }; - return $rb_lt(self, 0) - }, $Numeric_negative$ques$33.$$arity = 0); - - Opal.def(self, '$dup', $Numeric_dup$34 = function $$dup() { - var self = this; + // Create a new range instance with first and last values, and whether the + // range excludes the last value. + // + Opal.range = function(first, last, exc) { + var range = new Opal.Range(); + range.begin = first; + range.end = last; + range.excl = exc; - return self - }, $Numeric_dup$34.$$arity = 0); - - Opal.def(self, '$clone', $Numeric_clone$35 = function $$clone($kwargs) { - var freeze, self = this; + return range; + }; - - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - freeze = $kwargs.$$smap["freeze"]; - if (freeze == null) { - freeze = true - }; - return self; - }, $Numeric_clone$35.$$arity = -1); - - Opal.def(self, '$finite?', $Numeric_finite$ques$36 = function() { - var self = this; + var reserved_ivar_names = [ + // properties + "constructor", "displayName", "__count__", "__noSuchMethod__", + "__parent__", "__proto__", + // methods + "hasOwnProperty", "valueOf" + ]; - return true - }, $Numeric_finite$ques$36.$$arity = 0); - return (Opal.def(self, '$infinite?', $Numeric_infinite$ques$37 = function() { - var self = this; + // Get the ivar name for a given name. + // Mostly adds a trailing $ to reserved names. + // + Opal.ivar = function(name) { + if (reserved_ivar_names.indexOf(name) !== -1) { + name += "$"; + } - return nil - }, $Numeric_infinite$ques$37.$$arity = 0), nil) && 'infinite?'; - })($nesting[0], null, $nesting); -}; + return name; + }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/array"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $hash2 = Opal.hash2, $send = Opal.send, $gvars = Opal.gvars; + // Support for #freeze + // ------------------- - Opal.add_stubs(['$require', '$include', '$to_a', '$warn', '$raise', '$replace', '$respond_to?', '$to_ary', '$coerce_to', '$coerce_to?', '$===', '$join', '$to_str', '$class', '$hash', '$<=>', '$==', '$object_id', '$inspect', '$enum_for', '$bsearch_index', '$to_proc', '$nil?', '$coerce_to!', '$>', '$*', '$enumerator_size', '$empty?', '$size', '$map', '$equal?', '$dup', '$each', '$[]', '$dig', '$eql?', '$length', '$begin', '$end', '$exclude_end?', '$flatten', '$__id__', '$to_s', '$new', '$max', '$min', '$!', '$>=', '$**', '$delete_if', '$reverse', '$rotate', '$rand', '$at', '$keep_if', '$shuffle!', '$<', '$sort', '$sort_by', '$!=', '$times', '$[]=', '$-', '$<<', '$values', '$is_a?', '$last', '$first', '$upto', '$reject', '$pristine', '$singleton_class']); - - self.$require("corelib/enumerable"); - self.$require("corelib/numeric"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Array'); + // helper that can be used from methods + function $deny_frozen_access(obj) { + if (obj.$$frozen) { + $raise(Opal.FrozenError, "can't modify frozen " + (obj.$class()) + ": " + (obj), Opal.hash2(["receiver"], {"receiver": obj})); + } + } Opal.deny_frozen_access = $deny_frozen_access; - var $nesting = [self].concat($parent_nesting), $Array_$$$1, $Array_initialize$2, $Array_try_convert$3, $Array_$$4, $Array_$$5, $Array_$$6, $Array_$plus$7, $Array_$minus$8, $Array_$lt$lt$9, $Array_$lt_eq_gt$10, $Array_$eq_eq$11, $Array_$$$12, $Array_$$$eq$13, $Array_any$ques$14, $Array_assoc$15, $Array_at$16, $Array_bsearch_index$17, $Array_bsearch$18, $Array_cycle$19, $Array_clear$21, $Array_count$22, $Array_initialize_copy$23, $Array_collect$24, $Array_collect$excl$26, $Array_combination$28, $Array_repeated_combination$30, $Array_compact$32, $Array_compact$excl$33, $Array_concat$34, $Array_delete$37, $Array_delete_at$38, $Array_delete_if$39, $Array_dig$41, $Array_drop$42, $Array_dup$43, $Array_each$44, $Array_each_index$46, $Array_empty$ques$48, $Array_eql$ques$49, $Array_fetch$50, $Array_fill$51, $Array_first$52, $Array_flatten$53, $Array_flatten$excl$54, $Array_hash$55, $Array_include$ques$56, $Array_index$57, $Array_insert$58, $Array_inspect$59, $Array_join$60, $Array_keep_if$61, $Array_last$63, $Array_length$64, $Array_max$65, $Array_min$66, $Array_permutation$67, $Array_repeated_permutation$69, $Array_pop$71, $Array_product$72, $Array_push$73, $Array_rassoc$74, $Array_reject$75, $Array_reject$excl$77, $Array_replace$79, $Array_reverse$80, $Array_reverse$excl$81, $Array_reverse_each$82, $Array_rindex$84, $Array_rotate$85, $Array_rotate$excl$86, $Array_sample$89, $Array_select$90, $Array_select$excl$92, $Array_shift$94, $Array_shuffle$95, $Array_shuffle$excl$96, $Array_slice$excl$97, $Array_sort$98, $Array_sort$excl$99, $Array_sort_by$excl$100, $Array_take$102, $Array_take_while$103, $Array_to_a$104, $Array_to_h$105, $Array_transpose$106, $Array_uniq$109, $Array_uniq$excl$110, $Array_unshift$111, $Array_values_at$112, $Array_zip$115, $Array_inherited$116, $Array_instance_variables$117, $Array_pack$119; + // common #freeze runtime support + Opal.freeze = function(obj) { + $prop(obj, "$$frozen", true); - - self.$include($$($nesting, 'Enumerable')); - Opal.defineProperty(self.$$prototype, '$$is_array', true); - - // Recent versions of V8 (> 7.1) only use an optimized implementation when Array.prototype is unmodified. - // For instance, "array-splice.tq" has a "fast path" (ExtractFastJSArray, defined in "src/codegen/code-stub-assembler.cc") - // but it's only enabled when "IsPrototypeInitialArrayPrototype()" is true. - // - // Older versions of V8 were using relatively fast JS-with-extensions code even when Array.prototype is modified: - // https://github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642 - // - // In short, Array operations are slow in recent versions of V8 when the Array.prototype has been tampered. - // So, when possible, we are using faster open-coded version to boost the performance. + // set $$id + if (!obj.hasOwnProperty('$$id')) { $prop(obj, '$$id', $uid()); } - // As of V8 8.4, depending on the size of the array, this is up to ~25x times faster than Array#shift() - // Implementation is heavily inspired by: https://github.com/nodejs/node/blob/ba684805b6c0eded76e5cd89ee00328ac7a59365/lib/internal/util.js#L341-L347 - function shiftNoArg(list) { - var r = list[0]; - var index = 1; - var length = list.length; - for (; index < length; index++) { - list[index - 1] = list[index]; - } - list.pop(); - return r; + if (obj.hasOwnProperty('$$meta')) { + // freeze $$meta if it has already been set + obj.$$meta.$freeze(); + } else { + // ensure $$meta can be set lazily, $$meta is frozen when set in runtime.js + $prop(obj, '$$meta', null); } - function toArraySubclass(obj, klass) { - if (klass.$$name === Opal.Array) { - return obj; - } else { - return klass.$allocate().$replace((obj).$to_a()); - } - } - ; - Opal.defs(self, '$[]', $Array_$$$1 = function($a) { - var $post_args, objects, self = this; + // $$comparable is used internally and set multiple times + // defining it before sealing ensures it can be modified later on + if (!obj.hasOwnProperty('$$comparable')) { $prop(obj, '$$comparable', null); } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - objects = $post_args;; - return toArraySubclass(objects, self);; - }, $Array_$$$1.$$arity = -1); - - Opal.def(self, '$initialize', $Array_initialize$2 = function $$initialize(size, obj) { - var $iter = $Array_initialize$2.$$p, block = $iter || nil, self = this; + // seal the Object + Object.seal(obj); - if ($iter) $Array_initialize$2.$$p = null; - - - if ($iter) $Array_initialize$2.$$p = null;; - - if (size == null) { - size = nil; - }; - - if (obj == null) { - obj = nil; - }; - - if (obj !== nil && block !== nil) { - self.$warn("warning: block supersedes default value argument") - } + return obj; + }; - if (size > $$$($$($nesting, 'Integer'), 'MAX')) { - self.$raise($$($nesting, 'ArgumentError'), "array size too big") - } + // freze props, make setters of instance variables throw FrozenError + Opal.freeze_props = function(obj) { + var prop, prop_type, desc; - if (arguments.length > 2) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arguments.length) + " for 0..2)") - } + for(prop in obj) { + prop_type = typeof(prop); - if (arguments.length === 0) { - self.splice(0, self.length); - return self; + // prop_type "object" here is a String(), skip $ props + if ((prop_type === "string" || prop_type === "object") && prop[0] === '$') { + continue; } - if (arguments.length === 1) { - if (size.$$is_array) { - self.$replace(size.$to_a()) - return self; - } else if (size['$respond_to?']("to_ary")) { - self.$replace(size.$to_ary()) - return self; - } + desc = Object.getOwnPropertyDescriptor(obj, prop); + if (desc && desc.enumerable && desc.writable) { + // create closure to retain current value as cv + // for Opal 2.0 let for cv should do the trick, instead of a function + (function() { + // set v to undefined, as if the property is not set + var cv = obj[prop]; + Object.defineProperty(obj, prop, { + get: function() { return cv; }, + set: function(_val) { $deny_frozen_access(obj); }, + enumerable: true + }); + })(); } + } + }; - size = $$($nesting, 'Opal').$coerce_to(size, $$($nesting, 'Integer'), "to_int") + // Regexps + // ------- - if (size < 0) { - self.$raise($$($nesting, 'ArgumentError'), "negative array size") - } + // Escape Regexp special chars letting the resulting string be used to build + // a new Regexp. + // + Opal.escape_regexp = function(str) { + return str.replace(/([-[\]\/{}()*+?.^$\\| ])/g, '\\$1') + .replace(/[\n]/g, '\\n') + .replace(/[\r]/g, '\\r') + .replace(/[\f]/g, '\\f') + .replace(/[\t]/g, '\\t'); + }; - self.splice(0, self.length); - var i, value; + // Create a global Regexp from a RegExp object and cache the result + // on the object itself ($$g attribute). + // + Opal.global_regexp = function(pattern) { + if (pattern.global) { + return pattern; // RegExp already has the global flag + } + if (pattern.$$g == null) { + pattern.$$g = new RegExp(pattern.source, (pattern.multiline ? 'gm' : 'g') + (pattern.ignoreCase ? 'i' : '')); + } else { + pattern.$$g.lastIndex = null; // reset lastIndex property + } + return pattern.$$g; + }; - if (block === nil) { - for (i = 0; i < size; i++) { - self.push(obj); - } - } - else { - for (i = 0, value; i < size; i++) { - value = block(i); - self[i] = value; - } - } + // Create a global multiline Regexp from a RegExp object and cache the result + // on the object itself ($$gm or $$g attribute). + // + Opal.global_multiline_regexp = function(pattern) { + var result, flags; - return self; - ; - }, $Array_initialize$2.$$arity = -1); - Opal.defs(self, '$try_convert', $Array_try_convert$3 = function $$try_convert(obj) { - var self = this; + // RegExp already has the global and multiline flag + if (pattern.global && pattern.multiline) return pattern; - return $$($nesting, 'Opal')['$coerce_to?'](obj, $$($nesting, 'Array'), "to_ary") - }, $Array_try_convert$3.$$arity = 1); - - Opal.def(self, '$&', $Array_$$4 = function(other) { - var self = this; + flags = 'gm' + (pattern.ignoreCase ? 'i' : ''); + if (pattern.multiline) { + // we are using the $$g attribute because the Regexp is already multiline + if (pattern.$$g == null) { + pattern.$$g = new RegExp(pattern.source, flags); + } + result = pattern.$$g; + } else { + if (pattern.$$gm == null) { + pattern.$$gm = new RegExp(pattern.source, flags); + } + result = pattern.$$gm; + } + result.lastIndex = null; // reset lastIndex property + return result; + }; - - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - - var result = [], hash = $hash2([], {}), i, length, item; + // Combine multiple regexp parts together + Opal.regexp = function(parts, flags) { + var part; + var ignoreCase = typeof flags !== 'undefined' && flags && flags.indexOf('i') >= 0; - for (i = 0, length = other.length; i < length; i++) { - Opal.hash_put(hash, other[i], true); - } + for (var i = 0, ii = parts.length; i < ii; i++) { + part = parts[i]; + if (part instanceof RegExp) { + if (part.ignoreCase !== ignoreCase) + Opal.Kernel.$warn( + "ignore case doesn't match for " + part.source.$inspect(), + Opal.hash({uplevel: 1}) + ); - for (i = 0, length = self.length; i < length; i++) { - item = self[i]; - if (Opal.hash_delete(hash, item) !== undefined) { - result.push(item); - } + part = part.source; } + if (part === '') part = '(?:' + part + ')'; + parts[i] = part; + } - return result; - ; - }, $Array_$$4.$$arity = 1); - - Opal.def(self, '$|', $Array_$$5 = function(other) { - var self = this; + if (flags) { + return new RegExp(parts.join(''), flags); + } else { + return new RegExp(parts.join('')); + } + }; - - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - - var hash = $hash2([], {}), i, length, item; + // Require system + // -------------- - for (i = 0, length = self.length; i < length; i++) { - Opal.hash_put(hash, self[i], true); - } + Opal.modules = {}; + Opal.loaded_features = ['corelib/runtime']; + Opal.current_dir = '.'; + Opal.require_table = {'corelib/runtime': true}; - for (i = 0, length = other.length; i < length; i++) { - Opal.hash_put(hash, other[i], true); - } + Opal.normalize = function(path) { + var parts, part, new_parts = [], SEPARATOR = '/'; - return hash.$keys(); - ; - }, $Array_$$5.$$arity = 1); - - Opal.def(self, '$*', $Array_$$6 = function(other) { - var self = this; + if (Opal.current_dir !== '.') { + path = Opal.current_dir.replace(/\/*$/, '/') + path; + } - - if ($truthy(other['$respond_to?']("to_str"))) { - return self.$join(other.$to_str())}; - other = $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Integer'), "to_int"); - if ($truthy(other < 0)) { - self.$raise($$($nesting, 'ArgumentError'), "negative argument")}; - - var result = [], - converted = self.$to_a(); + path = path.replace(/^\.\//, ''); + path = path.replace(/\.(rb|opal|js)$/, ''); + parts = path.split(SEPARATOR); - for (var i = 0; i < other; i++) { - result = result.concat(converted); - } + for (var i = 0, ii = parts.length; i < ii; i++) { + part = parts[i]; + if (part === '') continue; + (part === '..') ? new_parts.pop() : new_parts.push(part); + } - return toArraySubclass(result, self.$class()); - ; - }, $Array_$$6.$$arity = 1); - - Opal.def(self, '$+', $Array_$plus$7 = function(other) { - var self = this; + return new_parts.join(SEPARATOR); + }; - - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - return self.concat(other);; - }, $Array_$plus$7.$$arity = 1); - - Opal.def(self, '$-', $Array_$minus$8 = function(other) { - var self = this; + Opal.loaded = function(paths) { + var i, l, path; - - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - if ($truthy(self.length === 0)) { - return []}; - if ($truthy(other.length === 0)) { - return self.slice()}; - - var result = [], hash = $hash2([], {}), i, length, item; + for (i = 0, l = paths.length; i < l; i++) { + path = Opal.normalize(paths[i]); - for (i = 0, length = other.length; i < length; i++) { - Opal.hash_put(hash, other[i], true); + if (Opal.require_table[path]) { + continue; } - for (i = 0, length = self.length; i < length; i++) { - item = self[i]; - if (Opal.hash_get(hash, item) === undefined) { - result.push(item); - } - } + Opal.loaded_features.push(path); + Opal.require_table[path] = true; + } + }; - return result; - ; - }, $Array_$minus$8.$$arity = 1); - - Opal.def(self, '$<<', $Array_$lt$lt$9 = function(object) { - var self = this; + Opal.load_normalized = function(path) { + Opal.loaded([path]); - - self.push(object); - return self; - }, $Array_$lt$lt$9.$$arity = 1); - - Opal.def(self, '$<=>', $Array_$lt_eq_gt$10 = function(other) { - var self = this; + var module = Opal.modules[path]; - - if ($truthy($$($nesting, 'Array')['$==='](other))) { - other = other.$to_a() - } else if ($truthy(other['$respond_to?']("to_ary"))) { - other = other.$to_ary().$to_a() - } else { - return nil - }; - - if (self.$hash() === other.$hash()) { - return 0; + if (module) { + var retval = module(Opal); + if (typeof Promise !== 'undefined' && retval instanceof Promise) { + // A special case of require having an async top: + // We will need to await it. + return retval.then($return_val(true)); } + } + else { + var severity = Opal.config.missing_require_severity; + var message = 'cannot load such file -- ' + path; - var count = Math.min(self.length, other.length); - - for (var i = 0; i < count; i++) { - var tmp = (self[i])['$<=>'](other[i]); - - if (tmp !== 0) { - return tmp; - } + if (severity === "error") { + $raise(Opal.LoadError, message); } + else if (severity === "warning") { + console.warn('WARNING: LoadError: ' + message); + } + } - return (self.length)['$<=>'](other.length); - ; - }, $Array_$lt_eq_gt$10.$$arity = 1); - - Opal.def(self, '$==', $Array_$eq_eq$11 = function(other) { - var self = this; + return true; + }; - - var recursed = {}; + Opal.load = function(path) { + path = Opal.normalize(path); - function _eqeq(array, other) { - var i, length, a, b; + return Opal.load_normalized(path); + }; - if (array === other) - return true; + Opal.require = function(path) { + path = Opal.normalize(path); - if (!other.$$is_array) { - if ($$($nesting, 'Opal')['$respond_to?'](other, "to_ary")) { - return (other)['$=='](array); - } else { - return false; - } - } + if (Opal.require_table[path]) { + return false; + } - if (array.$$constructor !== Array) - array = (array).$to_a(); - if (other.$$constructor !== Array) - other = (other).$to_a(); + return Opal.load_normalized(path); + }; - if (array.length !== other.length) { - return false; - } - recursed[(array).$object_id()] = true; + // Strings + // ------- - for (i = 0, length = array.length; i < length; i++) { - a = array[i]; - b = other[i]; - if (a.$$is_array) { - if (b.$$is_array && b.length !== a.length) { - return false; - } - if (!recursed.hasOwnProperty((a).$object_id())) { - if (!_eqeq(a, b)) { - return false; - } - } - } else { - if (!(a)['$=='](b)) { - return false; - } - } - } + Opal.encodings = Object.create(null); - return true; - } + // Sets the encoding on a string, will treat string literals as frozen strings + // raising a FrozenError. + // + // @param str [String] the string on which the encoding should be set + // @param name [String] the canonical name of the encoding + // @param type [String] possible values are either `"encoding"`, `"internal_encoding"`, or `undefined + Opal.set_encoding = function(str, name, type) { + if (typeof type === "undefined") type = "encoding"; + if (typeof str === 'string' || str.$$frozen === true) + $raise(Opal.FrozenError, "can't modify frozen String"); - return _eqeq(self, other); - - }, $Array_$eq_eq$11.$$arity = 1); - - function $array_slice_range(self, index) { - var size = self.length, - exclude, from, to, result; + var encoding = Opal.find_encoding(name); - exclude = index.excl; - from = Opal.Opal.$coerce_to(index.begin, Opal.Integer, 'to_int'); - to = Opal.Opal.$coerce_to(index.end, Opal.Integer, 'to_int'); + if (encoding === str[type]) { return str; } - if (from < 0) { - from += size; + str[type] = encoding; - if (from < 0) { - return nil; - } - } + return str; + }; - if (from > size) { - return nil; - } + // Fetches the encoding for the given name or raises ArgumentError. + Opal.find_encoding = function(name) { + var register = Opal.encodings; + var encoding = register[name] || register[name.toUpperCase()]; + if (!encoding) $raise(Opal.ArgumentError, "unknown encoding name - " + name); + return encoding; + }; - if (to < 0) { - to += size; + // @returns a String object with the encoding set from a string literal + Opal.enc = function(str, name) { + var dup = new String(str); + dup = Opal.set_encoding(dup, name); + dup.internal_encoding = dup.encoding; + return dup + }; - if (to < 0) { - return []; - } - } + // @returns a String object with the internal encoding set to Binary + Opal.binary = function(str) { + var dup = new String(str); + return Opal.set_encoding(dup, "binary", "internal_encoding"); + }; - if (!exclude) { - to += 1; + Opal.last_promise = null; + Opal.promise_unhandled_exception = false; + + // Run a block of code, but if it returns a Promise, don't run the next + // one, but queue it. + Opal.queue = function(proc) { + if (Opal.last_promise) { + // The async path is taken only if anything before returned a + // Promise(V2). + Opal.last_promise = Opal.last_promise.then(function() { + if (!Opal.promise_unhandled_exception) return proc(Opal); + })['catch'](function(error) { + if (Opal.respond_to(error, '$full_message')) { + error = error.$full_message(); + } + console.error(error); + // Abort further execution + Opal.promise_unhandled_exception = true; + Opal.exit(1); + }); + return Opal.last_promise; + } + else { + var ret = proc(Opal); + if (typeof Promise === 'function' && typeof ret === 'object' && ret instanceof Promise) { + Opal.last_promise = ret; } - - result = self.slice(from, to); - return toArraySubclass(result, self.$class()); + return ret; } + }; - function $array_slice_index_length(self, index, length) { - var size = self.length, - exclude, from, to, result; - - index = Opal.Opal.$coerce_to(index, Opal.Integer, 'to_int'); + // Operator helpers + // ---------------- - if (index < 0) { - index += size; + function are_both_numbers(l,r) { return typeof(l) === 'number' && typeof(r) === 'number' } - if (index < 0) { - return nil; - } - } + Opal.rb_plus = function(l,r) { return are_both_numbers(l,r) ? l + r : l['$+'](r); }; + Opal.rb_minus = function(l,r) { return are_both_numbers(l,r) ? l - r : l['$-'](r); }; + Opal.rb_times = function(l,r) { return are_both_numbers(l,r) ? l * r : l['$*'](r); }; + Opal.rb_divide = function(l,r) { return are_both_numbers(l,r) ? l / r : l['$/'](r); }; + Opal.rb_lt = function(l,r) { return are_both_numbers(l,r) ? l < r : l['$<'](r); }; + Opal.rb_gt = function(l,r) { return are_both_numbers(l,r) ? l > r : l['$>'](r); }; + Opal.rb_le = function(l,r) { return are_both_numbers(l,r) ? l <= r : l['$<='](r); }; + Opal.rb_ge = function(l,r) { return are_both_numbers(l,r) ? l >= r : l['$>='](r); }; - if (length === undefined) { - if (index >= size || index < 0) { - return nil; - } + // Optimized helpers for calls like $truthy((a)['$==='](b)) -> $eqeqeq(a, b) + function are_both_numbers_or_strings(lhs, rhs) { + return (typeof lhs === 'number' && typeof rhs === 'number') || + (typeof lhs === 'string' && typeof rhs === 'string'); + } - return self[index]; - } - else { - length = Opal.Opal.$coerce_to(length, Opal.Integer, 'to_int'); + function $eqeq(lhs, rhs) { + return are_both_numbers_or_strings(lhs,rhs) ? lhs === rhs : $truthy((lhs)['$=='](rhs)); + } Opal.eqeq = $eqeq; + Opal.eqeqeq = function(lhs, rhs) { + return are_both_numbers_or_strings(lhs,rhs) ? lhs === rhs : $truthy((lhs)['$==='](rhs)); + }; + Opal.neqeq = function(lhs, rhs) { + return are_both_numbers_or_strings(lhs,rhs) ? lhs !== rhs : $truthy((lhs)['$!='](rhs)); + }; + Opal.not = function(arg) { + if (undefined === arg || null === arg || false === arg || nil === arg) return true; + if (true === arg || arg['$!'].$$pristine) return false; + return $truthy(arg['$!']()); + }; - if (length < 0 || index > size || index < 0) { - return nil; - } + // Shortcuts - optimized function generators for simple kinds of functions + function $return_val(arg) { + return function() { + return arg; + } + } + Opal.return_val = $return_val; - result = self.slice(index, index + length); - } - return toArraySubclass(result, self.$class()); + Opal.return_self = function() { + return this; + }; + Opal.return_ivar = function(ivar) { + return function() { + if (this[ivar] == null) { return nil; } + return this[ivar]; } - ; - - Opal.def(self, '$[]', $Array_$$$12 = function(index, length) { - var self = this; + }; + Opal.assign_ivar = function(ivar) { + return function(val) { + $deny_frozen_access(this); + return this[ivar] = val; + } + }; + Opal.assign_ivar_val = function(ivar, static_val) { + return function() { + $deny_frozen_access(this); + return this[ivar] = static_val; + } + }; - - ; - - if (index.$$is_range) { - return $array_slice_range(self, index); - } - else { - return $array_slice_index_length(self, index, length); - } - ; - }, $Array_$$$12.$$arity = -2); - - Opal.def(self, '$[]=', $Array_$$$eq$13 = function(index, value, extra) { - var self = this, data = nil, length = nil; + // Primitives for handling parameters + Opal.ensure_kwargs = function(kwargs) { + if (kwargs == null) { + return Opal.hash2([], {}); + } else if (kwargs.$$is_hash) { + return kwargs; + } else { + $raise(Opal.ArgumentError, 'expected kwargs'); + } + }; - - ; - var i, size = self.length;; - if ($truthy($$($nesting, 'Range')['$==='](index))) { - - data = (function() {if ($truthy($$($nesting, 'Array')['$==='](value))) { - return value.$to_a() - } else if ($truthy(value['$respond_to?']("to_ary"))) { - return value.$to_ary().$to_a() - } else { - return [value] - }; return nil; })(); - - var exclude = index.excl, - from = $$($nesting, 'Opal').$coerce_to(index.begin, $$($nesting, 'Integer'), "to_int"), - to = $$($nesting, 'Opal').$coerce_to(index.end, $$($nesting, 'Integer'), "to_int"); + Opal.get_kwarg = function(kwargs, key) { + if (!$has_own(kwargs.$$smap, key)) { + $raise(Opal.ArgumentError, 'missing keyword: '+key); + } + return kwargs.$$smap[key]; + }; - if (from < 0) { - from += size; + // Arrays of size > 32 elements that contain only strings, + // symbols, integers and nils are compiled as a self-extracting + // string. + Opal.large_array_unpack = function(str) { + var array = str.split(","), length = array.length, i; + for (i = 0; i < length; i++) { + switch(array[i][0]) { + case undefined: + array[i] = nil; + break; + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + array[i] = +array[i]; + } + } + return array; + }; - if (from < 0) { - self.$raise($$($nesting, 'RangeError'), "" + (index.$inspect()) + " out of range"); - } - } + // Initialization + // -------------- + Opal.BasicObject = BasicObject = $allocate_class('BasicObject', null); + Opal.Object = _Object = $allocate_class('Object', Opal.BasicObject); + Opal.Module = Module = $allocate_class('Module', Opal.Object); + Opal.Class = Class = $allocate_class('Class', Opal.Module); + Opal.Opal = _Opal = $allocate_module('Opal'); + Opal.Kernel = Kernel = $allocate_module('Kernel'); + + $set_proto(Opal.BasicObject, Opal.Class.$$prototype); + $set_proto(Opal.Object, Opal.Class.$$prototype); + $set_proto(Opal.Module, Opal.Class.$$prototype); + $set_proto(Opal.Class, Opal.Class.$$prototype); - if (to < 0) { - to += size; - } + // BasicObject can reach itself, avoid const_set to skip the $$base_module logic + BasicObject.$$const.BasicObject = BasicObject; - if (!exclude) { - to += 1; - } + // Assign basic constants + $const_set(_Object, "BasicObject", BasicObject); + $const_set(_Object, "Object", _Object); + $const_set(_Object, "Module", Module); + $const_set(_Object, "Class", Class); + $const_set(_Object, "Opal", _Opal); + $const_set(_Object, "Kernel", Kernel); - if (from > size) { - for (i = size; i < from; i++) { - self[i] = nil; - } - } + // Fix booted classes to have correct .class value + BasicObject.$$class = Class; + _Object.$$class = Class; + Module.$$class = Class; + Class.$$class = Class; + _Opal.$$class = Module; + Kernel.$$class = Module; - if (to < 0) { - self.splice.apply(self, [from, 0].concat(data)); - } - else { - self.splice.apply(self, [from, to - from].concat(data)); - } + // Forward .toString() to #to_s + $prop(_Object.$$prototype, 'toString', function() { + var to_s = this.$to_s(); + if (to_s.$$is_string && typeof(to_s) === 'object') { + // a string created using new String('string') + return to_s.valueOf(); + } else { + return to_s; + } + }); - return value; - ; - } else { - - if ($truthy(extra === undefined)) { - length = 1 - } else { - - length = value; - value = extra; - data = (function() {if ($truthy($$($nesting, 'Array')['$==='](value))) { - return value.$to_a() - } else if ($truthy(value['$respond_to?']("to_ary"))) { - return value.$to_ary().$to_a() - } else { - return [value] - }; return nil; })(); - }; - - var old; + // Make Kernel#require immediately available as it's needed to require all the + // other corelib files. + $prop(_Object.$$prototype, '$require', Opal.require); - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); - length = $$($nesting, 'Opal').$coerce_to(length, $$($nesting, 'Integer'), "to_int"); + // Instantiate the main object + Opal.top = new _Object(); + Opal.top.$to_s = Opal.top.$inspect = $return_val('main'); + Opal.top.$define_method = top_define_method; - if (index < 0) { - old = index; - index += size; + // Foward calls to define_method on the top object to Object + function top_define_method() { + var args = $slice(arguments); + var block = top_define_method.$$p; + top_define_method.$$p = null; + return Opal.send(_Object, 'define_method', args, block) + } + // Nil + Opal.NilClass = $allocate_class('NilClass', Opal.Object); + $const_set(_Object, 'NilClass', Opal.NilClass); + nil = Opal.nil = new Opal.NilClass(); + nil.$$id = nil_id; + nil.call = nil.apply = function() { $raise(Opal.LocalJumpError, 'no block given'); }; + nil.$$frozen = true; + nil.$$comparable = false; + Object.seal(nil); + + Opal.thrower = function(type) { + var thrower = new Error('unexpected '+type); + thrower.$thrower_type = type; + thrower.$throw = function(value) { + if (value == null) value = nil; + thrower.$v = value; + throw thrower; + }; + return thrower; + }; - if (index < 0) { - self.$raise($$($nesting, 'IndexError'), "" + "index " + (old) + " too small for array; minimum " + (-self.length)); - } - } + Opal.t_eval_return = Opal.thrower("return"); - if (length < 0) { - self.$raise($$($nesting, 'IndexError'), "" + "negative length (" + (length) + ")") - } + TypeError.$$super = Error; - if (index > size) { - for (i = size; i < index; i++) { - self[i] = nil; - } - } + // If enable-file-source-embed compiler option is enabled, each module loaded will add its + // sources to this object + Opal.file_sources = {}; +}).call(undefined); +Opal.loaded(["corelib/runtime.js"]); +Opal.modules["corelib/helpers"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $type_error = Opal.type_error, $coerce_to = Opal.coerce_to, $module = Opal.module, $defs = Opal.defs, $slice = Opal.slice, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $Opal = Opal.Opal, nil = Opal.nil, $$$ = Opal.$$$; - if (extra === undefined) { - self[index] = value; - } - else { - self.splice.apply(self, [index, length].concat(data)); - } + Opal.add_stubs('===,raise,respond_to?,nil?,__send__,<=>,class,coerce_to!,new,to_s,__id__'); + return (function($base) { + var self = $module($base, 'Opal'); - return value; - ; - }; - }, $Array_$$$eq$13.$$arity = -3); - Opal.def(self, '$any?', $Array_any$ques$14 = function(pattern) { - var $iter = $Array_any$ques$14.$$p, block = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + + $defs(self, '$bridge', function $$bridge(constructor, klass) { + + return Opal.bridge(constructor, klass); + }); + $defs(self, '$coerce_to!', function $Opal_coerce_to$excl$1(object, type, method, $a) { + var $post_args, args, coerced = nil; - if ($iter) $Array_any$ques$14.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } + $post_args = $slice(arguments, 3); + args = $post_args; + coerced = $coerce_to(object, type, method, args); + if (!$eqeqeq(type, coerced)) { + $Kernel.$raise($type_error(object, type, method, coerced)); + } return coerced; + }, -4); + $defs(self, '$coerce_to?', function $Opal_coerce_to$ques$2(object, type, method, $a) { + var $post_args, args, coerced = nil; + - if ($iter) $Array_any$ques$14.$$p = null;; - ; - if (self.length === 0) return false; - return $send(self, Opal.find_super_dispatcher(self, 'any?', $Array_any$ques$14, false), $zuper, $iter); - }, $Array_any$ques$14.$$arity = -1); - - Opal.def(self, '$assoc', $Array_assoc$15 = function $$assoc(object) { - var self = this; + $post_args = $slice(arguments, 3); + args = $post_args; + if (!$truthy(object['$respond_to?'](method))) { + return nil + } coerced = $coerce_to(object, type, method, args); + if ($truthy(coerced['$nil?']())) { + return nil + } if (!$eqeqeq(type, coerced)) { + $Kernel.$raise($type_error(object, type, method, coerced)); + } return coerced; + }, -4); + $defs(self, '$try_convert', function $$try_convert(object, type, method) { + + + if ($eqeqeq(type, object)) { + return object + } if ($truthy(object['$respond_to?'](method))) { + return object.$__send__(method) + } else { + return nil + } }); + $defs(self, '$compare', function $$compare(a, b) { + var compare = nil; - for (var i = 0, length = self.length, item; i < length; i++) { - if (item = self[i], item.length && (item[0])['$=='](object)) { - return item; - } + compare = a['$<=>'](b); + if ($truthy(compare === nil)) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + (a.$class()) + " with " + (b.$class()) + " failed"); + } return compare; + }); + $defs(self, '$destructure', function $$destructure(args) { + + + if (args.length == 1) { + return args[0]; + } + else if (args.$$is_array) { + return args; } + else { + var args_ary = new Array(args.length); + for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; } - return nil; - - }, $Array_assoc$15.$$arity = 1); + return args_ary; + } - Opal.def(self, '$at', $Array_at$16 = function $$at(index) { - var self = this; - + }); + $defs(self, '$respond_to?', function $Opal_respond_to$ques$3(obj, method, include_all) { - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); - if (index < 0) { - index += self.length; + if (include_all == null) include_all = false; + + if (obj == null || !obj.$$class) { + return false; } - - if (index < 0 || index >= self.length) { - return nil; + return obj['$respond_to?'](method, include_all); + }, -3); + $defs(self, '$instance_variable_name!', function $Opal_instance_variable_name$excl$4(name) { + + + name = $Opal['$coerce_to!'](name, $$$('String'), "to_str"); + if (!$truthy(/^@[a-zA-Z_][a-zA-Z0-9_]*?$/.test(name))) { + $Kernel.$raise($$$('NameError').$new("'" + (name) + "' is not allowed as an instance variable name", name)); + } return name; + }); + $defs(self, '$class_variable_name!', function $Opal_class_variable_name$excl$5(name) { + + + name = $Opal['$coerce_to!'](name, $$$('String'), "to_str"); + if ($truthy(name.length < 3 || name.slice(0,2) !== '@@')) { + $Kernel.$raise($$$('NameError').$new("`" + (name) + "' is not allowed as a class variable name", name)); + } return name; + }); + $defs(self, '$const_name?', function $Opal_const_name$ques$6(const_name) { + + + if (typeof const_name !== 'string') { + (const_name = $Opal['$coerce_to!'](const_name, $$$('String'), "to_str")); } - return self[index]; - ; - }, $Array_at$16.$$arity = 1); + return const_name[0] === const_name[0].toUpperCase() - Opal.def(self, '$bsearch_index', $Array_bsearch_index$17 = function $$bsearch_index() { - var $iter = $Array_bsearch_index$17.$$p, block = $iter || nil, self = this; + }); + $defs(self, '$const_name!', function $Opal_const_name$excl$7(const_name) { + var self = this; - if ($iter) $Array_bsearch_index$17.$$p = null; + if ($truthy((($$$('::', 'String', 'skip_raise')) ? 'constant' : nil))) { + const_name = $Opal['$coerce_to!'](const_name, $$$('String'), "to_str"); + } + if (!const_name || const_name[0] != const_name[0].toUpperCase()) { + self.$raise($$$('NameError'), "wrong constant name " + (const_name)); + } + return const_name; + }); + $defs(self, '$pristine', function $$pristine(owner_class, $a) { + var $post_args, method_names; + - if ($iter) $Array_bsearch_index$17.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("bsearch_index") - }; + $post_args = $slice(arguments, 1); + method_names = $post_args; - var min = 0, - max = self.length, - mid, - val, - ret, - smaller = false, - satisfied = nil; - - while (min < max) { - mid = min + Math.floor((max - min) / 2); - val = self[mid]; - ret = Opal.yield1(block, val); + var method_name, method; + for (var i = method_names.length - 1; i >= 0; i--) { + method_name = method_names[i]; + method = owner_class.$$prototype[Opal.jsid(method_name)]; - if (ret === true) { - satisfied = mid; - smaller = true; + if (method && !method.$$stub) { + method.$$pristine = true; } - else if (ret === false || ret === nil) { - smaller = false; + } + return nil; + }, -2); + var inspect_stack = []; + return $defs(self, '$inspect', function $$inspect(value) { + var e = nil; + var pushed = false; + + return (function() { try { + try { + + + if (value === null) { + // JS null value + return 'null'; } - else if (ret.$$is_number) { - if (ret === 0) { return mid; } - smaller = (ret < 0); + else if (value === undefined) { + // JS undefined value + return 'undefined'; + } + else if (typeof value.$$class === 'undefined') { + // JS object / other value that is not bridged + return Object.prototype.toString.apply(value); + } + else if (typeof value.$inspect !== 'function' || value.$inspect.$$stub) { + // BasicObject and friends + return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">" + } + else if (inspect_stack.indexOf(value.$__id__()) !== -1) { + // inspect recursing inside inspect to find out about the + // same object + return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">" } else { - self.$raise($$($nesting, 'TypeError'), "" + "wrong argument type " + ((ret).$class()) + " (must be numeric, true, false or nil)") + // anything supporting Opal + inspect_stack.push(value.$__id__()); + pushed = true; + return value.$inspect(); } - - if (smaller) { max = mid; } else { min = mid + 1; } + ; + return nil; + } catch ($err) { + if (Opal.rescue($err, [$$$('Exception')])) {(e = $err); + try { + return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">" + } finally { Opal.pop_exception(); } + } else { throw $err; } } + } finally { + if (pushed) inspect_stack.pop(); + } })(); }, -1); + })('::') +}; + +Opal.modules["corelib/module"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $const_set = Opal.const_set, $Object = Opal.Object, $return_ivar = Opal.return_ivar, $assign_ivar = Opal.assign_ivar, $ivar = Opal.ivar, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $prop = Opal.prop, $jsid = Opal.jsid, $klass = Opal.klass, $defs = Opal.defs, $send = Opal.send, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $Module = Opal.Module, $Kernel = Opal.Kernel, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $slice = Opal.slice, $to_a = Opal.to_a, $hash2 = Opal.hash2, $Opal = Opal.Opal, $return_val = Opal.return_val, $eqeq = Opal.eqeq, $lambda = Opal.lambda, $range = Opal.range, $send2 = Opal.send2, $find_super = Opal.find_super, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('module_eval,to_proc,===,raise,equal?,<,>,nil?,attr_reader,attr_writer,warn,attr_accessor,const_name?,class_variable_name!,pristine,const_name!,=~,new,inject,split,const_get,==,start_with?,!~,bind,call,class,frozen?,name,append_features,included,cover?,size,merge,compile,proc,any?,prepend_features,prepended,to_s,__id__,constants,include?,copy_class_variables,copy_constants,class_exec,module_exec,inspect'); + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Module'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return satisfied; - ; - }, $Array_bsearch_index$17.$$arity = 0); - Opal.def(self, '$bsearch', $Array_bsearch$18 = function $$bsearch() { - var $iter = $Array_bsearch$18.$$p, block = $iter || nil, self = this, index = nil; + $defs(self, '$allocate', function $$allocate() { + var self = this; - if ($iter) $Array_bsearch$18.$$p = null; - - if ($iter) $Array_bsearch$18.$$p = null;; + var module = Opal.allocate_module(nil, function(){}); + // Link the prototype of Module subclasses + if (self !== Opal.Module) Object.setPrototypeOf(module, self.$$prototype); + return module; + + }); + + $def(self, '$initialize', function $$initialize() { + var block = $$initialize.$$p || nil, self = this; + + $$initialize.$$p = null; if ((block !== nil)) { + return $send(self, 'module_eval', [], block.$to_proc()) } else { - return self.$enum_for("bsearch") - }; - index = $send(self, 'bsearch_index', [], block.$to_proc()); - - if (index != null && index.$$is_number) { - return self[index]; - } else { - return index; - } - ; - }, $Array_bsearch$18.$$arity = 0); + return nil + } }); - Opal.def(self, '$cycle', $Array_cycle$19 = function $$cycle(n) { - var $iter = $Array_cycle$19.$$p, block = $iter || nil, $$20, $a, self = this; + $def(self, '$===', function $Module_$eq_eq_eq$1(object) { + var self = this; - if ($iter) $Array_cycle$19.$$p = null; - - if ($iter) $Array_cycle$19.$$p = null;; - - if (n == null) { - n = nil; - }; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["cycle", n], ($$20 = function(){var self = $$20.$$s || this; + if ($truthy(object == null)) { + return false + } return Opal.is_a(object, self); }); + + $def(self, '$<', function $Module_$lt$2(other) { + var self = this; - if ($truthy(n['$nil?']())) { - return $$$($$($nesting, 'Float'), 'INFINITY') - } else { - - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_gt(n, 0))) { - return $rb_times(self.$enumerator_size(), n) - } else { - return 0 - }; - }}, $$20.$$s = self, $$20.$$arity = 0, $$20)) - }; - if ($truthy(($truthy($a = self['$empty?']()) ? $a : n['$=='](0)))) { - return nil}; - var i, length, value; + if (!$eqeqeq($Module, other)) { + $Kernel.$raise($$$('TypeError'), "compared with non class/module"); + } + var working = self, + ancestors, + i, length; - if (n === nil) { - while (true) { - for (i = 0, length = self.length; i < length; i++) { - value = Opal.yield1(block, self[i]); - } + if (working === other) { + return false; + } + + for (i = 0, ancestors = Opal.ancestors(self), length = ancestors.length; i < length; i++) { + if (ancestors[i] === other) { + return true; } } - else { - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if (n <= 0) { - return self; - } - - while (n > 0) { - for (i = 0, length = self.length; i < length; i++) { - value = Opal.yield1(block, self[i]); - } - n--; + for (i = 0, ancestors = Opal.ancestors(other), length = ancestors.length; i < length; i++) { + if (ancestors[i] === self) { + return false; } } - ; - return self; - }, $Array_cycle$19.$$arity = -1); - - Opal.def(self, '$clear', $Array_clear$21 = function $$clear() { - var self = this; - - self.splice(0, self.length); - return self; - }, $Array_clear$21.$$arity = 0); + return nil; + }); - Opal.def(self, '$count', $Array_count$22 = function $$count(object) { - var $iter = $Array_count$22.$$p, block = $iter || nil, $a, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + $def(self, '$<=', function $Module_$lt_eq$3(other) { + var self = this, $ret_or_1 = nil; - if ($iter) $Array_count$22.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - - if ($iter) $Array_count$22.$$p = null;; - - if (object == null) { - object = nil; - }; - if ($truthy(($truthy($a = object) ? $a : block))) { - return $send(self, Opal.find_super_dispatcher(self, 'count', $Array_count$22, false), $zuper, $iter) + if ($truthy(($ret_or_1 = self['$equal?'](other)))) { + return $ret_or_1 } else { - return self.$size() - }; - }, $Array_count$22.$$arity = -1); + return $rb_lt(self, other) + } + }); - Opal.def(self, '$initialize_copy', $Array_initialize_copy$23 = function $$initialize_copy(other) { + $def(self, '$>', function $Module_$gt$4(other) { var self = this; - return self.$replace(other) - }, $Array_initialize_copy$23.$$arity = 1); + + if (!$eqeqeq($Module, other)) { + $Kernel.$raise($$$('TypeError'), "compared with non class/module"); + } return $rb_lt(other, self); + }); - Opal.def(self, '$collect', $Array_collect$24 = function $$collect() { - var $iter = $Array_collect$24.$$p, block = $iter || nil, $$25, self = this; + $def(self, '$>=', function $Module_$gt_eq$5(other) { + var self = this, $ret_or_1 = nil; - if ($iter) $Array_collect$24.$$p = null; - - - if ($iter) $Array_collect$24.$$p = null;; - if ((block !== nil)) { + if ($truthy(($ret_or_1 = self['$equal?'](other)))) { + return $ret_or_1 } else { - return $send(self, 'enum_for', ["collect"], ($$25 = function(){var self = $$25.$$s || this; - - return self.$size()}, $$25.$$s = self, $$25.$$arity = 0, $$25)) - }; - - var result = []; - - for (var i = 0, length = self.length; i < length; i++) { - var value = Opal.yield1(block, self[i]); - result.push(value); + return $rb_gt(self, other) } - - return result; - ; - }, $Array_collect$24.$$arity = 0); + }); - Opal.def(self, '$collect!', $Array_collect$excl$26 = function() { - var $iter = $Array_collect$excl$26.$$p, block = $iter || nil, $$27, self = this; + $def(self, '$<=>', function $Module_$lt_eq_gt$6(other) { + var self = this, lt = nil; - if ($iter) $Array_collect$excl$26.$$p = null; - if ($iter) $Array_collect$excl$26.$$p = null;; - if ((block !== nil)) { + if (self === other) { + return 0; + } + if (!$eqeqeq($Module, other)) { + return nil + } lt = $rb_lt(self, other); + if ($truthy(lt['$nil?']())) { + return nil + } if ($truthy(lt)) { + return -1 } else { - return $send(self, 'enum_for', ["collect!"], ($$27 = function(){var self = $$27.$$s || this; + return 1 + } }); + + $def(self, '$alias_method', function $$alias_method(newname, oldname) { + var self = this; - return self.$size()}, $$27.$$s = self, $$27.$$arity = 0, $$27)) - }; - for (var i = 0, length = self.length; i < length; i++) { - var value = Opal.yield1(block, self[i]); - self[i] = value; - } - ; + $deny_frozen_access(self); + newname = $coerce_to(newname, $$$('String'), 'to_str'); + oldname = $coerce_to(oldname, $$$('String'), 'to_str'); + Opal.alias(self, newname, oldname); return self; - }, $Array_collect$excl$26.$$arity = 0); + }); - function binomial_coefficient(n, k) { - if (n === k || k === 0) { - return 1; - } - - if (k > 0 && n > k) { - return binomial_coefficient(n - 1, k - 1) + binomial_coefficient(n - 1, k); - } + $def(self, '$alias_native', function $$alias_native(mid, jsid) { + var self = this; - return 0; - } - ; + + if (jsid == null) jsid = mid; + $deny_frozen_access(self); + Opal.alias_native(self, mid, jsid); + return self; + }, -2); - Opal.def(self, '$combination', $Array_combination$28 = function $$combination(n) { - var $$29, $iter = $Array_combination$28.$$p, $yield = $iter || nil, self = this, num = nil; + $def(self, '$ancestors', function $$ancestors() { + var self = this; - if ($iter) $Array_combination$28.$$p = null; - - num = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["combination", num], ($$29 = function(){var self = $$29.$$s || this; + return Opal.ancestors(self); + }); + + $def(self, '$append_features', function $$append_features(includer) { + var self = this; - return binomial_coefficient(self.length, num)}, $$29.$$s = self, $$29.$$arity = 0, $$29)) - }; - var i, length, stack, chosen, lev, done, next; - - if (num === 0) { - Opal.yield1($yield, []) - } else if (num === 1) { - for (i = 0, length = self.length; i < length; i++) { - Opal.yield1($yield, [self[i]]) - } - } - else if (num === self.length) { - Opal.yield1($yield, self.slice()) - } - else if (num >= 0 && num < self.length) { - stack = []; - for (i = 0; i <= num + 1; i++) { - stack.push(0); - } - - chosen = []; - lev = 0; - done = false; - stack[0] = -1; - - while (!done) { - chosen[lev] = self[stack[lev+1]]; - while (lev < num - 1) { - lev++; - next = stack[lev+1] = stack[lev] + 1; - chosen[lev] = self[next]; - } - Opal.yield1($yield, chosen.slice()) - lev++; - do { - done = (lev === 0); - stack[lev]++; - lev--; - } while ( stack[lev+1] + num === self.length + lev + 1 ); - } - } - ; + $deny_frozen_access(includer); + Opal.append_features(self, includer); return self; - }, $Array_combination$28.$$arity = 1); + }); - Opal.def(self, '$repeated_combination', $Array_repeated_combination$30 = function $$repeated_combination(n) { - var $$31, $iter = $Array_repeated_combination$30.$$p, $yield = $iter || nil, self = this, num = nil; + $def(self, '$attr_accessor', function $$attr_accessor($a) { + var $post_args, names, self = this; - if ($iter) $Array_repeated_combination$30.$$p = null; - num = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["repeated_combination", num], ($$31 = function(){var self = $$31.$$s || this; + $post_args = $slice(arguments); + names = $post_args; + $send(self, 'attr_reader', $to_a(names)); + return $send(self, 'attr_writer', $to_a(names)); + }, -1); + + $def(self, '$attr', function $$attr($a) { + var $post_args, args, self = this; - return binomial_coefficient(self.length + num - 1, num);}, $$31.$$s = self, $$31.$$arity = 0, $$31)) - }; - function iterate(max, from, buffer, self) { - if (buffer.length == max) { - var copy = buffer.slice(); - Opal.yield1($yield, copy) - return; - } - for (var i = from; i < self.length; i++) { - buffer.push(self[i]); - iterate(max, i, buffer, self); - buffer.pop(); - } - } + $post_args = $slice(arguments); + args = $post_args; + + if (args.length == 2 && (args[1] === true || args[1] === false)) { + self.$warn("optional boolean argument is obsoleted", $hash2(["uplevel"], {"uplevel": 1})); - if (num >= 0) { - iterate(num, 0, [], self); + args[1] ? self.$attr_accessor(args[0]) : self.$attr_reader(args[0]); + return nil; } - ; - return self; - }, $Array_repeated_combination$30.$$arity = 1); + return $send(self, 'attr_reader', $to_a(args)); + }, -1); - Opal.def(self, '$compact', $Array_compact$32 = function $$compact() { - var self = this; + $def(self, '$attr_reader', function $$attr_reader($a) { + var $post_args, names, self = this; - var result = []; + $post_args = $slice(arguments); + names = $post_args; + + $deny_frozen_access(self); - for (var i = 0, length = self.length, item; i < length; i++) { - if ((item = self[i]) !== nil) { - result.push(item); - } - } + var proto = self.$$prototype; - return result; - - }, $Array_compact$32.$$arity = 0); - - Opal.def(self, '$compact!', $Array_compact$excl$33 = function() { - var self = this; + for (var i = names.length - 1; i >= 0; i--) { + var name = names[i], + id = $jsid(name), + ivar = $ivar(name); - - var original = self.length; + var body = $return_ivar(ivar); - for (var i = 0, length = self.length; i < length; i++) { - if (self[i] === nil) { - self.splice(i, 1); + // initialize the instance variable as nil + Opal.prop(proto, ivar, nil); - length--; - i--; - } - } + body.$$parameters = []; + body.$$arity = 0; - return self.length === original ? nil : self; - - }, $Array_compact$excl$33.$$arity = 0); + Opal.defn(self, id, body); + } + return nil; + }, -1); - Opal.def(self, '$concat', $Array_concat$34 = function $$concat($a) { - var $post_args, others, $$35, $$36, self = this; + $def(self, '$attr_writer', function $$attr_writer($a) { + var $post_args, names, self = this; + $post_args = $slice(arguments); + names = $post_args; - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - others = $post_args;; - others = $send(others, 'map', [], ($$35 = function(other){var self = $$35.$$s || this; + $deny_frozen_access(self); - - - if (other == null) { - other = nil; - }; - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - if ($truthy(other['$equal?'](self))) { - other = other.$dup()}; - return other;}, $$35.$$s = self, $$35.$$arity = 1, $$35)); - $send(others, 'each', [], ($$36 = function(other){var self = $$36.$$s || this; + var proto = self.$$prototype; - - - if (other == null) { - other = nil; - }; - - for (var i = 0, length = other.length; i < length; i++) { - self.push(other[i]); - } - ;}, $$36.$$s = self, $$36.$$arity = 1, $$36)); - return self; - }, $Array_concat$34.$$arity = -1); - - Opal.def(self, '$delete', $Array_delete$37 = function(object) { - var $iter = $Array_delete$37.$$p, $yield = $iter || nil, self = this; + for (var i = names.length - 1; i >= 0; i--) { + var name = names[i], + id = $jsid(name + '='), + ivar = $ivar(name); - if ($iter) $Array_delete$37.$$p = null; - - var original = self.length; + var body = $assign_ivar(ivar); - for (var i = 0, length = original; i < length; i++) { - if ((self[i])['$=='](object)) { - self.splice(i, 1); + body.$$parameters = [['req']]; + body.$$arity = 1; - length--; - i--; - } - } + // initialize the instance variable as nil + Opal.prop(proto, ivar, nil); - if (self.length === original) { - if (($yield !== nil)) { - return Opal.yieldX($yield, []); - } - return nil; + Opal.defn(self, id, body); } - return object; - - }, $Array_delete$37.$$arity = 1); + return nil; + }, -1); - Opal.def(self, '$delete_at', $Array_delete_at$38 = function $$delete_at(index) { + $def(self, '$autoload', function $$autoload(const$, path) { var self = this; - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); + $deny_frozen_access(self); - if (index < 0) { - index += self.length; + if (!$$('Opal')['$const_name?'](const$)) { + $Kernel.$raise($$$('NameError'), "autoload must be constant name: " + (const$)); } - if (index < 0 || index >= self.length) { - return nil; + if (path == "") { + $Kernel.$raise($$$('ArgumentError'), "empty file name"); } - var result = self[index]; - - self.splice(index, 1); + if (!self.$$const.hasOwnProperty(const$)) { + if (!self.$$autoload) { + self.$$autoload = {}; + } + Opal.const_cache_version++; + self.$$autoload[const$] = { path: path, loaded: false, required: false, success: false, exception: false }; - return result; + if (self.$const_added && !self.$const_added.$$pristine) { + self.$const_added(const$); + } + } + return nil; - }, $Array_delete_at$38.$$arity = 1); + }); - Opal.def(self, '$delete_if', $Array_delete_if$39 = function $$delete_if() { - var $iter = $Array_delete_if$39.$$p, block = $iter || nil, $$40, self = this; - - if ($iter) $Array_delete_if$39.$$p = null; - - - if ($iter) $Array_delete_if$39.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["delete_if"], ($$40 = function(){var self = $$40.$$s || this; + $def(self, '$autoload?', function $Module_autoload$ques$7(const$) { + var self = this; - return self.$size()}, $$40.$$s = self, $$40.$$arity = 0, $$40)) - }; - for (var i = 0, length = self.length, value; i < length; i++) { - value = block(self[i]); + if (self.$$autoload && self.$$autoload[const$] && !self.$$autoload[const$].required && !self.$$autoload[const$].success) { + return self.$$autoload[const$].path; + } - if (value !== false && value !== nil) { - self.splice(i, 1); + var ancestors = self.$ancestors(); - length--; - i--; + for (var i = 0, length = ancestors.length; i < length; i++) { + if (ancestors[i].$$autoload && ancestors[i].$$autoload[const$] && !ancestors[i].$$autoload[const$].required && !ancestors[i].$$autoload[const$].success) { + return ancestors[i].$$autoload[const$].path; } } - ; - return self; - }, $Array_delete_if$39.$$arity = 0); + return nil; - Opal.def(self, '$dig', $Array_dig$41 = function $$dig(idx, $a) { - var $post_args, idxs, self = this, item = nil; + }); + + $def(self, '$class_variables', function $$class_variables() { + var self = this; + + return Object.keys(Opal.class_variables(self)); + }); + + $def(self, '$class_variable_get', function $$class_variable_get(name) { + var self = this; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - idxs = $post_args;; - item = self['$[]'](idx); - - if (item === nil || idxs.length === 0) { - return item; - } - ; - if ($truthy(item['$respond_to?']("dig"))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + (item.$class()) + " does not have #dig method") - }; - return $send(item, 'dig', Opal.to_a(idxs)); - }, $Array_dig$41.$$arity = -2); + name = $Opal['$class_variable_name!'](name); + return Opal.class_variable_get(self, name, false); }); - Opal.def(self, '$drop', $Array_drop$42 = function $$drop(number) { + $def(self, '$class_variable_set', function $$class_variable_set(name, value) { var self = this; - if (number < 0) { - self.$raise($$($nesting, 'ArgumentError')) - } + $deny_frozen_access(self); + name = $Opal['$class_variable_name!'](name); + return Opal.class_variable_set(self, name, value); }); + + $def(self, '$class_variable_defined?', function $Module_class_variable_defined$ques$8(name) { + var self = this; - return self.slice(number); + + name = $Opal['$class_variable_name!'](name); + return Opal.class_variables(self).hasOwnProperty(name); }); - }, $Array_drop$42.$$arity = 1); + $def(self, '$const_added', $return_val(nil)); + $Opal.$pristine(self, "const_added"); - Opal.def(self, '$dup', $Array_dup$43 = function $$dup() { - var $iter = $Array_dup$43.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + $def(self, '$remove_class_variable', function $$remove_class_variable(name) { + var self = this; - if ($iter) $Array_dup$43.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } + $deny_frozen_access(self); + name = $Opal['$class_variable_name!'](name); - if (self.$$class === Opal.Array && - self.$$class.$allocate.$$pristine && - self.$copy_instance_variables.$$pristine && - self.$initialize_dup.$$pristine) { - return self.slice(0); + if (Opal.hasOwnProperty.call(self.$$cvars, name)) { + var value = self.$$cvars[name]; + delete self.$$cvars[name]; + return value; + } else { + $Kernel.$raise($$$('NameError'), "cannot remove " + (name) + " for " + (self)); } - ; - return $send(self, Opal.find_super_dispatcher(self, 'dup', $Array_dup$43, false), $zuper, $iter); - }, $Array_dup$43.$$arity = 0); + }); - Opal.def(self, '$each', $Array_each$44 = function $$each() { - var $iter = $Array_each$44.$$p, block = $iter || nil, $$45, self = this; + $def(self, '$constants', function $$constants(inherit) { + var self = this; - if ($iter) $Array_each$44.$$p = null; + if (inherit == null) inherit = true; + return Opal.constants(self, inherit); }, -1); + $defs(self, '$constants', function $$constants(inherit) { + var self = this; - if ($iter) $Array_each$44.$$p = null;; - if ((block !== nil)) { + if (inherit == null) { + var nesting = (self.$$nesting || []).concat($Object), + constant, constants = {}, + i, ii; + + for(i = 0, ii = nesting.length; i < ii; i++) { + for (constant in nesting[i].$$const) { + constants[constant] = true; + } + } + return Object.keys(constants); } else { - return $send(self, 'enum_for', ["each"], ($$45 = function(){var self = $$45.$$s || this; + return Opal.constants(self, inherit) + } + }, -1); + $defs(self, '$nesting', function $$nesting() { + var self = this; + + return self.$$nesting || []; + }); + + $def(self, '$const_defined?', function $Module_const_defined$ques$9(name, inherit) { + var self = this; - return self.$size()}, $$45.$$s = self, $$45.$$arity = 0, $$45)) - }; - for (var i = 0, length = self.length; i < length; i++) { - var value = Opal.yield1(block, self[i]); + if (inherit == null) inherit = true; + name = $$('Opal')['$const_name!'](name); + if (!$truthy(name['$=~']($$$($Opal, 'CONST_NAME_REGEXP')))) { + $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name)); + } + var module, modules = [self], i, ii; + + // Add up ancestors if inherit is true + if (inherit) { + modules = modules.concat(Opal.ancestors(self)); + + // Add Object's ancestors if it's a module – modules have no ancestors otherwise + if (self.$$is_module) { + modules = modules.concat([$Object]).concat(Opal.ancestors($Object)); + } } - ; - return self; - }, $Array_each$44.$$arity = 0); + + for (i = 0, ii = modules.length; i < ii; i++) { + module = modules[i]; + if (module.$$const[name] != null) { return true; } + if ( + module.$$autoload && + module.$$autoload[name] && + !module.$$autoload[name].required && + !module.$$autoload[name].success + ) { + return true; + } + } + + return false; + }, -2); - Opal.def(self, '$each_index', $Array_each_index$46 = function $$each_index() { - var $iter = $Array_each_index$46.$$p, block = $iter || nil, $$47, self = this; + $def(self, '$const_get', function $$const_get(name, inherit) { + var self = this; - if ($iter) $Array_each_index$46.$$p = null; + if (inherit == null) inherit = true; + name = $$('Opal')['$const_name!'](name); - if ($iter) $Array_each_index$46.$$p = null;; - if ((block !== nil)) { + if (name.indexOf('::') === 0 && name !== '::'){ + name = name.slice(2); + } + if ($truthy(name.indexOf('::') != -1 && name != '::')) { + return $send(name.$split("::"), 'inject', [self], function $$10(o, c){ + + if (o == null) o = nil; + if (c == null) c = nil; + return o.$const_get(c);}) + } if (!$truthy(name['$=~']($$$($Opal, 'CONST_NAME_REGEXP')))) { + $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name)); + } + if (inherit) { + return Opal.$$([self], name); } else { - return $send(self, 'enum_for', ["each_index"], ($$47 = function(){var self = $$47.$$s || this; - - return self.$size()}, $$47.$$s = self, $$47.$$arity = 0, $$47)) - }; - - for (var i = 0, length = self.length; i < length; i++) { - var value = Opal.yield1(block, i); + return Opal.const_get_local(self, name); } - ; - return self; - }, $Array_each_index$46.$$arity = 0); + }, -2); - Opal.def(self, '$empty?', $Array_empty$ques$48 = function() { - var self = this; + $def(self, '$const_missing', function $$const_missing(name) { + var self = this, full_const_name = nil; - return self.length === 0; - }, $Array_empty$ques$48.$$arity = 0); + + full_const_name = ($eqeq(self, $Object) ? (name) : ("" + (self) + "::" + (name))); + return $Kernel.$raise($$$('NameError').$new("uninitialized constant " + (full_const_name), name)); + }); - Opal.def(self, '$eql?', $Array_eql$ques$49 = function(other) { + $def(self, '$const_set', function $$const_set(name, value) { var self = this; - var recursed = {}; - - function _eql(array, other) { - var i, length, a, b; - - if (!other.$$is_array) { - return false; - } + $deny_frozen_access(self); + name = $Opal['$const_name!'](name); + if (($truthy(name['$!~']($$$($Opal, 'CONST_NAME_REGEXP'))) || ($truthy(name['$start_with?']("::"))))) { + $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name)); + } $const_set(self, name, value); + return value; + }); + + $def(self, '$public_constant', $return_val(nil)); + + $def(self, '$define_method', function $$define_method(name, method) { + var block = $$define_method.$$p || nil, self = this, $ret_or_1 = nil, $ret_or_2 = nil; - other = other.$to_a(); + $$define_method.$$p = null; + + $deny_frozen_access(self); - if (array.length !== other.length) { - return false; - } + if (method === undefined && block === nil) + $Kernel.$raise($$$('ArgumentError'), "tried to create a Proc object without a block") + ; + block = ($truthy(($ret_or_1 = block)) ? ($ret_or_1) : ($eqeqeq($$$('Proc'), ($ret_or_2 = method)) ? (method) : ($eqeqeq($$$('Method'), $ret_or_2) ? (method.$to_proc().$$unbound) : ($eqeqeq($$$('UnboundMethod'), $ret_or_2) ? ($lambda(function $$11($a){var $post_args, args, self = $$11.$$s == null ? this : $$11.$$s, bound = nil; - recursed[(array).$object_id()] = true; + + $post_args = $slice(arguments); + args = $post_args; + bound = method.$bind(self); + return $send(bound, 'call', $to_a(args));}, {$$arity: -1, $$s: self})) : ($Kernel.$raise($$$('TypeError'), "wrong argument type " + (block.$class()) + " (expected Proc/Method)")))))); + + if (typeof(Proxy) !== 'undefined') { - for (i = 0, length = array.length; i < length; i++) { - a = array[i]; - b = other[i]; - if (a.$$is_array) { - if (b.$$is_array && b.length !== a.length) { - return false; - } - if (!recursed.hasOwnProperty((a).$object_id())) { - if (!_eql(a, b)) { - return false; - } - } - } else { - if (!(a)['$eql?'](b)) { - return false; + block.$$proxy_target = block; + block = new Proxy(block, { + apply: function(target, self, args) { + var old_name = target.$$jsid; + target.$$jsid = name; + try { + return target.apply(self, args); + } catch(e) { + if (e === target.$$brk || e === target.$$ret) return e.$v; + throw e; + } finally { + target.$$jsid = old_name; } } - } - - return true; + }); } - return _eql(self, other); - - }, $Array_eql$ques$49.$$arity = 1); + block.$$jsid = name; + block.$$s = null; + block.$$def = block; + block.$$define_meth = true; + + return Opal.defn(self, $jsid(name), block); + }, -2); - Opal.def(self, '$fetch', $Array_fetch$50 = function $$fetch(index, defaults) { - var $iter = $Array_fetch$50.$$p, block = $iter || nil, self = this; + $def(self, '$freeze', function $$freeze() { + var self = this; - if ($iter) $Array_fetch$50.$$p = null; + if ($truthy(self['$frozen?']())) { + return self + } + if (!self.hasOwnProperty('$$base_module')) { $prop(self, '$$base_module', null); } + + return $freeze(self); + }); + + $def(self, '$remove_method', function $$remove_method($a) { + var $post_args, names, self = this; + - if ($iter) $Array_fetch$50.$$p = null;; - ; + $post_args = $slice(arguments); + names = $post_args; - var original = index; - - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); + for (var i = 0; i < names.length; i++) { + var name = names[i]; + if (!(typeof name === "string" || name.$$is_string)) { + self.$raise($$$('TypeError'), "" + (self.$name()) + " is not a symbol nor a string"); + } + $deny_frozen_access(self); - if (index < 0) { - index += self.length; + Opal.rdef(self, "$" + name); } + return self; + }, -1); + + $def(self, '$singleton_class?', function $Module_singleton_class$ques$12() { + var self = this; - if (index >= 0 && index < self.length) { - return self[index]; - } + return !!self.$$is_singleton; + }); + + $def(self, '$include', function $$include($a) { + var $post_args, mods, self = this; - if (block !== nil && defaults != null) { - self.$warn("warning: block supersedes default value argument") - } + + $post_args = $slice(arguments); + mods = $post_args; + + for (var i = mods.length - 1; i >= 0; i--) { + var mod = mods[i]; - if (block !== nil) { - return block(original); - } + if (!mod.$$is_module) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)"); + } - if (defaults != null) { - return defaults; + (mod).$append_features(self); + (mod).$included(self); } + return self; + }, -1); + + $def(self, '$included_modules', function $$included_modules() { + var self = this; - if (self.length === 0) { - self.$raise($$($nesting, 'IndexError'), "" + "index " + (original) + " outside of array bounds: 0...0") - } - else { - self.$raise($$($nesting, 'IndexError'), "" + "index " + (original) + " outside of array bounds: -" + (self.length) + "..." + (self.length)); - } - ; - }, $Array_fetch$50.$$arity = -2); + return Opal.included_modules(self); + }); - Opal.def(self, '$fill', $Array_fill$51 = function $$fill($a) { - var $iter = $Array_fill$51.$$p, block = $iter || nil, $post_args, args, $b, $c, self = this, one = nil, two = nil, obj = nil, left = nil, right = nil; + $def(self, '$include?', function $Module_include$ques$13(mod) { + var self = this; - if ($iter) $Array_fill$51.$$p = null; - - - if ($iter) $Array_fill$51.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - var i, length, value;; - if ($truthy(block)) { - - if ($truthy(args.length > 2)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (args.$length()) + " for 0..2)")}; - $c = args, $b = Opal.to_ary($c), (one = ($b[0] == null ? nil : $b[0])), (two = ($b[1] == null ? nil : $b[1])), $c; - } else { - - if ($truthy(args.length == 0)) { - self.$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (0 for 1..3)") - } else if ($truthy(args.length > 3)) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (args.$length()) + " for 1..3)")}; - $c = args, $b = Opal.to_ary($c), (obj = ($b[0] == null ? nil : $b[0])), (one = ($b[1] == null ? nil : $b[1])), (two = ($b[2] == null ? nil : $b[2])), $c; - }; - if ($truthy($$($nesting, 'Range')['$==='](one))) { - - if ($truthy(two)) { - self.$raise($$($nesting, 'TypeError'), "length invalid with range")}; - left = $$($nesting, 'Opal').$coerce_to(one.$begin(), $$($nesting, 'Integer'), "to_int"); - if ($truthy(left < 0)) { - left += this.length}; - if ($truthy(left < 0)) { - self.$raise($$($nesting, 'RangeError'), "" + (one.$inspect()) + " out of range")}; - right = $$($nesting, 'Opal').$coerce_to(one.$end(), $$($nesting, 'Integer'), "to_int"); - if ($truthy(right < 0)) { - right += this.length}; - if ($truthy(one['$exclude_end?']())) { - } else { - right += 1 - }; - if ($truthy(right <= left)) { - return self}; - } else if ($truthy(one)) { - - left = $$($nesting, 'Opal').$coerce_to(one, $$($nesting, 'Integer'), "to_int"); - if ($truthy(left < 0)) { - left += this.length}; - if ($truthy(left < 0)) { - left = 0}; - if ($truthy(two)) { - - right = $$($nesting, 'Opal').$coerce_to(two, $$($nesting, 'Integer'), "to_int"); - if ($truthy(right == 0)) { - return self}; - right += left; - } else { - right = this.length - }; - } else { - - left = 0; - right = this.length; - }; - if ($truthy(left > this.length)) { - - for (i = this.length; i < right; i++) { - self[i] = nil; - } - }; - if ($truthy(right > this.length)) { - this.length = right}; - if ($truthy(block)) { - - for (length = this.length; left < right; left++) { - value = block(left); - self[left] = value; - } - - } else { - - for (length = this.length; left < right; left++) { - self[left] = obj; - } - }; - return self; - }, $Array_fill$51.$$arity = -1); + if (!mod.$$is_module) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)"); + } + + var i, ii, mod2, ancestors = Opal.ancestors(self); + + for (i = 0, ii = ancestors.length; i < ii; i++) { + mod2 = ancestors[i]; + if (mod2 === mod && mod2 !== self) { + return true; + } + } + + return false; + + }); - Opal.def(self, '$first', $Array_first$52 = function $$first(count) { + $def(self, '$instance_method', function $$instance_method(name) { var self = this; - ; - - if (count == null) { - return self.length === 0 ? nil : self[0]; - } + var meth = self.$$prototype[$jsid(name)]; - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); - - if (count < 0) { - self.$raise($$($nesting, 'ArgumentError'), "negative array size"); + if (!meth || meth.$$stub) { + $Kernel.$raise($$$('NameError').$new("undefined method `" + (name) + "' for class `" + (self.$name()) + "'", name)); } - return self.slice(0, count); - ; - }, $Array_first$52.$$arity = -1); + return $$$('UnboundMethod').$new(self, meth.$$owner || self, meth, name); + + }); - Opal.def(self, '$flatten', $Array_flatten$53 = function $$flatten(level) { + $def(self, '$instance_methods', function $$instance_methods(include_super) { var self = this; - ; + if (include_super == null) include_super = true; - function _flatten(array, level) { - var result = [], - i, length, - item, ary; + if ($truthy(include_super)) { + return Opal.instance_methods(self); + } else { + return Opal.own_instance_methods(self); + } + }, -1); + + $def(self, '$included', $return_val(nil)); + + $def(self, '$extended', $return_val(nil)); + + $def(self, '$extend_object', function $$extend_object(object) { + + + $deny_frozen_access(object); + return nil; + }); + + $def(self, '$method_added', function $$method_added($a) { - array = (array).$to_a(); + + $slice(arguments); + return nil; + }, -1); + + $def(self, '$method_removed', function $$method_removed($a) { - for (i = 0, length = array.length; i < length; i++) { - item = array[i]; + + $slice(arguments); + return nil; + }, -1); + + $def(self, '$method_undefined', function $$method_undefined($a) { - if (!$$($nesting, 'Opal')['$respond_to?'](item, "to_ary", true)) { - result.push(item); - continue; - } + + $slice(arguments); + return nil; + }, -1); + + $def(self, '$module_eval', function $$module_eval($a) { + var block = $$module_eval.$$p || nil, $post_args, args, $b, self = this, string = nil, file = nil, default_eval_options = nil, $ret_or_1 = nil, compiling_options = nil, compiled = nil; - ary = (item).$to_ary(); + $$module_eval.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (($truthy(block['$nil?']()) && ($truthy(!!Opal.compile)))) { + + if (!$truthy($range(1, 3, false)['$cover?'](args.$size()))) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)"); + } $b = [].concat($to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (($b[2] == null ? nil : $b[2])); + default_eval_options = $hash2(["file", "eval"], {"file": ($truthy(($ret_or_1 = file)) ? ($ret_or_1) : ("(eval)")), "eval": true}); + compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options); + compiled = $Opal.$compile(string, compiling_options); + block = $send($Kernel, 'proc', [], function $$14(){var self = $$14.$$s == null ? this : $$14.$$s; - if (ary === nil) { - result.push(item); - continue; - } + return new Function("Opal,self", "return " + compiled)(Opal, self);}, {$$s: self}); + } else if ($truthy(args['$any?']())) { + $Kernel.$raise($$$('ArgumentError'), "" + ("wrong number of arguments (" + (args.$size()) + " for 0)") + "\n\n NOTE:If you want to enable passing a String argument please add \"require 'opal-parser'\" to your script\n"); + } + var old = block.$$s, + result; - if (!ary.$$is_array) { - self.$raise($$($nesting, 'TypeError')); - } + block.$$s = null; + result = block.apply(self, [self]); + block.$$s = old; - if (ary === self) { - self.$raise($$($nesting, 'ArgumentError')); - } + return result; + }, -1); + + $def(self, '$module_exec', function $$module_exec($a) { + var block = $$module_exec.$$p || nil, $post_args, args, self = this; - switch (level) { - case undefined: - result = result.concat(_flatten(ary)); - break; - case 0: - result.push(ary); - break; - default: - result.push.apply(result, _flatten(ary, level - 1)); - } - } - return result; + $$module_exec.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + if (block === nil) { + $Kernel.$raise($$$('LocalJumpError'), "no block given"); } - if (level !== undefined) { - level = $$($nesting, 'Opal').$coerce_to(level, $$($nesting, 'Integer'), "to_int"); - } + var block_self = block.$$s, result; - return toArraySubclass(_flatten(self, level), self.$class()); - ; - }, $Array_flatten$53.$$arity = -1); + block.$$s = null; + result = block.apply(self, args); + block.$$s = block_self; + + return result; + }, -1); - Opal.def(self, '$flatten!', $Array_flatten$excl$54 = function(level) { + $def(self, '$method_defined?', function $Module_method_defined$ques$15(method) { var self = this; - ; + var body = self.$$prototype[$jsid(method)]; + return (!!body) && !body.$$stub; + + }); + + $def(self, '$module_function', function $$module_function($a) { + var $post_args, methods, self = this; + - var flattened = self.$flatten(level); + $post_args = $slice(arguments); + methods = $post_args; + + $deny_frozen_access(self); - if (self.length == flattened.length) { - for (var i = 0, length = self.length; i < length; i++) { - if (self[i] !== flattened[i]) { - break; - } - } + if (methods.length === 0) { + self.$$module_function = true; + return nil; + } + else { + for (var i = 0, length = methods.length; i < length; i++) { + var meth = methods[i], + id = $jsid(meth), + func = self.$$prototype[id]; - if (i == length) { - return nil; + Opal.defs(self, id, func); } + return methods.length === 1 ? methods[0] : methods; } - - self.$replace(flattened); - ; - return self; - }, $Array_flatten$excl$54.$$arity = -1); + }, -1); - Opal.def(self, '$hash', $Array_hash$55 = function $$hash() { + $def(self, '$name', function $$name() { var self = this; - var top = (Opal.hash_ids === undefined), - result = ['A'], - hash_id = self.$object_id(), - item, i, key; - - try { - if (top) { - Opal.hash_ids = Object.create(null); - } + if (self.$$full_name) { + return self.$$full_name; + } - // return early for recursive structures - if (Opal.hash_ids[hash_id]) { - return 'self'; - } + var result = [], base = self; - for (key in Opal.hash_ids) { - item = Opal.hash_ids[key]; - if (self['$eql?'](item)) { - return 'self'; - } - } + while (base) { + // Give up if any of the ancestors is unnamed + if (base.$$name === nil || base.$$name == null) return nil; - Opal.hash_ids[hash_id] = self; + result.unshift(base.$$name); - for (i = 0; i < self.length; i++) { - item = self[i]; - result.push(item.$hash()); - } + base = base.$$base_module; - return result.join(','); - } finally { - if (top) { - Opal.hash_ids = undefined; + if (base === $Object) { + break; } } - - }, $Array_hash$55.$$arity = 0); - - Opal.def(self, '$include?', $Array_include$ques$56 = function(member) { - var self = this; - - for (var i = 0, length = self.length; i < length; i++) { - if ((self[i])['$=='](member)) { - return true; - } + if (result.length === 0) { + return nil; } - return false; + return self.$$full_name = result.join('::'); - }, $Array_include$ques$56.$$arity = 1); + }); - Opal.def(self, '$index', $Array_index$57 = function $$index(object) { - var $iter = $Array_index$57.$$p, block = $iter || nil, self = this; + $def(self, '$prepend', function $$prepend($a) { + var $post_args, mods, self = this; - if ($iter) $Array_index$57.$$p = null; - - if ($iter) $Array_index$57.$$p = null;; - ; + $post_args = $slice(arguments); + mods = $post_args; - var i, length, value; - - if (object != null && block !== nil) { - self.$warn("warning: given block not used") + if (mods.length === 0) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (given 0, expected 1+)"); } - if (object != null) { - for (i = 0, length = self.length; i < length; i++) { - if ((self[i])['$=='](object)) { - return i; - } - } - } - else if (block !== nil) { - for (i = 0, length = self.length; i < length; i++) { - value = block(self[i]); + for (var i = mods.length - 1; i >= 0; i--) { + var mod = mods[i]; - if (value !== false && value !== nil) { - return i; - } + if (!mod.$$is_module) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)"); } + + (mod).$prepend_features(self); + (mod).$prepended(self); } - else { - return self.$enum_for("index"); + return self; + }, -1); + + $def(self, '$prepend_features', function $$prepend_features(prepender) { + var self = this; + + + + $deny_frozen_access(prepender); + + if (!self.$$is_module) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (self.$class()) + " (expected Module)"); } - return nil; + Opal.prepend_features(self, prepender) ; - }, $Array_index$57.$$arity = -1); + return self; + }); - Opal.def(self, '$insert', $Array_insert$58 = function $$insert(index, $a) { - var $post_args, objects, self = this; + $def(self, '$prepended', $return_val(nil)); + + $def(self, '$remove_const', function $$remove_const(name) { + var self = this; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - objects = $post_args;; - - index = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); + $deny_frozen_access(self); + return Opal.const_remove(self, name); }); + + $def(self, '$to_s', function $$to_s() { + var self = this, $ret_or_1 = nil; - if (objects.length > 0) { - if (index < 0) { - index += self.length + 1; + if ($truthy(($ret_or_1 = Opal.Module.$name.call(self)))) { + return $ret_or_1 + } else { + return "#<" + (self.$$is_module ? 'Module' : 'Class') + ":0x" + (self.$__id__().$to_s(16)) + ">" + } + }); + + $def(self, '$undef_method', function $$undef_method($a) { + var $post_args, names, self = this; - if (index < 0) { - self.$raise($$($nesting, 'IndexError'), "" + (index) + " is out of bounds"); - } - } - if (index > self.length) { - for (var i = self.length; i < index; i++) { - self.push(nil); - } + + $post_args = $slice(arguments); + names = $post_args; + + for (var i = 0; i < names.length; i++) { + var name = names[i]; + if (!(typeof name === "string" || name.$$is_string)) { + self.$raise($$$('TypeError'), "" + (self.$name()) + " is not a symbol nor a string"); } + $deny_frozen_access(self); - self.splice.apply(self, [index, 0].concat(objects)); + Opal.udef(self, "$" + names[i]); } - ; return self; - }, $Array_insert$58.$$arity = -2); + }, -1); - Opal.def(self, '$inspect', $Array_inspect$59 = function $$inspect() { - var self = this; + $def(self, '$instance_variables', function $$instance_variables() { + var self = this, consts = nil; - var result = [], - id = self.$__id__(); - - for (var i = 0, length = self.length; i < length; i++) { - var item = self['$[]'](i); + consts = (Opal.Module.$$nesting = $nesting, self.$constants()); + + var result = []; - if ((item).$__id__() === id) { - result.push('[...]'); - } - else { - result.push((item).$inspect()); + for (var name in self) { + if (self.hasOwnProperty(name) && name.charAt(0) !== '$' && name !== 'constructor' && !consts['$include?'](name)) { + result.push('@' + name); } } - return '[' + result.join(', ') + ']'; + return result; + }); + + $def(self, '$dup', function $$dup() { + var $yield = $$dup.$$p || nil, self = this, copy = nil; + + $$dup.$$p = null; + + copy = $send2(self, $find_super(self, 'dup', $$dup, false, true), 'dup', [], $yield); + copy.$copy_class_variables(self); + copy.$copy_constants(self); + return copy; + }); + + $def(self, '$copy_class_variables', function $$copy_class_variables(other) { + var self = this; + + + for (var name in other.$$cvars) { + self.$$cvars[name] = other.$$cvars[name]; + } - }, $Array_inspect$59.$$arity = 0); + }); - Opal.def(self, '$join', $Array_join$60 = function $$join(sep) { + $def(self, '$copy_constants', function $$copy_constants(other) { var self = this; - if ($gvars[","] == null) $gvars[","] = nil; + var name, other_constants = other.$$const; + + for (name in other_constants) { + $const_set(self, name, other_constants[name]); + } + + }); + + $def(self, '$refine', function $$refine(klass) { + var block = $$refine.$$p || nil, $a, self = this, refinement_module = nil, m = nil, klass_id = nil; + + $$refine.$$p = null; + $a = [self, nil, nil], (refinement_module = $a[0]), (m = $a[1]), (klass_id = $a[2]); - if (sep == null) { - sep = nil; - }; - if ($truthy(self.length === 0)) { - return ""}; - if ($truthy(sep === nil)) { - sep = $gvars[","]}; + klass_id = Opal.id(klass); + if (typeof self.$$refine_modules === "undefined") { + self.$$refine_modules = Object.create(null); + } + if (typeof self.$$refine_modules[klass_id] === "undefined") { + m = self.$$refine_modules[klass_id] = $$$('Refinement').$new(); + } + else { + m = self.$$refine_modules[klass_id]; + } + m.refinement_module = refinement_module; + m.refined_class = klass + ; + $send(m, 'class_exec', [], block.$to_proc()); + return m; + }); + + $def(self, '$refinements', function $$refinements() { + var self = this; + - var result = []; - var i, length, item, tmp; + var refine_modules = self.$$refine_modules, hash = $hash2([], {}); if (typeof refine_modules === "undefined") return hash; + for (var id in refine_modules) { + hash['$[]='](refine_modules[id].refined_class, refine_modules[id]); + } + return hash; + + }); + + $def(self, '$using', function $$using(mod) { + + return $Kernel.$raise("Module#using is not permitted in methods") + }); + $alias(self, "class_eval", "module_eval"); + $alias(self, "class_exec", "module_exec"); + return $alias(self, "inspect", "to_s"); + })('::', null, $nesting); + return (function($base, $super) { + var self = $klass($base, $super, 'Refinement'); - for (i = 0, length = self.length; i < length; i++) { - item = self[i]; + var $proto = self.$$prototype; - if ($$($nesting, 'Opal')['$respond_to?'](item, "to_str")) { - tmp = (item).$to_str(); + $proto.refinement_module = $proto.refined_class = nil; + + self.$attr_reader("refined_class"); + return $def(self, '$inspect', function $$inspect() { + var $yield = $$inspect.$$p || nil, self = this; - if (tmp !== nil) { - result.push((tmp).$to_s()); + $$inspect.$$p = null; + if ($truthy(self.refinement_module)) { + return "#<refinement:" + (self.refined_class.$inspect()) + "@" + (self.refinement_module.$inspect()) + ">" + } else { + return $send2(self, $find_super(self, 'inspect', $$inspect, false, true), 'inspect', [], $yield) + } + }); + })('::', $Module); +}; - continue; - } - } +Opal.modules["corelib/class"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $send = Opal.send, $defs = Opal.defs, $def = Opal.def, $rb_plus = Opal.rb_plus, $return_val = Opal.return_val, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $Kernel = Opal.Kernel, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - if ($$($nesting, 'Opal')['$respond_to?'](item, "to_ary")) { - tmp = (item).$to_ary(); + Opal.add_stubs('require,class_eval,to_proc,+,subclasses,flatten,map,initialize_copy,allocate,name,to_s,raise'); + + self.$require("corelib/module"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Class'); - if (tmp === self) { - self.$raise($$($nesting, 'ArgumentError')); - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (tmp !== nil) { - result.push((tmp).$join(sep)); + + $defs(self, '$new', function $Class_new$1(superclass) { + var block = $Class_new$1.$$p || nil; - continue; - } - } + $Class_new$1.$$p = null; + if (superclass == null) superclass = $$('Object'); + + if (!superclass.$$is_class) { + throw Opal.TypeError.$new("superclass must be a Class"); + } - if ($$($nesting, 'Opal')['$respond_to?'](item, "to_s")) { - tmp = (item).$to_s(); + var klass = Opal.allocate_class(nil, superclass); + superclass.$inherited(klass); + ((block !== nil) ? ($send((klass), 'class_eval', [], block.$to_proc())) : nil); + return klass; + }, -1); + + $def(self, '$allocate', function $$allocate() { + var self = this; - if (tmp !== nil) { - result.push(tmp); + + var obj = new self.$$constructor(); + obj.$$id = Opal.uid(); + return obj; + + }); + + $def(self, '$descendants', function $$descendants() { + var self = this; - continue; - } - } + return $rb_plus(self.$subclasses(), $send(self.$subclasses(), 'map', [], "descendants".$to_proc()).$flatten()) + }); + + $def(self, '$inherited', $return_val(nil)); + + $def(self, '$initialize_dup', function $$initialize_dup(original) { + var self = this; - self.$raise($$($nesting, 'NoMethodError').$new("" + (Opal.inspect(item)) + " doesn't respond to #to_str, #to_ary or #to_s", "to_str")); - } + + self.$initialize_copy(original); + + self.$$name = null; + self.$$full_name = null; + }); + + $def(self, '$new', function $Class_new$2($a) { + var block = $Class_new$2.$$p || nil, $post_args, args, self = this; - if (sep === nil) { - return result.join(''); + $Class_new$2.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + var object = self.$allocate(); + Opal.send(object, object.$initialize, args, block); + return object; + }, -1); + + $def(self, '$subclasses', function $$subclasses() { + var self = this; + + + if (typeof WeakRef !== 'undefined') { + var i, subclass, out = []; + for (i = 0; i < self.$$subclasses.length; i++) { + subclass = self.$$subclasses[i].deref(); + if (subclass !== undefined) { + out.push(subclass); + } + } + return out; } else { - return result.join($$($nesting, 'Opal')['$coerce_to!'](sep, $$($nesting, 'String'), "to_str").$to_s()); + return self.$$subclasses; } - ; - }, $Array_join$60.$$arity = -1); - Opal.def(self, '$keep_if', $Array_keep_if$61 = function $$keep_if() { - var $iter = $Array_keep_if$61.$$p, block = $iter || nil, $$62, self = this; + }); + + $def(self, '$superclass', function $$superclass() { + var self = this; - if ($iter) $Array_keep_if$61.$$p = null; - - - if ($iter) $Array_keep_if$61.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["keep_if"], ($$62 = function(){var self = $$62.$$s || this; + return self.$$super || nil; + }); + + $def(self, '$to_s', function $$to_s() { + var self = this; - return self.$size()}, $$62.$$s = self, $$62.$$arity = 0, $$62)) - }; + $$to_s.$$p = null; - for (var i = 0, length = self.length, value; i < length; i++) { - value = block(self[i]); - - if (value === false || value === nil) { - self.splice(i, 1); + var singleton_of = self.$$singleton_of; - length--; - i--; - } + if (singleton_of && singleton_of.$$is_a_module) { + return "#<Class:" + ((singleton_of).$name()) + ">"; } - ; - return self; - }, $Array_keep_if$61.$$arity = 0); + else if (singleton_of) { + // a singleton class created from an object + return "#<Class:#<" + ((singleton_of.$$class).$name()) + ":0x" + ((Opal.id(singleton_of)).$to_s(16)) + ">>"; + } + + return $send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], null); + + }); - Opal.def(self, '$last', $Array_last$63 = function $$last(count) { + $def(self, '$attached_object', function $$attached_object() { var self = this; - ; - - if (count == null) { - return self.length === 0 ? nil : self[self.length - 1]; + if (self.$$singleton_of != null) { + return self.$$singleton_of; } + else { + $Kernel.$raise($$$('TypeError'), "`" + (self) + "' is not a singleton class"); + } + + }); + return $alias(self, "inspect", "to_s"); + })('::', null, $nesting); +}; - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); +Opal.modules["corelib/basic_object"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $slice = Opal.slice, $def = Opal.def, $alias = Opal.alias, $return_val = Opal.return_val, $Opal = Opal.Opal, $truthy = Opal.truthy, $range = Opal.range, $Kernel = Opal.Kernel, $to_a = Opal.to_a, $hash2 = Opal.hash2, $send = Opal.send, $eqeq = Opal.eqeq, $rb_ge = Opal.rb_ge, nil = Opal.nil, $$$ = Opal.$$$; - if (count < 0) { - self.$raise($$($nesting, 'ArgumentError'), "negative array size"); - } + Opal.add_stubs('==,raise,inspect,pristine,!,nil?,cover?,size,merge,compile,proc,[],first,>=,length,instance_variable_get,any?,new,caller'); + return (function($base, $super) { + var self = $klass($base, $super, 'BasicObject'); - if (count > self.length) { - count = self.length; - } + + + + $def(self, '$initialize', function $$initialize($a) { - return self.slice(self.length - count, self.length); - ; - }, $Array_last$63.$$arity = -1); + + $slice(arguments); + return nil; + }, -1); - Opal.def(self, '$length', $Array_length$64 = function $$length() { + $def(self, '$==', function $BasicObject_$eq_eq$1(other) { var self = this; - return self.length; - }, $Array_length$64.$$arity = 0); - Opal.alias(self, "map", "collect"); - Opal.alias(self, "map!", "collect!"); + return self === other; + }); - Opal.def(self, '$max', $Array_max$65 = function $$max(n) { - var $iter = $Array_max$65.$$p, block = $iter || nil, self = this; + $def(self, '$eql?', function $BasicObject_eql$ques$2(other) { + var self = this; - if ($iter) $Array_max$65.$$p = null; - - - if ($iter) $Array_max$65.$$p = null;; - ; - return $send(self.$each(), 'max', [n], block.$to_proc()); - }, $Array_max$65.$$arity = -1); + return self['$=='](other) + }); + $alias(self, "equal?", "=="); - Opal.def(self, '$min', $Array_min$66 = function $$min() { - var $iter = $Array_min$66.$$p, block = $iter || nil, self = this; + $def(self, '$__id__', function $$__id__() { + var self = this; - if ($iter) $Array_min$66.$$p = null; - - if ($iter) $Array_min$66.$$p = null;; - return $send(self.$each(), 'min', [], block.$to_proc()); - }, $Array_min$66.$$arity = 0); - - // Returns the product of from, from-1, ..., from - how_many + 1. - function descending_factorial(from, how_many) { - var count = how_many >= 0 ? 1 : 0; - while (how_many) { - count *= from; - from--; - how_many--; + if (self.$$id != null) { + return self.$$id; } - return count; - } - ; + Opal.prop(self, '$$id', Opal.uid()); + return self.$$id; + + }); - Opal.def(self, '$permutation', $Array_permutation$67 = function $$permutation(num) { - var $iter = $Array_permutation$67.$$p, block = $iter || nil, $$68, self = this, perm = nil, used = nil; + $def(self, '$__send__', function $$__send__(symbol, $a) { + var block = $$__send__.$$p || nil, $post_args, args, self = this; - if ($iter) $Array_permutation$67.$$p = null; - + $$__send__.$$p = null; + $post_args = $slice(arguments, 1); + args = $post_args; - if ($iter) $Array_permutation$67.$$p = null;; - ; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["permutation", num], ($$68 = function(){var self = $$68.$$s || this; + if (!symbol.$$is_string) { + self.$raise($$$('TypeError'), "" + (self.$inspect()) + " is not a symbol nor a string"); + } - return descending_factorial(self.length, num === undefined ? self.length : num);}, $$68.$$s = self, $$68.$$arity = 0, $$68)) - }; - - var permute, offensive, output; + var func = self[Opal.jsid(symbol)]; - if (num === undefined) { - num = self.length; - } - else { - num = $$($nesting, 'Opal').$coerce_to(num, $$($nesting, 'Integer'), "to_int") - } + if (func) { + if (block !== nil) { + func.$$p = block; + } - if (num < 0 || self.length < num) { - // no permutations, yield nothing - } - else if (num === 0) { - // exactly one permutation: the zero-length array - Opal.yield1(block, []) + return func.apply(self, args); } - else if (num === 1) { - // this is a special, easy case - for (var i = 0; i < self.length; i++) { - Opal.yield1(block, [self[i]]) - } + + if (block !== nil) { + self.$method_missing.$$p = block; } - else { - // this is the general case - (perm = $$($nesting, 'Array').$new(num)); - (used = $$($nesting, 'Array').$new(self.length, false)); - permute = function(num, perm, index, used, blk) { - self = this; - for(var i = 0; i < self.length; i++){ - if(used['$[]'](i)['$!']()) { - perm[index] = i; - if(index < num - 1) { - used[i] = true; - permute.call(self, num, perm, index + 1, used, blk); - used[i] = false; - } - else { - output = []; - for (var j = 0; j < perm.length; j++) { - output.push(self[perm[j]]); - } - Opal.yield1(blk, output); - } - } - } - } + return self.$method_missing.apply(self, [symbol].concat(args)); + }, -2); + + $def(self, '$!', $return_val(false)); + $Opal.$pristine("!"); + + $def(self, '$!=', function $BasicObject_$not_eq$3(other) { + var self = this; + + return self['$=='](other)['$!']() + }); + + $def(self, '$instance_eval', function $$instance_eval($a) { + var block = $$instance_eval.$$p || nil, $post_args, args, $b, self = this, string = nil, file = nil, default_eval_options = nil, $ret_or_1 = nil, compiling_options = nil, compiled = nil; - if ((block !== nil)) { - // offensive (both definitions) copy. - offensive = self.slice(); - permute.call(offensive, num, perm, 0, used, block); + $$instance_eval.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (($truthy(block['$nil?']()) && ($truthy(!!Opal.compile)))) { + + if (!$truthy($range(1, 3, false)['$cover?'](args.$size()))) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)"); + } $b = [].concat($to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (($b[2] == null ? nil : $b[2])); + default_eval_options = $hash2(["file", "eval"], {"file": ($truthy(($ret_or_1 = file)) ? ($ret_or_1) : ("(eval)")), "eval": true}); + compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options); + compiled = $Opal.$compile(string, compiling_options); + block = $send($Kernel, 'proc', [], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s; + + return new Function("Opal,self", "return " + compiled)(Opal, self);}, {$$s: self}); + } else if ((($truthy(block['$nil?']()) && ($truthy($rb_ge(args.$length(), 1)))) && ($eqeq(args.$first()['$[]'](0), "@")))) { + return self.$instance_variable_get(args.$first()) + } else if ($truthy(args['$any?']())) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$size()) + " for 0)"); + } + var old = block.$$s, + result; + + block.$$s = null; + + // Need to pass $$eval so that method definitions know if this is + // being done on a class/module. Cannot be compiler driven since + // send(:instance_eval) needs to work. + if (self.$$is_a_module) { + self.$$eval = true; + try { + result = block.call(self, self); } - else { - permute.call(self, num, perm, 0, used, block); + finally { + self.$$eval = false; } } - ; - return self; - }, $Array_permutation$67.$$arity = -1); + else { + result = block.call(self, self); + } + + block.$$s = old; + + return result; + }, -1); - Opal.def(self, '$repeated_permutation', $Array_repeated_permutation$69 = function $$repeated_permutation(n) { - var $$70, $iter = $Array_repeated_permutation$69.$$p, $yield = $iter || nil, self = this, num = nil; + $def(self, '$instance_exec', function $$instance_exec($a) { + var block = $$instance_exec.$$p || nil, $post_args, args, self = this; - if ($iter) $Array_repeated_permutation$69.$$p = null; - - num = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["repeated_permutation", num], ($$70 = function(){var self = $$70.$$s || this; + $$instance_exec.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "no block given"); + } + var block_self = block.$$s, + result; - if ($truthy($rb_ge(num, 0))) { - return self.$size()['$**'](num) - } else { - return 0 - }}, $$70.$$s = self, $$70.$$arity = 0, $$70)) - }; - - function iterate(max, buffer, self) { - if (buffer.length == max) { - var copy = buffer.slice(); - Opal.yield1($yield, copy) - return; + block.$$s = null; + + if (self.$$is_a_module) { + self.$$eval = true; + try { + result = block.apply(self, args); } - for (var i = 0; i < self.length; i++) { - buffer.push(self[i]); - iterate(max, buffer, self); - buffer.pop(); + finally { + self.$$eval = false; } } + else { + result = block.apply(self, args); + } - iterate(num, [], self.slice()); - ; - return self; - }, $Array_repeated_permutation$69.$$arity = 1); + block.$$s = block_self; + + return result; + }, -1); - Opal.def(self, '$pop', $Array_pop$71 = function $$pop(count) { - var self = this; + $def(self, '$singleton_method_added', function $$singleton_method_added($a) { - ; - if ($truthy(count === undefined)) { - - if ($truthy(self.length === 0)) { - return nil}; - return self.pop();}; - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); - if ($truthy(count < 0)) { - self.$raise($$($nesting, 'ArgumentError'), "negative array size")}; - if ($truthy(self.length === 0)) { - return []}; - if ($truthy(count > self.length)) { - return self.splice(0, self.length); - } else { - return self.splice(self.length - count, self.length); - }; - }, $Array_pop$71.$$arity = -1); + $slice(arguments); + return nil; + }, -1); - Opal.def(self, '$product', $Array_product$72 = function $$product($a) { - var $iter = $Array_product$72.$$p, block = $iter || nil, $post_args, args, self = this; + $def(self, '$singleton_method_removed', function $$singleton_method_removed($a) { - if ($iter) $Array_product$72.$$p = null; + $slice(arguments); + return nil; + }, -1); + + $def(self, '$singleton_method_undefined', function $$singleton_method_undefined($a) { + - if ($iter) $Array_product$72.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var result = (block !== nil) ? null : [], - n = args.length + 1, - counters = new Array(n), - lengths = new Array(n), - arrays = new Array(n), - i, m, subarray, len, resultlen = 1; + $slice(arguments); + return nil; + }, -1); + + $def(self, '$method_missing', function $$method_missing(symbol, $a) { + var $post_args, args, self = this, inspect_result = nil; + + $$method_missing.$$p = null; + $post_args = $slice(arguments, 1); + args = $post_args; + inspect_result = $Opal.$inspect(self); + return $Kernel.$raise($$$('NoMethodError').$new("undefined method `" + (symbol) + "' for " + (inspect_result), symbol, args), nil, $Kernel.$caller(1)); + }, -2); + $Opal.$pristine(self, "method_missing"); + return $def(self, '$respond_to_missing?', function $BasicObject_respond_to_missing$ques$5(method_name, include_all) { + return false; + }, -2); + })('::', null) +}; - arrays[0] = self; - for (i = 1; i < n; i++) { - arrays[i] = $$($nesting, 'Opal').$coerce_to(args[i - 1], $$($nesting, 'Array'), "to_ary"); - } +Opal.modules["corelib/kernel"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $Opal = Opal.Opal, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $freeze_props = Opal.freeze_props, $jsid = Opal.jsid, $module = Opal.module, $return_val = Opal.return_val, $def = Opal.def, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $ensure_kwargs = Opal.ensure_kwargs, $eqeq = Opal.eqeq, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $eqeqeq = Opal.eqeqeq, $return_self = Opal.return_self, $rb_le = Opal.rb_le, $extract_kwargs = Opal.extract_kwargs, $rb_lt = Opal.rb_lt, $Object = Opal.Object, $alias = Opal.alias, $klass = Opal.klass, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - for (i = 0; i < n; i++) { - len = arrays[i].length; - if (len === 0) { - return result || self; - } - resultlen *= len; - if (resultlen > 2147483647) { - self.$raise($$($nesting, 'RangeError'), "too big to product") - } - lengths[i] = len; - counters[i] = 0; - } + Opal.add_stubs('!,=~,==,object_id,raise,new,class,coerce_to?,<<,map,caller,nil?,allocate,copy_instance_variables,copy_singleton_methods,initialize_clone,frozen?,freeze,initialize_copy,define_method,singleton_class,to_proc,initialize_dup,for,empty?,pop,call,append_features,extend_object,extended,gets,__id__,include?,each,instance_variables,instance_variable_get,inspect,+,to_s,instance_variable_name!,respond_to?,to_int,coerce_to!,Integer,===,enum_for,result,any?,print,format,puts,<=,length,[],readline,<,first,split,to_str,exception,backtrace,rand,respond_to_missing?,pristine,try_convert!,expand_path,join,start_with?,new_seed,srand,tag,value,open,is_a?,__send__,yield_self,include'); + + (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); - outer_loop: for (;;) { - subarray = []; - for (i = 0; i < n; i++) { - subarray.push(arrays[i][counters[i]]); - } - if (result) { - result.push(subarray); - } else { - Opal.yield1(block, subarray) - } - m = n - 1; - counters[m]++; - while (counters[m] === lengths[m]) { - counters[m] = 0; - if (--m < 0) break outer_loop; - counters[m]++; - } - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return result || self; - ; - }, $Array_product$72.$$arity = -1); - Opal.def(self, '$push', $Array_push$73 = function $$push($a) { - var $post_args, objects, self = this; + + $def(self, '$=~', $return_val(false)); + + $def(self, '$!~', function $Kernel_$excl_tilde$1(obj) { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - objects = $post_args;; - - for (var i = 0, length = objects.length; i < length; i++) { - self.push(objects[i]); + return self['$=~'](obj)['$!']() + }); + + $def(self, '$===', function $Kernel_$eq_eq_eq$2(other) { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.$object_id()['$=='](other.$object_id())))) { + return $ret_or_1 + } else { + return self['$=='](other) } - ; - return self; - }, $Array_push$73.$$arity = -1); - Opal.alias(self, "append", "push"); + }); - Opal.def(self, '$rassoc', $Array_rassoc$74 = function $$rassoc(object) { + $def(self, '$<=>', function $Kernel_$lt_eq_gt$3(other) { var self = this; - for (var i = 0, length = self.length, item; i < length; i++) { - item = self[i]; + // set guard for infinite recursion + self.$$comparable = true; - if (item.length && item[1] !== undefined) { - if ((item[1])['$=='](object)) { - return item; - } - } + var x = self['$=='](other); + + if (x && x !== nil) { + return 0; } return nil; - }, $Array_rassoc$74.$$arity = 1); + }); - Opal.def(self, '$reject', $Array_reject$75 = function $$reject() { - var $iter = $Array_reject$75.$$p, block = $iter || nil, $$76, self = this; - - if ($iter) $Array_reject$75.$$p = null; - - - if ($iter) $Array_reject$75.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["reject"], ($$76 = function(){var self = $$76.$$s || this; + $def(self, '$method', function $$method(name) { + var self = this; - return self.$size()}, $$76.$$s = self, $$76.$$arity = 0, $$76)) - }; - var result = []; - - for (var i = 0, length = self.length, value; i < length; i++) { - value = block(self[i]); + var meth = self[$jsid(name)]; - if (value === false || value === nil) { - result.push(self[i]); - } + if (!meth || meth.$$stub) { + $Kernel.$raise($$$('NameError').$new("undefined method `" + (name) + "' for class `" + (self.$class()) + "'", name)); } - return result; - ; - }, $Array_reject$75.$$arity = 0); + + return $$$('Method').$new(self, meth.$$owner || self.$class(), meth, name); + + }); - Opal.def(self, '$reject!', $Array_reject$excl$77 = function() { - var $iter = $Array_reject$excl$77.$$p, block = $iter || nil, $$78, self = this, original = nil; + $def(self, '$methods', function $$methods(all) { + var self = this; - if ($iter) $Array_reject$excl$77.$$p = null; + if (all == null) all = true; - if ($iter) $Array_reject$excl$77.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["reject!"], ($$78 = function(){var self = $$78.$$s || this; - - return self.$size()}, $$78.$$s = self, $$78.$$arity = 0, $$78)) - }; - original = self.$length(); - $send(self, 'delete_if', [], block.$to_proc()); - if (self.$length()['$=='](original)) { - return nil + if ($truthy(all)) { + return Opal.methods(self); } else { - return self - }; - }, $Array_reject$excl$77.$$arity = 0); + return Opal.own_methods(self); + } + }, -1); - Opal.def(self, '$replace', $Array_replace$79 = function $$replace(other) { + $def(self, '$public_methods', function $$public_methods(all) { var self = this; - other = (function() {if ($truthy($$($nesting, 'Array')['$==='](other))) { - return other.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(other, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); + if (all == null) all = true; - self.splice(0, self.length); - self.push.apply(self, other); - ; - return self; - }, $Array_replace$79.$$arity = 1); + if ($truthy(all)) { + return Opal.methods(self); + } else { + return Opal.receiver_methods(self); + } + }, -1); - Opal.def(self, '$reverse', $Array_reverse$80 = function $$reverse() { - var self = this; + $def(self, '$Array', function $$Array(object) { + + + var coerced; - return self.slice(0).reverse(); - }, $Array_reverse$80.$$arity = 0); - - Opal.def(self, '$reverse!', $Array_reverse$excl$81 = function() { - var self = this; + if (object === nil) { + return []; + } - return self.reverse(); - }, $Array_reverse$excl$81.$$arity = 0); - - Opal.def(self, '$reverse_each', $Array_reverse_each$82 = function $$reverse_each() { - var $iter = $Array_reverse_each$82.$$p, block = $iter || nil, $$83, self = this; + if (object.$$is_array) { + return object; + } - if ($iter) $Array_reverse_each$82.$$p = null; - - - if ($iter) $Array_reverse_each$82.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["reverse_each"], ($$83 = function(){var self = $$83.$$s || this; + coerced = $Opal['$coerce_to?'](object, $$$('Array'), "to_ary"); + if (coerced !== nil) { return coerced; } - return self.$size()}, $$83.$$s = self, $$83.$$arity = 0, $$83)) - }; - $send(self.$reverse(), 'each', [], block.$to_proc()); - return self; - }, $Array_reverse_each$82.$$arity = 0); + coerced = $Opal['$coerce_to?'](object, $$$('Array'), "to_a"); + if (coerced !== nil) { return coerced; } + + return [object]; + + }); - Opal.def(self, '$rindex', $Array_rindex$84 = function $$rindex(object) { - var $iter = $Array_rindex$84.$$p, block = $iter || nil, self = this; + $def(self, '$at_exit', function $$at_exit() { + var block = $$at_exit.$$p || nil, $ret_or_1 = nil; + if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil; - if ($iter) $Array_rindex$84.$$p = null; + $$at_exit.$$p = null; + $gvars.__at_exit__ = ($truthy(($ret_or_1 = $gvars.__at_exit__)) ? ($ret_or_1) : ([])); + $gvars.__at_exit__['$<<'](block); + return block; + }); + + $def(self, '$caller', function $$caller(start, length) { - if ($iter) $Array_rindex$84.$$p = null;; - ; + if (start == null) start = 1; + if (length == null) length = nil; - var i, value; + var stack, result; - if (object != null && block !== nil) { - self.$warn("warning: given block not used") + stack = new Error().$backtrace(); + result = []; + + for (var i = start + 1, ii = stack.length; i < ii; i++) { + if (!stack[i].match(/runtime\.js/)) { + result.push(stack[i]); + } } + if (length != nil) result = result.slice(0, length); + return result; + }, -1); + + $def(self, '$caller_locations', function $$caller_locations($a) { + var $post_args, args, self = this; - if (object != null) { - for (i = self.length - 1; i >= 0; i--) { - if (i >= self.length) { - break; - } - if ((self[i])['$=='](object)) { - return i; - } + + $post_args = $slice(arguments); + args = $post_args; + return $send($send(self, 'caller', $to_a(args)), 'map', [], function $$4(loc){ + + if (loc == null) loc = nil; + return $$$($$$($$$('Thread'), 'Backtrace'), 'Location').$new(loc);}); + }, -1); + + $def(self, '$class', function $Kernel_class$5() { + var self = this; + + return self.$$class; + }); + + $def(self, '$copy_instance_variables', function $$copy_instance_variables(other) { + var self = this; + + + var keys = Object.keys(other), i, ii, name; + for (i = 0, ii = keys.length; i < ii; i++) { + name = keys[i]; + if (name.charAt(0) !== '$' && other.hasOwnProperty(name)) { + self[name] = other[name]; } } - else if (block !== nil) { - for (i = self.length - 1; i >= 0; i--) { - if (i >= self.length) { - break; - } + + }); + + $def(self, '$copy_singleton_methods', function $$copy_singleton_methods(other) { + var self = this; - value = block(self[i]); + + var i, name, names, length; - if (value !== false && value !== nil) { - return i; + if (other.hasOwnProperty('$$meta') && other.$$meta !== null) { + var other_singleton_class = Opal.get_singleton_class(other); + var self_singleton_class = Opal.get_singleton_class(self); + names = Object.getOwnPropertyNames(other_singleton_class.$$prototype); + + for (i = 0, length = names.length; i < length; i++) { + name = names[i]; + if (Opal.is_method(name)) { + self_singleton_class.$$prototype[name] = other_singleton_class.$$prototype[name]; } } + + self_singleton_class.$$const = Object.assign({}, other_singleton_class.$$const); + Object.setPrototypeOf( + self_singleton_class.$$prototype, + Object.getPrototypeOf(other_singleton_class.$$prototype) + ); } - else if (object == null) { - return self.$enum_for("rindex"); + + for (i = 0, names = Object.getOwnPropertyNames(other), length = names.length; i < length; i++) { + name = names[i]; + if (name.charAt(0) === '$' && name.charAt(1) !== '$' && other.hasOwnProperty(name)) { + self[name] = other[name]; + } } + + }); + + $def(self, '$clone', function $$clone($kwargs) { + var freeze, self = this, copy = nil; - return nil; - ; - }, $Array_rindex$84.$$arity = -1); + + $kwargs = $ensure_kwargs($kwargs); + + freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = nil; + if (!(($truthy(freeze['$nil?']()) || ($eqeq(freeze, true))) || ($eqeq(freeze, false)))) { + self.$raise($$('ArgumentError'), "unexpected value for freeze: " + (freeze.$class())); + } copy = self.$class().$allocate(); + copy.$copy_instance_variables(self); + copy.$copy_singleton_methods(self); + copy.$initialize_clone(self, $hash2(["freeze"], {"freeze": freeze})); + if (($eqeq(freeze, true) || (($truthy(freeze['$nil?']()) && ($truthy(self['$frozen?']())))))) { + copy.$freeze(); + } return copy; + }, -1); - Opal.def(self, '$rotate', $Array_rotate$85 = function $$rotate(n) { + $def(self, '$initialize_clone', function $$initialize_clone(other, $kwargs) { var self = this; + $kwargs = $ensure_kwargs($kwargs); - if (n == null) { - n = 1; - }; - n = $$($nesting, 'Opal').$coerce_to(n, $$($nesting, 'Integer'), "to_int"); - - var ary, idx, firstPart, lastPart; + $kwargs.$$smap["freeze"]; self.$initialize_copy(other); + return self; + }, -2); + + $def(self, '$define_singleton_method', function $$define_singleton_method(name, method) { + var block = $$define_singleton_method.$$p || nil, self = this; - if (self.length === 1) { - return self.slice(); - } - if (self.length === 0) { - return []; - } + $$define_singleton_method.$$p = null; + return $send(self.$singleton_class(), 'define_method', [name, method], block.$to_proc()); + }, -2); + + $def(self, '$dup', function $$dup() { + var self = this, copy = nil; - ary = self.slice(); - idx = n % ary.length; + + copy = self.$class().$allocate(); + copy.$copy_instance_variables(self); + copy.$initialize_dup(self); + return copy; + }); + + $def(self, '$initialize_dup', function $$initialize_dup(other) { + var self = this; - firstPart = ary.slice(idx); - lastPart = ary.slice(0, idx); - return firstPart.concat(lastPart); - ; - }, $Array_rotate$85.$$arity = -1); + return self.$initialize_copy(other) + }); - Opal.def(self, '$rotate!', $Array_rotate$excl$86 = function(cnt) { - var self = this, ary = nil; + $def(self, '$enum_for', function $$enum_for($a, $b) { + var block = $$enum_for.$$p || nil, $post_args, method, args, self = this; + $$enum_for.$$p = null; + $post_args = $slice(arguments); - - if (cnt == null) { - cnt = 1; - }; - - if (self.length === 0 || self.length === 1) { - return self; - } - ; - cnt = $$($nesting, 'Opal').$coerce_to(cnt, $$($nesting, 'Integer'), "to_int"); - ary = self.$rotate(cnt); - return self.$replace(ary); - }, $Array_rotate$excl$86.$$arity = -1); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'SampleRandom'); + if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each"; + args = $post_args; + return $send($$$('Enumerator'), 'for', [self, method].concat($to_a(args)), block.$to_proc()); + }, -1); + + $def(self, '$equal?', function $Kernel_equal$ques$6(other) { + var self = this; - var $nesting = [self].concat($parent_nesting), $SampleRandom_initialize$87, $SampleRandom_rand$88; + return self === other; + }); + + $def(self, '$exit', function $$exit(status) { + var $ret_or_1 = nil, block = nil; + if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil; - self.$$prototype.rng = nil; + if (status == null) status = true; + $gvars.__at_exit__ = ($truthy(($ret_or_1 = $gvars.__at_exit__)) ? ($ret_or_1) : ([])); + while (!($truthy($gvars.__at_exit__['$empty?']()))) { - Opal.def(self, '$initialize', $SampleRandom_initialize$87 = function $$initialize(rng) { - var self = this; - - return (self.rng = rng) - }, $SampleRandom_initialize$87.$$arity = 1); - return (Opal.def(self, '$rand', $SampleRandom_rand$88 = function $$rand(size) { - var self = this, random = nil; + block = $gvars.__at_exit__.$pop(); + block.$call(); + } + if (status.$$is_boolean) { + status = status ? 0 : 1; + } else { + status = $coerce_to(status, $$$('Integer'), 'to_int'); + } - - random = $$($nesting, 'Opal').$coerce_to(self.rng.$rand(size), $$($nesting, 'Integer'), "to_int"); - if ($truthy(random < 0)) { - self.$raise($$($nesting, 'RangeError'), "random value must be >= 0")}; - if ($truthy(random < size)) { - } else { - self.$raise($$($nesting, 'RangeError'), "random value must be less than Array size") - }; - return random; - }, $SampleRandom_rand$88.$$arity = 1), nil) && 'rand'; - })($nesting[0], null, $nesting); + Opal.exit(status); + return nil; + }, -1); - Opal.def(self, '$sample', $Array_sample$89 = function $$sample(count, options) { - var $a, self = this, o = nil, rng = nil; + $def(self, '$extend', function $$extend($a) { + var $post_args, mods, self = this; - ; - ; - if ($truthy(count === undefined)) { - return self.$at($$($nesting, 'Kernel').$rand(self.length))}; - if ($truthy(options === undefined)) { - if ($truthy((o = $$($nesting, 'Opal')['$coerce_to?'](count, $$($nesting, 'Hash'), "to_hash")))) { - - options = o; - count = nil; - } else { - - options = nil; - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); - } - } else { - - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); - options = $$($nesting, 'Opal').$coerce_to(options, $$($nesting, 'Hash'), "to_hash"); - }; - if ($truthy(($truthy($a = count) ? count < 0 : $a))) { - self.$raise($$($nesting, 'ArgumentError'), "count must be greater than 0")}; - if ($truthy(options)) { - rng = options['$[]']("random")}; - rng = (function() {if ($truthy(($truthy($a = rng) ? rng['$respond_to?']("rand") : $a))) { - return $$($nesting, 'SampleRandom').$new(rng) - } else { - return $$($nesting, 'Kernel') - }; return nil; })(); - if ($truthy(count)) { - } else { - return self[rng.$rand(self.length)] - }; + $post_args = $slice(arguments); + mods = $post_args; - - var abandon, spin, result, i, j, k, targetIndex, oldValue; - - if (count > self.length) { - count = self.length; + if (mods.length == 0) { + self.$raise($$$('ArgumentError'), "wrong number of arguments (given 0, expected 1+)"); } - switch (count) { - case 0: - return []; - break; - case 1: - return [self[rng.$rand(self.length)]]; - break; - case 2: - i = rng.$rand(self.length); - j = rng.$rand(self.length); - if (i === j) { - j = i === 0 ? i + 1 : i - 1; - } - return [self[i], self[j]]; - break; - default: - if (self.length / count > 3) { - abandon = false; - spin = 0; - - result = $$($nesting, 'Array').$new(count); - i = 1; - - result[0] = rng.$rand(self.length); - while (i < count) { - k = rng.$rand(self.length); - j = 0; - - while (j < i) { - while (k === result[j]) { - spin++; - if (spin > 100) { - abandon = true; - break; - } - k = rng.$rand(self.length); - } - if (abandon) { break; } - - j++; - } - - if (abandon) { break; } - - result[i] = k; - - i++; - } - - if (!abandon) { - i = 0; - while (i < count) { - result[i] = self[result[i]]; - i++; - } + $deny_frozen_access(self); - return result; - } - } + var singleton = self.$singleton_class(); - result = self.slice(); + for (var i = mods.length - 1; i >= 0; i--) { + var mod = mods[i]; - for (var c = 0; c < count; c++) { - targetIndex = rng.$rand(self.length); - oldValue = result[c]; - result[c] = result[targetIndex]; - result[targetIndex] = oldValue; - } + if (!mod.$$is_module) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)"); + } - return count === self.length ? result : (result)['$[]'](0, count); + (mod).$append_features(singleton); + (mod).$extend_object(self); + (mod).$extended(self); } - ; - }, $Array_sample$89.$$arity = -1); + return self; + }, -1); - Opal.def(self, '$select', $Array_select$90 = function $$select() { - var $iter = $Array_select$90.$$p, block = $iter || nil, $$91, self = this; + $def(self, '$freeze', function $$freeze() { + var self = this; - if ($iter) $Array_select$90.$$p = null; + if ($truthy(self['$frozen?']())) { + return self + } + if (typeof(self) === "object") { + $freeze_props(self); + return $freeze(self); + } + return self; + }); + + $def(self, '$frozen?', function $Kernel_frozen$ques$7() { + var self = this; + - if ($iter) $Array_select$90.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["select"], ($$91 = function(){var self = $$91.$$s || this; + switch (typeof(self)) { + case "string": + case "symbol": + case "number": + case "boolean": + return true; + case "object": + return (self.$$frozen || false); + default: + return false; + } + + }); + + $def(self, '$gets', function $$gets($a) { + var $post_args, args; + if ($gvars.stdin == null) $gvars.stdin = nil; - return self.$size()}, $$91.$$s = self, $$91.$$arity = 0, $$91)) - }; - var result = []; + $post_args = $slice(arguments); + args = $post_args; + return $send($gvars.stdin, 'gets', $to_a(args)); + }, -1); + + $def(self, '$hash', function $$hash() { + var self = this; - for (var i = 0, length = self.length, item, value; i < length; i++) { - item = self[i]; + return self.$__id__() + }); + + $def(self, '$initialize_copy', $return_val(nil)); + var inspect_stack = []; + + $def(self, '$inspect', function $$inspect() { + var self = this, ivs = nil, id = nil, pushed = nil, e = nil; - value = Opal.yield1(block, item); + return (function() { try { + try { + + ivs = ""; + id = self.$__id__(); + if ($truthy((inspect_stack)['$include?'](id))) { + ivs = " ..."; + } else { + + (inspect_stack)['$<<'](id); + pushed = true; + $send(self.$instance_variables(), 'each', [], function $$8(i){var self = $$8.$$s == null ? this : $$8.$$s, ivar = nil, inspect = nil; - if (Opal.truthy(value)) { - result.push(item); - } + + if (i == null) i = nil; + ivar = self.$instance_variable_get(i); + inspect = $$('Opal').$inspect(ivar); + return (ivs = $rb_plus(ivs, " " + (i) + "=" + (inspect)));}, {$$s: self}); + }; + return "#<" + (self.$class()) + ":0x" + (id.$to_s(16)) + (ivs) + ">"; + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) {(e = $err); + try { + return "#<" + (self.$class()) + ":0x" + (id.$to_s(16)) + ">" + } finally { Opal.pop_exception(); } + } else { throw $err; } } - - return result; - ; - }, $Array_select$90.$$arity = 0); + } finally { + ($truthy(pushed) ? ((inspect_stack).$pop()) : nil); + } })() + }); - Opal.def(self, '$select!', $Array_select$excl$92 = function() { - var $iter = $Array_select$excl$92.$$p, block = $iter || nil, $$93, self = this; + $def(self, '$instance_of?', function $Kernel_instance_of$ques$9(klass) { + var self = this; - if ($iter) $Array_select$excl$92.$$p = null; - - if ($iter) $Array_select$excl$92.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["select!"], ($$93 = function(){var self = $$93.$$s || this; + if (!klass.$$is_class && !klass.$$is_module) { + $Kernel.$raise($$$('TypeError'), "class or module required"); + } + + return self.$$class === klass; + + }); + + $def(self, '$instance_variable_defined?', function $Kernel_instance_variable_defined$ques$10(name) { + var self = this; - return self.$size()}, $$93.$$s = self, $$93.$$arity = 0, $$93)) - }; - var original = self.length; - $send(self, 'keep_if', [], block.$to_proc()); - return self.length === original ? nil : self; - ; - }, $Array_select$excl$92.$$arity = 0); + name = $Opal['$instance_variable_name!'](name); + return Opal.hasOwnProperty.call(self, name.substr(1)); }); - Opal.def(self, '$shift', $Array_shift$94 = function $$shift(count) { + $def(self, '$instance_variable_get', function $$instance_variable_get(name) { var self = this; - ; - if ($truthy(count === undefined)) { - - if ($truthy(self.length === 0)) { - return nil}; - return shiftNoArg(self);}; - count = $$($nesting, 'Opal').$coerce_to(count, $$($nesting, 'Integer'), "to_int"); - if ($truthy(count < 0)) { - self.$raise($$($nesting, 'ArgumentError'), "negative array size")}; - if ($truthy(self.length === 0)) { - return []}; - return self.splice(0, count);; - }, $Array_shift$94.$$arity = -1); - Opal.alias(self, "size", "length"); + name = $Opal['$instance_variable_name!'](name); + + var ivar = self[Opal.ivar(name.substr(1))]; + + return ivar == null ? nil : ivar; + }); - Opal.def(self, '$shuffle', $Array_shuffle$95 = function $$shuffle(rng) { + $def(self, '$instance_variable_set', function $$instance_variable_set(name, value) { var self = this; - ; - return self.$dup().$to_a()['$shuffle!'](rng); - }, $Array_shuffle$95.$$arity = -1); + $deny_frozen_access(self); + name = $Opal['$instance_variable_name!'](name); + return self[Opal.ivar(name.substr(1))] = value; }); - Opal.def(self, '$shuffle!', $Array_shuffle$excl$96 = function(rng) { + $def(self, '$remove_instance_variable', function $$remove_instance_variable(name) { var self = this; - ; + name = $Opal['$instance_variable_name!'](name); - var randgen, i = self.length, j, tmp; - - if (rng !== undefined) { - rng = $$($nesting, 'Opal')['$coerce_to?'](rng, $$($nesting, 'Hash'), "to_hash"); + var key = Opal.ivar(name.substr(1)), + val; + if (self.hasOwnProperty(key)) { + val = self[key]; + delete self[key]; + return val; + } + return $Kernel.$raise($$$('NameError'), "instance variable " + (name) + " not defined"); + }); + + $def(self, '$instance_variables', function $$instance_variables() { + var self = this; - if (rng !== nil) { - rng = rng['$[]']("random"); + + var result = [], ivar; - if (rng !== nil && rng['$respond_to?']("rand")) { - randgen = rng; + for (var name in self) { + if (self.hasOwnProperty(name) && name.charAt(0) !== '$') { + if (name.substr(-1) === '$') { + ivar = name.slice(0, name.length - 1); + } else { + ivar = name; } + result.push('@' + ivar); } } - while (i) { - if (randgen) { - j = randgen.$rand(i).$to_int(); - - if (j < 0) { - self.$raise($$($nesting, 'RangeError'), "" + "random number too small " + (j)) - } + return result; + + }); + + $def(self, '$Integer', function $$Integer(value, base) { + + var i, str, base_digits; - if (j >= i) { - self.$raise($$($nesting, 'RangeError'), "" + "random number too big " + (j)) + if (!value.$$is_string) { + if (base !== undefined) { + $Kernel.$raise($$$('ArgumentError'), "base specified for non string value"); + } + if (value === nil) { + $Kernel.$raise($$$('TypeError'), "can't convert nil into Integer"); + } + if (value.$$is_number) { + if (value === Infinity || value === -Infinity || isNaN(value)) { + $Kernel.$raise($$$('FloatDomainError'), value); } + return Math.floor(value); } - else { - j = self.$rand(i); + if (value['$respond_to?']("to_int")) { + i = value.$to_int(); + if (i !== nil) { + return i; + } } - - tmp = self[--i]; - self[i] = self[j]; - self[j] = tmp; + return $Opal['$coerce_to!'](value, $$$('Integer'), "to_i"); } - return self; - ; - }, $Array_shuffle$excl$96.$$arity = -1); - Opal.alias(self, "slice", "[]"); - - Opal.def(self, '$slice!', $Array_slice$excl$97 = function(index, length) { - var self = this, result = nil, range = nil, range_start = nil, range_end = nil, start = nil; + if (value === "0") { + return 0; + } - - ; - result = nil; - if ($truthy(length === undefined)) { - if ($truthy($$($nesting, 'Range')['$==='](index))) { - - range = index; - result = self['$[]'](range); - range_start = $$($nesting, 'Opal').$coerce_to(range.$begin(), $$($nesting, 'Integer'), "to_int"); - range_end = $$($nesting, 'Opal').$coerce_to(range.$end(), $$($nesting, 'Integer'), "to_int"); - - if (range_start < 0) { - range_start += self.length; - } + if (base === undefined) { + base = 0; + } else { + base = $coerce_to(base, $$$('Integer'), 'to_int'); + if (base === 1 || base < 0 || base > 36) { + $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base)); + } + } - if (range_end < 0) { - range_end += self.length; - } else if (range_end >= self.length) { - range_end = self.length - 1; - if (range.excl) { - range_end += 1; - } - } + str = value.toLowerCase(); - var range_length = range_end - range_start; - if (range.excl) { - range_end -= 1; - } else { - range_length += 1; - } + str = str.replace(/(\d)_(?=\d)/g, '$1'); - if (range_start < self.length && range_start >= 0 && range_end < self.length && range_end >= 0 && range_length > 0) { - self.splice(range_start, range_length); + str = str.replace(/^(\s*[+-]?)(0[bodx]?)/, function (_, head, flag) { + switch (flag) { + case '0b': + if (base === 0 || base === 2) { + base = 2; + return head; } - ; - } else { - - start = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); - - if (start < 0) { - start += self.length; + // no-break + case '0': + case '0o': + if (base === 0 || base === 8) { + base = 8; + return head; } - - if (start < 0 || start >= self.length) { - return nil; + // no-break + case '0d': + if (base === 0 || base === 10) { + base = 10; + return head; } - - result = self[start]; - - if (start === 0) { - self.shift(); - } else { - self.splice(start, 1); + // no-break + case '0x': + if (base === 0 || base === 16) { + base = 16; + return head; } - ; - } - } else { - - start = $$($nesting, 'Opal').$coerce_to(index, $$($nesting, 'Integer'), "to_int"); - length = $$($nesting, 'Opal').$coerce_to(length, $$($nesting, 'Integer'), "to_int"); - - if (length < 0) { - return nil; + // no-break } + $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\""); + }); - var end = start + length; + base = (base === 0 ? 10 : base); - result = self['$[]'](start, length); + base_digits = '0-' + (base <= 10 ? base - 1 : '9a-' + String.fromCharCode(97 + (base - 11))); - if (start < 0) { - start += self.length; - } + if (!(new RegExp('^\\s*[+-]?[' + base_digits + ']+\\s*$')).test(str)) { + $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\""); + } - if (start + length > self.length) { - length = self.length - start; - } + i = parseInt(str, base); - if (start < self.length && start >= 0) { - self.splice(start, length); - } - ; - }; - return result; - }, $Array_slice$excl$97.$$arity = -2); - - Opal.def(self, '$sort', $Array_sort$98 = function $$sort() { - var $iter = $Array_sort$98.$$p, block = $iter || nil, self = this; + if (isNaN(i)) { + $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\""); + } - if ($iter) $Array_sort$98.$$p = null; - + return i; + }, -2); + + $def(self, '$Float', function $$Float(value) { - if ($iter) $Array_sort$98.$$p = null;; - if ($truthy(self.length > 1)) { - } else { - return self - }; - if (block === nil) { - block = function(a, b) { - return (a)['$<=>'](b); - }; - } + var str; - return self.slice().sort(function(x, y) { - var ret = block(x, y); + if (value === nil) { + $Kernel.$raise($$$('TypeError'), "can't convert nil into Float"); + } - if (ret === nil) { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + ((x).$inspect()) + " with " + ((y).$inspect()) + " failed"); - } + if (value.$$is_string) { + str = value.toString(); - return $rb_gt(ret, 0) ? 1 : ($rb_lt(ret, 0) ? -1 : 0); - }); - ; - }, $Array_sort$98.$$arity = 0); - - Opal.def(self, '$sort!', $Array_sort$excl$99 = function() { - var $iter = $Array_sort$excl$99.$$p, block = $iter || nil, self = this; + str = str.replace(/(\d)_(?=\d)/g, '$1'); - if ($iter) $Array_sort$excl$99.$$p = null; - - - if ($iter) $Array_sort$excl$99.$$p = null;; - - var result; + //Special case for hex strings only: + if (/^\s*[-+]?0[xX][0-9a-fA-F]+\s*$/.test(str)) { + return $Kernel.$Integer(str); + } - if ((block !== nil)) { - result = $send((self.slice()), 'sort', [], block.$to_proc()); - } - else { - result = (self.slice()).$sort(); - } + if (!/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/.test(str)) { + $Kernel.$raise($$$('ArgumentError'), "invalid value for Float(): \"" + (value) + "\""); + } - self.length = 0; - for(var i = 0, length = result.length; i < length; i++) { - self.push(result[i]); + return parseFloat(str); } - return self; - ; - }, $Array_sort$excl$99.$$arity = 0); + return $Opal['$coerce_to!'](value, $$$('Float'), "to_f"); - Opal.def(self, '$sort_by!', $Array_sort_by$excl$100 = function() { - var $iter = $Array_sort_by$excl$100.$$p, block = $iter || nil, $$101, self = this; - - if ($iter) $Array_sort_by$excl$100.$$p = null; + }); + + $def(self, '$Hash', function $$Hash(arg) { - if ($iter) $Array_sort_by$excl$100.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["sort_by!"], ($$101 = function(){var self = $$101.$$s || this; - - return self.$size()}, $$101.$$s = self, $$101.$$arity = 0, $$101)) - }; - return self.$replace($send(self, 'sort_by', [], block.$to_proc())); - }, $Array_sort_by$excl$100.$$arity = 0); + if (($truthy(arg['$nil?']()) || ($eqeq(arg, [])))) { + return $hash2([], {}) + } if ($eqeqeq($$$('Hash'), arg)) { + return arg + } return $Opal['$coerce_to!'](arg, $$$('Hash'), "to_hash"); + }); - Opal.def(self, '$take', $Array_take$102 = function $$take(count) { + $def(self, '$is_a?', function $Kernel_is_a$ques$11(klass) { var self = this; - if (count < 0) { - self.$raise($$($nesting, 'ArgumentError')); + if (!klass.$$is_class && !klass.$$is_module) { + $Kernel.$raise($$$('TypeError'), "class or module required"); } - return self.slice(0, count); + return Opal.is_a(self, klass); + + }); - }, $Array_take$102.$$arity = 1); + $def(self, '$itself', $return_self); - Opal.def(self, '$take_while', $Array_take_while$103 = function $$take_while() { - var $iter = $Array_take_while$103.$$p, block = $iter || nil, self = this; + $def(self, '$lambda', function $$lambda() { + var block = $$lambda.$$p || nil; - if ($iter) $Array_take_while$103.$$p = null; - + $$lambda.$$p = null; + return Opal.lambda(block); }); + + $def(self, '$load', function $$load(file) { - if ($iter) $Array_take_while$103.$$p = null;; - var result = []; - - for (var i = 0, length = self.length, item, value; i < length; i++) { - item = self[i]; - - value = block(item); - - if (value === false || value === nil) { - return result; - } + file = $Opal['$coerce_to!'](file, $$$('String'), "to_str"); + return Opal.load(file); + }); + + $def(self, '$loop', function $$loop() { + var $yield = $$loop.$$p || nil, self = this, e = nil; - result.push(item); - } + $$loop.$$p = null; + + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["loop"], function $$12(){ + return $$$($$$('Float'), 'INFINITY')}) + } while ($truthy(true)) { + + try { + Opal.yieldX($yield, []); + } catch ($err) { + if (Opal.rescue($err, [$$$('StopIteration')])) {(e = $err); + try { + return e.$result() + } finally { Opal.pop_exception(); } + } else { throw $err; } + } } return self; + }); + + $def(self, '$nil?', $return_val(false)); + + $def(self, '$printf', function $$printf($a) { + var $post_args, args, self = this; - return result; - ; - }, $Array_take_while$103.$$arity = 0); + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy(args['$any?']())) { + self.$print($send(self, 'format', $to_a(args))); + } return nil; + }, -1); - Opal.def(self, '$to_a', $Array_to_a$104 = function $$to_a() { - var self = this; + $def(self, '$proc', function $$proc() { + var block = $$proc.$$p || nil; - return self - }, $Array_to_a$104.$$arity = 0); - Opal.alias(self, "to_ary", "to_a"); + $$proc.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to create Proc object without a block"); + } block.$$is_lambda = false; + return block; + }); - Opal.def(self, '$to_h', $Array_to_h$105 = function $$to_h() { - var self = this; + $def(self, '$puts', function $$puts($a) { + var $post_args, strs; + if ($gvars.stdout == null) $gvars.stdout = nil; - var i, len = self.length, ary, key, val, hash = $hash2([], {}); + $post_args = $slice(arguments); + strs = $post_args; + return $send($gvars.stdout, 'puts', $to_a(strs)); + }, -1); + + $def(self, '$p', function $$p($a) { + var $post_args, args; - for (i = 0; i < len; i++) { - ary = $$($nesting, 'Opal')['$coerce_to?'](self[i], $$($nesting, 'Array'), "to_ary"); - if (!ary.$$is_array) { - self.$raise($$($nesting, 'TypeError'), "" + "wrong element type " + ((ary).$class()) + " at " + (i) + " (expected array)") - } - if (ary.length !== 2) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong array length at " + (i) + " (expected 2, was " + ((ary).$length()) + ")") - } - key = ary[0]; - val = ary[1]; - Opal.hash_put(hash, key, val); - } + + $post_args = $slice(arguments); + args = $post_args; + $send(args, 'each', [], function $$13(obj){ if ($gvars.stdout == null) $gvars.stdout = nil; - return hash; - - }, $Array_to_h$105.$$arity = 0); - Opal.alias(self, "to_s", "inspect"); + + if (obj == null) obj = nil; + return $gvars.stdout.$puts(obj.$inspect());}); + if ($truthy($rb_le(args.$length(), 1))) { + return args['$[]'](0) + } else { + return args + } }, -1); - Opal.def(self, '$transpose', $Array_transpose$106 = function $$transpose() { - var $$107, self = this, result = nil, max = nil; + $def(self, '$print', function $$print($a) { + var $post_args, strs; + if ($gvars.stdout == null) $gvars.stdout = nil; - if ($truthy(self['$empty?']())) { - return []}; - result = []; - max = nil; - $send(self, 'each', [], ($$107 = function(row){var self = $$107.$$s || this, $a, $$108; + $post_args = $slice(arguments); + strs = $post_args; + return $send($gvars.stdout, 'print', $to_a(strs)); + }, -1); + + $def(self, '$readline', function $$readline($a) { + var $post_args, args; + if ($gvars.stdin == null) $gvars.stdin = nil; - - if (row == null) { - row = nil; - }; - row = (function() {if ($truthy($$($nesting, 'Array')['$==='](row))) { - return row.$to_a() - } else { - return $$($nesting, 'Opal').$coerce_to(row, $$($nesting, 'Array'), "to_ary").$to_a() - }; return nil; })(); - max = ($truthy($a = max) ? $a : row.length); - if ($truthy((row.length)['$!='](max))) { - self.$raise($$($nesting, 'IndexError'), "" + "element size differs (" + (row.length) + " should be " + (max) + ")")}; - return $send((row.length), 'times', [], ($$108 = function(i){var self = $$108.$$s || this, $b, entry = nil, $writer = nil; - - - - if (i == null) { - i = nil; - }; - entry = ($truthy($b = result['$[]'](i)) ? $b : (($writer = [i, []]), $send(result, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])); - return entry['$<<'](row.$at(i));}, $$108.$$s = self, $$108.$$arity = 1, $$108));}, $$107.$$s = self, $$107.$$arity = 1, $$107)); - return result; - }, $Array_transpose$106.$$arity = 0); + $post_args = $slice(arguments); + args = $post_args; + return $send($gvars.stdin, 'readline', $to_a(args)); + }, -1); - Opal.def(self, '$uniq', $Array_uniq$109 = function $$uniq() { - var $iter = $Array_uniq$109.$$p, block = $iter || nil, self = this; + $def(self, '$warn', function $$warn($a, $b) { + var $post_args, $kwargs, strs, uplevel, $c, $d, self = this, location = nil; + if ($gvars.VERBOSE == null) $gvars.VERBOSE = nil; + if ($gvars.stderr == null) $gvars.stderr = nil; - if ($iter) $Array_uniq$109.$$p = null; + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + strs = $post_args; - if ($iter) $Array_uniq$109.$$p = null;; + uplevel = $kwargs.$$smap["uplevel"];if (uplevel == null) uplevel = nil; + if ($truthy(uplevel)) { + + uplevel = $Opal['$coerce_to!'](uplevel, $$$('Integer'), "to_str"); + if ($truthy($rb_lt(uplevel, 0))) { + $Kernel.$raise($$$('ArgumentError'), "negative level (" + (uplevel) + ")"); + } location = ($c = ($d = self.$caller($rb_plus(uplevel, 1), 1).$first(), ($d === nil || $d == null) ? nil : $d.$split(":in `")), ($c === nil || $c == null) ? nil : $c.$first()); + if ($truthy(location)) { + location = "" + (location) + ": "; + } strs = $send(strs, 'map', [], function $$14(s){ + + if (s == null) s = nil; + return "" + (location) + "warning: " + (s);}); + } if (($truthy($gvars.VERBOSE['$nil?']()) || ($truthy(strs['$empty?']())))) { + return nil + } else { + return $send($gvars.stderr, 'puts', $to_a(strs)) + } }, -1); + + $def(self, '$raise', function $$raise(exception, string, backtrace) { + if ($gvars["!"] == null) $gvars["!"] = nil; + if ($gvars["@"] == null) $gvars["@"] = nil; + if (string == null) string = nil; + if (backtrace == null) backtrace = nil; - var hash = $hash2([], {}), i, length, item, key; - - if (block === nil) { - for (i = 0, length = self.length; i < length; i++) { - item = self[i]; - if (Opal.hash_get(hash, item) === undefined) { - Opal.hash_put(hash, item, item); - } - } + if (exception == null && $gvars["!"] !== nil) { + throw $gvars["!"]; + } + if (exception == null) { + exception = $$$('RuntimeError').$new(""); + } + else if ($respond_to(exception, '$to_str')) { + exception = $$$('RuntimeError').$new(exception.$to_str()); + } + // using respond_to? and not an undefined check to avoid method_missing matching as true + else if (exception.$$is_class && $respond_to(exception, '$exception')) { + exception = exception.$exception(string); } + else if (exception.$$is_exception) ; else { - for (i = 0, length = self.length; i < length; i++) { - item = self[i]; - key = Opal.yield1(block, item); - if (Opal.hash_get(hash, key) === undefined) { - Opal.hash_put(hash, key, item); - } - } + exception = $$$('TypeError').$new("exception class/object expected"); } - return toArraySubclass((hash).$values(), self.$class()); - ; - }, $Array_uniq$109.$$arity = 0); - - Opal.def(self, '$uniq!', $Array_uniq$excl$110 = function() { - var $iter = $Array_uniq$excl$110.$$p, block = $iter || nil, self = this; + if (backtrace !== nil) { + exception.$set_backtrace(backtrace); + } - if ($iter) $Array_uniq$excl$110.$$p = null; - - - if ($iter) $Array_uniq$excl$110.$$p = null;; + if ($gvars["!"] !== nil) { + Opal.exceptions.push($gvars["!"]); + } + + $gvars["!"] = exception; + $gvars["@"] = (exception).$backtrace(); + + throw exception; + }, -1); + + $def(self, '$rand', function $$rand(max) { - var original_length = self.length, hash = $hash2([], {}), i, length, item, key; + if (max === undefined) { + return $$$($$$('Random'), 'DEFAULT').$rand(); + } - for (i = 0, length = original_length; i < length; i++) { - item = self[i]; - key = (block === nil ? item : Opal.yield1(block, item)); + if (max.$$is_number) { + if (max < 0) { + max = Math.abs(max); + } - if (Opal.hash_get(hash, key) === undefined) { - Opal.hash_put(hash, key, item); - continue; + if (max % 1 !== 0) { + max = max.$to_i(); } - self.splice(i, 1); - length--; - i--; + if (max === 0) { + max = undefined; + } } - - return self.length === original_length ? nil : self; - ; - }, $Array_uniq$excl$110.$$arity = 0); + return $$$($$$('Random'), 'DEFAULT').$rand(max); + }, -1); - Opal.def(self, '$unshift', $Array_unshift$111 = function $$unshift($a) { - var $post_args, objects, self = this; + $def(self, '$respond_to?', function $Kernel_respond_to$ques$15(name, include_all) { + var self = this; + if (include_all == null) include_all = false; - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - objects = $post_args;; - - for (var i = objects.length - 1; i >= 0; i--) { - self.unshift(objects[i]); + var body = self[$jsid(name)]; + + if (typeof(body) === "function" && !body.$$stub) { + return true; } - ; - return self; - }, $Array_unshift$111.$$arity = -1); - Opal.alias(self, "prepend", "unshift"); - - Opal.def(self, '$values_at', $Array_values_at$112 = function $$values_at($a) { - var $post_args, args, $$113, self = this, out = nil; + if (self['$respond_to_missing?'].$$pristine === true) { + return false; + } else { + return self['$respond_to_missing?'](name, include_all); + } + }, -2); + + $def(self, '$respond_to_missing?', function $Kernel_respond_to_missing$ques$16(method_name, include_all) { + return false; + }, -2); + $Opal.$pristine(self, "respond_to?", "respond_to_missing?"); + + $def(self, '$require', function $$require(file) { - $post_args = Opal.slice.call(arguments, 0, arguments.length); + // As Object.require refers to Kernel.require once Kernel has been loaded the String + // class may not be available yet, the coercion requires both String and Array to be loaded. + if (typeof file !== 'string' && Opal.String && Opal.Array) { + (file = $Opal['$coerce_to!'](file, $$$('String'), "to_str")); + } + return Opal.require(file) + + }); + + $def(self, '$require_relative', function $$require_relative(file) { - args = $post_args;; - out = []; - $send(args, 'each', [], ($$113 = function(elem){var self = $$113.$$s || this, $$114, finish = nil, start = nil, i = nil; - - - if (elem == null) { - elem = nil; - }; - if ($truthy(elem['$is_a?']($$($nesting, 'Range')))) { - - finish = $$($nesting, 'Opal').$coerce_to(elem.$last(), $$($nesting, 'Integer'), "to_int"); - start = $$($nesting, 'Opal').$coerce_to(elem.$first(), $$($nesting, 'Integer'), "to_int"); - - if (start < 0) { - start = start + self.length; - return nil;; - } - ; - - if (finish < 0) { - finish = finish + self.length; - } - if (elem['$exclude_end?']()) { - finish--; - } - if (finish < start) { - return nil;; - } - ; - return $send(start, 'upto', [finish], ($$114 = function(i){var self = $$114.$$s || this; - - - - if (i == null) { - i = nil; - }; - return out['$<<'](self.$at(i));}, $$114.$$s = self, $$114.$$arity = 1, $$114)); - } else { - - i = $$($nesting, 'Opal').$coerce_to(elem, $$($nesting, 'Integer'), "to_int"); - return out['$<<'](self.$at(i)); - };}, $$113.$$s = self, $$113.$$arity = 1, $$113)); - return out; - }, $Array_values_at$112.$$arity = -1); + $Opal['$try_convert!'](file, $$$('String'), "to_str"); + file = $$$('File').$expand_path($$$('File').$join(Opal.current_file, "..", file)); + return Opal.require(file); + }); - Opal.def(self, '$zip', $Array_zip$115 = function $$zip($a) { - var $iter = $Array_zip$115.$$p, block = $iter || nil, $post_args, others, $b, self = this; + $def(self, '$require_tree', function $$require_tree(path, $kwargs) { + var autoload; - if ($iter) $Array_zip$115.$$p = null; - - - if ($iter) $Array_zip$115.$$p = null;; - $post_args = Opal.slice.call(arguments, 0, arguments.length); + $kwargs = $ensure_kwargs($kwargs); - others = $post_args;; + autoload = $kwargs.$$smap["autoload"];if (autoload == null) autoload = false; - var result = [], size = self.length, part, o, i, j, jj; + var result = []; - for (j = 0, jj = others.length; j < jj; j++) { - o = others[j]; - if (o.$$is_array) { - continue; - } - if (o.$$is_enumerator) { - if (o.$size() === Infinity) { - others[j] = o.$take(size); + path = $$$('File').$expand_path(path); + path = Opal.normalize(path); + if (path === '.') path = ''; + for (var name in Opal.modules) { + if ((name)['$start_with?'](path)) { + if(!autoload) { + result.push([name, Opal.require(name)]); } else { - others[j] = o.$to_a(); + result.push([name, true]); // do nothing, delegated to a autoloading } - continue; } - others[j] = ($truthy($b = $$($nesting, 'Opal')['$coerce_to?'](o, $$($nesting, 'Array'), "to_ary")) ? $b : $$($nesting, 'Opal')['$coerce_to!'](o, $$($nesting, 'Enumerator'), "each")).$to_a(); } - for (i = 0; i < size; i++) { - part = [self[i]]; - - for (j = 0, jj = others.length; j < jj; j++) { - o = others[j][i]; - - if (o == null) { - o = nil; - } - - part[j + 1] = o; - } + return result; + }, -2); + + $def(self, '$singleton_class', function $$singleton_class() { + var self = this; - result[i] = part; + return Opal.get_singleton_class(self); + }); + + $def(self, '$sleep', function $$sleep(seconds) { + + + if (seconds == null) seconds = nil; + + if (seconds === nil) { + $Kernel.$raise($$$('TypeError'), "can't convert NilClass into time interval"); + } + if (!seconds.$$is_number) { + $Kernel.$raise($$$('TypeError'), "can't convert " + (seconds.$class()) + " into time interval"); + } + if (seconds < 0) { + $Kernel.$raise($$$('ArgumentError'), "time interval must be positive"); } + var get_time = Opal.global.performance ? + function() {return performance.now()} : + function() {return new Date()}; - if (block !== nil) { - for (i = 0; i < size; i++) { - block(result[i]); - } + var t = get_time(); + while (get_time() - t <= seconds * 1000); + return Math.round(seconds); + }, -1); + + $def(self, '$srand', function $$srand(seed) { + + + if (seed == null) seed = $$('Random').$new_seed(); + return $$$('Random').$srand(seed); + }, -1); + + $def(self, '$String', function $$String(str) { + var $ret_or_1 = nil; - return nil; + if ($truthy(($ret_or_1 = $Opal['$coerce_to?'](str, $$$('String'), "to_str")))) { + return $ret_or_1 + } else { + return $Opal['$coerce_to!'](str, $$$('String'), "to_s") } + }); + + $def(self, '$tap', function $$tap() { + var block = $$tap.$$p || nil, self = this; - return result; - ; - }, $Array_zip$115.$$arity = -1); - Opal.defs(self, '$inherited', $Array_inherited$116 = function $$inherited(klass) { + $$tap.$$p = null; + Opal.yield1(block, self); + return self; + }); + + $def(self, '$to_proc', $return_self); + + $def(self, '$to_s', function $$to_s() { var self = this; + return "#<" + (self.$class()) + ":0x" + (self.$__id__().$to_s(16)) + ">" + }); + + $def(self, '$catch', function $Kernel_catch$17(tag) { + var $yield = $Kernel_catch$17.$$p || nil, $ret_or_1 = nil, e = nil; + + $Kernel_catch$17.$$p = null; + + if (tag == null) tag = nil; + try { + + tag = ($truthy(($ret_or_1 = tag)) ? ($ret_or_1) : ($Object.$new())); + return Opal.yield1($yield, tag);; + } catch ($err) { + if (Opal.rescue($err, [$$$('UncaughtThrowError')])) {(e = $err); + try { + + if ($eqeq(e.$tag(), tag)) { + return e.$value() + }; + return $Kernel.$raise(); + } finally { Opal.pop_exception(); } + } else { throw $err; } + } }, -1); + + $def(self, '$throw', function $Kernel_throw$18(tag, obj) { + + + if (obj == null) obj = nil; + return $Kernel.$raise($$$('UncaughtThrowError').$new(tag, obj)); + }, -2); + + $def(self, '$open', function $$open($a) { + var block = $$open.$$p || nil, $post_args, args; + + $$open.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + return $send($$$('File'), 'open', $to_a(args), block.$to_proc()); + }, -1); + + $def(self, '$yield_self', function $$yield_self() { + var $yield = $$yield_self.$$p || nil, self = this; + + $$yield_self.$$p = null; - klass.$$prototype.$to_a = function() { - return this.slice(0, this.length); - } + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["yield_self"], $return_val(1)) + } return Opal.yield1($yield, self); }); + $alias(self, "fail", "raise"); + $alias(self, "kind_of?", "is_a?"); + $alias(self, "object_id", "__id__"); + $alias(self, "public_send", "__send__"); + $alias(self, "send", "__send__"); + $alias(self, "then", "yield_self"); + return $alias(self, "to_enum", "enum_for"); + })('::', $nesting); + return (function($base, $super) { + var self = $klass($base, $super, 'Object'); + - }, $Array_inherited$116.$$arity = 1); - Opal.def(self, '$instance_variables', $Array_instance_variables$117 = function $$instance_variables() { - var $$118, $iter = $Array_instance_variables$117.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + delete $Object.$$prototype.$require; + return self.$include($Kernel); + })('::', null); +}; - if ($iter) $Array_instance_variables$117.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - return $send($send(self, Opal.find_super_dispatcher(self, 'instance_variables', $Array_instance_variables$117, false), $zuper, $iter), 'reject', [], ($$118 = function(ivar){var self = $$118.$$s || this, $a; +Opal.modules["corelib/main"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $return_val = Opal.return_val, $def = Opal.def, $Object = Opal.Object, $slice = Opal.slice, $Kernel = Opal.Kernel, self = Opal.top; Opal.nil; + Opal.add_stubs('include,raise'); + return (function(self, $parent_nesting) { + + + + $def(self, '$to_s', $return_val("main")); + + $def(self, '$include', function $$include(mod) { - - if (ivar == null) { - ivar = nil; - }; - return ($truthy($a = /^@\d+$/.test(ivar)) ? $a : ivar['$==']("@length"));}, $$118.$$s = self, $$118.$$arity = 1, $$118)) - }, $Array_instance_variables$117.$$arity = 0); - $$($nesting, 'Opal').$pristine(self.$singleton_class(), "allocate"); - $$($nesting, 'Opal').$pristine(self, "copy_instance_variables", "initialize_dup"); - return (Opal.def(self, '$pack', $Array_pack$119 = function $$pack($a) { - var $post_args, args, self = this; + return $Object.$include(mod) + }); + + $def(self, '$autoload', function $$autoload($a) { + var $post_args, args; + $post_args = $slice(arguments); + args = $post_args; + return Opal.Object.$autoload.apply(Opal.Object, args); }, -1); + return $def(self, '$using', function $$using(mod) { - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return self.$raise("To use Array#pack, you must first require 'corelib/array/pack'."); - }, $Array_pack$119.$$arity = -1), nil) && 'pack'; - })($nesting[0], Array, $nesting); + return $Kernel.$raise("main.using is permitted only at toplevel") + }); + })(Opal.get_singleton_class(self)) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/hash"] = function(Opal) { - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $send = Opal.send, $hash2 = Opal.hash2, $truthy = Opal.truthy; +Opal.modules["corelib/error/errno"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $klass = Opal.klass, nil = Opal.nil, $$$ = Opal.$$$; - Opal.add_stubs(['$require', '$include', '$coerce_to?', '$[]', '$merge!', '$allocate', '$raise', '$coerce_to!', '$each', '$fetch', '$>=', '$>', '$==', '$compare_by_identity', '$lambda?', '$abs', '$arity', '$enum_for', '$size', '$respond_to?', '$class', '$dig', '$new', '$inspect', '$map', '$to_proc', '$flatten', '$eql?', '$default', '$dup', '$default_proc', '$default_proc=', '$-', '$default=', '$proc']); + Opal.add_stubs('+,errno,class,attr_reader'); - self.$require("corelib/enumerable"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Hash'); + (function($base, $parent_nesting) { + var self = $module($base, 'Errno'); - var $nesting = [self].concat($parent_nesting), $Hash_$$$1, $Hash_allocate$2, $Hash_try_convert$3, $Hash_initialize$4, $Hash_$eq_eq$5, $Hash_$gt_eq$6, $Hash_$gt$8, $Hash_$lt$9, $Hash_$lt_eq$10, $Hash_$$$11, $Hash_$$$eq$12, $Hash_assoc$13, $Hash_clear$14, $Hash_clone$15, $Hash_compact$16, $Hash_compact$excl$17, $Hash_compare_by_identity$18, $Hash_compare_by_identity$ques$19, $Hash_default$20, $Hash_default$eq$21, $Hash_default_proc$22, $Hash_default_proc$eq$23, $Hash_delete$24, $Hash_delete_if$25, $Hash_dig$27, $Hash_each$28, $Hash_each_key$30, $Hash_each_value$32, $Hash_empty$ques$34, $Hash_fetch$35, $Hash_fetch_values$36, $Hash_flatten$38, $Hash_has_key$ques$39, $Hash_has_value$ques$40, $Hash_hash$41, $Hash_index$42, $Hash_indexes$43, $Hash_inspect$44, $Hash_invert$45, $Hash_keep_if$46, $Hash_keys$48, $Hash_length$49, $Hash_merge$50, $Hash_merge$excl$51, $Hash_rassoc$52, $Hash_rehash$53, $Hash_reject$54, $Hash_reject$excl$56, $Hash_replace$58, $Hash_select$59, $Hash_select$excl$61, $Hash_shift$63, $Hash_slice$64, $Hash_to_a$65, $Hash_to_h$66, $Hash_to_hash$67, $Hash_to_proc$68, $Hash_transform_keys$70, $Hash_transform_keys$excl$72, $Hash_transform_values$74, $Hash_transform_values$excl$76, $Hash_values$78; + var errors = nil, klass = nil; - self.$include($$($nesting, 'Enumerable')); - self.$$prototype.$$is_hash = true; - Opal.defs(self, '$[]', $Hash_$$$1 = function($a) { - var $post_args, argv, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - argv = $post_args;; - - var hash, argc = argv.length, i; + errors = [["EINVAL", "Invalid argument", 22], ["EEXIST", "File exists", 17], ["EISDIR", "Is a directory", 21], ["EMFILE", "Too many open files", 24], ["ESPIPE", "Illegal seek", 29], ["EACCES", "Permission denied", 13], ["EPERM", "Operation not permitted", 1], ["ENOENT", "No such file or directory", 2], ["ENAMETOOLONG", "File name too long", 36]]; + klass = nil; + + var i; + for (i = 0; i < errors.length; i++) { + (function() { // Create a closure + var class_name = errors[i][0]; + var default_message = errors[i][1]; + var errno = errors[i][2]; - if (argc === 1) { - hash = $$($nesting, 'Opal')['$coerce_to?'](argv['$[]'](0), $$($nesting, 'Hash'), "to_hash"); - if (hash !== nil) { - return self.$allocate()['$merge!'](hash); - } + klass = Opal.klass(self, Opal.SystemCallError, class_name); + klass.errno = errno; - argv = $$($nesting, 'Opal')['$coerce_to?'](argv['$[]'](0), $$($nesting, 'Array'), "to_ary"); - if (argv === nil) { - self.$raise($$($nesting, 'ArgumentError'), "odd number of arguments for Hash") - } + (function(self, $parent_nesting) { + + return $def(self, '$new', function $new$1(name) { + var self = this, message = nil; - argc = argv.length; - hash = self.$allocate(); + $new$1.$$p = null; + + if (name == null) name = nil; + message = default_message; + if ($truthy(name)) { + message = $rb_plus(message, " - " + (name)); + } return $send2(self, $find_super(self, 'new', $new$1, false, true), 'new', [message], null); + }, -1) + })(Opal.get_singleton_class(klass)); + })(); + } + })('::'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'SystemCallError'); - for (i = 0; i < argc; i++) { - if (!argv[i].$$is_array) continue; - switch(argv[i].length) { - case 1: - hash.$store(argv[i][0], nil); - break; - case 2: - hash.$store(argv[i][0], argv[i][1]); - break; - default: - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid number of elements (" + (argv[i].length) + " for 1..2)") - } - } + + + $def(self, '$errno', function $$errno() { + var self = this; - return hash; - } + return self.$class().$errno() + }); + return (function(self, $parent_nesting) { + + return self.$attr_reader("errno") + })(Opal.get_singleton_class(self)); + })('::', $$$('StandardError')); +}; - if (argc % 2 !== 0) { - self.$raise($$($nesting, 'ArgumentError'), "odd number of arguments for Hash") - } +Opal.modules["corelib/error"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $slice = Opal.slice, $gvars = Opal.gvars, $defs = Opal.defs, $send = Opal.send, $to_a = Opal.to_a, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $Kernel = Opal.Kernel, $not = Opal.not, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $Object = Opal.Object, $ensure_kwargs = Opal.ensure_kwargs, $send2 = Opal.send2, $find_super = Opal.find_super, $module = Opal.module, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - hash = self.$allocate(); + Opal.add_stubs('new,map,backtrace,clone,to_s,merge,tty?,[],include?,raise,dup,empty?,!,caller,shift,+,class,join,cause,full_message,==,reverse,split,autoload,attr_reader,inspect'); + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Exception'); - for (i = 0; i < argc; i += 2) { - hash.$store(argv[i], argv[i + 1]); - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - return hash; - ; - }, $Hash_$$$1.$$arity = -1); - Opal.defs(self, '$allocate', $Hash_allocate$2 = function $$allocate() { - var self = this; + $proto.message = nil; + + Opal.prop(self.$$prototype, '$$is_exception', true); + var stack_trace_limit; + Error.stackTraceLimit = 100; + $defs(self, '$new', function $Exception_new$1($a) { + var $post_args, args, self = this; + if ($gvars["!"] == null) $gvars["!"] = nil; - var hash = new self.$$constructor(); + $post_args = $slice(arguments); + args = $post_args; + + var message = (args.length > 0) ? args[0] : nil; + var error = new self.$$constructor(message); + error.name = self.$$name; + error.message = message; + error.cause = $gvars["!"]; + Opal.send(error, error.$initialize, args); - Opal.hash_init(hash); + // Error.captureStackTrace() will use .name and .toString to build the + // first line of the stack trace so it must be called after the error + // has been initialized. + // https://nodejs.org/dist/latest-v6.x/docs/api/errors.html + if (Opal.config.enable_stack_trace && Error.captureStackTrace) { + // Passing Kernel.raise will cut the stack trace from that point above + Error.captureStackTrace(error, stack_trace_limit); + } - hash.$$none = nil; - hash.$$proc = nil; + return error; + }, -1); + stack_trace_limit = self.$new; + $defs(self, '$exception', function $$exception($a) { + var $post_args, args, self = this; - return hash; + + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'new', $to_a(args)); + }, -1); - }, $Hash_allocate$2.$$arity = 0); - Opal.defs(self, '$try_convert', $Hash_try_convert$3 = function $$try_convert(obj) { - var self = this; + $def(self, '$initialize', function $$initialize($a) { + var $post_args, args, self = this; - return $$($nesting, 'Opal')['$coerce_to?'](obj, $$($nesting, 'Hash'), "to_hash") - }, $Hash_try_convert$3.$$arity = 1); + + $post_args = $slice(arguments); + args = $post_args; + return self.message = (args.length > 0) ? args[0] : nil; }, -1); - Opal.def(self, '$initialize', $Hash_initialize$4 = function $$initialize(defaults) { - var $iter = $Hash_initialize$4.$$p, block = $iter || nil, self = this; + // Convert backtrace from any format to Ruby format + function correct_backtrace(backtrace) { + var new_bt = [], m; - if ($iter) $Hash_initialize$4.$$p = null; - - - if ($iter) $Hash_initialize$4.$$p = null;; - ; - - if (defaults !== undefined && block !== nil) { - self.$raise($$($nesting, 'ArgumentError'), "wrong number of arguments (1 for 0)") + for (var i = 0; i < backtrace.length; i++) { + var loc = backtrace[i]; + if (!loc || !loc.$$is_string) ; + /* Chromium format */ + else if ((m = loc.match(/^ at (.*?) \((.*?)\)$/))) { + new_bt.push(m[2] + ":in `" + m[1] + "'"); + } + else if ((m = loc.match(/^ at (.*?)$/))) { + new_bt.push(m[1] + ":in `undefined'"); + } + /* Node format */ + else if ((m = loc.match(/^ from (.*?)$/))) { + new_bt.push(m[1]); + } + /* Mozilla/Apple format */ + else if ((m = loc.match(/^(.*?)@(.*?)$/))) { + new_bt.push(m[2] + ':in `' + m[1] + "'"); + } } - self.$$none = (defaults === undefined ? nil : defaults); - self.$$proc = block; - return self; - ; - }, $Hash_initialize$4.$$arity = -1); + return new_bt; + } - Opal.def(self, '$==', $Hash_$eq_eq$5 = function(other) { + $def(self, '$backtrace', function $$backtrace() { var self = this; - if (self === other) { - return true; + if (self.backtrace) { + // nil is a valid backtrace + return self.backtrace; } - if (!other.$$is_hash) { - return false; - } + var backtrace = self.stack; - if (self.$$keys.length !== other.$$keys.length) { - return false; + if (typeof(backtrace) !== 'undefined' && backtrace.$$is_string) { + return self.backtrace = correct_backtrace(backtrace.split("\n")); } - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, other_value; i < length; i++) { - key = keys[i]; - - if (key.$$is_string) { - value = self.$$smap[key]; - other_value = other.$$smap[key]; - } else { - value = key.value; - other_value = Opal.hash_get(other, key.key); - } - - if (other_value === undefined || !value['$eql?'](other_value)) { - return false; - } + else if (backtrace) { + return self.backtrace = correct_backtrace(backtrace); } - return true; + return []; - }, $Hash_$eq_eq$5.$$arity = 1); + }); - Opal.def(self, '$>=', $Hash_$gt_eq$6 = function(other) { - var $$7, self = this, result = nil; - - - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - - if (self.$$keys.length < other.$$keys.length) { - return false - } - ; - result = true; - $send(other, 'each', [], ($$7 = function(other_key, other_val){var self = $$7.$$s || this, val = nil; + $def(self, '$backtrace_locations', function $$backtrace_locations() { + var $a, self = this; + if (self.backtrace_locations) return self.backtrace_locations; + self.backtrace_locations = ($a = self.$backtrace(), ($a === nil || $a == null) ? nil : $send($a, 'map', [], function $$2(loc){ - if (other_key == null) { - other_key = nil; - }; - - if (other_val == null) { - other_val = nil; - }; - val = self.$fetch(other_key, null); - - if (val == null || val !== other_val) { - result = false; - return; - } - ;}, $$7.$$s = self, $$7.$$arity = 2, $$7)); - return result; - }, $Hash_$gt_eq$6.$$arity = 1); + if (loc == null) loc = nil; + return $$$($$$($$$('Thread'), 'Backtrace'), 'Location').$new(loc);})); + return self.backtrace_locations; - Opal.def(self, '$>', $Hash_$gt$8 = function(other) { - var self = this; - - - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - - if (self.$$keys.length <= other.$$keys.length) { - return false - } - ; - return $rb_ge(self, other); - }, $Hash_$gt$8.$$arity = 1); + }); - Opal.def(self, '$<', $Hash_$lt$9 = function(other) { + $def(self, '$cause', function $$cause() { var self = this; - - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - return $rb_gt(other, self); - }, $Hash_$lt$9.$$arity = 1); + return self.cause || nil; + }); - Opal.def(self, '$<=', $Hash_$lt_eq$10 = function(other) { + $def(self, '$exception', function $$exception(str) { var self = this; - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - return $rb_ge(other, self); - }, $Hash_$lt_eq$10.$$arity = 1); - - Opal.def(self, '$[]', $Hash_$$$11 = function(key) { - var self = this; - + if (str == null) str = nil; - var value = Opal.hash_get(self, key); - - if (value !== undefined) { - return value; + if (str === nil || self === str) { + return self; } - return self.$default(key); - - }, $Hash_$$$11.$$arity = 1); + var cloned = self.$clone(); + cloned.message = str; + if (self.backtrace) cloned.backtrace = self.backtrace.$dup(); + cloned.stack = self.stack; + cloned.cause = self.cause; + return cloned; + }, -1); - Opal.def(self, '$[]=', $Hash_$$$eq$12 = function(key, value) { + $def(self, '$message', function $$message() { var self = this; - - Opal.hash_put(self, key, value); - return value; + return self.$to_s() + }); - }, $Hash_$$$eq$12.$$arity = 2); + $def(self, '$full_message', function $$full_message(kwargs) { + var $b, self = this, $ret_or_1 = nil, highlight = nil, order = nil, bold_underline = nil, bold = nil, reset = nil, bt = nil, first = nil, msg = nil; + if ($gvars.stderr == null) $gvars.stderr = nil; + + + if (kwargs == null) kwargs = nil; + if (!$truthy((($$('Hash', 'skip_raise')) ? 'constant' : nil))) { + return "" + (self.message) + "\n" + (self.stack) + } kwargs = $hash2(["highlight", "order"], {"highlight": $gvars.stderr['$tty?'](), "order": "top"}).$merge(($truthy(($ret_or_1 = kwargs)) ? ($ret_or_1) : ($hash2([], {})))); + $b = [kwargs['$[]']("highlight"), kwargs['$[]']("order")], (highlight = $b[0]), (order = $b[1]); + if (!$truthy([true, false]['$include?'](highlight))) { + $Kernel.$raise($$$('ArgumentError'), "expected true or false as highlight: " + (highlight)); + } if (!$truthy(["top", "bottom"]['$include?'](order))) { + $Kernel.$raise($$$('ArgumentError'), "expected :top or :bottom as order: " + (order)); + } if ($truthy(highlight)) { + + bold_underline = "\u001b[1;4m"; + bold = "\u001b[1m"; + reset = "\u001b[m"; + } else { + bold_underline = (bold = (reset = "")); + } bt = self.$backtrace().$dup(); + if (($not(bt) || ($truthy(bt['$empty?']())))) { + bt = self.$caller(); + } first = bt.$shift(); + msg = "" + (first) + ": "; + msg = $rb_plus(msg, "" + (bold) + (self.$to_s()) + " (" + (bold_underline) + (self.$class()) + (reset) + (bold) + ")" + (reset) + "\n"); + msg = $rb_plus(msg, $send(bt, 'map', [], function $$3(loc){ + + if (loc == null) loc = nil; + return "\tfrom " + (loc) + "\n";}).$join()); + if ($truthy(self.$cause())) { + msg = $rb_plus(msg, self.$cause().$full_message($hash2(["highlight"], {"highlight": highlight}))); + } if ($eqeq(order, "bottom")) { + + msg = msg.$split("\n").$reverse().$join("\n"); + msg = $rb_plus("" + (bold) + "Traceback" + (reset) + " (most recent call last):\n", msg); + } return msg; + }, -1); + + $def(self, '$inspect', function $$inspect() { + var self = this, as_str = nil; + + + as_str = self.$to_s(); + if ($truthy(as_str['$empty?']())) { + return self.$class().$to_s() + } else { + return "#<" + (self.$class().$to_s()) + ": " + (self.$to_s()) + ">" + } }); - Opal.def(self, '$assoc', $Hash_assoc$13 = function $$assoc(object) { + $def(self, '$set_backtrace', function $$set_backtrace(backtrace) { var self = this; - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + var valid = true, i, ii; - if (key.$$is_string) { - if ((key)['$=='](object)) { - return [key, self.$$smap[key]]; + if (backtrace === nil) { + self.backtrace = nil; + self.stack = ''; + } else if (backtrace.$$is_string) { + self.backtrace = [backtrace]; + self.stack = ' from ' + backtrace; + } else { + if (backtrace.$$is_array) { + for (i = 0, ii = backtrace.length; i < ii; i++) { + if (!backtrace[i].$$is_string) { + valid = false; + break; + } } } else { - if ((key.key)['$=='](object)) { - return [key.key, key.value]; - } + valid = false; } + + if (valid === false) { + $Kernel.$raise($$$('TypeError'), "backtrace must be Array of String"); + } + + self.backtrace = backtrace; + self.stack = $send((backtrace), 'map', [], function $$4(i){ + + if (i == null) i = nil; + return $rb_plus(" from ", i);}).join("\n"); } - return nil; - - }, $Hash_assoc$13.$$arity = 1); + return backtrace; - Opal.def(self, '$clear', $Hash_clear$14 = function $$clear() { - var self = this; + }); + return $def(self, '$to_s', function $$to_s() { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; + + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.message)) ? (self.message.$to_s()) : ($ret_or_2))))) { + return $ret_or_1 + } else { + return self.$class().$to_s() + } + }); + })('::', Error, $nesting); + $klass('::', $$$('Exception'), 'ScriptError'); + $klass('::', $$$('ScriptError'), 'SyntaxError'); + $klass('::', $$$('ScriptError'), 'LoadError'); + $klass('::', $$$('ScriptError'), 'NotImplementedError'); + $klass('::', $$$('Exception'), 'SystemExit'); + $klass('::', $$$('Exception'), 'NoMemoryError'); + $klass('::', $$$('Exception'), 'SignalException'); + $klass('::', $$$('SignalException'), 'Interrupt'); + $klass('::', $$$('Exception'), 'SecurityError'); + $klass('::', $$$('Exception'), 'SystemStackError'); + $klass('::', $$$('Exception'), 'StandardError'); + $klass('::', $$$('StandardError'), 'EncodingError'); + $klass('::', $$$('StandardError'), 'ZeroDivisionError'); + $klass('::', $$$('StandardError'), 'NameError'); + $klass('::', $$$('NameError'), 'NoMethodError'); + $klass('::', $$$('StandardError'), 'RuntimeError'); + $klass('::', $$$('RuntimeError'), 'FrozenError'); + $klass('::', $$$('StandardError'), 'LocalJumpError'); + $klass('::', $$$('StandardError'), 'TypeError'); + $klass('::', $$$('StandardError'), 'ArgumentError'); + $klass('::', $$$('ArgumentError'), 'UncaughtThrowError'); + $klass('::', $$$('StandardError'), 'IndexError'); + $klass('::', $$$('IndexError'), 'StopIteration'); + $klass('::', $$$('StopIteration'), 'ClosedQueueError'); + $klass('::', $$$('IndexError'), 'KeyError'); + $klass('::', $$$('StandardError'), 'RangeError'); + $klass('::', $$$('RangeError'), 'FloatDomainError'); + $klass('::', $$$('StandardError'), 'IOError'); + $klass('::', $$$('IOError'), 'EOFError'); + $klass('::', $$$('StandardError'), 'SystemCallError'); + $klass('::', $$$('StandardError'), 'RegexpError'); + $klass('::', $$$('StandardError'), 'ThreadError'); + $klass('::', $$$('StandardError'), 'FiberError'); + $Object.$autoload("Errno", "corelib/error/errno"); + (function($base, $super) { + var self = $klass($base, $super, 'FrozenError'); - - Opal.hash_init(self); - return self; - }, $Hash_clear$14.$$arity = 0); - Opal.def(self, '$clone', $Hash_clone$15 = function $$clone() { - var self = this; + self.$attr_reader("receiver"); + return $def(self, '$initialize', function $$initialize(message, $kwargs) { + var receiver, self = this; + $$initialize.$$p = null; - var hash = new self.$$class(); + $kwargs = $ensure_kwargs($kwargs); + + receiver = $kwargs.$$smap["receiver"];if (receiver == null) receiver = nil; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null); + return (self.receiver = receiver); + }, -2); + })('::', $$$('RuntimeError')); + (function($base, $super) { + var self = $klass($base, $super, 'UncaughtThrowError'); - Opal.hash_init(hash); - Opal.hash_clone(self, hash); + var $proto = self.$$prototype; - return hash; - - }, $Hash_clone$15.$$arity = 0); + $proto.tag = nil; - Opal.def(self, '$compact', $Hash_compact$16 = function $$compact() { + self.$attr_reader("tag", "value"); + return $def(self, '$initialize', function $$initialize(tag, value) { var self = this; + $$initialize.$$p = null; - var hash = Opal.hash(); - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + if (value == null) value = nil; + self.tag = tag; + self.value = value; + return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', ["uncaught throw " + (self.tag.$inspect())], null); + }, -2); + })('::', $$$('ArgumentError')); + (function($base, $super) { + var self = $klass($base, $super, 'NameError'); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + + + self.$attr_reader("name"); + return $def(self, '$initialize', function $$initialize(message, name) { + var self = this; - if (value !== nil) { - Opal.hash_put(hash, key, value); - } - } + $$initialize.$$p = null; + + if (name == null) name = nil; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null); + return (self.name = name); + }, -2); + })('::', null); + (function($base, $super) { + var self = $klass($base, $super, 'NoMethodError'); - return hash; - }, $Hash_compact$16.$$arity = 0); - Opal.def(self, '$compact!', $Hash_compact$excl$17 = function() { + self.$attr_reader("args"); + return $def(self, '$initialize', function $$initialize(message, name, args) { var self = this; + $$initialize.$$p = null; - var changes_were_made = false; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + if (name == null) name = nil; + if (args == null) args = []; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message, name], null); + return (self.args = args); + }, -2); + })('::', null); + (function($base, $super) { + var self = $klass($base, $super, 'StopIteration'); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + + return self.$attr_reader("result") + })('::', null); + (function($base, $super) { + var self = $klass($base, $super, 'KeyError'); - if (value === nil) { - if (Opal.hash_delete(self, key) !== undefined) { - changes_were_made = true; - length--; - i--; - } - } - } + var $proto = self.$$prototype; - return changes_were_made ? self : nil; + $proto.receiver = $proto.key = nil; - }, $Hash_compact$excl$17.$$arity = 0); - Opal.def(self, '$compare_by_identity', $Hash_compare_by_identity$18 = function $$compare_by_identity() { - var self = this; + $def(self, '$initialize', function $$initialize(message, $kwargs) { + var receiver, key, self = this; + $$initialize.$$p = null; - var i, ii, key, keys = self.$$keys, identity_hash; + $kwargs = $ensure_kwargs($kwargs); + + receiver = $kwargs.$$smap["receiver"];if (receiver == null) receiver = nil; + + key = $kwargs.$$smap["key"];if (key == null) key = nil; + $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null); + self.receiver = receiver; + return (self.key = key); + }, -2); + + $def(self, '$receiver', function $$receiver() { + var self = this, $ret_or_1 = nil; - if (self.$$by_identity) return self; - if (self.$$keys.length === 0) { - self.$$by_identity = true - return self; + if ($truthy(($ret_or_1 = self.receiver))) { + return $ret_or_1 + } else { + return $Kernel.$raise($$$('ArgumentError'), "no receiver is available") } + }); + return $def(self, '$key', function $$key() { + var self = this, $ret_or_1 = nil; - identity_hash = $hash2([], {}).$compare_by_identity(); - for(i = 0, ii = keys.length; i < ii; i++) { - key = keys[i]; - if (!key.$$is_string) key = key.key; - Opal.hash_put(identity_hash, key, Opal.hash_get(self, key)); + if ($truthy(($ret_or_1 = self.key))) { + return $ret_or_1 + } else { + return $Kernel.$raise($$$('ArgumentError'), "no key is available") } + }); + })('::', null); + return (function($base, $parent_nesting) { + var self = $module($base, 'JS'); - self.$$by_identity = true; - self.$$map = identity_hash.$$map; - self.$$smap = identity_hash.$$smap; - return self; - - }, $Hash_compare_by_identity$18.$$arity = 0); - - Opal.def(self, '$compare_by_identity?', $Hash_compare_by_identity$ques$19 = function() { - var self = this; + var $nesting = [self].concat($parent_nesting); + + return ($klass($nesting[0], null, 'Error'), nil) + })('::', $nesting); +}; + +Opal.modules["corelib/constants"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $const_set = Opal.const_set; Opal.nil; var $$$ = Opal.$$$; + + + $const_set('::', 'RUBY_PLATFORM', "opal"); + $const_set('::', 'RUBY_ENGINE', "opal"); + $const_set('::', 'RUBY_VERSION', "3.2.0"); + $const_set('::', 'RUBY_ENGINE_VERSION', "1.7.3"); + $const_set('::', 'RUBY_RELEASE_DATE', "2023-03-23"); + $const_set('::', 'RUBY_PATCHLEVEL', 0); + $const_set('::', 'RUBY_REVISION', "0"); + $const_set('::', 'RUBY_COPYRIGHT', "opal - Copyright (C) 2011-2023 Adam Beynon and the Opal contributors"); + return $const_set('::', 'RUBY_DESCRIPTION', "opal " + ($$$('RUBY_ENGINE_VERSION')) + " (" + ($$$('RUBY_RELEASE_DATE')) + " revision " + ($$$('RUBY_REVISION')) + ")"); +}; + +Opal.modules["opal/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $Object = Opal.Object; Opal.nil; + + Opal.add_stubs('require'); + + $Object.$require("corelib/runtime"); + $Object.$require("corelib/helpers"); + $Object.$require("corelib/module"); + $Object.$require("corelib/class"); + $Object.$require("corelib/basic_object"); + $Object.$require("corelib/kernel"); + $Object.$require("corelib/main"); + $Object.$require("corelib/error"); + return $Object.$require("corelib/constants"); +}; + +Opal.modules["corelib/nil"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $Kernel = Opal.Kernel, $def = Opal.def, $return_val = Opal.return_val, $ensure_kwargs = Opal.ensure_kwargs, $NilClass = Opal.NilClass, $slice = Opal.slice, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('raise,name,new,>,length,Rational,to_i'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'NilClass'); - return self.$$by_identity === true; - }, $Hash_compare_by_identity$ques$19.$$arity = 0); - Opal.def(self, '$default', $Hash_default$20 = function(key) { - var self = this; + self.$$prototype.$$meta = self; + (function(self, $parent_nesting) { + + + + $def(self, '$allocate', function $$allocate() { + var self = this; + return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name())) + }); - ; - if (key !== undefined && self.$$proc !== nil && self.$$proc !== undefined) { - return self.$$proc.$call(self, key); - } - if (self.$$none === undefined) { - return nil; - } - return self.$$none; - ; - }, $Hash_default$20.$$arity = -1); + Opal.udef(self, '$' + "new"); return nil; })(Opal.get_singleton_class(self)); - Opal.def(self, '$default=', $Hash_default$eq$21 = function(object) { - var self = this; - + $def(self, '$!', $return_val(true)); + + $def(self, '$&', $return_val(false)); + + $def(self, '$|', function $NilClass_$$1(other) { - self.$$proc = nil; - self.$$none = object; - - return object; + return other !== false && other !== nil; + }); + + $def(self, '$^', function $NilClass_$$2(other) { + + return other !== false && other !== nil; + }); + + $def(self, '$==', function $NilClass_$eq_eq$3(other) { + + return other === nil; + }); - }, $Hash_default$eq$21.$$arity = 1); + $def(self, '$dup', $return_val(nil)); - Opal.def(self, '$default_proc', $Hash_default_proc$22 = function $$default_proc() { - var self = this; + $def(self, '$clone', function $$clone($kwargs) { - if (self.$$proc !== undefined) { - return self.$$proc; - } - return nil; + $kwargs = $ensure_kwargs($kwargs); + + $kwargs.$$smap["freeze"]; return nil; + }, -1); - }, $Hash_default_proc$22.$$arity = 0); + $def(self, '$inspect', $return_val("nil")); - Opal.def(self, '$default_proc=', $Hash_default_proc$eq$23 = function(default_proc) { - var self = this; - + $def(self, '$nil?', $return_val(true)); + + $def(self, '$singleton_class', function $$singleton_class() { - var proc = default_proc; + return $NilClass + }); + + $def(self, '$to_a', function $$to_a() { + + return [] + }); + + $def(self, '$to_h', function $$to_h() { + + return Opal.hash(); + }); + + $def(self, '$to_i', $return_val(0)); + + $def(self, '$to_s', $return_val("")); + + $def(self, '$to_c', function $$to_c() { + + return $$$('Complex').$new(0, 0) + }); + + $def(self, '$rationalize', function $$rationalize($a) { + var $post_args, args; - if (proc !== nil) { - proc = $$($nesting, 'Opal')['$coerce_to!'](proc, $$($nesting, 'Proc'), "to_proc"); + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy($rb_gt(args.$length(), 1))) { + $Kernel.$raise($$$('ArgumentError')); + } return $Kernel.$Rational(0, 1); + }, -1); + + $def(self, '$to_r', function $$to_r() { + + return $Kernel.$Rational(0, 1) + }); + + $def(self, '$instance_variables', function $$instance_variables() { + + return [] + }); + return $alias(self, "to_f", "to_i"); + })('::', null) +}; - if ((proc)['$lambda?']() && (proc).$arity().$abs() !== 2) { - self.$raise($$($nesting, 'TypeError'), "default_proc takes two arguments"); - } - } +Opal.modules["corelib/boolean"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $Kernel = Opal.Kernel, $def = Opal.def, $return_self = Opal.return_self, $ensure_kwargs = Opal.ensure_kwargs, $slice = Opal.slice, $truthy = Opal.truthy, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$; - self.$$none = nil; - self.$$proc = proc; + Opal.add_stubs('raise,name,==,to_s,__id__'); + + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Boolean'); - return default_proc; - }, $Hash_default_proc$eq$23.$$arity = 1); + Opal.prop(self.$$prototype, '$$is_boolean', true); - Opal.def(self, '$delete', $Hash_delete$24 = function(key) { - var $iter = $Hash_delete$24.$$p, block = $iter || nil, self = this; + var properties = ['$$class', '$$meta']; + + for (var i = 0; i < properties.length; i++) { + Object.defineProperty(self.$$prototype, properties[i], { + configurable: true, + enumerable: false, + get: function() { + return this == true ? Opal.TrueClass : + this == false ? Opal.FalseClass : + Opal.Boolean; + } + }); + } - if ($iter) $Hash_delete$24.$$p = null; + Object.defineProperty(self.$$prototype, "$$id", { + configurable: true, + enumerable: false, + get: function() { + return this == true ? 2 : + this == false ? 0 : + nil; + } + }); + (function(self, $parent_nesting) { - if ($iter) $Hash_delete$24.$$p = null;; - var value = Opal.hash_delete(self, key); + $def(self, '$allocate', function $$allocate() { + var self = this; - if (value !== undefined) { - return value; - } + return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name())) + }); + + + Opal.udef(self, '$' + "new"); return nil; })(Opal.get_singleton_class(self)); + + $def(self, '$__id__', function $$__id__() { + var self = this; - if (block !== nil) { - return Opal.yield1(block, key); - } + return self.valueOf() ? 2 : 0; + }); + + $def(self, '$!', function $Boolean_$excl$1() { + var self = this; - return nil; - ; - }, $Hash_delete$24.$$arity = 1); + return self != true; + }); - Opal.def(self, '$delete_if', $Hash_delete_if$25 = function $$delete_if() { - var $iter = $Hash_delete_if$25.$$p, block = $iter || nil, $$26, self = this; + $def(self, '$&', function $Boolean_$$2(other) { + var self = this; - if ($iter) $Hash_delete_if$25.$$p = null; - - - if ($iter) $Hash_delete_if$25.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["delete_if"], ($$26 = function(){var self = $$26.$$s || this; + return (self == true) ? (other !== false && other !== nil) : false; + }); + + $def(self, '$|', function $Boolean_$$3(other) { + var self = this; - return self.$size()}, $$26.$$s = self, $$26.$$arity = 0, $$26)) - }; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + return (self == true) ? true : (other !== false && other !== nil); + }); + + $def(self, '$^', function $Boolean_$$4(other) { + var self = this; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + return (self == true) ? (other === false || other === nil) : (other !== false && other !== nil); + }); + + $def(self, '$==', function $Boolean_$eq_eq$5(other) { + var self = this; - obj = block(key, value); + return (self == true) === other.valueOf(); + }); + + $def(self, '$singleton_class', function $$singleton_class() { + var self = this; - if (obj !== false && obj !== nil) { - if (Opal.hash_delete(self, key) !== undefined) { - length--; - i--; - } - } - } + return self.$$meta; + }); + + $def(self, '$to_s', function $$to_s() { + var self = this; - return self; - ; - }, $Hash_delete_if$25.$$arity = 0); - Opal.alias(self, "dup", "clone"); + return (self == true) ? 'true' : 'false'; + }); - Opal.def(self, '$dig', $Hash_dig$27 = function $$dig(key, $a) { - var $post_args, keys, self = this, item = nil; + $def(self, '$dup', $return_self); + + $def(self, '$clone', function $$clone($kwargs) { + var self = this; + $kwargs = $ensure_kwargs($kwargs); - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - keys = $post_args;; - item = self['$[]'](key); - - if (item === nil || keys.length === 0) { - return item; - } - ; - if ($truthy(item['$respond_to?']("dig"))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + (item.$class()) + " does not have #dig method") - }; - return $send(item, 'dig', Opal.to_a(keys)); - }, $Hash_dig$27.$$arity = -2); + $kwargs.$$smap["freeze"]; return self; + }, -1); - Opal.def(self, '$each', $Hash_each$28 = function $$each() { - var $iter = $Hash_each$28.$$p, block = $iter || nil, $$29, self = this; + $def(self, '$method_missing', function $$method_missing(method, $a) { + var block = $$method_missing.$$p || nil, $post_args, args, self = this; - if ($iter) $Hash_each$28.$$p = null; - - - if ($iter) $Hash_each$28.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["each"], ($$29 = function(){var self = $$29.$$s || this; + $$method_missing.$$p = null; + $post_args = $slice(arguments, 1); + args = $post_args; + var body = self.$$class.$$prototype[Opal.jsid(method)]; + if (!$truthy(typeof body !== 'undefined' && !body.$$stub)) { + $send2(self, $find_super(self, 'method_missing', $$method_missing, false, true), 'method_missing', [method].concat($to_a(args)), block); + } return Opal.send(self, body, args, block); + }, -2); + + $def(self, '$respond_to_missing?', function $Boolean_respond_to_missing$ques$6(method, _include_all) { + var self = this; + var body = self.$$class.$$prototype[Opal.jsid(method)]; + return typeof body !== 'undefined' && !body.$$stub; }, -2); + $alias(self, "eql?", "=="); + $alias(self, "equal?", "=="); + $alias(self, "inspect", "to_s"); + return $alias(self, "object_id", "__id__"); + })('::', Boolean); + $klass('::', $$$('Boolean'), 'TrueClass'); + return ($klass('::', $$$('Boolean'), 'FalseClass'), nil); +}; - return self.$size()}, $$29.$$s = self, $$29.$$arity = 0, $$29)) - }; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; +Opal.modules["corelib/comparable"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $module = Opal.module, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $def = Opal.def, nil = Opal.nil, $$$ = Opal.$$$; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + Opal.add_stubs('>,<,===,raise,class,<=>,equal?'); + return (function($base) { + var self = $module($base, 'Comparable'); - Opal.yield1(block, [key, value]); - } + var $ret_or_1 = nil; - return self; - ; - }, $Hash_each$28.$$arity = 0); - Opal.def(self, '$each_key', $Hash_each_key$30 = function $$each_key() { - var $iter = $Hash_each_key$30.$$p, block = $iter || nil, $$31, self = this; - - if ($iter) $Hash_each_key$30.$$p = null; - - - if ($iter) $Hash_each_key$30.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["each_key"], ($$31 = function(){var self = $$31.$$s || this; + + function normalize(what) { + if (Opal.is_a(what, Opal.Integer)) { return what; } - return self.$size()}, $$31.$$s = self, $$31.$$arity = 0, $$31)) - }; - - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + if ($rb_gt(what, 0)) { return 1; } + if ($rb_lt(what, 0)) { return -1; } + return 0; + } - block(key.$$is_string ? key : key.key); - } + function fail_comparison(lhs, rhs) { + var class_name; + (($eqeqeq(nil, ($ret_or_1 = rhs)) || (($eqeqeq(true, $ret_or_1) || (($eqeqeq(false, $ret_or_1) || (($eqeqeq($$$('Integer'), $ret_or_1) || ($eqeqeq($$$('Float'), $ret_or_1))))))))) ? (class_name = rhs.$inspect()) : (class_name = rhs.$$class)); + $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((lhs).$class()) + " with " + (class_name) + " failed"); + } - return self; - ; - }, $Hash_each_key$30.$$arity = 0); - Opal.alias(self, "each_pair", "each"); + function cmp_or_fail(lhs, rhs) { + var cmp = (lhs)['$<=>'](rhs); + if (!$truthy(cmp)) fail_comparison(lhs, rhs); + return normalize(cmp); + } - Opal.def(self, '$each_value', $Hash_each_value$32 = function $$each_value() { - var $iter = $Hash_each_value$32.$$p, block = $iter || nil, $$33, self = this; - - if ($iter) $Hash_each_value$32.$$p = null; - - - if ($iter) $Hash_each_value$32.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["each_value"], ($$33 = function(){var self = $$33.$$s || this; + $def(self, '$==', function $Comparable_$eq_eq$1(other) { + var self = this, cmp = nil; - return self.$size()}, $$33.$$s = self, $$33.$$arity = 0, $$33)) - }; - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + if ($truthy(self['$equal?'](other))) { + return true + } + if (self["$<=>"] == Opal.Kernel["$<=>"]) { + return false; + } - block(key.$$is_string ? self.$$smap[key] : key.value); + // check for infinite recursion + if (self.$$comparable) { + self.$$comparable = false; + return false; } + if (!$truthy((cmp = self['$<=>'](other)))) { + return false + } return normalize(cmp) == 0; }); + + $def(self, '$>', function $Comparable_$gt$2(other) { + var self = this; - return self; - ; - }, $Hash_each_value$32.$$arity = 0); + return cmp_or_fail(self, other) > 0; + }); - Opal.def(self, '$empty?', $Hash_empty$ques$34 = function() { + $def(self, '$>=', function $Comparable_$gt_eq$3(other) { var self = this; - return self.$$keys.length === 0; - }, $Hash_empty$ques$34.$$arity = 0); - Opal.alias(self, "eql?", "=="); + return cmp_or_fail(self, other) >= 0; + }); + + $def(self, '$<', function $Comparable_$lt$4(other) { + var self = this; + + return cmp_or_fail(self, other) < 0; + }); + + $def(self, '$<=', function $Comparable_$lt_eq$5(other) { + var self = this; + + return cmp_or_fail(self, other) <= 0; + }); - Opal.def(self, '$fetch', $Hash_fetch$35 = function $$fetch(key, defaults) { - var $iter = $Hash_fetch$35.$$p, block = $iter || nil, self = this; + $def(self, '$between?', function $Comparable_between$ques$6(min, max) { + var self = this; - if ($iter) $Hash_fetch$35.$$p = null; + if ($rb_lt(self, min)) { + return false + } if ($rb_gt(self, max)) { + return false + } return true; + }); + return $def(self, '$clamp', function $$clamp(min, max) { + var self = this; + - if ($iter) $Hash_fetch$35.$$p = null;; - ; + if (max == null) max = nil; - var value = Opal.hash_get(self, key); + var c, excl; - if (value !== undefined) { - return value; + if (max === nil) { + // We are dealing with a new Ruby 2.7 behaviour that we are able to + // provide a single Range argument instead of 2 Comparables. + + if (!Opal.is_a(min, Opal.Range)) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (min.$class()) + " (expected Range)"); + } + + excl = min.excl; + max = min.end; + min = min.begin; + + if (max !== nil && excl) { + $Kernel.$raise($$$('ArgumentError'), "cannot clamp with an exclusive range"); + } } - if (block !== nil) { - return block(key); + if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) { + $Kernel.$raise($$$('ArgumentError'), "min argument must be smaller than max argument"); } - if (defaults !== undefined) { - return defaults; + if (min !== nil) { + c = cmp_or_fail(self, min); + + if (c == 0) return self; + if (c < 0) return min; } - ; - return self.$raise($$($nesting, 'KeyError').$new("" + "key not found: " + (key.$inspect()), $hash2(["key", "receiver"], {"key": key, "receiver": self}))); - }, $Hash_fetch$35.$$arity = -2); + + if (max !== nil) { + c = cmp_or_fail(self, max); + + if (c > 0) return max; + } + + return self; + }, -2); + })('::') +}; + +Opal.modules["corelib/regexp"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $coerce_to = Opal.coerce_to, $prop = Opal.prop, $freeze = Opal.freeze, $klass = Opal.klass, $const_set = Opal.const_set, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $truthy = Opal.truthy, $gvars = Opal.gvars, $slice = Opal.slice, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $alias = Opal.alias, $send = Opal.send, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $ensure_kwargs = Opal.ensure_kwargs, $rb_ge = Opal.rb_ge, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_minus = Opal.rb_minus, $return_ivar = Opal.return_ivar, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('nil?,[],raise,escape,options,to_str,new,join,coerce_to!,!,match,coerce_to?,begin,frozen?,uniq,map,scan,source,to_proc,transform_values,group_by,each_with_index,+,last,=~,==,attr_reader,>=,length,is_a?,include?,names,regexp,named_captures,===,captures,-,inspect,empty?,each,to_a'); + + $klass('::', $$$('StandardError'), 'RegexpError'); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Regexp'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + - Opal.def(self, '$fetch_values', $Hash_fetch_values$36 = function $$fetch_values($a) { - var $iter = $Hash_fetch_values$36.$$p, block = $iter || nil, $post_args, keys, $$37, self = this; + $const_set(self, 'IGNORECASE', 1); + $const_set(self, 'EXTENDED', 2); + $const_set(self, 'MULTILINE', 4); + Opal.prop(self.$$prototype, '$$is_regexp', true); + (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if ($iter) $Hash_fetch_values$36.$$p = null; - - if ($iter) $Hash_fetch_values$36.$$p = null;; - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - keys = $post_args;; - return $send(keys, 'map', [], ($$37 = function(key){var self = $$37.$$s || this; + $def(self, '$allocate', function $$allocate() { + var $yield = $$allocate.$$p || nil, self = this, allocated = nil; + $$allocate.$$p = null; + + allocated = $send2(self, $find_super(self, 'allocate', $$allocate, false, true), 'allocate', [], $yield); + allocated.uninitialized = true; + return allocated; + }); + $def(self, '$escape', function $$escape(string) { - if (key == null) { - key = nil; - }; - return $send(self, 'fetch', [key], block.$to_proc());}, $$37.$$s = self, $$37.$$arity = 1, $$37)); - }, $Hash_fetch_values$36.$$arity = -1); - - Opal.def(self, '$flatten', $Hash_flatten$38 = function $$flatten(level) { - var self = this; - + return Opal.escape_regexp(string); + }); + $def(self, '$last_match', function $$last_match(n) { + if ($gvars["~"] == null) $gvars["~"] = nil; + + + if (n == null) n = nil; + if ($truthy(n['$nil?']())) { + return $gvars["~"] + } else if ($truthy($gvars["~"])) { + return $gvars["~"]['$[]'](n) + } else { + return nil + } }, -1); - if (level == null) { - level = 1; - }; - level = $$($nesting, 'Opal')['$coerce_to!'](level, $$($nesting, 'Integer'), "to_int"); + $def(self, '$union', function $$union($a) { + var $post_args, parts, self = this; + + + $post_args = $slice(arguments); + parts = $post_args; + + var is_first_part_array, quoted_validated, part, options, each_part_options; + if (parts.length == 0) { + return /(?!)/; + } + // return fast if there's only one element + if (parts.length == 1 && parts[0].$$is_regexp) { + return parts[0]; + } + // cover the 2 arrays passed as arguments case + is_first_part_array = parts[0].$$is_array; + if (parts.length > 1 && is_first_part_array) { + $Kernel.$raise($$$('TypeError'), "no implicit conversion of Array into String"); + } + // deal with splat issues (related to https://github.com/opal/opal/issues/858) + if (is_first_part_array) { + parts = parts[0]; + } + options = undefined; + quoted_validated = []; + for (var i=0; i < parts.length; i++) { + part = parts[i]; + if (part.$$is_string) { + quoted_validated.push(self.$escape(part)); + } + else if (part.$$is_regexp) { + each_part_options = (part).$options(); + if (options != undefined && options != each_part_options) { + $Kernel.$raise($$$('TypeError'), "All expressions must use the same options"); + } + options = each_part_options; + quoted_validated.push('('+part.source+')'); + } + else { + quoted_validated.push(self.$escape((part).$to_str())); + } + } + return self.$new((quoted_validated).$join("|"), options); + }, -1); - var result = []; + $def(self, '$new', function $new$1(regexp, options) { + + if (regexp.$$is_regexp) { + return new RegExp(regexp); + } - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + regexp = $Opal['$coerce_to!'](regexp, $$$('String'), "to_str"); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (regexp.charAt(regexp.length - 1) === '\\' && regexp.charAt(regexp.length - 2) !== '\\') { + $Kernel.$raise($$$('RegexpError'), "too short escape sequence: /" + (regexp) + "/"); } - result.push(key); + regexp = regexp.replace('\\A', '^').replace('\\z', '$'); - if (value.$$is_array) { - if (level === 1) { - result.push(value); - continue; - } + if (options === undefined || options['$!']()) { + return new RegExp(regexp); + } - result = result.concat((value).$flatten(level - 2)); - continue; + if (options.$$is_number) { + var temp = ''; + if ($$('IGNORECASE') & options) { temp += 'i'; } + if ($$('MULTILINE') & options) { temp += 'm'; } + options = temp; + } + else { + options = 'i'; } - result.push(value); - } + return new RegExp(regexp, options); + }, -2); + $alias(self, "compile", "new"); + return $alias(self, "quote", "escape"); + })(Opal.get_singleton_class(self), $nesting); + + $def(self, '$==', function $Regexp_$eq_eq$2(other) { + var self = this; - return result; - ; - }, $Hash_flatten$38.$$arity = -1); + return other instanceof RegExp && self.toString() === other.toString(); + }); - Opal.def(self, '$has_key?', $Hash_has_key$ques$39 = function(key) { + $def(self, '$===', function $Regexp_$eq_eq_eq$3(string) { var self = this; - return Opal.hash_get(self, key) !== undefined; - }, $Hash_has_key$ques$39.$$arity = 1); + return self.$match($Opal['$coerce_to?'](string, $$$('String'), "to_str")) !== nil + }); + + $def(self, '$=~', function $Regexp_$eq_tilde$4(string) { + var self = this, $ret_or_1 = nil; + if ($gvars["~"] == null) $gvars["~"] = nil; + + if ($truthy(($ret_or_1 = self.$match(string)))) { + return $gvars["~"].$begin(0) + } else { + return $ret_or_1 + } + }); - Opal.def(self, '$has_value?', $Hash_has_value$ques$40 = function(value) { + $def(self, '$freeze', function $$freeze() { var self = this; - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + if ($truthy(self['$frozen?']())) { + return self + } + if (!self.hasOwnProperty('$$g')) { $prop(self, '$$g', null); } + if (!self.hasOwnProperty('$$gm')) { $prop(self, '$$gm', null); } - if (((key.$$is_string ? self.$$smap[key] : key.value))['$=='](value)) { - return true; + return $freeze(self); + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + + var regexp_format = /^\/(.*)\/([^\/]*)$/; + var value = self.toString(); + var matches = regexp_format.exec(value); + if (matches) { + var regexp_pattern = matches[1]; + var regexp_flags = matches[2]; + var chars = regexp_pattern.split(''); + var chars_length = chars.length; + var char_escaped = false; + var regexp_pattern_escaped = ''; + for (var i = 0; i < chars_length; i++) { + var current_char = chars[i]; + if (!char_escaped && current_char == '/') { + regexp_pattern_escaped = regexp_pattern_escaped.concat('\\'); + } + regexp_pattern_escaped = regexp_pattern_escaped.concat(current_char); + if (current_char == '\\') { + if (char_escaped) { + // does not over escape + char_escaped = false; + } else { + char_escaped = true; + } + } else { + char_escaped = false; + } } + return '/' + regexp_pattern_escaped + '/' + regexp_flags; + } else { + return value; } - - return false; - }, $Hash_has_value$ques$40.$$arity = 1); + }); - Opal.def(self, '$hash', $Hash_hash$41 = function $$hash() { - var self = this; + $def(self, '$match', function $$match(string, pos) { + var block = $$match.$$p || nil, self = this; + if ($gvars["~"] == null) $gvars["~"] = nil; + $$match.$$p = null; - var top = (Opal.hash_ids === undefined), - hash_id = self.$object_id(), - result = ['Hash'], - key, item; - - try { - if (top) { - Opal.hash_ids = Object.create(null); - } + if (self.uninitialized) { + $Kernel.$raise($$$('TypeError'), "uninitialized Regexp"); + } - if (Opal[hash_id]) { - return 'self'; + if (pos === undefined) { + if (string === nil) return ($gvars["~"] = nil); + var m = self.exec($coerce_to(string, $$$('String'), 'to_str')); + if (m) { + ($gvars["~"] = $$$('MatchData').$new(self, m)); + return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]); + } else { + return ($gvars["~"] = nil); } + } - for (key in Opal.hash_ids) { - item = Opal.hash_ids[key]; - if (self['$eql?'](item)) { - return 'self'; - } - } + pos = $coerce_to(pos, $$$('Integer'), 'to_int'); - Opal.hash_ids[hash_id] = self; + if (string === nil) { + return ($gvars["~"] = nil); + } - for (var i = 0, keys = self.$$keys, length = keys.length; i < length; i++) { - key = keys[i]; + string = $coerce_to(string, $$$('String'), 'to_str'); - if (key.$$is_string) { - result.push([key, self.$$smap[key].$hash()]); - } else { - result.push([key.key_hash, key.value.$hash()]); - } + if (pos < 0) { + pos += string.length; + if (pos < 0) { + return ($gvars["~"] = nil); } + } - return result.sort().join(); + // global RegExp maintains state, so not using self/this + var md, re = Opal.global_regexp(self); - } finally { - if (top) { - Opal.hash_ids = undefined; + while (true) { + md = re.exec(string); + if (md === null) { + return ($gvars["~"] = nil); } + if (md.index >= pos) { + ($gvars["~"] = $$$('MatchData').$new(re, md)); + return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]); + } + re.lastIndex = md.index + 1; } + }, -2); - }, $Hash_hash$41.$$arity = 0); - Opal.alias(self, "include?", "has_key?"); - - Opal.def(self, '$index', $Hash_index$42 = function $$index(object) { + $def(self, '$match?', function $Regexp_match$ques$5(string, pos) { var self = this; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + if (self.uninitialized) { + $Kernel.$raise($$$('TypeError'), "uninitialized Regexp"); + } - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + if (pos === undefined) { + return string === nil ? false : self.test($coerce_to(string, $$$('String'), 'to_str')); + } - if ((value)['$=='](object)) { - return key; + pos = $coerce_to(pos, $$$('Integer'), 'to_int'); + + if (string === nil) { + return false; + } + + string = $coerce_to(string, $$$('String'), 'to_str'); + + if (pos < 0) { + pos += string.length; + if (pos < 0) { + return false; } } - return nil; + // global RegExp maintains state, so not using self/this + var md, re = Opal.global_regexp(self); + + md = re.exec(string); + if (md === null || md.index < pos) { + return false; + } else { + return true; + } + }, -2); - }, $Hash_index$42.$$arity = 1); + $def(self, '$names', function $$names() { + var self = this; + + return $send(self.$source().$scan(/\(?<(\w+)>/, $hash2(["no_matchdata"], {"no_matchdata": true})), 'map', [], "first".$to_proc()).$uniq() + }); - Opal.def(self, '$indexes', $Hash_indexes$43 = function $$indexes($a) { - var $post_args, args, self = this; + $def(self, '$named_captures', function $$named_captures() { + var self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - var result = []; + return $send($send($send(self.$source().$scan(/\(?<(\w+)>/, $hash2(["no_matchdata"], {"no_matchdata": true})), 'map', [], "first".$to_proc()).$each_with_index(), 'group_by', [], "first".$to_proc()), 'transform_values', [], function $$6(i){ + + if (i == null) i = nil; + return $send(i, 'map', [], function $$7(j){ + + if (j == null) j = nil; + return $rb_plus(j.$last(), 1);});}) + }); + + $def(self, '$~', function $Regexp_$$8() { + var self = this; + if ($gvars._ == null) $gvars._ = nil; - for (var i = 0, length = args.length, key, value; i < length; i++) { - key = args[i]; - value = Opal.hash_get(self, key); + return self['$=~']($gvars._) + }); + + $def(self, '$source', function $$source() { + var self = this; - if (value === undefined) { - result.push(self.$default()); - continue; - } + return self.source; + }); + + $def(self, '$options', function $$options() { + var self = this; - result.push(value); + + if (self.uninitialized) { + $Kernel.$raise($$$('TypeError'), "uninitialized Regexp"); + } + var result = 0; + // should be supported in IE6 according to https://msdn.microsoft.com/en-us/library/7f5z26w4(v=vs.94).aspx + if (self.multiline) { + result |= $$('MULTILINE'); + } + if (self.ignoreCase) { + result |= $$('IGNORECASE'); } - return result; - ; - }, $Hash_indexes$43.$$arity = -1); - Opal.alias(self, "indices", "indexes"); - var inspect_ids; - Opal.def(self, '$inspect', $Hash_inspect$44 = function $$inspect() { + }); + + $def(self, '$casefold?', function $Regexp_casefold$ques$9() { var self = this; + return self.ignoreCase; + }); + $alias(self, "eql?", "=="); + return $alias(self, "to_s", "source"); + })('::', RegExp, $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'MatchData'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + + $proto.matches = nil; + + self.$attr_reader("post_match", "pre_match", "regexp", "string"); + + $def(self, '$initialize', function $$initialize(regexp, match_groups, $kwargs) { + var no_matchdata, self = this; + - var top = (inspect_ids === undefined), - hash_id = self.$object_id(), - result = []; + $kwargs = $ensure_kwargs($kwargs); + + no_matchdata = $kwargs.$$smap["no_matchdata"];if (no_matchdata == null) no_matchdata = false; + if (!$truthy(no_matchdata)) { + $gvars["~"] = self; + } self.regexp = regexp; + self.begin = match_groups.index; + self.string = match_groups.input; + self.pre_match = match_groups.input.slice(0, match_groups.index); + self.post_match = match_groups.input.slice(match_groups.index + match_groups[0].length); + self.matches = []; + + for (var i = 0, length = match_groups.length; i < length; i++) { + var group = match_groups[i]; - try { - if (top) { - inspect_ids = {}; + if (group == null) { + self.matches.push(nil); } - - if (inspect_ids.hasOwnProperty(hash_id)) { - return '{...}'; + else { + self.matches.push(group); } + } + }, -3); + + $def(self, '$match', function $$match(idx) { + var self = this, match = nil; - inspect_ids[hash_id] = true; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + if ($truthy((match = self['$[]'](idx)))) { + return match + } else if (($truthy(idx['$is_a?']($$('Integer'))) && ($truthy($rb_ge(idx, self.$length()))))) { + return $Kernel.$raise($$$('IndexError'), "index " + (idx) + " out of matches") + } else { + return nil + } + }); + + $def(self, '$match_length', function $$match_length(idx) { + var $a, self = this; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + return ($a = self.$match(idx), ($a === nil || $a == null) ? nil : $a.$length()) + }); + + $def(self, '$[]', function $MatchData_$$$10($a) { + var $post_args, args, self = this; - result.push(key.$inspect() + '=>' + value.$inspect()); + + $post_args = $slice(arguments); + args = $post_args; + + if (args[0].$$is_string) { + if (self.$regexp().$names()['$include?'](args['$[]'](0))['$!']()) { + $Kernel.$raise($$$('IndexError'), "undefined group name reference: " + (args['$[]'](0))); } + return self.$named_captures()['$[]'](args['$[]'](0)) + } + else { + return $send(self.matches, '[]', $to_a(args)) + } + }, -1); + + $def(self, '$offset', function $$offset(n) { + var self = this; - return '{' + result.join(', ') + '}'; + + if (n !== 0) { + $Kernel.$raise($$$('ArgumentError'), "MatchData#offset only supports 0th element"); + } + return [self.begin, self.begin + self.matches[n].length]; + + }); + + $def(self, '$==', function $MatchData_$eq_eq$11(other) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil; - } finally { - if (top) { - inspect_ids = undefined; - } + + if (!$eqeqeq($$$('MatchData'), other)) { + return false + } if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = self.string == other.string)) ? (self.regexp.toString() == other.regexp.toString()) : ($ret_or_4)))) ? (self.pre_match == other.pre_match) : ($ret_or_3)))) ? (self.post_match == other.post_match) : ($ret_or_2))))) { + return self.begin == other.begin; + } else { + return $ret_or_1 + } }); + + $def(self, '$begin', function $$begin(n) { + var self = this; + + + if (n !== 0) { + $Kernel.$raise($$$('ArgumentError'), "MatchData#begin only supports 0th element"); } + return self.begin; - }, $Hash_inspect$44.$$arity = 0); + }); - Opal.def(self, '$invert', $Hash_invert$45 = function $$invert() { + $def(self, '$end', function $$end(n) { var self = this; - var hash = Opal.hash(); + if (n !== 0) { + $Kernel.$raise($$$('ArgumentError'), "MatchData#end only supports 0th element"); + } + return self.begin + self.matches[n].length; + + }); + + $def(self, '$captures', function $$captures() { + var self = this; - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + return self.matches.slice(1) + }); + + $def(self, '$named_captures', function $$named_captures() { + var self = this, matches = nil; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + + matches = self.$captures(); + return $send(self.$regexp().$named_captures(), 'transform_values', [], function $$12(i){ + + if (i == null) i = nil; + return matches['$[]']($rb_minus(i.$last(), 1));}); + }); + + $def(self, '$names', function $$names() { + var self = this; + + return self.$regexp().$names() + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; - Opal.hash_put(hash, value, key); + + var str = "#<MatchData " + (self.matches[0]).$inspect(); + + if (self.$regexp().$names()['$empty?']()) { + for (var i = 1, length = self.matches.length; i < length; i++) { + str += " " + i + ":" + (self.matches[i]).$inspect(); + } + } + else { + $send(self.$named_captures(), 'each', [], function $$13(k, v){ + + if (k == null) k = nil; + if (v == null) v = nil; + return str += " " + k + ":" + v.$inspect();}); } - return hash; + return str + ">"; + + }); + + $def(self, '$length', function $$length() { + var self = this; + + return self.matches.length + }); - }, $Hash_invert$45.$$arity = 0); + $def(self, '$to_a', $return_ivar("matches")); - Opal.def(self, '$keep_if', $Hash_keep_if$46 = function $$keep_if() { - var $iter = $Hash_keep_if$46.$$p, block = $iter || nil, $$47, self = this; + $def(self, '$to_s', function $$to_s() { + var self = this; + + return self.matches[0] + }); + + $def(self, '$values_at', function $$values_at($a) { + var $post_args, args, self = this; - if ($iter) $Hash_keep_if$46.$$p = null; + $post_args = $slice(arguments); + args = $post_args; - if ($iter) $Hash_keep_if$46.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["keep_if"], ($$47 = function(){var self = $$47.$$s || this; + var i, a, index, values = []; - return self.$size()}, $$47.$$s = self, $$47.$$arity = 0, $$47)) - }; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + for (i = 0; i < args.length; i++) { - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (args[i].$$is_range) { + a = (args[i]).$to_a(); + a.unshift(i, 1); + Array.prototype.splice.apply(args, a); } - obj = block(key, value); + index = $Opal['$coerce_to!'](args[i], $$$('Integer'), "to_int"); - if (obj === false || obj === nil) { - if (Opal.hash_delete(self, key) !== undefined) { - length--; - i--; + if (index < 0) { + index += self.matches.length; + if (index < 0) { + values.push(nil); + continue; } } + + values.push(self.matches[index]); } - return self; - ; - }, $Hash_keep_if$46.$$arity = 0); - Opal.alias(self, "key", "index"); - Opal.alias(self, "key?", "has_key?"); - - Opal.def(self, '$keys', $Hash_keys$48 = function $$keys() { - var self = this; + return values; + }, -1); + $alias(self, "eql?", "=="); + return $alias(self, "size", "length"); + })($nesting[0], null, $nesting); +}; - - var result = []; +Opal.modules["corelib/string"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $global_multiline_regexp = Opal.global_multiline_regexp, $prop = Opal.prop, $klass = Opal.klass, $def = Opal.def, $Opal = Opal.Opal, $defs = Opal.defs, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $gvars = Opal.gvars, $rb_divide = Opal.rb_divide, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $hash2 = Opal.hash2, $alias = Opal.alias, $const_set = Opal.const_set, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$; - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + Opal.add_stubs('require,include,coerce_to?,initialize,===,format,raise,respond_to?,to_s,to_str,<=>,==,=~,new,force_encoding,casecmp,empty?,ljust,ceil,/,+,rjust,floor,coerce_to!,nil?,class,copy_singleton_methods,initialize_clone,initialize_dup,enum_for,chomp,[],to_i,length,each_line,to_proc,to_a,match,match?,captures,proc,succ,escape,include?,upcase,unicode_normalize,dup,__id__,next,intern,pristine'); + + self.$require("corelib/comparable"); + self.$require("corelib/regexp"); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'String'); - if (key.$$is_string) { - result.push(key); - } else { - result.push(key.key); - } - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - return result; - }, $Hash_keys$48.$$arity = 0); + self.$include($$$('Comparable')); + + Opal.prop(self.$$prototype, '$$is_string', true); - Opal.def(self, '$length', $Hash_length$49 = function $$length() { + $def(self, '$__id__', function $$__id__() { var self = this; - return self.$$keys.length; - }, $Hash_length$49.$$arity = 0); - Opal.alias(self, "member?", "has_key?"); - - Opal.def(self, '$merge', $Hash_merge$50 = function $$merge(other) { - var $iter = $Hash_merge$50.$$p, block = $iter || nil, self = this; + return self.toString(); + }); + $defs(self, '$try_convert', function $$try_convert(what) { + + return $Opal['$coerce_to?'](what, $$$('String'), "to_str") + }); + $defs(self, '$new', function $String_new$1($a) { + var $post_args, args, self = this; - if ($iter) $Hash_merge$50.$$p = null; + $post_args = $slice(arguments); + args = $post_args; - if ($iter) $Hash_merge$50.$$p = null;; - return $send(self.$dup(), 'merge!', [other], block.$to_proc()); - }, $Hash_merge$50.$$arity = 1); + var str = args[0] || ""; + var opts = args[args.length-1]; + str = $coerce_to(str, $$$('String'), 'to_str'); + if (opts && opts.$$is_hash) { + if (opts.$$smap.encoding) str = str.$force_encoding(opts.$$smap.encoding); + } + str = new self.$$constructor(str); + if (!str.$initialize.$$pristine) $send((str), 'initialize', $to_a(args)); + return str; + }, -1); - Opal.def(self, '$merge!', $Hash_merge$excl$51 = function(other) { - var $iter = $Hash_merge$excl$51.$$p, block = $iter || nil, self = this; + $def(self, '$initialize', function $$initialize($a, $b) { + var $post_args, $kwargs; - if ($iter) $Hash_merge$excl$51.$$p = null; - - if ($iter) $Hash_merge$excl$51.$$p = null;; + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); - if (!other.$$is_hash) { - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - } - - var i, other_keys = other.$$keys, length = other_keys.length, key, value, other_value; + if ($post_args.length > 0) $post_args.shift(); + $kwargs.$$smap["encoding"]; + $kwargs.$$smap["capacity"]; return nil; + }, -1); + + $def(self, '$%', function $String_$percent$2(data) { + var self = this; - if (block === nil) { - for (i = 0; i < length; i++) { - key = other_keys[i]; + if ($eqeqeq($$$('Array'), data)) { + return $send(self, 'format', [self].concat($to_a(data))) + } else { + return self.$format(self, data) + } + }); + + $def(self, '$*', function $String_$$3(count) { + var self = this; - if (key.$$is_string) { - other_value = other.$$smap[key]; - } else { - other_value = key.value; - key = key.key; - } + + count = $coerce_to(count, $$$('Integer'), 'to_int'); - Opal.hash_put(self, key, other_value); - } + if (count < 0) { + $Kernel.$raise($$$('ArgumentError'), "negative argument"); + } - return self; + if (count === 0) { + return ''; } - for (i = 0; i < length; i++) { - key = other_keys[i]; + var result = '', + string = self.toString(); - if (key.$$is_string) { - other_value = other.$$smap[key]; - } else { - other_value = key.value; - key = key.key; - } + // All credit for the bit-twiddling magic code below goes to Mozilla + // polyfill implementation of String.prototype.repeat() posted here: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat - value = Opal.hash_get(self, key); + if (string.length * count >= 1 << 28) { + $Kernel.$raise($$$('RangeError'), "multiply count must not overflow maximum string size"); + } - if (value === undefined) { - Opal.hash_put(self, key, other_value); - continue; + for (;;) { + if ((count & 1) === 1) { + result += string; } - - Opal.hash_put(self, key, block(key, value, other_value)); + count >>>= 1; + if (count === 0) { + break; + } + string += string; } - return self; - ; - }, $Hash_merge$excl$51.$$arity = 1); + return result; - Opal.def(self, '$rassoc', $Hash_rassoc$52 = function $$rassoc(object) { + }); + + $def(self, '$+', function $String_$plus$4(other) { var self = this; - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + other = $coerce_to(other, $$$('String'), 'to_str'); + + if (other == "" && self.$$class === Opal.String) return self; + if (self == "" && other.$$class === Opal.String) return other; + var out = self + other; + if (self.encoding === out.encoding && other.encoding === out.encoding) return out; + if (self.encoding.name === "UTF-8" || other.encoding.name === "UTF-8") return out; + return Opal.enc(out, self.encoding); + }); + + $def(self, '$<=>', function $String_$lt_eq_gt$5(other) { + var self = this; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + if ($truthy(other['$respond_to?']("to_str"))) { + + other = other.$to_str().$to_s(); + return self > other ? 1 : (self < other ? -1 : 0); } else { + + var cmp = other['$<=>'](self); - if ((value)['$=='](object)) { - return [key, value]; + if (cmp === nil) { + return nil; + } + else { + return cmp > 0 ? -1 : (cmp < 0 ? 1 : 0); } + } - - return nil; - - }, $Hash_rassoc$52.$$arity = 1); + }); - Opal.def(self, '$rehash', $Hash_rehash$53 = function $$rehash() { + $def(self, '$==', function $String_$eq_eq$6(other) { var self = this; - Opal.hash_rehash(self); - return self; + if (other.$$is_string) { + return self.toString() === other.toString(); + } + if ($respond_to(other, '$to_str')) { + return other['$=='](self); + } + return false; - }, $Hash_rehash$53.$$arity = 0); + }); - Opal.def(self, '$reject', $Hash_reject$54 = function $$reject() { - var $iter = $Hash_reject$54.$$p, block = $iter || nil, $$55, self = this; + $def(self, '$=~', function $String_$eq_tilde$7(other) { + var self = this; - if ($iter) $Hash_reject$54.$$p = null; - - if ($iter) $Hash_reject$54.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["reject"], ($$55 = function(){var self = $$55.$$s || this; + if (other.$$is_string) { + $Kernel.$raise($$$('TypeError'), "type mismatch: String given"); + } - return self.$size()}, $$55.$$s = self, $$55.$$arity = 0, $$55)) - }; + return other['$=~'](self); + + }); + + $def(self, '$[]', function $String_$$$8(index, length) { + var self = this; - var hash = Opal.hash(); + var size = self.length, exclude, range; - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + if (index.$$is_range) { + exclude = index.excl; + range = index; + length = index.end === nil ? -1 : $coerce_to(index.end, $$$('Integer'), 'to_int'); + index = index.begin === nil ? 0 : $coerce_to(index.begin, $$$('Integer'), 'to_int'); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (Math.abs(index) > size) { + return nil; } - obj = block(key, value); - - if (obj === false || obj === nil) { - Opal.hash_put(hash, key, value); + if (index < 0) { + index += size; } - } - - return hash; - ; - }, $Hash_reject$54.$$arity = 0); - - Opal.def(self, '$reject!', $Hash_reject$excl$56 = function() { - var $iter = $Hash_reject$excl$56.$$p, block = $iter || nil, $$57, self = this; - if ($iter) $Hash_reject$excl$56.$$p = null; - - - if ($iter) $Hash_reject$excl$56.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["reject!"], ($$57 = function(){var self = $$57.$$s || this; + if (length < 0) { + length += size; + } - return self.$size()}, $$57.$$s = self, $$57.$$arity = 0, $$57)) - }; - - var changes_were_made = false; + if (!exclude || range.end === nil) { + length += 1; + } - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + length = length - index; - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (length < 0) { + length = 0; } - obj = block(key, value); + return self.substr(index, length); + } - if (obj !== false && obj !== nil) { - if (Opal.hash_delete(self, key) !== undefined) { - changes_were_made = true; - length--; - i--; - } + + if (index.$$is_string) { + if (length != null) { + $Kernel.$raise($$$('TypeError')); } + return self.indexOf(index) !== -1 ? index : nil; } - return changes_were_made ? self : nil; - ; - }, $Hash_reject$excl$56.$$arity = 0); - - Opal.def(self, '$replace', $Hash_replace$58 = function $$replace(other) { - var self = this, $writer = nil; - - - other = $$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Hash'), "to_hash"); - - Opal.hash_init(self); - for (var i = 0, other_keys = other.$$keys, length = other_keys.length, key, value, other_value; i < length; i++) { - key = other_keys[i]; + if (index.$$is_regexp) { + var match = self.match(index); - if (key.$$is_string) { - other_value = other.$$smap[key]; - } else { - other_value = key.value; - key = key.key; + if (match === null) { + ($gvars["~"] = nil); + return nil; } - Opal.hash_put(self, key, other_value); - } - ; - if ($truthy(other.$default_proc())) { - - $writer = [other.$default_proc()]; - $send(self, 'default_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)]; - } else { - - $writer = [other.$default()]; - $send(self, 'default=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)]; - }; - return self; - }, $Hash_replace$58.$$arity = 1); - - Opal.def(self, '$select', $Hash_select$59 = function $$select() { - var $iter = $Hash_select$59.$$p, block = $iter || nil, $$60, self = this; - - if ($iter) $Hash_select$59.$$p = null; - - - if ($iter) $Hash_select$59.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["select"], ($$60 = function(){var self = $$60.$$s || this; + ($gvars["~"] = $$$('MatchData').$new(index, match)); - return self.$size()}, $$60.$$s = self, $$60.$$arity = 0, $$60)) - }; - - var hash = Opal.hash(); + if (length == null) { + return match[0]; + } - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + length = $coerce_to(length, $$$('Integer'), 'to_int'); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (length < 0 && -length < match.length) { + return match[length += match.length]; } - obj = block(key, value); - - if (obj !== false && obj !== nil) { - Opal.hash_put(hash, key, value); + if (length >= 0 && length < match.length) { + return match[length]; } - } - return hash; - ; - }, $Hash_select$59.$$arity = 0); - - Opal.def(self, '$select!', $Hash_select$excl$61 = function() { - var $iter = $Hash_select$excl$61.$$p, block = $iter || nil, $$62, self = this; + return nil; + } - if ($iter) $Hash_select$excl$61.$$p = null; - - - if ($iter) $Hash_select$excl$61.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["select!"], ($$62 = function(){var self = $$62.$$s || this; - return self.$size()}, $$62.$$s = self, $$62.$$arity = 0, $$62)) - }; - - var result = nil; + index = $coerce_to(index, $$$('Integer'), 'to_int'); - for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { - key = keys[i]; + if (index < 0) { + index += size; + } - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (length == null) { + if (index >= size || index < 0) { + return nil; } + return self.substr(index, 1); + } - obj = block(key, value); + length = $coerce_to(length, $$$('Integer'), 'to_int'); - if (obj === false || obj === nil) { - if (Opal.hash_delete(self, key) !== undefined) { - length--; - i--; - } - result = self; - } + if (length < 0) { + return nil; } - return result; - ; - }, $Hash_select$excl$61.$$arity = 0); + if (index > size || index < 0) { + return nil; + } + + return self.substr(index, length); + }, -2); - Opal.def(self, '$shift', $Hash_shift$63 = function $$shift() { + $def(self, '$b', function $$b() { var self = this; - - var keys = self.$$keys, - key; - - if (keys.length > 0) { - key = keys[0]; + return (new String(self)).$force_encoding("binary") + }); + + $def(self, '$capitalize', function $$capitalize() { + var self = this; - key = key.$$is_string ? key : key.key; + return self.charAt(0).toUpperCase() + self.substr(1).toLowerCase(); + }); + + $def(self, '$casecmp', function $$casecmp(other) { + var self = this; - return [key, Opal.hash_delete(self, key)]; + + if (!$truthy(other['$respond_to?']("to_str"))) { + return nil + } other = ($coerce_to(other, $$$('String'), 'to_str')).$to_s(); + + var ascii_only = /^[\x00-\x7F]*$/; + if (ascii_only.test(self) && ascii_only.test(other)) { + self = self.toLowerCase(); + other = other.toLowerCase(); } + return self['$<=>'](other); + }); + + $def(self, '$casecmp?', function $String_casecmp$ques$9(other) { + var self = this; - return self.$default(nil); + + var cmp = self.$casecmp(other); + if (cmp === nil) { + return nil; + } else { + return cmp === 0; + } - }, $Hash_shift$63.$$arity = 0); - Opal.alias(self, "size", "length"); + }); - Opal.def(self, '$slice', $Hash_slice$64 = function $$slice($a) { - var $post_args, keys, self = this; + $def(self, '$center', function $$center(width, padstr) { + var self = this; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - keys = $post_args;; - - var result = Opal.hash(); - - for (var i = 0, length = keys.length; i < length; i++) { - var key = keys[i], value = Opal.hash_get(self, key); - - if (value !== undefined) { - Opal.hash_put(result, key, value); - } - } + if (padstr == null) padstr = " "; + width = $coerce_to(width, $$$('Integer'), 'to_int'); + padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s(); + if ($truthy(padstr['$empty?']())) { + $Kernel.$raise($$$('ArgumentError'), "zero width padding"); + } if ($truthy(width <= self.length)) { + return self + } + var ljustified = self.$ljust($rb_divide($rb_plus(width, self.length), 2).$ceil(), padstr), + rjustified = self.$rjust($rb_divide($rb_plus(width, self.length), 2).$floor(), padstr); - return result; - ; - }, $Hash_slice$64.$$arity = -1); - Opal.alias(self, "store", "[]="); + return rjustified + ljustified.slice(self.length); + }, -2); - Opal.def(self, '$to_a', $Hash_to_a$65 = function $$to_a() { + $def(self, '$chomp', function $$chomp(separator) { var self = this; + if ($gvars["/"] == null) $gvars["/"] = nil; - var result = []; + if (separator == null) separator = $gvars["/"]; + if ($truthy(separator === nil || self.length === 0)) { + return self + } separator = $Opal['$coerce_to!'](separator, $$$('String'), "to_str").$to_s(); + + var result; - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + if (separator === "\n") { + result = self.replace(/\r?\n?$/, ''); + } + else if (separator === "") { + result = self.replace(/(\r?\n)+$/, ''); + } + else if (self.length >= separator.length) { + var tail = self.substr(self.length - separator.length, separator.length); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (tail === separator) { + result = self.substr(0, self.length - separator.length); } - - result.push([key, value]); } - return result; - - }, $Hash_to_a$65.$$arity = 0); + if (result != null) { + return result; + } + return self; + }, -1); - Opal.def(self, '$to_h', $Hash_to_h$66 = function $$to_h() { + $def(self, '$chop', function $$chop() { var self = this; - if (self.$$class === Opal.Hash) { - return self; - } - - var hash = new Opal.Hash(); + var length = self.length, result; - Opal.hash_init(hash); - Opal.hash_clone(self, hash); + if (length <= 1) { + result = ""; + } else if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") { + result = self.substr(0, length - 2); + } else { + result = self.substr(0, length - 1); + } - return hash; + return result; - }, $Hash_to_h$66.$$arity = 0); + }); - Opal.def(self, '$to_hash', $Hash_to_hash$67 = function $$to_hash() { + $def(self, '$chr', function $$chr() { var self = this; - return self - }, $Hash_to_hash$67.$$arity = 0); + return self.charAt(0); + }); - Opal.def(self, '$to_proc', $Hash_to_proc$68 = function $$to_proc() { - var $$69, self = this; + $def(self, '$clone', function $$clone($kwargs) { + var freeze, self = this, copy = nil; - return $send(self, 'proc', [], ($$69 = function(key){var self = $$69.$$s || this; + + $kwargs = $ensure_kwargs($kwargs); + + freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = nil; + if (!(($truthy(freeze['$nil?']()) || ($eqeq(freeze, true))) || ($eqeq(freeze, false)))) { + self.$raise($$('ArgumentError'), "unexpected value for freeze: " + (freeze.$class())); + } copy = new String(self); + copy.$copy_singleton_methods(self); + copy.$initialize_clone(self, $hash2(["freeze"], {"freeze": freeze})); + if ($eqeq(freeze, true)) { + if (!copy.$$frozen) { copy.$$frozen = true; } + } else if ($truthy(freeze['$nil?']())) { + if (self.$$frozen) { copy.$$frozen = true; } + } return copy; + }, -1); + + $def(self, '$dup', function $$dup() { + var self = this, copy = nil; - ; - - if (key == null) { - self.$raise($$($nesting, 'ArgumentError'), "no key given") - } - ; - return self['$[]'](key);}, $$69.$$s = self, $$69.$$arity = -1, $$69)) - }, $Hash_to_proc$68.$$arity = 0); - Opal.alias(self, "to_s", "inspect"); + copy = new String(self); + copy.$initialize_dup(self); + return copy; + }); - Opal.def(self, '$transform_keys', $Hash_transform_keys$70 = function $$transform_keys() { - var $iter = $Hash_transform_keys$70.$$p, block = $iter || nil, $$71, self = this; + $def(self, '$count', function $$count($a) { + var $post_args, sets, self = this; - if ($iter) $Hash_transform_keys$70.$$p = null; + $post_args = $slice(arguments); + sets = $post_args; - if ($iter) $Hash_transform_keys$70.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["transform_keys"], ($$71 = function(){var self = $$71.$$s || this; - - return self.$size()}, $$71.$$s = self, $$71.$$arity = 0, $$71)) - }; - - var result = Opal.hash(); - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; - - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } - - key = Opal.yield1(block, key); - - Opal.hash_put(result, key, value); + if (sets.length === 0) { + $Kernel.$raise($$$('ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)"); } - - return result; - ; - }, $Hash_transform_keys$70.$$arity = 0); + var char_class = char_class_from_char_sets(sets); + if (char_class === null) { + return 0; + } + return self.length - self.replace(new RegExp(char_class, 'g'), '').length; + }, -1); - Opal.def(self, '$transform_keys!', $Hash_transform_keys$excl$72 = function() { - var $iter = $Hash_transform_keys$excl$72.$$p, block = $iter || nil, $$73, self = this; + $def(self, '$delete', function $String_delete$10($a) { + var $post_args, sets, self = this; - if ($iter) $Hash_transform_keys$excl$72.$$p = null; + $post_args = $slice(arguments); + sets = $post_args; - if ($iter) $Hash_transform_keys$excl$72.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["transform_keys!"], ($$73 = function(){var self = $$73.$$s || this; + if (sets.length === 0) { + $Kernel.$raise($$$('ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)"); + } + var char_class = char_class_from_char_sets(sets); + if (char_class === null) { + return self; + } + return self.replace(new RegExp(char_class, 'g'), ''); + }, -1); + + $def(self, '$delete_prefix', function $$delete_prefix(prefix) { + var self = this; - return self.$size()}, $$73.$$s = self, $$73.$$arity = 0, $$73)) - }; - var keys = Opal.slice.call(self.$$keys), - i, length = keys.length, key, value, new_key; - - for (i = 0; i < length; i++) { - key = keys[i]; + if (!prefix.$$is_string) { + prefix = $coerce_to(prefix, $$$('String'), 'to_str'); + } - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; - } + if (self.slice(0, prefix.length) === prefix) { + return self.slice(prefix.length); + } else { + return self; + } + + }); + + $def(self, '$delete_suffix', function $$delete_suffix(suffix) { + var self = this; - new_key = Opal.yield1(block, key); + + if (!suffix.$$is_string) { + suffix = $coerce_to(suffix, $$$('String'), 'to_str'); + } - Opal.hash_delete(self, key); - Opal.hash_put(self, new_key, value); + if (self.slice(self.length - suffix.length) === suffix) { + return self.slice(0, self.length - suffix.length); + } else { + return self; } + + }); + + $def(self, '$downcase', function $$downcase() { + var self = this; - return self; - ; - }, $Hash_transform_keys$excl$72.$$arity = 0); + return self.toLowerCase(); + }); - Opal.def(self, '$transform_values', $Hash_transform_values$74 = function $$transform_values() { - var $iter = $Hash_transform_values$74.$$p, block = $iter || nil, $$75, self = this; + $def(self, '$each_line', function $$each_line($a, $b) { + var block = $$each_line.$$p || nil, $post_args, $kwargs, separator, chomp, self = this; + if ($gvars["/"] == null) $gvars["/"] = nil; - if ($iter) $Hash_transform_values$74.$$p = null; + $$each_line.$$p = null; + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + if ($post_args.length > 0) separator = $post_args.shift();if (separator == null) separator = $gvars["/"]; - if ($iter) $Hash_transform_values$74.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["transform_values"], ($$75 = function(){var self = $$75.$$s || this; + chomp = $kwargs.$$smap["chomp"];if (chomp == null) chomp = false; + if (!(block !== nil)) { + return self.$enum_for("each_line", separator, $hash2(["chomp"], {"chomp": chomp})) + } + if (separator === nil) { + Opal.yield1(block, self); - return self.$size()}, $$75.$$s = self, $$75.$$arity = 0, $$75)) - }; - - var result = Opal.hash(); + return self; + } - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + separator = $coerce_to(separator, $$$('String'), 'to_str'); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + var a, i, n, length, chomped, trailing, splitted, value; + + if (separator.length === 0) { + for (a = self.split(/((?:\r?\n){2})(?:(?:\r?\n)*)/), i = 0, n = a.length; i < n; i += 2) { + if (a[i] || a[i + 1]) { + value = (a[i] || "") + (a[i + 1] || ""); + if (chomp) { + value = (value).$chomp("\n"); + } + Opal.yield1(block, value); + } } - value = Opal.yield1(block, value); + return self; + } + + chomped = self.$chomp(separator); + trailing = self.length != chomped.length; + splitted = chomped.split(separator); - Opal.hash_put(result, key, value); + for (i = 0, length = splitted.length; i < length; i++) { + value = splitted[i]; + if (i < length - 1 || trailing) { + value += separator; + } + if (chomp) { + value = (value).$chomp(separator); + } + Opal.yield1(block, value); } + return self; + }, -1); + + $def(self, '$empty?', function $String_empty$ques$11() { + var self = this; - return result; - ; - }, $Hash_transform_values$74.$$arity = 0); + return self.length === 0; + }); - Opal.def(self, '$transform_values!', $Hash_transform_values$excl$76 = function() { - var $iter = $Hash_transform_values$excl$76.$$p, block = $iter || nil, $$77, self = this; + $def(self, '$end_with?', function $String_end_with$ques$12($a) { + var $post_args, suffixes, self = this; - if ($iter) $Hash_transform_values$excl$76.$$p = null; + $post_args = $slice(arguments); + suffixes = $post_args; - if ($iter) $Hash_transform_values$excl$76.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["transform_values!"], ($$77 = function(){var self = $$77.$$s || this; - - return self.$size()}, $$77.$$s = self, $$77.$$arity = 0, $$77)) - }; - - for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { - key = keys[i]; + for (var i = 0, length = suffixes.length; i < length; i++) { + var suffix = $coerce_to(suffixes[i], $$$('String'), 'to_str').$to_s(); - if (key.$$is_string) { - value = self.$$smap[key]; - } else { - value = key.value; - key = key.key; + if (self.length >= suffix.length && + self.substr(self.length - suffix.length, suffix.length) == suffix) { + return true; } - - value = Opal.yield1(block, value); - - Opal.hash_put(self, key, value); } + return false; + }, -1); + + $def(self, '$gsub', function $$gsub(pattern, replacement) { + var block = $$gsub.$$p || nil, self = this; - return self; - ; - }, $Hash_transform_values$excl$76.$$arity = 0); - Opal.alias(self, "update", "merge!"); - Opal.alias(self, "value?", "has_value?"); - Opal.alias(self, "values_at", "indexes"); - return (Opal.def(self, '$values', $Hash_values$78 = function $$values() { - var self = this; - + $$gsub.$$p = null; - var result = []; + if (replacement === undefined && block === nil) { + return self.$enum_for("gsub", pattern); + } - for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { - key = keys[i]; + var result = '', match_data = nil, index = 0, match, _replacement; - if (key.$$is_string) { - result.push(self.$$smap[key]); - } else { - result.push(key.value); - } + if (pattern.$$is_regexp) { + pattern = $global_multiline_regexp(pattern); + } else { + pattern = $coerce_to(pattern, $$$('String'), 'to_str'); + pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); } - return result; - - }, $Hash_values$78.$$arity = 0), nil) && 'values'; - })($nesting[0], null, $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/number"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_divide(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); - } - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send, $hash2 = Opal.hash2; + var lastIndex; + while (true) { + match = pattern.exec(self); - Opal.add_stubs(['$require', '$bridge', '$raise', '$name', '$class', '$Float', '$respond_to?', '$coerce_to!', '$__coerced__', '$===', '$!', '$>', '$**', '$new', '$<', '$to_f', '$==', '$nan?', '$infinite?', '$enum_for', '$+', '$-', '$gcd', '$lcm', '$%', '$/', '$frexp', '$to_i', '$ldexp', '$rationalize', '$*', '$<<', '$to_r', '$truncate', '$-@', '$size', '$<=', '$>=', '$<=>', '$compare', '$any?']); - - self.$require("corelib/numeric"); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Number'); + if (match === null) { + ($gvars["~"] = nil); + result += self.slice(index); + break; + } - var $nesting = [self].concat($parent_nesting), $Number_coerce$2, $Number___id__$3, $Number_$plus$4, $Number_$minus$5, $Number_$$6, $Number_$slash$7, $Number_$percent$8, $Number_$$9, $Number_$$10, $Number_$$11, $Number_$lt$12, $Number_$lt_eq$13, $Number_$gt$14, $Number_$gt_eq$15, $Number_$lt_eq_gt$16, $Number_$lt$lt$17, $Number_$gt$gt$18, $Number_$$$19, $Number_$plus$$20, $Number_$minus$$21, $Number_$$22, $Number_$$$23, $Number_$eq_eq_eq$24, $Number_$eq_eq$25, $Number_abs$26, $Number_abs2$27, $Number_allbits$ques$28, $Number_anybits$ques$29, $Number_angle$30, $Number_bit_length$31, $Number_ceil$32, $Number_chr$33, $Number_denominator$34, $Number_downto$35, $Number_equal$ques$37, $Number_even$ques$38, $Number_floor$39, $Number_gcd$40, $Number_gcdlcm$41, $Number_integer$ques$42, $Number_is_a$ques$43, $Number_instance_of$ques$44, $Number_lcm$45, $Number_next$46, $Number_nobits$ques$47, $Number_nonzero$ques$48, $Number_numerator$49, $Number_odd$ques$50, $Number_ord$51, $Number_pow$52, $Number_pred$53, $Number_quo$54, $Number_rationalize$55, $Number_remainder$56, $Number_round$57, $Number_step$58, $Number_times$60, $Number_to_f$62, $Number_to_i$63, $Number_to_r$64, $Number_to_s$65, $Number_truncate$66, $Number_digits$67, $Number_divmod$68, $Number_upto$69, $Number_zero$ques$71, $Number_size$72, $Number_nan$ques$73, $Number_finite$ques$74, $Number_infinite$ques$75, $Number_positive$ques$76, $Number_negative$ques$77; + match_data = $$$('MatchData').$new(pattern, match); - - $$($nesting, 'Opal').$bridge(Number, self); - Opal.defineProperty(self.$$prototype, '$$is_number', true); - self.$$is_number_class = true; - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$1; + if (replacement === undefined) { + lastIndex = pattern.lastIndex; + _replacement = block(match[0]); + pattern.lastIndex = lastIndex; // save and restore lastIndex + } + else if (replacement.$$is_hash) { + _replacement = (replacement)['$[]'](match[0]).$to_s(); + } + else { + if (!replacement.$$is_string) { + replacement = $coerce_to(replacement, $$$('String'), 'to_str'); + } + _replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) { + if (slashes.length % 2 === 0) { + return original; + } + switch (command) { + case "+": + for (var i = match.length - 1; i > 0; i--) { + if (match[i] !== undefined) { + return slashes.slice(1) + match[i]; + } + } + return ''; + case "&": return slashes.slice(1) + match[0]; + case "`": return slashes.slice(1) + self.slice(0, match.index); + case "'": return slashes.slice(1) + self.slice(match.index + match[0].length); + default: return slashes.slice(1) + (match[command] || ''); + } + }).replace(/\\\\/g, '\\'); + } - - - Opal.def(self, '$allocate', $allocate$1 = function $$allocate() { - var self = this; + if (pattern.lastIndex === match.index) { + result += (self.slice(index, match.index) + _replacement + (self[match.index] || "")); + pattern.lastIndex += 1; + } + else { + result += (self.slice(index, match.index) + _replacement); + } + index = pattern.lastIndex; + } - return self.$raise($$($nesting, 'TypeError'), "" + "allocator undefined for " + (self.$name())) - }, $allocate$1.$$arity = 0); - - - Opal.udef(self, '$' + "new");; - return nil;; - })(Opal.get_singleton_class(self), $nesting); + ($gvars["~"] = match_data); + return result; + }, -2); - Opal.def(self, '$coerce', $Number_coerce$2 = function $$coerce(other) { + $def(self, '$hash', function $$hash() { var self = this; - - if (other === nil) { - self.$raise($$($nesting, 'TypeError'), "" + "can't convert " + (other.$class()) + " into Float"); - } - else if (other.$$is_string) { - return [self.$Float(other), self]; - } - else if (other['$respond_to?']("to_f")) { - return [$$($nesting, 'Opal')['$coerce_to!'](other, $$($nesting, 'Float'), "to_f"), self]; - } - else if (other.$$is_number) { - return [other, self]; - } - else { - self.$raise($$($nesting, 'TypeError'), "" + "can't convert " + (other.$class()) + " into Float"); - } - - }, $Number_coerce$2.$$arity = 1); + return self.toString(); + }); - Opal.def(self, '$__id__', $Number___id__$3 = function $$__id__() { + $def(self, '$hex', function $$hex() { var self = this; - return (self * 2) + 1; - }, $Number___id__$3.$$arity = 0); - Opal.alias(self, "object_id", "__id__"); + return self.$to_i(16) + }); - Opal.def(self, '$+', $Number_$plus$4 = function(other) { + $def(self, '$include?', function $String_include$ques$13(other) { var self = this; - if (other.$$is_number) { - return self + other; - } - else { - return self.$__coerced__("+", other); + if (!other.$$is_string) { + other = $coerce_to(other, $$$('String'), 'to_str'); } + return self.indexOf(other) !== -1; - }, $Number_$plus$4.$$arity = 1); + }); - Opal.def(self, '$-', $Number_$minus$5 = function(other) { + $def(self, '$index', function $$index(search, offset) { var self = this; - - if (other.$$is_number) { - return self - other; + var index, + match, + regex; + + if (offset === undefined) { + offset = 0; + } else { + offset = $coerce_to(offset, $$$('Integer'), 'to_int'); + if (offset < 0) { + offset += self.length; + if (offset < 0) { + return nil; + } + } } - else { - return self.$__coerced__("-", other); + + if (search.$$is_regexp) { + regex = $global_multiline_regexp(search); + while (true) { + match = regex.exec(self); + if (match === null) { + ($gvars["~"] = nil); + index = -1; + break; + } + if (match.index >= offset) { + ($gvars["~"] = $$$('MatchData').$new(regex, match)); + index = match.index; + break; + } + regex.lastIndex = match.index + 1; + } + } else { + search = $coerce_to(search, $$$('String'), 'to_str'); + if (search.length === 0 && offset > self.length) { + index = -1; + } else { + index = self.indexOf(search, offset); + } } + + return index === -1 ? nil : index; + }, -2); - }, $Number_$minus$5.$$arity = 1); - - Opal.def(self, '$*', $Number_$$6 = function(other) { + $def(self, '$inspect', function $$inspect() { var self = this; - if (other.$$is_number) { - return self * other; - } - else { - return self.$__coerced__("*", other); - } + /* eslint-disable no-misleading-character-class */ + var escapable = /[\\\"\x00-\x1f\u007F-\u009F\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + meta = { + '\u0007': '\\a', + '\u001b': '\\e', + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '\v': '\\v', + '"' : '\\"', + '\\': '\\\\' + }, + escaped = self.replace(escapable, function (chr) { + if (meta[chr]) return meta[chr]; + chr = chr.charCodeAt(0); + if (chr <= 0xff && (self.encoding["$binary?"]() || self.internal_encoding["$binary?"]())) { + return '\\x' + ('00' + chr.toString(16).toUpperCase()).slice(-2); + } else { + return '\\u' + ('0000' + chr.toString(16).toUpperCase()).slice(-4); + } + }); + return '"' + escaped.replace(/\#[\$\@\{]/g, '\\$&') + '"'; + /* eslint-enable no-misleading-character-class */ - }, $Number_$$6.$$arity = 1); + }); - Opal.def(self, '$/', $Number_$slash$7 = function(other) { + $def(self, '$intern', function $$intern() { var self = this; - - if (other.$$is_number) { - return self / other; - } - else { - return self.$__coerced__("/", other); - } - - }, $Number_$slash$7.$$arity = 1); - Opal.alias(self, "fdiv", "/"); + return self.toString(); + }); - Opal.def(self, '$%', $Number_$percent$8 = function(other) { + $def(self, '$length', function $$length() { var self = this; - - if (other.$$is_number) { - if (other == -Infinity) { - return other; - } - else if (other == 0) { - self.$raise($$($nesting, 'ZeroDivisionError'), "divided by 0"); - } - else if (other < 0 || self < 0) { - return (self % other + other) % other; - } - else { - return self % other; - } - } - else { - return self.$__coerced__("%", other); - } + return self.length; + }); + $alias(self, "size", "length"); - }, $Number_$percent$8.$$arity = 1); + $def(self, '$lines', function $$lines($a, $b) { + var block = $$lines.$$p || nil, $post_args, $kwargs, separator, chomp, self = this, e = nil; + if ($gvars["/"] == null) $gvars["/"] = nil; + + $$lines.$$p = null; + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + + if ($post_args.length > 0) separator = $post_args.shift();if (separator == null) separator = $gvars["/"]; + + chomp = $kwargs.$$smap["chomp"];if (chomp == null) chomp = false; + e = $send(self, 'each_line', [separator, $hash2(["chomp"], {"chomp": chomp})], block.$to_proc()); + if ($truthy(block)) { + return self + } else { + return e.$to_a() + } }, -1); - Opal.def(self, '$&', $Number_$$9 = function(other) { + $def(self, '$ljust', function $$ljust(width, padstr) { var self = this; - if (other.$$is_number) { - return self & other; - } - else { - return self.$__coerced__("&", other); + if (padstr == null) padstr = " "; + width = $coerce_to(width, $$$('Integer'), 'to_int'); + padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s(); + if ($truthy(padstr['$empty?']())) { + $Kernel.$raise($$$('ArgumentError'), "zero width padding"); + } if ($truthy(width <= self.length)) { + return self + } + var index = -1, + result = ""; + + width -= self.length; + + while (++index < width) { + result += padstr; } + + return self + result.slice(0, width); + }, -2); - }, $Number_$$9.$$arity = 1); + $def(self, '$lstrip', function $$lstrip() { + var self = this; + + return self.replace(/^[\u0000\s]*/, ''); + }); - Opal.def(self, '$|', $Number_$$10 = function(other) { + $def(self, '$ascii_only?', function $String_ascii_only$ques$14() { var self = this; - if (other.$$is_number) { - return self | other; - } - else { - return self.$__coerced__("|", other); - } + if (!self.encoding.ascii) return false; + return /^[\x00-\x7F]*$/.test(self); - }, $Number_$$10.$$arity = 1); + }); - Opal.def(self, '$^', $Number_$$11 = function(other) { - var self = this; + $def(self, '$match', function $$match(pattern, pos) { + var block = $$match.$$p || nil, self = this; - - if (other.$$is_number) { - return self ^ other; - } - else { - return self.$__coerced__("^", other); - } + $$match.$$p = null; + if (($eqeqeq($$('String'), pattern) || ($truthy(pattern['$respond_to?']("to_str"))))) { + pattern = $$$('Regexp').$new(pattern.$to_str()); + } if (!$eqeqeq($$$('Regexp'), pattern)) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (pattern.$class()) + " (expected Regexp)"); + } return $send(pattern, 'match', [self, pos], block.$to_proc()); + }, -2); - }, $Number_$$11.$$arity = 1); + $def(self, '$match?', function $String_match$ques$15(pattern, pos) { + var self = this; + if (($eqeqeq($$('String'), pattern) || ($truthy(pattern['$respond_to?']("to_str"))))) { + pattern = $$$('Regexp').$new(pattern.$to_str()); + } if (!$eqeqeq($$$('Regexp'), pattern)) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (pattern.$class()) + " (expected Regexp)"); + } return pattern['$match?'](self, pos); + }, -2); - Opal.def(self, '$<', $Number_$lt$12 = function(other) { + $def(self, '$next', function $$next() { var self = this; - if (other.$$is_number) { - return self < other; + var i = self.length; + if (i === 0) { + return ''; } - else { - return self.$__coerced__("<", other); + var result = self; + var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/); + var carry = false; + var code; + while (i--) { + code = self.charCodeAt(i); + if ((code >= 48 && code <= 57) || + (code >= 65 && code <= 90) || + (code >= 97 && code <= 122)) { + switch (code) { + case 57: + carry = true; + code = 48; + break; + case 90: + carry = true; + code = 65; + break; + case 122: + carry = true; + code = 97; + break; + default: + carry = false; + code += 1; + } + } else { + if (first_alphanum_char_index === -1) { + if (code === 255) { + carry = true; + code = 0; + } else { + carry = false; + code += 1; + } + } else { + carry = true; + } + } + result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i + 1); + if (carry && (i === 0 || i === first_alphanum_char_index)) { + switch (code) { + case 65: + break; + case 97: + break; + default: + code += 1; + } + if (i === 0) { + result = String.fromCharCode(code) + result; + } else { + result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i); + } + carry = false; + } + if (!carry) { + break; + } } + return result; - }, $Number_$lt$12.$$arity = 1); + }); - Opal.def(self, '$<=', $Number_$lt_eq$13 = function(other) { + $def(self, '$oct', function $$oct() { var self = this; - if (other.$$is_number) { - return self <= other; - } - else { - return self.$__coerced__("<=", other); + var result, + string = self, + radix = 8; + + if (/^\s*_/.test(string)) { + return 0; } + + string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/i, function (original, head, flag, tail) { + switch (tail.charAt(0)) { + case '+': + case '-': + return original; + case '0': + if (tail.charAt(1) === 'x' && flag === '0x') { + return original; + } + } + switch (flag) { + case '0b': + radix = 2; + break; + case '0': + case '0o': + radix = 8; + break; + case '0d': + radix = 10; + break; + case '0x': + radix = 16; + break; + } + return head + tail; + }); + + result = parseInt(string.replace(/_(?!_)/g, ''), radix); + return isNaN(result) ? 0 : result; - }, $Number_$lt_eq$13.$$arity = 1); + }); - Opal.def(self, '$>', $Number_$gt$14 = function(other) { + $def(self, '$ord', function $$ord() { var self = this; - if (other.$$is_number) { - return self > other; + if (typeof self.codePointAt === "function") { + return self.codePointAt(0); } else { - return self.$__coerced__(">", other); + return self.charCodeAt(0); } - }, $Number_$gt$14.$$arity = 1); + }); - Opal.def(self, '$>=', $Number_$gt_eq$15 = function(other) { + $def(self, '$partition', function $$partition(sep) { var self = this; - if (other.$$is_number) { - return self >= other; - } - else { - return self.$__coerced__(">=", other); - } - - }, $Number_$gt_eq$15.$$arity = 1); - - var spaceship_operator = function(self, other) { - if (other.$$is_number) { - if (isNaN(self) || isNaN(other)) { - return nil; - } + var i, m; - if (self > other) { - return 1; - } else if (self < other) { - return -1; + if (sep.$$is_regexp) { + m = sep.exec(self); + if (m === null) { + i = -1; } else { - return 0; + $$$('MatchData').$new(sep, m); + sep = m[0]; + i = m.index; } + } else { + sep = $coerce_to(sep, $$$('String'), 'to_str'); + i = self.indexOf(sep); } - else { - return self.$__coerced__("<=>", other); + + if (i === -1) { + return [self, '', '']; } - } - ; + + return [ + self.slice(0, i), + self.slice(i, i + sep.length), + self.slice(i + sep.length) + ]; + + }); - Opal.def(self, '$<=>', $Number_$lt_eq_gt$16 = function(other) { + $def(self, '$reverse', function $$reverse() { var self = this; - try { - return spaceship_operator(self, other); - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'ArgumentError')])) { - try { - return nil - } finally { Opal.pop_exception() } - } else { throw $err; } - } - }, $Number_$lt_eq_gt$16.$$arity = 1); + return self.split('').reverse().join(''); + }); - Opal.def(self, '$<<', $Number_$lt$lt$17 = function(count) { + $def(self, '$rindex', function $$rindex(search, offset) { var self = this; + + var i, m, r, _m; + + if (offset === undefined) { + offset = self.length; + } else { + offset = $coerce_to(offset, $$$('Integer'), 'to_int'); + if (offset < 0) { + offset += self.length; + if (offset < 0) { + return nil; + } + } + } + + if (search.$$is_regexp) { + m = null; + r = $global_multiline_regexp(search); + while (true) { + _m = r.exec(self); + if (_m === null || _m.index > offset) { + break; + } + m = _m; + r.lastIndex = m.index + 1; + } + if (m === null) { + ($gvars["~"] = nil); + i = -1; + } else { + $$$('MatchData').$new(r, m); + i = m.index; + } + } else { + search = $coerce_to(search, $$$('String'), 'to_str'); + i = self.lastIndexOf(search, offset); + } - - count = $$($nesting, 'Opal')['$coerce_to!'](count, $$($nesting, 'Integer'), "to_int"); - return count > 0 ? self << count : self >> -count; - }, $Number_$lt$lt$17.$$arity = 1); + return i === -1 ? nil : i; + }, -2); - Opal.def(self, '$>>', $Number_$gt$gt$18 = function(count) { + $def(self, '$rjust', function $$rjust(width, padstr) { var self = this; - count = $$($nesting, 'Opal')['$coerce_to!'](count, $$($nesting, 'Integer'), "to_int"); - return count > 0 ? self >> count : self << -count; - }, $Number_$gt$gt$18.$$arity = 1); - - Opal.def(self, '$[]', $Number_$$$19 = function(bit) { - var self = this; + if (padstr == null) padstr = " "; + width = $coerce_to(width, $$$('Integer'), 'to_int'); + padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s(); + if ($truthy(padstr['$empty?']())) { + $Kernel.$raise($$$('ArgumentError'), "zero width padding"); + } if ($truthy(width <= self.length)) { + return self + } + var chars = Math.floor(width - self.length), + patterns = Math.floor(chars / padstr.length), + result = Array(patterns + 1).join(padstr), + remaining = chars - result.length; - - bit = $$($nesting, 'Opal')['$coerce_to!'](bit, $$($nesting, 'Integer'), "to_int"); - - if (bit < 0) { - return 0; - } - if (bit >= 32) { - return self < 0 ? 1 : 0; - } - return (self >> bit) & 1; - ; - }, $Number_$$$19.$$arity = 1); + return result + padstr.slice(0, remaining) + self; + }, -2); - Opal.def(self, '$+@', $Number_$plus$$20 = function() { + $def(self, '$rpartition', function $$rpartition(sep) { var self = this; - return +self; - }, $Number_$plus$$20.$$arity = 0); - - Opal.def(self, '$-@', $Number_$minus$$21 = function() { - var self = this; + + var i, m, r, _m; - return -self; - }, $Number_$minus$$21.$$arity = 0); - - Opal.def(self, '$~', $Number_$$22 = function() { - var self = this; + if (sep.$$is_regexp) { + m = null; + r = $global_multiline_regexp(sep); - return ~self; - }, $Number_$$22.$$arity = 0); - - Opal.def(self, '$**', $Number_$$$23 = function(other) { - var $a, $b, self = this; + while (true) { + _m = r.exec(self); + if (_m === null) { + break; + } + m = _m; + r.lastIndex = m.index + 1; + } - if ($truthy($$($nesting, 'Integer')['$==='](other))) { - if ($truthy(($truthy($a = $$($nesting, 'Integer')['$==='](self)['$!']()) ? $a : $rb_gt(other, 0)))) { - return Math.pow(self, other); + if (m === null) { + i = -1; } else { - return $$($nesting, 'Rational').$new(self, 1)['$**'](other) + $$$('MatchData').$new(r, m); + sep = m[0]; + i = m.index; } - } else if ($truthy((($a = $rb_lt(self, 0)) ? ($truthy($b = $$($nesting, 'Float')['$==='](other)) ? $b : $$($nesting, 'Rational')['$==='](other)) : $rb_lt(self, 0)))) { - return $$($nesting, 'Complex').$new(self, 0)['$**'](other.$to_f()) - } else if ($truthy(other.$$is_number != null)) { - return Math.pow(self, other); + } else { - return self.$__coerced__("**", other) + sep = $coerce_to(sep, $$$('String'), 'to_str'); + i = self.lastIndexOf(sep); } - }, $Number_$$$23.$$arity = 1); - - Opal.def(self, '$===', $Number_$eq_eq_eq$24 = function(other) { - var self = this; - - if (other.$$is_number) { - return self.valueOf() === other.valueOf(); - } - else if (other['$respond_to?']("==")) { - return other['$=='](self); - } - else { - return false; + if (i === -1) { + return ['', '', self]; } + + return [ + self.slice(0, i), + self.slice(i, i + sep.length), + self.slice(i + sep.length) + ]; - }, $Number_$eq_eq_eq$24.$$arity = 1); + }); - Opal.def(self, '$==', $Number_$eq_eq$25 = function(other) { + $def(self, '$rstrip', function $$rstrip() { var self = this; + return self.replace(/[\s\u0000]*$/, ''); + }); + + $def(self, '$scan', function $$scan(pattern, $kwargs) { + var block = $$scan.$$p || nil, no_matchdata, self = this; + + $$scan.$$p = null; + $kwargs = $ensure_kwargs($kwargs); - if (other.$$is_number) { - return self.valueOf() === other.valueOf(); - } - else if (other['$respond_to?']("==")) { - return other['$=='](self); + no_matchdata = $kwargs.$$smap["no_matchdata"];if (no_matchdata == null) no_matchdata = false; + + var result = [], + match_data = nil, + match; + + if (pattern.$$is_regexp) { + pattern = $global_multiline_regexp(pattern); + } else { + pattern = $coerce_to(pattern, $$$('String'), 'to_str'); + pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); } - else { - return false; + + while ((match = pattern.exec(self)) != null) { + match_data = $$$('MatchData').$new(pattern, match, $hash2(["no_matchdata"], {"no_matchdata": no_matchdata})); + if (block === nil) { + match.length == 1 ? result.push(match[0]) : result.push((match_data).$captures()); + } else { + match.length == 1 ? Opal.yield1(block, match[0]) : Opal.yield1(block, (match_data).$captures()); + } + if (pattern.lastIndex === match.index) { + pattern.lastIndex += 1; + } } - - }, $Number_$eq_eq$25.$$arity = 1); - - Opal.def(self, '$abs', $Number_abs$26 = function $$abs() { - var self = this; - return Math.abs(self); - }, $Number_abs$26.$$arity = 0); - - Opal.def(self, '$abs2', $Number_abs2$27 = function $$abs2() { - var self = this; + if (!no_matchdata) ($gvars["~"] = match_data); - return Math.abs(self * self); - }, $Number_abs2$27.$$arity = 0); + return (block !== nil ? self : result); + }, -2); - Opal.def(self, '$allbits?', $Number_allbits$ques$28 = function(mask) { + $def(self, '$singleton_class', function $$singleton_class() { var self = this; - - mask = $$($nesting, 'Opal')['$coerce_to!'](mask, $$($nesting, 'Integer'), "to_int"); - return (self & mask) == mask;; - }, $Number_allbits$ques$28.$$arity = 1); + return Opal.get_singleton_class(self); + }); - Opal.def(self, '$anybits?', $Number_anybits$ques$29 = function(mask) { - var self = this; - + $def(self, '$split', function $$split(pattern, limit) { + var self = this, $ret_or_1 = nil; + if ($gvars[";"] == null) $gvars[";"] = nil; - mask = $$($nesting, 'Opal')['$coerce_to!'](mask, $$($nesting, 'Integer'), "to_int"); - return (self & mask) !== 0;; - }, $Number_anybits$ques$29.$$arity = 1); - - Opal.def(self, '$angle', $Number_angle$30 = function $$angle() { - var self = this; + if (self.length === 0) { + return []; + } - - if ($truthy(self['$nan?']())) { - return self}; - - if (self == 0) { - if (1 / self > 0) { - return 0; - } - else { - return Math.PI; + if (limit === undefined) { + limit = 0; + } else { + limit = $Opal['$coerce_to!'](limit, $$$('Integer'), "to_int"); + if (limit === 1) { + return [self]; } } - else if (self < 0) { - return Math.PI; - } - else { - return 0; + + if (pattern === undefined || pattern === nil) { + pattern = ($truthy(($ret_or_1 = $gvars[";"])) ? ($ret_or_1) : (" ")); } - ; - }, $Number_angle$30.$$arity = 0); - Opal.alias(self, "arg", "angle"); - Opal.alias(self, "phase", "angle"); - - Opal.def(self, '$bit_length', $Number_bit_length$31 = function $$bit_length() { - var self = this; - - if ($truthy($$($nesting, 'Integer')['$==='](self))) { + var result = [], + string = self.toString(), + index = 0, + match, + i, ii; + + if (pattern.$$is_regexp) { + pattern = $global_multiline_regexp(pattern); } else { - self.$raise($$($nesting, 'NoMethodError').$new("" + "undefined method `bit_length` for " + (self) + ":Float", "bit_length")) - }; - - if (self === 0 || self === -1) { - return 0; + pattern = $coerce_to(pattern, $$$('String'), 'to_str').$to_s(); + if (pattern === ' ') { + pattern = /\s+/gm; + string = string.replace(/^\s+/, ''); + } else { + pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm'); + } } - var result = 0, - value = self < 0 ? ~self : self; + result = string.split(pattern); - while (value != 0) { - result += 1; - value >>>= 1; + if (result.length === 1 && result[0] === string) { + return [result[0]]; } - return result; - ; - }, $Number_bit_length$31.$$arity = 0); - - Opal.def(self, '$ceil', $Number_ceil$32 = function $$ceil(ndigits) { - var self = this; + while ((i = result.indexOf(undefined)) !== -1) { + result.splice(i, 1); + } - - - if (ndigits == null) { - ndigits = 0; - }; - - var f = self.$to_f(); + if (limit === 0) { + while (result[result.length - 1] === '') { + result.length -= 1; + } + return result; + } - if (f % 1 === 0 && ndigits >= 0) { - return f; + match = pattern.exec(string); + + if (limit < 0) { + if (match !== null && match[0] === '' && pattern.source.indexOf('(?=') === -1) { + for (i = 0, ii = match.length; i < ii; i++) { + result.push(''); + } + } + return result; } - var factor = Math.pow(10, ndigits), - result = Math.ceil(f * factor) / factor; + if (match !== null && match[0] === '') { + result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join('')); + return result; + } - if (f % 1 === 0) { - result = Math.round(result); + if (limit >= result.length) { + return result; } + i = 0; + while (match !== null) { + i++; + index = pattern.lastIndex; + if (i + 1 === limit) { + break; + } + match = pattern.exec(string); + } + result.splice(limit - 1, result.length - 1, string.slice(index)); return result; - ; - }, $Number_ceil$32.$$arity = -1); + }, -1); - Opal.def(self, '$chr', $Number_chr$33 = function $$chr(encoding) { - var self = this; + $def(self, '$squeeze', function $$squeeze($a) { + var $post_args, sets, self = this; - ; - return String.fromCharCode(self);; - }, $Number_chr$33.$$arity = -1); - - Opal.def(self, '$denominator', $Number_denominator$34 = function $$denominator() { - var $a, $iter = $Number_denominator$34.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - - if ($iter) $Number_denominator$34.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; + $post_args = $slice(arguments); + sets = $post_args; + + if (sets.length === 0) { + return self.replace(/(.)\1+/g, '$1'); } - if ($truthy(($truthy($a = self['$nan?']()) ? $a : self['$infinite?']()))) { - return 1 - } else { - return $send(self, Opal.find_super_dispatcher(self, 'denominator', $Number_denominator$34, false), $zuper, $iter) + var char_class = char_class_from_char_sets(sets); + if (char_class === null) { + return self; } - }, $Number_denominator$34.$$arity = 0); + return self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1'); + }, -1); - Opal.def(self, '$downto', $Number_downto$35 = function $$downto(stop) { - var $iter = $Number_downto$35.$$p, block = $iter || nil, $$36, self = this; + $def(self, '$start_with?', function $String_start_with$ques$16($a) { + var $post_args, prefixes, self = this; - if ($iter) $Number_downto$35.$$p = null; + $post_args = $slice(arguments); + prefixes = $post_args; - if ($iter) $Number_downto$35.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["downto", stop], ($$36 = function(){var self = $$36.$$s || this; + for (var i = 0, length = prefixes.length; i < length; i++) { + if (prefixes[i].$$is_regexp) { + var regexp = prefixes[i]; + var match = regexp.exec(self); - - if ($truthy($$($nesting, 'Numeric')['$==='](stop))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed") - }; - if ($truthy($rb_gt(stop, self))) { - return 0 + if (match != null && match.index === 0) { + ($gvars["~"] = $$$('MatchData').$new(regexp, match)); + return true; } else { - return $rb_plus($rb_minus(self, stop), 1) - };}, $$36.$$s = self, $$36.$$arity = 0, $$36)) - }; - - if (!stop.$$is_number) { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed") - } - for (var i = self; i >= stop; i--) { - block(i); + ($gvars["~"] = nil); + } + } else { + var prefix = $coerce_to(prefixes[i], $$$('String'), 'to_str').$to_s(); + + if (self.indexOf(prefix) === 0) { + return true; + } + } } - ; - return self; - }, $Number_downto$35.$$arity = 1); - Opal.alias(self, "eql?", "=="); - - Opal.def(self, '$equal?', $Number_equal$ques$37 = function(other) { - var $a, self = this; - return ($truthy($a = self['$=='](other)) ? $a : isNaN(self) && isNaN(other)) - }, $Number_equal$ques$37.$$arity = 1); + return false; + }, -1); - Opal.def(self, '$even?', $Number_even$ques$38 = function() { + $def(self, '$strip', function $$strip() { var self = this; - return self % 2 === 0; - }, $Number_even$ques$38.$$arity = 0); + return self.replace(/^[\s\u0000]*|[\s\u0000]*$/g, ''); + }); - Opal.def(self, '$floor', $Number_floor$39 = function $$floor(ndigits) { - var self = this; + $def(self, '$sub', function $$sub(pattern, replacement) { + var block = $$sub.$$p || nil, self = this; + $$sub.$$p = null; - - if (ndigits == null) { - ndigits = 0; - }; - - var f = self.$to_f(); - - if (f % 1 === 0 && ndigits >= 0) { - return f; + if (!pattern.$$is_regexp) { + pattern = $coerce_to(pattern, $$$('String'), 'to_str'); + pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')); } - var factor = Math.pow(10, ndigits), - result = Math.floor(f * factor) / factor; + var result, match = pattern.exec(self); - if (f % 1 === 0) { - result = Math.round(result); + if (match === null) { + ($gvars["~"] = nil); + result = self.toString(); + } else { + $$$('MatchData').$new(pattern, match); + + if (replacement === undefined) { + + if (block === nil) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (1 for 2)"); + } + result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length); + + } else if (replacement.$$is_hash) { + + result = self.slice(0, match.index) + (replacement)['$[]'](match[0]).$to_s() + self.slice(match.index + match[0].length); + + } else { + + replacement = $coerce_to(replacement, $$$('String'), 'to_str'); + + replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) { + if (slashes.length % 2 === 0) { + return original; + } + switch (command) { + case "+": + for (var i = match.length - 1; i > 0; i--) { + if (match[i] !== undefined) { + return slashes.slice(1) + match[i]; + } + } + return ''; + case "&": return slashes.slice(1) + match[0]; + case "`": return slashes.slice(1) + self.slice(0, match.index); + case "'": return slashes.slice(1) + self.slice(match.index + match[0].length); + default: return slashes.slice(1) + (match[command] || ''); + } + }).replace(/\\\\/g, '\\'); + + result = self.slice(0, match.index) + replacement + self.slice(match.index + match[0].length); + } } return result; - ; - }, $Number_floor$39.$$arity = -1); + }, -2); - Opal.def(self, '$gcd', $Number_gcd$40 = function $$gcd(other) { + $def(self, '$sum', function $$sum(n) { var self = this; - if ($truthy($$($nesting, 'Integer')['$==='](other))) { - } else { - self.$raise($$($nesting, 'TypeError'), "not an integer") - }; + if (n == null) n = 16; - var min = Math.abs(self), - max = Math.abs(other); + n = $coerce_to(n, $$$('Integer'), 'to_int'); - while (min > 0) { - var tmp = min; + var result = 0, + length = self.length, + i = 0; - min = max % min; - max = tmp; + for (; i < length; i++) { + result += self.charCodeAt(i); } - return max; - ; - }, $Number_gcd$40.$$arity = 1); - - Opal.def(self, '$gcdlcm', $Number_gcdlcm$41 = function $$gcdlcm(other) { - var self = this; + if (n <= 0) { + return result; + } - return [self.$gcd(), self.$lcm()] - }, $Number_gcdlcm$41.$$arity = 1); + return result & (Math.pow(2, n) - 1); + }, -1); - Opal.def(self, '$integer?', $Number_integer$ques$42 = function() { + $def(self, '$swapcase', function $$swapcase() { var self = this; - return self % 1 === 0; - }, $Number_integer$ques$42.$$arity = 0); - - Opal.def(self, '$is_a?', $Number_is_a$ques$43 = function(klass) { - var $a, $iter = $Number_is_a$ques$43.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - - if ($iter) $Number_is_a$ques$43.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - if ($truthy((($a = klass['$==']($$($nesting, 'Integer'))) ? $$($nesting, 'Integer')['$==='](self) : klass['$==']($$($nesting, 'Integer'))))) { - return true}; - if ($truthy((($a = klass['$==']($$($nesting, 'Integer'))) ? $$($nesting, 'Integer')['$==='](self) : klass['$==']($$($nesting, 'Integer'))))) { - return true}; - if ($truthy((($a = klass['$==']($$($nesting, 'Float'))) ? $$($nesting, 'Float')['$==='](self) : klass['$==']($$($nesting, 'Float'))))) { - return true}; - return $send(self, Opal.find_super_dispatcher(self, 'is_a?', $Number_is_a$ques$43, false), $zuper, $iter); - }, $Number_is_a$ques$43.$$arity = 1); - Opal.alias(self, "kind_of?", "is_a?"); - - Opal.def(self, '$instance_of?', $Number_instance_of$ques$44 = function(klass) { - var $a, $iter = $Number_instance_of$ques$44.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + var str = self.replace(/([a-z]+)|([A-Z]+)/g, function($0,$1,$2) { + return $1 ? $0.toUpperCase() : $0.toLowerCase(); + }); - if ($iter) $Number_instance_of$ques$44.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - if ($truthy((($a = klass['$==']($$($nesting, 'Integer'))) ? $$($nesting, 'Integer')['$==='](self) : klass['$==']($$($nesting, 'Integer'))))) { - return true}; - if ($truthy((($a = klass['$==']($$($nesting, 'Integer'))) ? $$($nesting, 'Integer')['$==='](self) : klass['$==']($$($nesting, 'Integer'))))) { - return true}; - if ($truthy((($a = klass['$==']($$($nesting, 'Float'))) ? $$($nesting, 'Float')['$==='](self) : klass['$==']($$($nesting, 'Float'))))) { - return true}; - return $send(self, Opal.find_super_dispatcher(self, 'instance_of?', $Number_instance_of$ques$44, false), $zuper, $iter); - }, $Number_instance_of$ques$44.$$arity = 1); + return str; + + }); - Opal.def(self, '$lcm', $Number_lcm$45 = function $$lcm(other) { + $def(self, '$to_f', function $$to_f() { var self = this; - if ($truthy($$($nesting, 'Integer')['$==='](other))) { - } else { - self.$raise($$($nesting, 'TypeError'), "not an integer") - }; - - if (self == 0 || other == 0) { + if (self.charAt(0) === '_') { + return 0; + } + + var result = parseFloat(self.replace(/_/g, '')); + + if (isNaN(result) || result == Infinity || result == -Infinity) { return 0; } else { - return Math.abs(self * other / self.$gcd(other)); + return result; } - ; - }, $Number_lcm$45.$$arity = 1); - Opal.alias(self, "magnitude", "abs"); - Opal.alias(self, "modulo", "%"); - Opal.def(self, '$next', $Number_next$46 = function $$next() { - var self = this; - - return self + 1; - }, $Number_next$46.$$arity = 0); + }); - Opal.def(self, '$nobits?', $Number_nobits$ques$47 = function(mask) { + $def(self, '$to_i', function $$to_i(base) { var self = this; - mask = $$($nesting, 'Opal')['$coerce_to!'](mask, $$($nesting, 'Integer'), "to_int"); - return (self & mask) == 0;; - }, $Number_nobits$ques$47.$$arity = 1); - - Opal.def(self, '$nonzero?', $Number_nonzero$ques$48 = function() { - var self = this; - - return self == 0 ? nil : self; - }, $Number_nonzero$ques$48.$$arity = 0); - - Opal.def(self, '$numerator', $Number_numerator$49 = function $$numerator() { - var $a, $iter = $Number_numerator$49.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + if (base == null) base = 10; + + var result, + string = self.toLowerCase(), + radix = $coerce_to(base, $$$('Integer'), 'to_int'); - if ($iter) $Number_numerator$49.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; + if (radix === 1 || radix < 0 || radix > 36) { + $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (radix)); } - if ($truthy(($truthy($a = self['$nan?']()) ? $a : self['$infinite?']()))) { - return self - } else { - return $send(self, Opal.find_super_dispatcher(self, 'numerator', $Number_numerator$49, false), $zuper, $iter) + + if (/^\s*_/.test(string)) { + return 0; } - }, $Number_numerator$49.$$arity = 0); + + string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/, function (original, head, flag, tail) { + switch (tail.charAt(0)) { + case '+': + case '-': + return original; + case '0': + if (tail.charAt(1) === 'x' && flag === '0x' && (radix === 0 || radix === 16)) { + return original; + } + } + switch (flag) { + case '0b': + if (radix === 0 || radix === 2) { + radix = 2; + return head + tail; + } + break; + case '0': + case '0o': + if (radix === 0 || radix === 8) { + radix = 8; + return head + tail; + } + break; + case '0d': + if (radix === 0 || radix === 10) { + radix = 10; + return head + tail; + } + break; + case '0x': + if (radix === 0 || radix === 16) { + radix = 16; + return head + tail; + } + break; + } + return original + }); + + result = parseInt(string.replace(/_(?!_)/g, ''), radix); + return isNaN(result) ? 0 : result; + }, -1); - Opal.def(self, '$odd?', $Number_odd$ques$50 = function() { - var self = this; + $def(self, '$to_proc', function $$to_proc() { + var self = this, method_name = nil, jsid = nil, proc = nil; - return self % 2 !== 0; - }, $Number_odd$ques$50.$$arity = 0); + $$to_proc.$$p = null; + + method_name = self.valueOf(); + jsid = Opal.jsid(method_name); + proc = $send($Kernel, 'proc', [], function $$17($a){var block = $$17.$$p || nil, $post_args, args; + + $$17.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + if (args.length === 0) { + $Kernel.$raise($$$('ArgumentError'), "no receiver given"); + } + + var recv = args[0]; + + if (recv == null) recv = nil; + + var body = recv[jsid]; + + if (!body) { + body = recv.$method_missing; + args[0] = method_name; + } else { + args = args.slice(1); + } + + if (typeof block === 'function') { + body.$$p = block; + } + + if (args.length === 0) { + return body.call(recv); + } else { + return body.apply(recv, args); + } +}, -1); + proc.$$source_location = nil; + return proc; + }); - Opal.def(self, '$ord', $Number_ord$51 = function $$ord() { + $def(self, '$to_s', function $$to_s() { var self = this; - return self - }, $Number_ord$51.$$arity = 0); + return self.toString(); + }); - Opal.def(self, '$pow', $Number_pow$52 = function $$pow(b, m) { + $def(self, '$tr', function $$tr(from, to) { var self = this; - ; - - if (self == 0) { - self.$raise($$($nesting, 'ZeroDivisionError'), "divided by 0") + from = $coerce_to(from, $$$('String'), 'to_str').$to_s(); + to = $coerce_to(to, $$$('String'), 'to_str').$to_s(); + + if (from.length == 0 || from === to) { + return self; + } + + var i, in_range, c, ch, start, end, length; + var subs = {}; + var from_chars = from.split(''); + var from_length = from_chars.length; + var to_chars = to.split(''); + var to_length = to_chars.length; + + var inverse = false; + var global_sub = null; + if (from_chars[0] === '^' && from_chars.length > 1) { + inverse = true; + from_chars.shift(); + global_sub = to_chars[to_length - 1]; + from_length -= 1; + } + + var from_chars_expanded = []; + var last_from = null; + in_range = false; + for (i = 0; i < from_length; i++) { + ch = from_chars[i]; + if (last_from == null) { + last_from = ch; + from_chars_expanded.push(ch); + } + else if (ch === '-') { + if (last_from === '-') { + from_chars_expanded.push('-'); + from_chars_expanded.push('-'); + } + else if (i == from_length - 1) { + from_chars_expanded.push('-'); + } + else { + in_range = true; + } + } + else if (in_range) { + start = last_from.charCodeAt(0); + end = ch.charCodeAt(0); + if (start > end) { + $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration"); + } + for (c = start + 1; c < end; c++) { + from_chars_expanded.push(String.fromCharCode(c)); + } + from_chars_expanded.push(ch); + in_range = null; + last_from = null; + } + else { + from_chars_expanded.push(ch); + } } - if (m === undefined) { - return self['$**'](b); - } else { - if (!($$($nesting, 'Integer')['$==='](b))) { - self.$raise($$($nesting, 'TypeError'), "Integer#pow() 2nd argument not allowed unless a 1st argument is integer") - } + from_chars = from_chars_expanded; + from_length = from_chars.length; - if (b < 0) { - self.$raise($$($nesting, 'TypeError'), "Integer#pow() 1st argument cannot be negative when 2nd argument specified") + if (inverse) { + for (i = 0; i < from_length; i++) { + subs[from_chars[i]] = true; } + } + else { + if (to_length > 0) { + var to_chars_expanded = []; + var last_to = null; + in_range = false; + for (i = 0; i < to_length; i++) { + ch = to_chars[i]; + if (last_to == null) { + last_to = ch; + to_chars_expanded.push(ch); + } + else if (ch === '-') { + if (last_to === '-') { + to_chars_expanded.push('-'); + to_chars_expanded.push('-'); + } + else if (i == to_length - 1) { + to_chars_expanded.push('-'); + } + else { + in_range = true; + } + } + else if (in_range) { + start = last_to.charCodeAt(0); + end = ch.charCodeAt(0); + if (start > end) { + $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration"); + } + for (c = start + 1; c < end; c++) { + to_chars_expanded.push(String.fromCharCode(c)); + } + to_chars_expanded.push(ch); + in_range = null; + last_to = null; + } + else { + to_chars_expanded.push(ch); + } + } - if (!($$($nesting, 'Integer')['$==='](m))) { - self.$raise($$($nesting, 'TypeError'), "Integer#pow() 2nd argument not allowed unless all arguments are integers") + to_chars = to_chars_expanded; + to_length = to_chars.length; } - if (m === 0) { - self.$raise($$($nesting, 'ZeroDivisionError'), "divided by 0") + var length_diff = from_length - to_length; + if (length_diff > 0) { + var pad_char = (to_length > 0 ? to_chars[to_length - 1] : ''); + for (i = 0; i < length_diff; i++) { + to_chars.push(pad_char); + } } - return self['$**'](b)['$%'](m) + for (i = 0; i < from_length; i++) { + subs[from_chars[i]] = to_chars[i]; + } } - ; - }, $Number_pow$52.$$arity = -2); - - Opal.def(self, '$pred', $Number_pred$53 = function $$pred() { - var self = this; - - return self - 1; - }, $Number_pred$53.$$arity = 0); - - Opal.def(self, '$quo', $Number_quo$54 = function $$quo(other) { - var $iter = $Number_quo$54.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - if ($iter) $Number_quo$54.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - if ($truthy($$($nesting, 'Integer')['$==='](self))) { - return $send(self, Opal.find_super_dispatcher(self, 'quo', $Number_quo$54, false), $zuper, $iter) - } else { - return $rb_divide(self, other) + var new_str = ''; + for (i = 0, length = self.length; i < length; i++) { + ch = self.charAt(i); + var sub = subs[ch]; + if (inverse) { + new_str += (sub == null ? global_sub : ch); + } + else { + new_str += (sub != null ? sub : ch); + } } - }, $Number_quo$54.$$arity = 1); + return new_str; - Opal.def(self, '$rationalize', $Number_rationalize$55 = function $$rationalize(eps) { - var $a, $b, self = this, f = nil, n = nil; - - - ; - - if (arguments.length > 1) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arguments.length) + " for 0..1)"); - } - ; - if ($truthy($$($nesting, 'Integer')['$==='](self))) { - return $$($nesting, 'Rational').$new(self, 1) - } else if ($truthy(self['$infinite?']())) { - return self.$raise($$($nesting, 'FloatDomainError'), "Infinity") - } else if ($truthy(self['$nan?']())) { - return self.$raise($$($nesting, 'FloatDomainError'), "NaN") - } else if ($truthy(eps == null)) { - - $b = $$($nesting, 'Math').$frexp(self), $a = Opal.to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (n = ($a[1] == null ? nil : $a[1])), $b; - f = $$($nesting, 'Math').$ldexp(f, $$$($$($nesting, 'Float'), 'MANT_DIG')).$to_i(); - n = $rb_minus(n, $$$($$($nesting, 'Float'), 'MANT_DIG')); - return $$($nesting, 'Rational').$new($rb_times(2, f), (1)['$<<']($rb_minus(1, n))).$rationalize($$($nesting, 'Rational').$new(1, (1)['$<<']($rb_minus(1, n)))); - } else { - return self.$to_r().$rationalize(eps) - }; - }, $Number_rationalize$55.$$arity = -1); + }); - Opal.def(self, '$remainder', $Number_remainder$56 = function $$remainder(y) { + $def(self, '$tr_s', function $$tr_s(from, to) { var self = this; - return $rb_minus(self, $rb_times(y, $rb_divide(self, y).$truncate())) - }, $Number_remainder$56.$$arity = 1); - - Opal.def(self, '$round', $Number_round$57 = function $$round(ndigits) { - var $a, $b, self = this, _ = nil, exp = nil; - - ; - if ($truthy($$($nesting, 'Integer')['$==='](self))) { - - if ($truthy(ndigits == null)) { - return self}; - if ($truthy(($truthy($a = $$($nesting, 'Float')['$==='](ndigits)) ? ndigits['$infinite?']() : $a))) { - self.$raise($$($nesting, 'RangeError'), "Infinity")}; - ndigits = $$($nesting, 'Opal')['$coerce_to!'](ndigits, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_lt(ndigits, $$$($$($nesting, 'Integer'), 'MIN')))) { - self.$raise($$($nesting, 'RangeError'), "out of bounds")}; - if ($truthy(ndigits >= 0)) { - return self}; - ndigits = ndigits['$-@'](); - - if (0.415241 * ndigits - 0.125 > self.$size()) { - return 0; - } - - var f = Math.pow(10, ndigits), - x = Math.floor((Math.abs(x) + f / 2) / f) * f; - - return self < 0 ? -x : x; - ; - } else { - - if ($truthy(($truthy($a = self['$nan?']()) ? ndigits == null : $a))) { - self.$raise($$($nesting, 'FloatDomainError'), "NaN")}; - ndigits = $$($nesting, 'Opal')['$coerce_to!'](ndigits || 0, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_le(ndigits, 0))) { - if ($truthy(self['$nan?']())) { - self.$raise($$($nesting, 'RangeError'), "NaN") - } else if ($truthy(self['$infinite?']())) { - self.$raise($$($nesting, 'FloatDomainError'), "Infinity")} - } else if (ndigits['$=='](0)) { - return Math.round(self) - } else if ($truthy(($truthy($a = self['$nan?']()) ? $a : self['$infinite?']()))) { - return self}; - $b = $$($nesting, 'Math').$frexp(self), $a = Opal.to_ary($b), (_ = ($a[0] == null ? nil : $a[0])), (exp = ($a[1] == null ? nil : $a[1])), $b; - if ($truthy($rb_ge(ndigits, $rb_minus($rb_plus($$$($$($nesting, 'Float'), 'DIG'), 2), (function() {if ($truthy($rb_gt(exp, 0))) { - return $rb_divide(exp, 4) - } else { - return $rb_minus($rb_divide(exp, 3), 1) - }; return nil; })())))) { - return self}; - if ($truthy($rb_lt(ndigits, (function() {if ($truthy($rb_gt(exp, 0))) { - return $rb_plus($rb_divide(exp, 3), 1) - } else { - return $rb_divide(exp, 4) - }; return nil; })()['$-@']()))) { - return 0}; - return Math.round(self * Math.pow(10, ndigits)) / Math.pow(10, ndigits);; - }; - }, $Number_round$57.$$arity = -1); - - Opal.def(self, '$step', $Number_step$58 = function $$step($a, $b, $c) { - var $iter = $Number_step$58.$$p, block = $iter || nil, $post_args, $kwargs, limit, step, to, by, $$59, self = this, positional_args = nil, keyword_args = nil; + from = $coerce_to(from, $$$('String'), 'to_str').$to_s(); + to = $coerce_to(to, $$$('String'), 'to_str').$to_s(); - if ($iter) $Number_step$58.$$p = null; - - - if ($iter) $Number_step$58.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - $kwargs = Opal.extract_kwargs($post_args); - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - if ($post_args.length > 0) { - limit = $post_args[0]; - $post_args.splice(0, 1); - }; - - if ($post_args.length > 0) { - step = $post_args[0]; - $post_args.splice(0, 1); - }; - - to = $kwargs.$$smap["to"];; - - by = $kwargs.$$smap["by"];; - - if (limit !== undefined && to !== undefined) { - self.$raise($$($nesting, 'ArgumentError'), "to is given twice") + if (from.length == 0) { + return self; } - if (step !== undefined && by !== undefined) { - self.$raise($$($nesting, 'ArgumentError'), "step is given twice") + var i, in_range, c, ch, start, end, length; + var subs = {}; + var from_chars = from.split(''); + var from_length = from_chars.length; + var to_chars = to.split(''); + var to_length = to_chars.length; + + var inverse = false; + var global_sub = null; + if (from_chars[0] === '^' && from_chars.length > 1) { + inverse = true; + from_chars.shift(); + global_sub = to_chars[to_length - 1]; + from_length -= 1; } - function validateParameters() { - if (to !== undefined) { - limit = to; + var from_chars_expanded = []; + var last_from = null; + in_range = false; + for (i = 0; i < from_length; i++) { + ch = from_chars[i]; + if (last_from == null) { + last_from = ch; + from_chars_expanded.push(ch); } - - if (limit === undefined) { - limit = nil; + else if (ch === '-') { + if (last_from === '-') { + from_chars_expanded.push('-'); + from_chars_expanded.push('-'); + } + else if (i == from_length - 1) { + from_chars_expanded.push('-'); + } + else { + in_range = true; + } } - - if (step === nil) { - self.$raise($$($nesting, 'TypeError'), "step must be numeric") + else if (in_range) { + start = last_from.charCodeAt(0); + end = ch.charCodeAt(0); + if (start > end) { + $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration"); + } + for (c = start + 1; c < end; c++) { + from_chars_expanded.push(String.fromCharCode(c)); + } + from_chars_expanded.push(ch); + in_range = null; + last_from = null; } - - if (step === 0) { - self.$raise($$($nesting, 'ArgumentError'), "step can't be 0") + else { + from_chars_expanded.push(ch); } + } - if (by !== undefined) { - step = by; - } + from_chars = from_chars_expanded; + from_length = from_chars.length; - if (step === nil || step == null) { - step = 1; + if (inverse) { + for (i = 0; i < from_length; i++) { + subs[from_chars[i]] = true; } + } + else { + if (to_length > 0) { + var to_chars_expanded = []; + var last_to = null; + in_range = false; + for (i = 0; i < to_length; i++) { + ch = to_chars[i]; + if (last_from == null) { + last_from = ch; + to_chars_expanded.push(ch); + } + else if (ch === '-') { + if (last_to === '-') { + to_chars_expanded.push('-'); + to_chars_expanded.push('-'); + } + else if (i == to_length - 1) { + to_chars_expanded.push('-'); + } + else { + in_range = true; + } + } + else if (in_range) { + start = last_from.charCodeAt(0); + end = ch.charCodeAt(0); + if (start > end) { + $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration"); + } + for (c = start + 1; c < end; c++) { + to_chars_expanded.push(String.fromCharCode(c)); + } + to_chars_expanded.push(ch); + in_range = null; + last_from = null; + } + else { + to_chars_expanded.push(ch); + } + } - var sign = step['$<=>'](0); - - if (sign === nil) { - self.$raise($$($nesting, 'ArgumentError'), "" + "0 can't be coerced into " + (step.$class())) + to_chars = to_chars_expanded; + to_length = to_chars.length; } - if (limit === nil || limit == null) { - limit = sign > 0 ? $$$($$($nesting, 'Float'), 'INFINITY') : $$$($$($nesting, 'Float'), 'INFINITY')['$-@'](); + var length_diff = from_length - to_length; + if (length_diff > 0) { + var pad_char = (to_length > 0 ? to_chars[to_length - 1] : ''); + for (i = 0; i < length_diff; i++) { + to_chars.push(pad_char); + } } - $$($nesting, 'Opal').$compare(self, limit) + for (i = 0; i < from_length; i++) { + subs[from_chars[i]] = to_chars[i]; + } } - - function stepFloatSize() { - if ((step > 0 && self > limit) || (step < 0 && self < limit)) { - return 0; - } else if (step === Infinity || step === -Infinity) { - return 1; - } else { - var abs = Math.abs, floor = Math.floor, - err = (abs(self) + abs(limit) + abs(limit - self)) / abs(step) * $$$($$($nesting, 'Float'), 'EPSILON'); - - if (err === Infinity || err === -Infinity) { - return 0; - } else { - if (err > 0.5) { - err = 0.5; + var new_str = ''; + var last_substitute = null; + for (i = 0, length = self.length; i < length; i++) { + ch = self.charAt(i); + var sub = subs[ch]; + if (inverse) { + if (sub == null) { + if (last_substitute == null) { + new_str += global_sub; + last_substitute = true; + } + } + else { + new_str += ch; + last_substitute = null; + } + } + else { + if (sub != null) { + if (last_substitute == null || last_substitute !== sub) { + new_str += sub; + last_substitute = sub; } - - return floor((limit - self) / step + err) + 1 + } + else { + new_str += ch; + last_substitute = null; } } } + return new_str; + + }); + + $def(self, '$upcase', function $$upcase() { + var self = this; - function stepSize() { - validateParameters(); + return self.toUpperCase(); + }); + + $def(self, '$upto', function $$upto(stop, excl) { + var block = $$upto.$$p || nil, self = this; - if (step === 0) { - return Infinity; - } + $$upto.$$p = null; + if (excl == null) excl = false; + if (!(block !== nil)) { + return self.$enum_for("upto", stop, excl) + } + var a, b, s = self.toString(); - if (step % 1 !== 0) { - return stepFloatSize(); - } else if ((step > 0 && self > limit) || (step < 0 && self < limit)) { - return 0; - } else { - var ceil = Math.ceil, abs = Math.abs, - lhs = abs(self - limit) + 1, - rhs = abs(step); + stop = $coerce_to(stop, $$$('String'), 'to_str'); - return ceil(lhs / rhs); - } - } - ; - if ((block !== nil)) { - } else { - - positional_args = []; - keyword_args = $hash2([], {}); - - if (limit !== undefined) { - positional_args.push(limit); - } + if (s.length === 1 && stop.length === 1) { - if (step !== undefined) { - positional_args.push(step); - } + a = s.charCodeAt(0); + b = stop.charCodeAt(0); - if (to !== undefined) { - Opal.hash_put(keyword_args, "to", to); - } + while (a <= b) { + if (excl && a === b) { + break; + } - if (by !== undefined) { - Opal.hash_put(keyword_args, "by", by); - } + block(String.fromCharCode(a)); - if (keyword_args['$any?']()) { - positional_args.push(keyword_args); + a += 1; } - ; - return $send(self, 'enum_for', ["step"].concat(Opal.to_a(positional_args)), ($$59 = function(){var self = $$59.$$s || this; - return stepSize();}, $$59.$$s = self, $$59.$$arity = 0, $$59)); - }; - - validateParameters(); + } else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) { - if (step === 0) { - while (true) { - block(self); - } - } + a = parseInt(s, 10); + b = parseInt(stop, 10); - if (self % 1 !== 0 || limit % 1 !== 0 || step % 1 !== 0) { - var n = stepFloatSize(); + while (a <= b) { + if (excl && a === b) { + break; + } - if (n > 0) { - if (step === Infinity || step === -Infinity) { - block(self); - } else { - var i = 0, d; + block(a.toString()); - if (step > 0) { - while (i < n) { - d = i * step + self; - if (limit < d) { - d = limit; - } - block(d); - i += 1; - } - } else { - while (i < n) { - d = i * step + self; - if (limit > d) { - d = limit; - } - block(d); - i += 1 - } - } - } + a += 1; } + } else { - var value = self; - if (step > 0) { - while (value <= limit) { - block(value); - value += step; - } - } else { - while (value >= limit) { - block(value); - value += step + while (s.length <= stop.length && s <= stop) { + if (excl && s === stop) { + break; } - } - } - return self; - ; - }, $Number_step$58.$$arity = -1); - Opal.alias(self, "succ", "next"); - - Opal.def(self, '$times', $Number_times$60 = function $$times() { - var $iter = $Number_times$60.$$p, block = $iter || nil, $$61, self = this; + block(s); - if ($iter) $Number_times$60.$$p = null; - - - if ($iter) $Number_times$60.$$p = null;; - if ($truthy(block)) { - } else { - return $send(self, 'enum_for', ["times"], ($$61 = function(){var self = $$61.$$s || this; + s = (s).$succ(); + } - return self}, $$61.$$s = self, $$61.$$arity = 0, $$61)) - }; - - for (var i = 0; i < self; i++) { - block(i); } - ; return self; - }, $Number_times$60.$$arity = 0); - - Opal.def(self, '$to_f', $Number_to_f$62 = function $$to_f() { - var self = this; - - return self - }, $Number_to_f$62.$$arity = 0); + }, -2); - Opal.def(self, '$to_i', $Number_to_i$63 = function $$to_i() { - var self = this; - - return parseInt(self, 10); - }, $Number_to_i$63.$$arity = 0); - Opal.alias(self, "to_int", "to_i"); - - Opal.def(self, '$to_r', $Number_to_r$64 = function $$to_r() { - var $a, $b, self = this, f = nil, e = nil; - - if ($truthy($$($nesting, 'Integer')['$==='](self))) { - return $$($nesting, 'Rational').$new(self, 1) - } else { - - $b = $$($nesting, 'Math').$frexp(self), $a = Opal.to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (e = ($a[1] == null ? nil : $a[1])), $b; - f = $$($nesting, 'Math').$ldexp(f, $$$($$($nesting, 'Float'), 'MANT_DIG')).$to_i(); - e = $rb_minus(e, $$$($$($nesting, 'Float'), 'MANT_DIG')); - return $rb_times(f, $$$($$($nesting, 'Float'), 'RADIX')['$**'](e)).$to_r(); - } - }, $Number_to_r$64.$$arity = 0); - - Opal.def(self, '$to_s', $Number_to_s$65 = function $$to_s(base) { - var $a, self = this; - - - - if (base == null) { - base = 10; - }; - base = $$($nesting, 'Opal')['$coerce_to!'](base, $$($nesting, 'Integer'), "to_int"); - if ($truthy(($truthy($a = $rb_lt(base, 2)) ? $a : $rb_gt(base, 36)))) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid radix " + (base))}; - return self.toString(base);; - }, $Number_to_s$65.$$arity = -1); - - Opal.def(self, '$truncate', $Number_truncate$66 = function $$truncate(ndigits) { - var self = this; - - - - if (ndigits == null) { - ndigits = 0; - }; - - var f = self.$to_f(); - - if (f % 1 === 0 && ndigits >= 0) { - return f; + function char_class_from_char_sets(sets) { + function explode_sequences_in_character_set(set) { + var result = '', + i, len = set.length, + curr_char, + skip_next_dash, + char_code_from, + char_code_upto, + char_code; + for (i = 0; i < len; i++) { + curr_char = set.charAt(i); + if (curr_char === '-' && i > 0 && i < (len - 1) && !skip_next_dash) { + char_code_from = set.charCodeAt(i - 1); + char_code_upto = set.charCodeAt(i + 1); + if (char_code_from > char_code_upto) { + $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (char_code_from) + "-" + (char_code_upto) + "\" in string transliteration"); + } + for (char_code = char_code_from + 1; char_code < char_code_upto + 1; char_code++) { + result += String.fromCharCode(char_code); + } + skip_next_dash = true; + i++; + } else { + skip_next_dash = (curr_char === '\\'); + result += curr_char; + } + } + return result; } - var factor = Math.pow(10, ndigits), - result = parseInt(f * factor, 10) / factor; - - if (f % 1 === 0) { - result = Math.round(result); + function intersection(setA, setB) { + if (setA.length === 0) { + return setB; + } + var result = '', + i, len = setA.length, + chr; + for (i = 0; i < len; i++) { + chr = setA.charAt(i); + if (setB.indexOf(chr) !== -1) { + result += chr; + } + } + return result; } - return result; - ; - }, $Number_truncate$66.$$arity = -1); - Opal.alias(self, "inspect", "to_s"); - - Opal.def(self, '$digits', $Number_digits$67 = function $$digits(base) { - var self = this; - - - - if (base == null) { - base = 10; - }; - if ($rb_lt(self, 0)) { - self.$raise($$$($$($nesting, 'Math'), 'DomainError'), "out of domain")}; - base = $$($nesting, 'Opal')['$coerce_to!'](base, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_lt(base, 2))) { - self.$raise($$($nesting, 'ArgumentError'), "" + "invalid radix " + (base))}; - - var value = self, result = []; + var i, len, set, neg, chr, tmp, + pos_intersection = '', + neg_intersection = ''; - while (value !== 0) { - result.push(value % base); - value = parseInt(value / base, 10); + for (i = 0, len = sets.length; i < len; i++) { + set = $coerce_to(sets[i], $$$('String'), 'to_str'); + neg = (set.charAt(0) === '^' && set.length > 1); + set = explode_sequences_in_character_set(neg ? set.slice(1) : set); + if (neg) { + neg_intersection = intersection(neg_intersection, set); + } else { + pos_intersection = intersection(pos_intersection, set); + } } - return result; - ; - }, $Number_digits$67.$$arity = -1); - - Opal.def(self, '$divmod', $Number_divmod$68 = function $$divmod(other) { - var $a, $iter = $Number_divmod$68.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; - - if ($iter) $Number_divmod$68.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - if ($truthy(($truthy($a = self['$nan?']()) ? $a : other['$nan?']()))) { - return self.$raise($$($nesting, 'FloatDomainError'), "NaN") - } else if ($truthy(self['$infinite?']())) { - return self.$raise($$($nesting, 'FloatDomainError'), "Infinity") - } else { - return $send(self, Opal.find_super_dispatcher(self, 'divmod', $Number_divmod$68, false), $zuper, $iter) + if (pos_intersection.length > 0 && neg_intersection.length > 0) { + tmp = ''; + for (i = 0, len = pos_intersection.length; i < len; i++) { + chr = pos_intersection.charAt(i); + if (neg_intersection.indexOf(chr) === -1) { + tmp += chr; + } + } + pos_intersection = tmp; + neg_intersection = ''; } - }, $Number_divmod$68.$$arity = 1); - - Opal.def(self, '$upto', $Number_upto$69 = function $$upto(stop) { - var $iter = $Number_upto$69.$$p, block = $iter || nil, $$70, self = this; - - if ($iter) $Number_upto$69.$$p = null; - - - if ($iter) $Number_upto$69.$$p = null;; - if ((block !== nil)) { - } else { - return $send(self, 'enum_for', ["upto", stop], ($$70 = function(){var self = $$70.$$s || this; - - if ($truthy($$($nesting, 'Numeric')['$==='](stop))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed") - }; - if ($truthy($rb_lt(stop, self))) { - return 0 - } else { - return $rb_plus($rb_minus(stop, self), 1) - };}, $$70.$$s = self, $$70.$$arity = 0, $$70)) - }; - - if (!stop.$$is_number) { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed") + if (pos_intersection.length > 0) { + return '[' + $$$('Regexp').$escape(pos_intersection) + ']'; } - for (var i = self; i <= stop; i++) { - block(i); + + if (neg_intersection.length > 0) { + return '[^' + $$$('Regexp').$escape(neg_intersection) + ']'; } - ; - return self; - }, $Number_upto$69.$$arity = 1); + + return null; + } - Opal.def(self, '$zero?', $Number_zero$ques$71 = function() { - var self = this; + $def(self, '$instance_variables', function $$instance_variables() { + + return [] + }); + $defs(self, '$_load', function $$_load($a) { + var $post_args, args, self = this; - return self == 0; - }, $Number_zero$ques$71.$$arity = 0); + + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'new', $to_a(args)); + }, -1); - Opal.def(self, '$size', $Number_size$72 = function $$size() { + $def(self, '$unicode_normalize', function $$unicode_normalize(form) { var self = this; - return 4 - }, $Number_size$72.$$arity = 0); + + if (form == null) form = "nfc"; + if (!$truthy(["nfc", "nfd", "nfkc", "nfkd"]['$include?'](form))) { + $Kernel.$raise($$$('ArgumentError'), "Invalid normalization form " + (form)); + } return self.normalize(form.$upcase()); + }, -1); - Opal.def(self, '$nan?', $Number_nan$ques$73 = function() { + $def(self, '$unicode_normalized?', function $String_unicode_normalized$ques$18(form) { var self = this; - return isNaN(self); - }, $Number_nan$ques$73.$$arity = 0); + + if (form == null) form = "nfc"; + return self.$unicode_normalize(form)['$=='](self); + }, -1); + + $def(self, '$unpack', function $$unpack(format) { + + return $Kernel.$raise("To use String#unpack, you must first require 'corelib/string/unpack'.") + }); + + $def(self, '$unpack1', function $$unpack1(format) { + + return $Kernel.$raise("To use String#unpack1, you must first require 'corelib/string/unpack'.") + }); - Opal.def(self, '$finite?', $Number_finite$ques$74 = function() { + $def(self, '$freeze', function $$freeze() { var self = this; - return self != Infinity && self != -Infinity && !isNaN(self); - }, $Number_finite$ques$74.$$arity = 0); + + if (typeof self === 'string') { return self; } + $prop(self, "$$frozen", true); + return self; + + }); - Opal.def(self, '$infinite?', $Number_infinite$ques$75 = function() { + $def(self, '$-@', function $String_$minus$$19() { var self = this; - if (self == Infinity) { - return +1; - } - else if (self == -Infinity) { - return -1; - } - else { - return nil; - } + if (typeof self === 'string') return self; + if (self.$$frozen) return self; + if (self.encoding.name == 'UTF-8' && self.internal_encoding.name == 'UTF-8') return self.toString(); + return self.$dup().$freeze(); - }, $Number_infinite$ques$75.$$arity = 0); + }); - Opal.def(self, '$positive?', $Number_positive$ques$76 = function() { + $def(self, '$frozen?', function $String_frozen$ques$20() { var self = this; - return self != 0 && (self == Infinity || 1 / self > 0); - }, $Number_positive$ques$76.$$arity = 0); - return (Opal.def(self, '$negative?', $Number_negative$ques$77 = function() { - var self = this; + return typeof self === 'string' || self.$$frozen === true; + }); + $alias(self, "+@", "dup"); + $alias(self, "===", "=="); + $alias(self, "byteslice", "[]"); + $alias(self, "eql?", "=="); + $alias(self, "equal?", "==="); + $alias(self, "object_id", "__id__"); + $alias(self, "slice", "[]"); + $alias(self, "succ", "next"); + $alias(self, "to_str", "to_s"); + $alias(self, "to_sym", "intern"); + return $Opal.$pristine(self, "initialize"); + })('::', String, $nesting); + return $const_set($nesting[0], 'Symbol', $$('String')); +}; - return self == -Infinity || 1 / self < 0; - }, $Number_negative$ques$77.$$arity = 0), nil) && 'negative?'; - })($nesting[0], $$($nesting, 'Numeric'), $nesting); - Opal.const_set($nesting[0], 'Fixnum', $$($nesting, 'Number')); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Integer'); +Opal.modules["corelib/enumerable"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $yield1 = Opal.yield1, $yieldX = Opal.yieldX, $deny_frozen_access = Opal.deny_frozen_access, $module = Opal.module, $send = Opal.send, $slice = Opal.slice, $to_a = Opal.to_a, $Opal = Opal.Opal, $thrower = Opal.thrower, $def = Opal.def, $Kernel = Opal.Kernel, $return_val = Opal.return_val, $rb_gt = Opal.rb_gt, $rb_times = Opal.rb_times, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_divide = Opal.rb_divide, $rb_le = Opal.rb_le, $hash2 = Opal.hash2, $lambda = Opal.lambda, $not = Opal.not, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - var $nesting = [self].concat($parent_nesting); + Opal.add_stubs('each,public_send,destructure,to_enum,enumerator_size,new,yield,raise,slice_when,!,enum_for,flatten,map,to_proc,compact,to_a,warn,proc,==,nil?,respond_to?,coerce_to!,>,*,try_convert,<,+,-,ceil,/,size,select,__send__,length,<=,[],push,<<,[]=,===,inspect,<=>,first,reverse,sort,take,sort_by,compare,call,dup,sort!,map!,include?,-@,key?,values,transform_values,group_by,fetch,to_h,coerce_to?,class,zip,detect,find_all,collect_concat,collect,inject,entries'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Enumerable'); - - self.$$is_number_class = true; - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$78, $eq_eq_eq$79, $sqrt$80; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - - - Opal.def(self, '$allocate', $allocate$78 = function $$allocate() { - var self = this; + + + function comparableForPattern(value) { + if (value.length === 0) { + value = [nil]; + } - return self.$raise($$($nesting, 'TypeError'), "" + "allocator undefined for " + (self.$name())) - }, $allocate$78.$$arity = 0); - - Opal.udef(self, '$' + "new");; - - Opal.def(self, '$===', $eq_eq_eq$79 = function(other) { - var self = this; + if (value.length > 1) { + value = [value]; + } - - if (!other.$$is_number) { - return false; - } + return value; + } + + $def(self, '$all?', function $Enumerable_all$ques$1(pattern) {try { var $t_return = $thrower('return'); + var block = $Enumerable_all$ques$1.$$p || nil, self = this; - return (other % 1) === 0; + $Enumerable_all$ques$1.$$p = null; - }, $eq_eq_eq$79.$$arity = 1); - return (Opal.def(self, '$sqrt', $sqrt$80 = function $$sqrt(n) { - var self = this; - - - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int"); - - if (n < 0) { - self.$raise($$$($$($nesting, 'Math'), 'DomainError'), "Numerical argument is out of domain - \"isqrt\"") - } - - return parseInt(Math.sqrt(n), 10); ; - }, $sqrt$80.$$arity = 1), nil) && 'sqrt'; - })(Opal.get_singleton_class(self), $nesting); - Opal.const_set($nesting[0], 'MAX', Math.pow(2, 30) - 1); - return Opal.const_set($nesting[0], 'MIN', -Math.pow(2, 30)); - })($nesting[0], $$($nesting, 'Numeric'), $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Float'); + ; + if ($truthy(pattern !== undefined)) { + $send(self, 'each', [], function $$2($a){var $post_args, value, comparable = nil; - var $nesting = [self].concat($parent_nesting); + + $post_args = $slice(arguments); + value = $post_args; + comparable = comparableForPattern(value); + if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) { + return nil + } else { + $t_return.$throw(false); + };}, {$$arity: -1, $$ret: $t_return}); + } else if ((block !== nil)) { + $send(self, 'each', [], function $$3($a){var $post_args, value; + + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy(Opal.yieldX(block, $to_a(value)))) { + return nil + } else { + $t_return.$throw(false); + };}, {$$arity: -1, $$ret: $t_return}); + } else { + $send(self, 'each', [], function $$4($a){var $post_args, value; + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy($Opal.$destructure(value))) { + return nil + } else { + $t_return.$throw(false); + };}, {$$arity: -1, $$ret: $t_return}); + }; + return true;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); - self.$$is_number_class = true; - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $allocate$81, $eq_eq_eq$82; + $def(self, '$any?', function $Enumerable_any$ques$5(pattern) {try { var $t_return = $thrower('return'); + var block = $Enumerable_any$ques$5.$$p || nil, self = this; + $Enumerable_any$ques$5.$$p = null; - - Opal.def(self, '$allocate', $allocate$81 = function $$allocate() { - var self = this; + ; + ; + if ($truthy(pattern !== undefined)) { + $send(self, 'each', [], function $$6($a){var $post_args, value, comparable = nil; - return self.$raise($$($nesting, 'TypeError'), "" + "allocator undefined for " + (self.$name())) - }, $allocate$81.$$arity = 0); - - Opal.udef(self, '$' + "new");; - return (Opal.def(self, '$===', $eq_eq_eq$82 = function(other) { - var self = this; + + $post_args = $slice(arguments); + value = $post_args; + comparable = comparableForPattern(value); + if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) { + $t_return.$throw(true); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else if ((block !== nil)) { + $send(self, 'each', [], function $$7($a){var $post_args, value; - return !!other.$$is_number; - }, $eq_eq_eq$82.$$arity = 1), nil) && '==='; - })(Opal.get_singleton_class(self), $nesting); - Opal.const_set($nesting[0], 'INFINITY', Infinity); - Opal.const_set($nesting[0], 'MAX', Number.MAX_VALUE); - Opal.const_set($nesting[0], 'MIN', Number.MIN_VALUE); - Opal.const_set($nesting[0], 'NAN', NaN); - Opal.const_set($nesting[0], 'DIG', 15); - Opal.const_set($nesting[0], 'MANT_DIG', 53); - Opal.const_set($nesting[0], 'RADIX', 2); - return Opal.const_set($nesting[0], 'EPSILON', Number.EPSILON || 2.2204460492503130808472633361816E-16); - })($nesting[0], $$($nesting, 'Numeric'), $nesting); -}; + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy(Opal.yieldX(block, $to_a(value)))) { + $t_return.$throw(true); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else { + $send(self, 'each', [], function $$8($a){var $post_args, value; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/range"] = function(Opal) { - function $rb_le(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs <= rhs : lhs['$<='](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_divide(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs / rhs : lhs['$/'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_times(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs * rhs : lhs['$*'](rhs); - } - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send; + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy($Opal.$destructure(value))) { + $t_return.$throw(true); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + }; + return false;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + + $def(self, '$chunk', function $$chunk() { + var block = $$chunk.$$p || nil, self = this; - Opal.add_stubs(['$require', '$include', '$attr_reader', '$raise', '$<=>', '$include?', '$<=', '$<', '$enum_for', '$upto', '$to_proc', '$respond_to?', '$class', '$succ', '$!', '$==', '$===', '$exclude_end?', '$eql?', '$begin', '$end', '$last', '$to_a', '$>', '$-', '$abs', '$to_i', '$coerce_to!', '$ceil', '$/', '$size', '$loop', '$+', '$*', '$>=', '$each_with_index', '$%', '$bsearch', '$inspect', '$[]', '$hash']); - - self.$require("corelib/enumerable"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Range'); + $$chunk.$$p = null; + if (!(block !== nil)) { + return $send(self, 'to_enum', ["chunk"], function $$9(){var self = $$9.$$s == null ? this : $$9.$$s; - var $nesting = [self].concat($parent_nesting), $Range_initialize$1, $Range_$eq_eq$2, $Range_$eq_eq_eq$3, $Range_cover$ques$4, $Range_each$5, $Range_eql$ques$6, $Range_exclude_end$ques$7, $Range_first$8, $Range_last$9, $Range_max$10, $Range_min$11, $Range_size$12, $Range_step$13, $Range_bsearch$17, $Range_to_s$18, $Range_inspect$19, $Range_marshal_load$20, $Range_hash$21; + return self.$enumerator_size()}, {$$s: self}) + } return $send($$$('Enumerator'), 'new', [], function $$10(yielder){var self = $$10.$$s == null ? this : $$10.$$s; - self.$$prototype.begin = self.$$prototype.end = self.$$prototype.excl = nil; - - self.$include($$($nesting, 'Enumerable')); - self.$$prototype.$$is_range = true; - self.$attr_reader("begin", "end"); - - Opal.def(self, '$initialize', $Range_initialize$1 = function $$initialize(first, last, exclude) { - var self = this; + + if (yielder == null) yielder = nil; + + var previous = nil, accumulate = []; - - - if (exclude == null) { - exclude = false; - }; - if ($truthy(self.begin)) { - self.$raise($$($nesting, 'NameError'), "'initialize' called twice")}; - if ($truthy(first['$<=>'](last))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "bad value for range") - }; - self.begin = first; - self.end = last; - return (self.excl = exclude); - }, $Range_initialize$1.$$arity = -3); - - Opal.def(self, '$==', $Range_$eq_eq$2 = function(other) { - var self = this; + function releaseAccumulate() { + if (accumulate.length > 0) { + yielder.$yield(previous, accumulate); + } + } - - if (!other.$$is_range) { - return false; - } + self.$each.$$p = function(value) { + var key = $yield1(block, value); - return self.excl === other.excl && - self.begin == other.begin && - self.end == other.end; - - }, $Range_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$===', $Range_$eq_eq_eq$3 = function(value) { - var self = this; + if (key === nil) { + releaseAccumulate(); + accumulate = []; + previous = nil; + } else { + if (previous === nil || previous === key) { + accumulate.push(value); + } else { + releaseAccumulate(); + accumulate = [value]; + } - return self['$include?'](value) - }, $Range_$eq_eq_eq$3.$$arity = 1); - - Opal.def(self, '$cover?', $Range_cover$ques$4 = function(value) { - var $a, self = this, beg_cmp = nil, end_cmp = nil; + previous = key; + } + }; - - beg_cmp = self.begin['$<=>'](value); - if ($truthy(($truthy($a = beg_cmp) ? $rb_le(beg_cmp, 0) : $a))) { - } else { - return false - }; - end_cmp = value['$<=>'](self.end); - if ($truthy(self.excl)) { - return ($truthy($a = end_cmp) ? $rb_lt(end_cmp, 0) : $a) - } else { - return ($truthy($a = end_cmp) ? $rb_le(end_cmp, 0) : $a) - }; - }, $Range_cover$ques$4.$$arity = 1); + self.$each(); + + releaseAccumulate(); +}, {$$s: self}); + }); - Opal.def(self, '$each', $Range_each$5 = function $$each() { - var $iter = $Range_each$5.$$p, block = $iter || nil, $a, self = this, current = nil, last = nil; + $def(self, '$chunk_while', function $$chunk_while() { + var block = $$chunk_while.$$p || nil, self = this; - if ($iter) $Range_each$5.$$p = null; - - - if ($iter) $Range_each$5.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("each") - }; - - var i, limit; + $$chunk_while.$$p = null; + if (!(block !== nil)) { + $Kernel.$raise($$$('ArgumentError'), "no block given"); + } return $send(self, 'slice_when', [], function $$11(before, after){ + + if (before == null) before = nil; + if (after == null) after = nil; + return Opal.yieldX(block, [before, after])['$!']();}); + }); + + $def(self, '$collect', function $$collect() { + var block = $$collect.$$p || nil, self = this; - if (self.begin.$$is_number && self.end.$$is_number) { - if (self.begin % 1 !== 0 || self.end % 1 !== 0) { - self.$raise($$($nesting, 'TypeError'), "can't iterate from Float") - } + $$collect.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["collect"], function $$12(){var self = $$12.$$s == null ? this : $$12.$$s; - for (i = self.begin, limit = self.end + (function() {if ($truthy(self.excl)) { - return 0 - } else { - return 1 - }; return nil; })(); i < limit; i++) { - block(i); - } + return self.$enumerator_size()}, {$$s: self}) + } + var result = []; - return self; - } + self.$each.$$p = function() { + var value = $yieldX(block, arguments); - if (self.begin.$$is_string && self.end.$$is_string) { - $send(self.begin, 'upto', [self.end, self.excl], block.$to_proc()) - return self; - } - ; - current = self.begin; - last = self.end; - if ($truthy(current['$respond_to?']("succ"))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + "can't iterate from " + (current.$class())) - }; - while ($truthy($rb_lt(current['$<=>'](last), 0))) { - - Opal.yield1(block, current); - current = current.$succ(); + result.push(value); }; - if ($truthy(($truthy($a = self.excl['$!']()) ? current['$=='](last) : $a))) { - Opal.yield1(block, current)}; - return self; - }, $Range_each$5.$$arity = 0); - - Opal.def(self, '$eql?', $Range_eql$ques$6 = function(other) { - var $a, $b, self = this; - - if ($truthy($$($nesting, 'Range')['$==='](other))) { - } else { - return false - }; - return ($truthy($a = ($truthy($b = self.excl['$==='](other['$exclude_end?']())) ? self.begin['$eql?'](other.$begin()) : $b)) ? self.end['$eql?'](other.$end()) : $a); - }, $Range_eql$ques$6.$$arity = 1); - - Opal.def(self, '$exclude_end?', $Range_exclude_end$ques$7 = function() { - var self = this; + self.$each(); - return self.excl - }, $Range_exclude_end$ques$7.$$arity = 0); + return result; + }); - Opal.def(self, '$first', $Range_first$8 = function $$first(n) { - var $iter = $Range_first$8.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + $def(self, '$collect_concat', function $$collect_concat() { + var block = $$collect_concat.$$p || nil, self = this; - if ($iter) $Range_first$8.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - - ; - if ($truthy(n == null)) { - return self.begin}; - return $send(self, Opal.find_super_dispatcher(self, 'first', $Range_first$8, false), $zuper, $iter); - }, $Range_first$8.$$arity = -1); - Opal.alias(self, "include?", "cover?"); + $$collect_concat.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["collect_concat"], function $$13(){var self = $$13.$$s == null ? this : $$13.$$s; + + return self.$enumerator_size()}, {$$s: self}) + } return $send(self, 'map', [], block.$to_proc()).$flatten(1); + }); - Opal.def(self, '$last', $Range_last$9 = function $$last(n) { + $def(self, '$compact', function $$compact() { var self = this; - - ; - if ($truthy(n == null)) { - return self.end}; - return self.$to_a().$last(n); - }, $Range_last$9.$$arity = -1); + return self.$to_a().$compact() + }); - Opal.def(self, '$max', $Range_max$10 = function $$max() { - var $a, $iter = $Range_max$10.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + $def(self, '$count', function $$count(object) { + var block = $$count.$$p || nil, self = this, result = nil; - if ($iter) $Range_max$10.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - if (($yield !== nil)) { - return $send(self, Opal.find_super_dispatcher(self, 'max', $Range_max$10, false), $zuper, $iter) - } else if ($truthy($rb_gt(self.begin, self.end))) { - return nil - } else if ($truthy(($truthy($a = self.excl) ? self.begin['$=='](self.end) : $a))) { - return nil - } else { - return self.excl ? self.end - 1 : self.end + $$count.$$p = null; + result = 0; + + if (object != null && block !== nil) { + self.$warn("warning: given block not used"); } - }, $Range_max$10.$$arity = 0); - Opal.alias(self, "member?", "cover?"); - - Opal.def(self, '$min', $Range_min$11 = function $$min() { - var $a, $iter = $Range_min$11.$$p, $yield = $iter || nil, self = this, $zuper = nil, $zuper_i = nil, $zuper_ii = nil; + if ($truthy(object != null)) { + block = $send($Kernel, 'proc', [], function $$14($a){var $post_args, args; - if ($iter) $Range_min$11.$$p = null; - // Prepare super implicit arguments - for($zuper_i = 0, $zuper_ii = arguments.length, $zuper = new Array($zuper_ii); $zuper_i < $zuper_ii; $zuper_i++) { - $zuper[$zuper_i] = arguments[$zuper_i]; - } - if (($yield !== nil)) { - return $send(self, Opal.find_super_dispatcher(self, 'min', $Range_min$11, false), $zuper, $iter) - } else if ($truthy($rb_gt(self.begin, self.end))) { - return nil - } else if ($truthy(($truthy($a = self.excl) ? self.begin['$=='](self.end) : $a))) { - return nil - } else { - return self.begin - } - }, $Range_min$11.$$arity = 0); - - Opal.def(self, '$size', $Range_size$12 = function $$size() { - var $a, self = this, range_begin = nil, range_end = nil, infinity = nil; + + $post_args = $slice(arguments); + args = $post_args; + return $Opal.$destructure(args)['$=='](object);}, -1); + } else if ($truthy(block['$nil?']())) { + block = $send($Kernel, 'proc', [], $return_val(true)); + } $send(self, 'each', [], function $$15($a){var $post_args, args; - - range_begin = self.begin; - range_end = self.end; - if ($truthy(self.excl)) { - range_end = $rb_minus(range_end, 1)}; - if ($truthy(($truthy($a = $$($nesting, 'Numeric')['$==='](range_begin)) ? $$($nesting, 'Numeric')['$==='](range_end) : $a))) { - } else { - return nil - }; - if ($truthy($rb_lt(range_end, range_begin))) { - return 0}; - infinity = $$$($$($nesting, 'Float'), 'INFINITY'); - if ($truthy([range_begin.$abs(), range_end.$abs()]['$include?'](infinity))) { - return infinity}; - return (Math.abs(range_end - range_begin) + 1).$to_i(); - }, $Range_size$12.$$arity = 0); + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy($yieldX(block, args))) { + return result++; + } else { + return nil + }}, -1); + return result; + }, -1); - Opal.def(self, '$step', $Range_step$13 = function $$step(n) { - var $$14, $$15, $$16, $iter = $Range_step$13.$$p, $yield = $iter || nil, self = this, i = nil; + $def(self, '$cycle', function $$cycle(n) { + var block = $$cycle.$$p || nil, self = this; - if ($iter) $Range_step$13.$$p = null; - - - if (n == null) { - n = 1; - }; - - function coerceStepSize() { - if (!n.$$is_number) { - n = $$($nesting, 'Opal')['$coerce_to!'](n, $$($nesting, 'Integer'), "to_int") - } + $$cycle.$$p = null; + if (n == null) n = nil; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["cycle", n], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s; - if (n < 0) { - self.$raise($$($nesting, 'ArgumentError'), "step can't be negative") - } else if (n === 0) { - self.$raise($$($nesting, 'ArgumentError'), "step can't be 0") - } - } + if ($truthy(n['$nil?']())) { + if ($truthy(self['$respond_to?']("size"))) { + return $$$($$$('Float'), 'INFINITY') + } else { + return nil + } + } else { + + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if ($truthy($rb_gt(n, 0))) { + return $rb_times(self.$enumerator_size(), n) + } else { + return 0 + } }}, {$$s: self}) + } if (!$truthy(n['$nil?']())) { + + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if ($truthy(n <= 0)) { + return nil + } } + var all = [], i, length; - function enumeratorSize() { - if (!self.begin['$respond_to?']("succ")) { - return nil; - } + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); + $yield1(block, param); - if (self.begin.$$is_string && self.end.$$is_string) { - return nil; - } + all.push(param); + }; - if (n % 1 === 0) { - return $rb_divide(self.$size(), n).$ceil(); - } else { - // n is a float - var begin = self.begin, end = self.end, - abs = Math.abs, floor = Math.floor, - err = (abs(begin) + abs(end) + abs(end - begin)) / abs(n) * $$$($$($nesting, 'Float'), 'EPSILON'), - size; + self.$each(); - if (err > 0.5) { - err = 0.5; - } + if (all.length === 0) { + return nil; + } - if (self.excl) { - size = floor((end - begin) / n - err); - if (size * n + begin < end) { - size++; - } - } else { - size = floor((end - begin) / n + err) + 1 + if (n === nil) { + while (true) { + for (i = 0, length = all.length; i < length; i++) { + $yield1(block, all[i]); } - - return size; } } - ; - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["step", n], ($$14 = function(){var self = $$14.$$s || this; - - - coerceStepSize(); - return enumeratorSize(); - }, $$14.$$s = self, $$14.$$arity = 0, $$14)) - }; - coerceStepSize(); - if ($truthy(self.begin.$$is_number && self.end.$$is_number)) { - - i = 0; - (function(){var $brk = Opal.new_brk(); try {return $send(self, 'loop', [], ($$15 = function(){var self = $$15.$$s || this, current = nil; - if (self.begin == null) self.begin = nil; - if (self.excl == null) self.excl = nil; - if (self.end == null) self.end = nil; + else { + while (n > 1) { + for (i = 0, length = all.length; i < length; i++) { + $yield1(block, all[i]); + } - - current = $rb_plus(self.begin, $rb_times(i, n)); - if ($truthy(self.excl)) { - if ($truthy($rb_ge(current, self.end))) { - - Opal.brk(nil, $brk)} - } else if ($truthy($rb_gt(current, self.end))) { - - Opal.brk(nil, $brk)}; - Opal.yield1($yield, current); - return (i = $rb_plus(i, 1));}, $$15.$$s = self, $$15.$$brk = $brk, $$15.$$arity = 0, $$15)) - } catch (err) { if (err === $brk) { return err.$v } else { throw err } }})(); - } else { - - - if (self.begin.$$is_string && self.end.$$is_string && n % 1 !== 0) { - self.$raise($$($nesting, 'TypeError'), "no implicit conversion to float from string") + n--; } - ; - $send(self, 'each_with_index', [], ($$16 = function(value, idx){var self = $$16.$$s || this; - - - - if (value == null) { - value = nil; - }; - - if (idx == null) { - idx = nil; - }; - if (idx['$%'](n)['$=='](0)) { - return Opal.yield1($yield, value); - } else { - return nil - };}, $$16.$$s = self, $$16.$$arity = 2, $$16)); - }; - return self; - }, $Range_step$13.$$arity = -1); + } + }, -1); - Opal.def(self, '$bsearch', $Range_bsearch$17 = function $$bsearch() { - var $iter = $Range_bsearch$17.$$p, block = $iter || nil, self = this; + $def(self, '$detect', function $$detect(ifnone) {try { var $t_return = $thrower('return'); + var block = $$detect.$$p || nil, self = this; - if ($iter) $Range_bsearch$17.$$p = null; - + $$detect.$$p = null; - if ($iter) $Range_bsearch$17.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("bsearch") - }; - if ($truthy(self.begin.$$is_number && self.end.$$is_number)) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + "can't do binary search for " + (self.begin.$class())) + ; + ; + if (!(block !== nil)) { + return self.$enum_for("detect", ifnone) }; - return $send(self.$to_a(), 'bsearch', [], block.$to_proc()); - }, $Range_bsearch$17.$$arity = 0); - - Opal.def(self, '$to_s', $Range_to_s$18 = function $$to_s() { - var self = this; - - return "" + (self.begin) + ((function() {if ($truthy(self.excl)) { - return "..." - } else { - return ".." - }; return nil; })()) + (self.end) - }, $Range_to_s$18.$$arity = 0); - - Opal.def(self, '$inspect', $Range_inspect$19 = function $$inspect() { - var self = this; + $send(self, 'each', [], function $$17($a){var $post_args, args, value = nil; - return "" + (self.begin.$inspect()) + ((function() {if ($truthy(self.excl)) { - return "..." - } else { - return ".." - }; return nil; })()) + (self.end.$inspect()) - }, $Range_inspect$19.$$arity = 0); + + $post_args = $slice(arguments); + args = $post_args; + value = $Opal.$destructure(args); + if ($truthy(Opal.yield1(block, value))) { + $t_return.$throw(value); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + + if (ifnone !== undefined) { + if (typeof(ifnone) === 'function') { + return ifnone(); + } else { + return ifnone; + } + } + ; + return nil;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); - Opal.def(self, '$marshal_load', $Range_marshal_load$20 = function $$marshal_load(args) { + $def(self, '$drop', function $$drop(number) { var self = this; - self.begin = args['$[]']("begin"); - self.end = args['$[]']("end"); - return (self.excl = args['$[]']("excl")); - }, $Range_marshal_load$20.$$arity = 1); - return (Opal.def(self, '$hash', $Range_hash$21 = function $$hash() { - var self = this; - - return [self.begin, self.end, self.excl].$hash() - }, $Range_hash$21.$$arity = 0), nil) && 'hash'; - })($nesting[0], null, $nesting); -}; + number = $coerce_to(number, $$$('Integer'), 'to_int'); + if ($truthy(number < 0)) { + $Kernel.$raise($$$('ArgumentError'), "attempt to drop negative size"); + } + var result = [], + current = 0; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/proc"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; + self.$each.$$p = function() { + if (number <= current) { + result.push($Opal.$destructure(arguments)); + } - Opal.add_stubs(['$raise', '$coerce_to!']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Proc'); + current++; + }; - var $nesting = [self].concat($parent_nesting), $Proc_new$1, $Proc_call$2, $Proc_to_proc$3, $Proc_lambda$ques$4, $Proc_arity$5, $Proc_source_location$6, $Proc_binding$7, $Proc_parameters$8, $Proc_curry$9, $Proc_dup$10; + self.$each(); + return result; + }); - Opal.defineProperty(self.$$prototype, '$$is_proc', true); - Opal.defineProperty(self.$$prototype, '$$is_lambda', false); - Opal.defs(self, '$new', $Proc_new$1 = function() { - var $iter = $Proc_new$1.$$p, block = $iter || nil, self = this; + $def(self, '$drop_while', function $$drop_while() { + var block = $$drop_while.$$p || nil, self = this; - if ($iter) $Proc_new$1.$$p = null; - - - if ($iter) $Proc_new$1.$$p = null;; - if ($truthy(block)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "tried to create a Proc object without a block") - }; - return block; - }, $Proc_new$1.$$arity = 0); - - Opal.def(self, '$call', $Proc_call$2 = function $$call($a) { - var $iter = $Proc_call$2.$$p, block = $iter || nil, $post_args, args, self = this; + $$drop_while.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("drop_while") + } + var result = [], + dropping = true; - if ($iter) $Proc_call$2.$$p = null; - - - if ($iter) $Proc_call$2.$$p = null;; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - if (block !== nil) { - self.$$p = block; - } + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - var result, $brk = self.$$brk; + if (dropping) { + var value = $yield1(block, param); - if ($brk) { - try { - if (self.$$is_lambda) { - result = self.apply(null, args); - } - else { - result = Opal.yieldX(self, args); - } - } catch (err) { - if (err === $brk) { - return $brk.$v - } - else { - throw err + if (!$truthy(value)) { + dropping = false; + result.push(param); } } - } - else { - if (self.$$is_lambda) { - result = self.apply(null, args); - } else { - result = Opal.yieldX(self, args); + result.push(param); } - } + }; + + self.$each(); return result; - ; - }, $Proc_call$2.$$arity = -1); - Opal.alias(self, "[]", "call"); - Opal.alias(self, "===", "call"); - Opal.alias(self, "yield", "call"); + }); - Opal.def(self, '$to_proc', $Proc_to_proc$3 = function $$to_proc() { - var self = this; + $def(self, '$each_cons', function $$each_cons(n) { + var block = $$each_cons.$$p || nil, self = this; - return self - }, $Proc_to_proc$3.$$arity = 0); - - Opal.def(self, '$lambda?', $Proc_lambda$ques$4 = function() { - var self = this; + $$each_cons.$$p = null; + if ($truthy(arguments.length != 1)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 1)"); + } n = $Opal.$try_convert(n, $$$('Integer'), "to_int"); + if ($truthy(n <= 0)) { + $Kernel.$raise($$$('ArgumentError'), "invalid size"); + } if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_cons", n], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s, enum_size = nil; - return !!self.$$is_lambda; - }, $Proc_lambda$ques$4.$$arity = 0); - - Opal.def(self, '$arity', $Proc_arity$5 = function $$arity() { - var self = this; + + enum_size = self.$enumerator_size(); + if ($truthy(enum_size['$nil?']())) { + return nil + } else if (($eqeq(enum_size, 0) || ($truthy($rb_lt(enum_size, n))))) { + return 0 + } else { + return $rb_plus($rb_minus(enum_size, n), 1) + }}, {$$s: self}) + } + var buffer = []; - - if (self.$$is_curried) { - return -1; - } else { - return self.$$arity; - } - - }, $Proc_arity$5.$$arity = 0); - - Opal.def(self, '$source_location', $Proc_source_location$6 = function $$source_location() { - var self = this; + self.$each.$$p = function() { + var element = $Opal.$destructure(arguments); + buffer.push(element); + if (buffer.length > n) { + buffer.shift(); + } + if (buffer.length == n) { + $yield1(block, buffer.slice(0, n)); + } + }; - - if (self.$$is_curried) { return nil; }; - return nil; - }, $Proc_source_location$6.$$arity = 0); - - Opal.def(self, '$binding', $Proc_binding$7 = function $$binding() { - var self = this; + self.$each(); - - if (self.$$is_curried) { self.$raise($$($nesting, 'ArgumentError'), "Can't create Binding") }; - return nil; - }, $Proc_binding$7.$$arity = 0); + return self; + }); - Opal.def(self, '$parameters', $Proc_parameters$8 = function $$parameters() { - var self = this; + $def(self, '$each_entry', function $$each_entry($a) { + var block = $$each_entry.$$p || nil, $post_args, data, self = this; - - if (self.$$is_curried) { - return [["rest"]]; - } else if (self.$$parameters) { - if (self.$$is_lambda) { - return self.$$parameters; - } else { - var result = [], i, length; + $$each_entry.$$p = null; + $post_args = $slice(arguments); + data = $post_args; + if (!(block !== nil)) { + return $send(self, 'to_enum', ["each_entry"].concat($to_a(data)), function $$19(){var self = $$19.$$s == null ? this : $$19.$$s; - for (i = 0, length = self.$$parameters.length; i < length; i++) { - var parameter = self.$$parameters[i]; + return self.$enumerator_size()}, {$$s: self}) + } + self.$each.$$p = function() { + var item = $Opal.$destructure(arguments); - if (parameter[0] === 'req') { - // required arguments always have name - parameter = ['opt', parameter[1]]; - } + $yield1(block, item); + }; - result.push(parameter); - } + self.$each.apply(self, data); - return result; - } - } else { - return []; - } - - }, $Proc_parameters$8.$$arity = 0); + return self; + }, -1); - Opal.def(self, '$curry', $Proc_curry$9 = function $$curry(arity) { - var self = this; + $def(self, '$each_slice', function $$each_slice(n) { + var block = $$each_slice.$$p || nil, self = this; - - ; - - if (arity === undefined) { - arity = self.length; - } - else { - arity = $$($nesting, 'Opal')['$coerce_to!'](arity, $$($nesting, 'Integer'), "to_int"); - if (self.$$is_lambda && arity !== self.length) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (arity) + " for " + (self.length) + ")") - } - } + $$each_slice.$$p = null; + n = $coerce_to(n, $$$('Integer'), 'to_int'); + if ($truthy(n <= 0)) { + $Kernel.$raise($$$('ArgumentError'), "invalid slice size"); + } if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_slice", n], function $$20(){var self = $$20.$$s == null ? this : $$20.$$s; - function curried () { - var args = $slice.call(arguments), - length = args.length, - result; + if ($truthy(self['$respond_to?']("size"))) { + return $rb_divide(self.$size(), n).$ceil() + } else { + return nil + }}, {$$s: self}) + } + var slice = []; - if (length > arity && self.$$is_lambda && !self.$$is_curried) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (" + (length) + " for " + (arity) + ")") - } + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - if (length >= arity) { - return self.$call.apply(self, args); - } + slice.push(param); - result = function () { - return curried.apply(null, - args.concat($slice.call(arguments))); + if (slice.length === n) { + $yield1(block, slice); + slice = []; } - result.$$is_lambda = self.$$is_lambda; - result.$$is_curried = true; - - return result; }; - curried.$$is_lambda = self.$$is_lambda; - curried.$$is_curried = true; - return curried; - ; - }, $Proc_curry$9.$$arity = -1); - - Opal.def(self, '$dup', $Proc_dup$10 = function $$dup() { - var self = this; - - - var original_proc = self.$$original_proc || self, - proc = function () { - return original_proc.apply(this, arguments); - }; + self.$each(); - for (var prop in self) { - if (self.hasOwnProperty(prop)) { - proc[prop] = self[prop]; - } + // our "last" group, if smaller than n then won't have been yielded + if (slice.length > 0) { + $yield1(block, slice); } - - return proc; + return self; + }); - }, $Proc_dup$10.$$arity = 0); - return Opal.alias(self, "clone", "dup"); - })($nesting[0], Function, $nesting) -}; + $def(self, '$each_with_index', function $$each_with_index($a) { + var block = $$each_with_index.$$p || nil, $post_args, args, self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/method"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; + $$each_with_index.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_with_index"].concat($to_a(args)), function $$21(){var self = $$21.$$s == null ? this : $$21.$$s; - Opal.add_stubs(['$attr_reader', '$arity', '$new', '$class', '$join', '$source_location', '$raise']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Method'); + return self.$enumerator_size()}, {$$s: self}) + } + var index = 0; - var $nesting = [self].concat($parent_nesting), $Method_initialize$1, $Method_arity$2, $Method_parameters$3, $Method_source_location$4, $Method_comments$5, $Method_call$6, $Method_unbind$7, $Method_to_proc$8, $Method_inspect$9; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - self.$$prototype.method = self.$$prototype.receiver = self.$$prototype.owner = self.$$prototype.name = nil; - - self.$attr_reader("owner", "receiver", "name"); - - Opal.def(self, '$initialize', $Method_initialize$1 = function $$initialize(receiver, owner, method, name) { - var self = this; + block(param, index); - - self.receiver = receiver; - self.owner = owner; - self.name = name; - return (self.method = method); - }, $Method_initialize$1.$$arity = 4); - - Opal.def(self, '$arity', $Method_arity$2 = function $$arity() { - var self = this; + index++; + }; - return self.method.$arity() - }, $Method_arity$2.$$arity = 0); + self.$each.apply(self, args); + return self; + }, -1); - Opal.def(self, '$parameters', $Method_parameters$3 = function $$parameters() { - var self = this; + $def(self, '$each_with_object', function $$each_with_object(object) { + var block = $$each_with_object.$$p || nil, self = this; - return self.method.$$parameters - }, $Method_parameters$3.$$arity = 0); - - Opal.def(self, '$source_location', $Method_source_location$4 = function $$source_location() { - var $a, self = this; + $$each_with_object.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_with_object", object], function $$22(){var self = $$22.$$s == null ? this : $$22.$$s; - return ($truthy($a = self.method.$$source_location) ? $a : ["(eval)", 0]) - }, $Method_source_location$4.$$arity = 0); - - Opal.def(self, '$comments', $Method_comments$5 = function $$comments() { - var $a, self = this; + return self.$enumerator_size()}, {$$s: self}) + } + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - return ($truthy($a = self.method.$$comments) ? $a : []) - }, $Method_comments$5.$$arity = 0); + block(param, object); + }; + + self.$each(); + return object; + }); - Opal.def(self, '$call', $Method_call$6 = function $$call($a) { - var $iter = $Method_call$6.$$p, block = $iter || nil, $post_args, args, self = this; + $def(self, '$entries', function $$entries($a) { + var $post_args, args, self = this; - if ($iter) $Method_call$6.$$p = null; - - if ($iter) $Method_call$6.$$p = null;; + $post_args = $slice(arguments); + args = $post_args; - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - - self.method.$$p = block; + var result = []; - return self.method.apply(self.receiver, args); - ; - }, $Method_call$6.$$arity = -1); - Opal.alias(self, "[]", "call"); - - Opal.def(self, '$unbind', $Method_unbind$7 = function $$unbind() { - var self = this; + self.$each.$$p = function() { + result.push($Opal.$destructure(arguments)); + }; - return $$($nesting, 'UnboundMethod').$new(self.receiver.$class(), self.owner, self.method, self.name) - }, $Method_unbind$7.$$arity = 0); - - Opal.def(self, '$to_proc', $Method_to_proc$8 = function $$to_proc() { - var self = this; + self.$each.apply(self, args); - - var proc = self.$call.bind(self); - proc.$$unbound = self.method; - proc.$$is_lambda = true; - proc.$$arity = self.method.$$arity; - proc.$$parameters = self.method.$$parameters; - return proc; + return result; + }, -1); - }, $Method_to_proc$8.$$arity = 0); - return (Opal.def(self, '$inspect', $Method_inspect$9 = function $$inspect() { - var self = this; - - return "" + "#<" + (self.$class()) + ": " + (self.receiver.$class()) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>" - }, $Method_inspect$9.$$arity = 0), nil) && 'inspect'; - })($nesting[0], null, $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'UnboundMethod'); + $def(self, '$filter_map', function $$filter_map() { + var block = $$filter_map.$$p || nil, self = this; - var $nesting = [self].concat($parent_nesting), $UnboundMethod_initialize$10, $UnboundMethod_arity$11, $UnboundMethod_parameters$12, $UnboundMethod_source_location$13, $UnboundMethod_comments$14, $UnboundMethod_bind$15, $UnboundMethod_inspect$16; + $$filter_map.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["filter_map"], function $$23(){var self = $$23.$$s == null ? this : $$23.$$s; - self.$$prototype.method = self.$$prototype.owner = self.$$prototype.name = self.$$prototype.source = nil; - - self.$attr_reader("source", "owner", "name"); + return self.$enumerator_size()}, {$$s: self}) + } return $send($send(self, 'map', [], block.$to_proc()), 'select', [], "itself".$to_proc()); + }); - Opal.def(self, '$initialize', $UnboundMethod_initialize$10 = function $$initialize(source, owner, method, name) { - var self = this; + $def(self, '$find_all', function $$find_all() { + var block = $$find_all.$$p || nil, self = this; - - self.source = source; - self.owner = owner; - self.method = method; - return (self.name = name); - }, $UnboundMethod_initialize$10.$$arity = 4); - - Opal.def(self, '$arity', $UnboundMethod_arity$11 = function $$arity() { - var self = this; + $$find_all.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["find_all"], function $$24(){var self = $$24.$$s == null ? this : $$24.$$s; - return self.method.$arity() - }, $UnboundMethod_arity$11.$$arity = 0); - - Opal.def(self, '$parameters', $UnboundMethod_parameters$12 = function $$parameters() { - var self = this; + return self.$enumerator_size()}, {$$s: self}) + } + var result = []; - return self.method.$$parameters - }, $UnboundMethod_parameters$12.$$arity = 0); - - Opal.def(self, '$source_location', $UnboundMethod_source_location$13 = function $$source_location() { - var $a, self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - return ($truthy($a = self.method.$$source_location) ? $a : ["(eval)", 0]) - }, $UnboundMethod_source_location$13.$$arity = 0); - - Opal.def(self, '$comments', $UnboundMethod_comments$14 = function $$comments() { - var $a, self = this; + if ($truthy(value)) { + result.push(param); + } + }; + + self.$each(); - return ($truthy($a = self.method.$$comments) ? $a : []) - }, $UnboundMethod_comments$14.$$arity = 0); + return result; + }); - Opal.def(self, '$bind', $UnboundMethod_bind$15 = function $$bind(object) { - var self = this; + $def(self, '$find_index', function $$find_index(object) {try { var $t_return = $thrower('return'); + var block = $$find_index.$$p || nil, self = this, index = nil; + $$find_index.$$p = null; - if (self.owner.$$is_module || Opal.is_a(object, self.owner)) { - return $$($nesting, 'Method').$new(object, self.owner, self.method, self.name); + ; + ; + if ($truthy(object === undefined && block === nil)) { + return self.$enum_for("find_index") + }; + + if (object != null && block !== nil) { + self.$warn("warning: given block not used"); } - else { - self.$raise($$($nesting, 'TypeError'), "" + "can't bind singleton method to a different class (expected " + (object) + ".kind_of?(" + (self.owner) + " to be true)"); + ; + index = 0; + if ($truthy(object != null)) { + $send(self, 'each', [], function $$25($a){var $post_args, value; + + + $post_args = $slice(arguments); + value = $post_args; + if ($eqeq($Opal.$destructure(value), object)) { + $t_return.$throw(index); + }; + return index += 1;;}, {$$arity: -1, $$ret: $t_return}); + } else { + $send(self, 'each', [], function $$26($a){var $post_args, value; + + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy(Opal.yieldX(block, $to_a(value)))) { + $t_return.$throw(index); + }; + return index += 1;;}, {$$arity: -1, $$ret: $t_return}); + }; + return nil;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; } + }, -1); - }, $UnboundMethod_bind$15.$$arity = 1); - return (Opal.def(self, '$inspect', $UnboundMethod_inspect$16 = function $$inspect() { - var self = this; - - return "" + "#<" + (self.$class()) + ": " + (self.source) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>" - }, $UnboundMethod_inspect$16.$$arity = 0), nil) && 'inspect'; - })($nesting[0], null, $nesting); -}; + $def(self, '$first', function $$first(number) {try { var $t_return = $thrower('return'); + var self = this, result = nil, current = nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/variables"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $gvars = Opal.gvars, $hash2 = Opal.hash2; + + ; + if ($truthy(number === undefined)) { + return $send(self, 'each', [], function $$27(value){ + + if (value == null) value = nil; + $t_return.$throw(value);}, {$$ret: $t_return}) + } else { + + result = []; + number = $coerce_to(number, $$$('Integer'), 'to_int'); + if ($truthy(number < 0)) { + $Kernel.$raise($$$('ArgumentError'), "attempt to take negative size"); + }; + if ($truthy(number == 0)) { + return [] + }; + current = 0; + $send(self, 'each', [], function $$28($a){var $post_args, args; - Opal.add_stubs(['$new']); - - $gvars['&'] = $gvars['~'] = $gvars['`'] = $gvars["'"] = nil; - $gvars.LOADED_FEATURES = ($gvars["\""] = Opal.loaded_features); - $gvars.LOAD_PATH = ($gvars[":"] = []); - $gvars["/"] = "\n"; - $gvars[","] = nil; - Opal.const_set($nesting[0], 'ARGV', []); - Opal.const_set($nesting[0], 'ARGF', $$($nesting, 'Object').$new()); - Opal.const_set($nesting[0], 'ENV', $hash2([], {})); - $gvars.VERBOSE = false; - $gvars.DEBUG = false; - return ($gvars.SAFE = 0); -}; + + $post_args = $slice(arguments); + args = $post_args; + result.push($Opal.$destructure(args)); + if ($truthy(number <= ++current)) { + $t_return.$throw(result); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + return result; + };} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + + $def(self, '$grep', function $$grep(pattern) { + var block = $$grep.$$p || nil, self = this, result = nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["opal/regexp_anchors"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module; + $$grep.$$p = null; + result = []; + $send(self, 'each', [], function $$29($a){var $post_args, value, cmp = nil; - Opal.add_stubs(['$==', '$new']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Opal'); + + $post_args = $slice(arguments); + value = $post_args; + cmp = comparableForPattern(value); + if (!$truthy($send(pattern, '__send__', ["==="].concat($to_a(cmp))))) { + return nil + } if ((block !== nil)) { + + if ($truthy($rb_gt(value.$length(), 1))) { + value = [value]; + } value = Opal.yieldX(block, $to_a(value)); + } else if ($truthy($rb_le(value.$length(), 1))) { + value = value['$[]'](0); + } return result.$push(value);}, -1); + return result; + }); + + $def(self, '$grep_v', function $$grep_v(pattern) { + var block = $$grep_v.$$p || nil, self = this, result = nil; - var $nesting = [self].concat($parent_nesting); + $$grep_v.$$p = null; + result = []; + $send(self, 'each', [], function $$30($a){var $post_args, value, cmp = nil; + + $post_args = $slice(arguments); + value = $post_args; + cmp = comparableForPattern(value); + if ($truthy($send(pattern, '__send__', ["==="].concat($to_a(cmp))))) { + return nil + } if ((block !== nil)) { + + if ($truthy($rb_gt(value.$length(), 1))) { + value = [value]; + } value = Opal.yieldX(block, $to_a(value)); + } else if ($truthy($rb_le(value.$length(), 1))) { + value = value['$[]'](0); + } return result.$push(value);}, -1); + return result; + }); - Opal.const_set($nesting[0], 'REGEXP_START', (function() {if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - return "^" - } else { - return nil - }; return nil; })()); - Opal.const_set($nesting[0], 'REGEXP_END', (function() {if ($$($nesting, 'RUBY_ENGINE')['$==']("opal")) { - return "$" - } else { - return nil - }; return nil; })()); - Opal.const_set($nesting[0], 'FORBIDDEN_STARTING_IDENTIFIER_CHARS', "\\u0001-\\u002F\\u003A-\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); - Opal.const_set($nesting[0], 'FORBIDDEN_ENDING_IDENTIFIER_CHARS', "\\u0001-\\u0020\\u0022-\\u002F\\u003A-\\u003E\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); - Opal.const_set($nesting[0], 'INLINE_IDENTIFIER_REGEXP', $$($nesting, 'Regexp').$new("" + "[^" + ($$($nesting, 'FORBIDDEN_STARTING_IDENTIFIER_CHARS')) + "]*[^" + ($$($nesting, 'FORBIDDEN_ENDING_IDENTIFIER_CHARS')) + "]")); - Opal.const_set($nesting[0], 'FORBIDDEN_CONST_NAME_CHARS', "\\u0001-\\u0020\\u0021-\\u002F\\u003B-\\u003F\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); - Opal.const_set($nesting[0], 'CONST_NAME_REGEXP', $$($nesting, 'Regexp').$new("" + ($$($nesting, 'REGEXP_START')) + "(::)?[A-Z][^" + ($$($nesting, 'FORBIDDEN_CONST_NAME_CHARS')) + "]*" + ($$($nesting, 'REGEXP_END')))); - })($nesting[0], $nesting) -}; + $def(self, '$group_by', function $$group_by() { + var block = $$group_by.$$p || nil, $a, self = this, hash = nil, $ret_or_1 = nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["opal/mini"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; - - Opal.add_stubs(['$require']); - - self.$require("opal/base"); - self.$require("corelib/nil"); - self.$require("corelib/boolean"); - self.$require("corelib/string"); - self.$require("corelib/comparable"); - self.$require("corelib/enumerable"); - self.$require("corelib/enumerator"); - self.$require("corelib/array"); - self.$require("corelib/hash"); - self.$require("corelib/number"); - self.$require("corelib/range"); - self.$require("corelib/proc"); - self.$require("corelib/method"); - self.$require("corelib/regexp"); - self.$require("corelib/variables"); - return self.$require("opal/regexp_anchors"); -}; + $$group_by.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["group_by"], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/string/encoding"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var $$11, $$14, $$17, $$20, $$23, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy, $send = Opal.send; + return self.$enumerator_size()}, {$$s: self}) + } hash = $hash2([], {}); - Opal.add_stubs(['$require', '$+', '$[]', '$new', '$to_proc', '$each', '$const_set', '$sub', '$==', '$default_external', '$upcase', '$raise', '$attr_accessor', '$attr_reader', '$register', '$length', '$bytes', '$to_a', '$each_byte', '$dup', '$bytesize', '$enum_for', '$coerce_to!', '$find', '$<']); - - self.$require("corelib/string"); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Encoding'); + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - var $nesting = [self].concat($parent_nesting), $Encoding_register$1, $Encoding_find$3, $Encoding_initialize$4, $Encoding_ascii_compatible$ques$5, $Encoding_dummy$ques$6, $Encoding_to_s$7, $Encoding_inspect$8, $Encoding_each_byte$9, $Encoding_bytesize$10; + ($truthy(($ret_or_1 = hash['$[]'](value))) ? ($ret_or_1) : (($a = [value, []], $send(hash, '[]=', $a), $a[$a.length - 1])))['$<<'](param); + }; - self.$$prototype.ascii = self.$$prototype.dummy = self.$$prototype.name = nil; + self.$each(); + return hash; + }); - Opal.defineProperty(self, '$$register', {}); - Opal.defs(self, '$register', $Encoding_register$1 = function $$register(name, options) { - var $iter = $Encoding_register$1.$$p, block = $iter || nil, $a, $$2, self = this, names = nil, encoding = nil, register = nil; + $def(self, '$include?', function $Enumerable_include$ques$32(obj) {try { var $t_return = $thrower('return'); + var self = this; - if ($iter) $Encoding_register$1.$$p = null; - - if ($iter) $Encoding_register$1.$$p = null;; - - if (options == null) { - options = $hash2([], {}); - }; - names = $rb_plus([name], ($truthy($a = options['$[]']("aliases")) ? $a : [])); - encoding = $send($$($nesting, 'Class'), 'new', [self], block.$to_proc()).$new(name, names, ($truthy($a = options['$[]']("ascii")) ? $a : false), ($truthy($a = options['$[]']("dummy")) ? $a : false)); - register = self["$$register"]; - return $send(names, 'each', [], ($$2 = function(encoding_name){var self = $$2.$$s || this; + $send(self, 'each', [], function $$33($a){var $post_args, args; - - if (encoding_name == null) { - encoding_name = nil; - }; - self.$const_set(encoding_name.$sub("-", "_"), encoding); - return register["" + "$$" + (encoding_name)] = encoding;}, $$2.$$s = self, $$2.$$arity = 1, $$2)); - }, $Encoding_register$1.$$arity = -2); - Opal.defs(self, '$find', $Encoding_find$3 = function $$find(name) { - var $a, self = this, register = nil, encoding = nil; - - - if (name['$==']("default_external")) { - return self.$default_external()}; - register = self["$$register"]; - encoding = ($truthy($a = register["" + "$$" + (name)]) ? $a : register["" + "$$" + (name.$upcase())]); - if ($truthy(encoding)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "unknown encoding name - " + (name)) - }; - return encoding; - }, $Encoding_find$3.$$arity = 1); - (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting); - - return self.$attr_accessor("default_external") - })(Opal.get_singleton_class(self), $nesting); - self.$attr_reader("name", "names"); + $post_args = $slice(arguments); + args = $post_args; + if ($eqeq($Opal.$destructure(args), obj)) { + $t_return.$throw(true); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + return false;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }); - Opal.def(self, '$initialize', $Encoding_initialize$4 = function $$initialize(name, names, ascii, dummy) { - var self = this; + $def(self, '$inject', function $$inject(object, sym) { + var block = $$inject.$$p || nil, self = this; + $$inject.$$p = null; - self.name = name; - self.names = names; - self.ascii = ascii; - return (self.dummy = dummy); - }, $Encoding_initialize$4.$$arity = 4); - - Opal.def(self, '$ascii_compatible?', $Encoding_ascii_compatible$ques$5 = function() { - var self = this; + var result = object; - return self.ascii - }, $Encoding_ascii_compatible$ques$5.$$arity = 0); - - Opal.def(self, '$dummy?', $Encoding_dummy$ques$6 = function() { - var self = this; + if (block !== nil && sym === undefined) { + self.$each.$$p = function() { + var value = $Opal.$destructure(arguments); - return self.dummy - }, $Encoding_dummy$ques$6.$$arity = 0); - - Opal.def(self, '$to_s', $Encoding_to_s$7 = function $$to_s() { - var self = this; + if (result === undefined) { + result = value; + return; + } - return self.name - }, $Encoding_to_s$7.$$arity = 0); - - Opal.def(self, '$inspect', $Encoding_inspect$8 = function $$inspect() { - var self = this; + value = $yieldX(block, [result, value]); - return "" + "#<Encoding:" + (self.name) + ((function() {if ($truthy(self.dummy)) { - return " (dummy)" - } else { - return nil - }; return nil; })()) + ">" - }, $Encoding_inspect$8.$$arity = 0); - - Opal.def(self, '$each_byte', $Encoding_each_byte$9 = function $$each_byte($a) { - var $post_args, self = this; + result = value; + }; + } + else { + if (sym === undefined) { + if (!$$$('Symbol')['$==='](object)) { + $Kernel.$raise($$$('TypeError'), "" + (object.$inspect()) + " is not a Symbol"); + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError')); - }, $Encoding_each_byte$9.$$arity = -1); - - Opal.def(self, '$bytesize', $Encoding_bytesize$10 = function $$bytesize($a) { - var $post_args, self = this; + sym = object; + result = undefined; + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError')); - }, $Encoding_bytesize$10.$$arity = -1); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'EncodingError'); + self.$each.$$p = function() { + var value = $Opal.$destructure(arguments); - var $nesting = [self].concat($parent_nesting); + if (result === undefined) { + result = value; + return; + } - return nil - })($nesting[0], $$($nesting, 'StandardError'), $nesting); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'CompatibilityError'); + result = (result).$__send__(sym, value); + }; + } - var $nesting = [self].concat($parent_nesting); + self.$each(); - return nil - })($nesting[0], $$($nesting, 'EncodingError'), $nesting); - })($nesting[0], null, $nesting); - $send($$($nesting, 'Encoding'), 'register', ["UTF-8", $hash2(["aliases", "ascii"], {"aliases": ["CP65001"], "ascii": true})], ($$11 = function(){var self = $$11.$$s || this, $each_byte$12, $bytesize$13; + return result == undefined ? nil : result; + }, -1); + + $def(self, '$lazy', function $$lazy() { + var self = this; - + return $send($$$($$$('Enumerator'), 'Lazy'), 'new', [self, self.$enumerator_size()], function $$34(enum$, $a){var $post_args, args; + + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + return $send(enum$, 'yield', $to_a(args));}, -2) + }); - Opal.def(self, '$each_byte', $each_byte$12 = function $$each_byte(string) { - var $iter = $each_byte$12.$$p, block = $iter || nil, self = this; + $def(self, '$enumerator_size', function $$enumerator_size() { + var self = this; - if ($iter) $each_byte$12.$$p = null; - - - if ($iter) $each_byte$12.$$p = null;; - - var units = Infinity - var codePoint - var length = string.length - var leadSurrogate = null + if ($truthy(self['$respond_to?']("size"))) { + return self.$size() + } else { + return nil + } + }); + + $def(self, '$max', function $$max(n) { + var block = $$max.$$p || nil, self = this; - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i) + $$max.$$p = null; + + if (n === undefined || n === nil) { + var result, value; - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) { - Opal.yield1(block, 0xEF); - Opal.yield1(block, 0xBF); - Opal.yield1(block, 0xBD); - } - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) { - Opal.yield1(block, 0xEF); - Opal.yield1(block, 0xBF); - Opal.yield1(block, 0xBD); - } - continue - } + self.$each.$$p = function() { + var item = $Opal.$destructure(arguments); - // valid lead - leadSurrogate = codePoint + if (result === undefined) { + result = item; + return; + } - continue + if (block !== nil) { + value = $yieldX(block, [item, result]); + } else { + value = (item)['$<=>'](result); } - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) { - Opal.yield1(block, 0xEF); - Opal.yield1(block, 0xBF); - Opal.yield1(block, 0xBD); - } - leadSurrogate = codePoint - continue + if (value === nil) { + $Kernel.$raise($$$('ArgumentError'), "comparison failed"); } - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) { - Opal.yield1(block, 0xEF); - Opal.yield1(block, 0xBF); - Opal.yield1(block, 0xBD); + if (value > 0) { + result = item; } - } + }; - leadSurrogate = null + self.$each(); - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - Opal.yield1(block, codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - Opal.yield1(block, codePoint >> 0x6 | 0xC0); - Opal.yield1(block, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - Opal.yield1(block, codePoint >> 0xC | 0xE0); - Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80); - Opal.yield1(block, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - Opal.yield1(block, codePoint >> 0x12 | 0xF0); - Opal.yield1(block, codePoint >> 0xC & 0x3F | 0x80); - Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80); - Opal.yield1(block, codePoint & 0x3F | 0x80); + if (result === undefined) { + return nil; } else { - // Invalid code point + return result; } } - ; - }, $each_byte$12.$$arity = 1); - return (Opal.def(self, '$bytesize', $bytesize$13 = function $$bytesize(string) { - var self = this; - - return string.$bytes().$length() - }, $bytesize$13.$$arity = 1), nil) && 'bytesize';}, $$11.$$s = self, $$11.$$arity = 0, $$11)); - $send($$($nesting, 'Encoding'), 'register', ["UTF-16LE"], ($$14 = function(){var self = $$14.$$s || this, $each_byte$15, $bytesize$16; - + n = $coerce_to(n, $$$('Integer'), 'to_int'); + return $send(self, 'sort', [], block.$to_proc()).$reverse().$first(n); + }, -1); - Opal.def(self, '$each_byte', $each_byte$15 = function $$each_byte(string) { - var $iter = $each_byte$15.$$p, block = $iter || nil, self = this; - - if ($iter) $each_byte$15.$$p = null; - - - if ($iter) $each_byte$15.$$p = null;; - - for (var i = 0, length = string.length; i < length; i++) { - var code = string.charCodeAt(i); + $def(self, '$max_by', function $$max_by(n) { + var block = $$max_by.$$p || nil, self = this; - Opal.yield1(block, code & 0xff); - Opal.yield1(block, code >> 8); - } - ; - }, $each_byte$15.$$arity = 1); - return (Opal.def(self, '$bytesize', $bytesize$16 = function $$bytesize(string) { - var self = this; + $$max_by.$$p = null; + if (n == null) n = nil; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["max_by", n], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s; - return string.$bytes().$length() - }, $bytesize$16.$$arity = 1), nil) && 'bytesize';}, $$14.$$s = self, $$14.$$arity = 0, $$14)); - $send($$($nesting, 'Encoding'), 'register', ["UTF-16BE"], ($$17 = function(){var self = $$17.$$s || this, $each_byte$18, $bytesize$19; + return self.$enumerator_size()}, {$$s: self}) + } if (!$truthy(n['$nil?']())) { + return $send(self, 'sort_by', [], block.$to_proc()).$reverse().$take(n) + } + var result, + by; - - - Opal.def(self, '$each_byte', $each_byte$18 = function $$each_byte(string) { - var $iter = $each_byte$18.$$p, block = $iter || nil, self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - if ($iter) $each_byte$18.$$p = null; - - - if ($iter) $each_byte$18.$$p = null;; - - for (var i = 0, length = string.length; i < length; i++) { - var code = string.charCodeAt(i); + if (result === undefined) { + result = param; + by = value; + return; + } - Opal.yield1(block, code >> 8); - Opal.yield1(block, code & 0xff); - } - ; - }, $each_byte$18.$$arity = 1); - return (Opal.def(self, '$bytesize', $bytesize$19 = function $$bytesize(string) { - var self = this; + if ((value)['$<=>'](by) > 0) { + result = param; + by = value; + } + }; - return string.$bytes().$length() - }, $bytesize$19.$$arity = 1), nil) && 'bytesize';}, $$17.$$s = self, $$17.$$arity = 0, $$17)); - $send($$($nesting, 'Encoding'), 'register', ["UTF-32LE"], ($$20 = function(){var self = $$20.$$s || this, $each_byte$21, $bytesize$22; + self.$each(); - + return result === undefined ? nil : result; + }, -1); - Opal.def(self, '$each_byte', $each_byte$21 = function $$each_byte(string) { - var $iter = $each_byte$21.$$p, block = $iter || nil, self = this; + $def(self, '$min', function $$min(n) { + var block = $$min.$$p || nil, self = this; - if ($iter) $each_byte$21.$$p = null; - - - if ($iter) $each_byte$21.$$p = null;; - - for (var i = 0, length = string.length; i < length; i++) { - var code = string.charCodeAt(i); + $$min.$$p = null; + if (n == null) n = nil; + if (!$truthy(n['$nil?']())) { + if ((block !== nil)) { + return $send(self, 'sort', [], function $$36(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return Opal.yieldX(block, [a, b]);}).$take(n) + } else { + return self.$sort().$take(n) + } + } + var result; - Opal.yield1(block, code & 0xff); - Opal.yield1(block, code >> 8); - } - ; - }, $each_byte$21.$$arity = 1); - return (Opal.def(self, '$bytesize', $bytesize$22 = function $$bytesize(string) { - var self = this; + if (block !== nil) { + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - return string.$bytes().$length() - }, $bytesize$22.$$arity = 1), nil) && 'bytesize';}, $$20.$$s = self, $$20.$$arity = 0, $$20)); - $send($$($nesting, 'Encoding'), 'register', ["ASCII-8BIT", $hash2(["aliases", "ascii", "dummy"], {"aliases": ["BINARY", "US-ASCII", "ASCII"], "ascii": true, "dummy": true})], ($$23 = function(){var self = $$23.$$s || this, $each_byte$24, $bytesize$25; + if (result === undefined) { + result = param; + return; + } - - - Opal.def(self, '$each_byte', $each_byte$24 = function $$each_byte(string) { - var $iter = $each_byte$24.$$p, block = $iter || nil, self = this; + var value = block(param, result); - if ($iter) $each_byte$24.$$p = null; - - - if ($iter) $each_byte$24.$$p = null;; - - for (var i = 0, length = string.length; i < length; i++) { - var code = string.charCodeAt(i); - Opal.yield1(block, code & 0xff); - Opal.yield1(block, code >> 8); + if (value === nil) { + $Kernel.$raise($$$('ArgumentError'), "comparison failed"); + } + + if (value < 0) { + result = param; + } + }; } - ; - }, $each_byte$24.$$arity = 1); - return (Opal.def(self, '$bytesize', $bytesize$25 = function $$bytesize(string) { - var self = this; + else { + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); - return string.$bytes().$length() - }, $bytesize$25.$$arity = 1), nil) && 'bytesize';}, $$23.$$s = self, $$23.$$arity = 0, $$23)); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'String'); + if (result === undefined) { + result = param; + return; + } - var $nesting = [self].concat($parent_nesting), $String_bytes$26, $String_bytesize$27, $String_each_byte$28, $String_encode$29, $String_force_encoding$30, $String_getbyte$31, $String_valid_encoding$ques$32; + if ($Opal.$compare(param, result) < 0) { + result = param; + } + }; + } - self.$$prototype.bytes = self.$$prototype.internal_encoding = nil; - - self.$attr_reader("encoding"); - self.$attr_reader("internal_encoding"); - Opal.defineProperty(String.prototype, 'bytes', nil); - Opal.defineProperty(String.prototype, 'encoding', $$$($$($nesting, 'Encoding'), 'UTF_8')); - Opal.defineProperty(String.prototype, 'internal_encoding', $$$($$($nesting, 'Encoding'), 'UTF_8')); - - Opal.def(self, '$bytes', $String_bytes$26 = function $$bytes() { - var $a, self = this; + self.$each(); - - self.bytes = ($truthy($a = self.bytes) ? $a : self.$each_byte().$to_a()); - return self.bytes.$dup(); - }, $String_bytes$26.$$arity = 0); + return result === undefined ? nil : result; + }, -1); - Opal.def(self, '$bytesize', $String_bytesize$27 = function $$bytesize() { - var self = this; + $def(self, '$min_by', function $$min_by(n) { + var block = $$min_by.$$p || nil, self = this; - return self.internal_encoding.$bytesize(self) - }, $String_bytesize$27.$$arity = 0); - - Opal.def(self, '$each_byte', $String_each_byte$28 = function $$each_byte() { - var $iter = $String_each_byte$28.$$p, block = $iter || nil, self = this; + $$min_by.$$p = null; + if (n == null) n = nil; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["min_by", n], function $$37(){var self = $$37.$$s == null ? this : $$37.$$s; - if ($iter) $String_each_byte$28.$$p = null; - - - if ($iter) $String_each_byte$28.$$p = null;; - if ((block !== nil)) { - } else { - return self.$enum_for("each_byte") - }; - $send(self.internal_encoding, 'each_byte', [self], block.$to_proc()); - return self; - }, $String_each_byte$28.$$arity = 0); - - Opal.def(self, '$encode', $String_encode$29 = function $$encode(encoding) { - var self = this; + return self.$enumerator_size()}, {$$s: self}) + } if (!$truthy(n['$nil?']())) { + return $send(self, 'sort_by', [], block.$to_proc()).$take(n) + } + var result, + by; - return Opal.enc(self, encoding); - }, $String_encode$29.$$arity = 1); - - Opal.def(self, '$force_encoding', $String_force_encoding$30 = function $$force_encoding(encoding) { - var self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - - if (encoding === self.encoding) { return self; } + if (result === undefined) { + result = param; + by = value; + return; + } - encoding = $$($nesting, 'Opal')['$coerce_to!'](encoding, $$($nesting, 'String'), "to_s"); - encoding = $$($nesting, 'Encoding').$find(encoding); + if ((value)['$<=>'](by) < 0) { + result = param; + by = value; + } + }; - if (encoding === self.encoding) { return self; } + self.$each(); - self.encoding = encoding; - return self; - - }, $String_force_encoding$30.$$arity = 1); + return result === undefined ? nil : result; + }, -1); - Opal.def(self, '$getbyte', $String_getbyte$31 = function $$getbyte(idx) { - var self = this, string_bytes = nil; + $def(self, '$minmax', function $$minmax() { + var block = $$minmax.$$p || nil, self = this, $ret_or_1 = nil; + $$minmax.$$p = null; + block = ($truthy(($ret_or_1 = block)) ? ($ret_or_1) : ($send($Kernel, 'proc', [], function $$38(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$<=>'](b);}))); - string_bytes = self.$bytes(); - idx = $$($nesting, 'Opal')['$coerce_to!'](idx, $$($nesting, 'Integer'), "to_int"); - if ($truthy($rb_lt(string_bytes.$length(), idx))) { - return nil}; - return string_bytes['$[]'](idx); - }, $String_getbyte$31.$$arity = 1); - return (Opal.def(self, '$valid_encoding?', $String_valid_encoding$ques$32 = function() { - var self = this; + var min = nil, max = nil, first_time = true; - return true - }, $String_valid_encoding$ques$32.$$arity = 0), nil) && 'valid_encoding?'; - })($nesting[0], null, $nesting); -}; + self.$each.$$p = function() { + var element = $Opal.$destructure(arguments); + if (first_time) { + min = max = element; + first_time = false; + } else { + var min_cmp = block.$call(min, element); -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/struct"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy, $send = Opal.send; + if (min_cmp === nil) { + $Kernel.$raise($$$('ArgumentError'), "comparison failed"); + } else if (min_cmp > 0) { + min = element; + } - Opal.add_stubs(['$require', '$include', '$const_name!', '$unshift', '$map', '$coerce_to!', '$new', '$each', '$define_struct_attribute', '$allocate', '$initialize', '$alias_method', '$module_eval', '$to_proc', '$const_set', '$==', '$raise', '$<<', '$members', '$define_method', '$instance_eval', '$class', '$last', '$>', '$length', '$-', '$keys', '$any?', '$join', '$[]', '$[]=', '$each_with_index', '$hash', '$===', '$<', '$-@', '$size', '$>=', '$include?', '$to_sym', '$instance_of?', '$__id__', '$eql?', '$enum_for', '$name', '$+', '$each_pair', '$inspect', '$each_with_object', '$flatten', '$to_a', '$respond_to?', '$dig']); - - self.$require("corelib/enumerable"); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Struct'); + var max_cmp = block.$call(max, element); - var $nesting = [self].concat($parent_nesting), $Struct_new$1, $Struct_define_struct_attribute$6, $Struct_members$9, $Struct_inherited$10, $Struct_initialize$12, $Struct_members$15, $Struct_hash$16, $Struct_$$$17, $Struct_$$$eq$18, $Struct_$eq_eq$19, $Struct_eql$ques$20, $Struct_each$21, $Struct_each_pair$24, $Struct_length$27, $Struct_to_a$28, $Struct_inspect$30, $Struct_to_h$32, $Struct_values_at$34, $Struct_dig$36; + if (max_cmp === nil) { + $Kernel.$raise($$$('ArgumentError'), "comparison failed"); + } else if (max_cmp < 0) { + max = element; + } + } + }; - - self.$include($$($nesting, 'Enumerable')); - Opal.defs(self, '$new', $Struct_new$1 = function(const_name, $a, $b) { - var $iter = $Struct_new$1.$$p, block = $iter || nil, $post_args, $kwargs, args, keyword_init, $$2, $$3, self = this, klass = nil; + self.$each(); - if ($iter) $Struct_new$1.$$p = null; - - - if ($iter) $Struct_new$1.$$p = null;; - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - $kwargs = Opal.extract_kwargs($post_args); - - if ($kwargs == null) { - $kwargs = $hash2([], {}); - } else if (!$kwargs.$$is_hash) { - throw Opal.ArgumentError.$new('expected kwargs'); - }; - - args = $post_args;; - - keyword_init = $kwargs.$$smap["keyword_init"]; - if (keyword_init == null) { - keyword_init = false - }; - if ($truthy(const_name)) { - - try { - const_name = $$($nesting, 'Opal')['$const_name!'](const_name) - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'TypeError'), $$($nesting, 'NameError')])) { - try { - - args.$unshift(const_name); - const_name = nil; - } finally { Opal.pop_exception() } - } else { throw $err; } - };}; - $send(args, 'map', [], ($$2 = function(arg){var self = $$2.$$s || this; + return [min, max]; + }); + + $def(self, '$minmax_by', function $$minmax_by() { + var block = $$minmax_by.$$p || nil, self = this; - - - if (arg == null) { - arg = nil; - }; - return $$($nesting, 'Opal')['$coerce_to!'](arg, $$($nesting, 'String'), "to_str");}, $$2.$$s = self, $$2.$$arity = 1, $$2)); - klass = $send($$($nesting, 'Class'), 'new', [self], ($$3 = function(){var self = $$3.$$s || this, $$4; + $$minmax_by.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["minmax_by"], function $$39(){var self = $$39.$$s == null ? this : $$39.$$s; - - $send(args, 'each', [], ($$4 = function(arg){var self = $$4.$$s || this; + return self.$enumerator_size()}, {$$s: self}) + } + var min_result = nil, + max_result = nil, + min_by, + max_by; - - - if (arg == null) { - arg = nil; - }; - return self.$define_struct_attribute(arg);}, $$4.$$s = self, $$4.$$arity = 1, $$4)); - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $new$5; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - - - Opal.def(self, '$new', $new$5 = function($a) { - var $post_args, args, self = this, instance = nil; + if ((min_by === undefined) || (value)['$<=>'](min_by) < 0) { + min_result = param; + min_by = value; + } - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - instance = self.$allocate(); - instance.$$data = {}; - $send(instance, 'initialize', Opal.to_a(args)); - return instance; - }, $new$5.$$arity = -1); - return self.$alias_method("[]", "new"); - })(Opal.get_singleton_class(self), $nesting);}, $$3.$$s = self, $$3.$$arity = 0, $$3)); - if ($truthy(block)) { - $send(klass, 'module_eval', [], block.$to_proc())}; - klass.$$keyword_init = keyword_init; - if ($truthy(const_name)) { - $$($nesting, 'Struct').$const_set(const_name, klass)}; - return klass; - }, $Struct_new$1.$$arity = -2); - Opal.defs(self, '$define_struct_attribute', $Struct_define_struct_attribute$6 = function $$define_struct_attribute(name) { - var $$7, $$8, self = this; + if ((max_by === undefined) || (value)['$<=>'](max_by) > 0) { + max_result = param; + max_by = value; + } + }; - - if (self['$==']($$($nesting, 'Struct'))) { - self.$raise($$($nesting, 'ArgumentError'), "you cannot define attributes to the Struct class")}; - self.$members()['$<<'](name); - $send(self, 'define_method', [name], ($$7 = function(){var self = $$7.$$s || this; + self.$each(); - return self.$$data[name];}, $$7.$$s = self, $$7.$$arity = 0, $$7)); - return $send(self, 'define_method', ["" + (name) + "="], ($$8 = function(value){var self = $$8.$$s || this; + return [min_result, max_result]; + }); + + $def(self, '$none?', function $Enumerable_none$ques$40(pattern) {try { var $t_return = $thrower('return'); + var block = $Enumerable_none$ques$40.$$p || nil, self = this; + $Enumerable_none$ques$40.$$p = null; - - if (value == null) { - value = nil; - }; - return self.$$data[name] = value;;}, $$8.$$s = self, $$8.$$arity = 1, $$8)); - }, $Struct_define_struct_attribute$6.$$arity = 1); - Opal.defs(self, '$members', $Struct_members$9 = function $$members() { - var $a, self = this; - if (self.members == null) self.members = nil; + ; + ; + if ($truthy(pattern !== undefined)) { + $send(self, 'each', [], function $$41($a){var $post_args, value, comparable = nil; - - if (self['$==']($$($nesting, 'Struct'))) { - self.$raise($$($nesting, 'ArgumentError'), "the Struct class has no members")}; - return (self.members = ($truthy($a = self.members) ? $a : [])); - }, $Struct_members$9.$$arity = 0); - Opal.defs(self, '$inherited', $Struct_inherited$10 = function $$inherited(klass) { - var $$11, self = this, members = nil; - if (self.members == null) self.members = nil; + + $post_args = $slice(arguments); + value = $post_args; + comparable = comparableForPattern(value); + if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) { + $t_return.$throw(false); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else if ((block !== nil)) { + $send(self, 'each', [], function $$42($a){var $post_args, value; - - members = self.members; - return $send(klass, 'instance_eval', [], ($$11 = function(){var self = $$11.$$s || this; + + $post_args = $slice(arguments); + value = $post_args; + if ($truthy(Opal.yieldX(block, $to_a(value)))) { + $t_return.$throw(false); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else { + $send(self, 'each', [], function $$43($a){var $post_args, value, item = nil; - return (self.members = members)}, $$11.$$s = self, $$11.$$arity = 0, $$11)); - }, $Struct_inherited$10.$$arity = 1); + + $post_args = $slice(arguments); + value = $post_args; + item = $Opal.$destructure(value); + if ($truthy(item)) { + $t_return.$throw(false); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + }; + return true;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); - Opal.def(self, '$initialize', $Struct_initialize$12 = function $$initialize($a) { - var $post_args, args, $b, $$13, $$14, self = this, kwargs = nil, extra = nil; + $def(self, '$one?', function $Enumerable_one$ques$44(pattern) {try { var $t_return = $thrower('return'); + var block = $Enumerable_one$ques$44.$$p || nil, self = this, count = nil; + $Enumerable_one$ques$44.$$p = null; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(self.$class().$$keyword_init)) { - - kwargs = ($truthy($b = args.$last()) ? $b : $hash2([], {})); - if ($truthy(($truthy($b = $rb_gt(args.$length(), 1)) ? $b : (args.length === 1 && !kwargs.$$is_hash)))) { - self.$raise($$($nesting, 'ArgumentError'), "" + "wrong number of arguments (given " + (args.$length()) + ", expected 0)")}; - extra = $rb_minus(kwargs.$keys(), self.$class().$members()); - if ($truthy(extra['$any?']())) { - self.$raise($$($nesting, 'ArgumentError'), "" + "unknown keywords: " + (extra.$join(", ")))}; - return $send(self.$class().$members(), 'each', [], ($$13 = function(name){var self = $$13.$$s || this, $writer = nil; + ; + ; + count = 0; + if ($truthy(pattern !== undefined)) { + $send(self, 'each', [], function $$45($a){var $post_args, value, comparable = nil; - - if (name == null) { - name = nil; - }; - $writer = [name, kwargs['$[]'](name)]; - $send(self, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$13.$$s = self, $$13.$$arity = 1, $$13)); - } else { - - if ($truthy($rb_gt(args.$length(), self.$class().$members().$length()))) { - self.$raise($$($nesting, 'ArgumentError'), "struct size differs")}; - return $send(self.$class().$members(), 'each_with_index', [], ($$14 = function(name, index){var self = $$14.$$s || this, $writer = nil; + $post_args = $slice(arguments); + value = $post_args; + comparable = comparableForPattern(value); + if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) { + + count = $rb_plus(count, 1); + if ($truthy($rb_gt(count, 1))) { + $t_return.$throw(false); + } else { + return nil + }; + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else if ((block !== nil)) { + $send(self, 'each', [], function $$46($a){var $post_args, value; - - if (name == null) { - name = nil; + $post_args = $slice(arguments); + value = $post_args; + if (!$truthy(Opal.yieldX(block, $to_a(value)))) { + return nil }; + count = $rb_plus(count, 1); + if ($truthy($rb_gt(count, 1))) { + $t_return.$throw(false); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); + } else { + $send(self, 'each', [], function $$47($a){var $post_args, value; + - if (index == null) { - index = nil; + $post_args = $slice(arguments); + value = $post_args; + if (!$truthy($Opal.$destructure(value))) { + return nil }; - $writer = [name, args['$[]'](index)]; - $send(self, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$14.$$s = self, $$14.$$arity = 2, $$14)); + count = $rb_plus(count, 1); + if ($truthy($rb_gt(count, 1))) { + $t_return.$throw(false); + } else { + return nil + };}, {$$arity: -1, $$ret: $t_return}); }; - }, $Struct_initialize$12.$$arity = -1); + return count['$=='](1);} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); - Opal.def(self, '$members', $Struct_members$15 = function $$members() { - var self = this; + $def(self, '$partition', function $$partition() { + var block = $$partition.$$p || nil, self = this; - return self.$class().$members() - }, $Struct_members$15.$$arity = 0); - - Opal.def(self, '$hash', $Struct_hash$16 = function $$hash() { - var self = this; + $$partition.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["partition"], function $$48(){var self = $$48.$$s == null ? this : $$48.$$s; - return $$($nesting, 'Hash').$new(self.$$data).$hash() - }, $Struct_hash$16.$$arity = 0); - - Opal.def(self, '$[]', $Struct_$$$17 = function(name) { - var self = this; + return self.$enumerator_size()}, {$$s: self}) + } + var truthy = [], falsy = []; - - if ($truthy($$($nesting, 'Integer')['$==='](name))) { - - if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) { - self.$raise($$($nesting, 'IndexError'), "" + "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")")}; - if ($truthy($rb_ge(name, self.$class().$members().$size()))) { - self.$raise($$($nesting, 'IndexError'), "" + "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")")}; - name = self.$class().$members()['$[]'](name); - } else if ($truthy($$($nesting, 'String')['$==='](name))) { - - if(!self.$$data.hasOwnProperty(name)) { - self.$raise($$($nesting, 'NameError').$new("" + "no member '" + (name) + "' in struct", name)) - } - - } else { - self.$raise($$($nesting, 'TypeError'), "" + "no implicit conversion of " + (name.$class()) + " into Integer") - }; - name = $$($nesting, 'Opal')['$coerce_to!'](name, $$($nesting, 'String'), "to_str"); - return self.$$data[name];; - }, $Struct_$$$17.$$arity = 1); - - Opal.def(self, '$[]=', $Struct_$$$eq$18 = function(name, value) { - var self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - - if ($truthy($$($nesting, 'Integer')['$==='](name))) { - - if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) { - self.$raise($$($nesting, 'IndexError'), "" + "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")")}; - if ($truthy($rb_ge(name, self.$class().$members().$size()))) { - self.$raise($$($nesting, 'IndexError'), "" + "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")")}; - name = self.$class().$members()['$[]'](name); - } else if ($truthy($$($nesting, 'String')['$==='](name))) { - if ($truthy(self.$class().$members()['$include?'](name.$to_sym()))) { - } else { - self.$raise($$($nesting, 'NameError').$new("" + "no member '" + (name) + "' in struct", name)) + if ($truthy(value)) { + truthy.push(param); + } + else { + falsy.push(param); } - } else { - self.$raise($$($nesting, 'TypeError'), "" + "no implicit conversion of " + (name.$class()) + " into Integer") }; - name = $$($nesting, 'Opal')['$coerce_to!'](name, $$($nesting, 'String'), "to_str"); - return self.$$data[name] = value;; - }, $Struct_$$$eq$18.$$arity = 2); - - Opal.def(self, '$==', $Struct_$eq_eq$19 = function(other) { - var self = this; - - if ($truthy(other['$instance_of?'](self.$class()))) { - } else { - return false - }; - - var recursed1 = {}, recursed2 = {}; + self.$each(); - function _eqeq(struct, other) { - var key, a, b; + return [truthy, falsy]; + }); + + $def(self, '$reject', function $$reject() { + var block = $$reject.$$p || nil, self = this; - recursed1[(struct).$__id__()] = true; - recursed2[(other).$__id__()] = true; + $$reject.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["reject"], function $$49(){var self = $$49.$$s == null ? this : $$49.$$s; - for (key in struct.$$data) { - a = struct.$$data[key]; - b = other.$$data[key]; + return self.$enumerator_size()}, {$$s: self}) + } + var result = []; - if ($$($nesting, 'Struct')['$==='](a)) { - if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) { - if (!_eqeq(a, b)) { - return false; - } - } - } else { - if (!(a)['$=='](b)) { - return false; - } - } + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); + + if (!$truthy(value)) { + result.push(param); } + }; - return true; - } + self.$each(); - return _eqeq(self, other); - ; - }, $Struct_$eq_eq$19.$$arity = 1); + return result; + }); - Opal.def(self, '$eql?', $Struct_eql$ques$20 = function(other) { - var self = this; - - - if ($truthy(other['$instance_of?'](self.$class()))) { - } else { - return false - }; - - var recursed1 = {}, recursed2 = {}; + $def(self, '$reverse_each', function $$reverse_each() { + var block = $$reverse_each.$$p || nil, self = this; - function _eqeq(struct, other) { - var key, a, b; + $$reverse_each.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["reverse_each"], function $$50(){var self = $$50.$$s == null ? this : $$50.$$s; - recursed1[(struct).$__id__()] = true; - recursed2[(other).$__id__()] = true; + return self.$enumerator_size()}, {$$s: self}) + } + var result = []; - for (key in struct.$$data) { - a = struct.$$data[key]; - b = other.$$data[key]; + self.$each.$$p = function() { + result.push(arguments); + }; - if ($$($nesting, 'Struct')['$==='](a)) { - if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) { - if (!_eqeq(a, b)) { - return false; - } - } - } else { - if (!(a)['$eql?'](b)) { - return false; - } - } - } + self.$each(); - return true; + for (var i = result.length - 1; i >= 0; i--) { + $yieldX(block, result[i]); } - return _eqeq(self, other); - ; - }, $Struct_eql$ques$20.$$arity = 1); + return result; + }); - Opal.def(self, '$each', $Struct_each$21 = function $$each() { - var $$22, $$23, $iter = $Struct_each$21.$$p, $yield = $iter || nil, self = this; - - if ($iter) $Struct_each$21.$$p = null; - - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["each"], ($$22 = function(){var self = $$22.$$s || this; + $def(self, '$slice_before', function $$slice_before(pattern) { + var block = $$slice_before.$$p || nil, self = this; - return self.$size()}, $$22.$$s = self, $$22.$$arity = 0, $$22)) - }; - $send(self.$class().$members(), 'each', [], ($$23 = function(name){var self = $$23.$$s || this; + $$slice_before.$$p = null; + if ($truthy(pattern === undefined && block === nil)) { + $Kernel.$raise($$$('ArgumentError'), "both pattern and block are given"); + } if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " expected 1)"); + } return $send($$$('Enumerator'), 'new', [], function $$51(e){var self = $$51.$$s == null ? this : $$51.$$s; - - if (name == null) { - name = nil; - }; - return Opal.yield1($yield, self['$[]'](name));;}, $$23.$$s = self, $$23.$$arity = 1, $$23)); - return self; - }, $Struct_each$21.$$arity = 0); - - Opal.def(self, '$each_pair', $Struct_each_pair$24 = function $$each_pair() { - var $$25, $$26, $iter = $Struct_each_pair$24.$$p, $yield = $iter || nil, self = this; + if (e == null) e = nil; + + var slice = []; - if ($iter) $Struct_each_pair$24.$$p = null; - - if (($yield !== nil)) { - } else { - return $send(self, 'enum_for', ["each_pair"], ($$25 = function(){var self = $$25.$$s || this; + if (block !== nil) { + if (pattern === undefined) { + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = $yield1(block, param); - return self.$size()}, $$25.$$s = self, $$25.$$arity = 0, $$25)) - }; - $send(self.$class().$members(), 'each', [], ($$26 = function(name){var self = $$26.$$s || this; + if ($truthy(value) && slice.length > 0) { + e['$<<'](slice); + slice = []; + } - - - if (name == null) { - name = nil; - }; - return Opal.yield1($yield, [name, self['$[]'](name)]);;}, $$26.$$s = self, $$26.$$arity = 1, $$26)); - return self; - }, $Struct_each_pair$24.$$arity = 0); - - Opal.def(self, '$length', $Struct_length$27 = function $$length() { - var self = this; + slice.push(param); + }; + } + else { + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = block(param, pattern.$dup()); - return self.$class().$members().$length() - }, $Struct_length$27.$$arity = 0); - Opal.alias(self, "size", "length"); - - Opal.def(self, '$to_a', $Struct_to_a$28 = function $$to_a() { - var $$29, self = this; + if ($truthy(value) && slice.length > 0) { + e['$<<'](slice); + slice = []; + } + + slice.push(param); + }; + } + } + else { + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = pattern['$==='](param); - return $send(self.$class().$members(), 'map', [], ($$29 = function(name){var self = $$29.$$s || this; + if ($truthy(value) && slice.length > 0) { + e['$<<'](slice); + slice = []; + } - - - if (name == null) { - name = nil; - }; - return self['$[]'](name);}, $$29.$$s = self, $$29.$$arity = 1, $$29)) - }, $Struct_to_a$28.$$arity = 0); - Opal.alias(self, "values", "to_a"); - - Opal.def(self, '$inspect', $Struct_inspect$30 = function $$inspect() { - var $a, $$31, self = this, result = nil; + slice.push(param); + }; + } - - result = "#<struct "; - if ($truthy(($truthy($a = $$($nesting, 'Struct')['$==='](self)) ? self.$class().$name() : $a))) { - result = $rb_plus(result, "" + (self.$class()) + " ")}; - result = $rb_plus(result, $send(self.$each_pair(), 'map', [], ($$31 = function(name, value){var self = $$31.$$s || this; + self.$each(); - - - if (name == null) { - name = nil; - }; - - if (value == null) { - value = nil; - }; - return "" + (name) + "=" + (value.$inspect());}, $$31.$$s = self, $$31.$$arity = 2, $$31)).$join(", ")); - result = $rb_plus(result, ">"); - return result; - }, $Struct_inspect$30.$$arity = 0); - Opal.alias(self, "to_s", "inspect"); + if (slice.length > 0) { + e['$<<'](slice); + } +}, {$$s: self}); + }, -1); - Opal.def(self, '$to_h', $Struct_to_h$32 = function $$to_h() { - var $$33, self = this; + $def(self, '$slice_after', function $$slice_after(pattern) { + var block = $$slice_after.$$p || nil, self = this; - return $send(self.$class().$members(), 'each_with_object', [$hash2([], {})], ($$33 = function(name, h){var self = $$33.$$s || this, $writer = nil; + $$slice_after.$$p = null; + if ($truthy(pattern === undefined && block === nil)) { + $Kernel.$raise($$$('ArgumentError'), "both pattern and block are given"); + } if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " expected 1)"); + } if ($truthy(pattern !== undefined)) { + block = $send($Kernel, 'proc', [], function $$52(e){ + + if (e == null) e = nil; + return pattern['$==='](e);}); + } return $send($$$('Enumerator'), 'new', [], function $$53(yielder){var self = $$53.$$s == null ? this : $$53.$$s; - - if (name == null) { - name = nil; - }; + if (yielder == null) yielder = nil; - if (h == null) { - h = nil; - }; - $writer = [name, self['$[]'](name)]; - $send(h, '[]=', Opal.to_a($writer)); - return $writer[$rb_minus($writer["length"], 1)];}, $$33.$$s = self, $$33.$$arity = 2, $$33)) - }, $Struct_to_h$32.$$arity = 0); - - Opal.def(self, '$values_at', $Struct_values_at$34 = function $$values_at($a) { - var $post_args, args, $$35, self = this; + var accumulate; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - args = $send(args, 'map', [], ($$35 = function(arg){var self = $$35.$$s || this; + self.$each.$$p = function() { + var element = $Opal.$destructure(arguments), + end_chunk = $yield1(block, element); - - - if (arg == null) { - arg = nil; + if (accumulate == null) { + accumulate = []; + } + + if ($truthy(end_chunk)) { + accumulate.push(element); + yielder.$yield(accumulate); + accumulate = null; + } else { + accumulate.push(element); + } }; - return arg.$$is_range ? arg.$to_a() : arg;}, $$35.$$s = self, $$35.$$arity = 1, $$35)).$flatten(); - - var result = []; - for (var i = 0, len = args.length; i < len; i++) { - if (!args[i].$$is_number) { - self.$raise($$($nesting, 'TypeError'), "" + "no implicit conversion of " + ((args[i]).$class()) + " into Integer") + + self.$each(); + + if (accumulate != null) { + yielder.$yield(accumulate); } - result.push(self['$[]'](args[i])); - } - return result; - ; - }, $Struct_values_at$34.$$arity = -1); - return (Opal.def(self, '$dig', $Struct_dig$36 = function $$dig(key, $a) { - var $post_args, keys, self = this, item = nil; +}, {$$s: self}); + }, -1); + + $def(self, '$slice_when', function $$slice_when() { + var block = $$slice_when.$$p || nil, self = this; - - - $post_args = Opal.slice.call(arguments, 1, arguments.length); - - keys = $post_args;; - item = (function() {if ($truthy(key.$$is_string && self.$$data.hasOwnProperty(key))) { - return self.$$data[key] || nil; - } else { - return nil - }; return nil; })(); - - if (item === nil || keys.length === 0) { - return item; - } - ; - if ($truthy(item['$respond_to?']("dig"))) { - } else { - self.$raise($$($nesting, 'TypeError'), "" + (item.$class()) + " does not have #dig method") - }; - return $send(item, 'dig', Opal.to_a(keys)); - }, $Struct_dig$36.$$arity = -2), nil) && 'dig'; - })($nesting[0], null, $nesting); -}; + $$slice_when.$$p = null; + if (!(block !== nil)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1)"); + } return $send($$$('Enumerator'), 'new', [], function $$54(yielder){var self = $$54.$$s == null ? this : $$54.$$s; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/io"] = function(Opal) { - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $module = Opal.module, $send = Opal.send, $gvars = Opal.gvars, $truthy = Opal.truthy, $writer = nil; + + if (yielder == null) yielder = nil; + + var slice = nil, last_after = nil; - Opal.add_stubs(['$attr_accessor', '$size', '$write', '$join', '$map', '$String', '$empty?', '$concat', '$chomp', '$getbyte', '$getc', '$raise', '$new', '$write_proc=', '$-', '$extend']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'IO'); + self.$each_cons.$$p = function() { + var params = $Opal.$destructure(arguments), + before = params[0], + after = params[1], + match = $yieldX(block, [before, after]); - var $nesting = [self].concat($parent_nesting), $IO_tty$ques$1, $IO_closed$ques$2, $IO_write$3, $IO_flush$4; + last_after = after; - self.$$prototype.tty = self.$$prototype.closed = nil; - - Opal.const_set($nesting[0], 'SEEK_SET', 0); - Opal.const_set($nesting[0], 'SEEK_CUR', 1); - Opal.const_set($nesting[0], 'SEEK_END', 2); - - Opal.def(self, '$tty?', $IO_tty$ques$1 = function() { - var self = this; + if (slice === nil) { + slice = []; + } - return self.tty - }, $IO_tty$ques$1.$$arity = 0); - - Opal.def(self, '$closed?', $IO_closed$ques$2 = function() { - var self = this; + if ($truthy(match)) { + slice.push(before); + yielder.$yield(slice); + slice = []; + } else { + slice.push(before); + } + }; - return self.closed - }, $IO_closed$ques$2.$$arity = 0); - self.$attr_accessor("write_proc"); - - Opal.def(self, '$write', $IO_write$3 = function $$write(string) { - var self = this; + self.$each_cons(2); - - self.write_proc(string); - return string.$size(); - }, $IO_write$3.$$arity = 1); - self.$attr_accessor("sync", "tty"); + if (slice !== nil) { + slice.push(last_after); + yielder.$yield(slice); + } +}, {$$s: self}); + }); - Opal.def(self, '$flush', $IO_flush$4 = function $$flush() { - var self = this; + $def(self, '$sort', function $$sort() { + var block = $$sort.$$p || nil, self = this, ary = nil; - return nil - }, $IO_flush$4.$$arity = 0); - (function($base, $parent_nesting) { - var self = $module($base, 'Writable'); - - var $nesting = [self].concat($parent_nesting), $Writable_$lt$lt$5, $Writable_print$6, $Writable_puts$8; + $$sort.$$p = null; + ary = self.$to_a(); + if (!(block !== nil)) { + block = $lambda(function $$55(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$<=>'](b);}); + } return $send(ary, 'sort', [], block.$to_proc()); + }); + + $def(self, '$sort_by', function $$sort_by() { + var block = $$sort_by.$$p || nil, self = this, dup = nil; - - - Opal.def(self, '$<<', $Writable_$lt$lt$5 = function(string) { - var self = this; + $$sort_by.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["sort_by"], function $$56(){var self = $$56.$$s == null ? this : $$56.$$s; - - self.$write(string); - return self; - }, $Writable_$lt$lt$5.$$arity = 1); - - Opal.def(self, '$print', $Writable_print$6 = function $$print($a) { - var $post_args, args, $$7, self = this; - if ($gvars[","] == null) $gvars[","] = nil; + return self.$enumerator_size()}, {$$s: self}) + } dup = $send(self, 'map', [], function $$57(){var arg = nil; + arg = $Opal.$destructure(arguments); + return [Opal.yield1(block, arg), arg];}); + $send(dup, 'sort!', [], function $$58(a, b){ - $post_args = Opal.slice.call(arguments, 0, arguments.length); + if (a == null) a = nil; + if (b == null) b = nil; + return (a[0])['$<=>'](b[0]);}); + return $send(dup, 'map!', [], function $$59(i){ - args = $post_args;; - self.$write($send(args, 'map', [], ($$7 = function(arg){var self = $$7.$$s || this; + if (i == null) i = nil; + return i[1];}); + }); + + $def(self, '$sum', function $$sum(initial) { + var $yield = $$sum.$$p || nil, self = this, result = nil, compensation = nil; - - - if (arg == null) { - arg = nil; - }; - return self.$String(arg);}, $$7.$$s = self, $$7.$$arity = 1, $$7)).$join($gvars[","])); - return nil; - }, $Writable_print$6.$$arity = -1); + $$sum.$$p = null; - Opal.def(self, '$puts', $Writable_puts$8 = function $$puts($a) { - var $post_args, args, $$9, self = this, newline = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; + if (initial == null) initial = 0; + result = initial; + compensation = 0; + $send(self, 'each', [], function $$60($a){var $post_args, args, item = nil, y = nil, t = nil; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - newline = $gvars["/"]; - if ($truthy(args['$empty?']())) { - self.$write($gvars["/"]) - } else { - self.$write($send(args, 'map', [], ($$9 = function(arg){var self = $$9.$$s || this; - + $post_args = $slice(arguments); + args = $post_args; + item = (($yield !== nil) ? (Opal.yieldX($yield, $to_a(args))) : ($Opal.$destructure(args))); + if (($not([$$$($$$('Float'), 'INFINITY'), $$$($$$('Float'), 'INFINITY')['$-@']()]['$include?'](item)) && ($truthy(item['$respond_to?']("-"))))) { - - if (arg == null) { - arg = nil; - }; - return self.$String(arg).$chomp();}, $$9.$$s = self, $$9.$$arity = 1, $$9)).$concat([nil]).$join(newline)) - }; - return nil; - }, $Writable_puts$8.$$arity = -1); - })($nesting[0], $nesting); - return (function($base, $parent_nesting) { - var self = $module($base, 'Readable'); - - var $nesting = [self].concat($parent_nesting), $Readable_readbyte$10, $Readable_readchar$11, $Readable_readline$12, $Readable_readpartial$13; - - - - Opal.def(self, '$readbyte', $Readable_readbyte$10 = function $$readbyte() { - var self = this; + y = $rb_minus(item, compensation); + t = $rb_plus(result, y); + compensation = $rb_minus($rb_minus(t, result), y); + return (result = t); + } else { + return (result = $rb_plus(result, item)) + }}, -1); + return result; + }, -1); + + $def(self, '$take', function $$take(num) { + var self = this; - return self.$getbyte() - }, $Readable_readbyte$10.$$arity = 0); - - Opal.def(self, '$readchar', $Readable_readchar$11 = function $$readchar() { - var self = this; + return self.$first(num) + }); + + $def(self, '$take_while', function $$take_while() {try { var $t_return = $thrower('return'); + var block = $$take_while.$$p || nil, self = this, result = nil; - return self.$getc() - }, $Readable_readchar$11.$$arity = 0); + $$take_while.$$p = null; - Opal.def(self, '$readline', $Readable_readline$12 = function $$readline(sep) { - var self = this; - if ($gvars["/"] == null) $gvars["/"] = nil; + ; + if (!$truthy(block)) { + return self.$enum_for("take_while") + }; + result = []; + return $send(self, 'each', [], function $$61($a){var $post_args, args, value = nil; - - if (sep == null) { - sep = $gvars["/"]; + $post_args = $slice(arguments); + args = $post_args; + value = $Opal.$destructure(args); + if (!$truthy(Opal.yield1(block, value))) { + $t_return.$throw(result); }; - return self.$raise($$($nesting, 'NotImplementedError')); - }, $Readable_readline$12.$$arity = -1); - - Opal.def(self, '$readpartial', $Readable_readpartial$13 = function $$readpartial(integer, outbuf) { - var self = this; + return result.push(value);;}, {$$arity: -1, $$ret: $t_return});} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }); + + $def(self, '$uniq', function $$uniq() { + var block = $$uniq.$$p || nil, self = this, hash = nil; + + $$uniq.$$p = null; + hash = $hash2([], {}); + $send(self, 'each', [], function $$62($a){var $post_args, args, $b, value = nil, produced = nil; + $post_args = $slice(arguments); + args = $post_args; + value = $Opal.$destructure(args); + produced = ((block !== nil) ? (Opal.yield1(block, value)) : (value)); + if ($truthy(hash['$key?'](produced))) { + return nil + } else { + return ($b = [produced, value], $send(hash, '[]=', $b), $b[$b.length - 1]) + }}, -1); + return hash.$values(); + }); + + $def(self, '$tally', function $$tally(hash) { + var self = this, out = nil; + if (hash && hash !== nil) { $deny_frozen_access(hash); } out = $send($send(self, 'group_by', [], "itself".$to_proc()), 'transform_values', [], "count".$to_proc()); + if ($truthy(hash)) { - if (outbuf == null) { - outbuf = nil; - }; - return self.$raise($$($nesting, 'NotImplementedError')); - }, $Readable_readpartial$13.$$arity = -2); - })($nesting[0], $nesting); - })($nesting[0], null, $nesting); - Opal.const_set($nesting[0], 'STDERR', ($gvars.stderr = $$($nesting, 'IO').$new())); - Opal.const_set($nesting[0], 'STDIN', ($gvars.stdin = $$($nesting, 'IO').$new())); - Opal.const_set($nesting[0], 'STDOUT', ($gvars.stdout = $$($nesting, 'IO').$new())); - var console = Opal.global.console; - - $writer = [typeof(process) === 'object' && typeof(process.stdout) === 'object' ? function(s){process.stdout.write(s)} : function(s){console.log(s)}]; - $send($$($nesting, 'STDOUT'), 'write_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - - $writer = [typeof(process) === 'object' && typeof(process.stderr) === 'object' ? function(s){process.stderr.write(s)} : function(s){console.warn(s)}]; - $send($$($nesting, 'STDERR'), 'write_proc=', Opal.to_a($writer)); - $writer[$rb_minus($writer["length"], 1)];; - $$($nesting, 'STDOUT').$extend($$$($$($nesting, 'IO'), 'Writable')); - return $$($nesting, 'STDERR').$extend($$$($$($nesting, 'IO'), 'Writable')); -}; + $send(out, 'each', [], function $$63(k, v){var $a; + + + if (k == null) k = nil; + if (v == null) v = nil; + return ($a = [k, $rb_plus(hash.$fetch(k, 0), v)], $send(hash, '[]=', $a), $a[$a.length - 1]);}); + return hash; + } else { + return out + } }, -1); + + $def(self, '$to_h', function $$to_h($a) { + var block = $$to_h.$$p || nil, $post_args, args, self = this; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/main"] = function(Opal) { - var $to_s$1, $include$2, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; + $$to_h.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if ((block !== nil)) { + return $send($send(self, 'map', [], block.$to_proc()), 'to_h', $to_a(args)) + } + var hash = $hash2([], {}); - Opal.add_stubs(['$include']); - - Opal.defs(self, '$to_s', $to_s$1 = function $$to_s() { - var self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments); + var ary = $Opal['$coerce_to?'](param, $$$('Array'), "to_ary"), key, val; + if (!ary.$$is_array) { + $Kernel.$raise($$$('TypeError'), "wrong element type " + ((ary).$class()) + " (expected array)"); + } + if (ary.length !== 2) { + $Kernel.$raise($$$('ArgumentError'), "wrong array length (expected 2, was " + ((ary).$length()) + ")"); + } + key = ary[0]; + val = ary[1]; + + Opal.hash_put(hash, key, val); + }; - return "main" - }, $to_s$1.$$arity = 0); - return (Opal.defs(self, '$include', $include$2 = function $$include(mod) { - var self = this; + self.$each.apply(self, args); - return $$($nesting, 'Object').$include(mod) - }, $include$2.$$arity = 1), nil) && 'include'; + return hash; + }, -1); + + $def(self, '$to_set', function $$to_set($a, $b) { + var block = $$to_set.$$p || nil, $post_args, klass, args, self = this; + + $$to_set.$$p = null; + $post_args = $slice(arguments); + + if ($post_args.length > 0) klass = $post_args.shift();if (klass == null) klass = $$('Set'); + args = $post_args; + return $send(klass, 'new', [self].concat($to_a(args)), block.$to_proc()); + }, -1); + + $def(self, '$zip', function $$zip($a) { + var $post_args, others, self = this; + + $$zip.$$p = null; + $post_args = $slice(arguments); + others = $post_args; + return $send(self.$to_a(), 'zip', $to_a(others)); + }, -1); + $alias(self, "find", "detect"); + $alias(self, "filter", "find_all"); + $alias(self, "flat_map", "collect_concat"); + $alias(self, "map", "collect"); + $alias(self, "member?", "include?"); + $alias(self, "reduce", "inject"); + $alias(self, "select", "find_all"); + return $alias(self, "to_a", "entries"); + })('::', $nesting) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/dir"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; +Opal.modules["corelib/enumerator/arithmetic_sequence"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $to_a = Opal.to_a, $eqeq = Opal.eqeq, $Kernel = Opal.Kernel, $def = Opal.def, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $not = Opal.not, $rb_times = Opal.rb_times, $rb_divide = Opal.rb_divide, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - Opal.add_stubs(['$[]']); + Opal.add_stubs('is_a?,==,raise,respond_to?,class,attr_reader,begin,end,exclude_end?,>,step,<,<=,>=,-@,_lesser_than_end?,<<,+,-,===,%,_greater_than_begin?,reverse,!,include?,*,to_i,abs,/,hash,inspect'); return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Dir'); + var self = $klass($base, $super, 'Enumerator'); var $nesting = [self].concat($parent_nesting); - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $chdir$1, $pwd$2, $home$3; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'ArithmeticSequence'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.step_arg2 = $proto.receiver_num = $proto.step_arg1 = $proto.step = $proto.range = $proto.topfx = $proto.bypfx = $proto.creation_method = $proto.skipped_arg = nil; + Opal.prop(self.$$prototype, '$$is_arithmetic_seq', true); + var inf = Infinity; - Opal.def(self, '$chdir', $chdir$1 = function $$chdir(dir) { - var $iter = $chdir$1.$$p, $yield = $iter || nil, self = this, prev_cwd = nil; - - if ($iter) $chdir$1.$$p = null; - return (function() { try { - - prev_cwd = Opal.current_dir; - Opal.current_dir = dir; - return Opal.yieldX($yield, []);; - } finally { - Opal.current_dir = prev_cwd - }; })() - }, $chdir$1.$$arity = 1); + $def(self, '$initialize', function $$initialize(range, step, creation_method) { + var $a, self = this, $ret_or_1 = nil; + if (creation_method == null) creation_method = "step"; + self.creation_method = creation_method; + if ($truthy(range['$is_a?']($$$('Array')))) { + + $a = [].concat($to_a(range)), (self.step_arg1 = ($a[0] == null ? nil : $a[0])), (self.step_arg2 = ($a[1] == null ? nil : $a[1])), (self.topfx = ($a[2] == null ? nil : $a[2])), (self.bypfx = ($a[3] == null ? nil : $a[3])); + self.receiver_num = step; + self.step = 1; + self.range = ($truthy(self.step_arg2) ? (((self.step = self.step_arg2), Opal.Range.$new(self.receiver_num, self.step_arg1, false))) : ($truthy(self.step_arg1) ? (Opal.Range.$new(self.receiver_num, self.step_arg1, false)) : (Opal.Range.$new(self.receiver_num, nil, false)))); + } else { + + if (!$truthy(step)) { + self.skipped_arg = true; + } $a = [range, ($truthy(($ret_or_1 = step)) ? ($ret_or_1) : (1))], (self.range = $a[0]), (self.step = $a[1]); + } self.object = self; + if ($eqeq(self.step, 0)) { + $Kernel.$raise($$('ArgumentError'), "step can't be 0"); + } if ($truthy(self.step['$respond_to?']("to_int"))) { + return nil + } else { + return $Kernel.$raise($$('ArgumentError'), "" + ("no implicit conversion of " + (self.step.$class()) + " ") + "into Integer") + } }, -2); + self.$attr_reader("step"); - Opal.def(self, '$pwd', $pwd$2 = function $$pwd() { + $def(self, '$begin', function $$begin() { var self = this; - return Opal.current_dir || '.'; - }, $pwd$2.$$arity = 0); - Opal.alias(self, "getwd", "pwd"); - return (Opal.def(self, '$home', $home$3 = function $$home() { - var $a, self = this; - - return ($truthy($a = $$($nesting, 'ENV')['$[]']("HOME")) ? $a : ".") - }, $home$3.$$arity = 0), nil) && 'home'; - })(Opal.get_singleton_class(self), $nesting) - })($nesting[0], null, $nesting) -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/file"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $range = Opal.range, $send = Opal.send; - - Opal.add_stubs(['$respond_to?', '$to_path', '$pwd', '$split', '$sub', '$+', '$unshift', '$join', '$home', '$raise', '$start_with?', '$absolute_path', '$coerce_to!', '$basename', '$empty?', '$rindex', '$[]', '$nil?', '$==', '$-', '$length', '$gsub', '$find', '$=~', '$map', '$each_with_index', '$flatten', '$reject', '$to_proc', '$end_with?']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'File'); - - var $nesting = [self].concat($parent_nesting), windows_root_rx = nil; - - - Opal.const_set($nesting[0], 'Separator', Opal.const_set($nesting[0], 'SEPARATOR', "/")); - Opal.const_set($nesting[0], 'ALT_SEPARATOR', nil); - Opal.const_set($nesting[0], 'PATH_SEPARATOR', ":"); - Opal.const_set($nesting[0], 'FNM_SYSCASE', 0); - windows_root_rx = /^[a-zA-Z]:(?:\\|\/)/; - return (function(self, $parent_nesting) { - var $nesting = [self].concat($parent_nesting), $absolute_path$1, $expand_path$2, $dirname$3, $basename$4, $extname$5, $exist$ques$6, $directory$ques$7, $join$9, $split$12; + return self.range.$begin() + }); + + $def(self, '$end', function $$end() { + var self = this; + return self.range.$end() + }); + $def(self, '$exclude_end?', function $ArithmeticSequence_exclude_end$ques$1() { + var self = this; + + return self.range['$exclude_end?']() + }); - Opal.def(self, '$absolute_path', $absolute_path$1 = function $$absolute_path(path, basedir) { - var $a, self = this, sep = nil, sep_chars = nil, new_parts = nil, path_abs = nil, basedir_abs = nil, parts = nil, leading_sep = nil, abs = nil, new_path = nil; + $def(self, '$_lesser_than_end?', function $ArithmeticSequence__lesser_than_end$ques$2(val) { + var self = this, end_ = nil, $ret_or_1 = nil; - - if (basedir == null) { - basedir = nil; - }; - sep = $$($nesting, 'SEPARATOR'); - sep_chars = $sep_chars(); - new_parts = []; - path = (function() {if ($truthy(path['$respond_to?']("to_path"))) { - return path.$to_path() - } else { - return path - }; return nil; })(); - basedir = ($truthy($a = basedir) ? $a : $$($nesting, 'Dir').$pwd()); - path_abs = path.substr(0, sep.length) === sep || windows_root_rx.test(path); - basedir_abs = basedir.substr(0, sep.length) === sep || windows_root_rx.test(basedir); - if ($truthy(path_abs)) { - - parts = path.$split(new RegExp("" + "[" + (sep_chars) + "]")); - leading_sep = windows_root_rx.test(path) ? '' : path.$sub(new RegExp("" + "^([" + (sep_chars) + "]+).*$"), "\\1"); - abs = true; - } else { - - parts = $rb_plus(basedir.$split(new RegExp("" + "[" + (sep_chars) + "]")), path.$split(new RegExp("" + "[" + (sep_chars) + "]"))); - leading_sep = windows_root_rx.test(basedir) ? '' : basedir.$sub(new RegExp("" + "^([" + (sep_chars) + "]+).*$"), "\\1"); - abs = basedir_abs; - }; - - var part; - for (var i = 0, ii = parts.length; i < ii; i++) { - part = parts[i]; - - if ( - (part === nil) || - (part === '' && ((new_parts.length === 0) || abs)) || - (part === '.' && ((new_parts.length === 0) || abs)) - ) { - continue; - } - if (part === '..') { - new_parts.pop(); + end_ = ($truthy(($ret_or_1 = self.$end())) ? ($ret_or_1) : (inf)); + if ($truthy($rb_gt(self.$step(), 0))) { + if ($truthy(self['$exclude_end?']())) { + return $rb_lt(val, end_) } else { - new_parts.push(part); + return $rb_le(val, end_) } - } - - if (!abs && parts[0] !== '.') { - new_parts.$unshift(".") - } - ; - new_path = new_parts.$join(sep); - if ($truthy(abs)) { - new_path = $rb_plus(leading_sep, new_path)}; - return new_path; - }, $absolute_path$1.$$arity = -2); + } else if ($truthy(self['$exclude_end?']())) { + return $rb_gt(val, end_) + } else { + return $rb_ge(val, end_) + } }); - Opal.def(self, '$expand_path', $expand_path$2 = function $$expand_path(path, basedir) { - var self = this, sep = nil, sep_chars = nil, home = nil, leading_sep = nil, home_path_regexp = nil; + $def(self, '$_greater_than_begin?', function $ArithmeticSequence__greater_than_begin$ques$3(val) { + var self = this, begin_ = nil, $ret_or_1 = nil; + begin_ = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']())); + if ($truthy($rb_gt(self.$step(), 0))) { + return $rb_gt(val, begin_) + } else { + return $rb_lt(val, begin_) + } }); + + $def(self, '$first', function $$first(count) { + var self = this, iter = nil, $ret_or_1 = nil, out = nil; + iter = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']())); + if (!$truthy(count)) { + return ($truthy(self['$_lesser_than_end?'](iter)) ? (iter) : (nil)) + } out = []; + while ($truthy(($truthy(($ret_or_1 = self['$_lesser_than_end?'](iter))) ? ($rb_gt(count, 0)) : ($ret_or_1)))) { - if (basedir == null) { - basedir = nil; - }; - sep = $$($nesting, 'SEPARATOR'); - sep_chars = $sep_chars(); - if ($truthy(path[0] === '~' || (basedir && basedir[0] === '~'))) { - - home = $$($nesting, 'Dir').$home(); - if ($truthy(home)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "couldn't find HOME environment -- expanding `~'") - }; - leading_sep = windows_root_rx.test(home) ? '' : home.$sub(new RegExp("" + "^([" + (sep_chars) + "]+).*$"), "\\1"); - if ($truthy(home['$start_with?'](leading_sep))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "non-absolute home") - }; - home = $rb_plus(home, sep); - home_path_regexp = new RegExp("" + "^\\~(?:" + (sep) + "|$)"); - path = path.$sub(home_path_regexp, home); - if ($truthy(basedir)) { - basedir = basedir.$sub(home_path_regexp, home)};}; - return self.$absolute_path(path, basedir); - }, $expand_path$2.$$arity = -2); - Opal.alias(self, "realpath", "expand_path"); + out['$<<'](iter); + iter = $rb_plus(iter, self.$step()); + count = $rb_minus(count, 1); + } return out; + }, -1); - // Coerce a given path to a path string using #to_path and #to_str - function $coerce_to_path(path) { - if ($truthy((path)['$respond_to?']("to_path"))) { - path = path.$to_path(); - } - - path = $$($nesting, 'Opal')['$coerce_to!'](path, $$($nesting, 'String'), "to_str"); - - return path; - } + $def(self, '$each', function $$each() { + var block = $$each.$$p || nil, self = this, $ret_or_1 = nil, iter = nil; - // Return a RegExp compatible char class - function $sep_chars() { - if ($$($nesting, 'ALT_SEPARATOR') === nil) { - return Opal.escape_regexp($$($nesting, 'SEPARATOR')); + $$each.$$p = null; + if (!(block !== nil)) { + return self + } if ($eqeqeq(nil, ($ret_or_1 = self.$begin()))) { + $Kernel.$raise($$('TypeError'), "nil can't be coerced into Integer"); + } iter = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']())); + while ($truthy(self['$_lesser_than_end?'](iter))) { + + Opal.yield1(block, iter); + iter = $rb_plus(iter, self.$step()); + } return self; + }); + + $def(self, '$last', function $$last(count) { + var self = this, $ret_or_1 = nil, iter = nil, out = nil; + if (($eqeqeq(inf, ($ret_or_1 = self.$end())) || ($eqeqeq((inf)['$-@'](), $ret_or_1)))) { + $Kernel.$raise($$$('FloatDomainError'), self.$end()); + } else if ($eqeqeq(nil, $ret_or_1)) { + $Kernel.$raise($$$('RangeError'), "cannot get the last element of endless arithmetic sequence"); + } else ; iter = $rb_minus(self.$end(), $rb_minus(self.$end(), self.$begin())['$%'](self.$step())); + if (!$truthy(self['$_lesser_than_end?'](iter))) { + iter = $rb_minus(iter, self.$step()); + } if (!$truthy(count)) { + return ($truthy(self['$_greater_than_begin?'](iter)) ? (iter) : (nil)) + } out = []; + while ($truthy(($truthy(($ret_or_1 = self['$_greater_than_begin?'](iter))) ? ($rb_gt(count, 0)) : ($ret_or_1)))) { + + out['$<<'](iter); + iter = $rb_minus(iter, self.$step()); + count = $rb_minus(count, 1); + } return out.$reverse(); + }, -1); + + $def(self, '$size', function $$size() { + var self = this, step_sign = nil, iter = nil; + + + step_sign = ($truthy($rb_gt(self.$step(), 0)) ? (1) : (-1)); + if ($not(self['$_lesser_than_end?'](self.$begin()))) { + return 0 + } else if ($truthy([(inf)['$-@'](), inf]['$include?'](self.$step()))) { + return 1 + } else if (($truthy([$rb_times((inf)['$-@'](), step_sign), nil]['$include?'](self.$begin())) || ($truthy([$rb_times(inf, step_sign), nil]['$include?'](self.$end()))))) { + return inf; } else { - return Opal.escape_regexp($rb_plus($$($nesting, 'SEPARATOR'), $$($nesting, 'ALT_SEPARATOR'))); - } - } - ; + + iter = $rb_minus(self.$end(), $rb_minus(self.$end(), self.$begin())['$%'](self.$step())); + if (!$truthy(self['$_lesser_than_end?'](iter))) { + iter = $rb_minus(iter, self.$step()); + } return $rb_plus($rb_divide($rb_minus(iter, self.$begin()), self.$step()).$abs().$to_i(), 1); + } }); - Opal.def(self, '$dirname', $dirname$3 = function $$dirname(path) { - var self = this, sep_chars = nil; - - - sep_chars = $sep_chars(); - path = $coerce_to_path(path); - - var absolute = path.match(new RegExp("" + "^[" + (sep_chars) + "]")); + $def(self, '$==', function $ArithmeticSequence_$eq_eq$4(other) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil; - path = path.replace(new RegExp("" + "[" + (sep_chars) + "]+$"), ''); // remove trailing separators - path = path.replace(new RegExp("" + "[^" + (sep_chars) + "]+$"), ''); // remove trailing basename - path = path.replace(new RegExp("" + "[" + (sep_chars) + "]+$"), ''); // remove final trailing separators - - if (path === '') { - return absolute ? '/' : '.'; + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = self.$class()['$=='](other.$class()))) ? (self.$begin()['$=='](other.$begin())) : ($ret_or_4)))) ? (self.$end()['$=='](other.$end())) : ($ret_or_3)))) ? (self.$step()['$=='](other.$step())) : ($ret_or_2))))) { + return self['$exclude_end?']()['$=='](other['$exclude_end?']()) + } else { + return $ret_or_1 } - - return path; - ; - }, $dirname$3.$$arity = 1); + }); - Opal.def(self, '$basename', $basename$4 = function $$basename(name, suffix) { - var self = this, sep_chars = nil; + $def(self, '$hash', function $$hash() { + var self = this; - - - if (suffix == null) { - suffix = nil; - }; - sep_chars = $sep_chars(); - name = $coerce_to_path(name); - - if (name.length == 0) { - return name; - } + return [self.$begin(), self.$end(), self.$step(), self['$exclude_end?']()].$hash() + }); + + $def(self, '$inspect', function $$inspect() { + var self = this, args = nil; - if (suffix !== nil) { - suffix = $$($nesting, 'Opal')['$coerce_to!'](suffix, $$($nesting, 'String'), "to_str") + if ($truthy(self.receiver_num)) { + + args = ($truthy(self.step_arg2) ? ("(" + (self.topfx) + (self.step_arg1.$inspect()) + ", " + (self.bypfx) + (self.step_arg2.$inspect()) + ")") : ($truthy(self.step_arg1) ? ("(" + (self.topfx) + (self.step_arg1.$inspect()) + ")") : nil)); + return "(" + (self.receiver_num.$inspect()) + "." + (self.creation_method) + (args) + ")"; } else { - suffix = null; + + args = ($truthy(self.skipped_arg) ? (nil) : ("(" + (self.step) + ")")); + return "((" + (self.range.$inspect()) + ")." + (self.creation_method) + (args) + ")"; } + }); + $alias(self, "===", "=="); + return $alias(self, "eql?", "=="); + })(self, self, $nesting) + })('::', null, $nesting) +}; - name = name.replace(new RegExp("" + "(.)[" + (sep_chars) + "]*$"), '$1'); - name = name.replace(new RegExp("" + "^(?:.*[" + (sep_chars) + "])?([^" + (sep_chars) + "]+)$"), '$1'); +Opal.modules["corelib/enumerator/chain"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $slice = Opal.slice, $def = Opal.def, $send = Opal.send, $to_a = Opal.to_a, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $thrower = Opal.thrower, nil = Opal.nil, $$$ = Opal.$$$; - if (suffix === ".*") { - name = name.replace(/\.[^\.]+$/, ''); - } else if(suffix !== null) { - suffix = Opal.escape_regexp(suffix); - name = name.replace(new RegExp("" + (suffix) + "$"), ''); - } + Opal.add_stubs('to_enum,size,each,<<,to_proc,include?,+,reverse_each,respond_to?,rewind,inspect'); + return (function($base, $super) { + var self = $klass($base, $super, 'Enumerator'); - return name; - ; - }, $basename$4.$$arity = -2); + + return (function($base, $super) { + var self = $klass($base, $super, 'Chain'); + + var $proto = self.$$prototype; + + $proto.enums = $proto.iterated = nil; - Opal.def(self, '$extname', $extname$5 = function $$extname(path) { - var $a, self = this, filename = nil, last_dot_idx = nil; + + $def(self, '$initialize', function $$initialize($a) { + var $post_args, enums, self = this; - path = $coerce_to_path(path); - filename = self.$basename(path); - if ($truthy(filename['$empty?']())) { - return ""}; - last_dot_idx = filename['$[]']($range(1, -1, false)).$rindex("."); - if ($truthy(($truthy($a = last_dot_idx['$nil?']()) ? $a : $rb_plus(last_dot_idx, 1)['$==']($rb_minus(filename.$length(), 1))))) { - return "" - } else { - return filename['$[]'](Opal.Range.$new($rb_plus(last_dot_idx, 1), -1, false)) - }; - }, $extname$5.$$arity = 1); + $post_args = $slice(arguments); + enums = $post_args; + $deny_frozen_access(self); + self.enums = enums; + self.iterated = []; + return (self.object = self); + }, -1); - Opal.def(self, '$exist?', $exist$ques$6 = function(path) { - var self = this; + $def(self, '$each', function $$each($a) { + var block = $$each.$$p || nil, $post_args, args, self = this; - return Opal.modules[path] != null - }, $exist$ques$6.$$arity = 1); - Opal.alias(self, "exists?", "exist?"); - - Opal.def(self, '$directory?', $directory$ques$7 = function(path) { - var $$8, self = this, files = nil, file = nil; + $$each.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (!(block !== nil)) { + return $send(self, 'to_enum', ["each"].concat($to_a(args)), function $$1(){var self = $$1.$$s == null ? this : $$1.$$s; - - files = []; - - for (var key in Opal.modules) { - files.push(key) - } - ; - path = path.$gsub(new RegExp("" + "(^." + ($$($nesting, 'SEPARATOR')) + "+|" + ($$($nesting, 'SEPARATOR')) + "+$)")); - file = $send(files, 'find', [], ($$8 = function(f){var self = $$8.$$s || this; + return self.$size()}, {$$s: self}) + } $send(self.enums, 'each', [], function $$2(enum$){var self = $$2.$$s == null ? this : $$2.$$s; + if (self.iterated == null) self.iterated = nil; - - if (f == null) { - f = nil; - }; - return f['$=~'](new RegExp("" + "^" + (path)));}, $$8.$$s = self, $$8.$$arity = 1, $$8)); - return file; - }, $directory$ques$7.$$arity = 1); + if (enum$ == null) enum$ = nil; + self.iterated['$<<'](enum$); + return $send(enum$, 'each', $to_a(args), block.$to_proc());}, {$$s: self}); + return self; + }, -1); - Opal.def(self, '$join', $join$9 = function $$join($a) { - var $post_args, paths, $$10, $$11, self = this, result = nil; + $def(self, '$size', function $$size($a) {try { var $t_return = $thrower('return'); + var $post_args, args, self = this, accum = nil; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - paths = $post_args;; - if ($truthy(paths['$empty?']())) { - return ""}; - result = ""; - paths = $send(paths.$flatten().$each_with_index(), 'map', [], ($$10 = function(item, index){var self = $$10.$$s || this, $b; + $post_args = $slice(arguments); + args = $post_args; + accum = 0; + $send(self.enums, 'each', [], function $$3(enum$){var size = nil; - - - if (item == null) { - item = nil; - }; - if (index == null) { - index = nil; + if (enum$ == null) enum$ = nil; + size = $send(enum$, 'size', $to_a(args)); + if ($truthy([nil, $$$($$$('Float'), 'INFINITY')]['$include?'](size))) { + $t_return.$throw(size); }; - if ($truthy((($b = index['$=='](0)) ? item['$empty?']() : index['$=='](0)))) { - return $$($nesting, 'SEPARATOR') - } else if ($truthy((($b = paths.$length()['$==']($rb_plus(index, 1))) ? item['$empty?']() : paths.$length()['$==']($rb_plus(index, 1))))) { - return $$($nesting, 'SEPARATOR') - } else { - return item - };}, $$10.$$s = self, $$10.$$arity = 2, $$10)); - paths = $send(paths, 'reject', [], "empty?".$to_proc()); - $send(paths, 'each_with_index', [], ($$11 = function(item, index){var self = $$11.$$s || this, $b, next_item = nil; + return (accum = $rb_plus(accum, size));}, {$$ret: $t_return}); + return accum;} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + + $def(self, '$rewind', function $$rewind() { + var self = this; + $send(self.iterated, 'reverse_each', [], function $$4(enum$){ - if (item == null) { - item = nil; - }; - - if (index == null) { - index = nil; - }; - next_item = paths['$[]']($rb_plus(index, 1)); - if ($truthy(next_item['$nil?']())) { - return (result = "" + (result) + (item)) + if (enum$ == null) enum$ = nil; + if ($truthy(enum$['$respond_to?']("rewind"))) { + return enum$.$rewind() } else { - - if ($truthy(($truthy($b = item['$end_with?']($$($nesting, 'SEPARATOR'))) ? next_item['$start_with?']($$($nesting, 'SEPARATOR')) : $b))) { - item = item.$sub(new RegExp("" + ($$($nesting, 'SEPARATOR')) + "+$"), "")}; - return (result = (function() {if ($truthy(($truthy($b = item['$end_with?']($$($nesting, 'SEPARATOR'))) ? $b : next_item['$start_with?']($$($nesting, 'SEPARATOR'))))) { - return "" + (result) + (item) - } else { - return "" + (result) + (item) + ($$($nesting, 'SEPARATOR')) - }; return nil; })()); - };}, $$11.$$s = self, $$11.$$arity = 2, $$11)); - return result; - }, $join$9.$$arity = -1); - return (Opal.def(self, '$split', $split$12 = function $$split(path) { + return nil + }}); + self.iterated = []; + return self; + }); + return $def(self, '$inspect', function $$inspect() { var self = this; - return path.$split($$($nesting, 'SEPARATOR')) - }, $split$12.$$arity = 1), nil) && 'split'; - })(Opal.get_singleton_class(self), $nesting); - })($nesting[0], $$($nesting, 'IO'), $nesting) + return "#<Enumerator::Chain: " + (self.enums.$inspect()) + ">" + }); + })(self, self) + })('::', null) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/process"] = function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy; - - Opal.add_stubs(['$const_set', '$size', '$<<', '$__register_clock__', '$to_f', '$now', '$new', '$[]', '$raise']); - - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Process'); - - var $nesting = [self].concat($parent_nesting), $Process___register_clock__$1, $Process_pid$2, $Process_times$3, $Process_clock_gettime$4, monotonic = nil; - - - self.__clocks__ = []; - Opal.defs(self, '$__register_clock__', $Process___register_clock__$1 = function $$__register_clock__(name, func) { - var self = this; - if (self.__clocks__ == null) self.__clocks__ = nil; - - - self.$const_set(name, self.__clocks__.$size()); - return self.__clocks__['$<<'](func); - }, $Process___register_clock__$1.$$arity = 2); - self.$__register_clock__("CLOCK_REALTIME", function() { return Date.now() }); - monotonic = false; - - if (Opal.global.performance) { - monotonic = function() { - return performance.now() - }; - } - else if (Opal.global.process && process.hrtime) { - // let now be the base to get smaller numbers - var hrtime_base = process.hrtime(); - - monotonic = function() { - var hrtime = process.hrtime(hrtime_base); - var us = (hrtime[1] / 1000) | 0; // cut below microsecs; - return ((hrtime[0] * 1000) + (us / 1000)); - }; - } - ; - if ($truthy(monotonic)) { - self.$__register_clock__("CLOCK_MONOTONIC", monotonic)}; - Opal.defs(self, '$pid', $Process_pid$2 = function $$pid() { - var self = this; - - return 0 - }, $Process_pid$2.$$arity = 0); - Opal.defs(self, '$times', $Process_times$3 = function $$times() { - var self = this, t = nil; - - - t = $$($nesting, 'Time').$now().$to_f(); - return $$$($$($nesting, 'Benchmark'), 'Tms').$new(t, t, t, t, t); - }, $Process_times$3.$$arity = 0); - return (Opal.defs(self, '$clock_gettime', $Process_clock_gettime$4 = function $$clock_gettime(clock_id, unit) { - var $a, self = this, clock = nil; - if (self.__clocks__ == null) self.__clocks__ = nil; - - - - if (unit == null) { - unit = "float_second"; - }; - ($truthy($a = (clock = self.__clocks__['$[]'](clock_id))) ? $a : self.$raise($$$($$($nesting, 'Errno'), 'EINVAL'), "" + "clock_gettime(" + (clock_id) + ") " + (self.__clocks__['$[]'](clock_id)))); - - var ms = clock(); - switch (unit) { - case 'float_second': return (ms / 1000); // number of seconds as a float (default) - case 'float_millisecond': return (ms / 1); // number of milliseconds as a float - case 'float_microsecond': return (ms * 1000); // number of microseconds as a float - case 'second': return ((ms / 1000) | 0); // number of seconds as an integer - case 'millisecond': return ((ms / 1) | 0); // number of milliseconds as an integer - case 'microsecond': return ((ms * 1000) | 0); // number of microseconds as an integer - case 'nanosecond': return ((ms * 1000000) | 0); // number of nanoseconds as an integer - default: self.$raise($$($nesting, 'ArgumentError'), "" + "unexpected unit: " + (unit)) - } - ; - }, $Process_clock_gettime$4.$$arity = -2), nil) && 'clock_gettime'; - })($nesting[0], null, $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Signal'); - - var $nesting = [self].concat($parent_nesting), $Signal_trap$5; - - return (Opal.defs(self, '$trap', $Signal_trap$5 = function $$trap($a) { - var $post_args, self = this; +Opal.modules["corelib/enumerator/generator"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $slice = Opal.slice, $send = Opal.send, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $Signal_trap$5.$$arity = -1), nil) && 'trap' - })($nesting[0], null, $nesting); + Opal.add_stubs('include,raise,new,to_proc'); return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'GC'); - - var $nesting = [self].concat($parent_nesting), $GC_start$6; - - return (Opal.defs(self, '$start', $GC_start$6 = function $$start() { - var self = this; - - return nil - }, $GC_start$6.$$arity = 0), nil) && 'start' - })($nesting[0], null, $nesting); -}; - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/unsupported"] = function(Opal) { - var $public$35, $private$36, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $module = Opal.module; - - Opal.add_stubs(['$raise', '$warn', '$%']); - - - var warnings = {}; - - function handle_unsupported_feature(message) { - switch (Opal.config.unsupported_features_severity) { - case 'error': - $$($nesting, 'Kernel').$raise($$($nesting, 'NotImplementedError'), message) - break; - case 'warning': - warn(message) - break; - default: // ignore - // noop - } - } - - function warn(string) { - if (warnings[string]) { - return; - } - - warnings[string] = true; - self.$warn(string); - } -; - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'String'); - - var $nesting = [self].concat($parent_nesting), $String_$lt$lt$1, $String_capitalize$excl$2, $String_chomp$excl$3, $String_chop$excl$4, $String_downcase$excl$5, $String_gsub$excl$6, $String_lstrip$excl$7, $String_next$excl$8, $String_reverse$excl$9, $String_slice$excl$10, $String_squeeze$excl$11, $String_strip$excl$12, $String_sub$excl$13, $String_succ$excl$14, $String_swapcase$excl$15, $String_tr$excl$16, $String_tr_s$excl$17, $String_upcase$excl$18, $String_prepend$19, $String_$$$eq$20, $String_clear$21, $String_encode$excl$22, $String_unicode_normalize$excl$23; - - - var ERROR = "String#%s not supported. Mutable String methods are not supported in Opal."; - - Opal.def(self, '$<<', $String_$lt$lt$1 = function($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("<<")); - }, $String_$lt$lt$1.$$arity = -1); - - Opal.def(self, '$capitalize!', $String_capitalize$excl$2 = function($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("capitalize!")); - }, $String_capitalize$excl$2.$$arity = -1); - - Opal.def(self, '$chomp!', $String_chomp$excl$3 = function($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("chomp!")); - }, $String_chomp$excl$3.$$arity = -1); - - Opal.def(self, '$chop!', $String_chop$excl$4 = function($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("chop!")); - }, $String_chop$excl$4.$$arity = -1); - - Opal.def(self, '$downcase!', $String_downcase$excl$5 = function($a) { - var $post_args, self = this; - - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("downcase!")); - }, $String_downcase$excl$5.$$arity = -1); - - Opal.def(self, '$gsub!', $String_gsub$excl$6 = function($a) { - var $post_args, self = this; + var self = $klass($base, $super, 'Enumerator'); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("gsub!")); - }, $String_gsub$excl$6.$$arity = -1); - - Opal.def(self, '$lstrip!', $String_lstrip$excl$7 = function($a) { - var $post_args, self = this; + var $nesting = [self].concat($parent_nesting); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("lstrip!")); - }, $String_lstrip$excl$7.$$arity = -1); - - Opal.def(self, '$next!', $String_next$excl$8 = function($a) { - var $post_args, self = this; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Generator'); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("next!")); - }, $String_next$excl$8.$$arity = -1); - - Opal.def(self, '$reverse!', $String_reverse$excl$9 = function($a) { - var $post_args, self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.block = nil; + self.$include($$$('Enumerable')); - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("reverse!")); - }, $String_reverse$excl$9.$$arity = -1); - - Opal.def(self, '$slice!', $String_slice$excl$10 = function($a) { - var $post_args, self = this; + $def(self, '$initialize', function $$initialize() { + var block = $$initialize.$$p || nil, self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("slice!")); - }, $String_slice$excl$10.$$arity = -1); - - Opal.def(self, '$squeeze!', $String_squeeze$excl$11 = function($a) { - var $post_args, self = this; + $$initialize.$$p = null; + $deny_frozen_access(self); + if (!$truthy(block)) { + $Kernel.$raise($$$('LocalJumpError'), "no block given"); + } return (self.block = block); + }); + return $def(self, '$each', function $$each($a) { + var block = $$each.$$p || nil, $post_args, args, self = this, yielder = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("squeeze!")); - }, $String_squeeze$excl$11.$$arity = -1); - - Opal.def(self, '$strip!', $String_strip$excl$12 = function($a) { - var $post_args, self = this; + $$each.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + yielder = $send($$('Yielder'), 'new', [], block.$to_proc()); + + try { + args.unshift(yielder); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("strip!")); - }, $String_strip$excl$12.$$arity = -1); - - Opal.def(self, '$sub!', $String_sub$excl$13 = function($a) { - var $post_args, self = this; + Opal.yieldX(self.block, args); + } + catch (e) { + if (e && e.$thrower_type == "breaker") { + return e.$v; + } + else { + throw e; + } + } + return self; + }, -1); + })($nesting[0], null, $nesting) + })($nesting[0], null, $nesting) +}; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("sub!")); - }, $String_sub$excl$13.$$arity = -1); - - Opal.def(self, '$succ!', $String_succ$excl$14 = function($a) { - var $post_args, self = this; +Opal.modules["corelib/enumerator/lazy"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $yield1 = Opal.yield1, $yieldX = Opal.yieldX, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $defs = Opal.defs, $Kernel = Opal.Kernel, $send = Opal.send, $def = Opal.def, $return_self = Opal.return_self, $Opal = Opal.Opal, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("succ!")); - }, $String_succ$excl$14.$$arity = -1); - - Opal.def(self, '$swapcase!', $String_swapcase$excl$15 = function($a) { - var $post_args, self = this; + Opal.add_stubs('raise,each,new,enumerator_size,yield,respond_to?,try_convert,<,===,+,for,class,to_proc,destructure,inspect,to_a,find_all,collect_concat,collect,enum_for'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Enumerator'); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("swapcase!")); - }, $String_swapcase$excl$15.$$arity = -1); - - Opal.def(self, '$tr!', $String_tr$excl$16 = function($a) { - var $post_args, self = this; + var $nesting = [self].concat($parent_nesting); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("tr!")); - }, $String_tr$excl$16.$$arity = -1); - - Opal.def(self, '$tr_s!', $String_tr_s$excl$17 = function($a) { - var $post_args, self = this; + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Lazy'); - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("tr_s!")); - }, $String_tr_s$excl$17.$$arity = -1); - - Opal.def(self, '$upcase!', $String_upcase$excl$18 = function($a) { - var $post_args, self = this; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + $proto.enumerator = nil; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("upcase!")); - }, $String_upcase$excl$18.$$arity = -1); - - Opal.def(self, '$prepend', $String_prepend$19 = function $$prepend($a) { - var $post_args, self = this; + $klass(self, $$$('Exception'), 'StopLazyError'); + $defs(self, '$for', function $Lazy_for$1(object, $a) { + var $post_args, $fwd_rest, $yield = $Lazy_for$1.$$p || nil, self = this, lazy = nil; + $Lazy_for$1.$$p = null; + + $post_args = $slice(arguments, 1); + $fwd_rest = $post_args; + lazy = $send2(self, $find_super(self, 'for', $Lazy_for$1, false, true), 'for', [object].concat($to_a($fwd_rest)), $yield); + lazy.enumerator = object; + return lazy; + }, -2); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("prepend")); - }, $String_prepend$19.$$arity = -1); - - Opal.def(self, '$[]=', $String_$$$eq$20 = function($a) { - var $post_args, self = this; + $def(self, '$initialize', function $$initialize(object, size) { + var block = $$initialize.$$p || nil, self = this; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("[]=")); - }, $String_$$$eq$20.$$arity = -1); - - Opal.def(self, '$clear', $String_clear$21 = function $$clear($a) { - var $post_args, self = this; + $$initialize.$$p = null; + if (size == null) size = nil; + $deny_frozen_access(self); + if (!(block !== nil)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy new without a block"); + } self.enumerator = object; + return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [size], function $$2(yielder, $a){var $post_args, each_args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("clear")); - }, $String_clear$21.$$arity = -1); - - Opal.def(self, '$encode!', $String_encode$excl$22 = function($a) { - var $post_args, self = this; + + if (yielder == null) yielder = nil; + $post_args = $slice(arguments, 1); + each_args = $post_args; + try { + return $send(object, 'each', $to_a(each_args), function $$3($b){var $post_args, args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("encode!")); - }, $String_encode$excl$22.$$arity = -1); - return (Opal.def(self, '$unicode_normalize!', $String_unicode_normalize$excl$23 = function($a) { - var $post_args, self = this; + + $post_args = $slice(arguments); + args = $post_args; + + args.unshift(yielder); + $yieldX(block, args); + ;}, -1) + } catch ($err) { + if (Opal.rescue($err, [$$('StopLazyError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + }}, -2); + }, -2); + $def(self, '$lazy', $return_self); - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), (ERROR)['$%']("unicode_normalize!")); - }, $String_unicode_normalize$excl$23.$$arity = -1), nil) && 'unicode_normalize!'; - })($nesting[0], null, $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); + $def(self, '$collect', function $$collect() { + var block = $$collect.$$p || nil, self = this; - var $nesting = [self].concat($parent_nesting), $Kernel_freeze$24, $Kernel_frozen$ques$25; + $$collect.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy map without a block"); + } return $send($$('Lazy'), 'new', [self, self.$enumerator_size()], function $$4(enum$, $a){var $post_args, args; - - var ERROR = "Object freezing is not supported by Opal"; - - Opal.def(self, '$freeze', $Kernel_freeze$24 = function $$freeze() { - var self = this; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var value = $yieldX(block, args); + enum$.$yield(value); +}, -2); + }); - handle_unsupported_feature(ERROR); - return self; - }, $Kernel_freeze$24.$$arity = 0); - - Opal.def(self, '$frozen?', $Kernel_frozen$ques$25 = function() { - var self = this; + $def(self, '$collect_concat', function $$collect_concat() { + var block = $$collect_concat.$$p || nil, self = this; - - handle_unsupported_feature(ERROR); - return false; - }, $Kernel_frozen$ques$25.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); + $$collect_concat.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy map without a block"); + } return $send($$('Lazy'), 'new', [self, nil], function $$5(enum$, $a){var $post_args, args; - var $nesting = [self].concat($parent_nesting), $Kernel_taint$26, $Kernel_untaint$27, $Kernel_tainted$ques$28; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var value = $yieldX(block, args); - - var ERROR = "Object tainting is not supported by Opal"; - - Opal.def(self, '$taint', $Kernel_taint$26 = function $$taint() { - var self = this; + if ((value)['$respond_to?']("force") && (value)['$respond_to?']("each")) { + $send((value), 'each', [], function $$6(v){ + + if (v == null) v = nil; + return enum$.$yield(v);}); + } + else { + var array = $Opal.$try_convert(value, $$$('Array'), "to_ary"); + if (array === nil) { + enum$.$yield(value); + } + else { + $send((value), 'each', [], function $$7(v){ + + if (v == null) v = nil; + return enum$.$yield(v);}); + } + } +}, -2); + }); - handle_unsupported_feature(ERROR); - return self; - }, $Kernel_taint$26.$$arity = 0); - - Opal.def(self, '$untaint', $Kernel_untaint$27 = function $$untaint() { - var self = this; + $def(self, '$drop', function $$drop(n) { + var self = this, current_size = nil, set_size = nil, dropped = nil; - - handle_unsupported_feature(ERROR); - return self; - }, $Kernel_untaint$27.$$arity = 0); - - Opal.def(self, '$tainted?', $Kernel_tainted$ques$28 = function() { - var self = this; + + n = $coerce_to(n, $$$('Integer'), 'to_int'); + if ($truthy($rb_lt(n, 0))) { + $Kernel.$raise($$$('ArgumentError'), "attempt to drop negative size"); + } current_size = self.$enumerator_size(); + set_size = ($eqeqeq($$$('Integer'), current_size) ? (($truthy($rb_lt(n, current_size)) ? (n) : (current_size))) : (current_size)); + dropped = 0; + return $send($$('Lazy'), 'new', [self, set_size], function $$8(enum$, $a){var $post_args, args; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + if ($truthy($rb_lt(dropped, n))) { + return (dropped = $rb_plus(dropped, 1)) + } else { + return $send(enum$, 'yield', $to_a(args)) + }}, -2); + }); - handle_unsupported_feature(ERROR); - return false; - }, $Kernel_tainted$ques$28.$$arity = 0); - })($nesting[0], $nesting); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Module'); + $def(self, '$drop_while', function $$drop_while() { + var block = $$drop_while.$$p || nil, self = this, succeeding = nil; - var $nesting = [self].concat($parent_nesting), $Module_public$29, $Module_private_class_method$30, $Module_private_method_defined$ques$31, $Module_private_constant$32; + $$drop_while.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy drop_while without a block"); + } succeeding = true; + return $send($$('Lazy'), 'new', [self, nil], function $$9(enum$, $a){var $post_args, args; - - - Opal.def(self, '$public', $Module_public$29 = function($a) { - var $post_args, methods, self = this; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + if ($truthy(succeeding)) { + + var value = $yieldX(block, args); + if (!$truthy(value)) { + succeeding = false; + + $send(enum$, 'yield', $to_a(args)); + } + + } else { + return $send(enum$, 'yield', $to_a(args)) + }}, -2); + }); + $def(self, '$enum_for', function $$enum_for($a, $b) { + var block = $$enum_for.$$p || nil, $post_args, method, args, self = this; + + $$enum_for.$$p = null; + $post_args = $slice(arguments); + + if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each"; + args = $post_args; + return $send(self.$class(), 'for', [self, method].concat($to_a(args)), block.$to_proc()); + }, -1); - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - methods = $post_args;; - - if (methods.length === 0) { - self.$$module_function = false; - } + $def(self, '$find_all', function $$find_all() { + var block = $$find_all.$$p || nil, self = this; - return nil; - ; - }, $Module_public$29.$$arity = -1); - Opal.alias(self, "private", "public"); - Opal.alias(self, "protected", "public"); - Opal.alias(self, "nesting", "public"); - - Opal.def(self, '$private_class_method', $Module_private_class_method$30 = function $$private_class_method($a) { - var $post_args, self = this; + $$find_all.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy select without a block"); + } return $send($$('Lazy'), 'new', [self, nil], function $$10(enum$, $a){var $post_args, args; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var value = $yieldX(block, args); + + if ($truthy(value)) { + $send(enum$, 'yield', $to_a(args)); + } +}, -2); + }); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self; - }, $Module_private_class_method$30.$$arity = -1); - Opal.alias(self, "public_class_method", "private_class_method"); - - Opal.def(self, '$private_method_defined?', $Module_private_method_defined$ques$31 = function(obj) { - var self = this; + $def(self, '$grep', function $$grep(pattern) { + var block = $$grep.$$p || nil, self = this; - return false - }, $Module_private_method_defined$ques$31.$$arity = 1); - - Opal.def(self, '$private_constant', $Module_private_constant$32 = function $$private_constant($a) { - var $post_args, self = this; + $$grep.$$p = null; + if ($truthy(block)) { + return $send($$('Lazy'), 'new', [self, nil], function $$11(enum$, $a){var $post_args, args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $Module_private_constant$32.$$arity = -1); - Opal.alias(self, "protected_method_defined?", "private_method_defined?"); - Opal.alias(self, "public_instance_methods", "instance_methods"); - Opal.alias(self, "public_instance_method", "instance_method"); - return Opal.alias(self, "public_method_defined?", "method_defined?"); - })($nesting[0], null, $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var param = $Opal.$destructure(args), + value = pattern['$==='](param); - var $nesting = [self].concat($parent_nesting), $Kernel_private_methods$33; + if ($truthy(value)) { + value = $yield1(block, param); - - - Opal.def(self, '$private_methods', $Kernel_private_methods$33 = function $$private_methods($a) { - var $post_args, self = this; + enum$.$yield($yield1(block, param)); + } +}, -2) + } else { + return $send($$('Lazy'), 'new', [self, nil], function $$12(enum$, $a){var $post_args, args; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var param = $Opal.$destructure(args), + value = pattern['$==='](param); + + if ($truthy(value)) { + enum$.$yield(param); + } +}, -2) + } }); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return []; - }, $Kernel_private_methods$33.$$arity = -1); - Opal.alias(self, "private_instance_methods", "private_methods"); - })($nesting[0], $nesting); - (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); + $def(self, '$reject', function $$reject() { + var block = $$reject.$$p || nil, self = this; - var $nesting = [self].concat($parent_nesting), $Kernel_eval$34; + $$reject.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy reject without a block"); + } return $send($$('Lazy'), 'new', [self, nil], function $$13(enum$, $a){var $post_args, args; - - Opal.def(self, '$eval', $Kernel_eval$34 = function($a) { - var $post_args, self = this; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var value = $yieldX(block, args); + if (!$truthy(value)) { + $send(enum$, 'yield', $to_a(args)); + } +}, -2); + }); - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return self.$raise($$($nesting, 'NotImplementedError'), "" + "To use Kernel#eval, you must first require 'opal-parser'. " + ("" + "See https://github.com/opal/opal/blob/" + ($$($nesting, 'RUBY_ENGINE_VERSION')) + "/docs/opal_parser.md for details.")); - }, $Kernel_eval$34.$$arity = -1) - })($nesting[0], $nesting); - Opal.defs(self, '$public', $public$35 = function($a) { - var $post_args, self = this; + $def(self, '$take', function $$take(n) { + var self = this, current_size = nil, set_size = nil, taken = nil; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $public$35.$$arity = -1); - return (Opal.defs(self, '$private', $private$36 = function($a) { - var $post_args, self = this; + + n = $coerce_to(n, $$$('Integer'), 'to_int'); + if ($truthy($rb_lt(n, 0))) { + $Kernel.$raise($$$('ArgumentError'), "attempt to take negative size"); + } current_size = self.$enumerator_size(); + set_size = ($eqeqeq($$$('Integer'), current_size) ? (($truthy($rb_lt(n, current_size)) ? (n) : (current_size))) : (current_size)); + taken = 0; + return $send($$('Lazy'), 'new', [self, set_size], function $$14(enum$, $a){var $post_args, args; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - ; - return nil; - }, $private$36.$$arity = -1), nil) && 'private'; -}; + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + if ($truthy($rb_lt(taken, n))) { + + $send(enum$, 'yield', $to_a(args)); + return (taken = $rb_plus(taken, 1)); + } else { + return $Kernel.$raise($$('StopLazyError')) + }}, -2); + }); + + $def(self, '$take_while', function $$take_while() { + var block = $$take_while.$$p || nil, self = this; -/* Generated by Opal 0.11.99.dev */ -(function(Opal) { - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice; + $$take_while.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to call lazy take_while without a block"); + } return $send($$('Lazy'), 'new', [self, nil], function $$15(enum$, $a){var $post_args, args; - Opal.add_stubs(['$require']); - - self.$require("opal/base"); - self.$require("opal/mini"); - self.$require("corelib/string/encoding"); - self.$require("corelib/struct"); - self.$require("corelib/io"); - self.$require("corelib/main"); - self.$require("corelib/dir"); - self.$require("corelib/file"); - self.$require("corelib/process"); - return self.$require("corelib/unsupported"); -})(Opal); + + if (enum$ == null) enum$ = nil; + $post_args = $slice(arguments, 1); + args = $post_args; + + var value = $yieldX(block, args); + if ($truthy(value)) { + $send(enum$, 'yield', $to_a(args)); + } + else { + $Kernel.$raise($$('StopLazyError')); + } +}, -2); + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; -/***/ }), + return "#<" + (self.$class()) + ": " + (self.enumerator.$inspect()) + ">" + }); + $alias(self, "force", "to_a"); + $alias(self, "filter", "find_all"); + $alias(self, "flat_map", "collect_concat"); + $alias(self, "map", "collect"); + $alias(self, "select", "find_all"); + return $alias(self, "to_enum", "enum_for"); + })(self, self, $nesting) + })('::', null, $nesting) +}; -/***/ 4007: -/***/ (() => { +Opal.modules["corelib/enumerator/yielder"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["corelib/comparable"] = function(Opal) { - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_lt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs < rhs : lhs['$<'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $truthy = Opal.truthy; + Opal.add_stubs('yield,proc'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Enumerator'); - Opal.add_stubs(['$===', '$>', '$<', '$equal?', '$<=>', '$normalize', '$raise', '$class']); - return (function($base, $parent_nesting) { - var self = $module($base, 'Comparable'); + var $nesting = [self].concat($parent_nesting); - var $nesting = [self].concat($parent_nesting), $Comparable_normalize$1, $Comparable_$eq_eq$2, $Comparable_$gt$3, $Comparable_$gt_eq$4, $Comparable_$lt$5, $Comparable_$lt_eq$6, $Comparable_between$ques$7, $Comparable_clamp$8; + return (function($base, $super) { + var self = $klass($base, $super, 'Yielder'); - - Opal.defs(self, '$normalize', $Comparable_normalize$1 = function $$normalize(what) { - var self = this; + var $proto = self.$$prototype; + $proto.block = nil; - if ($truthy($$($nesting, 'Integer')['$==='](what))) { - return what}; - if ($truthy($rb_gt(what, 0))) { - return 1}; - if ($truthy($rb_lt(what, 0))) { - return -1}; - return 0; - }, $Comparable_normalize$1.$$arity = 1); - - Opal.def(self, '$==', $Comparable_$eq_eq$2 = function(other) { - var self = this, cmp = nil; + + $def(self, '$initialize', function $$initialize() { + var block = $$initialize.$$p || nil, self = this; + + $$initialize.$$p = null; + self.block = block; + return self; + }); + + $def(self, '$yield', function $Yielder_yield$1($a) { + var $post_args, values, self = this; - try { - if ($truthy(self['$equal?'](other))) { - return true}; + $post_args = $slice(arguments); + values = $post_args; - if (self["$<=>"] == Opal.Kernel["$<=>"]) { - return false; - } - - // check for infinite recursion - if (self.$$comparable) { - delete self.$$comparable; - return false; - } - ; - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - return false - }; - return $$($nesting, 'Comparable').$normalize(cmp) == 0; - } catch ($err) { - if (Opal.rescue($err, [$$($nesting, 'StandardError')])) { - try { - return false - } finally { Opal.pop_exception() } - } else { throw $err; } - } - }, $Comparable_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$>', $Comparable_$gt$3 = function(other) { - var self = this, cmp = nil; - - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) > 0; - }, $Comparable_$gt$3.$$arity = 1); - - Opal.def(self, '$>=', $Comparable_$gt_eq$4 = function(other) { - var self = this, cmp = nil; + var value = Opal.yieldX(self.block, values); - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) >= 0; - }, $Comparable_$gt_eq$4.$$arity = 1); - - Opal.def(self, '$<', $Comparable_$lt$5 = function(other) { - var self = this, cmp = nil; + if (value && value.$thrower_type == "break") { + throw value; + } + return value; + }, -1); - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) < 0; - }, $Comparable_$lt$5.$$arity = 1); - - Opal.def(self, '$<=', $Comparable_$lt_eq$6 = function(other) { - var self = this, cmp = nil; + $def(self, '$<<', function $Yielder_$lt$lt$2(value) { + var self = this; - - if ($truthy((cmp = self['$<=>'](other)))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") - }; - return $$($nesting, 'Comparable').$normalize(cmp) <= 0; - }, $Comparable_$lt_eq$6.$$arity = 1); - - Opal.def(self, '$between?', $Comparable_between$ques$7 = function(min, max) { - var self = this; + + self.$yield(value); + return self; + }); + return $def(self, '$to_proc', function $$to_proc() { + var self = this; - - if ($rb_lt(self, min)) { - return false}; - if ($rb_gt(self, max)) { - return false}; - return true; - }, $Comparable_between$ques$7.$$arity = 2); - - Opal.def(self, '$clamp', $Comparable_clamp$8 = function $$clamp(min, max) { - var self = this, cmp = nil; + return $send(self, 'proc', [], function $$3($a){var $post_args, values, self = $$3.$$s == null ? this : $$3.$$s; - - cmp = min['$<=>'](max); - if ($truthy(cmp)) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "comparison of " + (min.$class()) + " with " + (max.$class()) + " failed") - }; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(cmp), 0))) { - self.$raise($$($nesting, 'ArgumentError'), "min argument must be smaller than max argument")}; - if ($truthy($rb_lt($$($nesting, 'Comparable').$normalize(self['$<=>'](min)), 0))) { - return min}; - if ($truthy($rb_gt($$($nesting, 'Comparable').$normalize(self['$<=>'](max)), 0))) { - return max}; - return self; - }, $Comparable_clamp$8.$$arity = 2); - })($nesting[0], $nesting) + + $post_args = $slice(arguments); + values = $post_args; + return $send(self, 'yield', $to_a(values));}, {$$arity: -1, $$s: self}) + }); + })($nesting[0], null) + })($nesting[0], null, $nesting) }; -/* Generated by Opal 0.11.99.dev */ -Opal.modules["pathname"] = function(Opal) { - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $send = Opal.send, $module = Opal.module; +Opal.modules["corelib/enumerator"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $slice = Opal.slice, $coerce_to = Opal.coerce_to, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $defs = Opal.defs, $truthy = Opal.truthy, $send = Opal.send, $not = Opal.not, $def = Opal.def, $rb_plus = Opal.rb_plus, $to_a = Opal.to_a, $Opal = Opal.Opal, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_ge = Opal.rb_ge, $Kernel = Opal.Kernel, $rb_le = Opal.rb_le, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - Opal.add_stubs(['$require', '$include', '$quote', '$===', '$to_s', '$path', '$respond_to?', '$to_path', '$is_a?', '$nil?', '$raise', '$class', '$==', '$attr_reader', '$!', '$relative?', '$chop_basename', '$basename', '$=~', '$new', '$source', '$[]', '$rindex', '$sub', '$absolute?', '$expand_path', '$plus', '$unshift', '$length', '$!=', '$empty?', '$first', '$shift', '$+', '$join', '$dirname', '$pop', '$reverse_each', '$directory?', '$extname', '$<=>', '$nonzero?', '$proc', '$casecmp', '$cleanpath', '$inspect', '$include?', '$fill', '$map', '$entries']); + Opal.add_stubs('require,include,allocate,new,to_proc,!,respond_to?,empty?,nil?,+,class,__send__,call,enum_for,size,destructure,map,>=,length,raise,[],peek_values,<=,next_values,inspect,any?,each_with_object,autoload'); - self.$require("corelib/comparable"); - (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'Pathname'); + self.$require("corelib/enumerable"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Enumerator'); - var $nesting = [self].concat($parent_nesting), $Pathname_initialize$1, $Pathname_$eq_eq$2, $Pathname_absolute$ques$3, $Pathname_relative$ques$4, $Pathname_chop_basename$5, $Pathname_root$ques$6, $Pathname_parent$7, $Pathname_sub$8, $Pathname_cleanpath$9, $Pathname_to_path$10, $Pathname_hash$11, $Pathname_expand_path$12, $Pathname_$plus$13, $Pathname_plus$14, $Pathname_join$15, $Pathname_split$17, $Pathname_dirname$18, $Pathname_basename$19, $Pathname_directory$ques$20, $Pathname_extname$21, $Pathname_$lt_eq_gt$22, $Pathname$23, $Pathname$24, $Pathname_relative_path_from$25, $Pathname_entries$26; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - self.$$prototype.path = nil; - - self.$include($$($nesting, 'Comparable')); - Opal.const_set($nesting[0], 'SEPARATOR_PAT', new RegExp($$($nesting, 'Regexp').$quote($$$($$($nesting, 'File'), 'SEPARATOR')))); + $proto.size = $proto.args = $proto.object = $proto.method = $proto.values = $proto.cursor = nil; - Opal.def(self, '$initialize', $Pathname_initialize$1 = function $$initialize(path) { - var self = this; + self.$include($$$('Enumerable')); + self.$$prototype.$$is_enumerator = true; + $defs(self, '$for', function $Enumerator_for$1(object, $a, $b) { + var block = $Enumerator_for$1.$$p || nil, $post_args, method, args, self = this; + $Enumerator_for$1.$$p = null; + $post_args = $slice(arguments, 1); - if ($truthy($$($nesting, 'Pathname')['$==='](path))) { - self.path = path.$path().$to_s() - } else if ($truthy(path['$respond_to?']("to_path"))) { - self.path = path.$to_path() - } else if ($truthy(path['$is_a?']($$($nesting, 'String')))) { - self.path = path - } else if ($truthy(path['$nil?']())) { - self.$raise($$($nesting, 'TypeError'), "no implicit conversion of nil into String") - } else { - self.$raise($$($nesting, 'TypeError'), "" + "no implicit conversion of " + (path.$class()) + " into String") - }; - if (self.path['$==']("\u0000")) { - return self.$raise($$($nesting, 'ArgumentError')) - } else { - return nil - }; - }, $Pathname_initialize$1.$$arity = 1); - self.$attr_reader("path"); - - Opal.def(self, '$==', $Pathname_$eq_eq$2 = function(other) { - var self = this; + if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each"; + args = $post_args; + + var obj = self.$allocate(); - return other.$path()['$=='](self.path) - }, $Pathname_$eq_eq$2.$$arity = 1); - - Opal.def(self, '$absolute?', $Pathname_absolute$ques$3 = function() { - var self = this; + obj.object = object; + obj.size = block; + obj.method = method; + obj.args = args; + obj.cursor = 0; - return self['$relative?']()['$!']() - }, $Pathname_absolute$ques$3.$$arity = 0); + return obj; + }, -2); - Opal.def(self, '$relative?', $Pathname_relative$ques$4 = function() { - var $a, $b, $c, self = this, path = nil, r = nil; + $def(self, '$initialize', function $$initialize($a) { + var block = $$initialize.$$p || nil, self = this; - - path = self.path; - while ($truthy((r = self.$chop_basename(path)))) { - $c = r, $b = Opal.to_ary($c), (path = ($b[0] == null ? nil : $b[0])), $c - }; - return path['$=='](""); - }, $Pathname_relative$ques$4.$$arity = 0); + $$initialize.$$p = null; + $slice(arguments); + $deny_frozen_access(self); + self.cursor = 0; + if ($truthy(block)) { + + self.object = $send($$('Generator'), 'new', [], block.$to_proc()); + self.method = "each"; + self.args = []; + self.size = arguments[0] || nil; + if (($truthy(self.size) && ($not(self.size['$respond_to?']("call"))))) { + return (self.size = $coerce_to(self.size, $$$('Integer'), 'to_int')) + } else { + return nil + } } else { + + self.object = arguments[0]; + self.method = arguments[1] || "each"; + self.args = $slice(arguments, 2); + return (self.size = nil); + } }, -1); - Opal.def(self, '$chop_basename', $Pathname_chop_basename$5 = function $$chop_basename(path) { - var self = this, base = nil; + $def(self, '$each', function $$each($a) { + var block = $$each.$$p || nil, $post_args, args, self = this; - - base = $$($nesting, 'File').$basename(path); - if ($truthy($$($nesting, 'Regexp').$new("" + "^" + ($$$($$($nesting, 'Pathname'), 'SEPARATOR_PAT').$source()) + "?$")['$=~'](base))) { - return nil - } else { - return [path['$[]'](0, path.$rindex(base)), base] - }; - }, $Pathname_chop_basename$5.$$arity = 1); + $$each.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (($truthy(block['$nil?']()) && ($truthy(args['$empty?']())))) { + return self + } args = $rb_plus(self.args, args); + if ($truthy(block['$nil?']())) { + return $send(self.$class(), 'new', [self.object, self.method].concat($to_a(args))) + } return $send(self.object, '__send__', [self.method].concat($to_a(args)), block.$to_proc()); + }, -1); - Opal.def(self, '$root?', $Pathname_root$ques$6 = function() { + $def(self, '$size', function $$size() { var self = this; - return self.path['$==']("/") - }, $Pathname_root$ques$6.$$arity = 0); + if ($truthy(self.size['$respond_to?']("call"))) { + return $send(self.size, 'call', $to_a(self.args)) + } else { + return self.size + } + }); - Opal.def(self, '$parent', $Pathname_parent$7 = function $$parent() { - var self = this, new_path = nil; + $def(self, '$with_index', function $$with_index(offset) { + var block = $$with_index.$$p || nil, self = this; - - new_path = self.path.$sub(/\/([^\/]+\/?$)/, ""); - if (new_path['$==']("")) { - new_path = (function() {if ($truthy(self['$absolute?']())) { - return "/" - } else { - return "." - }; return nil; })()}; - return $$($nesting, 'Pathname').$new(new_path); - }, $Pathname_parent$7.$$arity = 0); - - Opal.def(self, '$sub', $Pathname_sub$8 = function $$sub($a) { - var $post_args, args, self = this; + $$with_index.$$p = null; + if (offset == null) offset = 0; + offset = ($truthy(offset) ? ($coerce_to(offset, $$$('Integer'), 'to_int')) : (0)); + if (!$truthy(block)) { + return $send(self, 'enum_for', ["with_index", offset], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s; - - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - return $$($nesting, 'Pathname').$new($send(self.path, 'sub', Opal.to_a(args))); - }, $Pathname_sub$8.$$arity = -1); - - Opal.def(self, '$cleanpath', $Pathname_cleanpath$9 = function $$cleanpath() { - var self = this; + return self.$size()}, {$$s: self}) + } + var index = offset; - return Opal.normalize(self.path) - }, $Pathname_cleanpath$9.$$arity = 0); - - Opal.def(self, '$to_path', $Pathname_to_path$10 = function $$to_path() { - var self = this; + self.$each.$$p = function() { + var param = $Opal.$destructure(arguments), + value = block(param, index); - return self.path - }, $Pathname_to_path$10.$$arity = 0); - - Opal.def(self, '$hash', $Pathname_hash$11 = function $$hash() { - var self = this; + index++; + + return value; + }; - return self.path - }, $Pathname_hash$11.$$arity = 0); + return self.$each(); + }, -1); - Opal.def(self, '$expand_path', $Pathname_expand_path$12 = function $$expand_path() { - var self = this; + $def(self, '$each_with_index', function $$each_with_index() { + var block = $$each_with_index.$$p || nil, self = this; + + $$each_with_index.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_with_index"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s; - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$expand_path(self.path)) - }, $Pathname_expand_path$12.$$arity = 0); + return self.$size()}, {$$s: self}) + } $send2(self, $find_super(self, 'each_with_index', $$each_with_index, false, true), 'each_with_index', [], block); + return self.object; + }); - Opal.def(self, '$+', $Pathname_$plus$13 = function(other) { + $def(self, '$rewind', function $$rewind() { var self = this; - if ($truthy($$($nesting, 'Pathname')['$==='](other))) { - } else { - other = $$($nesting, 'Pathname').$new(other) - }; - return $$($nesting, 'Pathname').$new(self.$plus(self.path, other.$to_s())); - }, $Pathname_$plus$13.$$arity = 1); + self.cursor = 0; + return self; + }); - Opal.def(self, '$plus', $Pathname_plus$14 = function $$plus(path1, path2) { - var $a, $b, $c, self = this, prefix2 = nil, index_list2 = nil, basename_list2 = nil, r2 = nil, basename2 = nil, prefix1 = nil, r1 = nil, basename1 = nil, suffix2 = nil; + $def(self, '$peek_values', function $$peek_values() { + var self = this, $ret_or_1 = nil; - prefix2 = path2; - index_list2 = []; - basename_list2 = []; - while ($truthy((r2 = self.$chop_basename(prefix2)))) { - - $c = r2, $b = Opal.to_ary($c), (prefix2 = ($b[0] == null ? nil : $b[0])), (basename2 = ($b[1] == null ? nil : $b[1])), $c; - index_list2.$unshift(prefix2.$length()); - basename_list2.$unshift(basename2); - }; - if ($truthy(prefix2['$!='](""))) { - return path2}; - prefix1 = path1; - while ($truthy(true)) { - - while ($truthy(($truthy($c = basename_list2['$empty?']()['$!']()) ? basename_list2.$first()['$=='](".") : $c))) { - - index_list2.$shift(); - basename_list2.$shift(); - }; - if ($truthy((r1 = self.$chop_basename(prefix1)))) { - } else { - break; - }; - $c = r1, $b = Opal.to_ary($c), (prefix1 = ($b[0] == null ? nil : $b[0])), (basename1 = ($b[1] == null ? nil : $b[1])), $c; - if (basename1['$=='](".")) { - continue;}; - if ($truthy(($truthy($b = ($truthy($c = basename1['$==']("..")) ? $c : basename_list2['$empty?']())) ? $b : basename_list2.$first()['$!=']("..")))) { - - prefix1 = $rb_plus(prefix1, basename1); - break;;}; - index_list2.$shift(); - basename_list2.$shift(); - }; - r1 = self.$chop_basename(prefix1); - if ($truthy(($truthy($a = r1['$!']()) ? new RegExp($$($nesting, 'SEPARATOR_PAT'))['$=~']($$($nesting, 'File').$basename(prefix1)) : $a))) { - while ($truthy(($truthy($b = basename_list2['$empty?']()['$!']()) ? basename_list2.$first()['$==']("..") : $b))) { - - index_list2.$shift(); - basename_list2.$shift(); - }}; - if ($truthy(basename_list2['$empty?']()['$!']())) { + self.values = ($truthy(($ret_or_1 = self.values)) ? ($ret_or_1) : ($send(self, 'map', [], function $$4($a){var $post_args, i; + - suffix2 = path2['$[]'](Opal.Range.$new(index_list2.$first(), -1, false)); - if ($truthy(r1)) { - return $$($nesting, 'File').$join(prefix1, suffix2) - } else { - return $rb_plus(prefix1, suffix2) - }; - } else if ($truthy(r1)) { - return prefix1 - } else { - return $$($nesting, 'File').$dirname(prefix1) - }; - }, $Pathname_plus$14.$$arity = 2); + $post_args = $slice(arguments); + i = $post_args; + return i;}, -1))); + if ($truthy($rb_ge(self.cursor, self.values.$length()))) { + $Kernel.$raise($$$('StopIteration'), "iteration reached an end"); + } return self.values['$[]'](self.cursor); + }); - Opal.def(self, '$join', $Pathname_join$15 = function $$join($a) {try { - - var $post_args, args, $$16, self = this, result = nil; + $def(self, '$peek', function $$peek() { + var self = this, values = nil; - - $post_args = Opal.slice.call(arguments, 0, arguments.length); - - args = $post_args;; - if ($truthy(args['$empty?']())) { - return self}; - result = args.$pop(); - if ($truthy($$($nesting, 'Pathname')['$==='](result))) { + values = self.$peek_values(); + if ($truthy($rb_le(values.$length(), 1))) { + return values['$[]'](0) } else { - result = $$($nesting, 'Pathname').$new(result) - }; - if ($truthy(result['$absolute?']())) { - return result}; - $send(args, 'reverse_each', [], ($$16 = function(arg){var self = $$16.$$s || this; - - - - if (arg == null) { - arg = nil; - }; - if ($truthy($$($nesting, 'Pathname')['$==='](arg))) { - } else { - arg = $$($nesting, 'Pathname').$new(arg) - }; - result = $rb_plus(arg, result); - if ($truthy(result['$absolute?']())) { - Opal.ret(result) - } else { - return nil - };}, $$16.$$s = self, $$16.$$arity = 1, $$16)); - return $rb_plus(self, result); - } catch ($returner) { if ($returner === Opal.returner) { return $returner.$v } throw $returner; } - }, $Pathname_join$15.$$arity = -1); + return values + } }); - Opal.def(self, '$split', $Pathname_split$17 = function $$split() { - var self = this; + $def(self, '$next_values', function $$next_values() { + var self = this, out = nil; - return [self.$dirname(), self.$basename()] - }, $Pathname_split$17.$$arity = 0); + + out = self.$peek_values(); + self.cursor = $rb_plus(self.cursor, 1); + return out; + }); - Opal.def(self, '$dirname', $Pathname_dirname$18 = function $$dirname() { - var self = this; + $def(self, '$next', function $$next() { + var self = this, values = nil; - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$dirname(self.path)) - }, $Pathname_dirname$18.$$arity = 0); + + values = self.$next_values(); + if ($truthy($rb_le(values.$length(), 1))) { + return values['$[]'](0) + } else { + return values + } }); - Opal.def(self, '$basename', $Pathname_basename$19 = function $$basename() { + $def(self, '$feed', function $$feed(arg) { var self = this; - return $$($nesting, 'Pathname').$new($$($nesting, 'File').$basename(self.path)) - }, $Pathname_basename$19.$$arity = 0); + return self.$raise($$('NotImplementedError'), "Opal doesn't support Enumerator#feed") + }); - Opal.def(self, '$directory?', $Pathname_directory$ques$20 = function() { + $def(self, '$+', function $Enumerator_$plus$5(other) { var self = this; - return $$($nesting, 'File')['$directory?'](self.path) - }, $Pathname_directory$ques$20.$$arity = 0); + return $$$($$$('Enumerator'), 'Chain').$new(self, other) + }); - Opal.def(self, '$extname', $Pathname_extname$21 = function $$extname() { - var self = this; + $def(self, '$inspect', function $$inspect() { + var self = this, result = nil; - return $$($nesting, 'File').$extname(self.path) - }, $Pathname_extname$21.$$arity = 0); - - Opal.def(self, '$<=>', $Pathname_$lt_eq_gt$22 = function(other) { - var self = this; + + result = "#<" + (self.$class()) + ": " + (self.object.$inspect()) + ":" + (self.method); + if ($truthy(self.args['$any?']())) { + result = $rb_plus(result, "(" + (self.args.$inspect()['$[]']($$$('Range').$new(1, -2))) + ")"); + } return $rb_plus(result, ">"); + }); + $alias(self, "with_object", "each_with_object"); + self.$autoload("ArithmeticSequence", "corelib/enumerator/arithmetic_sequence"); + self.$autoload("Chain", "corelib/enumerator/chain"); + self.$autoload("Generator", "corelib/enumerator/generator"); + self.$autoload("Lazy", "corelib/enumerator/lazy"); + return self.$autoload("Yielder", "corelib/enumerator/yielder"); + })('::', null, $nesting); +}; - return self.$path()['$<=>'](other.$path()) - }, $Pathname_$lt_eq_gt$22.$$arity = 1); - Opal.alias(self, "eql?", "=="); - Opal.alias(self, "===", "=="); - Opal.alias(self, "to_str", "to_path"); - Opal.alias(self, "to_s", "to_path"); - Opal.const_set($nesting[0], 'SAME_PATHS', (function() {if ($truthy($$$($$($nesting, 'File'), 'FNM_SYSCASE')['$nonzero?']())) { - return $send(self, 'proc', [], ($Pathname$23 = function(a, b){var self = $Pathname$23.$$s || this; +Opal.modules["corelib/numeric"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $to_ary = Opal.to_ary, $return_self = Opal.return_self, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $rb_divide = Opal.rb_divide, $return_val = Opal.return_val, $Opal = Opal.Opal, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $not = Opal.not, $send = Opal.send, $rb_ge = Opal.rb_ge, $rb_le = Opal.rb_le, $rb_plus = Opal.rb_plus, $rb_gt = Opal.rb_gt, $alias = Opal.alias, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$; - - - if (a == null) { - a = nil; - }; - - if (b == null) { - b = nil; - }; - return a.$casecmp(b)['$=='](0);}, $Pathname$23.$$s = self, $Pathname$23.$$arity = 2, $Pathname$23)) - } else { - return $send(self, 'proc', [], ($Pathname$24 = function(a, b){var self = $Pathname$24.$$s || this; + Opal.add_stubs('require,include,instance_of?,class,Float,respond_to?,coerce,__send__,raise,equal?,-,*,div,<,-@,ceil,to_f,denominator,to_r,==,floor,/,%,Complex,zero?,numerator,abs,arg,coerce_to!,round,<=>,compare,is_a?,!,new,enum_for,to_proc,negative?,>=,<=,+,to_i,truncate,>,angle,conj,imag,rect'); + + self.$require("corelib/comparable"); + return (function($base, $super) { + var self = $klass($base, $super, 'Numeric'); - - - if (a == null) { - a = nil; - }; - - if (b == null) { - b = nil; - }; - return a['$=='](b);}, $Pathname$24.$$s = self, $Pathname$24.$$arity = 2, $Pathname$24)) - }; return nil; })()); - Opal.def(self, '$relative_path_from', $Pathname_relative_path_from$25 = function $$relative_path_from(base_directory) { - var $a, $b, $c, self = this, dest_directory = nil, dest_prefix = nil, dest_names = nil, r = nil, basename = nil, base_prefix = nil, base_names = nil, relpath_names = nil; + + self.$include($$$('Comparable')); + + $def(self, '$coerce', function $$coerce(other) { + var self = this; - dest_directory = self.$cleanpath().$to_s(); - base_directory = base_directory.$cleanpath().$to_s(); - dest_prefix = dest_directory; - dest_names = []; - while ($truthy((r = self.$chop_basename(dest_prefix)))) { - - $c = r, $b = Opal.to_ary($c), (dest_prefix = ($b[0] == null ? nil : $b[0])), (basename = ($b[1] == null ? nil : $b[1])), $c; - if ($truthy(basename['$!=']("."))) { - dest_names.$unshift(basename)}; - }; - base_prefix = base_directory; - base_names = []; - while ($truthy((r = self.$chop_basename(base_prefix)))) { - - $c = r, $b = Opal.to_ary($c), (base_prefix = ($b[0] == null ? nil : $b[0])), (basename = ($b[1] == null ? nil : $b[1])), $c; - if ($truthy(basename['$!=']("."))) { - base_names.$unshift(basename)}; - }; - if ($truthy($$($nesting, 'SAME_PATHS')['$[]'](dest_prefix, base_prefix))) { - } else { - self.$raise($$($nesting, 'ArgumentError'), "" + "different prefix: " + (dest_prefix.$inspect()) + " and " + (base_directory.$inspect())) - }; - while ($truthy(($truthy($b = ($truthy($c = dest_names['$empty?']()['$!']()) ? base_names['$empty?']()['$!']() : $c)) ? $$($nesting, 'SAME_PATHS')['$[]'](dest_names.$first(), base_names.$first()) : $b))) { - - dest_names.$shift(); - base_names.$shift(); - }; - if ($truthy(base_names['$include?'](".."))) { - self.$raise($$($nesting, 'ArgumentError'), "" + "base_directory has ..: " + (base_directory.$inspect()))}; - base_names.$fill(".."); - relpath_names = $rb_plus(base_names, dest_names); - if ($truthy(relpath_names['$empty?']())) { - return $$($nesting, 'Pathname').$new(".") - } else { - return $$($nesting, 'Pathname').$new($send($$($nesting, 'File'), 'join', Opal.to_a(relpath_names))) - }; - }, $Pathname_relative_path_from$25.$$arity = 1); - return (Opal.def(self, '$entries', $Pathname_entries$26 = function $$entries() { - var $$27, self = this; - - return $send($$($nesting, 'Dir').$entries(self.path), 'map', [], ($$27 = function(f){var self = $$27.$$s || this; + if ($truthy(other['$instance_of?'](self.$class()))) { + return [other, self] + } return [$Kernel.$Float(other), $Kernel.$Float(self)]; + }); + + $def(self, '$__coerced__', function $$__coerced__(method, other) { + var $a, $b, self = this, a = nil, b = nil; - + if ($truthy(other['$respond_to?']("coerce"))) { - if (f == null) { - f = nil; - }; - return self.$class().$new(f);}, $$27.$$s = self, $$27.$$arity = 1, $$27)) - }, $Pathname_entries$26.$$arity = 0), nil) && 'entries'; - })($nesting[0], null, $nesting); - return (function($base, $parent_nesting) { - var self = $module($base, 'Kernel'); - - var $nesting = [self].concat($parent_nesting), $Kernel_Pathname$28; - + $b = other.$coerce(self), $a = $to_ary($b), (a = ($a[0] == null ? nil : $a[0])), (b = ($a[1] == null ? nil : $a[1])); + return a.$__send__(method, b); + } else + switch (method) { + case "+": + case "-": + case "*": + case "/": + case "%": + case "&": + case "|": + case "^": + case "**": + return $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Numeric") + case ">": + case ">=": + case "<": + case "<=": + case "<=>": + return $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed") + default: + return nil + } + }); - Opal.def(self, '$Pathname', $Kernel_Pathname$28 = function $$Pathname(path) { + $def(self, '$<=>', function $Numeric_$lt_eq_gt$1(other) { var self = this; - return $$($nesting, 'Pathname').$new(path) - }, $Kernel_Pathname$28.$$arity = 1) - })($nesting[0], $nesting); -}; - - -/***/ }), - -/***/ 9442: -/***/ (() => { - -/* Generated by Opal 0.11.99.dev */ -Opal.modules["stringio"] = function(Opal) { - function $rb_ge(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs >= rhs : lhs['$>='](rhs); - } - function $rb_gt(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs > rhs : lhs['$>'](rhs); - } - function $rb_plus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs + rhs : lhs['$+'](rhs); - } - function $rb_minus(lhs, rhs) { - return (typeof(lhs) === 'number' && typeof(rhs) === 'number') ? lhs - rhs : lhs['$-'](rhs); - } - var self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.const_get_qualified, $$ = Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $gvars = Opal.gvars; - - Opal.add_stubs(['$include', '$new', '$call', '$close', '$attr_accessor', '$length', '$include?', '$!', '$check_readable', '$==', '$===', '$>=', '$raise', '$>', '$+', '$-', '$seek', '$enum_for', '$eof?', '$ord', '$[]', '$to_str', '$chomp', '$check_writable', '$String', '$write', '$closed_write?', '$closed_read?']); - return (function($base, $super, $parent_nesting) { - var self = $klass($base, $super, 'StringIO'); - - var $nesting = [self].concat($parent_nesting), $StringIO_open$1, $StringIO_initialize$2, $StringIO_eof$ques$3, $StringIO_seek$4, $StringIO_tell$5, $StringIO_rewind$6, $StringIO_each_byte$7, $StringIO_each_char$8, $StringIO_each$9, $StringIO_write$10, $StringIO_read$11, $StringIO_close$12, $StringIO_close_read$13, $StringIO_close_write$14, $StringIO_closed$ques$15, $StringIO_closed_read$ques$16, $StringIO_closed_write$ques$17, $StringIO_check_writable$18, $StringIO_check_readable$19; - - self.$$prototype.position = self.$$prototype.string = self.$$prototype.closed = nil; - - self.$include($$$($$($nesting, 'IO'), 'Readable')); - self.$include($$$($$($nesting, 'IO'), 'Writable')); - Opal.defs(self, '$open', $StringIO_open$1 = function $$open(string, mode) { - var $iter = $StringIO_open$1.$$p, block = $iter || nil, self = this, io = nil, res = nil; - - if ($iter) $StringIO_open$1.$$p = null; - - - if ($iter) $StringIO_open$1.$$p = null;; - - if (string == null) { - string = ""; - }; - if (mode == null) { - mode = nil; - }; - io = self.$new(string, mode); - res = block.$call(io); - io.$close(); - return res; - }, $StringIO_open$1.$$arity = -1); - self.$attr_accessor("string"); + if ($truthy(self['$equal?'](other))) { + return 0 + } return nil; + }); - Opal.def(self, '$initialize', $StringIO_initialize$2 = function $$initialize(string, mode) { - var $a, self = this; - - - - if (string == null) { - string = ""; - }; - - if (mode == null) { - mode = "rw"; - }; - self.string = string; - self.position = string.$length(); - if ($truthy(($truthy($a = mode['$include?']("r")) ? mode['$include?']("w")['$!']() : $a))) { - return (self.closed = "write") - } else if ($truthy(($truthy($a = mode['$include?']("w")) ? mode['$include?']("r")['$!']() : $a))) { - return (self.closed = "read") - } else { - return nil - }; - }, $StringIO_initialize$2.$$arity = -1); + $def(self, '$+@', $return_self); + + $def(self, '$-@', function $Numeric_$minus$$2() { + var self = this; + + return $rb_minus(0, self) + }); - Opal.def(self, '$eof?', $StringIO_eof$ques$3 = function() { + $def(self, '$%', function $Numeric_$percent$3(other) { var self = this; - - self.$check_readable(); - return self.position['$=='](self.string.$length()); - }, $StringIO_eof$ques$3.$$arity = 0); - Opal.alias(self, "eof", "eof?"); + return $rb_minus(self, $rb_times(other, self.$div(other))) + }); - Opal.def(self, '$seek', $StringIO_seek$4 = function $$seek(pos, whence) { - var self = this, $case = nil; + $def(self, '$abs', function $$abs() { + var self = this; - - - if (whence == null) { - whence = $$$($$($nesting, 'IO'), 'SEEK_SET'); - }; - $case = whence; - if ($$$($$($nesting, 'IO'), 'SEEK_SET')['$===']($case)) { - if ($truthy($rb_ge(pos, 0))) { - } else { - self.$raise($$$($$($nesting, 'Errno'), 'EINVAL')) - }; - self.position = pos;} - else if ($$$($$($nesting, 'IO'), 'SEEK_CUR')['$===']($case)) {if ($truthy($rb_gt($rb_plus(self.position, pos), self.string.$length()))) { - self.position = self.string.$length() - } else { - self.position = $rb_plus(self.position, pos) - }} - else if ($$$($$($nesting, 'IO'), 'SEEK_END')['$===']($case)) {if ($truthy($rb_gt(pos, self.string.$length()))) { - self.position = 0 + if ($rb_lt(self, 0)) { + return self['$-@']() } else { - self.position = $rb_minus(self.position, pos) - }}; - return 0; - }, $StringIO_seek$4.$$arity = -2); + return self + } + }); - Opal.def(self, '$tell', $StringIO_tell$5 = function $$tell() { + $def(self, '$abs2', function $$abs2() { var self = this; - return self.position - }, $StringIO_tell$5.$$arity = 0); - Opal.alias(self, "pos", "tell"); - Opal.alias(self, "pos=", "seek"); + return $rb_times(self, self) + }); - Opal.def(self, '$rewind', $StringIO_rewind$6 = function $$rewind() { + $def(self, '$angle', function $$angle() { var self = this; - return self.$seek(0) - }, $StringIO_rewind$6.$$arity = 0); + if ($rb_lt(self, 0)) { + return $$$($$$('Math'), 'PI') + } else { + return 0 + } + }); - Opal.def(self, '$each_byte', $StringIO_each_byte$7 = function $$each_byte() { - var $iter = $StringIO_each_byte$7.$$p, block = $iter || nil, $a, self = this, i = nil; + $def(self, '$ceil', function $$ceil(ndigits) { + var self = this; - if ($iter) $StringIO_each_byte$7.$$p = null; - - if ($iter) $StringIO_each_byte$7.$$p = null;; - if ($truthy(block)) { - } else { - return self.$enum_for("each_byte") - }; - self.$check_readable(); - i = self.position; - while (!($truthy(self['$eof?']()))) { - - block.$call(self.string['$[]'](i).$ord()); - i = $rb_plus(i, 1); - }; - return self; - }, $StringIO_each_byte$7.$$arity = 0); + if (ndigits == null) ndigits = 0; + return self.$to_f().$ceil(ndigits); + }, -1); - Opal.def(self, '$each_char', $StringIO_each_char$8 = function $$each_char() { - var $iter = $StringIO_each_char$8.$$p, block = $iter || nil, $a, self = this, i = nil; + $def(self, '$conj', $return_self); + + $def(self, '$denominator', function $$denominator() { + var self = this; - if ($iter) $StringIO_each_char$8.$$p = null; - - - if ($iter) $StringIO_each_char$8.$$p = null;; - if ($truthy(block)) { - } else { - return self.$enum_for("each_char") - }; - self.$check_readable(); - i = self.position; - while (!($truthy(self['$eof?']()))) { - - block.$call(self.string['$[]'](i)); - i = $rb_plus(i, 1); - }; - return self; - }, $StringIO_each_char$8.$$arity = 0); + return self.$to_r().$denominator() + }); - Opal.def(self, '$each', $StringIO_each$9 = function $$each(separator) { - var $iter = $StringIO_each$9.$$p, $yield = $iter || nil, self = this, chomp_lines = nil; - if ($gvars["/"] == null) $gvars["/"] = nil; + $def(self, '$div', function $$div(other) { + var self = this; - if ($iter) $StringIO_each$9.$$p = null; - - - if (separator == null) { - separator = $gvars["/"]; - }; - if (($yield !== nil)) { - } else { - return self.$enum_for("each_line") - }; - self.$check_readable(); - chomp_lines = false; - if ($truthy($$$('::', 'Hash')['$==='](separator))) { - separator = (function() {if ($truthy((chomp_lines = separator['$[]']("chomp")))) { - return /\r?\n/ - } else { - return $gvars["/"] - }; return nil; })() - } else if ($truthy(separator)) { - separator = separator.$to_str() - } else { - separator = undefined - }; - var str = self.string, stringLength = str.length; - if (self.position < stringLength) str = str.substr(self.position); - if (separator) { - var chomped = (str).$chomp(), trailing = str.length !== chomped.length, splitted = chomped.split(separator); - for (var i = 0, len = splitted.length; i < len; i++) { - var line = chomp_lines ? splitted[i] : (i < len - 1 || trailing ? splitted[i] + separator : splitted[i]); - Opal.yield1($yield, line); - } - } else if (separator === undefined) { - Opal.yield1($yield, str); - } else { - var m, re = /(.+(?:\n\n|$))\n*/g; - while ((m = re.exec(str))) Opal.yield1($yield, m[1]); - } - self.position = stringLength; - ; - return self; - }, $StringIO_each$9.$$arity = -1); - Opal.alias(self, "each_line", "each"); + if ($eqeq(other, 0)) { + $Kernel.$raise($$$('ZeroDivisionError'), "divided by o"); + } return $rb_divide(self, other).$floor(); + }); - Opal.def(self, '$write', $StringIO_write$10 = function $$write(string) { - var self = this, before = nil, after = nil; + $def(self, '$divmod', function $$divmod(other) { + var self = this; - - self.$check_writable(); - string = self.$String(string); - if (self.string.$length()['$=='](self.position)) { - - self.string = $rb_plus(self.string, string); - return (self.position = $rb_plus(self.position, string.$length())); - } else { - - before = self.string['$[]'](Opal.Range.$new(0, $rb_minus(self.position, 1), false)); - after = self.string['$[]'](Opal.Range.$new($rb_plus(self.position, string.$length()), -1, false)); - self.string = $rb_plus($rb_plus(before, string), after); - return (self.position = $rb_plus(self.position, string.$length())); - }; - }, $StringIO_write$10.$$arity = 1); + return [self.$div(other), self['$%'](other)] + }); - Opal.def(self, '$read', $StringIO_read$11 = function $$read(length, outbuf) { - var self = this, string = nil, str = nil; + $def(self, '$fdiv', function $$fdiv(other) { + var self = this; - - - if (length == null) { - length = nil; - }; - - if (outbuf == null) { - outbuf = nil; - }; - self.$check_readable(); - if ($truthy(self['$eof?']())) { - return nil}; - string = (function() {if ($truthy(length)) { - - str = self.string['$[]'](self.position, length); - self.position = $rb_plus(self.position, length); - return str; - } else { - - str = self.string['$[]'](Opal.Range.$new(self.position, -1, false)); - self.position = self.string.$length(); - return str; - }; return nil; })(); - if ($truthy(outbuf)) { - return outbuf.$write(string) - } else { - return string - }; - }, $StringIO_read$11.$$arity = -1); + return $rb_divide(self.$to_f(), other) + }); - Opal.def(self, '$close', $StringIO_close$12 = function $$close() { + $def(self, '$floor', function $$floor(ndigits) { var self = this; - return (self.closed = "both") - }, $StringIO_close$12.$$arity = 0); + + if (ndigits == null) ndigits = 0; + return self.$to_f().$floor(ndigits); + }, -1); - Opal.def(self, '$close_read', $StringIO_close_read$13 = function $$close_read() { + $def(self, '$i', function $$i() { var self = this; - if (self.closed['$==']("write")) { - return (self.closed = "both") - } else { - return (self.closed = "read") - } - }, $StringIO_close_read$13.$$arity = 0); + return $Kernel.$Complex(0, self) + }); + + $def(self, '$imag', $return_val(0)); - Opal.def(self, '$close_write', $StringIO_close_write$14 = function $$close_write() { + $def(self, '$integer?', $return_val(false)); + + $def(self, '$nonzero?', function $Numeric_nonzero$ques$4() { var self = this; - if (self.closed['$==']("read")) { - return (self.closed = "both") + if ($truthy(self['$zero?']())) { + return nil } else { - return (self.closed = "write") + return self } - }, $StringIO_close_write$14.$$arity = 0); + }); - Opal.def(self, '$closed?', $StringIO_closed$ques$15 = function() { + $def(self, '$numerator', function $$numerator() { var self = this; - return self.closed['$==']("both") - }, $StringIO_closed$ques$15.$$arity = 0); + return self.$to_r().$numerator() + }); - Opal.def(self, '$closed_read?', $StringIO_closed_read$ques$16 = function() { - var $a, self = this; + $def(self, '$polar', function $$polar() { + var self = this; - return ($truthy($a = self.closed['$==']("read")) ? $a : self.closed['$==']("both")) - }, $StringIO_closed_read$ques$16.$$arity = 0); + return [self.$abs(), self.$arg()] + }); - Opal.def(self, '$closed_write?', $StringIO_closed_write$ques$17 = function() { - var $a, self = this; + $def(self, '$quo', function $$quo(other) { + var self = this; - return ($truthy($a = self.closed['$==']("write")) ? $a : self.closed['$==']("both")) - }, $StringIO_closed_write$ques$17.$$arity = 0); + return $rb_divide($Opal['$coerce_to!'](self, $$$('Rational'), "to_r"), other) + }); + + $def(self, '$real', $return_self); - Opal.def(self, '$check_writable', $StringIO_check_writable$18 = function $$check_writable() { + $def(self, '$real?', $return_val(true)); + + $def(self, '$rect', function $$rect() { var self = this; - if ($truthy(self['$closed_write?']())) { - return self.$raise($$($nesting, 'IOError'), "not opened for writing") - } else { - return nil - } - }, $StringIO_check_writable$18.$$arity = 0); - return (Opal.def(self, '$check_readable', $StringIO_check_readable$19 = function $$check_readable() { + return [self, 0] + }); + + $def(self, '$round', function $$round(digits) { var self = this; + return self.$to_f().$round(digits); + }, -1); + + $def(self, '$step', function $$step($a, $b, $c) { + var block = $$step.$$p || nil, $post_args, $kwargs, limit, step, to, by, self = this, counter = nil; - if ($truthy(self['$closed_read?']())) { - return self.$raise($$($nesting, 'IOError'), "not opened for reading") - } else { - return nil + $$step.$$p = null; + $post_args = $slice(arguments); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + + if ($post_args.length > 0) limit = $post_args.shift(); + if ($post_args.length > 0) step = $post_args.shift(); + to = $kwargs.$$smap["to"]; + by = $kwargs.$$smap["by"]; + if (limit !== undefined && to !== undefined) { + $Kernel.$raise($$$('ArgumentError'), "to is given twice"); } - }, $StringIO_check_readable$19.$$arity = 0), nil) && 'check_readable'; - })($nesting[0], $$($nesting, 'IO'), $nesting) -}; + if (step !== undefined && by !== undefined) { + $Kernel.$raise($$$('ArgumentError'), "step is given twice"); + } -/***/ }), - -/***/ 9417: -/***/ ((module) => { + if (to !== undefined) { + limit = to; + } -"use strict"; + if (by !== undefined) { + step = by; + } -module.exports = balanced; -function balanced(a, b, str) { - if (a instanceof RegExp) a = maybeMatch(a, str); - if (b instanceof RegExp) b = maybeMatch(b, str); + if (limit === undefined) { + limit = nil; + } - var r = range(a, b, str); + function validateParameters() { + if (step === nil) { + $Kernel.$raise($$$('TypeError'), "step must be numeric"); + } - return r && { - start: r[0], - end: r[1], - pre: str.slice(0, r[0]), - body: str.slice(r[0] + a.length, r[1]), - post: str.slice(r[1] + b.length) - }; -} + if (step != null && step['$=='](0)) { + $Kernel.$raise($$$('ArgumentError'), "step can't be 0"); + } -function maybeMatch(reg, str) { - var m = str.match(reg); - return m ? m[0] : null; -} + if (step === nil || step == null) { + step = 1; + } -balanced.range = range; -function range(a, b, str) { - var begs, beg, left, right, result; - var ai = str.indexOf(a); - var bi = str.indexOf(b, ai + 1); - var i = ai; + var sign = step['$<=>'](0); - if (ai >= 0 && bi > 0) { - if(a===b) { - return [ai, bi]; - } - begs = []; - left = str.length; + if (sign === nil) { + $Kernel.$raise($$$('ArgumentError'), "0 can't be coerced into " + (step.$class())); + } - while (i >= 0 && !result) { - if (i == ai) { - begs.push(i); - ai = str.indexOf(a, i + 1); - } else if (begs.length == 1) { - result = [ begs.pop(), bi ]; - } else { - beg = begs.pop(); - if (beg < left) { - left = beg; - right = bi; + if (limit === nil || limit == null) { + limit = sign > 0 ? $$$($$$('Float'), 'INFINITY') : $$$($$$('Float'), 'INFINITY')['$-@'](); } - bi = str.indexOf(b, i + 1); + $Opal.$compare(self, limit); } - i = ai < bi && ai >= 0 ? ai : bi; - } - - if (begs.length) { - result = [ left, right ]; - } - } - - return result; -} - + function stepFloatSize() { + if ((step > 0 && self > limit) || (step < 0 && self < limit)) { + return 0; + } else if (step === Infinity || step === -Infinity) { + return 1; + } else { + var abs = Math.abs, floor = Math.floor, + err = (abs(self) + abs(limit) + abs(limit - self)) / abs(step) * $$$($$$('Float'), 'EPSILON'); -/***/ }), + if (err === Infinity || err === -Infinity) { + return 0; + } else { + if (err > 0.5) { + err = 0.5; + } -/***/ 3717: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + return floor((limit - self) / step + err) + 1 + } + } + } -var concatMap = __nccwpck_require__(6891); -var balanced = __nccwpck_require__(9417); + function stepSize() { + validateParameters(); -module.exports = expandTop; + if (step === 0) { + return Infinity; + } -var escSlash = '\0SLASH'+Math.random()+'\0'; -var escOpen = '\0OPEN'+Math.random()+'\0'; -var escClose = '\0CLOSE'+Math.random()+'\0'; -var escComma = '\0COMMA'+Math.random()+'\0'; -var escPeriod = '\0PERIOD'+Math.random()+'\0'; + if (step % 1 !== 0) { + return stepFloatSize(); + } else if ((step > 0 && self > limit) || (step < 0 && self < limit)) { + return 0; + } else { + var ceil = Math.ceil, abs = Math.abs, + lhs = abs(self - limit) + 1, + rhs = abs(step); -function numeric(str) { - return parseInt(str, 10) == str - ? parseInt(str, 10) - : str.charCodeAt(0); -} + return ceil(lhs / rhs); + } + } + if (!(block !== nil)) { + if ((($not(limit) || ($truthy(limit['$is_a?']($$$('Numeric'))))) && (($not(step) || ($truthy(step['$is_a?']($$$('Numeric')))))))) { + return $$$($$$('Enumerator'), 'ArithmeticSequence').$new([limit, step, ($truthy(to) ? ("to: ") : nil), ($truthy(by) ? ("by: ") : nil)], self) + } else { + return $send(self, 'enum_for', ["step", limit, step], (stepSize).$to_proc()) + } + } + validateParameters(); -function escapeBraces(str) { - return str.split('\\\\').join(escSlash) - .split('\\{').join(escOpen) - .split('\\}').join(escClose) - .split('\\,').join(escComma) - .split('\\.').join(escPeriod); -} + var isDesc = step['$negative?'](), + isInf = step['$=='](0) || + (limit === Infinity && !isDesc) || + (limit === -Infinity && isDesc); -function unescapeBraces(str) { - return str.split(escSlash).join('\\') - .split(escOpen).join('{') - .split(escClose).join('}') - .split(escComma).join(',') - .split(escPeriod).join('.'); -} + if (self.$$is_number && step.$$is_number && limit.$$is_number) { + if (self % 1 === 0 && (isInf || limit % 1 === 0) && step % 1 === 0) { + var value = self; + if (isInf) { + for (;; value += step) { + block(value); + } + } else if (isDesc) { + for (; value >= limit; value += step) { + block(value); + } + } else { + for (; value <= limit; value += step) { + block(value); + } + } -// Basically just str.split(","), but handling cases -// where we have nested braced sections, which should be -// treated as individual members, like {a,{b,c},d} -function parseCommaParts(str) { - if (!str) - return ['']; + return self; + } else { + var begin = self.$to_f().valueOf(); + step = step.$to_f().valueOf(); + limit = limit.$to_f().valueOf(); - var parts = []; - var m = balanced('{', '}', str); + var n = stepFloatSize(); - if (!m) - return str.split(','); + if (!isFinite(step)) { + if (n !== 0) block(begin); + } else if (step === 0) { + while (true) { + block(begin); + } + } else { + for (var i = 0; i < n; i++) { + var d = i * step + self; + if (step >= 0 ? limit < d : limit > d) { + d = limit; + } + block(d); + } + } - var pre = m.pre; - var body = m.body; - var post = m.post; - var p = pre.split(','); + return self; + } + } + counter = self; + while ($truthy(isDesc ? $rb_ge(counter, limit) : $rb_le(counter, limit))) { + + Opal.yield1(block, counter); + counter = $rb_plus(counter, step); + } }, -1); + + $def(self, '$to_c', function $$to_c() { + var self = this; - p[p.length-1] += '{' + body + '}'; - var postParts = parseCommaParts(post); - if (post.length) { - p[p.length-1] += postParts.shift(); - p.push.apply(p, postParts); - } + return $Kernel.$Complex(self, 0) + }); + + $def(self, '$to_int', function $$to_int() { + var self = this; - parts.push.apply(parts, p); + return self.$to_i() + }); + + $def(self, '$truncate', function $$truncate(ndigits) { + var self = this; - return parts; -} + + if (ndigits == null) ndigits = 0; + return self.$to_f().$truncate(ndigits); + }, -1); + + $def(self, '$zero?', function $Numeric_zero$ques$5() { + var self = this; -function expandTop(str) { - if (!str) - return []; + return self['$=='](0) + }); + + $def(self, '$positive?', function $Numeric_positive$ques$6() { + var self = this; - // I don't know why Bash 4.3 does this, but it does. - // Anything starting with {} will have the first two bytes preserved - // but *only* at the top level, so {},a}b will not expand to anything, - // but a{},b}c will be expanded to [a}c,abc]. - // One could argue that this is a bug in Bash, but since the goal of - // this module is to match Bash's rules, we escape a leading {} - if (str.substr(0, 2) === '{}') { - str = '\\{\\}' + str.substr(2); - } + return $rb_gt(self, 0) + }); + + $def(self, '$negative?', function $Numeric_negative$ques$7() { + var self = this; - return expand(escapeBraces(str), true).map(unescapeBraces); -} + return $rb_lt(self, 0) + }); + + $def(self, '$dup', $return_self); + + $def(self, '$clone', function $$clone($kwargs) { + var self = this; -function identity(e) { - return e; -} + + $kwargs = $ensure_kwargs($kwargs); + + $kwargs.$$smap["freeze"]; return self; + }, -1); + + $def(self, '$finite?', $return_val(true)); + + $def(self, '$infinite?', $return_val(nil)); + $alias(self, "arg", "angle"); + $alias(self, "conjugate", "conj"); + $alias(self, "imaginary", "imag"); + $alias(self, "magnitude", "abs"); + $alias(self, "modulo", "%"); + $alias(self, "phase", "arg"); + return $alias(self, "rectangular", "rect"); + })('::', null); +}; -function embrace(str) { - return '{' + str + '}'; -} -function isPadded(el) { - return /^-?0\d/.test(el); -} +Opal.modules["corelib/array"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $falsy = Opal.falsy, $hash_ids = Opal.hash_ids, $yield1 = Opal.yield1, $hash_get = Opal.hash_get, $hash_put = Opal.hash_put, $hash_delete = Opal.hash_delete, $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $Kernel = Opal.Kernel, $def = Opal.def, $Opal = Opal.Opal, $eqeqeq = Opal.eqeqeq, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $send = Opal.send, $rb_gt = Opal.rb_gt, $rb_times = Opal.rb_times, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $to_a = Opal.to_a, $to_ary = Opal.to_ary, $gvars = Opal.gvars, $rb_ge = Opal.rb_ge, $assign_ivar = Opal.assign_ivar, $rb_lt = Opal.rb_lt, $return_self = Opal.return_self, $neqeq = Opal.neqeq, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -function lte(i, y) { - return i <= y; -} -function gte(i, y) { - return i >= y; -} + Opal.add_stubs('require,include,to_a,warn,raise,replace,respond_to?,to_ary,coerce_to?,===,join,to_str,hash,<=>,==,object_id,inspect,enum_for,class,bsearch_index,to_proc,nil?,coerce_to!,>,*,enumerator_size,empty?,size,map,equal?,dup,each,reduce,-,[],dig,eql?,length,exclude_end?,flatten,frozen?,__id__,&,!,intersection,to_s,new,item,max,min,>=,**,delete_if,reverse,rotate,rand,at,keep_if,shuffle!,<,sort,sort_by,!=,times,[]=,<<,uniq,|,values,is_a?,end,begin,upto,reject,push,select,select!,collect,collect!,unshift,pristine,singleton_class'); + + self.$require("corelib/enumerable"); + self.$require("corelib/numeric"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Array'); -function expand(str, isTop) { - var expansions = []; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - var m = balanced('{', '}', str); - if (!m || /\$$/.test(m.pre)) return [str]; + + self.$include($$$('Enumerable')); + Opal.prop(self.$$prototype, '$$is_array', true); + + // Recent versions of V8 (> 7.1) only use an optimized implementation when Array.prototype is unmodified. + // For instance, "array-splice.tq" has a "fast path" (ExtractFastJSArray, defined in "src/codegen/code-stub-assembler.cc") + // but it's only enabled when "IsPrototypeInitialArrayPrototype()" is true. + // + // Older versions of V8 were using relatively fast JS-with-extensions code even when Array.prototype is modified: + // https://github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642 + // + // In short, Array operations are slow in recent versions of V8 when the Array.prototype has been tampered. + // So, when possible, we are using faster open-coded version to boost the performance. - var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body); - var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body); - var isSequence = isNumericSequence || isAlphaSequence; - var isOptions = m.body.indexOf(',') >= 0; - if (!isSequence && !isOptions) { - // {a},b} - if (m.post.match(/,.*\}/)) { - str = m.pre + '{' + m.body + escClose + m.post; - return expand(str); + // As of V8 8.4, depending on the size of the array, this is up to ~25x times faster than Array#shift() + // Implementation is heavily inspired by: https://github.com/nodejs/node/blob/ba684805b6c0eded76e5cd89ee00328ac7a59365/lib/internal/util.js#L341-L347 + function shiftNoArg(list) { + var r = list[0]; + var index = 1; + var length = list.length; + for (; index < length; index++) { + list[index - 1] = list[index]; + } + list.pop(); + return r; } - return [str]; - } - var n; - if (isSequence) { - n = m.body.split(/\.\./); - } else { - n = parseCommaParts(m.body); - if (n.length === 1) { - // x{{a,b}}y ==> x{a}y x{b}y - n = expand(n[0], false).map(embrace); - if (n.length === 1) { - var post = m.post.length - ? expand(m.post, false) - : ['']; - return post.map(function(p) { - return m.pre + n[0] + p; - }); + function toArraySubclass(obj, klass) { + if (klass.$$name === Opal.Array) { + return obj; + } else { + return klass.$allocate().$replace((obj).$to_a()); } } - } - // at this point, n is the parts, and we know it's not a comma set - // with a single entry. + // A helper for keep_if and delete_if, filter is either Opal.truthy + // or Opal.falsy. + function filterIf(self, filter, block) { + var value, raised = null, updated = new Array(self.length); + + for (var i = 0, i2 = 0, length = self.length; i < length; i++) { + if (!raised) { + try { + value = $yield1(block, self[i]); + } catch(error) { + raised = error; + } + } - // no need to expand pre, since it is guaranteed to be free of brace-sets - var pre = m.pre; - var post = m.post.length - ? expand(m.post, false) - : ['']; + if (raised || filter(value)) { + updated[i2] = self[i]; + i2 += 1; + } + } - var N; + if (i2 !== i) { + self.splice.apply(self, [0, updated.length].concat(updated)); + self.splice(i2, updated.length); + } - if (isSequence) { - var x = numeric(n[0]); - var y = numeric(n[1]); - var width = Math.max(n[0].length, n[1].length) - var incr = n.length == 3 - ? Math.abs(numeric(n[2])) - : 1; - var test = lte; - var reverse = y < x; - if (reverse) { - incr *= -1; - test = gte; + if (raised) throw raised; } - var pad = n.some(isPadded); + $defs(self, '$[]', function $Array_$$$1($a) { + var $post_args, objects, self = this; - N = []; + + $post_args = $slice(arguments); + objects = $post_args; + return toArraySubclass(objects, self); }, -1); + + $def(self, '$initialize', function $$initialize(size, obj) { + var block = $$initialize.$$p || nil, self = this; - for (var i = x; test(i, y); i += incr) { - var c; - if (isAlphaSequence) { - c = String.fromCharCode(i); - if (c === '\\') - c = ''; - } else { - c = String(i); - if (pad) { - var need = width - c.length; - if (need > 0) { - var z = new Array(need + 1).join('0'); - if (i < 0) - c = '-' + z + c.slice(1); - else - c = z + c; - } - } + $$initialize.$$p = null; + if (size == null) size = nil; + if (obj == null) obj = nil; + + $deny_frozen_access(self); + + if (obj !== nil && block !== nil) { + $Kernel.$warn("warning: block supersedes default value argument"); } - N.push(c); - } - } else { - N = concatMap(n, function(el) { return expand(el, false) }); - } - for (var j = 0; j < N.length; j++) { - for (var k = 0; k < post.length; k++) { - var expansion = pre + N[j] + post[k]; - if (!isTop || isSequence || expansion) - expansions.push(expansion); - } - } + if (size > $$$($$$('Integer'), 'MAX')) { + $Kernel.$raise($$$('ArgumentError'), "array size too big"); + } - return expansions; -} + if (arguments.length > 2) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..2)"); + } + if (arguments.length === 0) { + self.splice(0, self.length); + return self; + } + if (arguments.length === 1) { + if (size.$$is_array) { + self.$replace(size.$to_a()); + return self; + } else if (size['$respond_to?']("to_ary")) { + self.$replace(size.$to_ary()); + return self; + } + } -/***/ }), + size = $coerce_to(size, $$$('Integer'), 'to_int'); -/***/ 6891: -/***/ ((module) => { + if (size < 0) { + $Kernel.$raise($$$('ArgumentError'), "negative array size"); + } -module.exports = function (xs, fn) { - var res = []; - for (var i = 0; i < xs.length; i++) { - var x = fn(xs[i], i); - if (isArray(x)) res.push.apply(res, x); - else res.push(x); - } - return res; -}; + self.splice(0, self.length); + var i, value; -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; + if (block === nil) { + for (i = 0; i < size; i++) { + self.push(obj); + } + } + else { + for (i = 0, value; i < size; i++) { + value = block(i); + self[i] = value; + } + } + return self; + }, -1); + $defs(self, '$try_convert', function $$try_convert(obj) { + + return $Opal['$coerce_to?'](obj, $$$('Array'), "to_ary") + }); + + $def(self, '$&', function $Array_$$2(other) { + var self = this; -/***/ }), + + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + + var result = [], hash = $hash2([], {}), i, length, item; -/***/ 6323: -/***/ ((module) => { + for (i = 0, length = other.length; i < length; i++) { + $hash_put(hash, other[i], true); + } -"use strict"; + for (i = 0, length = self.length; i < length; i++) { + item = self[i]; + if ($hash_delete(hash, item) !== undefined) { + result.push(item); + } + } + return result; + }); + + $def(self, '$|', function $Array_$$3(other) { + var self = this; -var isMergeableObject = function isMergeableObject(value) { - return isNonNullObject(value) - && !isSpecial(value) -}; + + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + + var hash = $hash2([], {}), i, length; -function isNonNullObject(value) { - return !!value && typeof value === 'object' -} + for (i = 0, length = self.length; i < length; i++) { + $hash_put(hash, self[i], true); + } -function isSpecial(value) { - var stringValue = Object.prototype.toString.call(value); + for (i = 0, length = other.length; i < length; i++) { + $hash_put(hash, other[i], true); + } - return stringValue === '[object RegExp]' - || stringValue === '[object Date]' - || isReactElement(value) -} + return hash.$keys(); + }); + + $def(self, '$*', function $Array_$$4(other) { + var self = this; + + + if ($truthy(other['$respond_to?']("to_str"))) { + return self.$join(other.$to_str()) + } other = $coerce_to(other, $$$('Integer'), 'to_int'); + if ($truthy(other < 0)) { + $Kernel.$raise($$$('ArgumentError'), "negative argument"); + } + var result = [], + converted = self.$to_a(); -// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 -var canUseSymbol = typeof Symbol === 'function' && Symbol.for; -var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; + for (var i = 0; i < other; i++) { + result = result.concat(converted); + } -function isReactElement(value) { - return value.$$typeof === REACT_ELEMENT_TYPE -} + return result; + }); + + $def(self, '$+', function $Array_$plus$5(other) { + var self = this; -function emptyTarget(val) { - return Array.isArray(val) ? [] : {} -} + + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + return self.concat(other); }); + + $def(self, '$-', function $Array_$minus$6(other) { + var self = this; -function cloneUnlessOtherwiseSpecified(value, options) { - return (options.clone !== false && options.isMergeableObject(value)) - ? deepmerge(emptyTarget(value), value, options) - : value -} + + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + if ($truthy(self.length === 0)) { + return [] + } if ($truthy(other.length === 0)) { + return self.slice() + } + var result = [], hash = $hash2([], {}), i, length, item; -function defaultArrayMerge(target, source, options) { - return target.concat(source).map(function(element) { - return cloneUnlessOtherwiseSpecified(element, options) - }) -} + for (i = 0, length = other.length; i < length; i++) { + $hash_put(hash, other[i], true); + } -function getMergeFunction(key, options) { - if (!options.customMerge) { - return deepmerge - } - var customMerge = options.customMerge(key); - return typeof customMerge === 'function' ? customMerge : deepmerge -} + for (i = 0, length = self.length; i < length; i++) { + item = self[i]; + if ($hash_get(hash, item) === undefined) { + result.push(item); + } + } -function getEnumerableOwnPropertySymbols(target) { - return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter(function(symbol) { - return Object.propertyIsEnumerable.call(target, symbol) - }) - : [] -} + return result; + }); + + $def(self, '$<<', function $Array_$lt$lt$7(object) { + var self = this; -function getKeys(target) { - return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) -} + + $deny_frozen_access(self); + self.push(object); + return self; + }); + + $def(self, '$<=>', function $Array_$lt_eq_gt$8(other) { + var self = this; -function propertyIsOnObject(object, property) { - try { - return property in object - } catch(_) { - return false - } -} + + if ($eqeqeq($$$('Array'), other)) { + other = other.$to_a(); + } else if ($truthy(other['$respond_to?']("to_ary"))) { + other = other.$to_ary().$to_a(); + } else { + return nil + } + if (self.$hash() === other.$hash()) { + return 0; + } -// Protects from prototype poisoning and unexpected merging up the prototype chain. -function propertyIsUnsafe(target, key) { - return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, - && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, - && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. -} + var count = Math.min(self.length, other.length); -function mergeObject(target, source, options) { - var destination = {}; - if (options.isMergeableObject(target)) { - getKeys(target).forEach(function(key) { - destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); - }); - } - getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { - return - } + for (var i = 0; i < count; i++) { + var tmp = (self[i])['$<=>'](other[i]); - if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { - destination[key] = getMergeFunction(key, options)(target[key], source[key], options); - } else { - destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); - } - }); - return destination -} + if (tmp !== 0) { + return tmp; + } + } -function deepmerge(target, source, options) { - options = options || {}; - options.arrayMerge = options.arrayMerge || defaultArrayMerge; - options.isMergeableObject = options.isMergeableObject || isMergeableObject; - // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() - // implementations can use it. The caller may not replace it. - options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; + return (self.length)['$<=>'](other.length); + }); + + $def(self, '$==', function $Array_$eq_eq$9(other) { + var self = this; - var sourceIsArray = Array.isArray(source); - var targetIsArray = Array.isArray(target); - var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; + + var recursed = {}; - if (!sourceAndTargetTypesMatch) { - return cloneUnlessOtherwiseSpecified(source, options) - } else if (sourceIsArray) { - return options.arrayMerge(target, source, options) - } else { - return mergeObject(target, source, options) - } -} + function _eqeq(array, other) { + var i, length, a, b; -deepmerge.all = function deepmergeAll(array, options) { - if (!Array.isArray(array)) { - throw new Error('first argument should be an array') - } + if (array === other) + return true; - return array.reduce(function(prev, next) { - return deepmerge(prev, next, options) - }, {}) -}; + if (!other.$$is_array) { + if ($respond_to(other, '$to_ary')) { + return (other)['$=='](array); + } else { + return false; + } + } -var deepmerge_1 = deepmerge; + if (array.$$constructor !== Array) + array = (array).$to_a(); + if (other.$$constructor !== Array) + other = (other).$to_a(); -module.exports = deepmerge_1; + if (array.length !== other.length) { + return false; + } + recursed[(array).$object_id()] = true; -/***/ }), + for (i = 0, length = array.length; i < length; i++) { + a = array[i]; + b = other[i]; + if (a.$$is_array) { + if (b.$$is_array && b.length !== a.length) { + return false; + } + if (!recursed.hasOwnProperty((a).$object_id())) { + if (!_eqeq(a, b)) { + return false; + } + } + } else { + if (!(a)['$=='](b)) { + return false; + } + } + } -/***/ 4802: -/***/ ((__unused_webpack_module, exports) => { + return true; + } -"use strict"; + return _eqeq(self, other); + + }); + + function $array_slice_range(self, index) { + var size = self.length, + exclude, from, to, result; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.attributeNames = exports.elementNames = void 0; -exports.elementNames = new Map([ - "altGlyph", - "altGlyphDef", - "altGlyphItem", - "animateColor", - "animateMotion", - "animateTransform", - "clipPath", - "feBlend", - "feColorMatrix", - "feComponentTransfer", - "feComposite", - "feConvolveMatrix", - "feDiffuseLighting", - "feDisplacementMap", - "feDistantLight", - "feDropShadow", - "feFlood", - "feFuncA", - "feFuncB", - "feFuncG", - "feFuncR", - "feGaussianBlur", - "feImage", - "feMerge", - "feMergeNode", - "feMorphology", - "feOffset", - "fePointLight", - "feSpecularLighting", - "feSpotLight", - "feTile", - "feTurbulence", - "foreignObject", - "glyphRef", - "linearGradient", - "radialGradient", - "textPath", -].map(function (val) { return [val.toLowerCase(), val]; })); -exports.attributeNames = new Map([ - "definitionURL", - "attributeName", - "attributeType", - "baseFrequency", - "baseProfile", - "calcMode", - "clipPathUnits", - "diffuseConstant", - "edgeMode", - "filterUnits", - "glyphRef", - "gradientTransform", - "gradientUnits", - "kernelMatrix", - "kernelUnitLength", - "keyPoints", - "keySplines", - "keyTimes", - "lengthAdjust", - "limitingConeAngle", - "markerHeight", - "markerUnits", - "markerWidth", - "maskContentUnits", - "maskUnits", - "numOctaves", - "pathLength", - "patternContentUnits", - "patternTransform", - "patternUnits", - "pointsAtX", - "pointsAtY", - "pointsAtZ", - "preserveAlpha", - "preserveAspectRatio", - "primitiveUnits", - "refX", - "refY", - "repeatCount", - "repeatDur", - "requiredExtensions", - "requiredFeatures", - "specularConstant", - "specularExponent", - "spreadMethod", - "startOffset", - "stdDeviation", - "stitchTiles", - "surfaceScale", - "systemLanguage", - "tableValues", - "targetX", - "targetY", - "textLength", - "viewBox", - "viewTarget", - "xChannelSelector", - "yChannelSelector", - "zoomAndPan", -].map(function (val) { return [val.toLowerCase(), val]; })); + exclude = index.excl; + from = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int'); + to = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int'); + if (from < 0) { + from += size; -/***/ }), + if (from < 0) { + return nil; + } + } -/***/ 8621: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + if (index.excl_rev && index.begin !== nil) { + from += 1; + } -"use strict"; + if (from > size) { + return nil; + } -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.render = void 0; -/* - * Module dependencies - */ -var ElementType = __importStar(__nccwpck_require__(3944)); -var entities_1 = __nccwpck_require__(3000); -/** - * Mixed-case SVG and MathML tags & attributes - * recognized by the HTML parser. - * - * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign - */ -var foreignNames_js_1 = __nccwpck_require__(4802); -var unencodedElements = new Set([ - "style", - "script", - "xmp", - "iframe", - "noembed", - "noframes", - "plaintext", - "noscript", -]); -function replaceQuotes(value) { - return value.replace(/"/g, """); -} -/** - * Format attributes - */ -function formatAttributes(attributes, opts) { - var _a; - if (!attributes) - return; - var encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false - ? replaceQuotes - : opts.xmlMode || opts.encodeEntities !== "utf8" - ? entities_1.encodeXML - : entities_1.escapeAttribute; - return Object.keys(attributes) - .map(function (key) { - var _a, _b; - var value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : ""; - if (opts.xmlMode === "foreign") { - /* Fix up mixed-case attribute names */ - key = (_b = foreignNames_js_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key; - } - if (!opts.emptyAttrs && !opts.xmlMode && value === "") { - return key; - } - return "".concat(key, "=\"").concat(encode(value), "\""); - }) - .join(" "); -} -/** - * Self-enclosing tags - */ -var singleTag = new Set([ - "area", - "base", - "basefont", - "br", - "col", - "command", - "embed", - "frame", - "hr", - "img", - "input", - "isindex", - "keygen", - "link", - "meta", - "param", - "source", - "track", - "wbr", -]); -/** - * Renders a DOM node or an array of DOM nodes to a string. - * - * Can be thought of as the equivalent of the `outerHTML` of the passed node(s). - * - * @param node Node to be rendered. - * @param options Changes serialization behavior - */ -function render(node, options) { - if (options === void 0) { options = {}; } - var nodes = "length" in node ? node : [node]; - var output = ""; - for (var i = 0; i < nodes.length; i++) { - output += renderNode(nodes[i], options); - } - return output; -} -exports.render = render; -exports["default"] = render; -function renderNode(node, options) { - switch (node.type) { - case ElementType.Root: - return render(node.children, options); - // @ts-expect-error We don't use `Doctype` yet - case ElementType.Doctype: - case ElementType.Directive: - return renderDirective(node); - case ElementType.Comment: - return renderComment(node); - case ElementType.CDATA: - return renderCdata(node); - case ElementType.Script: - case ElementType.Style: - case ElementType.Tag: - return renderTag(node, options); - case ElementType.Text: - return renderText(node, options); - } -} -var foreignModeIntegrationPoints = new Set([ - "mi", - "mo", - "mn", - "ms", - "mtext", - "annotation-xml", - "foreignObject", - "desc", - "title", -]); -var foreignElements = new Set(["svg", "math"]); -function renderTag(elem, opts) { - var _a; - // Handle SVG / MathML in HTML - if (opts.xmlMode === "foreign") { - /* Fix up mixed-case element names */ - elem.name = (_a = foreignNames_js_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name; - /* Exit foreign mode at integration points */ - if (elem.parent && - foreignModeIntegrationPoints.has(elem.parent.name)) { - opts = __assign(__assign({}, opts), { xmlMode: false }); + if (to < 0) { + to += size; + + if (to < 0) { + return []; } + } + + if (!exclude || index.end === nil) { + to += 1; + } + + result = self.slice(from, to); + return result; } - if (!opts.xmlMode && foreignElements.has(elem.name)) { - opts = __assign(__assign({}, opts), { xmlMode: "foreign" }); - } - var tag = "<".concat(elem.name); - var attribs = formatAttributes(elem.attribs, opts); - if (attribs) { - tag += " ".concat(attribs); - } - if (elem.children.length === 0 && - (opts.xmlMode - ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags - opts.selfClosingTags !== false - : // User explicitly asked for self-closing tags, even in HTML mode - opts.selfClosingTags && singleTag.has(elem.name))) { - if (!opts.xmlMode) - tag += " "; - tag += "/>"; + + function $array_slice_arithmetic_seq(self, index) { + var array, out = [], i = 0, pseudorange; + + if (index.step < 0) { + pseudorange = { + begin: index.range.end, + end: index.range.begin, + excl: false, + excl_rev: index.range.excl + }; + array = $array_slice_range(self, pseudorange).$reverse(); + } + else { + array = $array_slice_range(self, index.range); + } + + while (i < array.length) { + out.push(array[i]); + i += Math.abs(index.step); + } + + return out; } - else { - tag += ">"; - if (elem.children.length > 0) { - tag += render(elem.children, opts); + + function $array_slice_index_length(self, index, length) { + var size = self.length, + result; + + index = $coerce_to(index, Opal.Integer, 'to_int'); + + if (index < 0) { + index += size; + + if (index < 0) { + return nil; } - if (opts.xmlMode || !singleTag.has(elem.name)) { - tag += "</".concat(elem.name, ">"); + } + + if (length === undefined) { + if (index >= size || index < 0) { + return nil; } + + return self[index]; + } + else { + length = $coerce_to(length, Opal.Integer, 'to_int'); + + if (length < 0 || index > size || index < 0) { + return nil; + } + + result = self.slice(index, index + length); + } + return result; } - return tag; -} -function renderDirective(elem) { - return "<".concat(elem.data, ">"); -} -function renderText(elem, opts) { - var _a; - var data = elem.data || ""; - // If entities weren't decoded, no need to encode them back - if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false && - !(!opts.xmlMode && - elem.parent && - unencodedElements.has(elem.parent.name))) { - data = - opts.xmlMode || opts.encodeEntities !== "utf8" - ? (0, entities_1.encodeXML)(data) - : (0, entities_1.escapeText)(data); - } - return data; -} -function renderCdata(elem) { - return "<![CDATA[".concat(elem.children[0].data, "]]>"); -} -function renderComment(elem) { - return "<!--".concat(elem.data, "-->"); -} + + $def(self, '$[]', function $Array_$$$10(index, length) { + var self = this; + + if (index.$$is_range) { + return $array_slice_range(self, index); + } + else if (index.$$is_arithmetic_seq) { + return $array_slice_arithmetic_seq(self, index); + } + else { + return $array_slice_index_length(self, index, length); + } + }, -2); + + $def(self, '$[]=', function $Array_$$$eq$11(index, value, extra) { + var self = this, data = nil, length = nil; + $deny_frozen_access(self); + data = nil; + + var i, size = self.length; + if (index.$$is_range) { + if (value.$$is_array) + data = value.$to_a(); + else if (value['$respond_to?']("to_ary")) + data = value.$to_ary().$to_a(); + else + data = [value]; -/***/ }), + var exclude = index.excl, + from = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int'), + to = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int'); -/***/ 3944: -/***/ ((__unused_webpack_module, exports) => { + if (from < 0) { + from += size; -"use strict"; + if (from < 0) { + $Kernel.$raise($$$('RangeError'), "" + (index.$inspect()) + " out of range"); + } + } -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0; -/** Types of elements found in htmlparser2's DOM */ -var ElementType; -(function (ElementType) { - /** Type for the root element of a document */ - ElementType["Root"] = "root"; - /** Type for Text */ - ElementType["Text"] = "text"; - /** Type for <? ... ?> */ - ElementType["Directive"] = "directive"; - /** Type for <!-- ... --> */ - ElementType["Comment"] = "comment"; - /** Type for <script> tags */ - ElementType["Script"] = "script"; - /** Type for <style> tags */ - ElementType["Style"] = "style"; - /** Type for Any tag */ - ElementType["Tag"] = "tag"; - /** Type for <![CDATA[ ... ]]> */ - ElementType["CDATA"] = "cdata"; - /** Type for <!doctype ...> */ - ElementType["Doctype"] = "doctype"; -})(ElementType = exports.ElementType || (exports.ElementType = {})); -/** - * Tests whether an element is a tag or not. - * - * @param elem Element to test - */ -function isTag(elem) { - return (elem.type === ElementType.Tag || - elem.type === ElementType.Script || - elem.type === ElementType.Style); -} -exports.isTag = isTag; -// Exports for backwards compatibility -/** Type for the root element of a document */ -exports.Root = ElementType.Root; -/** Type for Text */ -exports.Text = ElementType.Text; -/** Type for <? ... ?> */ -exports.Directive = ElementType.Directive; -/** Type for <!-- ... --> */ -exports.Comment = ElementType.Comment; -/** Type for <script> tags */ -exports.Script = ElementType.Script; -/** Type for <style> tags */ -exports.Style = ElementType.Style; -/** Type for Any tag */ -exports.Tag = ElementType.Tag; -/** Type for <![CDATA[ ... ]]> */ -exports.CDATA = ElementType.CDATA; -/** Type for <!doctype ...> */ -exports.Doctype = ElementType.Doctype; + if (to < 0) { + to += size; + } + if (!exclude || index.end === nil) { + to += 1; + } -/***/ }), + if (from > size) { + for (i = size; i < from; i++) { + self[i] = nil; + } + } -/***/ 4038: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + if (to < 0) { + self.splice.apply(self, [from, 0].concat(data)); + } + else { + self.splice.apply(self, [from, to - from].concat(data)); + } -"use strict"; + return value; + } else { + if (extra === undefined) { + (length = 1); + } else { + length = value; + value = extra; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DomHandler = void 0; -var domelementtype_1 = __nccwpck_require__(3944); -var node_js_1 = __nccwpck_require__(7822); -__exportStar(__nccwpck_require__(7822), exports); -// Default options -var defaultOpts = { - withStartIndices: false, - withEndIndices: false, - xmlMode: false, -}; -var DomHandler = /** @class */ (function () { - /** - * @param callback Called once parsing has completed. - * @param options Settings for the handler. - * @param elementCB Callback whenever a tag is closed. - */ - function DomHandler(callback, options, elementCB) { - /** The elements of the DOM */ - this.dom = []; - /** The root element for the DOM */ - this.root = new node_js_1.Document(this.dom); - /** Indicated whether parsing has been completed. */ - this.done = false; - /** Stack of open tags. */ - this.tagStack = [this.root]; - /** A data node that is still being written to. */ - this.lastNode = null; - /** Reference to the parser instance. Used for location information. */ - this.parser = null; - // Make it possible to skip arguments, for backwards-compatibility - if (typeof options === "function") { - elementCB = options; - options = defaultOpts; + if (value.$$is_array) + data = value.$to_a(); + else if (value['$respond_to?']("to_ary")) + data = value.$to_ary().$to_a(); + else + data = [value]; } - if (typeof callback === "object") { - options = callback; - callback = undefined; + + var old; + + index = $coerce_to(index, $$$('Integer'), 'to_int'); + length = $coerce_to(length, $$$('Integer'), 'to_int'); + + if (index < 0) { + old = index; + index += size; + + if (index < 0) { + $Kernel.$raise($$$('IndexError'), "index " + (old) + " too small for array; minimum " + (-self.length)); + } } - this.callback = callback !== null && callback !== void 0 ? callback : null; - this.options = options !== null && options !== void 0 ? options : defaultOpts; - this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null; - } - DomHandler.prototype.onparserinit = function (parser) { - this.parser = parser; - }; - // Resets the handler back to starting state - DomHandler.prototype.onreset = function () { - this.dom = []; - this.root = new node_js_1.Document(this.dom); - this.done = false; - this.tagStack = [this.root]; - this.lastNode = null; - this.parser = null; - }; - // Signals the handler that parsing is done - DomHandler.prototype.onend = function () { - if (this.done) - return; - this.done = true; - this.parser = null; - this.handleCallback(null); - }; - DomHandler.prototype.onerror = function (error) { - this.handleCallback(error); - }; - DomHandler.prototype.onclosetag = function () { - this.lastNode = null; - var elem = this.tagStack.pop(); - if (this.options.withEndIndices) { - elem.endIndex = this.parser.endIndex; + + if (length < 0) { + $Kernel.$raise($$$('IndexError'), "negative length (" + (length) + ")"); } - if (this.elementCB) - this.elementCB(elem); - }; - DomHandler.prototype.onopentag = function (name, attribs) { - var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined; - var element = new node_js_1.Element(name, attribs, undefined, type); - this.addNode(element); - this.tagStack.push(element); - }; - DomHandler.prototype.ontext = function (data) { - var lastNode = this.lastNode; - if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) { - lastNode.data += data; - if (this.options.withEndIndices) { - lastNode.endIndex = this.parser.endIndex; - } + + if (index > size) { + for (i = size; i < index; i++) { + self[i] = nil; + } + } + + if (extra === undefined) { + self[index] = value; } else { - var node = new node_js_1.Text(data); - this.addNode(node); - this.lastNode = node; + self.splice.apply(self, [index, length].concat(data)); } - }; - DomHandler.prototype.oncomment = function (data) { - if (this.lastNode && this.lastNode.type === domelementtype_1.ElementType.Comment) { - this.lastNode.data += data; - return; + + return value; + } + }, -3); + + $def(self, '$any?', function $Array_any$ques$12(pattern) { + var block = $Array_any$ques$12.$$p || nil, self = this; + + $Array_any$ques$12.$$p = null; + if (self.length === 0) return false; + return $send2(self, $find_super(self, 'any?', $Array_any$ques$12, false, true), 'any?', [pattern], block); + }, -1); + + $def(self, '$assoc', function $$assoc(object) { + var self = this; + + + for (var i = 0, length = self.length, item; i < length; i++) { + if (item = self[i], item.length && (item[0])['$=='](object)) { + return item; } - var node = new node_js_1.Comment(data); - this.addNode(node); - this.lastNode = node; - }; - DomHandler.prototype.oncommentend = function () { - this.lastNode = null; - }; - DomHandler.prototype.oncdatastart = function () { - var text = new node_js_1.Text(""); - var node = new node_js_1.CDATA([text]); - this.addNode(node); - text.parent = node; - this.lastNode = text; - }; - DomHandler.prototype.oncdataend = function () { - this.lastNode = null; - }; - DomHandler.prototype.onprocessinginstruction = function (name, data) { - var node = new node_js_1.ProcessingInstruction(name, data); - this.addNode(node); - }; - DomHandler.prototype.handleCallback = function (error) { - if (typeof this.callback === "function") { - this.callback(error, this.dom); + } + + return nil; + + }); + + $def(self, '$at', function $$at(index) { + var self = this; + + + index = $coerce_to(index, $$$('Integer'), 'to_int'); + + if (index < 0) { + index += self.length; + } + + if (index < 0 || index >= self.length) { + return nil; + } + + return self[index]; + + }); + + $def(self, '$bsearch_index', function $$bsearch_index() { + var block = $$bsearch_index.$$p || nil, self = this; + + $$bsearch_index.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("bsearch_index") + } + var min = 0, + max = self.length, + mid, + val, + ret, + smaller = false, + satisfied = nil; + + while (min < max) { + mid = min + Math.floor((max - min) / 2); + val = self[mid]; + ret = $yield1(block, val); + + if (ret === true) { + satisfied = mid; + smaller = true; } - else if (error) { - throw error; + else if (ret === false || ret === nil) { + smaller = false; + } + else if (ret.$$is_number) { + if (ret === 0) { return mid; } + smaller = (ret < 0); + } + else { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((ret).$class()) + " (must be numeric, true, false or nil)"); + } + + if (smaller) { max = mid; } else { min = mid + 1; } + } + + return satisfied; + }); + + $def(self, '$bsearch', function $$bsearch() { + var block = $$bsearch.$$p || nil, self = this, index = nil; + + $$bsearch.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("bsearch") + } index = $send(self, 'bsearch_index', [], block.$to_proc()); + + if (index != null && index.$$is_number) { + return self[index]; + } else { + return index; + } + }); + + $def(self, '$cycle', function $$cycle(n) { + var block = $$cycle.$$p || nil, self = this; + + $$cycle.$$p = null; + if (n == null) n = nil; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["cycle", n], function $$13(){var self = $$13.$$s == null ? this : $$13.$$s; + + if ($truthy(n['$nil?']())) { + return $$$($$$('Float'), 'INFINITY') + } else { + + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if ($truthy($rb_gt(n, 0))) { + return $rb_times(self.$enumerator_size(), n) + } else { + return 0 + } }}, {$$s: self}) + } if (($truthy(self['$empty?']()) || ($eqeq(n, 0)))) { + return nil + } + var i, length; + + if (n === nil) { + while (true) { + for (i = 0, length = self.length; i < length; i++) { + $yield1(block, self[i]); + } + } + } + else { + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if (n <= 0) { + return self; + } + + while (n > 0) { + for (i = 0, length = self.length; i < length; i++) { + $yield1(block, self[i]); + } + + n--; + } + } + return self; + }, -1); + + $def(self, '$clear', function $$clear() { + var self = this; + + + $deny_frozen_access(self); + self.splice(0, self.length); + return self; + }); + + $def(self, '$count', function $$count(object) { + var block = $$count.$$p || nil, self = this; + + $$count.$$p = null; + if (($truthy(object !== undefined) || ($truthy(block)))) { + return $send2(self, $find_super(self, 'count', $$count, false, true), 'count', [object], block) + } else { + return self.$size() + } }, -1); + + $def(self, '$initialize_copy', function $$initialize_copy(other) { + var self = this; + + return self.$replace(other) + }); + + $def(self, '$collect', function $$collect() { + var block = $$collect.$$p || nil, self = this; + + $$collect.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["collect"], function $$14(){var self = $$14.$$s == null ? this : $$14.$$s; + + return self.$size()}, {$$s: self}) + } + var result = []; + + for (var i = 0, length = self.length; i < length; i++) { + var value = $yield1(block, self[i]); + result.push(value); + } + + return result; + }); + + $def(self, '$collect!', function $Array_collect$excl$15() { + var block = $Array_collect$excl$15.$$p || nil, self = this; + + $Array_collect$excl$15.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["collect!"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s; + + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); + + for (var i = 0, length = self.length; i < length; i++) { + var value = $yield1(block, self[i]); + self[i] = value; + } + return self; + }); + + function binomial_coefficient(n, k) { + if (n === k || k === 0) { + return 1; + } + + if (k > 0 && n > k) { + return binomial_coefficient(n - 1, k - 1) + binomial_coefficient(n - 1, k); + } + + return 0; + } + + $def(self, '$combination', function $$combination(n) { + var $yield = $$combination.$$p || nil, self = this, num = nil; + + $$combination.$$p = null; + + num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["combination", num], function $$17(){var self = $$17.$$s == null ? this : $$17.$$s; + + return binomial_coefficient(self.length, num)}, {$$s: self}) + } + var i, length, stack, chosen, lev, done, next; + + if (num === 0) { + Opal.yield1($yield, []); + } else if (num === 1) { + for (i = 0, length = self.length; i < length; i++) { + Opal.yield1($yield, [self[i]]); + } + } + else if (num === self.length) { + Opal.yield1($yield, self.slice()); + } + else if (num >= 0 && num < self.length) { + stack = []; + for (i = 0; i <= num + 1; i++) { + stack.push(0); + } + + chosen = []; + lev = 0; + done = false; + stack[0] = -1; + + while (!done) { + chosen[lev] = self[stack[lev+1]]; + while (lev < num - 1) { + lev++; + next = stack[lev+1] = stack[lev] + 1; + chosen[lev] = self[next]; + } + Opal.yield1($yield, chosen.slice()); + lev++; + do { + done = (lev === 0); + stack[lev]++; + lev--; + } while ( stack[lev+1] + num === self.length + lev + 1 ); } - }; - DomHandler.prototype.addNode = function (node) { - var parent = this.tagStack[this.tagStack.length - 1]; - var previousSibling = parent.children[parent.children.length - 1]; - if (this.options.withStartIndices) { - node.startIndex = this.parser.startIndex; + } + return self; + }); + + $def(self, '$repeated_combination', function $$repeated_combination(n) { + var $yield = $$repeated_combination.$$p || nil, self = this, num = nil; + + $$repeated_combination.$$p = null; + + num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["repeated_combination", num], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s; + + return binomial_coefficient(self.length + num - 1, num);}, {$$s: self}) + } + function iterate(max, from, buffer, self) { + if (buffer.length == max) { + var copy = buffer.slice(); + Opal.yield1($yield, copy); + return; } - if (this.options.withEndIndices) { - node.endIndex = this.parser.endIndex; + for (var i = from; i < self.length; i++) { + buffer.push(self[i]); + iterate(max, i, buffer, self); + buffer.pop(); } - parent.children.push(node); - if (previousSibling) { - node.prev = previousSibling; - previousSibling.next = node; + } + + if (num >= 0) { + iterate(num, 0, [], self); + } + return self; + }); + + $def(self, '$compact', function $$compact() { + var self = this; + + + var result = []; + + for (var i = 0, length = self.length, item; i < length; i++) { + if ((item = self[i]) !== nil) { + result.push(item); } - node.parent = parent; - this.lastNode = null; - }; - return DomHandler; -}()); -exports.DomHandler = DomHandler; -exports["default"] = DomHandler; + } + return result; + + }); + + $def(self, '$compact!', function $Array_compact$excl$19() { + var self = this; -/***/ }), + + $deny_frozen_access(self); -/***/ 7822: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + var original = self.length; -"use strict"; + for (var i = 0, length = self.length; i < length; i++) { + if (self[i] === nil) { + self.splice(i, 1); -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; + length--; + i--; } - return t; - }; - return __assign.apply(this, arguments); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.cloneNode = exports.hasChildren = exports.isDocument = exports.isDirective = exports.isComment = exports.isText = exports.isCDATA = exports.isTag = exports.Element = exports.Document = exports.CDATA = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0; -var domelementtype_1 = __nccwpck_require__(3944); -/** - * This object will be used as the prototype for Nodes when creating a - * DOM-Level-1-compliant structure. - */ -var Node = /** @class */ (function () { - function Node() { - /** Parent of the node */ - this.parent = null; - /** Previous sibling */ - this.prev = null; - /** Next sibling */ - this.next = null; - /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */ - this.startIndex = null; - /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */ - this.endIndex = null; - } - Object.defineProperty(Node.prototype, "parentNode", { - // Read-write aliases for properties - /** - * Same as {@link parent}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.parent; - }, - set: function (parent) { - this.parent = parent; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(Node.prototype, "previousSibling", { - /** - * Same as {@link prev}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.prev; - }, - set: function (prev) { - this.prev = prev; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(Node.prototype, "nextSibling", { - /** - * Same as {@link next}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.next; - }, - set: function (next) { - this.next = next; - }, - enumerable: false, - configurable: true - }); - /** - * Clone this node, and optionally its children. - * - * @param recursive Clone child nodes as well. - * @returns A clone of the node. - */ - Node.prototype.cloneNode = function (recursive) { - if (recursive === void 0) { recursive = false; } - return cloneNode(this, recursive); - }; - return Node; -}()); -exports.Node = Node; -/** - * A node that contains some data. - */ -var DataNode = /** @class */ (function (_super) { - __extends(DataNode, _super); - /** - * @param data The content of the data node - */ - function DataNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - Object.defineProperty(DataNode.prototype, "nodeValue", { - /** - * Same as {@link data}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.data; - }, - set: function (data) { - this.data = data; - }, - enumerable: false, - configurable: true - }); - return DataNode; -}(Node)); -exports.DataNode = DataNode; -/** - * Text within the document. - */ -var Text = /** @class */ (function (_super) { - __extends(Text, _super); - function Text() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.type = domelementtype_1.ElementType.Text; - return _this; - } - Object.defineProperty(Text.prototype, "nodeType", { - get: function () { - return 3; - }, - enumerable: false, - configurable: true - }); - return Text; -}(DataNode)); -exports.Text = Text; -/** - * Comments within the document. - */ -var Comment = /** @class */ (function (_super) { - __extends(Comment, _super); - function Comment() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.type = domelementtype_1.ElementType.Comment; - return _this; - } - Object.defineProperty(Comment.prototype, "nodeType", { - get: function () { - return 8; - }, - enumerable: false, - configurable: true - }); - return Comment; -}(DataNode)); -exports.Comment = Comment; -/** - * Processing instructions, including doc types. - */ -var ProcessingInstruction = /** @class */ (function (_super) { - __extends(ProcessingInstruction, _super); - function ProcessingInstruction(name, data) { - var _this = _super.call(this, data) || this; - _this.name = name; - _this.type = domelementtype_1.ElementType.Directive; - return _this; - } - Object.defineProperty(ProcessingInstruction.prototype, "nodeType", { - get: function () { - return 1; - }, - enumerable: false, - configurable: true + } + + return self.length === original ? nil : self; + }); - return ProcessingInstruction; -}(DataNode)); -exports.ProcessingInstruction = ProcessingInstruction; -/** - * A `Node` that can have children. - */ -var NodeWithChildren = /** @class */ (function (_super) { - __extends(NodeWithChildren, _super); - /** - * @param children Children of the node. Only certain node types can have children. - */ - function NodeWithChildren(children) { - var _this = _super.call(this) || this; - _this.children = children; - return _this; - } - Object.defineProperty(NodeWithChildren.prototype, "firstChild", { - // Aliases - /** First child of the node. */ - get: function () { - var _a; - return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null; - }, - enumerable: false, - configurable: true + + $def(self, '$concat', function $$concat($a) { + var $post_args, others, self = this; + + + $post_args = $slice(arguments); + others = $post_args; + $deny_frozen_access(self); + others = $send(others, 'map', [], function $$20(other){var self = $$20.$$s == null ? this : $$20.$$s; + + + if (other == null) other = nil; + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + if ($truthy(other['$equal?'](self))) { + other = other.$dup(); + } return other;}, {$$s: self}); + $send(others, 'each', [], function $$21(other){var self = $$21.$$s == null ? this : $$21.$$s; + + + if (other == null) other = nil; + + for (var i = 0, length = other.length; i < length; i++) { + self.push(other[i]); + } +}, {$$s: self}); + return self; + }, -1); + + $def(self, '$delete', function $Array_delete$22(object) { + var $yield = $Array_delete$22.$$p || nil, self = this; + + $Array_delete$22.$$p = null; + + var original = self.length; + + for (var i = 0, length = original; i < length; i++) { + if ((self[i])['$=='](object)) { + $deny_frozen_access(self); + + self.splice(i, 1); + + length--; + i--; + } + } + + if (self.length === original) { + if (($yield !== nil)) { + return Opal.yieldX($yield, []); + } + return nil; + } + return object; + }); - Object.defineProperty(NodeWithChildren.prototype, "lastChild", { - /** Last child of the node. */ - get: function () { - return this.children.length > 0 - ? this.children[this.children.length - 1] - : null; - }, - enumerable: false, - configurable: true + + $def(self, '$delete_at', function $$delete_at(index) { + var self = this; + + + $deny_frozen_access(self); + + index = $coerce_to(index, $$$('Integer'), 'to_int'); + + if (index < 0) { + index += self.length; + } + + if (index < 0 || index >= self.length) { + return nil; + } + + var result = self[index]; + + self.splice(index, 1); + + return result; + }); - Object.defineProperty(NodeWithChildren.prototype, "childNodes", { - /** - * Same as {@link children}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.children; - }, - set: function (children) { - this.children = children; - }, - enumerable: false, - configurable: true + + $def(self, '$delete_if', function $$delete_if() { + var block = $$delete_if.$$p || nil, self = this; + + $$delete_if.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["delete_if"], function $$23(){var self = $$23.$$s == null ? this : $$23.$$s; + + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); + + filterIf(self, $falsy, block) + ; + return self; }); - return NodeWithChildren; -}(Node)); -exports.NodeWithChildren = NodeWithChildren; -var CDATA = /** @class */ (function (_super) { - __extends(CDATA, _super); - function CDATA() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.type = domelementtype_1.ElementType.CDATA; - return _this; - } - Object.defineProperty(CDATA.prototype, "nodeType", { - get: function () { - return 4; - }, - enumerable: false, - configurable: true + + $def(self, '$difference', function $$difference($a) { + var $post_args, arrays, self = this; + + + $post_args = $slice(arguments); + arrays = $post_args; + return $send(arrays, 'reduce', [self.$to_a().$dup()], function $$24(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return $rb_minus(a, b);}); + }, -1); + + $def(self, '$dig', function $$dig(idx, $a) { + var $post_args, idxs, self = this, item = nil; + + + $post_args = $slice(arguments, 1); + idxs = $post_args; + item = self['$[]'](idx); + + if (item === nil || idxs.length === 0) { + return item; + } + if (!$truthy(item['$respond_to?']("dig"))) { + $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method"); + } return $send(item, 'dig', $to_a(idxs)); + }, -2); + + $def(self, '$drop', function $$drop(number) { + var self = this; + + + number = $coerce_to(number, $$$('Integer'), 'to_int'); + + if (number < 0) { + $Kernel.$raise($$$('ArgumentError')); + } + + return self.slice(number); + }); - return CDATA; -}(NodeWithChildren)); -exports.CDATA = CDATA; -/** - * The root node of the document. - */ -var Document = /** @class */ (function (_super) { - __extends(Document, _super); - function Document() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.type = domelementtype_1.ElementType.Root; - return _this; - } - Object.defineProperty(Document.prototype, "nodeType", { - get: function () { - return 9; - }, - enumerable: false, - configurable: true + + $def(self, '$dup', function $$dup() { + var $yield = $$dup.$$p || nil, self = this; + + $$dup.$$p = null; + + + if (self.$$class === Opal.Array && + self.$$class.$allocate.$$pristine && + self.$copy_instance_variables.$$pristine && + self.$initialize_dup.$$pristine) { + return self.slice(0); + } + return $send2(self, $find_super(self, 'dup', $$dup, false, true), 'dup', [], $yield); }); - return Document; -}(NodeWithChildren)); -exports.Document = Document; -/** - * An element within the DOM. - */ -var Element = /** @class */ (function (_super) { - __extends(Element, _super); - /** - * @param name Name of the tag, eg. `div`, `span`. - * @param attribs Object mapping attribute names to attribute values. - * @param children Children of the node. - */ - function Element(name, attribs, children, type) { - if (children === void 0) { children = []; } - if (type === void 0) { type = name === "script" - ? domelementtype_1.ElementType.Script - : name === "style" - ? domelementtype_1.ElementType.Style - : domelementtype_1.ElementType.Tag; } - var _this = _super.call(this, children) || this; - _this.name = name; - _this.attribs = attribs; - _this.type = type; - return _this; - } - Object.defineProperty(Element.prototype, "nodeType", { - get: function () { - return 1; - }, - enumerable: false, - configurable: true + + $def(self, '$each', function $$each() { + var block = $$each.$$p || nil, self = this; + + $$each.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each"], function $$25(){var self = $$25.$$s == null ? this : $$25.$$s; + + return self.$size()}, {$$s: self}) + } + for (var i = 0, length = self.length; i < length; i++) { + $yield1(block, self[i]); + } + return self; }); - Object.defineProperty(Element.prototype, "tagName", { - // DOM Level 1 aliases - /** - * Same as {@link name}. - * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. - */ - get: function () { - return this.name; - }, - set: function (name) { - this.name = name; - }, - enumerable: false, - configurable: true + + $def(self, '$each_index', function $$each_index() { + var block = $$each_index.$$p || nil, self = this; + + $$each_index.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_index"], function $$26(){var self = $$26.$$s == null ? this : $$26.$$s; + + return self.$size()}, {$$s: self}) + } + for (var i = 0, length = self.length; i < length; i++) { + $yield1(block, i); + } + return self; }); - Object.defineProperty(Element.prototype, "attributes", { - get: function () { - var _this = this; - return Object.keys(this.attribs).map(function (name) { - var _a, _b; - return ({ - name: name, - value: _this.attribs[name], - namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name], - prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name], - }); - }); - }, - enumerable: false, - configurable: true + + $def(self, '$empty?', function $Array_empty$ques$27() { + var self = this; + + return self.length === 0; }); - return Element; -}(NodeWithChildren)); -exports.Element = Element; -/** - * @param node Node to check. - * @returns `true` if the node is a `Element`, `false` otherwise. - */ -function isTag(node) { - return (0, domelementtype_1.isTag)(node); -} -exports.isTag = isTag; -/** - * @param node Node to check. - * @returns `true` if the node has the type `CDATA`, `false` otherwise. - */ -function isCDATA(node) { - return node.type === domelementtype_1.ElementType.CDATA; -} -exports.isCDATA = isCDATA; -/** - * @param node Node to check. - * @returns `true` if the node has the type `Text`, `false` otherwise. - */ -function isText(node) { - return node.type === domelementtype_1.ElementType.Text; -} -exports.isText = isText; -/** - * @param node Node to check. - * @returns `true` if the node has the type `Comment`, `false` otherwise. - */ -function isComment(node) { - return node.type === domelementtype_1.ElementType.Comment; -} -exports.isComment = isComment; -/** - * @param node Node to check. - * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise. - */ -function isDirective(node) { - return node.type === domelementtype_1.ElementType.Directive; -} -exports.isDirective = isDirective; -/** - * @param node Node to check. - * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise. - */ -function isDocument(node) { - return node.type === domelementtype_1.ElementType.Root; -} -exports.isDocument = isDocument; -/** - * @param node Node to check. - * @returns `true` if the node has children, `false` otherwise. - */ -function hasChildren(node) { - return Object.prototype.hasOwnProperty.call(node, "children"); -} -exports.hasChildren = hasChildren; -/** - * Clone a node, and optionally its children. - * - * @param recursive Clone child nodes as well. - * @returns A clone of the node. - */ -function cloneNode(node, recursive) { - if (recursive === void 0) { recursive = false; } - var result; - if (isText(node)) { - result = new Text(node.data); - } - else if (isComment(node)) { - result = new Comment(node.data); - } - else if (isTag(node)) { - var children = recursive ? cloneChildren(node.children) : []; - var clone_1 = new Element(node.name, __assign({}, node.attribs), children); - children.forEach(function (child) { return (child.parent = clone_1); }); - if (node.namespace != null) { - clone_1.namespace = node.namespace; + + $def(self, '$eql?', function $Array_eql$ques$28(other) { + var self = this; + + + var recursed = {}; + + function _eql(array, other) { + var i, length, a, b; + + if (!other.$$is_array) { + return false; } - if (node["x-attribsNamespace"]) { - clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]); + + other = other.$to_a(); + + if (array.length !== other.length) { + return false; } - if (node["x-attribsPrefix"]) { - clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]); + + recursed[(array).$object_id()] = true; + + for (i = 0, length = array.length; i < length; i++) { + a = array[i]; + b = other[i]; + if (a.$$is_array) { + if (b.$$is_array && b.length !== a.length) { + return false; + } + if (!recursed.hasOwnProperty((a).$object_id())) { + if (!_eql(a, b)) { + return false; + } + } + } else { + if (!(a)['$eql?'](b)) { + return false; + } + } } - result = clone_1; - } - else if (isCDATA(node)) { - var children = recursive ? cloneChildren(node.children) : []; - var clone_2 = new CDATA(children); - children.forEach(function (child) { return (child.parent = clone_2); }); - result = clone_2; - } - else if (isDocument(node)) { - var children = recursive ? cloneChildren(node.children) : []; - var clone_3 = new Document(children); - children.forEach(function (child) { return (child.parent = clone_3); }); - if (node["x-mode"]) { - clone_3["x-mode"] = node["x-mode"]; + + return true; + } + + return _eql(self, other); + + }); + + $def(self, '$fetch', function $$fetch(index, defaults) { + var block = $$fetch.$$p || nil, self = this; + + $$fetch.$$p = null; + + var original = index; + + index = $coerce_to(index, $$$('Integer'), 'to_int'); + + if (index < 0) { + index += self.length; + } + + if (index >= 0 && index < self.length) { + return self[index]; + } + + if (block !== nil && defaults != null) { + self.$warn("warning: block supersedes default value argument"); + } + + if (block !== nil) { + return block(original); + } + + if (defaults != null) { + return defaults; + } + + if (self.length === 0) { + $Kernel.$raise($$$('IndexError'), "index " + (original) + " outside of array bounds: 0...0"); + } + else { + $Kernel.$raise($$$('IndexError'), "index " + (original) + " outside of array bounds: -" + (self.length) + "..." + (self.length)); + } + }, -2); + + $def(self, '$fill', function $$fill($a) { + var block = $$fill.$$p || nil, $post_args, args, $b, $c, self = this, one = nil, two = nil, obj = nil, left = nil, right = nil; + + $$fill.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + $deny_frozen_access(self); + + var i, value; + if ($truthy(block)) { + + if ($truthy(args.length > 2)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$length()) + " for 0..2)"); + } $c = args, $b = $to_ary($c), (one = ($b[0] == null ? nil : $b[0])), (two = ($b[1] == null ? nil : $b[1])); + } else { + + if ($truthy(args.length == 0)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)"); + } else if ($truthy(args.length > 3)) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$length()) + " for 1..3)"); + } $c = args, $b = $to_ary($c), (obj = ($b[0] == null ? nil : $b[0])), (one = ($b[1] == null ? nil : $b[1])), (two = ($b[2] == null ? nil : $b[2])); + } if ($eqeqeq($$$('Range'), one)) { + + if ($truthy(two)) { + $Kernel.$raise($$$('TypeError'), "length invalid with range"); + } left = one.begin === nil ? 0 : $coerce_to(one.begin, $$$('Integer'), 'to_int'); + if ($truthy(left < 0)) { + left += this.length; + } if ($truthy(left < 0)) { + $Kernel.$raise($$$('RangeError'), "" + (one.$inspect()) + " out of range"); + } right = one.end === nil ? -1 : $coerce_to(one.end, $$$('Integer'), 'to_int'); + if ($truthy(right < 0)) { + right += this.length; + } if (!$truthy(one['$exclude_end?']())) { + right += 1; + } if ($truthy(right <= left)) { + return self + } } else if ($truthy(one)) { + + left = $coerce_to(one, $$$('Integer'), 'to_int'); + if ($truthy(left < 0)) { + left += this.length; + } if ($truthy(left < 0)) { + left = 0; + } if ($truthy(two)) { + + right = $coerce_to(two, $$$('Integer'), 'to_int'); + if ($truthy(right == 0)) { + return self + } right += left; + } else { + right = this.length; + } } else { + + left = 0; + right = this.length; + } if ($truthy(left > this.length)) { + + for (i = this.length; i < right; i++) { + self[i] = nil; } - result = clone_3; - } - else if (isDirective(node)) { - var instruction = new ProcessingInstruction(node.name, node.data); - if (node["x-name"] != null) { - instruction["x-name"] = node["x-name"]; - instruction["x-publicId"] = node["x-publicId"]; - instruction["x-systemId"] = node["x-systemId"]; + + } if ($truthy(right > this.length)) { + this.length = right; + } if ($truthy(block)) { + + for (this.length; left < right; left++) { + value = block(left); + self[left] = value; } - result = instruction; - } - else { - throw new Error("Not implemented yet: ".concat(node.type)); - } - result.startIndex = node.startIndex; - result.endIndex = node.endIndex; - if (node.sourceCodeLocation != null) { - result.sourceCodeLocation = node.sourceCodeLocation; - } - return result; -} -exports.cloneNode = cloneNode; -function cloneChildren(childs) { - var children = childs.map(function (child) { return cloneNode(child, true); }); - for (var i = 1; i < children.length; i++) { - children[i].prev = children[i - 1]; - children[i - 1].next = children[i]; - } - return children; -} + + } else { + + for (this.length; left < right; left++) { + self[left] = obj; + } + + } return self; + }, -1); + + $def(self, '$first', function $$first(count) { + var self = this; + + if (count == null) { + return self.length === 0 ? nil : self[0]; + } + count = $coerce_to(count, $$$('Integer'), 'to_int'); -/***/ }), + if (count < 0) { + $Kernel.$raise($$$('ArgumentError'), "negative array size"); + } -/***/ 1503: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + return self.slice(0, count); + }, -1); + + $def(self, '$flatten', function $$flatten(level) { + var self = this; + + function _flatten(array, level) { + var result = [], + i, length, + item, ary; -"use strict"; + array = (array).$to_a(); -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getFeed = void 0; -var stringify_js_1 = __nccwpck_require__(9561); -var legacy_js_1 = __nccwpck_require__(2185); -/** - * Get the feed object from the root of a DOM tree. - * - * @category Feeds - * @param doc - The DOM to to extract the feed from. - * @returns The feed. - */ -function getFeed(doc) { - var feedRoot = getOneElement(isValidFeed, doc); - return !feedRoot - ? null - : feedRoot.name === "feed" - ? getAtomFeed(feedRoot) - : getRssFeed(feedRoot); -} -exports.getFeed = getFeed; -/** - * Parse an Atom feed. - * - * @param feedRoot The root of the feed. - * @returns The parsed feed. - */ -function getAtomFeed(feedRoot) { - var _a; - var childs = feedRoot.children; - var feed = { - type: "atom", - items: (0, legacy_js_1.getElementsByTagName)("entry", childs).map(function (item) { - var _a; - var children = item.children; - var entry = { media: getMediaElements(children) }; - addConditionally(entry, "id", "id", children); - addConditionally(entry, "title", "title", children); - var href = (_a = getOneElement("link", children)) === null || _a === void 0 ? void 0 : _a.attribs["href"]; - if (href) { - entry.link = href; - } - var description = fetch("summary", children) || fetch("content", children); - if (description) { - entry.description = description; - } - var pubDate = fetch("updated", children); - if (pubDate) { - entry.pubDate = new Date(pubDate); - } - return entry; - }), - }; - addConditionally(feed, "id", "id", childs); - addConditionally(feed, "title", "title", childs); - var href = (_a = getOneElement("link", childs)) === null || _a === void 0 ? void 0 : _a.attribs["href"]; - if (href) { - feed.link = href; - } - addConditionally(feed, "description", "subtitle", childs); - var updated = fetch("updated", childs); - if (updated) { - feed.updated = new Date(updated); - } - addConditionally(feed, "author", "email", childs, true); - return feed; -} -/** - * Parse a RSS feed. - * - * @param feedRoot The root of the feed. - * @returns The parsed feed. - */ -function getRssFeed(feedRoot) { - var _a, _b; - var childs = (_b = (_a = getOneElement("channel", feedRoot.children)) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : []; - var feed = { - type: feedRoot.name.substr(0, 3), - id: "", - items: (0, legacy_js_1.getElementsByTagName)("item", feedRoot.children).map(function (item) { - var children = item.children; - var entry = { media: getMediaElements(children) }; - addConditionally(entry, "id", "guid", children); - addConditionally(entry, "title", "title", children); - addConditionally(entry, "link", "link", children); - addConditionally(entry, "description", "description", children); - var pubDate = fetch("pubDate", children) || fetch("dc:date", children); - if (pubDate) - entry.pubDate = new Date(pubDate); - return entry; - }), - }; - addConditionally(feed, "title", "title", childs); - addConditionally(feed, "link", "link", childs); - addConditionally(feed, "description", "description", childs); - var updated = fetch("lastBuildDate", childs); - if (updated) { - feed.updated = new Date(updated); - } - addConditionally(feed, "author", "managingEditor", childs, true); - return feed; -} -var MEDIA_KEYS_STRING = ["url", "type", "lang"]; -var MEDIA_KEYS_INT = [ - "fileSize", - "bitrate", - "framerate", - "samplingrate", - "channels", - "duration", - "height", - "width", -]; -/** - * Get all media elements of a feed item. - * - * @param where Nodes to search in. - * @returns Media elements. - */ -function getMediaElements(where) { - return (0, legacy_js_1.getElementsByTagName)("media:content", where).map(function (elem) { - var attribs = elem.attribs; - var media = { - medium: attribs["medium"], - isDefault: !!attribs["isDefault"], - }; - for (var _i = 0, MEDIA_KEYS_STRING_1 = MEDIA_KEYS_STRING; _i < MEDIA_KEYS_STRING_1.length; _i++) { - var attrib = MEDIA_KEYS_STRING_1[_i]; - if (attribs[attrib]) { - media[attrib] = attribs[attrib]; - } + for (i = 0, length = array.length; i < length; i++) { + item = array[i]; + + if (!$respond_to(item, '$to_ary', true)) { + result.push(item); + continue; + } + + ary = (item).$to_ary(); + + if (ary === nil) { + result.push(item); + continue; + } + + if (!ary.$$is_array) { + $Kernel.$raise($$$('TypeError')); + } + + if (ary === self) { + $Kernel.$raise($$$('ArgumentError')); + } + + switch (level) { + case undefined: + result = result.concat(_flatten(ary)); + break; + case 0: + result.push(ary); + break; + default: + result.push.apply(result, _flatten(ary, level - 1)); + } } - for (var _a = 0, MEDIA_KEYS_INT_1 = MEDIA_KEYS_INT; _a < MEDIA_KEYS_INT_1.length; _a++) { - var attrib = MEDIA_KEYS_INT_1[_a]; - if (attribs[attrib]) { - media[attrib] = parseInt(attribs[attrib], 10); - } + return result; + } + + if (level !== undefined) { + level = $coerce_to(level, $$$('Integer'), 'to_int'); + } + + return _flatten(self, level); + }, -1); + + $def(self, '$flatten!', function $Array_flatten$excl$29(level) { + var self = this; + + $deny_frozen_access(self); + + var flattened = self.$flatten(level); + + if (self.length == flattened.length) { + for (var i = 0, length = self.length; i < length; i++) { + if (self[i] !== flattened[i]) { + break; + } } - if (attribs["expression"]) { - media.expression = attribs["expression"]; + + if (i == length) { + return nil; + } + } + + self.$replace(flattened); + return self; + }, -1); + + $def(self, '$freeze', function $$freeze() { + var self = this; + + + if ($truthy(self['$frozen?']())) { + return self + } return $freeze(self); }); + + $def(self, '$hash', function $$hash() { + var self = this; + + + var top = ($hash_ids === undefined), + result = ['A'], + hash_id = self.$object_id(), + item, i, key; + + try { + if (top) { + $hash_ids = Object.create(null); } - return media; - }); -} -/** - * Get one element by tag name. - * - * @param tagName Tag name to look for - * @param node Node to search in - * @returns The element or null - */ -function getOneElement(tagName, node) { - return (0, legacy_js_1.getElementsByTagName)(tagName, node, true, 1)[0]; -} -/** - * Get the text content of an element with a certain tag name. - * - * @param tagName Tag name to look for. - * @param where Node to search in. - * @param recurse Whether to recurse into child nodes. - * @returns The text content of the element. - */ -function fetch(tagName, where, recurse) { - if (recurse === void 0) { recurse = false; } - return (0, stringify_js_1.textContent)((0, legacy_js_1.getElementsByTagName)(tagName, where, recurse, 1)).trim(); -} -/** - * Adds a property to an object if it has a value. - * - * @param obj Object to be extended - * @param prop Property name - * @param tagName Tag name that contains the conditionally added property - * @param where Element to search for the property - * @param recurse Whether to recurse into child nodes. - */ -function addConditionally(obj, prop, tagName, where, recurse) { - if (recurse === void 0) { recurse = false; } - var val = fetch(tagName, where, recurse); - if (val) - obj[prop] = val; -} -/** - * Checks if an element is a feed root node. - * - * @param value The name of the element to check. - * @returns Whether an element is a feed root node. - */ -function isValidFeed(value) { - return value === "rss" || value === "feed" || value === "rdf:RDF"; -} -//# sourceMappingURL=feeds.js.map -/***/ }), + // return early for recursive structures + if ($hash_ids[hash_id]) { + return 'self'; + } -/***/ 1447: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + for (key in $hash_ids) { + item = $hash_ids[key]; + if (self['$eql?'](item)) { + return 'self'; + } + } -"use strict"; + $hash_ids[hash_id] = self; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.uniqueSort = exports.compareDocumentPosition = exports.DocumentPosition = exports.removeSubsets = void 0; -var domhandler_1 = __nccwpck_require__(4038); -/** - * Given an array of nodes, remove any member that is contained by another - * member. - * - * @category Helpers - * @param nodes Nodes to filter. - * @returns Remaining nodes that aren't contained by other nodes. - */ -function removeSubsets(nodes) { - var idx = nodes.length; - /* - * Check if each node (or one of its ancestors) is already contained in the - * array. - */ - while (--idx >= 0) { - var node = nodes[idx]; - /* - * Remove the node if it is not unique. - * We are going through the array from the end, so we only - * have to check nodes that preceed the node under consideration in the array. - */ - if (idx > 0 && nodes.lastIndexOf(node, idx - 1) >= 0) { - nodes.splice(idx, 1); - continue; + for (i = 0; i < self.length; i++) { + item = self[i]; + result.push(item.$hash()); } - for (var ancestor = node.parent; ancestor; ancestor = ancestor.parent) { - if (nodes.includes(ancestor)) { - nodes.splice(idx, 1); - break; - } + + return result.join(','); + } finally { + if (top) { + $hash_ids = undefined; } - } - return nodes; -} -exports.removeSubsets = removeSubsets; -/** - * @category Helpers - * @see {@link http://dom.spec.whatwg.org/#dom-node-comparedocumentposition} - */ -var DocumentPosition; -(function (DocumentPosition) { - DocumentPosition[DocumentPosition["DISCONNECTED"] = 1] = "DISCONNECTED"; - DocumentPosition[DocumentPosition["PRECEDING"] = 2] = "PRECEDING"; - DocumentPosition[DocumentPosition["FOLLOWING"] = 4] = "FOLLOWING"; - DocumentPosition[DocumentPosition["CONTAINS"] = 8] = "CONTAINS"; - DocumentPosition[DocumentPosition["CONTAINED_BY"] = 16] = "CONTAINED_BY"; -})(DocumentPosition = exports.DocumentPosition || (exports.DocumentPosition = {})); -/** - * Compare the position of one node against another node in any other document, - * returning a bitmask with the values from {@link DocumentPosition}. - * - * Document order: - * > There is an ordering, document order, defined on all the nodes in the - * > document corresponding to the order in which the first character of the - * > XML representation of each node occurs in the XML representation of the - * > document after expansion of general entities. Thus, the document element - * > node will be the first node. Element nodes occur before their children. - * > Thus, document order orders element nodes in order of the occurrence of - * > their start-tag in the XML (after expansion of entities). The attribute - * > nodes of an element occur after the element and before its children. The - * > relative order of attribute nodes is implementation-dependent. - * - * Source: - * http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order - * - * @category Helpers - * @param nodeA The first node to use in the comparison - * @param nodeB The second node to use in the comparison - * @returns A bitmask describing the input nodes' relative position. - * - * See http://dom.spec.whatwg.org/#dom-node-comparedocumentposition for - * a description of these values. - */ -function compareDocumentPosition(nodeA, nodeB) { - var aParents = []; - var bParents = []; - if (nodeA === nodeB) { - return 0; - } - var current = (0, domhandler_1.hasChildren)(nodeA) ? nodeA : nodeA.parent; - while (current) { - aParents.unshift(current); - current = current.parent; - } - current = (0, domhandler_1.hasChildren)(nodeB) ? nodeB : nodeB.parent; - while (current) { - bParents.unshift(current); - current = current.parent; - } - var maxIdx = Math.min(aParents.length, bParents.length); - var idx = 0; - while (idx < maxIdx && aParents[idx] === bParents[idx]) { - idx++; - } - if (idx === 0) { - return DocumentPosition.DISCONNECTED; - } - var sharedParent = aParents[idx - 1]; - var siblings = sharedParent.children; - var aSibling = aParents[idx]; - var bSibling = bParents[idx]; - if (siblings.indexOf(aSibling) > siblings.indexOf(bSibling)) { - if (sharedParent === nodeB) { - return DocumentPosition.FOLLOWING | DocumentPosition.CONTAINED_BY; + } + + }); + + $def(self, '$include?', function $Array_include$ques$30(member) { + var self = this; + + + for (var i = 0, length = self.length; i < length; i++) { + if ((self[i])['$=='](member)) { + return true; } - return DocumentPosition.FOLLOWING; - } - if (sharedParent === nodeA) { - return DocumentPosition.PRECEDING | DocumentPosition.CONTAINS; - } - return DocumentPosition.PRECEDING; -} -exports.compareDocumentPosition = compareDocumentPosition; -/** - * Sort an array of nodes based on their relative position in the document, - * removing any duplicate nodes. If the array contains nodes that do not belong - * to the same document, sort order is unspecified. - * - * @category Helpers - * @param nodes Array of DOM nodes. - * @returns Collection of unique nodes, sorted in document order. - */ -function uniqueSort(nodes) { - nodes = nodes.filter(function (node, i, arr) { return !arr.includes(node, i + 1); }); - nodes.sort(function (a, b) { - var relative = compareDocumentPosition(a, b); - if (relative & DocumentPosition.PRECEDING) { - return -1; + } + + return false; + + }); + + $def(self, '$index', function $$index(object) { + var block = $$index.$$p || nil, self = this; + + $$index.$$p = null; + + var i, length, value; + + if (object != null && block !== nil) { + self.$warn("warning: given block not used"); + } + + if (object != null) { + for (i = 0, length = self.length; i < length; i++) { + if ((self[i])['$=='](object)) { + return i; + } } - else if (relative & DocumentPosition.FOLLOWING) { - return 1; + } + else if (block !== nil) { + for (i = 0, length = self.length; i < length; i++) { + value = block(self[i]); + + if (value !== false && value !== nil) { + return i; + } } - return 0; - }); - return nodes; -} -exports.uniqueSort = uniqueSort; -//# sourceMappingURL=helpers.js.map + } + else { + return self.$enum_for("index"); + } -/***/ }), + return nil; + }, -1); + + $def(self, '$insert', function $$insert(index, $a) { + var $post_args, objects, self = this; -/***/ 1754: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + + $post_args = $slice(arguments, 1); + objects = $post_args; + + $deny_frozen_access(self); -"use strict"; + index = $coerce_to(index, $$$('Integer'), 'to_int'); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.hasChildren = exports.isDocument = exports.isComment = exports.isText = exports.isCDATA = exports.isTag = void 0; -__exportStar(__nccwpck_require__(9561), exports); -__exportStar(__nccwpck_require__(9228), exports); -__exportStar(__nccwpck_require__(177), exports); -__exportStar(__nccwpck_require__(9908), exports); -__exportStar(__nccwpck_require__(2185), exports); -__exportStar(__nccwpck_require__(1447), exports); -__exportStar(__nccwpck_require__(1503), exports); -/** @deprecated Use these methods from `domhandler` directly. */ -var domhandler_1 = __nccwpck_require__(4038); -Object.defineProperty(exports, "isTag", ({ enumerable: true, get: function () { return domhandler_1.isTag; } })); -Object.defineProperty(exports, "isCDATA", ({ enumerable: true, get: function () { return domhandler_1.isCDATA; } })); -Object.defineProperty(exports, "isText", ({ enumerable: true, get: function () { return domhandler_1.isText; } })); -Object.defineProperty(exports, "isComment", ({ enumerable: true, get: function () { return domhandler_1.isComment; } })); -Object.defineProperty(exports, "isDocument", ({ enumerable: true, get: function () { return domhandler_1.isDocument; } })); -Object.defineProperty(exports, "hasChildren", ({ enumerable: true, get: function () { return domhandler_1.hasChildren; } })); -//# sourceMappingURL=index.js.map + if (objects.length > 0) { + if (index < 0) { + index += self.length + 1; -/***/ }), + if (index < 0) { + $Kernel.$raise($$$('IndexError'), "" + (index) + " is out of bounds"); + } + } + if (index > self.length) { + for (var i = self.length; i < index; i++) { + self.push(nil); + } + } -/***/ 2185: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + self.splice.apply(self, [index, 0].concat(objects)); + } + return self; + }, -2); + var inspect_stack = []; + + $def(self, '$inspect', function $$inspect() { + var self = this; -"use strict"; + + + var result = [], + id = self.$__id__(), + pushed = true; + + return (function() { try { + + + if (inspect_stack.indexOf(id) !== -1) { + pushed = false; + return '[...]'; + } + inspect_stack.push(id); -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getElementsByTagType = exports.getElementsByTagName = exports.getElementById = exports.getElements = exports.testElement = void 0; -var domhandler_1 = __nccwpck_require__(4038); -var querying_js_1 = __nccwpck_require__(9908); -/** - * A map of functions to check nodes against. - */ -var Checks = { - tag_name: function (name) { - if (typeof name === "function") { - return function (elem) { return (0, domhandler_1.isTag)(elem) && name(elem.name); }; + for (var i = 0, length = self.length; i < length; i++) { + var item = self['$[]'](i); + + result.push($$('Opal').$inspect(item)); } - else if (name === "*") { - return domhandler_1.isTag; + + return '[' + result.join(', ') + ']'; + ; + return nil; + } finally { + if (pushed) inspect_stack.pop(); + } })(); }); + + $def(self, '$intersection', function $$intersection($a) { + var $post_args, arrays, self = this; + + + $post_args = $slice(arguments); + arrays = $post_args; + return $send(arrays, 'reduce', [self.$to_a().$dup()], function $$31(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$&'](b);}); + }, -1); + + $def(self, '$intersect?', function $Array_intersect$ques$32(other) { + var self = this; + + return self.$intersection(other)['$empty?']()['$!']() + }); + + $def(self, '$join', function $$join(sep) { + var self = this; + if ($gvars[","] == null) $gvars[","] = nil; + + + if (sep == null) sep = nil; + if ($truthy(self.length === 0)) { + return "" + } if ($truthy(sep === nil)) { + sep = $gvars[","]; + } + var result = []; + var i, length, item, tmp; + + for (i = 0, length = self.length; i < length; i++) { + item = self[i]; + + if ($respond_to(item, '$to_str')) { + tmp = (item).$to_str(); + + if (tmp !== nil) { + result.push((tmp).$to_s()); + + continue; + } } - return function (elem) { return (0, domhandler_1.isTag)(elem) && elem.name === name; }; - }, - tag_type: function (type) { - if (typeof type === "function") { - return function (elem) { return type(elem.type); }; + + if ($respond_to(item, '$to_ary')) { + tmp = (item).$to_ary(); + + if (tmp === self) { + $Kernel.$raise($$$('ArgumentError')); + } + + if (tmp !== nil) { + result.push((tmp).$join(sep)); + + continue; + } } - return function (elem) { return elem.type === type; }; - }, - tag_contains: function (data) { - if (typeof data === "function") { - return function (elem) { return (0, domhandler_1.isText)(elem) && data(elem.data); }; + + if ($respond_to(item, '$to_s')) { + tmp = (item).$to_s(); + + if (tmp !== nil) { + result.push(tmp); + + continue; + } } - return function (elem) { return (0, domhandler_1.isText)(elem) && elem.data === data; }; - }, -}; -/** - * Returns a function to check whether a node has an attribute with a particular - * value. - * - * @param attrib Attribute to check. - * @param value Attribute value to look for. - * @returns A function to check whether the a node has an attribute with a - * particular value. - */ -function getAttribCheck(attrib, value) { - if (typeof value === "function") { - return function (elem) { return (0, domhandler_1.isTag)(elem) && value(elem.attribs[attrib]); }; - } - return function (elem) { return (0, domhandler_1.isTag)(elem) && elem.attribs[attrib] === value; }; -} -/** - * Returns a function that returns `true` if either of the input functions - * returns `true` for a node. - * - * @param a First function to combine. - * @param b Second function to combine. - * @returns A function taking a node and returning `true` if either of the input - * functions returns `true` for the node. - */ -function combineFuncs(a, b) { - return function (elem) { return a(elem) || b(elem); }; -} -/** - * Returns a function that executes all checks in `options` and returns `true` - * if any of them match a node. - * - * @param options An object describing nodes to look for. - * @returns A function that executes all checks in `options` and returns `true` - * if any of them match a node. - */ -function compileTest(options) { - var funcs = Object.keys(options).map(function (key) { - var value = options[key]; - return Object.prototype.hasOwnProperty.call(Checks, key) - ? Checks[key](value) - : getAttribCheck(key, value); + + $Kernel.$raise($$$('NoMethodError').$new("" + ($$('Opal').$inspect(self.$item())) + " doesn't respond to #to_str, #to_ary or #to_s", "to_str")); + } + + if (sep === nil) { + return result.join(''); + } + else { + return result.join($Opal['$coerce_to!'](sep, $$$('String'), "to_str").$to_s()); + } + }, -1); + + $def(self, '$keep_if', function $$keep_if() { + var block = $$keep_if.$$p || nil, self = this; + + $$keep_if.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["keep_if"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s; + + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); + + filterIf(self, $truthy, block) + ; + return self; }); - return funcs.length === 0 ? null : funcs.reduce(combineFuncs); -} -/** - * Checks whether a node matches the description in `options`. - * - * @category Legacy Query Functions - * @param options An object describing nodes to look for. - * @param node The element to test. - * @returns Whether the element matches the description in `options`. - */ -function testElement(options, node) { - var test = compileTest(options); - return test ? test(node) : true; -} -exports.testElement = testElement; -/** - * Returns all nodes that match `options`. - * - * @category Legacy Query Functions - * @param options An object describing nodes to look for. - * @param nodes Nodes to search through. - * @param recurse Also consider child nodes. - * @param limit Maximum number of nodes to return. - * @returns All nodes that match `options`. - */ -function getElements(options, nodes, recurse, limit) { - if (limit === void 0) { limit = Infinity; } - var test = compileTest(options); - return test ? (0, querying_js_1.filter)(test, nodes, recurse, limit) : []; -} -exports.getElements = getElements; -/** - * Returns the node with the supplied ID. - * - * @category Legacy Query Functions - * @param id The unique ID attribute value to look for. - * @param nodes Nodes to search through. - * @param recurse Also consider child nodes. - * @returns The node with the supplied ID. - */ -function getElementById(id, nodes, recurse) { - if (recurse === void 0) { recurse = true; } - if (!Array.isArray(nodes)) - nodes = [nodes]; - return (0, querying_js_1.findOne)(getAttribCheck("id", id), nodes, recurse); -} -exports.getElementById = getElementById; -/** - * Returns all nodes with the supplied `tagName`. - * - * @category Legacy Query Functions - * @param tagName Tag name to search for. - * @param nodes Nodes to search through. - * @param recurse Also consider child nodes. - * @param limit Maximum number of nodes to return. - * @returns All nodes with the supplied `tagName`. - */ -function getElementsByTagName(tagName, nodes, recurse, limit) { - if (recurse === void 0) { recurse = true; } - if (limit === void 0) { limit = Infinity; } - return (0, querying_js_1.filter)(Checks["tag_name"](tagName), nodes, recurse, limit); -} -exports.getElementsByTagName = getElementsByTagName; -/** - * Returns all nodes with the supplied `type`. - * - * @category Legacy Query Functions - * @param type Element type to look for. - * @param nodes Nodes to search through. - * @param recurse Also consider child nodes. - * @param limit Maximum number of nodes to return. - * @returns All nodes with the supplied `type`. - */ -function getElementsByTagType(type, nodes, recurse, limit) { - if (recurse === void 0) { recurse = true; } - if (limit === void 0) { limit = Infinity; } - return (0, querying_js_1.filter)(Checks["tag_type"](type), nodes, recurse, limit); -} -exports.getElementsByTagType = getElementsByTagType; -//# sourceMappingURL=legacy.js.map + + $def(self, '$last', function $$last(count) { + var self = this; + + if (count == null) { + return self.length === 0 ? nil : self[self.length - 1]; + } + + count = $coerce_to(count, $$$('Integer'), 'to_int'); + + if (count < 0) { + $Kernel.$raise($$$('ArgumentError'), "negative array size"); + } + + if (count > self.length) { + count = self.length; + } + + return self.slice(self.length - count, self.length); + }, -1); + + $def(self, '$length', function $$length() { + var self = this; + + return self.length; + }); + + $def(self, '$max', function $$max(n) { + var block = $$max.$$p || nil, self = this; + + $$max.$$p = null; + return $send(self.$each(), 'max', [n], block.$to_proc()); + }, -1); + + $def(self, '$min', function $$min() { + var block = $$min.$$p || nil, self = this; + + $$min.$$p = null; + return $send(self.$each(), 'min', [], block.$to_proc()); + }); + + // Returns the product of from, from-1, ..., from - how_many + 1. + function descending_factorial(from, how_many) { + var count = how_many >= 0 ? 1 : 0; + while (how_many) { + count *= from; + from--; + how_many--; + } + return count; + } + + $def(self, '$permutation', function $$permutation(num) { + var block = $$permutation.$$p || nil, self = this, perm = nil, used = nil; + + $$permutation.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["permutation", num], function $$34(){var self = $$34.$$s == null ? this : $$34.$$s; + + return descending_factorial(self.length, num === undefined ? self.length : num);}, {$$s: self}) + } + var permute, offensive, output; + + if (num === undefined) { + num = self.length; + } + else { + num = $coerce_to(num, $$$('Integer'), 'to_int'); + } + + if (num < 0 || self.length < num) ; + else if (num === 0) { + // exactly one permutation: the zero-length array + Opal.yield1(block, []); + } + else if (num === 1) { + // this is a special, easy case + for (var i = 0; i < self.length; i++) { + Opal.yield1(block, [self[i]]); + } + } + else { + // this is the general case + (perm = $$('Array').$new(num)); + (used = $$('Array').$new(self.length, false)); -/***/ }), + permute = function(num, perm, index, used, blk) { + self = this; + for(var i = 0; i < self.length; i++){ + if(used['$[]'](i)['$!']()) { + perm[index] = i; + if(index < num - 1) { + used[i] = true; + permute.call(self, num, perm, index + 1, used, blk); + used[i] = false; + } + else { + output = []; + for (var j = 0; j < perm.length; j++) { + output.push(self[perm[j]]); + } + $yield1(blk, output); + } + } + } + }; -/***/ 177: -/***/ ((__unused_webpack_module, exports) => { + if ((block !== nil)) { + // offensive (both definitions) copy. + offensive = self.slice(); + permute.call(offensive, num, perm, 0, used, block); + } + else { + permute.call(self, num, perm, 0, used, block); + } + } + return self; + }, -1); + + $def(self, '$repeated_permutation', function $$repeated_permutation(n) { + var $yield = $$repeated_permutation.$$p || nil, self = this, num = nil; -"use strict"; + $$repeated_permutation.$$p = null; + + num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["repeated_permutation", num], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.prepend = exports.prependChild = exports.append = exports.appendChild = exports.replaceElement = exports.removeElement = void 0; -/** - * Remove an element from the dom - * - * @category Manipulation - * @param elem The element to be removed - */ -function removeElement(elem) { - if (elem.prev) - elem.prev.next = elem.next; - if (elem.next) - elem.next.prev = elem.prev; - if (elem.parent) { - var childs = elem.parent.children; - var childsIndex = childs.lastIndexOf(elem); - if (childsIndex >= 0) { - childs.splice(childsIndex, 1); + if ($truthy($rb_ge(num, 0))) { + return self.$size()['$**'](num) + } else { + return 0 + }}, {$$s: self}) + } + function iterate(max, buffer, self) { + if (buffer.length == max) { + var copy = buffer.slice(); + Opal.yield1($yield, copy); + return; } - } - elem.next = null; - elem.prev = null; - elem.parent = null; -} -exports.removeElement = removeElement; -/** - * Replace an element in the dom - * - * @category Manipulation - * @param elem The element to be replaced - * @param replacement The element to be added - */ -function replaceElement(elem, replacement) { - var prev = (replacement.prev = elem.prev); - if (prev) { - prev.next = replacement; - } - var next = (replacement.next = elem.next); - if (next) { - next.prev = replacement; - } - var parent = (replacement.parent = elem.parent); - if (parent) { - var childs = parent.children; - childs[childs.lastIndexOf(elem)] = replacement; - elem.parent = null; - } -} -exports.replaceElement = replaceElement; -/** - * Append a child to an element. - * - * @category Manipulation - * @param parent The element to append to. - * @param child The element to be added as a child. - */ -function appendChild(parent, child) { - removeElement(child); - child.next = null; - child.parent = parent; - if (parent.children.push(child) > 1) { - var sibling = parent.children[parent.children.length - 2]; - sibling.next = child; - child.prev = sibling; - } - else { - child.prev = null; - } -} -exports.appendChild = appendChild; -/** - * Append an element after another. - * - * @category Manipulation - * @param elem The element to append after. - * @param next The element be added. - */ -function append(elem, next) { - removeElement(next); - var parent = elem.parent; - var currNext = elem.next; - next.next = currNext; - next.prev = elem; - elem.next = next; - next.parent = parent; - if (currNext) { - currNext.prev = next; - if (parent) { - var childs = parent.children; - childs.splice(childs.lastIndexOf(currNext), 0, next); + for (var i = 0; i < self.length; i++) { + buffer.push(self[i]); + iterate(max, buffer, self); + buffer.pop(); } - } - else if (parent) { - parent.children.push(next); - } -} -exports.append = append; -/** - * Prepend a child to an element. - * - * @category Manipulation - * @param parent The element to prepend before. - * @param child The element to be added as a child. - */ -function prependChild(parent, child) { - removeElement(child); - child.parent = parent; - child.prev = null; - if (parent.children.unshift(child) !== 1) { - var sibling = parent.children[1]; - sibling.prev = child; - child.next = sibling; - } - else { - child.next = null; - } -} -exports.prependChild = prependChild; -/** - * Prepend an element before another. - * - * @category Manipulation - * @param elem The element to prepend before. - * @param prev The element be added. - */ -function prepend(elem, prev) { - removeElement(prev); - var parent = elem.parent; - if (parent) { - var childs = parent.children; - childs.splice(childs.indexOf(elem), 0, prev); - } - if (elem.prev) { - elem.prev.next = prev; - } - prev.parent = parent; - prev.prev = elem.prev; - prev.next = elem; - elem.prev = prev; -} -exports.prepend = prepend; -//# sourceMappingURL=manipulation.js.map + } -/***/ }), + iterate(num, [], self.slice()); + return self; + }); + + $def(self, '$pop', function $$pop(count) { + var self = this; + $deny_frozen_access(self); + if ($truthy(count === undefined)) { + + if ($truthy(self.length === 0)) { + return nil + } return self.pop(); + } count = $coerce_to(count, $$$('Integer'), 'to_int'); + if ($truthy(count < 0)) { + $Kernel.$raise($$$('ArgumentError'), "negative array size"); + } if ($truthy(self.length === 0)) { + return [] + } if ($truthy(count === 1)) { + return [self.pop()]; + } else if ($truthy(count > self.length)) { + return self.splice(0, self.length); + } else { + return self.splice(self.length - count, self.length); + } }, -1); + + $def(self, '$product', function $$product($a) { + var block = $$product.$$p || nil, $post_args, args, self = this; -/***/ 9908: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + $$product.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + var result = (block !== nil) ? null : [], + n = args.length + 1, + counters = new Array(n), + lengths = new Array(n), + arrays = new Array(n), + i, m, subarray, len, resultlen = 1; -"use strict"; + arrays[0] = self; + for (i = 1; i < n; i++) { + arrays[i] = $coerce_to(args[i - 1], $$$('Array'), 'to_ary'); + } -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.findAll = exports.existsOne = exports.findOne = exports.findOneChild = exports.find = exports.filter = void 0; -var domhandler_1 = __nccwpck_require__(4038); -/** - * Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one. - * - * @category Querying - * @param test Function to test nodes on. - * @param node Node to search. Will be included in the result set if it matches. - * @param recurse Also consider child nodes. - * @param limit Maximum number of nodes to return. - * @returns All nodes passing `test`. - */ -function filter(test, node, recurse, limit) { - if (recurse === void 0) { recurse = true; } - if (limit === void 0) { limit = Infinity; } - return find(test, Array.isArray(node) ? node : [node], recurse, limit); -} -exports.filter = filter; -/** - * Search an array of nodes and their children for nodes passing a test function. - * - * @category Querying - * @param test Function to test nodes on. - * @param nodes Array of nodes to search. - * @param recurse Also consider child nodes. - * @param limit Maximum number of nodes to return. - * @returns All nodes passing `test`. - */ -function find(test, nodes, recurse, limit) { - var result = []; - /** Stack of the arrays we are looking at. */ - var nodeStack = [nodes]; - /** Stack of the indices within the arrays. */ - var indexStack = [0]; - for (;;) { - // First, check if the current array has any more elements to look at. - if (indexStack[0] >= nodeStack[0].length) { - // If we have no more arrays to look at, we are done. - if (indexStack.length === 1) { - return result; - } - // Otherwise, remove the current array from the stack. - nodeStack.shift(); - indexStack.shift(); - // Loop back to the start to continue with the next array. - continue; + for (i = 0; i < n; i++) { + len = arrays[i].length; + if (len === 0) { + return result || self; } - var elem = nodeStack[0][indexStack[0]++]; - if (test(elem)) { - result.push(elem); - if (--limit <= 0) - return result; + resultlen *= len; + if (resultlen > 2147483647) { + $Kernel.$raise($$$('RangeError'), "too big to product"); } - if (recurse && (0, domhandler_1.hasChildren)(elem) && elem.children.length > 0) { - /* - * Add the children to the stack. We are depth-first, so this is - * the next array we look at. - */ - indexStack.unshift(0); - nodeStack.unshift(elem.children); + lengths[i] = len; + counters[i] = 0; + } + + outer_loop: for (;;) { + subarray = []; + for (i = 0; i < n; i++) { + subarray.push(arrays[i][counters[i]]); } - } -} -exports.find = find; -/** - * Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`. - * - * @category Querying - * @param test Function to test nodes on. - * @param nodes Array of nodes to search. - * @returns The first node in the array that passes `test`. - * @deprecated Use `Array.prototype.find` directly. - */ -function findOneChild(test, nodes) { - return nodes.find(test); -} -exports.findOneChild = findOneChild; -/** - * Finds one element in a tree that passes a test. - * - * @category Querying - * @param test Function to test nodes on. - * @param nodes Node or array of nodes to search. - * @param recurse Also consider child nodes. - * @returns The first node that passes `test`. - */ -function findOne(test, nodes, recurse) { - if (recurse === void 0) { recurse = true; } - var elem = null; - for (var i = 0; i < nodes.length && !elem; i++) { - var node = nodes[i]; - if (!(0, domhandler_1.isTag)(node)) { - continue; + if (result) { + result.push(subarray); + } else { + Opal.yield1(block, subarray); } - else if (test(node)) { - elem = node; + m = n - 1; + counters[m]++; + while (counters[m] === lengths[m]) { + counters[m] = 0; + if (--m < 0) break outer_loop; + counters[m]++; } - else if (recurse && node.children.length > 0) { - elem = findOne(test, node.children, true); + } + + return result || self; + }, -1); + + $def(self, '$push', function $$push($a) { + var $post_args, objects, self = this; + + + $post_args = $slice(arguments); + objects = $post_args; + + $deny_frozen_access(self); + + for (var i = 0, length = objects.length; i < length; i++) { + self.push(objects[i]); + } + return self; + }, -1); + + $def(self, '$rassoc', function $$rassoc(object) { + var self = this; + + + for (var i = 0, length = self.length, item; i < length; i++) { + item = self[i]; + + if (item.length && item[1] !== undefined) { + if ((item[1])['$=='](object)) { + return item; + } } - } - return elem; -} -exports.findOne = findOne; -/** - * Checks if a tree of nodes contains at least one node passing a test. - * - * @category Querying - * @param test Function to test nodes on. - * @param nodes Array of nodes to search. - * @returns Whether a tree of nodes contains at least one node passing the test. - */ -function existsOne(test, nodes) { - return nodes.some(function (checked) { - return (0, domhandler_1.isTag)(checked) && - (test(checked) || existsOne(test, checked.children)); + } + + return nil; + }); -} -exports.existsOne = existsOne; -/** - * Search an array of nodes and their children for elements passing a test function. - * - * Same as `find`, but limited to elements and with less options, leading to reduced complexity. - * - * @category Querying - * @param test Function to test nodes on. - * @param nodes Array of nodes to search. - * @returns All nodes passing `test`. - */ -function findAll(test, nodes) { - var result = []; - var nodeStack = [nodes]; - var indexStack = [0]; - for (;;) { - if (indexStack[0] >= nodeStack[0].length) { - if (nodeStack.length === 1) { - return result; - } - // Otherwise, remove the current array from the stack. - nodeStack.shift(); - indexStack.shift(); - // Loop back to the start to continue with the next array. - continue; + + $def(self, '$reject', function $$reject() { + var block = $$reject.$$p || nil, self = this; + + $$reject.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["reject"], function $$36(){var self = $$36.$$s == null ? this : $$36.$$s; + + return self.$size()}, {$$s: self}) + } + var result = []; + + for (var i = 0, length = self.length, value; i < length; i++) { + value = block(self[i]); + + if (value === false || value === nil) { + result.push(self[i]); } - var elem = nodeStack[0][indexStack[0]++]; - if (!(0, domhandler_1.isTag)(elem)) - continue; - if (test(elem)) - result.push(elem); - if (elem.children.length > 0) { - indexStack.unshift(0); - nodeStack.unshift(elem.children); + } + return result; + }); + + $def(self, '$reject!', function $Array_reject$excl$37() { + var block = $Array_reject$excl$37.$$p || nil, self = this, original = nil; + + $Array_reject$excl$37.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["reject!"], function $$38(){var self = $$38.$$s == null ? this : $$38.$$s; + + return self.$size()}, {$$s: self}) + } $deny_frozen_access(self); + original = self.$length(); + $send(self, 'delete_if', [], block.$to_proc()); + if ($eqeq(self.$length(), original)) { + return nil + } else { + return self + } }); + + $def(self, '$replace', function $$replace(other) { + var self = this; + + + $deny_frozen_access(self); + other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a())); + + self.splice(0, self.length); + self.push.apply(self, other); + return self; + }); + + $def(self, '$reverse', function $$reverse() { + var self = this; + + return self.slice(0).reverse(); + }); + + $def(self, '$reverse!', function $Array_reverse$excl$39() { + var self = this; + + + $deny_frozen_access(self); + return self.reverse(); }); + + $def(self, '$reverse_each', function $$reverse_each() { + var block = $$reverse_each.$$p || nil, self = this; + + $$reverse_each.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["reverse_each"], function $$40(){var self = $$40.$$s == null ? this : $$40.$$s; + + return self.$size()}, {$$s: self}) + } $send(self.$reverse(), 'each', [], block.$to_proc()); + return self; + }); + + $def(self, '$rindex', function $$rindex(object) { + var block = $$rindex.$$p || nil, self = this; + + $$rindex.$$p = null; + + var i, value; + + if (object != null && block !== nil) { + self.$warn("warning: given block not used"); + } + + if (object != null) { + for (i = self.length - 1; i >= 0; i--) { + if (i >= self.length) { + break; + } + if ((self[i])['$=='](object)) { + return i; + } } - } -} -exports.findAll = findAll; -//# sourceMappingURL=querying.js.map + } + else if (block !== nil) { + for (i = self.length - 1; i >= 0; i--) { + if (i >= self.length) { + break; + } + + value = block(self[i]); + + if (value !== false && value !== nil) { + return i; + } + } + } + else if (object == null) { + return self.$enum_for("rindex"); + } + + return nil; + }, -1); + + $def(self, '$rotate', function $$rotate(n) { + var self = this; + + + if (n == null) n = 1; + + var ary, idx, firstPart, lastPart; + + n = $coerce_to(n, $$$('Integer'), 'to_int'); + + if (self.length === 1) { + return self.slice(); + } + if (self.length === 0) { + return []; + } + + ary = self.slice(); + idx = n % ary.length; + + firstPart = ary.slice(idx); + lastPart = ary.slice(0, idx); + return firstPart.concat(lastPart); + }, -1); + + $def(self, '$rotate!', function $Array_rotate$excl$41(cnt) { + var self = this, ary = nil; + + + if (cnt == null) cnt = 1; + + $deny_frozen_access(self); + + if (self.length === 0 || self.length === 1) { + return self; + } + cnt = $coerce_to(cnt, $$$('Integer'), 'to_int'); + ary = self.$rotate(cnt); + return self.$replace(ary); + }, -1); + (function($base, $super) { + var self = $klass($base, $super, 'SampleRandom'); -/***/ }), + var $proto = self.$$prototype; -/***/ 9561: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + $proto.rng = nil; + + + $def(self, '$initialize', $assign_ivar("rng")); + return $def(self, '$rand', function $$rand(size) { + var self = this, random = nil; -"use strict"; + + random = $coerce_to(self.rng.$rand(size), $$$('Integer'), 'to_int'); + if ($truthy(random < 0)) { + $Kernel.$raise($$$('RangeError'), "random value must be >= 0"); + } if (!$truthy(random < size)) { + $Kernel.$raise($$$('RangeError'), "random value must be less than Array size"); + } return random; + }); + })(self, null); + + $def(self, '$sample', function $$sample(count, options) { + var self = this, o = nil, rng = nil; + if ($truthy(count === undefined)) { + return self.$at($Kernel.$rand(self.length)) + } if ($truthy(options === undefined)) { + if ($truthy((o = $Opal['$coerce_to?'](count, $$$('Hash'), "to_hash")))) { + + options = o; + count = nil; + } else { + + options = nil; + count = $coerce_to(count, $$$('Integer'), 'to_int'); + } + } else { + + count = $coerce_to(count, $$$('Integer'), 'to_int'); + options = $coerce_to(options, $$$('Hash'), 'to_hash'); + } if (($truthy(count) && ($truthy(count < 0)))) { + $Kernel.$raise($$$('ArgumentError'), "count must be greater than 0"); + } if ($truthy(options)) { + rng = options['$[]']("random"); + } rng = (($truthy(rng) && ($truthy(rng['$respond_to?']("rand")))) ? ($$('SampleRandom').$new(rng)) : ($Kernel)); + if (!$truthy(count)) { + return self[rng.$rand(self.length)] + } -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.innerText = exports.textContent = exports.getText = exports.getInnerHTML = exports.getOuterHTML = void 0; -var domhandler_1 = __nccwpck_require__(4038); -var dom_serializer_1 = __importDefault(__nccwpck_require__(8621)); -var domelementtype_1 = __nccwpck_require__(3944); -/** - * @category Stringify - * @deprecated Use the `dom-serializer` module directly. - * @param node Node to get the outer HTML of. - * @param options Options for serialization. - * @returns `node`'s outer HTML. - */ -function getOuterHTML(node, options) { - return (0, dom_serializer_1.default)(node, options); -} -exports.getOuterHTML = getOuterHTML; -/** - * @category Stringify - * @deprecated Use the `dom-serializer` module directly. - * @param node Node to get the inner HTML of. - * @param options Options for serialization. - * @returns `node`'s inner HTML. - */ -function getInnerHTML(node, options) { - return (0, domhandler_1.hasChildren)(node) - ? node.children.map(function (node) { return getOuterHTML(node, options); }).join("") - : ""; -} -exports.getInnerHTML = getInnerHTML; -/** - * Get a node's inner text. Same as `textContent`, but inserts newlines for `<br>` tags. Ignores comments. - * - * @category Stringify - * @deprecated Use `textContent` instead. - * @param node Node to get the inner text of. - * @returns `node`'s inner text. - */ -function getText(node) { - if (Array.isArray(node)) - return node.map(getText).join(""); - if ((0, domhandler_1.isTag)(node)) - return node.name === "br" ? "\n" : getText(node.children); - if ((0, domhandler_1.isCDATA)(node)) - return getText(node.children); - if ((0, domhandler_1.isText)(node)) - return node.data; - return ""; -} -exports.getText = getText; -/** - * Get a node's text content. Ignores comments. - * - * @category Stringify - * @param node Node to get the text content of. - * @returns `node`'s text content. - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent} - */ -function textContent(node) { - if (Array.isArray(node)) - return node.map(textContent).join(""); - if ((0, domhandler_1.hasChildren)(node) && !(0, domhandler_1.isComment)(node)) { - return textContent(node.children); - } - if ((0, domhandler_1.isText)(node)) - return node.data; - return ""; -} -exports.textContent = textContent; -/** - * Get a node's inner text, ignoring `<script>` and `<style>` tags. Ignores comments. - * - * @category Stringify - * @param node Node to get the inner text of. - * @returns `node`'s inner text. - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText} - */ -function innerText(node) { - if (Array.isArray(node)) - return node.map(innerText).join(""); - if ((0, domhandler_1.hasChildren)(node) && (node.type === domelementtype_1.ElementType.Tag || (0, domhandler_1.isCDATA)(node))) { - return innerText(node.children); - } - if ((0, domhandler_1.isText)(node)) - return node.data; - return ""; -} -exports.innerText = innerText; -//# sourceMappingURL=stringify.js.map + var abandon, spin, result, i, j, k, targetIndex, oldValue; -/***/ }), + if (count > self.length) { + count = self.length; + } -/***/ 9228: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + switch (count) { + case 0: + return []; + case 1: + return [self[rng.$rand(self.length)]]; + case 2: + i = rng.$rand(self.length); + j = rng.$rand(self.length - 1); + if (i <= j) { + j++; + } + return [self[i], self[j]]; + default: + if (self.length / count > 3) { + abandon = false; + spin = 0; -"use strict"; + result = $$('Array').$new(count); + i = 1; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.prevElementSibling = exports.nextElementSibling = exports.getName = exports.hasAttrib = exports.getAttributeValue = exports.getSiblings = exports.getParent = exports.getChildren = void 0; -var domhandler_1 = __nccwpck_require__(4038); -/** - * Get a node's children. - * - * @category Traversal - * @param elem Node to get the children of. - * @returns `elem`'s children, or an empty array. - */ -function getChildren(elem) { - return (0, domhandler_1.hasChildren)(elem) ? elem.children : []; -} -exports.getChildren = getChildren; -/** - * Get a node's parent. - * - * @category Traversal - * @param elem Node to get the parent of. - * @returns `elem`'s parent node, or `null` if `elem` is a root node. - */ -function getParent(elem) { - return elem.parent || null; -} -exports.getParent = getParent; -/** - * Gets an elements siblings, including the element itself. - * - * Attempts to get the children through the element's parent first. If we don't - * have a parent (the element is a root node), we walk the element's `prev` & - * `next` to get all remaining nodes. - * - * @category Traversal - * @param elem Element to get the siblings of. - * @returns `elem`'s siblings, including `elem`. - */ -function getSiblings(elem) { - var _a, _b; - var parent = getParent(elem); - if (parent != null) - return getChildren(parent); - var siblings = [elem]; - var prev = elem.prev, next = elem.next; - while (prev != null) { - siblings.unshift(prev); - (_a = prev, prev = _a.prev); - } - while (next != null) { - siblings.push(next); - (_b = next, next = _b.next); - } - return siblings; -} -exports.getSiblings = getSiblings; -/** - * Gets an attribute from an element. - * - * @category Traversal - * @param elem Element to check. - * @param name Attribute name to retrieve. - * @returns The element's attribute value, or `undefined`. - */ -function getAttributeValue(elem, name) { - var _a; - return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name]; -} -exports.getAttributeValue = getAttributeValue; -/** - * Checks whether an element has an attribute. - * - * @category Traversal - * @param elem Element to check. - * @param name Attribute name to look for. - * @returns Returns whether `elem` has the attribute `name`. - */ -function hasAttrib(elem, name) { - return (elem.attribs != null && - Object.prototype.hasOwnProperty.call(elem.attribs, name) && - elem.attribs[name] != null); -} -exports.hasAttrib = hasAttrib; -/** - * Get the tag name of an element. - * - * @category Traversal - * @param elem The element to get the name for. - * @returns The tag name of `elem`. - */ -function getName(elem) { - return elem.name; -} -exports.getName = getName; -/** - * Returns the next element sibling of a node. - * - * @category Traversal - * @param elem The element to get the next sibling of. - * @returns `elem`'s next sibling that is a tag, or `null` if there is no next - * sibling. - */ -function nextElementSibling(elem) { - var _a; - var next = elem.next; - while (next !== null && !(0, domhandler_1.isTag)(next)) - (_a = next, next = _a.next); - return next; -} -exports.nextElementSibling = nextElementSibling; -/** - * Returns the previous element sibling of a node. - * - * @category Traversal - * @param elem The element to get the previous sibling of. - * @returns `elem`'s previous sibling that is a tag, or `null` if there is no - * previous sibling. - */ -function prevElementSibling(elem) { - var _a; - var prev = elem.prev; - while (prev !== null && !(0, domhandler_1.isTag)(prev)) - (_a = prev, prev = _a.prev); - return prev; -} -exports.prevElementSibling = prevElementSibling; -//# sourceMappingURL=traversal.js.map + result[0] = rng.$rand(self.length); + while (i < count) { + k = rng.$rand(self.length); + j = 0; -/***/ }), + while (j < i) { + while (k === result[j]) { + spin++; + if (spin > 100) { + abandon = true; + break; + } + k = rng.$rand(self.length); + } + if (abandon) { break; } -/***/ 5107: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + j++; + } -"use strict"; + if (abandon) { break; } -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTMLAttribute = exports.decodeHTML = exports.determineBranch = exports.EntityDecoder = exports.DecodingMode = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0; -var decode_data_html_js_1 = __importDefault(__nccwpck_require__(6970)); -exports.htmlDecodeTree = decode_data_html_js_1.default; -var decode_data_xml_js_1 = __importDefault(__nccwpck_require__(7359)); -exports.xmlDecodeTree = decode_data_xml_js_1.default; -var decode_codepoint_js_1 = __importStar(__nccwpck_require__(1227)); -exports.decodeCodePoint = decode_codepoint_js_1.default; -var decode_codepoint_js_2 = __nccwpck_require__(1227); -Object.defineProperty(exports, "replaceCodePoint", ({ enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } })); -Object.defineProperty(exports, "fromCodePoint", ({ enumerable: true, get: function () { return decode_codepoint_js_2.fromCodePoint; } })); -var CharCodes; -(function (CharCodes) { - CharCodes[CharCodes["NUM"] = 35] = "NUM"; - CharCodes[CharCodes["SEMI"] = 59] = "SEMI"; - CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS"; - CharCodes[CharCodes["ZERO"] = 48] = "ZERO"; - CharCodes[CharCodes["NINE"] = 57] = "NINE"; - CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A"; - CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F"; - CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X"; - CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z"; - CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A"; - CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F"; - CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z"; -})(CharCodes || (CharCodes = {})); -/** Bit that needs to be set to convert an upper case ASCII character to lower case */ -var TO_LOWER_BIT = 32; -var BinTrieFlags; -(function (BinTrieFlags) { - BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH"; - BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH"; - BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE"; -})(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {})); -function isNumber(code) { - return code >= CharCodes.ZERO && code <= CharCodes.NINE; -} -function isHexadecimalCharacter(code) { - return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) || - (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F)); -} -function isAsciiAlphaNumeric(code) { - return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) || - (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) || - isNumber(code)); -} -/** - * Checks if the given character is a valid end character for an entity in an attribute. - * - * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error. - * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state - */ -function isEntityInAttributeInvalidEnd(code) { - return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code); -} -var EntityDecoderState; -(function (EntityDecoderState) { - EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart"; - EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart"; - EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal"; - EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex"; - EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity"; -})(EntityDecoderState || (EntityDecoderState = {})); -var DecodingMode; -(function (DecodingMode) { - /** Entities in text nodes that can end with any character. */ - DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy"; - /** Only allow entities terminated with a semicolon. */ - DecodingMode[DecodingMode["Strict"] = 1] = "Strict"; - /** Entities in attributes have limitations on ending characters. */ - DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute"; -})(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {})); -/** - * Token decoder with support of writing partial entities. - */ -var EntityDecoder = /** @class */ (function () { - function EntityDecoder( - /** The tree used to decode entities. */ - decodeTree, - /** - * The function that is called when a codepoint is decoded. - * - * For multi-byte named entities, this will be called multiple times, - * with the second codepoint, and the same `consumed` value. - * - * @param codepoint The decoded codepoint. - * @param consumed The number of bytes consumed by the decoder. - */ - emitCodePoint, - /** An object that is used to produce errors. */ - errors) { - this.decodeTree = decodeTree; - this.emitCodePoint = emitCodePoint; - this.errors = errors; - /** The current state of the decoder. */ - this.state = EntityDecoderState.EntityStart; - /** Characters that were consumed while parsing an entity. */ - this.consumed = 1; - /** - * The result of the entity. - * - * Either the result index of a numeric entity, or the codepoint of a - * numeric entity. - */ - this.result = 0; - /** The current index in the decode tree. */ - this.treeIndex = 0; - /** The number of characters that were consumed in excess. */ - this.excess = 1; - /** The mode in which the decoder is operating. */ - this.decodeMode = DecodingMode.Strict; - } - /** Resets the instance to make it reusable. */ - EntityDecoder.prototype.startEntity = function (decodeMode) { - this.decodeMode = decodeMode; - this.state = EntityDecoderState.EntityStart; - this.result = 0; - this.treeIndex = 0; - this.excess = 1; - this.consumed = 1; - }; - /** - * Write an entity to the decoder. This can be called multiple times with partial entities. - * If the entity is incomplete, the decoder will return -1. - * - * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the - * entity is incomplete, and resume when the next string is written. - * - * @param string The string containing the entity (or a continuation of the entity). - * @param offset The offset at which the entity begins. Should be 0 if this is not the first call. - * @returns The number of characters that were consumed, or -1 if the entity is incomplete. - */ - EntityDecoder.prototype.write = function (str, offset) { - switch (this.state) { - case EntityDecoderState.EntityStart: { - if (str.charCodeAt(offset) === CharCodes.NUM) { - this.state = EntityDecoderState.NumericStart; - this.consumed += 1; - return this.stateNumericStart(str, offset + 1); - } - this.state = EntityDecoderState.NamedEntity; - return this.stateNamedEntity(str, offset); - } - case EntityDecoderState.NumericStart: { - return this.stateNumericStart(str, offset); - } - case EntityDecoderState.NumericDecimal: { - return this.stateNumericDecimal(str, offset); - } - case EntityDecoderState.NumericHex: { - return this.stateNumericHex(str, offset); + result[i] = k; + + i++; } - case EntityDecoderState.NamedEntity: { - return this.stateNamedEntity(str, offset); + + if (!abandon) { + i = 0; + while (i < count) { + result[i] = self[result[i]]; + i++; + } + + return result; } + } + + result = self.slice(); + + for (var c = 0; c < count; c++) { + targetIndex = rng.$rand(self.length - c) + c; + oldValue = result[c]; + result[c] = result[targetIndex]; + result[targetIndex] = oldValue; + } + + return count === self.length ? result : (result)['$[]'](0, count); + } + }, -1); + + $def(self, '$select', function $$select() { + var block = $$select.$$p || nil, self = this; + + $$select.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["select"], function $$42(){var self = $$42.$$s == null ? this : $$42.$$s; + + return self.$size()}, {$$s: self}) + } + var result = []; + + for (var i = 0, length = self.length, item, value; i < length; i++) { + item = self[i]; + + value = $yield1(block, item); + + if ($truthy(value)) { + result.push(item); } - }; - /** - * Switches between the numeric decimal and hexadecimal states. - * - * Equivalent to the `Numeric character reference state` in the HTML spec. - * - * @param str The string containing the entity (or a continuation of the entity). - * @param offset The current offset. - * @returns The number of characters that were consumed, or -1 if the entity is incomplete. - */ - EntityDecoder.prototype.stateNumericStart = function (str, offset) { - if (offset >= str.length) { - return -1; + } + + return result; + }); + + $def(self, '$select!', function $Array_select$excl$43() { + var block = $Array_select$excl$43.$$p || nil, self = this; + + $Array_select$excl$43.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["select!"], function $$44(){var self = $$44.$$s == null ? this : $$44.$$s; + + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); + + var original = self.length; + $send(self, 'keep_if', [], block.$to_proc()); + return self.length === original ? nil : self; + }); + + $def(self, '$shift', function $$shift(count) { + var self = this; + $deny_frozen_access(self); + if ($truthy(count === undefined)) { + + if ($truthy(self.length === 0)) { + return nil + } return shiftNoArg(self); + } count = $coerce_to(count, $$$('Integer'), 'to_int'); + if ($truthy(count < 0)) { + $Kernel.$raise($$$('ArgumentError'), "negative array size"); + } if ($truthy(self.length === 0)) { + return [] + } return self.splice(0, count); }, -1); + + $def(self, '$shuffle', function $$shuffle(rng) { + var self = this; + return self.$dup().$to_a()['$shuffle!'](rng); + }, -1); + + $def(self, '$shuffle!', function $Array_shuffle$excl$45(rng) { + var self = this; + + $deny_frozen_access(self); + + var randgen, i = self.length, j, tmp; + + if (rng !== undefined) { + rng = $Opal['$coerce_to?'](rng, $$$('Hash'), "to_hash"); + + if (rng !== nil) { + rng = rng['$[]']("random"); + + if (rng !== nil && rng['$respond_to?']("rand")) { + randgen = rng; + } } - if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) { - this.state = EntityDecoderState.NumericHex; - this.consumed += 1; - return this.stateNumericHex(str, offset + 1); + } + + while (i) { + if (randgen) { + j = randgen.$rand(i).$to_int(); + + if (j < 0) { + $Kernel.$raise($$$('RangeError'), "random number too small " + (j)); + } + + if (j >= i) { + $Kernel.$raise($$$('RangeError'), "random number too big " + (j)); + } } - this.state = EntityDecoderState.NumericDecimal; - return this.stateNumericDecimal(str, offset); - }; - EntityDecoder.prototype.addToNumericResult = function (str, start, end, base) { - if (start !== end) { - var digitCount = end - start; - this.result = - this.result * Math.pow(base, digitCount) + - parseInt(str.substr(start, digitCount), base); - this.consumed += digitCount; + else { + j = self.$rand(i); } - }; - /** - * Parses a hexadecimal numeric entity. - * - * Equivalent to the `Hexademical character reference state` in the HTML spec. - * - * @param str The string containing the entity (or a continuation of the entity). - * @param offset The current offset. - * @returns The number of characters that were consumed, or -1 if the entity is incomplete. - */ - EntityDecoder.prototype.stateNumericHex = function (str, offset) { - var startIdx = offset; - while (offset < str.length) { - var char = str.charCodeAt(offset); - if (isNumber(char) || isHexadecimalCharacter(char)) { - offset += 1; - } - else { - this.addToNumericResult(str, startIdx, offset, 16); - return this.emitNumericEntity(char, 3); + + tmp = self[--i]; + self[i] = self[j]; + self[j] = tmp; + } + + return self; + }, -1); + + $def(self, '$slice!', function $Array_slice$excl$46(index, length) { + var self = this, result = nil, range = nil, range_start = nil, range_end = nil, start = nil; + $deny_frozen_access(self); + result = nil; + if ($truthy(length === undefined)) { + if ($eqeqeq($$$('Range'), index)) { + + range = index; + result = self['$[]'](range); + range_start = range.begin === nil ? 0 : $coerce_to(range.begin, $$$('Integer'), 'to_int'); + range_end = range.end === nil ? -1 : $coerce_to(range.end, $$$('Integer'), 'to_int'); + + if (range_start < 0) { + range_start += self.length; + } + + if (range_end < 0) { + range_end += self.length; + } else if (range_end >= self.length) { + range_end = self.length - 1; + if (range.excl) { + range_end += 1; } + } + + var range_length = range_end - range_start; + if (range.excl && range.end !== nil) { + range_end -= 1; + } else { + range_length += 1; + } + + if (range_start < self.length && range_start >= 0 && range_end < self.length && range_end >= 0 && range_length > 0) { + self.splice(range_start, range_length); + } + } else { + + start = $coerce_to(index, $$$('Integer'), 'to_int'); + + if (start < 0) { + start += self.length; + } + + if (start < 0 || start >= self.length) { + return nil; + } + + result = self[start]; + + if (start === 0) { + self.shift(); + } else { + self.splice(start, 1); + } } - this.addToNumericResult(str, startIdx, offset, 16); - return -1; - }; - /** - * Parses a decimal numeric entity. - * - * Equivalent to the `Decimal character reference state` in the HTML spec. - * - * @param str The string containing the entity (or a continuation of the entity). - * @param offset The current offset. - * @returns The number of characters that were consumed, or -1 if the entity is incomplete. - */ - EntityDecoder.prototype.stateNumericDecimal = function (str, offset) { - var startIdx = offset; - while (offset < str.length) { - var char = str.charCodeAt(offset); - if (isNumber(char)) { - offset += 1; - } - else { - this.addToNumericResult(str, startIdx, offset, 10); - return this.emitNumericEntity(char, 2); - } + } else { + + start = $coerce_to(index, $$$('Integer'), 'to_int'); + length = $coerce_to(length, $$$('Integer'), 'to_int'); + + if (length < 0) { + return nil; } - this.addToNumericResult(str, startIdx, offset, 10); - return -1; - }; - /** - * Validate and emit a numeric entity. - * - * Implements the logic from the `Hexademical character reference start - * state` and `Numeric character reference end state` in the HTML spec. - * - * @param lastCp The last code point of the entity. Used to see if the - * entity was terminated with a semicolon. - * @param expectedLength The minimum number of characters that should be - * consumed. Used to validate that at least one digit - * was consumed. - * @returns The number of characters that were consumed. - */ - EntityDecoder.prototype.emitNumericEntity = function (lastCp, expectedLength) { - var _a; - // Ensure we consumed at least one digit. - if (this.consumed <= expectedLength) { - (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); - return 0; + + result = self['$[]'](start, length); + + if (start < 0) { + start += self.length; } - // Figure out if this is a legit end of the entity - if (lastCp === CharCodes.SEMI) { - this.consumed += 1; + + if (start + length > self.length) { + length = self.length - start; } - else if (this.decodeMode === DecodingMode.Strict) { - return 0; + + if (start < self.length && start >= 0) { + self.splice(start, length); } - this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed); - if (this.errors) { - if (lastCp !== CharCodes.SEMI) { - this.errors.missingSemicolonAfterCharacterReference(); - } - this.errors.validateNumericCharacterReference(this.result); + } return result; + }, -2); + + $def(self, '$sort', function $$sort() { + var block = $$sort.$$p || nil, self = this; + + $$sort.$$p = null; + if (!$truthy(self.length > 1)) { + return self + } + if (block === nil) { + block = function(a, b) { + return (a)['$<=>'](b); + }; + } + + return self.slice().sort(function(x, y) { + var ret = block(x, y); + + if (ret === nil) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((x).$inspect()) + " with " + ((y).$inspect()) + " failed"); } - return this.consumed; - }; - /** - * Parses a named entity. - * - * Equivalent to the `Named character reference state` in the HTML spec. - * - * @param str The string containing the entity (or a continuation of the entity). - * @param offset The current offset. - * @returns The number of characters that were consumed, or -1 if the entity is incomplete. - */ - EntityDecoder.prototype.stateNamedEntity = function (str, offset) { - var decodeTree = this.decodeTree; - var current = decodeTree[this.treeIndex]; - // The mask is the number of bytes of the value, including the current byte. - var valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; - for (; offset < str.length; offset++, this.excess++) { - var char = str.charCodeAt(offset); - this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char); - if (this.treeIndex < 0) { - return this.result === 0 || - // If we are parsing an attribute - (this.decodeMode === DecodingMode.Attribute && - // We shouldn't have consumed any characters after the entity, - (valueLength === 0 || - // And there should be no invalid characters. - isEntityInAttributeInvalidEnd(char))) - ? 0 - : this.emitNotTerminatedNamedEntity(); - } - current = decodeTree[this.treeIndex]; - valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; - // If the branch is a value, store it and continue - if (valueLength !== 0) { - // If the entity is terminated by a semicolon, we are done. - if (char === CharCodes.SEMI) { - return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess); - } - // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it. - if (this.decodeMode !== DecodingMode.Strict) { - this.result = this.treeIndex; - this.consumed += this.excess; - this.excess = 0; - } - } + + return $rb_gt(ret, 0) ? 1 : ($rb_lt(ret, 0) ? -1 : 0); + }); + }); + + $def(self, '$sort!', function $Array_sort$excl$47() { + var block = $Array_sort$excl$47.$$p || nil, self = this; + + $Array_sort$excl$47.$$p = null; + + $deny_frozen_access(self); + + var result; + + if ((block !== nil)) { + result = $send((self.slice()), 'sort', [], block.$to_proc()); + } + else { + result = (self.slice()).$sort(); + } + + self.length = 0; + for(var i = 0, length = result.length; i < length; i++) { + self.push(result[i]); + } + + return self; + }); + + $def(self, '$sort_by!', function $Array_sort_by$excl$48() { + var block = $Array_sort_by$excl$48.$$p || nil, self = this; + + $Array_sort_by$excl$48.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["sort_by!"], function $$49(){var self = $$49.$$s == null ? this : $$49.$$s; + + return self.$size()}, {$$s: self}) + } $deny_frozen_access(self); + return self.$replace($send(self, 'sort_by', [], block.$to_proc())); + }); + + $def(self, '$take', function $$take(count) { + var self = this; + + + if (count < 0) { + $Kernel.$raise($$$('ArgumentError')); + } + + return self.slice(0, count); + + }); + + $def(self, '$take_while', function $$take_while() { + var block = $$take_while.$$p || nil, self = this; + + $$take_while.$$p = null; + + var result = []; + + for (var i = 0, length = self.length, item, value; i < length; i++) { + item = self[i]; + + value = block(item); + + if (value === false || value === nil) { + return result; } - return -1; - }; - /** - * Emit a named entity that was not terminated with a semicolon. - * - * @returns The number of characters consumed. - */ - EntityDecoder.prototype.emitNotTerminatedNamedEntity = function () { - var _a; - var _b = this, result = _b.result, decodeTree = _b.decodeTree; - var valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14; - this.emitNamedEntityData(result, valueLength, this.consumed); - (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference(); - return this.consumed; - }; - /** - * Emit a named entity. - * - * @param result The index of the entity in the decode tree. - * @param valueLength The number of bytes in the entity. - * @param consumed The number of characters consumed. - * - * @returns The number of characters consumed. - */ - EntityDecoder.prototype.emitNamedEntityData = function (result, valueLength, consumed) { - var decodeTree = this.decodeTree; - this.emitCodePoint(valueLength === 1 - ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH - : decodeTree[result + 1], consumed); - if (valueLength === 3) { - // For multi-byte values, we need to emit the second byte. - this.emitCodePoint(decodeTree[result + 2], consumed); + + result.push(item); + } + + return result; + }); + + $def(self, '$to_a', function $$to_a() { + var self = this; + + + if (self.$$class === Opal.Array) { + return self; + } + else { + return Opal.Array.$new(self); + } + + }); + + $def(self, '$to_ary', $return_self); + + $def(self, '$to_h', function $$to_h() { + var block = $$to_h.$$p || nil, self = this, array = nil; + + $$to_h.$$p = null; + array = self; + if ((block !== nil)) { + array = $send(array, 'map', [], block.$to_proc()); + } + var i, len = array.length, ary, key, val, hash = $hash2([], {}); + + for (i = 0; i < len; i++) { + ary = $Opal['$coerce_to?'](array[i], $$$('Array'), "to_ary"); + if (!ary.$$is_array) { + $Kernel.$raise($$$('TypeError'), "wrong element type " + ((ary).$class()) + " at " + (i) + " (expected array)"); } - return consumed; - }; - /** - * Signal to the parser that the end of the input was reached. - * - * Remaining data will be emitted and relevant errors will be produced. - * - * @returns The number of characters consumed. - */ - EntityDecoder.prototype.end = function () { - var _a; - switch (this.state) { - case EntityDecoderState.NamedEntity: { - // Emit a named entity if we have one. - return this.result !== 0 && - (this.decodeMode !== DecodingMode.Attribute || - this.result === this.treeIndex) - ? this.emitNotTerminatedNamedEntity() - : 0; - } - // Otherwise, emit a numeric entity if we have one. - case EntityDecoderState.NumericDecimal: { - return this.emitNumericEntity(0, 2); - } - case EntityDecoderState.NumericHex: { - return this.emitNumericEntity(0, 3); - } - case EntityDecoderState.NumericStart: { - (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); - return 0; - } - case EntityDecoderState.EntityStart: { - // Return 0 if we have no entity. - return 0; - } + if (ary.length !== 2) { + $Kernel.$raise($$$('ArgumentError'), "wrong array length at " + (i) + " (expected 2, was " + ((ary).$length()) + ")"); } - }; - return EntityDecoder; -}()); -exports.EntityDecoder = EntityDecoder; -/** - * Creates a function that decodes entities in a string. - * - * @param decodeTree The decode tree. - * @returns A function that decodes entities in a string. - */ -function getDecoder(decodeTree) { - var ret = ""; - var decoder = new EntityDecoder(decodeTree, function (str) { return (ret += (0, decode_codepoint_js_1.fromCodePoint)(str)); }); - return function decodeWithTrie(str, decodeMode) { - var lastIndex = 0; - var offset = 0; - while ((offset = str.indexOf("&", offset)) >= 0) { - ret += str.slice(lastIndex, offset); - decoder.startEntity(decodeMode); - var len = decoder.write(str, - // Skip the "&" - offset + 1); - if (len < 0) { - lastIndex = offset + decoder.end(); - break; - } - lastIndex = offset + len; - // If `len` is 0, skip the current `&` and continue. - offset = len === 0 ? lastIndex + 1 : lastIndex; + key = ary[0]; + val = ary[1]; + $hash_put(hash, key, val); + } + + return hash; + }); + + $def(self, '$transpose', function $$transpose() { + var self = this, result = nil, max = nil; + + + if ($truthy(self['$empty?']())) { + return [] + } result = []; + max = nil; + $send(self, 'each', [], function $$50(row){var $ret_or_1 = nil; + + + if (row == null) row = nil; + row = ($eqeqeq($$$('Array'), row) ? (row.$to_a()) : (($coerce_to(row, $$$('Array'), 'to_ary')).$to_a())); + max = ($truthy(($ret_or_1 = max)) ? ($ret_or_1) : (row.length)); + if ($neqeq(row.length, max)) { + $Kernel.$raise($$$('IndexError'), "element size differs (" + (row.length) + " should be " + (max) + ")"); + } return $send((row.length), 'times', [], function $$51(i){var $a, entry = nil; + + + if (i == null) i = nil; + entry = ($truthy(($ret_or_1 = result['$[]'](i))) ? ($ret_or_1) : (($a = [i, []], $send(result, '[]=', $a), $a[$a.length - 1]))); + return entry['$<<'](row.$at(i));});}); + return result; + }); + + $def(self, '$union', function $$union($a) { + var $post_args, arrays, self = this; + + + $post_args = $slice(arguments); + arrays = $post_args; + return $send(arrays, 'reduce', [self.$uniq()], function $$52(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$|'](b);}); + }, -1); + + $def(self, '$uniq', function $$uniq() { + var block = $$uniq.$$p || nil, self = this; + + $$uniq.$$p = null; + + var hash = $hash2([], {}), i, length, item, key; + + if (block === nil) { + for (i = 0, length = self.length; i < length; i++) { + item = self[i]; + if ($hash_get(hash, item) === undefined) { + $hash_put(hash, item, item); + } + } + } + else { + for (i = 0, length = self.length; i < length; i++) { + item = self[i]; + key = $yield1(block, item); + if ($hash_get(hash, key) === undefined) { + $hash_put(hash, key, item); + } + } + } + + return (hash).$values(); + }); + + $def(self, '$uniq!', function $Array_uniq$excl$53() { + var block = $Array_uniq$excl$53.$$p || nil, self = this; + + $Array_uniq$excl$53.$$p = null; + + $deny_frozen_access(self); + + var original_length = self.length, hash = $hash2([], {}), i, length, item, key; + + for (i = 0, length = original_length; i < length; i++) { + item = self[i]; + key = (block === nil ? item : $yield1(block, item)); + + if ($hash_get(hash, key) === undefined) { + $hash_put(hash, key, item); + continue; + } + + self.splice(i, 1); + length--; + i--; + } + + return self.length === original_length ? nil : self; + }); + + $def(self, '$unshift', function $$unshift($a) { + var $post_args, objects, self = this; + + + $post_args = $slice(arguments); + objects = $post_args; + + $deny_frozen_access(self); + + var selfLength = self.length; + var objectsLength = objects.length; + if (objectsLength == 0) return self; + var index = selfLength - objectsLength; + for (var i = 0; i < objectsLength; i++) { + self.push(self[index + i]); + } + var len = selfLength - 1; + while (len - objectsLength >= 0) { + self[len] = self[len - objectsLength]; + len--; + } + for (var j = 0; j < objectsLength; j++) { + self[j] = objects[j]; + } + return self; + }, -1); + + $def(self, '$values_at', function $$values_at($a) { + var $post_args, args, self = this, out = nil; + + + $post_args = $slice(arguments); + args = $post_args; + out = []; + $send(args, 'each', [], function $$54(elem){var self = $$54.$$s == null ? this : $$54.$$s, finish = nil, start = nil, i = nil; + + + if (elem == null) elem = nil; + if ($truthy(elem['$is_a?']($$$('Range')))) { + + finish = elem.$end() === nil ? -1 : $coerce_to(elem.$end(), $$$('Integer'), 'to_int'); + start = elem.$begin() === nil ? 0 : $coerce_to(elem.$begin(), $$$('Integer'), 'to_int'); + + if (start < 0) { + start = start + self.length; + return nil; + } + + if (finish < 0) { + finish = finish + self.length; + } + if (elem['$exclude_end?']() && elem.$end() !== nil) { + finish--; + } + if (finish < start) { + return nil; + } + return $send(start, 'upto', [finish], function $$55(i){var self = $$55.$$s == null ? this : $$55.$$s; + + + if (i == null) i = nil; + return out['$<<'](self.$at(i));}, {$$s: self}); + } else { + + i = $coerce_to(elem, $$$('Integer'), 'to_int'); + return out['$<<'](self.$at(i)); + }}, {$$s: self}); + return out; + }, -1); + + $def(self, '$zip', function $$zip($a) { + var block = $$zip.$$p || nil, $post_args, others, self = this, $ret_or_1 = nil; + + $$zip.$$p = null; + $post_args = $slice(arguments); + others = $post_args; + + var result = [], size = self.length, part, o, i, j, jj; + + for (j = 0, jj = others.length; j < jj; j++) { + o = others[j]; + if (o.$$is_array) { + continue; } - var result = ret + str.slice(lastIndex); - // Make sure we don't keep a reference to the final string. - ret = ""; - return result; - }; -} -/** - * Determines the branch of the current node that is taken given the current - * character. This function is used to traverse the trie. - * - * @param decodeTree The trie. - * @param current The current node. - * @param nodeIdx The index right after the current node and its value. - * @param char The current character. - * @returns The index of the next node, or -1 if no branch is taken. - */ -function determineBranch(decodeTree, current, nodeIdx, char) { - var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; - var jumpOffset = current & BinTrieFlags.JUMP_TABLE; - // Case 1: Single branch encoded in jump offset - if (branchCount === 0) { - return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1; - } - // Case 2: Multiple branches encoded in jump table - if (jumpOffset) { - var value = char - jumpOffset; - return value < 0 || value >= branchCount - ? -1 - : decodeTree[nodeIdx + value] - 1; - } - // Case 3: Multiple branches encoded in dictionary - // Binary search for the character. - var lo = nodeIdx; - var hi = lo + branchCount - 1; - while (lo <= hi) { - var mid = (lo + hi) >>> 1; - var midVal = decodeTree[mid]; - if (midVal < char) { - lo = mid + 1; + if (o.$$is_range || o.$$is_enumerator) { + others[j] = o.$take(size); + continue; } - else if (midVal > char) { - hi = mid - 1; + others[j] = ($truthy(($ret_or_1 = $Opal['$coerce_to?'](o, $$$('Array'), "to_ary"))) ? ($ret_or_1) : ($Opal['$coerce_to!'](o, $$$('Enumerator'), "to_enum", "each"))).$to_a(); + } + + for (i = 0; i < size; i++) { + part = [self[i]]; + + for (j = 0, jj = others.length; j < jj; j++) { + o = others[j][i]; + + if (o == null) { + o = nil; + } + + part[j + 1] = o; } - else { - return decodeTree[mid + branchCount]; + + result[i] = part; + } + + if (block !== nil) { + for (i = 0; i < size; i++) { + Opal.yield1(block, result[i]); } - } - return -1; -} -exports.determineBranch = determineBranch; -var htmlDecoder = getDecoder(decode_data_html_js_1.default); -var xmlDecoder = getDecoder(decode_data_xml_js_1.default); -/** - * Decodes an HTML string. - * - * @param str The string to decode. - * @param mode The decoding mode. - * @returns The decoded string. - */ -function decodeHTML(str, mode) { - if (mode === void 0) { mode = DecodingMode.Legacy; } - return htmlDecoder(str, mode); -} -exports.decodeHTML = decodeHTML; -/** - * Decodes an HTML string in an attribute. - * - * @param str The string to decode. - * @returns The decoded string. - */ -function decodeHTMLAttribute(str) { - return htmlDecoder(str, DecodingMode.Attribute); -} -exports.decodeHTMLAttribute = decodeHTMLAttribute; -/** - * Decodes an HTML string, requiring all entities to be terminated by a semicolon. - * - * @param str The string to decode. - * @returns The decoded string. - */ -function decodeHTMLStrict(str) { - return htmlDecoder(str, DecodingMode.Strict); -} -exports.decodeHTMLStrict = decodeHTMLStrict; -/** - * Decodes an XML string, requiring all entities to be terminated by a semicolon. - * - * @param str The string to decode. - * @returns The decoded string. - */ -function decodeXML(str) { - return xmlDecoder(str, DecodingMode.Strict); -} -exports.decodeXML = decodeXML; -//# sourceMappingURL=decode.js.map -/***/ }), + return nil; + } -/***/ 1227: -/***/ ((__unused_webpack_module, exports) => { + return result; + }, -1); + $defs(self, '$inherited', function $$inherited(klass) { + + + klass.$$prototype.$to_a = function() { + return this.slice(0, this.length); + }; + + }); + + $def(self, '$instance_variables', function $$instance_variables() { + var $yield = $$instance_variables.$$p || nil, self = this; -"use strict"; + $$instance_variables.$$p = null; + return $send($send2(self, $find_super(self, 'instance_variables', $$instance_variables, false, true), 'instance_variables', [], $yield), 'reject', [], function $$56(ivar){var $ret_or_1 = nil; -// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 -var _a; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.replaceCodePoint = exports.fromCodePoint = void 0; -var decodeMap = new Map([ - [0, 65533], - // C1 Unicode control character reference replacements - [128, 8364], - [130, 8218], - [131, 402], - [132, 8222], - [133, 8230], - [134, 8224], - [135, 8225], - [136, 710], - [137, 8240], - [138, 352], - [139, 8249], - [140, 338], - [142, 381], - [145, 8216], - [146, 8217], - [147, 8220], - [148, 8221], - [149, 8226], - [150, 8211], - [151, 8212], - [152, 732], - [153, 8482], - [154, 353], - [155, 8250], - [156, 339], - [158, 382], - [159, 376], -]); -/** - * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point. - */ -exports.fromCodePoint = -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins -(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) { - var output = ""; - if (codePoint > 0xffff) { - codePoint -= 0x10000; - output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800); - codePoint = 0xdc00 | (codePoint & 0x3ff); - } - output += String.fromCharCode(codePoint); - return output; + + if (ivar == null) ivar = nil; + if ($truthy(($ret_or_1 = /^@\d+$/.test(ivar)))) { + return $ret_or_1 + } else { + return ivar['$==']("@length") + }}) + }); + + $def(self, '$pack', function $$pack($a) { + + + $slice(arguments); + return $Kernel.$raise("To use Array#pack, you must first require 'corelib/array/pack'."); + }, -1); + $alias(self, "append", "push"); + $alias(self, "filter", "select"); + $alias(self, "filter!", "select!"); + $alias(self, "map", "collect"); + $alias(self, "map!", "collect!"); + $alias(self, "prepend", "unshift"); + $alias(self, "size", "length"); + $alias(self, "slice", "[]"); + $alias(self, "to_s", "inspect"); + $Opal.$pristine(self.$singleton_class(), "allocate"); + return $Opal.$pristine(self, "copy_instance_variables", "initialize_dup"); + })('::', Array, $nesting); }; -/** - * Replace the given code point with a replacement character if it is a - * surrogate or is outside the valid range. Otherwise return the code - * point unchanged. - */ -function replaceCodePoint(codePoint) { - var _a; - if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) { - return 0xfffd; - } - return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint; -} -exports.replaceCodePoint = replaceCodePoint; -/** - * Replace the code point if relevant, then convert it to a string. - * - * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead. - * @param codePoint The code point to decode. - * @returns The decoded code point. - */ -function decodeCodePoint(codePoint) { - return (0, exports.fromCodePoint)(replaceCodePoint(codePoint)); -} -exports["default"] = decodeCodePoint; -//# sourceMappingURL=decode_codepoint.js.map -/***/ }), +Opal.modules["corelib/hash"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $yield1 = Opal.yield1, $hash = Opal.hash, $hash_init = Opal.hash_init, $hash_get = Opal.hash_get, $hash_put = Opal.hash_put, $hash_delete = Opal.hash_delete, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $defs = Opal.defs, $def = Opal.def, $send = Opal.send, $rb_ge = Opal.rb_ge, $rb_gt = Opal.rb_gt, $hash2 = Opal.hash2, $truthy = Opal.truthy, $to_a = Opal.to_a, $return_self = Opal.return_self, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/***/ 2006: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + Opal.add_stubs('require,include,coerce_to?,[],merge!,allocate,raise,coerce_to!,each,fetch,>=,>,==,compare_by_identity,lambda?,abs,arity,enum_for,size,respond_to?,class,dig,except!,dup,delete,new,inspect,map,to_proc,flatten,frozen?,eql?,default,default_proc,default_proc=,default=,to_h,proc,clone,select,select!,has_key?,indexes,index,length,[]=,has_value?'); + + self.$require("corelib/enumerable"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Hash'); -"use strict"; + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.encodeNonAsciiHTML = exports.encodeHTML = void 0; -var encode_html_js_1 = __importDefault(__nccwpck_require__(8180)); -var escape_js_1 = __nccwpck_require__(7654); -var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g; -/** - * Encodes all characters in the input using HTML entities. This includes - * characters that are valid ASCII characters in HTML documents, such as `#`. - * - * To get a more compact output, consider using the `encodeNonAsciiHTML` - * function, which will only encode characters that are not valid in HTML - * documents, as well as non-ASCII characters. - * - * If a character has no equivalent entity, a numeric hexadecimal reference - * (eg. `ü`) will be used. - */ -function encodeHTML(data) { - return encodeHTMLTrieRe(htmlReplacer, data); -} -exports.encodeHTML = encodeHTML; -/** - * Encodes all non-ASCII characters, as well as characters not valid in HTML - * documents using HTML entities. This function will not encode characters that - * are valid in HTML documents, such as `#`. - * - * If a character has no equivalent entity, a numeric hexadecimal reference - * (eg. `ü`) will be used. - */ -function encodeNonAsciiHTML(data) { - return encodeHTMLTrieRe(escape_js_1.xmlReplacer, data); -} -exports.encodeNonAsciiHTML = encodeNonAsciiHTML; -function encodeHTMLTrieRe(regExp, str) { - var ret = ""; - var lastIdx = 0; - var match; - while ((match = regExp.exec(str)) !== null) { - var i = match.index; - ret += str.substring(lastIdx, i); - var char = str.charCodeAt(i); - var next = encode_html_js_1.default.get(char); - if (typeof next === "object") { - // We are in a branch. Try to match the next char. - if (i + 1 < str.length) { - var nextChar = str.charCodeAt(i + 1); - var value = typeof next.n === "number" - ? next.n === nextChar - ? next.o - : undefined - : next.n.get(nextChar); - if (value !== undefined) { - ret += value; - lastIdx = regExp.lastIndex += 1; - continue; - } - } - next = next.v; + + self.$include($$$('Enumerable')); + self.$$prototype.$$is_hash = true; + $defs(self, '$[]', function $Hash_$$$1($a) { + var $post_args, argv, self = this; + + + $post_args = $slice(arguments); + argv = $post_args; + + var hash, argc = argv.length, i; + + if (argc === 1) { + hash = $Opal['$coerce_to?'](argv['$[]'](0), $$$('Hash'), "to_hash"); + if (hash !== nil) { + return self.$allocate()['$merge!'](hash); } - // We might have a tree node without a value; skip and use a numeric entity. - if (next !== undefined) { - ret += next; - lastIdx = i + 1; + + argv = $Opal['$coerce_to?'](argv['$[]'](0), $$$('Array'), "to_ary"); + if (argv === nil) { + $Kernel.$raise($$$('ArgumentError'), "odd number of arguments for Hash"); } - else { - var cp = (0, escape_js_1.getCodePoint)(str, i); - ret += "&#x".concat(cp.toString(16), ";"); - // Increase by 1 if we have a surrogate pair - lastIdx = regExp.lastIndex += Number(cp !== char); + + argc = argv.length; + hash = self.$allocate(); + + for (i = 0; i < argc; i++) { + if (!argv[i].$$is_array) continue; + switch(argv[i].length) { + case 1: + hash.$store(argv[i][0], nil); + break; + case 2: + hash.$store(argv[i][0], argv[i][1]); + break; + default: + $Kernel.$raise($$$('ArgumentError'), "invalid number of elements (" + (argv[i].length) + " for 1..2)"); + } } - } - return ret + str.substr(lastIdx); -} -//# sourceMappingURL=encode.js.map -/***/ }), + return hash; + } -/***/ 7654: -/***/ ((__unused_webpack_module, exports) => { + if (argc % 2 !== 0) { + $Kernel.$raise($$$('ArgumentError'), "odd number of arguments for Hash"); + } -"use strict"; + hash = self.$allocate(); -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.getCodePoint = exports.xmlReplacer = void 0; -exports.xmlReplacer = /["&'<>$\x80-\uFFFF]/g; -var xmlCodeMap = new Map([ - [34, """], - [38, "&"], - [39, "'"], - [60, "<"], - [62, ">"], -]); -// For compatibility with node < 4, we wrap `codePointAt` -exports.getCodePoint = -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -String.prototype.codePointAt != null - ? function (str, index) { return str.codePointAt(index); } - : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - function (c, index) { - return (c.charCodeAt(index) & 0xfc00) === 0xd800 - ? (c.charCodeAt(index) - 0xd800) * 0x400 + - c.charCodeAt(index + 1) - - 0xdc00 + - 0x10000 - : c.charCodeAt(index); - }; -/** - * Encodes all non-ASCII characters, as well as characters not valid in XML - * documents using XML entities. - * - * If a character has no equivalent entity, a - * numeric hexadecimal reference (eg. `ü`) will be used. - */ -function encodeXML(str) { - var ret = ""; - var lastIdx = 0; - var match; - while ((match = exports.xmlReplacer.exec(str)) !== null) { - var i = match.index; - var char = str.charCodeAt(i); - var next = xmlCodeMap.get(char); - if (next !== undefined) { - ret += str.substring(lastIdx, i) + next; - lastIdx = i + 1; + for (i = 0; i < argc; i += 2) { + hash.$store(argv[i], argv[i + 1]); + } + + return hash; + }, -1); + $defs(self, '$allocate', function $$allocate() { + var self = this; + + + var hash = new self.$$constructor(); + + $hash_init(hash); + + hash.$$none = nil; + hash.$$proc = nil; + + return hash; + + }); + $defs(self, '$try_convert', function $$try_convert(obj) { + + return $Opal['$coerce_to?'](obj, $$$('Hash'), "to_hash") + }); + + $def(self, '$initialize', function $$initialize(defaults) { + var block = $$initialize.$$p || nil, self = this; + + $$initialize.$$p = null; + + $deny_frozen_access(self); + + if (defaults !== undefined && block !== nil) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (1 for 0)"); + } + self.$$none = (defaults === undefined ? nil : defaults); + self.$$proc = block; + + return self; + }, -1); + + $def(self, '$==', function $Hash_$eq_eq$2(other) { + var self = this; + + + if (self === other) { + return true; + } + + if (!other.$$is_hash) { + return false; + } + + if (self.$$keys.length !== other.$$keys.length) { + return false; + } + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, other_value; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + value = self.$$smap[key]; + other_value = other.$$smap[key]; + } else { + value = key.value; + other_value = $hash_get(other, key.key); } - else { - ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";"); - // Increase by 1 if we have a surrogate pair - lastIdx = exports.xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800); + + if (other_value === undefined || !value['$eql?'](other_value)) { + return false; } - } - return ret + str.substr(lastIdx); -} -exports.encodeXML = encodeXML; -/** - * Encodes all non-ASCII characters, as well as characters not valid in XML - * documents using numeric hexadecimal reference (eg. `ü`). - * - * Have a look at `escapeUTF8` if you want a more concise output at the expense - * of reduced transportability. - * - * @param data String to escape. - */ -exports.escape = encodeXML; -/** - * Creates a function that escapes all characters matched by the given regular - * expression using the given map of characters to escape to their entities. - * - * @param regex Regular expression to match characters to escape. - * @param map Map of characters to escape to their entities. - * - * @returns Function that escapes all characters matched by the given regular - * expression using the given map of characters to escape to their entities. - */ -function getEscaper(regex, map) { - return function escape(data) { - var match; - var lastIdx = 0; - var result = ""; - while ((match = regex.exec(data))) { - if (lastIdx !== match.index) { - result += data.substring(lastIdx, match.index); - } - // We know that this character will be in the map. - result += map.get(match[0].charCodeAt(0)); - // Every match will be of length 1 - lastIdx = match.index + 1; + } + + return true; + + }); + + $def(self, '$>=', function $Hash_$gt_eq$3(other) { + var self = this, result = nil; + + + other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash"); + + if (self.$$keys.length < other.$$keys.length) { + return false + } + result = true; + $send(other, 'each', [], function $$4(other_key, other_val){var self = $$4.$$s == null ? this : $$4.$$s, val = nil; + + + if (other_key == null) other_key = nil; + if (other_val == null) other_val = nil; + val = self.$fetch(other_key, null); + + if (val == null || val !== other_val) { + result = false; + return; + } +}, {$$s: self}); + return result; + }); + + $def(self, '$>', function $Hash_$gt$5(other) { + var self = this; + + + other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash"); + + if (self.$$keys.length <= other.$$keys.length) { + return false + } + return $rb_ge(self, other); + }); + + $def(self, '$<', function $Hash_$lt$6(other) { + var self = this; + + + other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash"); + return $rb_gt(other, self); + }); + + $def(self, '$<=', function $Hash_$lt_eq$7(other) { + var self = this; + + + other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash"); + return $rb_ge(other, self); + }); + + $def(self, '$[]', function $Hash_$$$8(key) { + var self = this; + + + var value = $hash_get(self, key); + + if (value !== undefined) { + return value; + } + + return self.$default(key); + + }); + + $def(self, '$[]=', function $Hash_$$$eq$9(key, value) { + var self = this; + + + $deny_frozen_access(self); + + $hash_put(self, key, value); + return value; + + }); + + $def(self, '$assoc', function $$assoc(object) { + var self = this; + + + for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + if ((key)['$=='](object)) { + return [key, self.$$smap[key]]; + } + } else { + if ((key.key)['$=='](object)) { + return [key.key, key.value]; + } } - return result + data.substring(lastIdx); - }; -} -/** - * Encodes all characters not valid in XML documents using XML entities. - * - * Note that the output will be character-set dependent. - * - * @param data String to escape. - */ -exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap); -/** - * Encodes all characters that have to be escaped in HTML attributes, - * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. - * - * @param data String to escape. - */ -exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([ - [34, """], - [38, "&"], - [160, " "], -])); -/** - * Encodes all characters that have to be escaped in HTML text, - * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. - * - * @param data String to escape. - */ -exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([ - [38, "&"], - [60, "<"], - [62, ">"], - [160, " "], -])); -//# sourceMappingURL=escape.js.map + } -/***/ }), + return nil; + + }); + + $def(self, '$clear', function $$clear() { + var self = this; -/***/ 6970: -/***/ ((__unused_webpack_module, exports) => { + + $deny_frozen_access(self); -"use strict"; + $hash_init(self); + return self; + + }); + + $def(self, '$clone', function $$clone() { + var self = this; -// Generated using scripts/write-decode-map.ts -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports["default"] = new Uint16Array( -// prettier-ignore -"\u1d41<\xd5\u0131\u028a\u049d\u057b\u05d0\u0675\u06de\u07a2\u07d6\u080f\u0a4a\u0a91\u0da1\u0e6d\u0f09\u0f26\u10ca\u1228\u12e1\u1415\u149d\u14c3\u14df\u1525\0\0\0\0\0\0\u156b\u16cd\u198d\u1c12\u1ddd\u1f7e\u2060\u21b0\u228d\u23c0\u23fb\u2442\u2824\u2912\u2d08\u2e48\u2fce\u3016\u32ba\u3639\u37ac\u38fe\u3a28\u3a71\u3ae0\u3b2e\u0800EMabcfglmnoprstu\\bfms\x7f\x84\x8b\x90\x95\x98\xa6\xb3\xb9\xc8\xcflig\u803b\xc6\u40c6P\u803b&\u4026cute\u803b\xc1\u40c1reve;\u4102\u0100iyx}rc\u803b\xc2\u40c2;\u4410r;\uc000\ud835\udd04rave\u803b\xc0\u40c0pha;\u4391acr;\u4100d;\u6a53\u0100gp\x9d\xa1on;\u4104f;\uc000\ud835\udd38plyFunction;\u6061ing\u803b\xc5\u40c5\u0100cs\xbe\xc3r;\uc000\ud835\udc9cign;\u6254ilde\u803b\xc3\u40c3ml\u803b\xc4\u40c4\u0400aceforsu\xe5\xfb\xfe\u0117\u011c\u0122\u0127\u012a\u0100cr\xea\xf2kslash;\u6216\u0176\xf6\xf8;\u6ae7ed;\u6306y;\u4411\u0180crt\u0105\u010b\u0114ause;\u6235noullis;\u612ca;\u4392r;\uc000\ud835\udd05pf;\uc000\ud835\udd39eve;\u42d8c\xf2\u0113mpeq;\u624e\u0700HOacdefhilorsu\u014d\u0151\u0156\u0180\u019e\u01a2\u01b5\u01b7\u01ba\u01dc\u0215\u0273\u0278\u027ecy;\u4427PY\u803b\xa9\u40a9\u0180cpy\u015d\u0162\u017aute;\u4106\u0100;i\u0167\u0168\u62d2talDifferentialD;\u6145leys;\u612d\u0200aeio\u0189\u018e\u0194\u0198ron;\u410cdil\u803b\xc7\u40c7rc;\u4108nint;\u6230ot;\u410a\u0100dn\u01a7\u01adilla;\u40b8terDot;\u40b7\xf2\u017fi;\u43a7rcle\u0200DMPT\u01c7\u01cb\u01d1\u01d6ot;\u6299inus;\u6296lus;\u6295imes;\u6297o\u0100cs\u01e2\u01f8kwiseContourIntegral;\u6232eCurly\u0100DQ\u0203\u020foubleQuote;\u601duote;\u6019\u0200lnpu\u021e\u0228\u0247\u0255on\u0100;e\u0225\u0226\u6237;\u6a74\u0180git\u022f\u0236\u023aruent;\u6261nt;\u622fourIntegral;\u622e\u0100fr\u024c\u024e;\u6102oduct;\u6210nterClockwiseContourIntegral;\u6233oss;\u6a2fcr;\uc000\ud835\udc9ep\u0100;C\u0284\u0285\u62d3ap;\u624d\u0580DJSZacefios\u02a0\u02ac\u02b0\u02b4\u02b8\u02cb\u02d7\u02e1\u02e6\u0333\u048d\u0100;o\u0179\u02a5trahd;\u6911cy;\u4402cy;\u4405cy;\u440f\u0180grs\u02bf\u02c4\u02c7ger;\u6021r;\u61a1hv;\u6ae4\u0100ay\u02d0\u02d5ron;\u410e;\u4414l\u0100;t\u02dd\u02de\u6207a;\u4394r;\uc000\ud835\udd07\u0100af\u02eb\u0327\u0100cm\u02f0\u0322ritical\u0200ADGT\u0300\u0306\u0316\u031ccute;\u40b4o\u0174\u030b\u030d;\u42d9bleAcute;\u42ddrave;\u4060ilde;\u42dcond;\u62c4ferentialD;\u6146\u0470\u033d\0\0\0\u0342\u0354\0\u0405f;\uc000\ud835\udd3b\u0180;DE\u0348\u0349\u034d\u40a8ot;\u60dcqual;\u6250ble\u0300CDLRUV\u0363\u0372\u0382\u03cf\u03e2\u03f8ontourIntegra\xec\u0239o\u0274\u0379\0\0\u037b\xbb\u0349nArrow;\u61d3\u0100eo\u0387\u03a4ft\u0180ART\u0390\u0396\u03a1rrow;\u61d0ightArrow;\u61d4e\xe5\u02cang\u0100LR\u03ab\u03c4eft\u0100AR\u03b3\u03b9rrow;\u67f8ightArrow;\u67faightArrow;\u67f9ight\u0100AT\u03d8\u03derrow;\u61d2ee;\u62a8p\u0241\u03e9\0\0\u03efrrow;\u61d1ownArrow;\u61d5erticalBar;\u6225n\u0300ABLRTa\u0412\u042a\u0430\u045e\u047f\u037crrow\u0180;BU\u041d\u041e\u0422\u6193ar;\u6913pArrow;\u61f5reve;\u4311eft\u02d2\u043a\0\u0446\0\u0450ightVector;\u6950eeVector;\u695eector\u0100;B\u0459\u045a\u61bdar;\u6956ight\u01d4\u0467\0\u0471eeVector;\u695fector\u0100;B\u047a\u047b\u61c1ar;\u6957ee\u0100;A\u0486\u0487\u62a4rrow;\u61a7\u0100ct\u0492\u0497r;\uc000\ud835\udc9frok;\u4110\u0800NTacdfglmopqstux\u04bd\u04c0\u04c4\u04cb\u04de\u04e2\u04e7\u04ee\u04f5\u0521\u052f\u0536\u0552\u055d\u0560\u0565G;\u414aH\u803b\xd0\u40d0cute\u803b\xc9\u40c9\u0180aiy\u04d2\u04d7\u04dcron;\u411arc\u803b\xca\u40ca;\u442dot;\u4116r;\uc000\ud835\udd08rave\u803b\xc8\u40c8ement;\u6208\u0100ap\u04fa\u04fecr;\u4112ty\u0253\u0506\0\0\u0512mallSquare;\u65fberySmallSquare;\u65ab\u0100gp\u0526\u052aon;\u4118f;\uc000\ud835\udd3csilon;\u4395u\u0100ai\u053c\u0549l\u0100;T\u0542\u0543\u6a75ilde;\u6242librium;\u61cc\u0100ci\u0557\u055ar;\u6130m;\u6a73a;\u4397ml\u803b\xcb\u40cb\u0100ip\u056a\u056fsts;\u6203onentialE;\u6147\u0280cfios\u0585\u0588\u058d\u05b2\u05ccy;\u4424r;\uc000\ud835\udd09lled\u0253\u0597\0\0\u05a3mallSquare;\u65fcerySmallSquare;\u65aa\u0370\u05ba\0\u05bf\0\0\u05c4f;\uc000\ud835\udd3dAll;\u6200riertrf;\u6131c\xf2\u05cb\u0600JTabcdfgorst\u05e8\u05ec\u05ef\u05fa\u0600\u0612\u0616\u061b\u061d\u0623\u066c\u0672cy;\u4403\u803b>\u403emma\u0100;d\u05f7\u05f8\u4393;\u43dcreve;\u411e\u0180eiy\u0607\u060c\u0610dil;\u4122rc;\u411c;\u4413ot;\u4120r;\uc000\ud835\udd0a;\u62d9pf;\uc000\ud835\udd3eeater\u0300EFGLST\u0635\u0644\u064e\u0656\u065b\u0666qual\u0100;L\u063e\u063f\u6265ess;\u62dbullEqual;\u6267reater;\u6aa2ess;\u6277lantEqual;\u6a7eilde;\u6273cr;\uc000\ud835\udca2;\u626b\u0400Aacfiosu\u0685\u068b\u0696\u069b\u069e\u06aa\u06be\u06caRDcy;\u442a\u0100ct\u0690\u0694ek;\u42c7;\u405eirc;\u4124r;\u610clbertSpace;\u610b\u01f0\u06af\0\u06b2f;\u610dizontalLine;\u6500\u0100ct\u06c3\u06c5\xf2\u06a9rok;\u4126mp\u0144\u06d0\u06d8ownHum\xf0\u012fqual;\u624f\u0700EJOacdfgmnostu\u06fa\u06fe\u0703\u0707\u070e\u071a\u071e\u0721\u0728\u0744\u0778\u078b\u078f\u0795cy;\u4415lig;\u4132cy;\u4401cute\u803b\xcd\u40cd\u0100iy\u0713\u0718rc\u803b\xce\u40ce;\u4418ot;\u4130r;\u6111rave\u803b\xcc\u40cc\u0180;ap\u0720\u072f\u073f\u0100cg\u0734\u0737r;\u412ainaryI;\u6148lie\xf3\u03dd\u01f4\u0749\0\u0762\u0100;e\u074d\u074e\u622c\u0100gr\u0753\u0758ral;\u622bsection;\u62c2isible\u0100CT\u076c\u0772omma;\u6063imes;\u6062\u0180gpt\u077f\u0783\u0788on;\u412ef;\uc000\ud835\udd40a;\u4399cr;\u6110ilde;\u4128\u01eb\u079a\0\u079ecy;\u4406l\u803b\xcf\u40cf\u0280cfosu\u07ac\u07b7\u07bc\u07c2\u07d0\u0100iy\u07b1\u07b5rc;\u4134;\u4419r;\uc000\ud835\udd0dpf;\uc000\ud835\udd41\u01e3\u07c7\0\u07ccr;\uc000\ud835\udca5rcy;\u4408kcy;\u4404\u0380HJacfos\u07e4\u07e8\u07ec\u07f1\u07fd\u0802\u0808cy;\u4425cy;\u440cppa;\u439a\u0100ey\u07f6\u07fbdil;\u4136;\u441ar;\uc000\ud835\udd0epf;\uc000\ud835\udd42cr;\uc000\ud835\udca6\u0580JTaceflmost\u0825\u0829\u082c\u0850\u0863\u09b3\u09b8\u09c7\u09cd\u0a37\u0a47cy;\u4409\u803b<\u403c\u0280cmnpr\u0837\u083c\u0841\u0844\u084dute;\u4139bda;\u439bg;\u67ealacetrf;\u6112r;\u619e\u0180aey\u0857\u085c\u0861ron;\u413ddil;\u413b;\u441b\u0100fs\u0868\u0970t\u0500ACDFRTUVar\u087e\u08a9\u08b1\u08e0\u08e6\u08fc\u092f\u095b\u0390\u096a\u0100nr\u0883\u088fgleBracket;\u67e8row\u0180;BR\u0899\u089a\u089e\u6190ar;\u61e4ightArrow;\u61c6eiling;\u6308o\u01f5\u08b7\0\u08c3bleBracket;\u67e6n\u01d4\u08c8\0\u08d2eeVector;\u6961ector\u0100;B\u08db\u08dc\u61c3ar;\u6959loor;\u630aight\u0100AV\u08ef\u08f5rrow;\u6194ector;\u694e\u0100er\u0901\u0917e\u0180;AV\u0909\u090a\u0910\u62a3rrow;\u61a4ector;\u695aiangle\u0180;BE\u0924\u0925\u0929\u62b2ar;\u69cfqual;\u62b4p\u0180DTV\u0937\u0942\u094cownVector;\u6951eeVector;\u6960ector\u0100;B\u0956\u0957\u61bfar;\u6958ector\u0100;B\u0965\u0966\u61bcar;\u6952ight\xe1\u039cs\u0300EFGLST\u097e\u098b\u0995\u099d\u09a2\u09adqualGreater;\u62daullEqual;\u6266reater;\u6276ess;\u6aa1lantEqual;\u6a7dilde;\u6272r;\uc000\ud835\udd0f\u0100;e\u09bd\u09be\u62d8ftarrow;\u61daidot;\u413f\u0180npw\u09d4\u0a16\u0a1bg\u0200LRlr\u09de\u09f7\u0a02\u0a10eft\u0100AR\u09e6\u09ecrrow;\u67f5ightArrow;\u67f7ightArrow;\u67f6eft\u0100ar\u03b3\u0a0aight\xe1\u03bfight\xe1\u03caf;\uc000\ud835\udd43er\u0100LR\u0a22\u0a2ceftArrow;\u6199ightArrow;\u6198\u0180cht\u0a3e\u0a40\u0a42\xf2\u084c;\u61b0rok;\u4141;\u626a\u0400acefiosu\u0a5a\u0a5d\u0a60\u0a77\u0a7c\u0a85\u0a8b\u0a8ep;\u6905y;\u441c\u0100dl\u0a65\u0a6fiumSpace;\u605flintrf;\u6133r;\uc000\ud835\udd10nusPlus;\u6213pf;\uc000\ud835\udd44c\xf2\u0a76;\u439c\u0480Jacefostu\u0aa3\u0aa7\u0aad\u0ac0\u0b14\u0b19\u0d91\u0d97\u0d9ecy;\u440acute;\u4143\u0180aey\u0ab4\u0ab9\u0aberon;\u4147dil;\u4145;\u441d\u0180gsw\u0ac7\u0af0\u0b0eative\u0180MTV\u0ad3\u0adf\u0ae8ediumSpace;\u600bhi\u0100cn\u0ae6\u0ad8\xeb\u0ad9eryThi\xee\u0ad9ted\u0100GL\u0af8\u0b06reaterGreate\xf2\u0673essLes\xf3\u0a48Line;\u400ar;\uc000\ud835\udd11\u0200Bnpt\u0b22\u0b28\u0b37\u0b3areak;\u6060BreakingSpace;\u40a0f;\u6115\u0680;CDEGHLNPRSTV\u0b55\u0b56\u0b6a\u0b7c\u0ba1\u0beb\u0c04\u0c5e\u0c84\u0ca6\u0cd8\u0d61\u0d85\u6aec\u0100ou\u0b5b\u0b64ngruent;\u6262pCap;\u626doubleVerticalBar;\u6226\u0180lqx\u0b83\u0b8a\u0b9bement;\u6209ual\u0100;T\u0b92\u0b93\u6260ilde;\uc000\u2242\u0338ists;\u6204reater\u0380;EFGLST\u0bb6\u0bb7\u0bbd\u0bc9\u0bd3\u0bd8\u0be5\u626fqual;\u6271ullEqual;\uc000\u2267\u0338reater;\uc000\u226b\u0338ess;\u6279lantEqual;\uc000\u2a7e\u0338ilde;\u6275ump\u0144\u0bf2\u0bfdownHump;\uc000\u224e\u0338qual;\uc000\u224f\u0338e\u0100fs\u0c0a\u0c27tTriangle\u0180;BE\u0c1a\u0c1b\u0c21\u62eaar;\uc000\u29cf\u0338qual;\u62ecs\u0300;EGLST\u0c35\u0c36\u0c3c\u0c44\u0c4b\u0c58\u626equal;\u6270reater;\u6278ess;\uc000\u226a\u0338lantEqual;\uc000\u2a7d\u0338ilde;\u6274ested\u0100GL\u0c68\u0c79reaterGreater;\uc000\u2aa2\u0338essLess;\uc000\u2aa1\u0338recedes\u0180;ES\u0c92\u0c93\u0c9b\u6280qual;\uc000\u2aaf\u0338lantEqual;\u62e0\u0100ei\u0cab\u0cb9verseElement;\u620cghtTriangle\u0180;BE\u0ccb\u0ccc\u0cd2\u62ebar;\uc000\u29d0\u0338qual;\u62ed\u0100qu\u0cdd\u0d0cuareSu\u0100bp\u0ce8\u0cf9set\u0100;E\u0cf0\u0cf3\uc000\u228f\u0338qual;\u62e2erset\u0100;E\u0d03\u0d06\uc000\u2290\u0338qual;\u62e3\u0180bcp\u0d13\u0d24\u0d4eset\u0100;E\u0d1b\u0d1e\uc000\u2282\u20d2qual;\u6288ceeds\u0200;EST\u0d32\u0d33\u0d3b\u0d46\u6281qual;\uc000\u2ab0\u0338lantEqual;\u62e1ilde;\uc000\u227f\u0338erset\u0100;E\u0d58\u0d5b\uc000\u2283\u20d2qual;\u6289ilde\u0200;EFT\u0d6e\u0d6f\u0d75\u0d7f\u6241qual;\u6244ullEqual;\u6247ilde;\u6249erticalBar;\u6224cr;\uc000\ud835\udca9ilde\u803b\xd1\u40d1;\u439d\u0700Eacdfgmoprstuv\u0dbd\u0dc2\u0dc9\u0dd5\u0ddb\u0de0\u0de7\u0dfc\u0e02\u0e20\u0e22\u0e32\u0e3f\u0e44lig;\u4152cute\u803b\xd3\u40d3\u0100iy\u0dce\u0dd3rc\u803b\xd4\u40d4;\u441eblac;\u4150r;\uc000\ud835\udd12rave\u803b\xd2\u40d2\u0180aei\u0dee\u0df2\u0df6cr;\u414cga;\u43a9cron;\u439fpf;\uc000\ud835\udd46enCurly\u0100DQ\u0e0e\u0e1aoubleQuote;\u601cuote;\u6018;\u6a54\u0100cl\u0e27\u0e2cr;\uc000\ud835\udcaaash\u803b\xd8\u40d8i\u016c\u0e37\u0e3cde\u803b\xd5\u40d5es;\u6a37ml\u803b\xd6\u40d6er\u0100BP\u0e4b\u0e60\u0100ar\u0e50\u0e53r;\u603eac\u0100ek\u0e5a\u0e5c;\u63deet;\u63b4arenthesis;\u63dc\u0480acfhilors\u0e7f\u0e87\u0e8a\u0e8f\u0e92\u0e94\u0e9d\u0eb0\u0efcrtialD;\u6202y;\u441fr;\uc000\ud835\udd13i;\u43a6;\u43a0usMinus;\u40b1\u0100ip\u0ea2\u0eadncareplan\xe5\u069df;\u6119\u0200;eio\u0eb9\u0eba\u0ee0\u0ee4\u6abbcedes\u0200;EST\u0ec8\u0ec9\u0ecf\u0eda\u627aqual;\u6aaflantEqual;\u627cilde;\u627eme;\u6033\u0100dp\u0ee9\u0eeeuct;\u620fortion\u0100;a\u0225\u0ef9l;\u621d\u0100ci\u0f01\u0f06r;\uc000\ud835\udcab;\u43a8\u0200Ufos\u0f11\u0f16\u0f1b\u0f1fOT\u803b\"\u4022r;\uc000\ud835\udd14pf;\u611acr;\uc000\ud835\udcac\u0600BEacefhiorsu\u0f3e\u0f43\u0f47\u0f60\u0f73\u0fa7\u0faa\u0fad\u1096\u10a9\u10b4\u10bearr;\u6910G\u803b\xae\u40ae\u0180cnr\u0f4e\u0f53\u0f56ute;\u4154g;\u67ebr\u0100;t\u0f5c\u0f5d\u61a0l;\u6916\u0180aey\u0f67\u0f6c\u0f71ron;\u4158dil;\u4156;\u4420\u0100;v\u0f78\u0f79\u611cerse\u0100EU\u0f82\u0f99\u0100lq\u0f87\u0f8eement;\u620builibrium;\u61cbpEquilibrium;\u696fr\xbb\u0f79o;\u43a1ght\u0400ACDFTUVa\u0fc1\u0feb\u0ff3\u1022\u1028\u105b\u1087\u03d8\u0100nr\u0fc6\u0fd2gleBracket;\u67e9row\u0180;BL\u0fdc\u0fdd\u0fe1\u6192ar;\u61e5eftArrow;\u61c4eiling;\u6309o\u01f5\u0ff9\0\u1005bleBracket;\u67e7n\u01d4\u100a\0\u1014eeVector;\u695dector\u0100;B\u101d\u101e\u61c2ar;\u6955loor;\u630b\u0100er\u102d\u1043e\u0180;AV\u1035\u1036\u103c\u62a2rrow;\u61a6ector;\u695biangle\u0180;BE\u1050\u1051\u1055\u62b3ar;\u69d0qual;\u62b5p\u0180DTV\u1063\u106e\u1078ownVector;\u694feeVector;\u695cector\u0100;B\u1082\u1083\u61bear;\u6954ector\u0100;B\u1091\u1092\u61c0ar;\u6953\u0100pu\u109b\u109ef;\u611dndImplies;\u6970ightarrow;\u61db\u0100ch\u10b9\u10bcr;\u611b;\u61b1leDelayed;\u69f4\u0680HOacfhimoqstu\u10e4\u10f1\u10f7\u10fd\u1119\u111e\u1151\u1156\u1161\u1167\u11b5\u11bb\u11bf\u0100Cc\u10e9\u10eeHcy;\u4429y;\u4428FTcy;\u442ccute;\u415a\u0280;aeiy\u1108\u1109\u110e\u1113\u1117\u6abcron;\u4160dil;\u415erc;\u415c;\u4421r;\uc000\ud835\udd16ort\u0200DLRU\u112a\u1134\u113e\u1149ownArrow\xbb\u041eeftArrow\xbb\u089aightArrow\xbb\u0fddpArrow;\u6191gma;\u43a3allCircle;\u6218pf;\uc000\ud835\udd4a\u0272\u116d\0\0\u1170t;\u621aare\u0200;ISU\u117b\u117c\u1189\u11af\u65a1ntersection;\u6293u\u0100bp\u118f\u119eset\u0100;E\u1197\u1198\u628fqual;\u6291erset\u0100;E\u11a8\u11a9\u6290qual;\u6292nion;\u6294cr;\uc000\ud835\udcaear;\u62c6\u0200bcmp\u11c8\u11db\u1209\u120b\u0100;s\u11cd\u11ce\u62d0et\u0100;E\u11cd\u11d5qual;\u6286\u0100ch\u11e0\u1205eeds\u0200;EST\u11ed\u11ee\u11f4\u11ff\u627bqual;\u6ab0lantEqual;\u627dilde;\u627fTh\xe1\u0f8c;\u6211\u0180;es\u1212\u1213\u1223\u62d1rset\u0100;E\u121c\u121d\u6283qual;\u6287et\xbb\u1213\u0580HRSacfhiors\u123e\u1244\u1249\u1255\u125e\u1271\u1276\u129f\u12c2\u12c8\u12d1ORN\u803b\xde\u40deADE;\u6122\u0100Hc\u124e\u1252cy;\u440by;\u4426\u0100bu\u125a\u125c;\u4009;\u43a4\u0180aey\u1265\u126a\u126fron;\u4164dil;\u4162;\u4422r;\uc000\ud835\udd17\u0100ei\u127b\u1289\u01f2\u1280\0\u1287efore;\u6234a;\u4398\u0100cn\u128e\u1298kSpace;\uc000\u205f\u200aSpace;\u6009lde\u0200;EFT\u12ab\u12ac\u12b2\u12bc\u623cqual;\u6243ullEqual;\u6245ilde;\u6248pf;\uc000\ud835\udd4bipleDot;\u60db\u0100ct\u12d6\u12dbr;\uc000\ud835\udcafrok;\u4166\u0ae1\u12f7\u130e\u131a\u1326\0\u132c\u1331\0\0\0\0\0\u1338\u133d\u1377\u1385\0\u13ff\u1404\u140a\u1410\u0100cr\u12fb\u1301ute\u803b\xda\u40dar\u0100;o\u1307\u1308\u619fcir;\u6949r\u01e3\u1313\0\u1316y;\u440eve;\u416c\u0100iy\u131e\u1323rc\u803b\xdb\u40db;\u4423blac;\u4170r;\uc000\ud835\udd18rave\u803b\xd9\u40d9acr;\u416a\u0100di\u1341\u1369er\u0100BP\u1348\u135d\u0100ar\u134d\u1350r;\u405fac\u0100ek\u1357\u1359;\u63dfet;\u63b5arenthesis;\u63ddon\u0100;P\u1370\u1371\u62c3lus;\u628e\u0100gp\u137b\u137fon;\u4172f;\uc000\ud835\udd4c\u0400ADETadps\u1395\u13ae\u13b8\u13c4\u03e8\u13d2\u13d7\u13f3rrow\u0180;BD\u1150\u13a0\u13a4ar;\u6912ownArrow;\u61c5ownArrow;\u6195quilibrium;\u696eee\u0100;A\u13cb\u13cc\u62a5rrow;\u61a5own\xe1\u03f3er\u0100LR\u13de\u13e8eftArrow;\u6196ightArrow;\u6197i\u0100;l\u13f9\u13fa\u43d2on;\u43a5ing;\u416ecr;\uc000\ud835\udcb0ilde;\u4168ml\u803b\xdc\u40dc\u0480Dbcdefosv\u1427\u142c\u1430\u1433\u143e\u1485\u148a\u1490\u1496ash;\u62abar;\u6aeby;\u4412ash\u0100;l\u143b\u143c\u62a9;\u6ae6\u0100er\u1443\u1445;\u62c1\u0180bty\u144c\u1450\u147aar;\u6016\u0100;i\u144f\u1455cal\u0200BLST\u1461\u1465\u146a\u1474ar;\u6223ine;\u407ceparator;\u6758ilde;\u6240ThinSpace;\u600ar;\uc000\ud835\udd19pf;\uc000\ud835\udd4dcr;\uc000\ud835\udcb1dash;\u62aa\u0280cefos\u14a7\u14ac\u14b1\u14b6\u14bcirc;\u4174dge;\u62c0r;\uc000\ud835\udd1apf;\uc000\ud835\udd4ecr;\uc000\ud835\udcb2\u0200fios\u14cb\u14d0\u14d2\u14d8r;\uc000\ud835\udd1b;\u439epf;\uc000\ud835\udd4fcr;\uc000\ud835\udcb3\u0480AIUacfosu\u14f1\u14f5\u14f9\u14fd\u1504\u150f\u1514\u151a\u1520cy;\u442fcy;\u4407cy;\u442ecute\u803b\xdd\u40dd\u0100iy\u1509\u150drc;\u4176;\u442br;\uc000\ud835\udd1cpf;\uc000\ud835\udd50cr;\uc000\ud835\udcb4ml;\u4178\u0400Hacdefos\u1535\u1539\u153f\u154b\u154f\u155d\u1560\u1564cy;\u4416cute;\u4179\u0100ay\u1544\u1549ron;\u417d;\u4417ot;\u417b\u01f2\u1554\0\u155boWidt\xe8\u0ad9a;\u4396r;\u6128pf;\u6124cr;\uc000\ud835\udcb5\u0be1\u1583\u158a\u1590\0\u15b0\u15b6\u15bf\0\0\0\0\u15c6\u15db\u15eb\u165f\u166d\0\u1695\u169b\u16b2\u16b9\0\u16becute\u803b\xe1\u40e1reve;\u4103\u0300;Ediuy\u159c\u159d\u15a1\u15a3\u15a8\u15ad\u623e;\uc000\u223e\u0333;\u623frc\u803b\xe2\u40e2te\u80bb\xb4\u0306;\u4430lig\u803b\xe6\u40e6\u0100;r\xb2\u15ba;\uc000\ud835\udd1erave\u803b\xe0\u40e0\u0100ep\u15ca\u15d6\u0100fp\u15cf\u15d4sym;\u6135\xe8\u15d3ha;\u43b1\u0100ap\u15dfc\u0100cl\u15e4\u15e7r;\u4101g;\u6a3f\u0264\u15f0\0\0\u160a\u0280;adsv\u15fa\u15fb\u15ff\u1601\u1607\u6227nd;\u6a55;\u6a5clope;\u6a58;\u6a5a\u0380;elmrsz\u1618\u1619\u161b\u161e\u163f\u164f\u1659\u6220;\u69a4e\xbb\u1619sd\u0100;a\u1625\u1626\u6221\u0461\u1630\u1632\u1634\u1636\u1638\u163a\u163c\u163e;\u69a8;\u69a9;\u69aa;\u69ab;\u69ac;\u69ad;\u69ae;\u69aft\u0100;v\u1645\u1646\u621fb\u0100;d\u164c\u164d\u62be;\u699d\u0100pt\u1654\u1657h;\u6222\xbb\xb9arr;\u637c\u0100gp\u1663\u1667on;\u4105f;\uc000\ud835\udd52\u0380;Eaeiop\u12c1\u167b\u167d\u1682\u1684\u1687\u168a;\u6a70cir;\u6a6f;\u624ad;\u624bs;\u4027rox\u0100;e\u12c1\u1692\xf1\u1683ing\u803b\xe5\u40e5\u0180cty\u16a1\u16a6\u16a8r;\uc000\ud835\udcb6;\u402amp\u0100;e\u12c1\u16af\xf1\u0288ilde\u803b\xe3\u40e3ml\u803b\xe4\u40e4\u0100ci\u16c2\u16c8onin\xf4\u0272nt;\u6a11\u0800Nabcdefiklnoprsu\u16ed\u16f1\u1730\u173c\u1743\u1748\u1778\u177d\u17e0\u17e6\u1839\u1850\u170d\u193d\u1948\u1970ot;\u6aed\u0100cr\u16f6\u171ek\u0200ceps\u1700\u1705\u170d\u1713ong;\u624cpsilon;\u43f6rime;\u6035im\u0100;e\u171a\u171b\u623dq;\u62cd\u0176\u1722\u1726ee;\u62bded\u0100;g\u172c\u172d\u6305e\xbb\u172drk\u0100;t\u135c\u1737brk;\u63b6\u0100oy\u1701\u1741;\u4431quo;\u601e\u0280cmprt\u1753\u175b\u1761\u1764\u1768aus\u0100;e\u010a\u0109ptyv;\u69b0s\xe9\u170cno\xf5\u0113\u0180ahw\u176f\u1771\u1773;\u43b2;\u6136een;\u626cr;\uc000\ud835\udd1fg\u0380costuvw\u178d\u179d\u17b3\u17c1\u17d5\u17db\u17de\u0180aiu\u1794\u1796\u179a\xf0\u0760rc;\u65efp\xbb\u1371\u0180dpt\u17a4\u17a8\u17adot;\u6a00lus;\u6a01imes;\u6a02\u0271\u17b9\0\0\u17becup;\u6a06ar;\u6605riangle\u0100du\u17cd\u17d2own;\u65bdp;\u65b3plus;\u6a04e\xe5\u1444\xe5\u14adarow;\u690d\u0180ako\u17ed\u1826\u1835\u0100cn\u17f2\u1823k\u0180lst\u17fa\u05ab\u1802ozenge;\u69ebriangle\u0200;dlr\u1812\u1813\u1818\u181d\u65b4own;\u65beeft;\u65c2ight;\u65b8k;\u6423\u01b1\u182b\0\u1833\u01b2\u182f\0\u1831;\u6592;\u65914;\u6593ck;\u6588\u0100eo\u183e\u184d\u0100;q\u1843\u1846\uc000=\u20e5uiv;\uc000\u2261\u20e5t;\u6310\u0200ptwx\u1859\u185e\u1867\u186cf;\uc000\ud835\udd53\u0100;t\u13cb\u1863om\xbb\u13cctie;\u62c8\u0600DHUVbdhmptuv\u1885\u1896\u18aa\u18bb\u18d7\u18db\u18ec\u18ff\u1905\u190a\u1910\u1921\u0200LRlr\u188e\u1890\u1892\u1894;\u6557;\u6554;\u6556;\u6553\u0280;DUdu\u18a1\u18a2\u18a4\u18a6\u18a8\u6550;\u6566;\u6569;\u6564;\u6567\u0200LRlr\u18b3\u18b5\u18b7\u18b9;\u655d;\u655a;\u655c;\u6559\u0380;HLRhlr\u18ca\u18cb\u18cd\u18cf\u18d1\u18d3\u18d5\u6551;\u656c;\u6563;\u6560;\u656b;\u6562;\u655fox;\u69c9\u0200LRlr\u18e4\u18e6\u18e8\u18ea;\u6555;\u6552;\u6510;\u650c\u0280;DUdu\u06bd\u18f7\u18f9\u18fb\u18fd;\u6565;\u6568;\u652c;\u6534inus;\u629flus;\u629eimes;\u62a0\u0200LRlr\u1919\u191b\u191d\u191f;\u655b;\u6558;\u6518;\u6514\u0380;HLRhlr\u1930\u1931\u1933\u1935\u1937\u1939\u193b\u6502;\u656a;\u6561;\u655e;\u653c;\u6524;\u651c\u0100ev\u0123\u1942bar\u803b\xa6\u40a6\u0200ceio\u1951\u1956\u195a\u1960r;\uc000\ud835\udcb7mi;\u604fm\u0100;e\u171a\u171cl\u0180;bh\u1968\u1969\u196b\u405c;\u69c5sub;\u67c8\u016c\u1974\u197el\u0100;e\u1979\u197a\u6022t\xbb\u197ap\u0180;Ee\u012f\u1985\u1987;\u6aae\u0100;q\u06dc\u06db\u0ce1\u19a7\0\u19e8\u1a11\u1a15\u1a32\0\u1a37\u1a50\0\0\u1ab4\0\0\u1ac1\0\0\u1b21\u1b2e\u1b4d\u1b52\0\u1bfd\0\u1c0c\u0180cpr\u19ad\u19b2\u19ddute;\u4107\u0300;abcds\u19bf\u19c0\u19c4\u19ca\u19d5\u19d9\u6229nd;\u6a44rcup;\u6a49\u0100au\u19cf\u19d2p;\u6a4bp;\u6a47ot;\u6a40;\uc000\u2229\ufe00\u0100eo\u19e2\u19e5t;\u6041\xee\u0693\u0200aeiu\u19f0\u19fb\u1a01\u1a05\u01f0\u19f5\0\u19f8s;\u6a4don;\u410ddil\u803b\xe7\u40e7rc;\u4109ps\u0100;s\u1a0c\u1a0d\u6a4cm;\u6a50ot;\u410b\u0180dmn\u1a1b\u1a20\u1a26il\u80bb\xb8\u01adptyv;\u69b2t\u8100\xa2;e\u1a2d\u1a2e\u40a2r\xe4\u01b2r;\uc000\ud835\udd20\u0180cei\u1a3d\u1a40\u1a4dy;\u4447ck\u0100;m\u1a47\u1a48\u6713ark\xbb\u1a48;\u43c7r\u0380;Ecefms\u1a5f\u1a60\u1a62\u1a6b\u1aa4\u1aaa\u1aae\u65cb;\u69c3\u0180;el\u1a69\u1a6a\u1a6d\u42c6q;\u6257e\u0261\u1a74\0\0\u1a88rrow\u0100lr\u1a7c\u1a81eft;\u61baight;\u61bb\u0280RSacd\u1a92\u1a94\u1a96\u1a9a\u1a9f\xbb\u0f47;\u64c8st;\u629birc;\u629aash;\u629dnint;\u6a10id;\u6aefcir;\u69c2ubs\u0100;u\u1abb\u1abc\u6663it\xbb\u1abc\u02ec\u1ac7\u1ad4\u1afa\0\u1b0aon\u0100;e\u1acd\u1ace\u403a\u0100;q\xc7\xc6\u026d\u1ad9\0\0\u1ae2a\u0100;t\u1ade\u1adf\u402c;\u4040\u0180;fl\u1ae8\u1ae9\u1aeb\u6201\xee\u1160e\u0100mx\u1af1\u1af6ent\xbb\u1ae9e\xf3\u024d\u01e7\u1afe\0\u1b07\u0100;d\u12bb\u1b02ot;\u6a6dn\xf4\u0246\u0180fry\u1b10\u1b14\u1b17;\uc000\ud835\udd54o\xe4\u0254\u8100\xa9;s\u0155\u1b1dr;\u6117\u0100ao\u1b25\u1b29rr;\u61b5ss;\u6717\u0100cu\u1b32\u1b37r;\uc000\ud835\udcb8\u0100bp\u1b3c\u1b44\u0100;e\u1b41\u1b42\u6acf;\u6ad1\u0100;e\u1b49\u1b4a\u6ad0;\u6ad2dot;\u62ef\u0380delprvw\u1b60\u1b6c\u1b77\u1b82\u1bac\u1bd4\u1bf9arr\u0100lr\u1b68\u1b6a;\u6938;\u6935\u0270\u1b72\0\0\u1b75r;\u62dec;\u62dfarr\u0100;p\u1b7f\u1b80\u61b6;\u693d\u0300;bcdos\u1b8f\u1b90\u1b96\u1ba1\u1ba5\u1ba8\u622arcap;\u6a48\u0100au\u1b9b\u1b9ep;\u6a46p;\u6a4aot;\u628dr;\u6a45;\uc000\u222a\ufe00\u0200alrv\u1bb5\u1bbf\u1bde\u1be3rr\u0100;m\u1bbc\u1bbd\u61b7;\u693cy\u0180evw\u1bc7\u1bd4\u1bd8q\u0270\u1bce\0\0\u1bd2re\xe3\u1b73u\xe3\u1b75ee;\u62ceedge;\u62cfen\u803b\xa4\u40a4earrow\u0100lr\u1bee\u1bf3eft\xbb\u1b80ight\xbb\u1bbde\xe4\u1bdd\u0100ci\u1c01\u1c07onin\xf4\u01f7nt;\u6231lcty;\u632d\u0980AHabcdefhijlorstuwz\u1c38\u1c3b\u1c3f\u1c5d\u1c69\u1c75\u1c8a\u1c9e\u1cac\u1cb7\u1cfb\u1cff\u1d0d\u1d7b\u1d91\u1dab\u1dbb\u1dc6\u1dcdr\xf2\u0381ar;\u6965\u0200glrs\u1c48\u1c4d\u1c52\u1c54ger;\u6020eth;\u6138\xf2\u1133h\u0100;v\u1c5a\u1c5b\u6010\xbb\u090a\u016b\u1c61\u1c67arow;\u690fa\xe3\u0315\u0100ay\u1c6e\u1c73ron;\u410f;\u4434\u0180;ao\u0332\u1c7c\u1c84\u0100gr\u02bf\u1c81r;\u61catseq;\u6a77\u0180glm\u1c91\u1c94\u1c98\u803b\xb0\u40b0ta;\u43b4ptyv;\u69b1\u0100ir\u1ca3\u1ca8sht;\u697f;\uc000\ud835\udd21ar\u0100lr\u1cb3\u1cb5\xbb\u08dc\xbb\u101e\u0280aegsv\u1cc2\u0378\u1cd6\u1cdc\u1ce0m\u0180;os\u0326\u1cca\u1cd4nd\u0100;s\u0326\u1cd1uit;\u6666amma;\u43ddin;\u62f2\u0180;io\u1ce7\u1ce8\u1cf8\u40f7de\u8100\xf7;o\u1ce7\u1cf0ntimes;\u62c7n\xf8\u1cf7cy;\u4452c\u026f\u1d06\0\0\u1d0arn;\u631eop;\u630d\u0280lptuw\u1d18\u1d1d\u1d22\u1d49\u1d55lar;\u4024f;\uc000\ud835\udd55\u0280;emps\u030b\u1d2d\u1d37\u1d3d\u1d42q\u0100;d\u0352\u1d33ot;\u6251inus;\u6238lus;\u6214quare;\u62a1blebarwedg\xe5\xfan\u0180adh\u112e\u1d5d\u1d67ownarrow\xf3\u1c83arpoon\u0100lr\u1d72\u1d76ef\xf4\u1cb4igh\xf4\u1cb6\u0162\u1d7f\u1d85karo\xf7\u0f42\u026f\u1d8a\0\0\u1d8ern;\u631fop;\u630c\u0180cot\u1d98\u1da3\u1da6\u0100ry\u1d9d\u1da1;\uc000\ud835\udcb9;\u4455l;\u69f6rok;\u4111\u0100dr\u1db0\u1db4ot;\u62f1i\u0100;f\u1dba\u1816\u65bf\u0100ah\u1dc0\u1dc3r\xf2\u0429a\xf2\u0fa6angle;\u69a6\u0100ci\u1dd2\u1dd5y;\u445fgrarr;\u67ff\u0900Dacdefglmnopqrstux\u1e01\u1e09\u1e19\u1e38\u0578\u1e3c\u1e49\u1e61\u1e7e\u1ea5\u1eaf\u1ebd\u1ee1\u1f2a\u1f37\u1f44\u1f4e\u1f5a\u0100Do\u1e06\u1d34o\xf4\u1c89\u0100cs\u1e0e\u1e14ute\u803b\xe9\u40e9ter;\u6a6e\u0200aioy\u1e22\u1e27\u1e31\u1e36ron;\u411br\u0100;c\u1e2d\u1e2e\u6256\u803b\xea\u40ealon;\u6255;\u444dot;\u4117\u0100Dr\u1e41\u1e45ot;\u6252;\uc000\ud835\udd22\u0180;rs\u1e50\u1e51\u1e57\u6a9aave\u803b\xe8\u40e8\u0100;d\u1e5c\u1e5d\u6a96ot;\u6a98\u0200;ils\u1e6a\u1e6b\u1e72\u1e74\u6a99nters;\u63e7;\u6113\u0100;d\u1e79\u1e7a\u6a95ot;\u6a97\u0180aps\u1e85\u1e89\u1e97cr;\u4113ty\u0180;sv\u1e92\u1e93\u1e95\u6205et\xbb\u1e93p\u01001;\u1e9d\u1ea4\u0133\u1ea1\u1ea3;\u6004;\u6005\u6003\u0100gs\u1eaa\u1eac;\u414bp;\u6002\u0100gp\u1eb4\u1eb8on;\u4119f;\uc000\ud835\udd56\u0180als\u1ec4\u1ece\u1ed2r\u0100;s\u1eca\u1ecb\u62d5l;\u69e3us;\u6a71i\u0180;lv\u1eda\u1edb\u1edf\u43b5on\xbb\u1edb;\u43f5\u0200csuv\u1eea\u1ef3\u1f0b\u1f23\u0100io\u1eef\u1e31rc\xbb\u1e2e\u0269\u1ef9\0\0\u1efb\xed\u0548ant\u0100gl\u1f02\u1f06tr\xbb\u1e5dess\xbb\u1e7a\u0180aei\u1f12\u1f16\u1f1als;\u403dst;\u625fv\u0100;D\u0235\u1f20D;\u6a78parsl;\u69e5\u0100Da\u1f2f\u1f33ot;\u6253rr;\u6971\u0180cdi\u1f3e\u1f41\u1ef8r;\u612fo\xf4\u0352\u0100ah\u1f49\u1f4b;\u43b7\u803b\xf0\u40f0\u0100mr\u1f53\u1f57l\u803b\xeb\u40ebo;\u60ac\u0180cip\u1f61\u1f64\u1f67l;\u4021s\xf4\u056e\u0100eo\u1f6c\u1f74ctatio\xee\u0559nential\xe5\u0579\u09e1\u1f92\0\u1f9e\0\u1fa1\u1fa7\0\0\u1fc6\u1fcc\0\u1fd3\0\u1fe6\u1fea\u2000\0\u2008\u205allingdotse\xf1\u1e44y;\u4444male;\u6640\u0180ilr\u1fad\u1fb3\u1fc1lig;\u8000\ufb03\u0269\u1fb9\0\0\u1fbdg;\u8000\ufb00ig;\u8000\ufb04;\uc000\ud835\udd23lig;\u8000\ufb01lig;\uc000fj\u0180alt\u1fd9\u1fdc\u1fe1t;\u666dig;\u8000\ufb02ns;\u65b1of;\u4192\u01f0\u1fee\0\u1ff3f;\uc000\ud835\udd57\u0100ak\u05bf\u1ff7\u0100;v\u1ffc\u1ffd\u62d4;\u6ad9artint;\u6a0d\u0100ao\u200c\u2055\u0100cs\u2011\u2052\u03b1\u201a\u2030\u2038\u2045\u2048\0\u2050\u03b2\u2022\u2025\u2027\u202a\u202c\0\u202e\u803b\xbd\u40bd;\u6153\u803b\xbc\u40bc;\u6155;\u6159;\u615b\u01b3\u2034\0\u2036;\u6154;\u6156\u02b4\u203e\u2041\0\0\u2043\u803b\xbe\u40be;\u6157;\u615c5;\u6158\u01b6\u204c\0\u204e;\u615a;\u615d8;\u615el;\u6044wn;\u6322cr;\uc000\ud835\udcbb\u0880Eabcdefgijlnorstv\u2082\u2089\u209f\u20a5\u20b0\u20b4\u20f0\u20f5\u20fa\u20ff\u2103\u2112\u2138\u0317\u213e\u2152\u219e\u0100;l\u064d\u2087;\u6a8c\u0180cmp\u2090\u2095\u209dute;\u41f5ma\u0100;d\u209c\u1cda\u43b3;\u6a86reve;\u411f\u0100iy\u20aa\u20aerc;\u411d;\u4433ot;\u4121\u0200;lqs\u063e\u0642\u20bd\u20c9\u0180;qs\u063e\u064c\u20c4lan\xf4\u0665\u0200;cdl\u0665\u20d2\u20d5\u20e5c;\u6aa9ot\u0100;o\u20dc\u20dd\u6a80\u0100;l\u20e2\u20e3\u6a82;\u6a84\u0100;e\u20ea\u20ed\uc000\u22db\ufe00s;\u6a94r;\uc000\ud835\udd24\u0100;g\u0673\u061bmel;\u6137cy;\u4453\u0200;Eaj\u065a\u210c\u210e\u2110;\u6a92;\u6aa5;\u6aa4\u0200Eaes\u211b\u211d\u2129\u2134;\u6269p\u0100;p\u2123\u2124\u6a8arox\xbb\u2124\u0100;q\u212e\u212f\u6a88\u0100;q\u212e\u211bim;\u62e7pf;\uc000\ud835\udd58\u0100ci\u2143\u2146r;\u610am\u0180;el\u066b\u214e\u2150;\u6a8e;\u6a90\u8300>;cdlqr\u05ee\u2160\u216a\u216e\u2173\u2179\u0100ci\u2165\u2167;\u6aa7r;\u6a7aot;\u62d7Par;\u6995uest;\u6a7c\u0280adels\u2184\u216a\u2190\u0656\u219b\u01f0\u2189\0\u218epro\xf8\u209er;\u6978q\u0100lq\u063f\u2196les\xf3\u2088i\xed\u066b\u0100en\u21a3\u21adrtneqq;\uc000\u2269\ufe00\xc5\u21aa\u0500Aabcefkosy\u21c4\u21c7\u21f1\u21f5\u21fa\u2218\u221d\u222f\u2268\u227dr\xf2\u03a0\u0200ilmr\u21d0\u21d4\u21d7\u21dbrs\xf0\u1484f\xbb\u2024il\xf4\u06a9\u0100dr\u21e0\u21e4cy;\u444a\u0180;cw\u08f4\u21eb\u21efir;\u6948;\u61adar;\u610firc;\u4125\u0180alr\u2201\u220e\u2213rts\u0100;u\u2209\u220a\u6665it\xbb\u220alip;\u6026con;\u62b9r;\uc000\ud835\udd25s\u0100ew\u2223\u2229arow;\u6925arow;\u6926\u0280amopr\u223a\u223e\u2243\u225e\u2263rr;\u61fftht;\u623bk\u0100lr\u2249\u2253eftarrow;\u61a9ightarrow;\u61aaf;\uc000\ud835\udd59bar;\u6015\u0180clt\u226f\u2274\u2278r;\uc000\ud835\udcbdas\xe8\u21f4rok;\u4127\u0100bp\u2282\u2287ull;\u6043hen\xbb\u1c5b\u0ae1\u22a3\0\u22aa\0\u22b8\u22c5\u22ce\0\u22d5\u22f3\0\0\u22f8\u2322\u2367\u2362\u237f\0\u2386\u23aa\u23b4cute\u803b\xed\u40ed\u0180;iy\u0771\u22b0\u22b5rc\u803b\xee\u40ee;\u4438\u0100cx\u22bc\u22bfy;\u4435cl\u803b\xa1\u40a1\u0100fr\u039f\u22c9;\uc000\ud835\udd26rave\u803b\xec\u40ec\u0200;ino\u073e\u22dd\u22e9\u22ee\u0100in\u22e2\u22e6nt;\u6a0ct;\u622dfin;\u69dcta;\u6129lig;\u4133\u0180aop\u22fe\u231a\u231d\u0180cgt\u2305\u2308\u2317r;\u412b\u0180elp\u071f\u230f\u2313in\xe5\u078ear\xf4\u0720h;\u4131f;\u62b7ed;\u41b5\u0280;cfot\u04f4\u232c\u2331\u233d\u2341are;\u6105in\u0100;t\u2338\u2339\u621eie;\u69dddo\xf4\u2319\u0280;celp\u0757\u234c\u2350\u235b\u2361al;\u62ba\u0100gr\u2355\u2359er\xf3\u1563\xe3\u234darhk;\u6a17rod;\u6a3c\u0200cgpt\u236f\u2372\u2376\u237by;\u4451on;\u412ff;\uc000\ud835\udd5aa;\u43b9uest\u803b\xbf\u40bf\u0100ci\u238a\u238fr;\uc000\ud835\udcben\u0280;Edsv\u04f4\u239b\u239d\u23a1\u04f3;\u62f9ot;\u62f5\u0100;v\u23a6\u23a7\u62f4;\u62f3\u0100;i\u0777\u23aelde;\u4129\u01eb\u23b8\0\u23bccy;\u4456l\u803b\xef\u40ef\u0300cfmosu\u23cc\u23d7\u23dc\u23e1\u23e7\u23f5\u0100iy\u23d1\u23d5rc;\u4135;\u4439r;\uc000\ud835\udd27ath;\u4237pf;\uc000\ud835\udd5b\u01e3\u23ec\0\u23f1r;\uc000\ud835\udcbfrcy;\u4458kcy;\u4454\u0400acfghjos\u240b\u2416\u2422\u2427\u242d\u2431\u2435\u243bppa\u0100;v\u2413\u2414\u43ba;\u43f0\u0100ey\u241b\u2420dil;\u4137;\u443ar;\uc000\ud835\udd28reen;\u4138cy;\u4445cy;\u445cpf;\uc000\ud835\udd5ccr;\uc000\ud835\udcc0\u0b80ABEHabcdefghjlmnoprstuv\u2470\u2481\u2486\u248d\u2491\u250e\u253d\u255a\u2580\u264e\u265e\u2665\u2679\u267d\u269a\u26b2\u26d8\u275d\u2768\u278b\u27c0\u2801\u2812\u0180art\u2477\u247a\u247cr\xf2\u09c6\xf2\u0395ail;\u691barr;\u690e\u0100;g\u0994\u248b;\u6a8bar;\u6962\u0963\u24a5\0\u24aa\0\u24b1\0\0\0\0\0\u24b5\u24ba\0\u24c6\u24c8\u24cd\0\u24f9ute;\u413amptyv;\u69b4ra\xee\u084cbda;\u43bbg\u0180;dl\u088e\u24c1\u24c3;\u6991\xe5\u088e;\u6a85uo\u803b\xab\u40abr\u0400;bfhlpst\u0899\u24de\u24e6\u24e9\u24eb\u24ee\u24f1\u24f5\u0100;f\u089d\u24e3s;\u691fs;\u691d\xeb\u2252p;\u61abl;\u6939im;\u6973l;\u61a2\u0180;ae\u24ff\u2500\u2504\u6aabil;\u6919\u0100;s\u2509\u250a\u6aad;\uc000\u2aad\ufe00\u0180abr\u2515\u2519\u251drr;\u690crk;\u6772\u0100ak\u2522\u252cc\u0100ek\u2528\u252a;\u407b;\u405b\u0100es\u2531\u2533;\u698bl\u0100du\u2539\u253b;\u698f;\u698d\u0200aeuy\u2546\u254b\u2556\u2558ron;\u413e\u0100di\u2550\u2554il;\u413c\xec\u08b0\xe2\u2529;\u443b\u0200cqrs\u2563\u2566\u256d\u257da;\u6936uo\u0100;r\u0e19\u1746\u0100du\u2572\u2577har;\u6967shar;\u694bh;\u61b2\u0280;fgqs\u258b\u258c\u0989\u25f3\u25ff\u6264t\u0280ahlrt\u2598\u25a4\u25b7\u25c2\u25e8rrow\u0100;t\u0899\u25a1a\xe9\u24f6arpoon\u0100du\u25af\u25b4own\xbb\u045ap\xbb\u0966eftarrows;\u61c7ight\u0180ahs\u25cd\u25d6\u25derrow\u0100;s\u08f4\u08a7arpoon\xf3\u0f98quigarro\xf7\u21f0hreetimes;\u62cb\u0180;qs\u258b\u0993\u25falan\xf4\u09ac\u0280;cdgs\u09ac\u260a\u260d\u261d\u2628c;\u6aa8ot\u0100;o\u2614\u2615\u6a7f\u0100;r\u261a\u261b\u6a81;\u6a83\u0100;e\u2622\u2625\uc000\u22da\ufe00s;\u6a93\u0280adegs\u2633\u2639\u263d\u2649\u264bppro\xf8\u24c6ot;\u62d6q\u0100gq\u2643\u2645\xf4\u0989gt\xf2\u248c\xf4\u099bi\xed\u09b2\u0180ilr\u2655\u08e1\u265asht;\u697c;\uc000\ud835\udd29\u0100;E\u099c\u2663;\u6a91\u0161\u2669\u2676r\u0100du\u25b2\u266e\u0100;l\u0965\u2673;\u696alk;\u6584cy;\u4459\u0280;acht\u0a48\u2688\u268b\u2691\u2696r\xf2\u25c1orne\xf2\u1d08ard;\u696bri;\u65fa\u0100io\u269f\u26a4dot;\u4140ust\u0100;a\u26ac\u26ad\u63b0che\xbb\u26ad\u0200Eaes\u26bb\u26bd\u26c9\u26d4;\u6268p\u0100;p\u26c3\u26c4\u6a89rox\xbb\u26c4\u0100;q\u26ce\u26cf\u6a87\u0100;q\u26ce\u26bbim;\u62e6\u0400abnoptwz\u26e9\u26f4\u26f7\u271a\u272f\u2741\u2747\u2750\u0100nr\u26ee\u26f1g;\u67ecr;\u61fdr\xeb\u08c1g\u0180lmr\u26ff\u270d\u2714eft\u0100ar\u09e6\u2707ight\xe1\u09f2apsto;\u67fcight\xe1\u09fdparrow\u0100lr\u2725\u2729ef\xf4\u24edight;\u61ac\u0180afl\u2736\u2739\u273dr;\u6985;\uc000\ud835\udd5dus;\u6a2dimes;\u6a34\u0161\u274b\u274fst;\u6217\xe1\u134e\u0180;ef\u2757\u2758\u1800\u65cange\xbb\u2758ar\u0100;l\u2764\u2765\u4028t;\u6993\u0280achmt\u2773\u2776\u277c\u2785\u2787r\xf2\u08a8orne\xf2\u1d8car\u0100;d\u0f98\u2783;\u696d;\u600eri;\u62bf\u0300achiqt\u2798\u279d\u0a40\u27a2\u27ae\u27bbquo;\u6039r;\uc000\ud835\udcc1m\u0180;eg\u09b2\u27aa\u27ac;\u6a8d;\u6a8f\u0100bu\u252a\u27b3o\u0100;r\u0e1f\u27b9;\u601arok;\u4142\u8400<;cdhilqr\u082b\u27d2\u2639\u27dc\u27e0\u27e5\u27ea\u27f0\u0100ci\u27d7\u27d9;\u6aa6r;\u6a79re\xe5\u25f2mes;\u62c9arr;\u6976uest;\u6a7b\u0100Pi\u27f5\u27f9ar;\u6996\u0180;ef\u2800\u092d\u181b\u65c3r\u0100du\u2807\u280dshar;\u694ahar;\u6966\u0100en\u2817\u2821rtneqq;\uc000\u2268\ufe00\xc5\u281e\u0700Dacdefhilnopsu\u2840\u2845\u2882\u288e\u2893\u28a0\u28a5\u28a8\u28da\u28e2\u28e4\u0a83\u28f3\u2902Dot;\u623a\u0200clpr\u284e\u2852\u2863\u287dr\u803b\xaf\u40af\u0100et\u2857\u2859;\u6642\u0100;e\u285e\u285f\u6720se\xbb\u285f\u0100;s\u103b\u2868to\u0200;dlu\u103b\u2873\u2877\u287bow\xee\u048cef\xf4\u090f\xf0\u13d1ker;\u65ae\u0100oy\u2887\u288cmma;\u6a29;\u443cash;\u6014asuredangle\xbb\u1626r;\uc000\ud835\udd2ao;\u6127\u0180cdn\u28af\u28b4\u28c9ro\u803b\xb5\u40b5\u0200;acd\u1464\u28bd\u28c0\u28c4s\xf4\u16a7ir;\u6af0ot\u80bb\xb7\u01b5us\u0180;bd\u28d2\u1903\u28d3\u6212\u0100;u\u1d3c\u28d8;\u6a2a\u0163\u28de\u28e1p;\u6adb\xf2\u2212\xf0\u0a81\u0100dp\u28e9\u28eeels;\u62a7f;\uc000\ud835\udd5e\u0100ct\u28f8\u28fdr;\uc000\ud835\udcc2pos\xbb\u159d\u0180;lm\u2909\u290a\u290d\u43bctimap;\u62b8\u0c00GLRVabcdefghijlmoprstuvw\u2942\u2953\u297e\u2989\u2998\u29da\u29e9\u2a15\u2a1a\u2a58\u2a5d\u2a83\u2a95\u2aa4\u2aa8\u2b04\u2b07\u2b44\u2b7f\u2bae\u2c34\u2c67\u2c7c\u2ce9\u0100gt\u2947\u294b;\uc000\u22d9\u0338\u0100;v\u2950\u0bcf\uc000\u226b\u20d2\u0180elt\u295a\u2972\u2976ft\u0100ar\u2961\u2967rrow;\u61cdightarrow;\u61ce;\uc000\u22d8\u0338\u0100;v\u297b\u0c47\uc000\u226a\u20d2ightarrow;\u61cf\u0100Dd\u298e\u2993ash;\u62afash;\u62ae\u0280bcnpt\u29a3\u29a7\u29ac\u29b1\u29ccla\xbb\u02deute;\u4144g;\uc000\u2220\u20d2\u0280;Eiop\u0d84\u29bc\u29c0\u29c5\u29c8;\uc000\u2a70\u0338d;\uc000\u224b\u0338s;\u4149ro\xf8\u0d84ur\u0100;a\u29d3\u29d4\u666el\u0100;s\u29d3\u0b38\u01f3\u29df\0\u29e3p\u80bb\xa0\u0b37mp\u0100;e\u0bf9\u0c00\u0280aeouy\u29f4\u29fe\u2a03\u2a10\u2a13\u01f0\u29f9\0\u29fb;\u6a43on;\u4148dil;\u4146ng\u0100;d\u0d7e\u2a0aot;\uc000\u2a6d\u0338p;\u6a42;\u443dash;\u6013\u0380;Aadqsx\u0b92\u2a29\u2a2d\u2a3b\u2a41\u2a45\u2a50rr;\u61d7r\u0100hr\u2a33\u2a36k;\u6924\u0100;o\u13f2\u13f0ot;\uc000\u2250\u0338ui\xf6\u0b63\u0100ei\u2a4a\u2a4ear;\u6928\xed\u0b98ist\u0100;s\u0ba0\u0b9fr;\uc000\ud835\udd2b\u0200Eest\u0bc5\u2a66\u2a79\u2a7c\u0180;qs\u0bbc\u2a6d\u0be1\u0180;qs\u0bbc\u0bc5\u2a74lan\xf4\u0be2i\xed\u0bea\u0100;r\u0bb6\u2a81\xbb\u0bb7\u0180Aap\u2a8a\u2a8d\u2a91r\xf2\u2971rr;\u61aear;\u6af2\u0180;sv\u0f8d\u2a9c\u0f8c\u0100;d\u2aa1\u2aa2\u62fc;\u62facy;\u445a\u0380AEadest\u2ab7\u2aba\u2abe\u2ac2\u2ac5\u2af6\u2af9r\xf2\u2966;\uc000\u2266\u0338rr;\u619ar;\u6025\u0200;fqs\u0c3b\u2ace\u2ae3\u2aeft\u0100ar\u2ad4\u2ad9rro\xf7\u2ac1ightarro\xf7\u2a90\u0180;qs\u0c3b\u2aba\u2aealan\xf4\u0c55\u0100;s\u0c55\u2af4\xbb\u0c36i\xed\u0c5d\u0100;r\u0c35\u2afei\u0100;e\u0c1a\u0c25i\xe4\u0d90\u0100pt\u2b0c\u2b11f;\uc000\ud835\udd5f\u8180\xac;in\u2b19\u2b1a\u2b36\u40acn\u0200;Edv\u0b89\u2b24\u2b28\u2b2e;\uc000\u22f9\u0338ot;\uc000\u22f5\u0338\u01e1\u0b89\u2b33\u2b35;\u62f7;\u62f6i\u0100;v\u0cb8\u2b3c\u01e1\u0cb8\u2b41\u2b43;\u62fe;\u62fd\u0180aor\u2b4b\u2b63\u2b69r\u0200;ast\u0b7b\u2b55\u2b5a\u2b5flle\xec\u0b7bl;\uc000\u2afd\u20e5;\uc000\u2202\u0338lint;\u6a14\u0180;ce\u0c92\u2b70\u2b73u\xe5\u0ca5\u0100;c\u0c98\u2b78\u0100;e\u0c92\u2b7d\xf1\u0c98\u0200Aait\u2b88\u2b8b\u2b9d\u2ba7r\xf2\u2988rr\u0180;cw\u2b94\u2b95\u2b99\u619b;\uc000\u2933\u0338;\uc000\u219d\u0338ghtarrow\xbb\u2b95ri\u0100;e\u0ccb\u0cd6\u0380chimpqu\u2bbd\u2bcd\u2bd9\u2b04\u0b78\u2be4\u2bef\u0200;cer\u0d32\u2bc6\u0d37\u2bc9u\xe5\u0d45;\uc000\ud835\udcc3ort\u026d\u2b05\0\0\u2bd6ar\xe1\u2b56m\u0100;e\u0d6e\u2bdf\u0100;q\u0d74\u0d73su\u0100bp\u2beb\u2bed\xe5\u0cf8\xe5\u0d0b\u0180bcp\u2bf6\u2c11\u2c19\u0200;Ees\u2bff\u2c00\u0d22\u2c04\u6284;\uc000\u2ac5\u0338et\u0100;e\u0d1b\u2c0bq\u0100;q\u0d23\u2c00c\u0100;e\u0d32\u2c17\xf1\u0d38\u0200;Ees\u2c22\u2c23\u0d5f\u2c27\u6285;\uc000\u2ac6\u0338et\u0100;e\u0d58\u2c2eq\u0100;q\u0d60\u2c23\u0200gilr\u2c3d\u2c3f\u2c45\u2c47\xec\u0bd7lde\u803b\xf1\u40f1\xe7\u0c43iangle\u0100lr\u2c52\u2c5ceft\u0100;e\u0c1a\u2c5a\xf1\u0c26ight\u0100;e\u0ccb\u2c65\xf1\u0cd7\u0100;m\u2c6c\u2c6d\u43bd\u0180;es\u2c74\u2c75\u2c79\u4023ro;\u6116p;\u6007\u0480DHadgilrs\u2c8f\u2c94\u2c99\u2c9e\u2ca3\u2cb0\u2cb6\u2cd3\u2ce3ash;\u62adarr;\u6904p;\uc000\u224d\u20d2ash;\u62ac\u0100et\u2ca8\u2cac;\uc000\u2265\u20d2;\uc000>\u20d2nfin;\u69de\u0180Aet\u2cbd\u2cc1\u2cc5rr;\u6902;\uc000\u2264\u20d2\u0100;r\u2cca\u2ccd\uc000<\u20d2ie;\uc000\u22b4\u20d2\u0100At\u2cd8\u2cdcrr;\u6903rie;\uc000\u22b5\u20d2im;\uc000\u223c\u20d2\u0180Aan\u2cf0\u2cf4\u2d02rr;\u61d6r\u0100hr\u2cfa\u2cfdk;\u6923\u0100;o\u13e7\u13e5ear;\u6927\u1253\u1a95\0\0\0\0\0\0\0\0\0\0\0\0\0\u2d2d\0\u2d38\u2d48\u2d60\u2d65\u2d72\u2d84\u1b07\0\0\u2d8d\u2dab\0\u2dc8\u2dce\0\u2ddc\u2e19\u2e2b\u2e3e\u2e43\u0100cs\u2d31\u1a97ute\u803b\xf3\u40f3\u0100iy\u2d3c\u2d45r\u0100;c\u1a9e\u2d42\u803b\xf4\u40f4;\u443e\u0280abios\u1aa0\u2d52\u2d57\u01c8\u2d5alac;\u4151v;\u6a38old;\u69bclig;\u4153\u0100cr\u2d69\u2d6dir;\u69bf;\uc000\ud835\udd2c\u036f\u2d79\0\0\u2d7c\0\u2d82n;\u42dbave\u803b\xf2\u40f2;\u69c1\u0100bm\u2d88\u0df4ar;\u69b5\u0200acit\u2d95\u2d98\u2da5\u2da8r\xf2\u1a80\u0100ir\u2d9d\u2da0r;\u69beoss;\u69bbn\xe5\u0e52;\u69c0\u0180aei\u2db1\u2db5\u2db9cr;\u414dga;\u43c9\u0180cdn\u2dc0\u2dc5\u01cdron;\u43bf;\u69b6pf;\uc000\ud835\udd60\u0180ael\u2dd4\u2dd7\u01d2r;\u69b7rp;\u69b9\u0380;adiosv\u2dea\u2deb\u2dee\u2e08\u2e0d\u2e10\u2e16\u6228r\xf2\u1a86\u0200;efm\u2df7\u2df8\u2e02\u2e05\u6a5dr\u0100;o\u2dfe\u2dff\u6134f\xbb\u2dff\u803b\xaa\u40aa\u803b\xba\u40bagof;\u62b6r;\u6a56lope;\u6a57;\u6a5b\u0180clo\u2e1f\u2e21\u2e27\xf2\u2e01ash\u803b\xf8\u40f8l;\u6298i\u016c\u2e2f\u2e34de\u803b\xf5\u40f5es\u0100;a\u01db\u2e3as;\u6a36ml\u803b\xf6\u40f6bar;\u633d\u0ae1\u2e5e\0\u2e7d\0\u2e80\u2e9d\0\u2ea2\u2eb9\0\0\u2ecb\u0e9c\0\u2f13\0\0\u2f2b\u2fbc\0\u2fc8r\u0200;ast\u0403\u2e67\u2e72\u0e85\u8100\xb6;l\u2e6d\u2e6e\u40b6le\xec\u0403\u0269\u2e78\0\0\u2e7bm;\u6af3;\u6afdy;\u443fr\u0280cimpt\u2e8b\u2e8f\u2e93\u1865\u2e97nt;\u4025od;\u402eil;\u6030enk;\u6031r;\uc000\ud835\udd2d\u0180imo\u2ea8\u2eb0\u2eb4\u0100;v\u2ead\u2eae\u43c6;\u43d5ma\xf4\u0a76ne;\u660e\u0180;tv\u2ebf\u2ec0\u2ec8\u43c0chfork\xbb\u1ffd;\u43d6\u0100au\u2ecf\u2edfn\u0100ck\u2ed5\u2eddk\u0100;h\u21f4\u2edb;\u610e\xf6\u21f4s\u0480;abcdemst\u2ef3\u2ef4\u1908\u2ef9\u2efd\u2f04\u2f06\u2f0a\u2f0e\u402bcir;\u6a23ir;\u6a22\u0100ou\u1d40\u2f02;\u6a25;\u6a72n\u80bb\xb1\u0e9dim;\u6a26wo;\u6a27\u0180ipu\u2f19\u2f20\u2f25ntint;\u6a15f;\uc000\ud835\udd61nd\u803b\xa3\u40a3\u0500;Eaceinosu\u0ec8\u2f3f\u2f41\u2f44\u2f47\u2f81\u2f89\u2f92\u2f7e\u2fb6;\u6ab3p;\u6ab7u\xe5\u0ed9\u0100;c\u0ece\u2f4c\u0300;acens\u0ec8\u2f59\u2f5f\u2f66\u2f68\u2f7eppro\xf8\u2f43urlye\xf1\u0ed9\xf1\u0ece\u0180aes\u2f6f\u2f76\u2f7approx;\u6ab9qq;\u6ab5im;\u62e8i\xed\u0edfme\u0100;s\u2f88\u0eae\u6032\u0180Eas\u2f78\u2f90\u2f7a\xf0\u2f75\u0180dfp\u0eec\u2f99\u2faf\u0180als\u2fa0\u2fa5\u2faalar;\u632eine;\u6312urf;\u6313\u0100;t\u0efb\u2fb4\xef\u0efbrel;\u62b0\u0100ci\u2fc0\u2fc5r;\uc000\ud835\udcc5;\u43c8ncsp;\u6008\u0300fiopsu\u2fda\u22e2\u2fdf\u2fe5\u2feb\u2ff1r;\uc000\ud835\udd2epf;\uc000\ud835\udd62rime;\u6057cr;\uc000\ud835\udcc6\u0180aeo\u2ff8\u3009\u3013t\u0100ei\u2ffe\u3005rnion\xf3\u06b0nt;\u6a16st\u0100;e\u3010\u3011\u403f\xf1\u1f19\xf4\u0f14\u0a80ABHabcdefhilmnoprstux\u3040\u3051\u3055\u3059\u30e0\u310e\u312b\u3147\u3162\u3172\u318e\u3206\u3215\u3224\u3229\u3258\u326e\u3272\u3290\u32b0\u32b7\u0180art\u3047\u304a\u304cr\xf2\u10b3\xf2\u03ddail;\u691car\xf2\u1c65ar;\u6964\u0380cdenqrt\u3068\u3075\u3078\u307f\u308f\u3094\u30cc\u0100eu\u306d\u3071;\uc000\u223d\u0331te;\u4155i\xe3\u116emptyv;\u69b3g\u0200;del\u0fd1\u3089\u308b\u308d;\u6992;\u69a5\xe5\u0fd1uo\u803b\xbb\u40bbr\u0580;abcfhlpstw\u0fdc\u30ac\u30af\u30b7\u30b9\u30bc\u30be\u30c0\u30c3\u30c7\u30cap;\u6975\u0100;f\u0fe0\u30b4s;\u6920;\u6933s;\u691e\xeb\u225d\xf0\u272el;\u6945im;\u6974l;\u61a3;\u619d\u0100ai\u30d1\u30d5il;\u691ao\u0100;n\u30db\u30dc\u6236al\xf3\u0f1e\u0180abr\u30e7\u30ea\u30eer\xf2\u17e5rk;\u6773\u0100ak\u30f3\u30fdc\u0100ek\u30f9\u30fb;\u407d;\u405d\u0100es\u3102\u3104;\u698cl\u0100du\u310a\u310c;\u698e;\u6990\u0200aeuy\u3117\u311c\u3127\u3129ron;\u4159\u0100di\u3121\u3125il;\u4157\xec\u0ff2\xe2\u30fa;\u4440\u0200clqs\u3134\u3137\u313d\u3144a;\u6937dhar;\u6969uo\u0100;r\u020e\u020dh;\u61b3\u0180acg\u314e\u315f\u0f44l\u0200;ips\u0f78\u3158\u315b\u109cn\xe5\u10bbar\xf4\u0fa9t;\u65ad\u0180ilr\u3169\u1023\u316esht;\u697d;\uc000\ud835\udd2f\u0100ao\u3177\u3186r\u0100du\u317d\u317f\xbb\u047b\u0100;l\u1091\u3184;\u696c\u0100;v\u318b\u318c\u43c1;\u43f1\u0180gns\u3195\u31f9\u31fcht\u0300ahlrst\u31a4\u31b0\u31c2\u31d8\u31e4\u31eerrow\u0100;t\u0fdc\u31ada\xe9\u30c8arpoon\u0100du\u31bb\u31bfow\xee\u317ep\xbb\u1092eft\u0100ah\u31ca\u31d0rrow\xf3\u0feaarpoon\xf3\u0551ightarrows;\u61c9quigarro\xf7\u30cbhreetimes;\u62ccg;\u42daingdotse\xf1\u1f32\u0180ahm\u320d\u3210\u3213r\xf2\u0feaa\xf2\u0551;\u600foust\u0100;a\u321e\u321f\u63b1che\xbb\u321fmid;\u6aee\u0200abpt\u3232\u323d\u3240\u3252\u0100nr\u3237\u323ag;\u67edr;\u61fer\xeb\u1003\u0180afl\u3247\u324a\u324er;\u6986;\uc000\ud835\udd63us;\u6a2eimes;\u6a35\u0100ap\u325d\u3267r\u0100;g\u3263\u3264\u4029t;\u6994olint;\u6a12ar\xf2\u31e3\u0200achq\u327b\u3280\u10bc\u3285quo;\u603ar;\uc000\ud835\udcc7\u0100bu\u30fb\u328ao\u0100;r\u0214\u0213\u0180hir\u3297\u329b\u32a0re\xe5\u31f8mes;\u62cai\u0200;efl\u32aa\u1059\u1821\u32ab\u65b9tri;\u69celuhar;\u6968;\u611e\u0d61\u32d5\u32db\u32df\u332c\u3338\u3371\0\u337a\u33a4\0\0\u33ec\u33f0\0\u3428\u3448\u345a\u34ad\u34b1\u34ca\u34f1\0\u3616\0\0\u3633cute;\u415bqu\xef\u27ba\u0500;Eaceinpsy\u11ed\u32f3\u32f5\u32ff\u3302\u330b\u330f\u331f\u3326\u3329;\u6ab4\u01f0\u32fa\0\u32fc;\u6ab8on;\u4161u\xe5\u11fe\u0100;d\u11f3\u3307il;\u415frc;\u415d\u0180Eas\u3316\u3318\u331b;\u6ab6p;\u6abaim;\u62e9olint;\u6a13i\xed\u1204;\u4441ot\u0180;be\u3334\u1d47\u3335\u62c5;\u6a66\u0380Aacmstx\u3346\u334a\u3357\u335b\u335e\u3363\u336drr;\u61d8r\u0100hr\u3350\u3352\xeb\u2228\u0100;o\u0a36\u0a34t\u803b\xa7\u40a7i;\u403bwar;\u6929m\u0100in\u3369\xf0nu\xf3\xf1t;\u6736r\u0100;o\u3376\u2055\uc000\ud835\udd30\u0200acoy\u3382\u3386\u3391\u33a0rp;\u666f\u0100hy\u338b\u338fcy;\u4449;\u4448rt\u026d\u3399\0\0\u339ci\xe4\u1464ara\xec\u2e6f\u803b\xad\u40ad\u0100gm\u33a8\u33b4ma\u0180;fv\u33b1\u33b2\u33b2\u43c3;\u43c2\u0400;deglnpr\u12ab\u33c5\u33c9\u33ce\u33d6\u33de\u33e1\u33e6ot;\u6a6a\u0100;q\u12b1\u12b0\u0100;E\u33d3\u33d4\u6a9e;\u6aa0\u0100;E\u33db\u33dc\u6a9d;\u6a9fe;\u6246lus;\u6a24arr;\u6972ar\xf2\u113d\u0200aeit\u33f8\u3408\u340f\u3417\u0100ls\u33fd\u3404lsetm\xe9\u336ahp;\u6a33parsl;\u69e4\u0100dl\u1463\u3414e;\u6323\u0100;e\u341c\u341d\u6aaa\u0100;s\u3422\u3423\u6aac;\uc000\u2aac\ufe00\u0180flp\u342e\u3433\u3442tcy;\u444c\u0100;b\u3438\u3439\u402f\u0100;a\u343e\u343f\u69c4r;\u633ff;\uc000\ud835\udd64a\u0100dr\u344d\u0402es\u0100;u\u3454\u3455\u6660it\xbb\u3455\u0180csu\u3460\u3479\u349f\u0100au\u3465\u346fp\u0100;s\u1188\u346b;\uc000\u2293\ufe00p\u0100;s\u11b4\u3475;\uc000\u2294\ufe00u\u0100bp\u347f\u348f\u0180;es\u1197\u119c\u3486et\u0100;e\u1197\u348d\xf1\u119d\u0180;es\u11a8\u11ad\u3496et\u0100;e\u11a8\u349d\xf1\u11ae\u0180;af\u117b\u34a6\u05b0r\u0165\u34ab\u05b1\xbb\u117car\xf2\u1148\u0200cemt\u34b9\u34be\u34c2\u34c5r;\uc000\ud835\udcc8tm\xee\xf1i\xec\u3415ar\xe6\u11be\u0100ar\u34ce\u34d5r\u0100;f\u34d4\u17bf\u6606\u0100an\u34da\u34edight\u0100ep\u34e3\u34eapsilo\xee\u1ee0h\xe9\u2eafs\xbb\u2852\u0280bcmnp\u34fb\u355e\u1209\u358b\u358e\u0480;Edemnprs\u350e\u350f\u3511\u3515\u351e\u3523\u352c\u3531\u3536\u6282;\u6ac5ot;\u6abd\u0100;d\u11da\u351aot;\u6ac3ult;\u6ac1\u0100Ee\u3528\u352a;\u6acb;\u628alus;\u6abfarr;\u6979\u0180eiu\u353d\u3552\u3555t\u0180;en\u350e\u3545\u354bq\u0100;q\u11da\u350feq\u0100;q\u352b\u3528m;\u6ac7\u0100bp\u355a\u355c;\u6ad5;\u6ad3c\u0300;acens\u11ed\u356c\u3572\u3579\u357b\u3326ppro\xf8\u32faurlye\xf1\u11fe\xf1\u11f3\u0180aes\u3582\u3588\u331bppro\xf8\u331aq\xf1\u3317g;\u666a\u0680123;Edehlmnps\u35a9\u35ac\u35af\u121c\u35b2\u35b4\u35c0\u35c9\u35d5\u35da\u35df\u35e8\u35ed\u803b\xb9\u40b9\u803b\xb2\u40b2\u803b\xb3\u40b3;\u6ac6\u0100os\u35b9\u35bct;\u6abeub;\u6ad8\u0100;d\u1222\u35c5ot;\u6ac4s\u0100ou\u35cf\u35d2l;\u67c9b;\u6ad7arr;\u697bult;\u6ac2\u0100Ee\u35e4\u35e6;\u6acc;\u628blus;\u6ac0\u0180eiu\u35f4\u3609\u360ct\u0180;en\u121c\u35fc\u3602q\u0100;q\u1222\u35b2eq\u0100;q\u35e7\u35e4m;\u6ac8\u0100bp\u3611\u3613;\u6ad4;\u6ad6\u0180Aan\u361c\u3620\u362drr;\u61d9r\u0100hr\u3626\u3628\xeb\u222e\u0100;o\u0a2b\u0a29war;\u692alig\u803b\xdf\u40df\u0be1\u3651\u365d\u3660\u12ce\u3673\u3679\0\u367e\u36c2\0\0\0\0\0\u36db\u3703\0\u3709\u376c\0\0\0\u3787\u0272\u3656\0\0\u365bget;\u6316;\u43c4r\xeb\u0e5f\u0180aey\u3666\u366b\u3670ron;\u4165dil;\u4163;\u4442lrec;\u6315r;\uc000\ud835\udd31\u0200eiko\u3686\u369d\u36b5\u36bc\u01f2\u368b\0\u3691e\u01004f\u1284\u1281a\u0180;sv\u3698\u3699\u369b\u43b8ym;\u43d1\u0100cn\u36a2\u36b2k\u0100as\u36a8\u36aeppro\xf8\u12c1im\xbb\u12acs\xf0\u129e\u0100as\u36ba\u36ae\xf0\u12c1rn\u803b\xfe\u40fe\u01ec\u031f\u36c6\u22e7es\u8180\xd7;bd\u36cf\u36d0\u36d8\u40d7\u0100;a\u190f\u36d5r;\u6a31;\u6a30\u0180eps\u36e1\u36e3\u3700\xe1\u2a4d\u0200;bcf\u0486\u36ec\u36f0\u36f4ot;\u6336ir;\u6af1\u0100;o\u36f9\u36fc\uc000\ud835\udd65rk;\u6ada\xe1\u3362rime;\u6034\u0180aip\u370f\u3712\u3764d\xe5\u1248\u0380adempst\u3721\u374d\u3740\u3751\u3757\u375c\u375fngle\u0280;dlqr\u3730\u3731\u3736\u3740\u3742\u65b5own\xbb\u1dbbeft\u0100;e\u2800\u373e\xf1\u092e;\u625cight\u0100;e\u32aa\u374b\xf1\u105aot;\u65ecinus;\u6a3alus;\u6a39b;\u69cdime;\u6a3bezium;\u63e2\u0180cht\u3772\u377d\u3781\u0100ry\u3777\u377b;\uc000\ud835\udcc9;\u4446cy;\u445brok;\u4167\u0100io\u378b\u378ex\xf4\u1777head\u0100lr\u3797\u37a0eftarro\xf7\u084fightarrow\xbb\u0f5d\u0900AHabcdfghlmoprstuw\u37d0\u37d3\u37d7\u37e4\u37f0\u37fc\u380e\u381c\u3823\u3834\u3851\u385d\u386b\u38a9\u38cc\u38d2\u38ea\u38f6r\xf2\u03edar;\u6963\u0100cr\u37dc\u37e2ute\u803b\xfa\u40fa\xf2\u1150r\u01e3\u37ea\0\u37edy;\u445eve;\u416d\u0100iy\u37f5\u37farc\u803b\xfb\u40fb;\u4443\u0180abh\u3803\u3806\u380br\xf2\u13adlac;\u4171a\xf2\u13c3\u0100ir\u3813\u3818sht;\u697e;\uc000\ud835\udd32rave\u803b\xf9\u40f9\u0161\u3827\u3831r\u0100lr\u382c\u382e\xbb\u0957\xbb\u1083lk;\u6580\u0100ct\u3839\u384d\u026f\u383f\0\0\u384arn\u0100;e\u3845\u3846\u631cr\xbb\u3846op;\u630fri;\u65f8\u0100al\u3856\u385acr;\u416b\u80bb\xa8\u0349\u0100gp\u3862\u3866on;\u4173f;\uc000\ud835\udd66\u0300adhlsu\u114b\u3878\u387d\u1372\u3891\u38a0own\xe1\u13b3arpoon\u0100lr\u3888\u388cef\xf4\u382digh\xf4\u382fi\u0180;hl\u3899\u389a\u389c\u43c5\xbb\u13faon\xbb\u389aparrows;\u61c8\u0180cit\u38b0\u38c4\u38c8\u026f\u38b6\0\0\u38c1rn\u0100;e\u38bc\u38bd\u631dr\xbb\u38bdop;\u630eng;\u416fri;\u65f9cr;\uc000\ud835\udcca\u0180dir\u38d9\u38dd\u38e2ot;\u62f0lde;\u4169i\u0100;f\u3730\u38e8\xbb\u1813\u0100am\u38ef\u38f2r\xf2\u38a8l\u803b\xfc\u40fcangle;\u69a7\u0780ABDacdeflnoprsz\u391c\u391f\u3929\u392d\u39b5\u39b8\u39bd\u39df\u39e4\u39e8\u39f3\u39f9\u39fd\u3a01\u3a20r\xf2\u03f7ar\u0100;v\u3926\u3927\u6ae8;\u6ae9as\xe8\u03e1\u0100nr\u3932\u3937grt;\u699c\u0380eknprst\u34e3\u3946\u394b\u3952\u395d\u3964\u3996app\xe1\u2415othin\xe7\u1e96\u0180hir\u34eb\u2ec8\u3959op\xf4\u2fb5\u0100;h\u13b7\u3962\xef\u318d\u0100iu\u3969\u396dgm\xe1\u33b3\u0100bp\u3972\u3984setneq\u0100;q\u397d\u3980\uc000\u228a\ufe00;\uc000\u2acb\ufe00setneq\u0100;q\u398f\u3992\uc000\u228b\ufe00;\uc000\u2acc\ufe00\u0100hr\u399b\u399fet\xe1\u369ciangle\u0100lr\u39aa\u39afeft\xbb\u0925ight\xbb\u1051y;\u4432ash\xbb\u1036\u0180elr\u39c4\u39d2\u39d7\u0180;be\u2dea\u39cb\u39cfar;\u62bbq;\u625alip;\u62ee\u0100bt\u39dc\u1468a\xf2\u1469r;\uc000\ud835\udd33tr\xe9\u39aesu\u0100bp\u39ef\u39f1\xbb\u0d1c\xbb\u0d59pf;\uc000\ud835\udd67ro\xf0\u0efbtr\xe9\u39b4\u0100cu\u3a06\u3a0br;\uc000\ud835\udccb\u0100bp\u3a10\u3a18n\u0100Ee\u3980\u3a16\xbb\u397en\u0100Ee\u3992\u3a1e\xbb\u3990igzag;\u699a\u0380cefoprs\u3a36\u3a3b\u3a56\u3a5b\u3a54\u3a61\u3a6airc;\u4175\u0100di\u3a40\u3a51\u0100bg\u3a45\u3a49ar;\u6a5fe\u0100;q\u15fa\u3a4f;\u6259erp;\u6118r;\uc000\ud835\udd34pf;\uc000\ud835\udd68\u0100;e\u1479\u3a66at\xe8\u1479cr;\uc000\ud835\udccc\u0ae3\u178e\u3a87\0\u3a8b\0\u3a90\u3a9b\0\0\u3a9d\u3aa8\u3aab\u3aaf\0\0\u3ac3\u3ace\0\u3ad8\u17dc\u17dftr\xe9\u17d1r;\uc000\ud835\udd35\u0100Aa\u3a94\u3a97r\xf2\u03c3r\xf2\u09f6;\u43be\u0100Aa\u3aa1\u3aa4r\xf2\u03b8r\xf2\u09eba\xf0\u2713is;\u62fb\u0180dpt\u17a4\u3ab5\u3abe\u0100fl\u3aba\u17a9;\uc000\ud835\udd69im\xe5\u17b2\u0100Aa\u3ac7\u3acar\xf2\u03cer\xf2\u0a01\u0100cq\u3ad2\u17b8r;\uc000\ud835\udccd\u0100pt\u17d6\u3adcr\xe9\u17d4\u0400acefiosu\u3af0\u3afd\u3b08\u3b0c\u3b11\u3b15\u3b1b\u3b21c\u0100uy\u3af6\u3afbte\u803b\xfd\u40fd;\u444f\u0100iy\u3b02\u3b06rc;\u4177;\u444bn\u803b\xa5\u40a5r;\uc000\ud835\udd36cy;\u4457pf;\uc000\ud835\udd6acr;\uc000\ud835\udcce\u0100cm\u3b26\u3b29y;\u444el\u803b\xff\u40ff\u0500acdefhiosw\u3b42\u3b48\u3b54\u3b58\u3b64\u3b69\u3b6d\u3b74\u3b7a\u3b80cute;\u417a\u0100ay\u3b4d\u3b52ron;\u417e;\u4437ot;\u417c\u0100et\u3b5d\u3b61tr\xe6\u155fa;\u43b6r;\uc000\ud835\udd37cy;\u4436grarr;\u61ddpf;\uc000\ud835\udd6bcr;\uc000\ud835\udccf\u0100jn\u3b85\u3b87;\u600dj;\u600c" - .split("") - .map(function (c) { return c.charCodeAt(0); })); -//# sourceMappingURL=decode-data-html.js.map + + var hash = new self.$$class(); -/***/ }), + $hash_init(hash); + Opal.hash_clone(self, hash); -/***/ 7359: -/***/ ((__unused_webpack_module, exports) => { + return hash; + + }); + + $def(self, '$compact', function $$compact() { + var self = this; -"use strict"; + + var hash = $hash(); -// Generated using scripts/write-decode-map.ts -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports["default"] = new Uint16Array( -// prettier-ignore -"\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022" - .split("") - .map(function (c) { return c.charCodeAt(0); })); -//# sourceMappingURL=decode-data-xml.js.map + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; -/***/ }), + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } -/***/ 8180: -/***/ ((__unused_webpack_module, exports) => { + if (value !== nil) { + $hash_put(hash, key, value); + } + } -"use strict"; + return hash; + + }); + + $def(self, '$compact!', function $Hash_compact$excl$10() { + var self = this; -// Generated using scripts/write-encode-map.ts -Object.defineProperty(exports, "__esModule", ({ value: true })); -function restoreDiff(arr) { - for (var i = 1; i < arr.length; i++) { - arr[i][0] += arr[i - 1][0] + 1; - } - return arr; -} -// prettier-ignore -exports["default"] = new Map(/* #__PURE__ */ restoreDiff([[9, " "], [0, " "], [22, "!"], [0, """], [0, "#"], [0, "$"], [0, "%"], [0, "&"], [0, "'"], [0, "("], [0, ")"], [0, "*"], [0, "+"], [0, ","], [1, "."], [0, "/"], [10, ":"], [0, ";"], [0, { v: "<", n: 8402, o: "<⃒" }], [0, { v: "=", n: 8421, o: "=⃥" }], [0, { v: ">", n: 8402, o: ">⃒" }], [0, "?"], [0, "@"], [26, "["], [0, "\"], [0, "]"], [0, "^"], [0, "_"], [0, "`"], [5, { n: 106, o: "fj" }], [20, "{"], [0, "|"], [0, "}"], [34, " "], [0, "¡"], [0, "¢"], [0, "£"], [0, "¤"], [0, "¥"], [0, "¦"], [0, "§"], [0, "¨"], [0, "©"], [0, "ª"], [0, "«"], [0, "¬"], [0, "­"], [0, "®"], [0, "¯"], [0, "°"], [0, "±"], [0, "²"], [0, "³"], [0, "´"], [0, "µ"], [0, "¶"], [0, "·"], [0, "¸"], [0, "¹"], [0, "º"], [0, "»"], [0, "¼"], [0, "½"], [0, "¾"], [0, "¿"], [0, "À"], [0, "Á"], [0, "Â"], [0, "Ã"], [0, "Ä"], [0, "Å"], [0, "Æ"], [0, "Ç"], [0, "È"], [0, "É"], [0, "Ê"], [0, "Ë"], [0, "Ì"], [0, "Í"], [0, "Î"], [0, "Ï"], [0, "Ð"], [0, "Ñ"], [0, "Ò"], [0, "Ó"], [0, "Ô"], [0, "Õ"], [0, "Ö"], [0, "×"], [0, "Ø"], [0, "Ù"], [0, "Ú"], [0, "Û"], [0, "Ü"], [0, "Ý"], [0, "Þ"], [0, "ß"], [0, "à"], [0, "á"], [0, "â"], [0, "ã"], [0, "ä"], [0, "å"], [0, "æ"], [0, "ç"], [0, "è"], [0, "é"], [0, "ê"], [0, "ë"], [0, "ì"], [0, "í"], [0, "î"], [0, "ï"], [0, "ð"], [0, "ñ"], [0, "ò"], [0, "ó"], [0, "ô"], [0, "õ"], [0, "ö"], [0, "÷"], [0, "ø"], [0, "ù"], [0, "ú"], [0, "û"], [0, "ü"], [0, "ý"], [0, "þ"], [0, "ÿ"], [0, "Ā"], [0, "ā"], [0, "Ă"], [0, "ă"], [0, "Ą"], [0, "ą"], [0, "Ć"], [0, "ć"], [0, "Ĉ"], [0, "ĉ"], [0, "Ċ"], [0, "ċ"], [0, "Č"], [0, "č"], [0, "Ď"], [0, "ď"], [0, "Đ"], [0, "đ"], [0, "Ē"], [0, "ē"], [2, "Ė"], [0, "ė"], [0, "Ę"], [0, "ę"], [0, "Ě"], [0, "ě"], [0, "Ĝ"], [0, "ĝ"], [0, "Ğ"], [0, "ğ"], [0, "Ġ"], [0, "ġ"], [0, "Ģ"], [1, "Ĥ"], [0, "ĥ"], [0, "Ħ"], [0, "ħ"], [0, "Ĩ"], [0, "ĩ"], [0, "Ī"], [0, "ī"], [2, "Į"], [0, "į"], [0, "İ"], [0, "ı"], [0, "IJ"], [0, "ij"], [0, "Ĵ"], [0, "ĵ"], [0, "Ķ"], [0, "ķ"], [0, "ĸ"], [0, "Ĺ"], [0, "ĺ"], [0, "Ļ"], [0, "ļ"], [0, "Ľ"], [0, "ľ"], [0, "Ŀ"], [0, "ŀ"], [0, "Ł"], [0, "ł"], [0, "Ń"], [0, "ń"], [0, "Ņ"], [0, "ņ"], [0, "Ň"], [0, "ň"], [0, "ʼn"], [0, "Ŋ"], [0, "ŋ"], [0, "Ō"], [0, "ō"], [2, "Ő"], [0, "ő"], [0, "Œ"], [0, "œ"], [0, "Ŕ"], [0, "ŕ"], [0, "Ŗ"], [0, "ŗ"], [0, "Ř"], [0, "ř"], [0, "Ś"], [0, "ś"], [0, "Ŝ"], [0, "ŝ"], [0, "Ş"], [0, "ş"], [0, "Š"], [0, "š"], [0, "Ţ"], [0, "ţ"], [0, "Ť"], [0, "ť"], [0, "Ŧ"], [0, "ŧ"], [0, "Ũ"], [0, "ũ"], [0, "Ū"], [0, "ū"], [0, "Ŭ"], [0, "ŭ"], [0, "Ů"], [0, "ů"], [0, "Ű"], [0, "ű"], [0, "Ų"], [0, "ų"], [0, "Ŵ"], [0, "ŵ"], [0, "Ŷ"], [0, "ŷ"], [0, "Ÿ"], [0, "Ź"], [0, "ź"], [0, "Ż"], [0, "ż"], [0, "Ž"], [0, "ž"], [19, "ƒ"], [34, "Ƶ"], [63, "ǵ"], [65, "ȷ"], [142, "ˆ"], [0, "ˇ"], [16, "˘"], [0, "˙"], [0, "˚"], [0, "˛"], [0, "˜"], [0, "˝"], [51, "̑"], [127, "Α"], [0, "Β"], [0, "Γ"], [0, "Δ"], [0, "Ε"], [0, "Ζ"], [0, "Η"], [0, "Θ"], [0, "Ι"], [0, "Κ"], [0, "Λ"], [0, "Μ"], [0, "Ν"], [0, "Ξ"], [0, "Ο"], [0, "Π"], [0, "Ρ"], [1, "Σ"], [0, "Τ"], [0, "Υ"], [0, "Φ"], [0, "Χ"], [0, "Ψ"], [0, "Ω"], [7, "α"], [0, "β"], [0, "γ"], [0, "δ"], [0, "ε"], [0, "ζ"], [0, "η"], [0, "θ"], [0, "ι"], [0, "κ"], [0, "λ"], [0, "μ"], [0, "ν"], [0, "ξ"], [0, "ο"], [0, "π"], [0, "ρ"], [0, "ς"], [0, "σ"], [0, "τ"], [0, "υ"], [0, "φ"], [0, "χ"], [0, "ψ"], [0, "ω"], [7, "ϑ"], [0, "ϒ"], [2, "ϕ"], [0, "ϖ"], [5, "Ϝ"], [0, "ϝ"], [18, "ϰ"], [0, "ϱ"], [3, "ϵ"], [0, "϶"], [10, "Ё"], [0, "Ђ"], [0, "Ѓ"], [0, "Є"], [0, "Ѕ"], [0, "І"], [0, "Ї"], [0, "Ј"], [0, "Љ"], [0, "Њ"], [0, "Ћ"], [0, "Ќ"], [1, "Ў"], [0, "Џ"], [0, "А"], [0, "Б"], [0, "В"], [0, "Г"], [0, "Д"], [0, "Е"], [0, "Ж"], [0, "З"], [0, "И"], [0, "Й"], [0, "К"], [0, "Л"], [0, "М"], [0, "Н"], [0, "О"], [0, "П"], [0, "Р"], [0, "С"], [0, "Т"], [0, "У"], [0, "Ф"], [0, "Х"], [0, "Ц"], [0, "Ч"], [0, "Ш"], [0, "Щ"], [0, "Ъ"], [0, "Ы"], [0, "Ь"], [0, "Э"], [0, "Ю"], [0, "Я"], [0, "а"], [0, "б"], [0, "в"], [0, "г"], [0, "д"], [0, "е"], [0, "ж"], [0, "з"], [0, "и"], [0, "й"], [0, "к"], [0, "л"], [0, "м"], [0, "н"], [0, "о"], [0, "п"], [0, "р"], [0, "с"], [0, "т"], [0, "у"], [0, "ф"], [0, "х"], [0, "ц"], [0, "ч"], [0, "ш"], [0, "щ"], [0, "ъ"], [0, "ы"], [0, "ь"], [0, "э"], [0, "ю"], [0, "я"], [1, "ё"], [0, "ђ"], [0, "ѓ"], [0, "є"], [0, "ѕ"], [0, "і"], [0, "ї"], [0, "ј"], [0, "љ"], [0, "њ"], [0, "ћ"], [0, "ќ"], [1, "ў"], [0, "џ"], [7074, " "], [0, " "], [0, " "], [0, " "], [1, " "], [0, " "], [0, " "], [0, " "], [0, "​"], [0, "‌"], [0, "‍"], [0, "‎"], [0, "‏"], [0, "‐"], [2, "–"], [0, "—"], [0, "―"], [0, "‖"], [1, "‘"], [0, "’"], [0, "‚"], [1, "“"], [0, "”"], [0, "„"], [1, "†"], [0, "‡"], [0, "•"], [2, "‥"], [0, "…"], [9, "‰"], [0, "‱"], [0, "′"], [0, "″"], [0, "‴"], [0, "‵"], [3, "‹"], [0, "›"], [3, "‾"], [2, "⁁"], [1, "⁃"], [0, "⁄"], [10, "⁏"], [7, "⁗"], [7, { v: " ", n: 8202, o: "  " }], [0, "⁠"], [0, "⁡"], [0, "⁢"], [0, "⁣"], [72, "€"], [46, "⃛"], [0, "⃜"], [37, "ℂ"], [2, "℅"], [4, "ℊ"], [0, "ℋ"], [0, "ℌ"], [0, "ℍ"], [0, "ℎ"], [0, "ℏ"], [0, "ℐ"], [0, "ℑ"], [0, "ℒ"], [0, "ℓ"], [1, "ℕ"], [0, "№"], [0, "℗"], [0, "℘"], [0, "ℙ"], [0, "ℚ"], [0, "ℛ"], [0, "ℜ"], [0, "ℝ"], [0, "℞"], [3, "™"], [1, "ℤ"], [2, "℧"], [0, "ℨ"], [0, "℩"], [2, "ℬ"], [0, "ℭ"], [1, "ℯ"], [0, "ℰ"], [0, "ℱ"], [1, "ℳ"], [0, "ℴ"], [0, "ℵ"], [0, "ℶ"], [0, "ℷ"], [0, "ℸ"], [12, "ⅅ"], [0, "ⅆ"], [0, "ⅇ"], [0, "ⅈ"], [10, "⅓"], [0, "⅔"], [0, "⅕"], [0, "⅖"], [0, "⅗"], [0, "⅘"], [0, "⅙"], [0, "⅚"], [0, "⅛"], [0, "⅜"], [0, "⅝"], [0, "⅞"], [49, "←"], [0, "↑"], [0, "→"], [0, "↓"], [0, "↔"], [0, "↕"], [0, "↖"], [0, "↗"], [0, "↘"], [0, "↙"], [0, "↚"], [0, "↛"], [1, { v: "↝", n: 824, o: "↝̸" }], [0, "↞"], [0, "↟"], [0, "↠"], [0, "↡"], [0, "↢"], [0, "↣"], [0, "↤"], [0, "↥"], [0, "↦"], [0, "↧"], [1, "↩"], [0, "↪"], [0, "↫"], [0, "↬"], [0, "↭"], [0, "↮"], [1, "↰"], [0, "↱"], [0, "↲"], [0, "↳"], [1, "↵"], [0, "↶"], [0, "↷"], [2, "↺"], [0, "↻"], [0, "↼"], [0, "↽"], [0, "↾"], [0, "↿"], [0, "⇀"], [0, "⇁"], [0, "⇂"], [0, "⇃"], [0, "⇄"], [0, "⇅"], [0, "⇆"], [0, "⇇"], [0, "⇈"], [0, "⇉"], [0, "⇊"], [0, "⇋"], [0, "⇌"], [0, "⇍"], [0, "⇎"], [0, "⇏"], [0, "⇐"], [0, "⇑"], [0, "⇒"], [0, "⇓"], [0, "⇔"], [0, "⇕"], [0, "⇖"], [0, "⇗"], [0, "⇘"], [0, "⇙"], [0, "⇚"], [0, "⇛"], [1, "⇝"], [6, "⇤"], [0, "⇥"], [15, "⇵"], [7, "⇽"], [0, "⇾"], [0, "⇿"], [0, "∀"], [0, "∁"], [0, { v: "∂", n: 824, o: "∂̸" }], [0, "∃"], [0, "∄"], [0, "∅"], [1, "∇"], [0, "∈"], [0, "∉"], [1, "∋"], [0, "∌"], [2, "∏"], [0, "∐"], [0, "∑"], [0, "−"], [0, "∓"], [0, "∔"], [1, "∖"], [0, "∗"], [0, "∘"], [1, "√"], [2, "∝"], [0, "∞"], [0, "∟"], [0, { v: "∠", n: 8402, o: "∠⃒" }], [0, "∡"], [0, "∢"], [0, "∣"], [0, "∤"], [0, "∥"], [0, "∦"], [0, "∧"], [0, "∨"], [0, { v: "∩", n: 65024, o: "∩︀" }], [0, { v: "∪", n: 65024, o: "∪︀" }], [0, "∫"], [0, "∬"], [0, "∭"], [0, "∮"], [0, "∯"], [0, "∰"], [0, "∱"], [0, "∲"], [0, "∳"], [0, "∴"], [0, "∵"], [0, "∶"], [0, "∷"], [0, "∸"], [1, "∺"], [0, "∻"], [0, { v: "∼", n: 8402, o: "∼⃒" }], [0, { v: "∽", n: 817, o: "∽̱" }], [0, { v: "∾", n: 819, o: "∾̳" }], [0, "∿"], [0, "≀"], [0, "≁"], [0, { v: "≂", n: 824, o: "≂̸" }], [0, "≃"], [0, "≄"], [0, "≅"], [0, "≆"], [0, "≇"], [0, "≈"], [0, "≉"], [0, "≊"], [0, { v: "≋", n: 824, o: "≋̸" }], [0, "≌"], [0, { v: "≍", n: 8402, o: "≍⃒" }], [0, { v: "≎", n: 824, o: "≎̸" }], [0, { v: "≏", n: 824, o: "≏̸" }], [0, { v: "≐", n: 824, o: "≐̸" }], [0, "≑"], [0, "≒"], [0, "≓"], [0, "≔"], [0, "≕"], [0, "≖"], [0, "≗"], [1, "≙"], [0, "≚"], [1, "≜"], [2, "≟"], [0, "≠"], [0, { v: "≡", n: 8421, o: "≡⃥" }], [0, "≢"], [1, { v: "≤", n: 8402, o: "≤⃒" }], [0, { v: "≥", n: 8402, o: "≥⃒" }], [0, { v: "≦", n: 824, o: "≦̸" }], [0, { v: "≧", n: 824, o: "≧̸" }], [0, { v: "≨", n: 65024, o: "≨︀" }], [0, { v: "≩", n: 65024, o: "≩︀" }], [0, { v: "≪", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≪̸"], [7577, "≪⃒"]])) }], [0, { v: "≫", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≫̸"], [7577, "≫⃒"]])) }], [0, "≬"], [0, "≭"], [0, "≮"], [0, "≯"], [0, "≰"], [0, "≱"], [0, "≲"], [0, "≳"], [0, "≴"], [0, "≵"], [0, "≶"], [0, "≷"], [0, "≸"], [0, "≹"], [0, "≺"], [0, "≻"], [0, "≼"], [0, "≽"], [0, "≾"], [0, { v: "≿", n: 824, o: "≿̸" }], [0, "⊀"], [0, "⊁"], [0, { v: "⊂", n: 8402, o: "⊂⃒" }], [0, { v: "⊃", n: 8402, o: "⊃⃒" }], [0, "⊄"], [0, "⊅"], [0, "⊆"], [0, "⊇"], [0, "⊈"], [0, "⊉"], [0, { v: "⊊", n: 65024, o: "⊊︀" }], [0, { v: "⊋", n: 65024, o: "⊋︀" }], [1, "⊍"], [0, "⊎"], [0, { v: "⊏", n: 824, o: "⊏̸" }], [0, { v: "⊐", n: 824, o: "⊐̸" }], [0, "⊑"], [0, "⊒"], [0, { v: "⊓", n: 65024, o: "⊓︀" }], [0, { v: "⊔", n: 65024, o: "⊔︀" }], [0, "⊕"], [0, "⊖"], [0, "⊗"], [0, "⊘"], [0, "⊙"], [0, "⊚"], [0, "⊛"], [1, "⊝"], [0, "⊞"], [0, "⊟"], [0, "⊠"], [0, "⊡"], [0, "⊢"], [0, "⊣"], [0, "⊤"], [0, "⊥"], [1, "⊧"], [0, "⊨"], [0, "⊩"], [0, "⊪"], [0, "⊫"], [0, "⊬"], [0, "⊭"], [0, "⊮"], [0, "⊯"], [0, "⊰"], [1, "⊲"], [0, "⊳"], [0, { v: "⊴", n: 8402, o: "⊴⃒" }], [0, { v: "⊵", n: 8402, o: "⊵⃒" }], [0, "⊶"], [0, "⊷"], [0, "⊸"], [0, "⊹"], [0, "⊺"], [0, "⊻"], [1, "⊽"], [0, "⊾"], [0, "⊿"], [0, "⋀"], [0, "⋁"], [0, "⋂"], [0, "⋃"], [0, "⋄"], [0, "⋅"], [0, "⋆"], [0, "⋇"], [0, "⋈"], [0, "⋉"], [0, "⋊"], [0, "⋋"], [0, "⋌"], [0, "⋍"], [0, "⋎"], [0, "⋏"], [0, "⋐"], [0, "⋑"], [0, "⋒"], [0, "⋓"], [0, "⋔"], [0, "⋕"], [0, "⋖"], [0, "⋗"], [0, { v: "⋘", n: 824, o: "⋘̸" }], [0, { v: "⋙", n: 824, o: "⋙̸" }], [0, { v: "⋚", n: 65024, o: "⋚︀" }], [0, { v: "⋛", n: 65024, o: "⋛︀" }], [2, "⋞"], [0, "⋟"], [0, "⋠"], [0, "⋡"], [0, "⋢"], [0, "⋣"], [2, "⋦"], [0, "⋧"], [0, "⋨"], [0, "⋩"], [0, "⋪"], [0, "⋫"], [0, "⋬"], [0, "⋭"], [0, "⋮"], [0, "⋯"], [0, "⋰"], [0, "⋱"], [0, "⋲"], [0, "⋳"], [0, "⋴"], [0, { v: "⋵", n: 824, o: "⋵̸" }], [0, "⋶"], [0, "⋷"], [1, { v: "⋹", n: 824, o: "⋹̸" }], [0, "⋺"], [0, "⋻"], [0, "⋼"], [0, "⋽"], [0, "⋾"], [6, "⌅"], [0, "⌆"], [1, "⌈"], [0, "⌉"], [0, "⌊"], [0, "⌋"], [0, "⌌"], [0, "⌍"], [0, "⌎"], [0, "⌏"], [0, "⌐"], [1, "⌒"], [0, "⌓"], [1, "⌕"], [0, "⌖"], [5, "⌜"], [0, "⌝"], [0, "⌞"], [0, "⌟"], [2, "⌢"], [0, "⌣"], [9, "⌭"], [0, "⌮"], [7, "⌶"], [6, "⌽"], [1, "⌿"], [60, "⍼"], [51, "⎰"], [0, "⎱"], [2, "⎴"], [0, "⎵"], [0, "⎶"], [37, "⏜"], [0, "⏝"], [0, "⏞"], [0, "⏟"], [2, "⏢"], [4, "⏧"], [59, "␣"], [164, "Ⓢ"], [55, "─"], [1, "│"], [9, "┌"], [3, "┐"], [3, "└"], [3, "┘"], [3, "├"], [7, "┤"], [7, "┬"], [7, "┴"], [7, "┼"], [19, "═"], [0, "║"], [0, "╒"], [0, "╓"], [0, "╔"], [0, "╕"], [0, "╖"], [0, "╗"], [0, "╘"], [0, "╙"], [0, "╚"], [0, "╛"], [0, "╜"], [0, "╝"], [0, "╞"], [0, "╟"], [0, "╠"], [0, "╡"], [0, "╢"], [0, "╣"], [0, "╤"], [0, "╥"], [0, "╦"], [0, "╧"], [0, "╨"], [0, "╩"], [0, "╪"], [0, "╫"], [0, "╬"], [19, "▀"], [3, "▄"], [3, "█"], [8, "░"], [0, "▒"], [0, "▓"], [13, "□"], [8, "▪"], [0, "▫"], [1, "▭"], [0, "▮"], [2, "▱"], [1, "△"], [0, "▴"], [0, "▵"], [2, "▸"], [0, "▹"], [3, "▽"], [0, "▾"], [0, "▿"], [2, "◂"], [0, "◃"], [6, "◊"], [0, "○"], [32, "◬"], [2, "◯"], [8, "◸"], [0, "◹"], [0, "◺"], [0, "◻"], [0, "◼"], [8, "★"], [0, "☆"], [7, "☎"], [49, "♀"], [1, "♂"], [29, "♠"], [2, "♣"], [1, "♥"], [0, "♦"], [3, "♪"], [2, "♭"], [0, "♮"], [0, "♯"], [163, "✓"], [3, "✗"], [8, "✠"], [21, "✶"], [33, "❘"], [25, "❲"], [0, "❳"], [84, "⟈"], [0, "⟉"], [28, "⟦"], [0, "⟧"], [0, "⟨"], [0, "⟩"], [0, "⟪"], [0, "⟫"], [0, "⟬"], [0, "⟭"], [7, "⟵"], [0, "⟶"], [0, "⟷"], [0, "⟸"], [0, "⟹"], [0, "⟺"], [1, "⟼"], [2, "⟿"], [258, "⤂"], [0, "⤃"], [0, "⤄"], [0, "⤅"], [6, "⤌"], [0, "⤍"], [0, "⤎"], [0, "⤏"], [0, "⤐"], [0, "⤑"], [0, "⤒"], [0, "⤓"], [2, "⤖"], [2, "⤙"], [0, "⤚"], [0, "⤛"], [0, "⤜"], [0, "⤝"], [0, "⤞"], [0, "⤟"], [0, "⤠"], [2, "⤣"], [0, "⤤"], [0, "⤥"], [0, "⤦"], [0, "⤧"], [0, "⤨"], [0, "⤩"], [0, "⤪"], [8, { v: "⤳", n: 824, o: "⤳̸" }], [1, "⤵"], [0, "⤶"], [0, "⤷"], [0, "⤸"], [0, "⤹"], [2, "⤼"], [0, "⤽"], [7, "⥅"], [2, "⥈"], [0, "⥉"], [0, "⥊"], [0, "⥋"], [2, "⥎"], [0, "⥏"], [0, "⥐"], [0, "⥑"], [0, "⥒"], [0, "⥓"], [0, "⥔"], [0, "⥕"], [0, "⥖"], [0, "⥗"], [0, "⥘"], [0, "⥙"], [0, "⥚"], [0, "⥛"], [0, "⥜"], [0, "⥝"], [0, "⥞"], [0, "⥟"], [0, "⥠"], [0, "⥡"], [0, "⥢"], [0, "⥣"], [0, "⥤"], [0, "⥥"], [0, "⥦"], [0, "⥧"], [0, "⥨"], [0, "⥩"], [0, "⥪"], [0, "⥫"], [0, "⥬"], [0, "⥭"], [0, "⥮"], [0, "⥯"], [0, "⥰"], [0, "⥱"], [0, "⥲"], [0, "⥳"], [0, "⥴"], [0, "⥵"], [0, "⥶"], [1, "⥸"], [0, "⥹"], [1, "⥻"], [0, "⥼"], [0, "⥽"], [0, "⥾"], [0, "⥿"], [5, "⦅"], [0, "⦆"], [4, "⦋"], [0, "⦌"], [0, "⦍"], [0, "⦎"], [0, "⦏"], [0, "⦐"], [0, "⦑"], [0, "⦒"], [0, "⦓"], [0, "⦔"], [0, "⦕"], [0, "⦖"], [3, "⦚"], [1, "⦜"], [0, "⦝"], [6, "⦤"], [0, "⦥"], [0, "⦦"], [0, "⦧"], [0, "⦨"], [0, "⦩"], [0, "⦪"], [0, "⦫"], [0, "⦬"], [0, "⦭"], [0, "⦮"], [0, "⦯"], [0, "⦰"], [0, "⦱"], [0, "⦲"], [0, "⦳"], [0, "⦴"], [0, "⦵"], [0, "⦶"], [0, "⦷"], [1, "⦹"], [1, "⦻"], [0, "⦼"], [1, "⦾"], [0, "⦿"], [0, "⧀"], [0, "⧁"], [0, "⧂"], [0, "⧃"], [0, "⧄"], [0, "⧅"], [3, "⧉"], [3, "⧍"], [0, "⧎"], [0, { v: "⧏", n: 824, o: "⧏̸" }], [0, { v: "⧐", n: 824, o: "⧐̸" }], [11, "⧜"], [0, "⧝"], [0, "⧞"], [4, "⧣"], [0, "⧤"], [0, "⧥"], [5, "⧫"], [8, "⧴"], [1, "⧶"], [9, "⨀"], [0, "⨁"], [0, "⨂"], [1, "⨄"], [1, "⨆"], [5, "⨌"], [0, "⨍"], [2, "⨐"], [0, "⨑"], [0, "⨒"], [0, "⨓"], [0, "⨔"], [0, "⨕"], [0, "⨖"], [0, "⨗"], [10, "⨢"], [0, "⨣"], [0, "⨤"], [0, "⨥"], [0, "⨦"], [0, "⨧"], [1, "⨩"], [0, "⨪"], [2, "⨭"], [0, "⨮"], [0, "⨯"], [0, "⨰"], [0, "⨱"], [1, "⨳"], [0, "⨴"], [0, "⨵"], [0, "⨶"], [0, "⨷"], [0, "⨸"], [0, "⨹"], [0, "⨺"], [0, "⨻"], [0, "⨼"], [2, "⨿"], [0, "⩀"], [1, "⩂"], [0, "⩃"], [0, "⩄"], [0, "⩅"], [0, "⩆"], [0, "⩇"], [0, "⩈"], [0, "⩉"], [0, "⩊"], [0, "⩋"], [0, "⩌"], [0, "⩍"], [2, "⩐"], [2, "⩓"], [0, "⩔"], [0, "⩕"], [0, "⩖"], [0, "⩗"], [0, "⩘"], [1, "⩚"], [0, "⩛"], [0, "⩜"], [0, "⩝"], [1, "⩟"], [6, "⩦"], [3, "⩪"], [2, { v: "⩭", n: 824, o: "⩭̸" }], [0, "⩮"], [0, "⩯"], [0, { v: "⩰", n: 824, o: "⩰̸" }], [0, "⩱"], [0, "⩲"], [0, "⩳"], [0, "⩴"], [0, "⩵"], [1, "⩷"], [0, "⩸"], [0, "⩹"], [0, "⩺"], [0, "⩻"], [0, "⩼"], [0, { v: "⩽", n: 824, o: "⩽̸" }], [0, { v: "⩾", n: 824, o: "⩾̸" }], [0, "⩿"], [0, "⪀"], [0, "⪁"], [0, "⪂"], [0, "⪃"], [0, "⪄"], [0, "⪅"], [0, "⪆"], [0, "⪇"], [0, "⪈"], [0, "⪉"], [0, "⪊"], [0, "⪋"], [0, "⪌"], [0, "⪍"], [0, "⪎"], [0, "⪏"], [0, "⪐"], [0, "⪑"], [0, "⪒"], [0, "⪓"], [0, "⪔"], [0, "⪕"], [0, "⪖"], [0, "⪗"], [0, "⪘"], [0, "⪙"], [0, "⪚"], [2, "⪝"], [0, "⪞"], [0, "⪟"], [0, "⪠"], [0, { v: "⪡", n: 824, o: "⪡̸" }], [0, { v: "⪢", n: 824, o: "⪢̸" }], [1, "⪤"], [0, "⪥"], [0, "⪦"], [0, "⪧"], [0, "⪨"], [0, "⪩"], [0, "⪪"], [0, "⪫"], [0, { v: "⪬", n: 65024, o: "⪬︀" }], [0, { v: "⪭", n: 65024, o: "⪭︀" }], [0, "⪮"], [0, { v: "⪯", n: 824, o: "⪯̸" }], [0, { v: "⪰", n: 824, o: "⪰̸" }], [2, "⪳"], [0, "⪴"], [0, "⪵"], [0, "⪶"], [0, "⪷"], [0, "⪸"], [0, "⪹"], [0, "⪺"], [0, "⪻"], [0, "⪼"], [0, "⪽"], [0, "⪾"], [0, "⪿"], [0, "⫀"], [0, "⫁"], [0, "⫂"], [0, "⫃"], [0, "⫄"], [0, { v: "⫅", n: 824, o: "⫅̸" }], [0, { v: "⫆", n: 824, o: "⫆̸" }], [0, "⫇"], [0, "⫈"], [2, { v: "⫋", n: 65024, o: "⫋︀" }], [0, { v: "⫌", n: 65024, o: "⫌︀" }], [2, "⫏"], [0, "⫐"], [0, "⫑"], [0, "⫒"], [0, "⫓"], [0, "⫔"], [0, "⫕"], [0, "⫖"], [0, "⫗"], [0, "⫘"], [0, "⫙"], [0, "⫚"], [0, "⫛"], [8, "⫤"], [1, "⫦"], [0, "⫧"], [0, "⫨"], [0, "⫩"], [1, "⫫"], [0, "⫬"], [0, "⫭"], [0, "⫮"], [0, "⫯"], [0, "⫰"], [0, "⫱"], [0, "⫲"], [0, "⫳"], [9, { v: "⫽", n: 8421, o: "⫽⃥" }], [44343, { n: new Map(/* #__PURE__ */ restoreDiff([[56476, "𝒜"], [1, "𝒞"], [0, "𝒟"], [2, "𝒢"], [2, "𝒥"], [0, "𝒦"], [2, "𝒩"], [0, "𝒪"], [0, "𝒫"], [0, "𝒬"], [1, "𝒮"], [0, "𝒯"], [0, "𝒰"], [0, "𝒱"], [0, "𝒲"], [0, "𝒳"], [0, "𝒴"], [0, "𝒵"], [0, "𝒶"], [0, "𝒷"], [0, "𝒸"], [0, "𝒹"], [1, "𝒻"], [1, "𝒽"], [0, "𝒾"], [0, "𝒿"], [0, "𝓀"], [0, "𝓁"], [0, "𝓂"], [0, "𝓃"], [1, "𝓅"], [0, "𝓆"], [0, "𝓇"], [0, "𝓈"], [0, "𝓉"], [0, "𝓊"], [0, "𝓋"], [0, "𝓌"], [0, "𝓍"], [0, "𝓎"], [0, "𝓏"], [52, "𝔄"], [0, "𝔅"], [1, "𝔇"], [0, "𝔈"], [0, "𝔉"], [0, "𝔊"], [2, "𝔍"], [0, "𝔎"], [0, "𝔏"], [0, "𝔐"], [0, "𝔑"], [0, "𝔒"], [0, "𝔓"], [0, "𝔔"], [1, "𝔖"], [0, "𝔗"], [0, "𝔘"], [0, "𝔙"], [0, "𝔚"], [0, "𝔛"], [0, "𝔜"], [1, "𝔞"], [0, "𝔟"], [0, "𝔠"], [0, "𝔡"], [0, "𝔢"], [0, "𝔣"], [0, "𝔤"], [0, "𝔥"], [0, "𝔦"], [0, "𝔧"], [0, "𝔨"], [0, "𝔩"], [0, "𝔪"], [0, "𝔫"], [0, "𝔬"], [0, "𝔭"], [0, "𝔮"], [0, "𝔯"], [0, "𝔰"], [0, "𝔱"], [0, "𝔲"], [0, "𝔳"], [0, "𝔴"], [0, "𝔵"], [0, "𝔶"], [0, "𝔷"], [0, "𝔸"], [0, "𝔹"], [1, "𝔻"], [0, "𝔼"], [0, "𝔽"], [0, "𝔾"], [1, "𝕀"], [0, "𝕁"], [0, "𝕂"], [0, "𝕃"], [0, "𝕄"], [1, "𝕆"], [3, "𝕊"], [0, "𝕋"], [0, "𝕌"], [0, "𝕍"], [0, "𝕎"], [0, "𝕏"], [0, "𝕐"], [1, "𝕒"], [0, "𝕓"], [0, "𝕔"], [0, "𝕕"], [0, "𝕖"], [0, "𝕗"], [0, "𝕘"], [0, "𝕙"], [0, "𝕚"], [0, "𝕛"], [0, "𝕜"], [0, "𝕝"], [0, "𝕞"], [0, "𝕟"], [0, "𝕠"], [0, "𝕡"], [0, "𝕢"], [0, "𝕣"], [0, "𝕤"], [0, "𝕥"], [0, "𝕦"], [0, "𝕧"], [0, "𝕨"], [0, "𝕩"], [0, "𝕪"], [0, "𝕫"]])) }], [8906, "ff"], [0, "fi"], [0, "fl"], [0, "ffi"], [0, "ffl"]])); -//# sourceMappingURL=encode-html.js.map + + $deny_frozen_access(self); -/***/ }), + var changes_were_made = false; -/***/ 3000: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; -"use strict"; + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLAttribute = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.DecodingMode = exports.EntityDecoder = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.EntityLevel = void 0; -var decode_js_1 = __nccwpck_require__(5107); -var encode_js_1 = __nccwpck_require__(2006); -var escape_js_1 = __nccwpck_require__(7654); -/** The level of entities to support. */ -var EntityLevel; -(function (EntityLevel) { - /** Support only XML entities. */ - EntityLevel[EntityLevel["XML"] = 0] = "XML"; - /** Support HTML entities, which are a superset of XML entities. */ - EntityLevel[EntityLevel["HTML"] = 1] = "HTML"; -})(EntityLevel = exports.EntityLevel || (exports.EntityLevel = {})); -var EncodingMode; -(function (EncodingMode) { - /** - * The output is UTF-8 encoded. Only characters that need escaping within - * XML will be escaped. - */ - EncodingMode[EncodingMode["UTF8"] = 0] = "UTF8"; - /** - * The output consists only of ASCII characters. Characters that need - * escaping within HTML, and characters that aren't ASCII characters will - * be escaped. - */ - EncodingMode[EncodingMode["ASCII"] = 1] = "ASCII"; - /** - * Encode all characters that have an equivalent entity, as well as all - * characters that are not ASCII characters. - */ - EncodingMode[EncodingMode["Extensive"] = 2] = "Extensive"; - /** - * Encode all characters that have to be escaped in HTML attributes, - * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. - */ - EncodingMode[EncodingMode["Attribute"] = 3] = "Attribute"; - /** - * Encode all characters that have to be escaped in HTML text, - * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. - */ - EncodingMode[EncodingMode["Text"] = 4] = "Text"; -})(EncodingMode = exports.EncodingMode || (exports.EncodingMode = {})); -/** - * Decodes a string with entities. - * - * @param data String to decode. - * @param options Decoding options. - */ -function decode(data, options) { - if (options === void 0) { options = EntityLevel.XML; } - var level = typeof options === "number" ? options : options.level; - if (level === EntityLevel.HTML) { - var mode = typeof options === "object" ? options.mode : undefined; - return (0, decode_js_1.decodeHTML)(data, mode); - } - return (0, decode_js_1.decodeXML)(data); -} -exports.decode = decode; -/** - * Decodes a string with entities. Does not allow missing trailing semicolons for entities. - * - * @param data String to decode. - * @param options Decoding options. - * @deprecated Use `decode` with the `mode` set to `Strict`. - */ -function decodeStrict(data, options) { - var _a; - if (options === void 0) { options = EntityLevel.XML; } - var opts = typeof options === "number" ? { level: options } : options; - (_a = opts.mode) !== null && _a !== void 0 ? _a : (opts.mode = decode_js_1.DecodingMode.Strict); - return decode(data, opts); -} -exports.decodeStrict = decodeStrict; -/** - * Encodes a string with entities. - * - * @param data String to encode. - * @param options Encoding options. - */ -function encode(data, options) { - if (options === void 0) { options = EntityLevel.XML; } - var opts = typeof options === "number" ? { level: options } : options; - // Mode `UTF8` just escapes XML entities - if (opts.mode === EncodingMode.UTF8) - return (0, escape_js_1.escapeUTF8)(data); - if (opts.mode === EncodingMode.Attribute) - return (0, escape_js_1.escapeAttribute)(data); - if (opts.mode === EncodingMode.Text) - return (0, escape_js_1.escapeText)(data); - if (opts.level === EntityLevel.HTML) { - if (opts.mode === EncodingMode.ASCII) { - return (0, encode_js_1.encodeNonAsciiHTML)(data); + if (value === nil) { + if ($hash_delete(self, key) !== undefined) { + changes_were_made = true; + length--; + i--; + } } - return (0, encode_js_1.encodeHTML)(data); - } - // ASCII and Extensive are equivalent - return (0, escape_js_1.encodeXML)(data); -} -exports.encode = encode; -var escape_js_2 = __nccwpck_require__(7654); -Object.defineProperty(exports, "encodeXML", ({ enumerable: true, get: function () { return escape_js_2.encodeXML; } })); -Object.defineProperty(exports, "escape", ({ enumerable: true, get: function () { return escape_js_2.escape; } })); -Object.defineProperty(exports, "escapeUTF8", ({ enumerable: true, get: function () { return escape_js_2.escapeUTF8; } })); -Object.defineProperty(exports, "escapeAttribute", ({ enumerable: true, get: function () { return escape_js_2.escapeAttribute; } })); -Object.defineProperty(exports, "escapeText", ({ enumerable: true, get: function () { return escape_js_2.escapeText; } })); -var encode_js_2 = __nccwpck_require__(2006); -Object.defineProperty(exports, "encodeHTML", ({ enumerable: true, get: function () { return encode_js_2.encodeHTML; } })); -Object.defineProperty(exports, "encodeNonAsciiHTML", ({ enumerable: true, get: function () { return encode_js_2.encodeNonAsciiHTML; } })); -// Legacy aliases (deprecated) -Object.defineProperty(exports, "encodeHTML4", ({ enumerable: true, get: function () { return encode_js_2.encodeHTML; } })); -Object.defineProperty(exports, "encodeHTML5", ({ enumerable: true, get: function () { return encode_js_2.encodeHTML; } })); -var decode_js_2 = __nccwpck_require__(5107); -Object.defineProperty(exports, "EntityDecoder", ({ enumerable: true, get: function () { return decode_js_2.EntityDecoder; } })); -Object.defineProperty(exports, "DecodingMode", ({ enumerable: true, get: function () { return decode_js_2.DecodingMode; } })); -Object.defineProperty(exports, "decodeXML", ({ enumerable: true, get: function () { return decode_js_2.decodeXML; } })); -Object.defineProperty(exports, "decodeHTML", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } })); -Object.defineProperty(exports, "decodeHTMLStrict", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } })); -Object.defineProperty(exports, "decodeHTMLAttribute", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLAttribute; } })); -// Legacy aliases (deprecated) -Object.defineProperty(exports, "decodeHTML4", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } })); -Object.defineProperty(exports, "decodeHTML5", ({ enumerable: true, get: function () { return decode_js_2.decodeHTML; } })); -Object.defineProperty(exports, "decodeHTML4Strict", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } })); -Object.defineProperty(exports, "decodeHTML5Strict", ({ enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } })); -Object.defineProperty(exports, "decodeXMLStrict", ({ enumerable: true, get: function () { return decode_js_2.decodeXML; } })); -//# sourceMappingURL=index.js.map + } -/***/ }), + return changes_were_made ? self : nil; + + }); + + $def(self, '$compare_by_identity', function $$compare_by_identity() { + var self = this; -/***/ 6863: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + + $deny_frozen_access(self); -module.exports = realpath -realpath.realpath = realpath -realpath.sync = realpathSync -realpath.realpathSync = realpathSync -realpath.monkeypatch = monkeypatch -realpath.unmonkeypatch = unmonkeypatch + var i, ii, key, keys = self.$$keys, identity_hash; -var fs = __nccwpck_require__(7147) -var origRealpath = fs.realpath -var origRealpathSync = fs.realpathSync + if (self.$$by_identity) return self; + if (self.$$keys.length === 0) { + self.$$by_identity = true; + return self; + } -var version = process.version -var ok = /^v[0-5]\./.test(version) -var old = __nccwpck_require__(1734) + identity_hash = $hash2([], {}).$compare_by_identity(); + for(i = 0, ii = keys.length; i < ii; i++) { + key = keys[i]; + if (!key.$$is_string) key = key.key; + $hash_put(identity_hash, key, $hash_get(self, key)); + } -function newError (er) { - return er && er.syscall === 'realpath' && ( - er.code === 'ELOOP' || - er.code === 'ENOMEM' || - er.code === 'ENAMETOOLONG' - ) -} + self.$$by_identity = true; + self.$$map = identity_hash.$$map; + self.$$smap = identity_hash.$$smap; + return self; + + }); + + $def(self, '$compare_by_identity?', function $Hash_compare_by_identity$ques$11() { + var self = this; -function realpath (p, cache, cb) { - if (ok) { - return origRealpath(p, cache, cb) - } + return self.$$by_identity === true; + }); + + $def(self, '$default', function $Hash_default$12(key) { + var self = this; + + if (key !== undefined && self.$$proc !== nil && self.$$proc !== undefined) { + return self.$$proc.$call(self, key); + } + if (self.$$none === undefined) { + return nil; + } + return self.$$none; + }, -1); + + $def(self, '$default=', function $Hash_default$eq$13(object) { + var self = this; - if (typeof cache === 'function') { - cb = cache - cache = null - } - origRealpath(p, cache, function (er, result) { - if (newError(er)) { - old.realpath(p, cache, cb) - } else { - cb(er, result) - } - }) -} + + $deny_frozen_access(self); -function realpathSync (p, cache) { - if (ok) { - return origRealpathSync(p, cache) - } + self.$$proc = nil; + self.$$none = object; - try { - return origRealpathSync(p, cache) - } catch (er) { - if (newError(er)) { - return old.realpathSync(p, cache) - } else { - throw er - } - } -} + return object; + + }); + + $def(self, '$default_proc', function $$default_proc() { + var self = this; -function monkeypatch () { - fs.realpath = realpath - fs.realpathSync = realpathSync -} + + if (self.$$proc !== undefined) { + return self.$$proc; + } + return nil; + + }); + + $def(self, '$default_proc=', function $Hash_default_proc$eq$14(default_proc) { + var self = this; -function unmonkeypatch () { - fs.realpath = origRealpath - fs.realpathSync = origRealpathSync -} + + $deny_frozen_access(self); + var proc = default_proc; -/***/ }), + if (proc !== nil) { + proc = $Opal['$coerce_to!'](proc, $$$('Proc'), "to_proc"); -/***/ 1734: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + if ((proc)['$lambda?']() && (proc).$arity().$abs() !== 2) { + $Kernel.$raise($$$('TypeError'), "default_proc takes two arguments"); + } + } -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + self.$$none = nil; + self.$$proc = proc; -var pathModule = __nccwpck_require__(1017); -var isWindows = process.platform === 'win32'; -var fs = __nccwpck_require__(7147); + return default_proc; + + }); + + $def(self, '$delete', function $Hash_delete$15(key) { + var block = $Hash_delete$15.$$p || nil, self = this; -// JavaScript implementation of realpath, ported from node pre-v6 + $Hash_delete$15.$$p = null; + + $deny_frozen_access(self); + var value = $hash_delete(self, key); -var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); + if (value !== undefined) { + return value; + } -function rethrow() { - // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and - // is fairly slow to generate. - var callback; - if (DEBUG) { - var backtrace = new Error; - callback = debugCallback; - } else - callback = missingCallback; + if (block !== nil) { + return Opal.yield1(block, key); + } - return callback; + return nil; + }); + + $def(self, '$delete_if', function $$delete_if() { + var block = $$delete_if.$$p || nil, self = this; - function debugCallback(err) { - if (err) { - backtrace.message = err.message; - err = backtrace; - missingCallback(err); - } - } + $$delete_if.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["delete_if"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s; - function missingCallback(err) { - if (err) { - if (process.throwDeprecation) - throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs - else if (!process.noDeprecation) { - var msg = 'fs: missing callback ' + (err.stack || err.message); - if (process.traceDeprecation) - console.trace(msg); - else - console.error(msg); + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } + + obj = block(key, value); + + if (obj !== false && obj !== nil) { + if ($hash_delete(self, key) !== undefined) { + length--; + i--; + } + } } - } - } -} -function maybeCallback(cb) { - return typeof cb === 'function' ? cb : rethrow(); -} + return self; + }); + + $def(self, '$dig', function $$dig(key, $a) { + var $post_args, keys, self = this, item = nil; -var normalize = pathModule.normalize; + + $post_args = $slice(arguments, 1); + keys = $post_args; + item = self['$[]'](key); + + if (item === nil || keys.length === 0) { + return item; + } + if (!$truthy(item['$respond_to?']("dig"))) { + $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method"); + } return $send(item, 'dig', $to_a(keys)); + }, -2); + + $def(self, '$each', function $$each() { + var block = $$each.$$p || nil, self = this; -// Regexp that finds the next partion of a (partial) path -// result is [base_with_slash, base], e.g. ['somedir/', 'somedir'] -if (isWindows) { - var nextPartRe = /(.*?)(?:[\/\\]+|$)/g; -} else { - var nextPartRe = /(.*?)(?:[\/]+|$)/g; -} + $$each.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["each"], function $$17(){var self = $$17.$$s == null ? this : $$17.$$s; -// Regex to find the device root, including trailing slash. E.g. 'c:\\'. -if (isWindows) { - var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/; -} else { - var splitRootRe = /^[\/]*/; -} + return self.$size()}, {$$s: self}) + } + for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key, value; i < length; i++) { + key = keys[i]; -exports.realpathSync = function realpathSync(p, cache) { - // make p is absolute - p = pathModule.resolve(p); + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return cache[p]; - } + $yield1(block, [key, value]); + } - var original = p, - seenLinks = {}, - knownHard = {}; + return self; + }); + + $def(self, '$each_key', function $$each_key() { + var block = $$each_key.$$p || nil, self = this; - // current character position in p - var pos; - // the partial path so far, including a trailing slash if any - var current; - // the partial path without a trailing slash (except when pointing at a root) - var base; - // the partial path scanned in the previous round, with slash - var previous; + $$each_key.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["each_key"], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s; - start(); + return self.$size()}, {$$s: self}) + } + for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key; i < length; i++) { + key = keys[i]; - function start() { - // Skip over roots - var m = splitRootRe.exec(p); - pos = m[0].length; - current = m[0]; - base = m[0]; - previous = ''; + block(key.$$is_string ? key : key.key); + } - // On windows, check that the root exists. On unix there is no need. - if (isWindows && !knownHard[base]) { - fs.lstatSync(base); - knownHard[base] = true; - } - } + return self; + }); + + $def(self, '$each_value', function $$each_value() { + var block = $$each_value.$$p || nil, self = this; - // walk down the path, swapping out linked pathparts for their real - // values - // NB: p.length changes. - while (pos < p.length) { - // find the next part - nextPartRe.lastIndex = pos; - var result = nextPartRe.exec(p); - previous = current; - current += result[0]; - base = previous + result[1]; - pos = nextPartRe.lastIndex; + $$each_value.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["each_value"], function $$19(){var self = $$19.$$s == null ? this : $$19.$$s; - // continue if not a symlink - if (knownHard[base] || (cache && cache[base] === base)) { - continue; - } + return self.$size()}, {$$s: self}) + } + for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key; i < length; i++) { + key = keys[i]; - var resolvedLink; - if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { - // some known symbolic link. no need to stat again. - resolvedLink = cache[base]; - } else { - var stat = fs.lstatSync(base); - if (!stat.isSymbolicLink()) { - knownHard[base] = true; - if (cache) cache[base] = base; - continue; + block(key.$$is_string ? self.$$smap[key] : key.value); } - // read the link if it wasn't read before - // dev/ino always return 0 on windows, so skip the check. - var linkTarget = null; - if (!isWindows) { - var id = stat.dev.toString(32) + ':' + stat.ino.toString(32); - if (seenLinks.hasOwnProperty(id)) { - linkTarget = seenLinks[id]; - } - } - if (linkTarget === null) { - fs.statSync(base); - linkTarget = fs.readlinkSync(base); - } - resolvedLink = pathModule.resolve(previous, linkTarget); - // track this, if given a cache. - if (cache) cache[base] = resolvedLink; - if (!isWindows) seenLinks[id] = linkTarget; - } + return self; + }); + + $def(self, '$empty?', function $Hash_empty$ques$20() { + var self = this; - // resolve the link, then start over - p = pathModule.resolve(resolvedLink, p.slice(pos)); - start(); - } + return self.$$keys.length === 0; + }); + + $def(self, '$except', function $$except($a) { + var $post_args, keys, self = this; - if (cache) cache[original] = p; + + $post_args = $slice(arguments); + keys = $post_args; + return $send(self.$dup(), 'except!', $to_a(keys)); + }, -1); + + $def(self, '$except!', function $Hash_except$excl$21($a) { + var $post_args, keys, self = this; - return p; -}; + + $post_args = $slice(arguments); + keys = $post_args; + $send(keys, 'each', [], function $$22(key){var self = $$22.$$s == null ? this : $$22.$$s; + + if (key == null) key = nil; + return self.$delete(key);}, {$$s: self}); + return self; + }, -1); + + $def(self, '$fetch', function $$fetch(key, defaults) { + var block = $$fetch.$$p || nil, self = this; -exports.realpath = function realpath(p, cache, cb) { - if (typeof cb !== 'function') { - cb = maybeCallback(cache); - cache = null; - } + $$fetch.$$p = null; + + var value = $hash_get(self, key); - // make p is absolute - p = pathModule.resolve(p); + if (value !== undefined) { + return value; + } - if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { - return process.nextTick(cb.bind(null, null, cache[p])); - } + if (block !== nil) { + return block(key); + } - var original = p, - seenLinks = {}, - knownHard = {}; + if (defaults !== undefined) { + return defaults; + } + return $Kernel.$raise($$$('KeyError').$new("key not found: " + (key.$inspect()), $hash2(["key", "receiver"], {"key": key, "receiver": self}))); + }, -2); + + $def(self, '$fetch_values', function $$fetch_values($a) { + var block = $$fetch_values.$$p || nil, $post_args, keys, self = this; - // current character position in p - var pos; - // the partial path so far, including a trailing slash if any - var current; - // the partial path without a trailing slash (except when pointing at a root) - var base; - // the partial path scanned in the previous round, with slash - var previous; + $$fetch_values.$$p = null; + $post_args = $slice(arguments); + keys = $post_args; + return $send(keys, 'map', [], function $$23(key){var self = $$23.$$s == null ? this : $$23.$$s; - start(); + + if (key == null) key = nil; + return $send(self, 'fetch', [key], block.$to_proc());}, {$$s: self}); + }, -1); + + $def(self, '$flatten', function $$flatten(level) { + var self = this; - function start() { - // Skip over roots - var m = splitRootRe.exec(p); - pos = m[0].length; - current = m[0]; - base = m[0]; - previous = ''; + + if (level == null) level = 1; + level = $Opal['$coerce_to!'](level, $$$('Integer'), "to_int"); + + var result = []; - // On windows, check that the root exists. On unix there is no need. - if (isWindows && !knownHard[base]) { - fs.lstat(base, function(err) { - if (err) return cb(err); - knownHard[base] = true; - LOOP(); - }); - } else { - process.nextTick(LOOP); - } - } + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - // walk down the path, swapping out linked pathparts for their real - // values - function LOOP() { - // stop if scanned past end of path - if (pos >= p.length) { - if (cache) cache[original] = p; - return cb(null, p); - } + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - // find the next part - nextPartRe.lastIndex = pos; - var result = nextPartRe.exec(p); - previous = current; - current += result[0]; - base = previous + result[1]; - pos = nextPartRe.lastIndex; + result.push(key); - // continue if not a symlink - if (knownHard[base] || (cache && cache[base] === base)) { - return process.nextTick(LOOP); - } + if (value.$$is_array) { + if (level === 1) { + result.push(value); + continue; + } - if (cache && Object.prototype.hasOwnProperty.call(cache, base)) { - // known symbolic link. no need to stat again. - return gotResolvedLink(cache[base]); - } + result = result.concat((value).$flatten(level - 2)); + continue; + } - return fs.lstat(base, gotStat); - } + result.push(value); + } - function gotStat(err, stat) { - if (err) return cb(err); + return result; + }, -1); + + $def(self, '$freeze', function $$freeze() { + var self = this; - // if not a symlink, skip to the next path part - if (!stat.isSymbolicLink()) { - knownHard[base] = true; - if (cache) cache[base] = base; - return process.nextTick(LOOP); - } + + if ($truthy(self['$frozen?']())) { + return self + } return $freeze(self); }); + + $def(self, '$has_key?', function $Hash_has_key$ques$24(key) { + var self = this; - // stat & read the link if not read before - // call gotTarget as soon as the link target is known - // dev/ino always return 0 on windows, so skip the check. - if (!isWindows) { - var id = stat.dev.toString(32) + ':' + stat.ino.toString(32); - if (seenLinks.hasOwnProperty(id)) { - return gotTarget(null, seenLinks[id], base); + return $hash_get(self, key) !== undefined; + }); + + $def(self, '$has_value?', function $Hash_has_value$ques$25(value) { + var self = this; + + + for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { + key = keys[i]; + + if (((key.$$is_string ? self.$$smap[key] : key.value))['$=='](value)) { + return true; + } } - } - fs.stat(base, function(err) { - if (err) return cb(err); - fs.readlink(base, function(err, target) { - if (!isWindows) seenLinks[id] = target; - gotTarget(err, target); - }); + return false; + }); - } + + $def(self, '$hash', function $$hash() { + var self = this; - function gotTarget(err, target, base) { - if (err) return cb(err); + + var top = (Opal.hash_ids === undefined), + hash_id = self.$object_id(), + result = ['Hash'], + key, item; - var resolvedLink = pathModule.resolve(previous, target); - if (cache) cache[base] = resolvedLink; - gotResolvedLink(resolvedLink); - } + try { + if (top) { + Opal.hash_ids = Object.create(null); + } - function gotResolvedLink(resolvedLink) { - // resolve the link, then start over - p = pathModule.resolve(resolvedLink, p.slice(pos)); - start(); - } -}; + if (Opal[hash_id]) { + return 'self'; + } + for (key in Opal.hash_ids) { + item = Opal.hash_ids[key]; + if (self['$eql?'](item)) { + return 'self'; + } + } -/***/ }), + Opal.hash_ids[hash_id] = self; -/***/ 7625: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + for (var i = 0, keys = self.$$keys, length = keys.length; i < length; i++) { + key = keys[i]; -exports.alphasort = alphasort -exports.alphasorti = alphasorti -exports.setopts = setopts -exports.ownProp = ownProp -exports.makeAbs = makeAbs -exports.finish = finish -exports.mark = mark -exports.isIgnored = isIgnored -exports.childrenIgnored = childrenIgnored + if (key.$$is_string) { + result.push([key, self.$$smap[key].$hash()]); + } else { + result.push([key.key_hash, key.value.$hash()]); + } + } -function ownProp (obj, field) { - return Object.prototype.hasOwnProperty.call(obj, field) -} + return result.sort().join(); -var path = __nccwpck_require__(1017) -var minimatch = __nccwpck_require__(3973) -var isAbsolute = __nccwpck_require__(8714) -var Minimatch = minimatch.Minimatch + } finally { + if (top) { + Opal.hash_ids = undefined; + } + } + + }); + + $def(self, '$index', function $$index(object) { + var self = this; -function alphasorti (a, b) { - return a.toLowerCase().localeCompare(b.toLowerCase()) -} + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; -function alphasort (a, b) { - return a.localeCompare(b) -} + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } -function setupIgnores (self, options) { - self.ignore = options.ignore || [] + if ((value)['$=='](object)) { + return key; + } + } - if (!Array.isArray(self.ignore)) - self.ignore = [self.ignore] + return nil; + + }); + + $def(self, '$indexes', function $$indexes($a) { + var $post_args, args, self = this; - if (self.ignore.length) { - self.ignore = self.ignore.map(ignoreMap) - } -} + + $post_args = $slice(arguments); + args = $post_args; + + var result = []; -// ignore patterns are always in dot:true mode. -function ignoreMap (pattern) { - var gmatcher = null - if (pattern.slice(-3) === '/**') { - var gpattern = pattern.replace(/(\/\*\*)+$/, '') - gmatcher = new Minimatch(gpattern, { dot: true }) - } + for (var i = 0, length = args.length, key, value; i < length; i++) { + key = args[i]; + value = $hash_get(self, key); - return { - matcher: new Minimatch(pattern, { dot: true }), - gmatcher: gmatcher - } -} + if (value === undefined) { + result.push(self.$default()); + continue; + } -function setopts (self, pattern, options) { - if (!options) - options = {} + result.push(value); + } - // base-matching: just use globstar for that. - if (options.matchBase && -1 === pattern.indexOf("/")) { - if (options.noglobstar) { - throw new Error("base matching requires globstar") - } - pattern = "**/" + pattern - } + return result; + }, -1); + var inspect_ids; + + $def(self, '$inspect', function $$inspect() { + var self = this; - self.silent = !!options.silent - self.pattern = pattern - self.strict = options.strict !== false - self.realpath = !!options.realpath - self.realpathCache = options.realpathCache || Object.create(null) - self.follow = !!options.follow - self.dot = !!options.dot - self.mark = !!options.mark - self.nodir = !!options.nodir - if (self.nodir) - self.mark = true - self.sync = !!options.sync - self.nounique = !!options.nounique - self.nonull = !!options.nonull - self.nosort = !!options.nosort - self.nocase = !!options.nocase - self.stat = !!options.stat - self.noprocess = !!options.noprocess - self.absolute = !!options.absolute + + + var top = (inspect_ids === undefined), + hash_id = self.$object_id(), + result = []; + + return (function() { try { + + + if (top) { + inspect_ids = {}; + } - self.maxLength = options.maxLength || Infinity - self.cache = options.cache || Object.create(null) - self.statCache = options.statCache || Object.create(null) - self.symlinks = options.symlinks || Object.create(null) + if (inspect_ids.hasOwnProperty(hash_id)) { + return '{...}'; + } - setupIgnores(self, options) + inspect_ids[hash_id] = true; - self.changedCwd = false - var cwd = process.cwd() - if (!ownProp(options, "cwd")) - self.cwd = cwd - else { - self.cwd = path.resolve(options.cwd) - self.changedCwd = self.cwd !== cwd - } + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - self.root = options.root || path.resolve(self.cwd, "/") - self.root = path.resolve(self.root) - if (process.platform === "win32") - self.root = self.root.replace(/\\/g, "/") + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - // TODO: is an absolute `cwd` supposed to be resolved against `root`? - // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test') - self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd) - if (process.platform === "win32") - self.cwdAbs = self.cwdAbs.replace(/\\/g, "/") - self.nomount = !!options.nomount + key = $$('Opal').$inspect(key); + value = $$('Opal').$inspect(value); - // disable comments and negation in Minimatch. - // Note that they are not supported in Glob itself anyway. - options.nonegate = true - options.nocomment = true + result.push(key + '=>' + value); + } - self.minimatch = new Minimatch(pattern, options) - self.options = self.minimatch.options -} + return '{' + result.join(', ') + '}'; + ; + return nil; + } finally { + if (top) inspect_ids = undefined; + } })(); }); + + $def(self, '$invert', function $$invert() { + var self = this; -function finish (self) { - var nou = self.nounique - var all = nou ? [] : Object.create(null) + + var hash = $hash(); - for (var i = 0, l = self.matches.length; i < l; i ++) { - var matches = self.matches[i] - if (!matches || Object.keys(matches).length === 0) { - if (self.nonull) { - // do like the shell, and spit out the literal glob - var literal = self.minimatch.globSet[i] - if (nou) - all.push(literal) - else - all[literal] = true - } - } else { - // had matches - var m = Object.keys(matches) - if (nou) - all.push.apply(all, m) - else - m.forEach(function (m) { - all[m] = true - }) - } - } + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - if (!nou) - all = Object.keys(all) + $hash_put(hash, value, key); + } - if (!self.nosort) - all = all.sort(self.nocase ? alphasorti : alphasort) + return hash; + + }); + + $def(self, '$keep_if', function $$keep_if() { + var block = $$keep_if.$$p || nil, self = this; - // at *some* point we statted all of these - if (self.mark) { - for (var i = 0; i < all.length; i++) { - all[i] = self._mark(all[i]) - } - if (self.nodir) { - all = all.filter(function (e) { - var notDir = !(/\/$/.test(e)) - var c = self.cache[e] || self.cache[makeAbs(self, e)] - if (notDir && c) - notDir = c !== 'DIR' && !Array.isArray(c) - return notDir - }) - } - } + $$keep_if.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["keep_if"], function $$26(){var self = $$26.$$s == null ? this : $$26.$$s; - if (self.ignore.length) - all = all.filter(function(m) { - return !isIgnored(self, m) - }) + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); - self.found = all -} + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; -function mark (self, p) { - var abs = makeAbs(self, p) - var c = self.cache[abs] - var m = p - if (c) { - var isDir = c === 'DIR' || Array.isArray(c) - var slash = p.slice(-1) === '/' + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - if (isDir && !slash) - m += '/' - else if (!isDir && slash) - m = m.slice(0, -1) + obj = block(key, value); - if (m !== p) { - var mabs = makeAbs(self, m) - self.statCache[mabs] = self.statCache[abs] - self.cache[mabs] = self.cache[abs] - } - } + if (obj === false || obj === nil) { + if ($hash_delete(self, key) !== undefined) { + length--; + i--; + } + } + } - return m -} + return self; + }); + + $def(self, '$keys', function $$keys() { + var self = this; -// lotta situps... -function makeAbs (self, f) { - var abs = f - if (f.charAt(0) === '/') { - abs = path.join(self.root, f) - } else if (isAbsolute(f) || f === '') { - abs = f - } else if (self.changedCwd) { - abs = path.resolve(self.cwd, f) - } else { - abs = path.resolve(f) - } + + var result = []; - if (process.platform === 'win32') - abs = abs.replace(/\\/g, '/') + for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { + key = keys[i]; - return abs -} + if (key.$$is_string) { + result.push(key); + } else { + result.push(key.key); + } + } + return result; + + }); + + $def(self, '$length', function $$length() { + var self = this; -// Return true, if pattern ends with globstar '**', for the accompanying parent directory. -// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents -function isIgnored (self, path) { - if (!self.ignore.length) - return false + return self.$$keys.length; + }); + + $def(self, '$merge', function $$merge($a) { + var block = $$merge.$$p || nil, $post_args, others, self = this; - return self.ignore.some(function(item) { - return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path)) - }) -} + $$merge.$$p = null; + $post_args = $slice(arguments); + others = $post_args; + return $send(self.$dup(), 'merge!', $to_a(others), block.$to_proc()); + }, -1); + + $def(self, '$merge!', function $Hash_merge$excl$27($a) { + var block = $Hash_merge$excl$27.$$p || nil, $post_args, others, self = this; -function childrenIgnored (self, path) { - if (!self.ignore.length) - return false + $Hash_merge$excl$27.$$p = null; + $post_args = $slice(arguments); + others = $post_args; + + $deny_frozen_access(self); + var i, j, other, other_keys, length, key, value, other_value; + for (i = 0; i < others.length; ++i) { + other = $Opal['$coerce_to!'](others[i], $$$('Hash'), "to_hash"); + other_keys = other.$$keys, length = other_keys.length; - return self.ignore.some(function(item) { - return !!(item.gmatcher && item.gmatcher.match(path)) - }) -} + if (block === nil) { + for (j = 0; j < length; j++) { + key = other_keys[j]; + if (key.$$is_string) { + other_value = other.$$smap[key]; + } else { + other_value = key.value; + key = key.key; + } -/***/ }), + $hash_put(self, key, other_value); + } + } else { + for (j = 0; j < length; j++) { + key = other_keys[j]; -/***/ 1957: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + if (key.$$is_string) { + other_value = other.$$smap[key]; + } else { + other_value = key.value; + key = key.key; + } -// Approach: -// -// 1. Get the minimatch set -// 2. For each pattern in the set, PROCESS(pattern, false) -// 3. Store matches per-set, then uniq them -// -// PROCESS(pattern, inGlobStar) -// Get the first [n] items from pattern that are all strings -// Join these together. This is PREFIX. -// If there is no more remaining, then stat(PREFIX) and -// add to matches if it succeeds. END. -// -// If inGlobStar and PREFIX is symlink and points to dir -// set ENTRIES = [] -// else readdir(PREFIX) as ENTRIES -// If fail, END -// -// with ENTRIES -// If pattern[n] is GLOBSTAR -// // handle the case where the globstar match is empty -// // by pruning it out, and testing the resulting pattern -// PROCESS(pattern[0..n] + pattern[n+1 .. $], false) -// // handle other cases. -// for ENTRY in ENTRIES (not dotfiles) -// // attach globstar + tail onto the entry -// // Mark that this entry is a globstar match -// PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true) -// -// else // not globstar -// for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot) -// Test ENTRY against pattern[n] -// If fails, continue -// If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $]) -// -// Caveat: -// Cache all stats and readdirs results to minimize syscall. Since all -// we ever care about is existence and directory-ness, we can just keep -// `true` for files, and [children,...] for directories, or `false` for -// things that don't exist. + value = $hash_get(self, key); -module.exports = glob + if (value === undefined) { + $hash_put(self, key, other_value); + continue; + } -var fs = __nccwpck_require__(7147) -var rp = __nccwpck_require__(6863) -var minimatch = __nccwpck_require__(3973) -var Minimatch = minimatch.Minimatch -var inherits = __nccwpck_require__(4124) -var EE = (__nccwpck_require__(2361).EventEmitter) -var path = __nccwpck_require__(1017) -var assert = __nccwpck_require__(9491) -var isAbsolute = __nccwpck_require__(8714) -var globSync = __nccwpck_require__(9010) -var common = __nccwpck_require__(7625) -var alphasort = common.alphasort -var alphasorti = common.alphasorti -var setopts = common.setopts -var ownProp = common.ownProp -var inflight = __nccwpck_require__(2492) -var util = __nccwpck_require__(3837) -var childrenIgnored = common.childrenIgnored -var isIgnored = common.isIgnored + $hash_put(self, key, block(key, value, other_value)); + } + } + } -var once = __nccwpck_require__(1223) + return self; + }, -1); + + $def(self, '$rassoc', function $$rassoc(object) { + var self = this; -function glob (pattern, options, cb) { - if (typeof options === 'function') cb = options, options = {} - if (!options) options = {} + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - if (options.sync) { - if (cb) - throw new TypeError('callback provided to sync glob') - return globSync(pattern, options) - } + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - return new Glob(pattern, options, cb) -} + if ((value)['$=='](object)) { + return [key, value]; + } + } -glob.sync = globSync -var GlobSync = glob.GlobSync = globSync.GlobSync + return nil; + + }); + + $def(self, '$rehash', function $$rehash() { + var self = this; -// old api surface -glob.glob = glob + + $deny_frozen_access(self); + Opal.hash_rehash(self); + return self; + + }); + + $def(self, '$reject', function $$reject() { + var block = $$reject.$$p || nil, self = this; -function extend (origin, add) { - if (add === null || typeof add !== 'object') { - return origin - } + $$reject.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["reject"], function $$28(){var self = $$28.$$s == null ? this : $$28.$$s; - var keys = Object.keys(add) - var i = keys.length - while (i--) { - origin[keys[i]] = add[keys[i]] - } - return origin -} + return self.$size()}, {$$s: self}) + } + var hash = $hash(); -glob.hasMagic = function (pattern, options_) { - var options = extend({}, options_) - options.noprocess = true + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; - var g = new Glob(pattern, options) - var set = g.minimatch.set + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - if (!pattern) - return false + obj = block(key, value); - if (set.length > 1) - return true + if (obj === false || obj === nil) { + $hash_put(hash, key, value); + } + } - for (var j = 0; j < set[0].length; j++) { - if (typeof set[0][j] !== 'string') - return true - } + return hash; + }); + + $def(self, '$reject!', function $Hash_reject$excl$29() { + var block = $Hash_reject$excl$29.$$p || nil, self = this; - return false -} + $Hash_reject$excl$29.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["reject!"], function $$30(){var self = $$30.$$s == null ? this : $$30.$$s; -glob.Glob = Glob -inherits(Glob, EE) -function Glob (pattern, options, cb) { - if (typeof options === 'function') { - cb = options - options = null - } + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); - if (options && options.sync) { - if (cb) - throw new TypeError('callback provided to sync glob') - return new GlobSync(pattern, options) - } + var changes_were_made = false; - if (!(this instanceof Glob)) - return new Glob(pattern, options, cb) + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; - setopts(this, pattern, options) - this._didRealPath = false + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - // process each pattern in the minimatch set - var n = this.minimatch.set.length + obj = block(key, value); - // The matches are stored as {<filename>: true,...} so that - // duplicates are automagically pruned. - // Later, we do an Object.keys() on these. - // Keep them as a list so we can fill in when nonull is set. - this.matches = new Array(n) + if (obj !== false && obj !== nil) { + if ($hash_delete(self, key) !== undefined) { + changes_were_made = true; + length--; + i--; + } + } + } - if (typeof cb === 'function') { - cb = once(cb) - this.on('error', cb) - this.on('end', function (matches) { - cb(null, matches) - }) - } + return changes_were_made ? self : nil; + }); + + $def(self, '$replace', function $$replace(other) { + var self = this; - var self = this - this._processing = 0 + + $deny_frozen_access(self); other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash"); + + $hash_init(self); - this._emitQueue = [] - this._processQueue = [] - this.paused = false + for (var i = 0, other_keys = other.$$keys, length = other_keys.length, key, value, other_value; i < length; i++) { + key = other_keys[i]; - if (this.noprocess) - return this + if (key.$$is_string) { + other_value = other.$$smap[key]; + } else { + other_value = key.value; + key = key.key; + } - if (n === 0) - return done() + $hash_put(self, key, other_value); + } + if ($truthy(other.$default_proc())) { + self['$default_proc='](other.$default_proc()); + } else { + self['$default='](other.$default()); + } return self; + }); + + $def(self, '$select', function $$select() { + var block = $$select.$$p || nil, self = this; - var sync = true - for (var i = 0; i < n; i ++) { - this._process(this.minimatch.set[i], i, false, done) - } - sync = false + $$select.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["select"], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s; - function done () { - --self._processing - if (self._processing <= 0) { - if (sync) { - process.nextTick(function () { - self._finish() - }) - } else { - self._finish() + return self.$size()}, {$$s: self}) + } + var hash = $hash(); + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } + + obj = block(key, value); + + if (obj !== false && obj !== nil) { + $hash_put(hash, key, value); + } } - } - } -} -Glob.prototype._finish = function () { - assert(this instanceof Glob) - if (this.aborted) - return + return hash; + }); + + $def(self, '$select!', function $Hash_select$excl$32() { + var block = $Hash_select$excl$32.$$p || nil, self = this; - if (this.realpath && !this._didRealpath) - return this._realpath() + $Hash_select$excl$32.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["select!"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s; - common.finish(this) - this.emit('end', this.found) -} + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); -Glob.prototype._realpath = function () { - if (this._didRealpath) - return + var result = nil; - this._didRealpath = true + for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) { + key = keys[i]; - var n = this.matches.length - if (n === 0) - return this._finish() + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - var self = this - for (var i = 0; i < this.matches.length; i++) - this._realpathSet(i, next) + obj = block(key, value); - function next () { - if (--n === 0) - self._finish() - } -} + if (obj === false || obj === nil) { + if ($hash_delete(self, key) !== undefined) { + length--; + i--; + } + result = self; + } + } -Glob.prototype._realpathSet = function (index, cb) { - var matchset = this.matches[index] - if (!matchset) - return cb() + return result; + }); + + $def(self, '$shift', function $$shift() { + var self = this; - var found = Object.keys(matchset) - var self = this - var n = found.length + + $deny_frozen_access(self); + var keys = self.$$keys, + key; - if (n === 0) - return cb() + if (keys.length > 0) { + key = keys[0]; - var set = this.matches[index] = Object.create(null) - found.forEach(function (p, i) { - // If there's a problem with the stat, then it means that - // one or more of the links in the realpath couldn't be - // resolved. just return the abs value in that case. - p = self._makeAbs(p) - rp.realpath(p, self.realpathCache, function (er, real) { - if (!er) - set[real] = true - else if (er.syscall === 'stat') - set[p] = true - else - self.emit('error', er) // srsly wtf right here + key = key.$$is_string ? key : key.key; - if (--n === 0) { - self.matches[index] = set - cb() + return [key, $hash_delete(self, key)]; } - }) - }) -} - -Glob.prototype._mark = function (p) { - return common.mark(this, p) -} -Glob.prototype._makeAbs = function (f) { - return common.makeAbs(this, f) -} + return nil; + + }); + + $def(self, '$slice', function $$slice($a) { + var $post_args, keys, self = this; -Glob.prototype.abort = function () { - this.aborted = true - this.emit('abort') -} + + $post_args = $slice(arguments); + keys = $post_args; + + var result = $hash(); -Glob.prototype.pause = function () { - if (!this.paused) { - this.paused = true - this.emit('pause') - } -} + for (var i = 0, length = keys.length; i < length; i++) { + var key = keys[i], value = $hash_get(self, key); -Glob.prototype.resume = function () { - if (this.paused) { - this.emit('resume') - this.paused = false - if (this._emitQueue.length) { - var eq = this._emitQueue.slice(0) - this._emitQueue.length = 0 - for (var i = 0; i < eq.length; i ++) { - var e = eq[i] - this._emitMatch(e[0], e[1]) + if (value !== undefined) { + $hash_put(result, key, value); + } } - } - if (this._processQueue.length) { - var pq = this._processQueue.slice(0) - this._processQueue.length = 0 - for (var i = 0; i < pq.length; i ++) { - var p = pq[i] - this._processing-- - this._process(p[0], p[1], p[2], p[3]) + + return result; + }, -1); + + $def(self, '$to_a', function $$to_a() { + var self = this; + + + var result = []; + + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; + + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } + + result.push([key, value]); } - } - } -} -Glob.prototype._process = function (pattern, index, inGlobStar, cb) { - assert(this instanceof Glob) - assert(typeof cb === 'function') + return result; + + }); + + $def(self, '$to_h', function $$to_h() { + var block = $$to_h.$$p || nil, self = this; - if (this.aborted) - return + $$to_h.$$p = null; + if ((block !== nil)) { + return $send(self, 'map', [], block.$to_proc()).$to_h() + } + if (self.$$class === Opal.Hash) { + return self; + } - this._processing++ - if (this.paused) { - this._processQueue.push([pattern, index, inGlobStar, cb]) - return - } + var hash = new Opal.Hash(); - //console.error('PROCESS %d', this._processing, pattern) + $hash_init(hash); + Opal.hash_clone(self, hash); - // Get the first [n] parts of pattern that are all strings. - var n = 0 - while (typeof pattern[n] === 'string') { - n ++ - } - // now n is the index of the first one that is *not* a string. + return hash; + }); + + $def(self, '$to_hash', $return_self); + + $def(self, '$to_proc', function $$to_proc() { + var self = this; - // see if there's anything else - var prefix - switch (n) { - // if not, then this is rather simple - case pattern.length: - this._processSimple(pattern.join('/'), index, cb) - return + return $send(self, 'proc', [], function $$34(key){var self = $$34.$$s == null ? this : $$34.$$s; + + if (key == null) { + $Kernel.$raise($$$('ArgumentError'), "no key given"); + } + return self['$[]'](key);}, {$$arity: -1, $$s: self}) + }); + + $def(self, '$transform_keys', function $$transform_keys() { + var block = $$transform_keys.$$p || nil, self = this; - case 0: - // pattern *starts* with some non-trivial item. - // going to readdir(cwd), but not include the prefix in matches. - prefix = null - break + $$transform_keys.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["transform_keys"], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s; - default: - // pattern has some string bits in the front. - // whatever it starts with, whether that's 'absolute' like /foo/bar, - // or 'relative' like '../baz' - prefix = pattern.slice(0, n).join('/') - break - } + return self.$size()}, {$$s: self}) + } + var result = $hash(); - var remain = pattern.slice(n) + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - // get the list of entries. - var read - if (prefix === null) - read = '.' - else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) { - if (!prefix || !isAbsolute(prefix)) - prefix = '/' + prefix - read = prefix - } else - read = prefix + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - var abs = this._makeAbs(read) + key = $yield1(block, key); - //if ignored, skip _processing - if (childrenIgnored(this, read)) - return cb() + $hash_put(result, key, value); + } - var isGlobStar = remain[0] === minimatch.GLOBSTAR - if (isGlobStar) - this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb) - else - this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb) -} + return result; + }); + + $def(self, '$transform_keys!', function $Hash_transform_keys$excl$36() { + var block = $Hash_transform_keys$excl$36.$$p || nil, self = this; -Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) { - var self = this - this._readdir(abs, inGlobStar, function (er, entries) { - return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb) - }) -} + $Hash_transform_keys$excl$36.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["transform_keys!"], function $$37(){var self = $$37.$$s == null ? this : $$37.$$s; -Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) { + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); - // if the abs isn't a dir, then nothing can match! - if (!entries) - return cb() + var keys = Opal.slice(self.$$keys), + i, length = keys.length, key, value, new_key; - // It will only match dot entries if it starts with a dot, or if - // dot is set. Stuff like @(.foo|.bar) isn't allowed. - var pn = remain[0] - var negate = !!this.minimatch.negate - var rawGlob = pn._glob - var dotOk = this.dot || rawGlob.charAt(0) === '.' + for (i = 0; i < length; i++) { + key = keys[i]; - var matchedEntries = [] - for (var i = 0; i < entries.length; i++) { - var e = entries[i] - if (e.charAt(0) !== '.' || dotOk) { - var m - if (negate && !prefix) { - m = !e.match(pn) - } else { - m = e.match(pn) - } - if (m) - matchedEntries.push(e) - } - } + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries) + new_key = $yield1(block, key); - var len = matchedEntries.length - // If there are no matched entries, then nothing matches. - if (len === 0) - return cb() + $hash_delete(self, key); + $hash_put(self, new_key, value); + } - // if this is the last remaining pattern bit, then no need for - // an additional stat *unless* the user has specified mark or - // stat explicitly. We know they exist, since readdir returned - // them. + return self; + }); + + $def(self, '$transform_values', function $$transform_values() { + var block = $$transform_values.$$p || nil, self = this; - if (remain.length === 1 && !this.mark && !this.stat) { - if (!this.matches[index]) - this.matches[index] = Object.create(null) + $$transform_values.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["transform_values"], function $$38(){var self = $$38.$$s == null ? this : $$38.$$s; - for (var i = 0; i < len; i ++) { - var e = matchedEntries[i] - if (prefix) { - if (prefix !== '/') - e = prefix + '/' + e - else - e = prefix + e - } + return self.$size()}, {$$s: self}) + } + var result = $hash(); - if (e.charAt(0) === '/' && !this.nomount) { - e = path.join(this.root, e) - } - this._emitMatch(index, e) - } - // This was the last one, and no stats were needed - return cb() - } + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - // now test all matched entries as stand-ins for that part - // of the pattern. - remain.shift() - for (var i = 0; i < len; i ++) { - var e = matchedEntries[i] - var newPattern - if (prefix) { - if (prefix !== '/') - e = prefix + '/' + e - else - e = prefix + e - } - this._process([e].concat(remain), index, inGlobStar, cb) - } - cb() -} + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } -Glob.prototype._emitMatch = function (index, e) { - if (this.aborted) - return + value = $yield1(block, value); - if (isIgnored(this, e)) - return + $hash_put(result, key, value); + } - if (this.paused) { - this._emitQueue.push([index, e]) - return - } + return result; + }); + + $def(self, '$transform_values!', function $Hash_transform_values$excl$39() { + var block = $Hash_transform_values$excl$39.$$p || nil, self = this; - var abs = isAbsolute(e) ? e : this._makeAbs(e) + $Hash_transform_values$excl$39.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["transform_values!"], function $$40(){var self = $$40.$$s == null ? this : $$40.$$s; - if (this.mark) - e = this._mark(e) + return self.$size()}, {$$s: self}) + } + $deny_frozen_access(self); - if (this.absolute) - e = abs + for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) { + key = keys[i]; - if (this.matches[index][e]) - return + if (key.$$is_string) { + value = self.$$smap[key]; + } else { + value = key.value; + key = key.key; + } - if (this.nodir) { - var c = this.cache[abs] - if (c === 'DIR' || Array.isArray(c)) - return - } + value = $yield1(block, value); - this.matches[index][e] = true + $hash_put(self, key, value); + } - var st = this.statCache[abs] - if (st) - this.emit('stat', e, st) + return self; + }); + + $def(self, '$values', function $$values() { + var self = this; - this.emit('match', e) -} + + var result = []; -Glob.prototype._readdirInGlobStar = function (abs, cb) { - if (this.aborted) - return + for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) { + key = keys[i]; - // follow all symlinked directories forever - // just proceed as if this is a non-globstar situation - if (this.follow) - return this._readdir(abs, false, cb) + if (key.$$is_string) { + result.push(self.$$smap[key]); + } else { + result.push(key.value); + } + } - var lstatkey = 'lstat\0' + abs - var self = this - var lstatcb = inflight(lstatkey, lstatcb_) + return result; + + }); + $alias(self, "dup", "clone"); + $alias(self, "each_pair", "each"); + $alias(self, "eql?", "=="); + $alias(self, "filter", "select"); + $alias(self, "filter!", "select!"); + $alias(self, "include?", "has_key?"); + $alias(self, "indices", "indexes"); + $alias(self, "key", "index"); + $alias(self, "key?", "has_key?"); + $alias(self, "member?", "has_key?"); + $alias(self, "size", "length"); + $alias(self, "store", "[]="); + $alias(self, "to_s", "inspect"); + $alias(self, "update", "merge!"); + $alias(self, "value?", "has_value?"); + return $alias(self, "values_at", "indexes"); + })('::', null, $nesting); +}; - if (lstatcb) - fs.lstat(abs, lstatcb) +Opal.modules["corelib/number"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $not = Opal.not, $rb_lt = Opal.rb_lt, $alias = Opal.alias, $send2 = Opal.send2, $find_super = Opal.find_super, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $eqeq = Opal.eqeq, $return_self = Opal.return_self, $rb_divide = Opal.rb_divide, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $rb_le = Opal.rb_le, $rb_ge = Opal.rb_ge, $return_val = Opal.return_val, $const_set = Opal.const_set, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - function lstatcb_ (er, lstat) { - if (er && er.code === 'ENOENT') - return cb() + Opal.add_stubs('require,bridge,raise,name,class,Float,respond_to?,coerce_to!,__coerced__,===,>,!,**,new,<,to_f,==,nan?,infinite?,enum_for,+,-,gcd,lcm,%,/,frexp,to_i,ldexp,rationalize,*,<<,to_r,truncate,-@,size,<=,>=,inspect,angle,to_s,is_a?,abs,__id__,next,coerce_to?'); + + self.$require("corelib/numeric"); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Number'); - var isSym = lstat && lstat.isSymbolicLink() - self.symlinks[abs] = isSym + + $Opal.$bridge(Number, self); + Opal.prop(self.$$prototype, '$$is_number', true); + self.$$is_number_class = true; + (function(self, $parent_nesting) { + + + + $def(self, '$allocate', function $$allocate() { + var self = this; - // If it's not a symlink or a dir, then it's definitely a regular file. - // don't bother doing a readdir in that case. - if (!isSym && lstat && !lstat.isDirectory()) { - self.cache[abs] = 'FILE' - cb() - } else - self._readdir(abs, false, cb) - } -} + return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name())) + }); + + + Opal.udef(self, '$' + "new"); return nil; })(Opal.get_singleton_class(self)); + + $def(self, '$coerce', function $$coerce(other) { + var self = this; -Glob.prototype._readdir = function (abs, inGlobStar, cb) { - if (this.aborted) - return + + if (other === nil) { + $Kernel.$raise($$$('TypeError'), "can't convert " + (other.$class()) + " into Float"); + } + else if (other.$$is_string) { + return [$Kernel.$Float(other), self]; + } + else if (other['$respond_to?']("to_f")) { + return [$Opal['$coerce_to!'](other, $$$('Float'), "to_f"), self]; + } + else if (other.$$is_number) { + return [other, self]; + } + else { + $Kernel.$raise($$$('TypeError'), "can't convert " + (other.$class()) + " into Float"); + } + + }); + + $def(self, '$__id__', function $$__id__() { + var self = this; - cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb) - if (!cb) - return + return (self * 2) + 1; + }); + + $def(self, '$+', function $Number_$plus$1(other) { + var self = this; - //console.error('RD %j %j', +inGlobStar, abs) - if (inGlobStar && !ownProp(this.symlinks, abs)) - return this._readdirInGlobStar(abs, cb) + + if (other.$$is_number) { + return self + other; + } + else { + return self.$__coerced__("+", other); + } + + }); + + $def(self, '$-', function $Number_$minus$2(other) { + var self = this; - if (ownProp(this.cache, abs)) { - var c = this.cache[abs] - if (!c || c === 'FILE') - return cb() + + if (other.$$is_number) { + return self - other; + } + else { + return self.$__coerced__("-", other); + } + + }); + + $def(self, '$*', function $Number_$$3(other) { + var self = this; - if (Array.isArray(c)) - return cb(null, c) - } + + if (other.$$is_number) { + return self * other; + } + else { + return self.$__coerced__("*", other); + } + + }); + + $def(self, '$/', function $Number_$slash$4(other) { + var self = this; - var self = this - fs.readdir(abs, readdirCb(this, abs, cb)) -} + + if (other.$$is_number) { + return self / other; + } + else { + return self.$__coerced__("/", other); + } + + }); + + $def(self, '$%', function $Number_$percent$5(other) { + var self = this; -function readdirCb (self, abs, cb) { - return function (er, entries) { - if (er) - self._readdirError(abs, er, cb) - else - self._readdirEntries(abs, entries, cb) - } -} + + if (other.$$is_number) { + if (other == -Infinity) { + return other; + } + else if (other == 0) { + $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0"); + } + else if (other < 0 || self < 0) { + return (self % other + other) % other; + } + else { + return self % other; + } + } + else { + return self.$__coerced__("%", other); + } + + }); + + $def(self, '$&', function $Number_$$6(other) { + var self = this; -Glob.prototype._readdirEntries = function (abs, entries, cb) { - if (this.aborted) - return + + if (other.$$is_number) { + return self & other; + } + else { + return self.$__coerced__("&", other); + } + + }); + + $def(self, '$|', function $Number_$$7(other) { + var self = this; - // if we haven't asked to stat everything, then just - // assume that everything in there exists, so we can avoid - // having to stat it a second time. - if (!this.mark && !this.stat) { - for (var i = 0; i < entries.length; i ++) { - var e = entries[i] - if (abs === '/') - e = abs + e - else - e = abs + '/' + e - this.cache[e] = true - } - } + + if (other.$$is_number) { + return self | other; + } + else { + return self.$__coerced__("|", other); + } + + }); + + $def(self, '$^', function $Number_$$8(other) { + var self = this; - this.cache[abs] = entries - return cb(null, entries) -} + + if (other.$$is_number) { + return self ^ other; + } + else { + return self.$__coerced__("^", other); + } + + }); + + $def(self, '$<', function $Number_$lt$9(other) { + var self = this; -Glob.prototype._readdirError = function (f, er, cb) { - if (this.aborted) - return + + if (other.$$is_number) { + return self < other; + } + else { + return self.$__coerced__("<", other); + } + + }); + + $def(self, '$<=', function $Number_$lt_eq$10(other) { + var self = this; - // handle errors, and cache the information - switch (er.code) { - case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205 - case 'ENOTDIR': // totally normal. means it *does* exist. - var abs = this._makeAbs(f) - this.cache[abs] = 'FILE' - if (abs === this.cwdAbs) { - var error = new Error(er.code + ' invalid cwd ' + this.cwd) - error.path = this.cwd - error.code = er.code - this.emit('error', error) - this.abort() + + if (other.$$is_number) { + return self <= other; } - break + else { + return self.$__coerced__("<=", other); + } + + }); + + $def(self, '$>', function $Number_$gt$11(other) { + var self = this; - case 'ENOENT': // not terribly unusual - case 'ELOOP': - case 'ENAMETOOLONG': - case 'UNKNOWN': - this.cache[this._makeAbs(f)] = false - break + + if (other.$$is_number) { + return self > other; + } + else { + return self.$__coerced__(">", other); + } + + }); + + $def(self, '$>=', function $Number_$gt_eq$12(other) { + var self = this; + + + if (other.$$is_number) { + return self >= other; + } + else { + return self.$__coerced__(">=", other); + } + + }); + + var spaceship_operator = function(self, other) { + if (other.$$is_number) { + if (isNaN(self) || isNaN(other)) { + return nil; + } - default: // some unusual error. Treat as failure. - this.cache[this._makeAbs(f)] = false - if (this.strict) { - this.emit('error', er) - // If the error is handled, then we abort - // if not, we threw out of here - this.abort() + if (self > other) { + return 1; + } else if (self < other) { + return -1; + } else { + return 0; + } } - if (!this.silent) - console.error('glob error', er) - break - } + else { + return self.$__coerced__("<=>", other); + } + } + ; + + $def(self, '$<=>', function $Number_$lt_eq_gt$13(other) { + var self = this; - return cb() -} + try { + return spaceship_operator(self, other); + } catch ($err) { + if (Opal.rescue($err, [$$$('ArgumentError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + + $def(self, '$<<', function $Number_$lt$lt$14(count) { + var self = this; -Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) { - var self = this - this._readdir(abs, inGlobStar, function (er, entries) { - self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb) - }) -} + + count = $Opal['$coerce_to!'](count, $$$('Integer'), "to_int"); + return count > 0 ? self << count : self >> -count; + }); + + $def(self, '$>>', function $Number_$gt$gt$15(count) { + var self = this; + + count = $Opal['$coerce_to!'](count, $$$('Integer'), "to_int"); + return count > 0 ? self >> count : self << -count; + }); + + $def(self, '$[]', function $Number_$$$16(bit) { + var self = this; -Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) { - //console.error('pgs2', prefix, remain[0], entries) + + bit = $Opal['$coerce_to!'](bit, $$$('Integer'), "to_int"); + + if (bit < 0) { + return 0; + } + if (bit >= 32) { + return self < 0 ? 1 : 0; + } + return (self >> bit) & 1; + }); + + $def(self, '$+@', function $Number_$plus$$17() { + var self = this; - // no entries means not a dir, so it can never have matches - // foo.txt/** doesn't match foo.txt - if (!entries) - return cb() + return +self; + }); + + $def(self, '$-@', function $Number_$minus$$18() { + var self = this; - // test without the globstar, and with every child both below - // and replacing the globstar. - var remainWithoutGlobStar = remain.slice(1) - var gspref = prefix ? [ prefix ] : [] - var noGlobStar = gspref.concat(remainWithoutGlobStar) + return -self; + }); + + $def(self, '$~', function $Number_$$19() { + var self = this; - // the noGlobStar pattern exits the inGlobStar state - this._process(noGlobStar, index, false, cb) + return ~self; + }); + + $def(self, '$**', function $Number_$$$20(other) { + var self = this; - var isSym = this.symlinks[abs] - var len = entries.length + if ($eqeqeq($$$('Integer'), other)) { + if (($not($$$('Integer')['$==='](self)) || ($truthy($rb_gt(other, 0))))) { + return Math.pow(self, other); + } else { + return $$$('Rational').$new(self, 1)['$**'](other) + } + } else if (($rb_lt(self, 0) && (($eqeqeq($$$('Float'), other) || ($eqeqeq($$$('Rational'), other)))))) { + return $$$('Complex').$new(self, 0)['$**'](other.$to_f()) + } else if ($truthy(other.$$is_number != null)) { + return Math.pow(self, other); + } else { + return self.$__coerced__("**", other) + } + }); + + $def(self, '$==', function $Number_$eq_eq$21(other) { + var self = this; - // If it's a symlink, and we're in a globstar, then stop - if (isSym && inGlobStar) - return cb() + + if (other.$$is_number) { + return self.valueOf() === other.valueOf(); + } + else if (other['$respond_to?']("==")) { + return other['$=='](self); + } + else { + return false; + } + + }); + $alias(self, "===", "=="); + + $def(self, '$abs', function $$abs() { + var self = this; - for (var i = 0; i < len; i++) { - var e = entries[i] - if (e.charAt(0) === '.' && !this.dot) - continue + return Math.abs(self); + }); + + $def(self, '$abs2', function $$abs2() { + var self = this; - // these two cases enter the inGlobStar state - var instead = gspref.concat(entries[i], remainWithoutGlobStar) - this._process(instead, index, true, cb) + return Math.abs(self * self); + }); + + $def(self, '$allbits?', function $Number_allbits$ques$22(mask) { + var self = this; - var below = gspref.concat(entries[i], remain) - this._process(below, index, true, cb) - } + + mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int"); + return (self & mask) == mask; }); + + $def(self, '$anybits?', function $Number_anybits$ques$23(mask) { + var self = this; - cb() -} + + mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int"); + return (self & mask) !== 0; }); + + $def(self, '$angle', function $$angle() { + var self = this; -Glob.prototype._processSimple = function (prefix, index, cb) { - // XXX review this. Shouldn't it be doing the mounting etc - // before doing stat? kinda weird? - var self = this - this._stat(prefix, function (er, exists) { - self._processSimple2(prefix, index, er, exists, cb) - }) -} -Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) { + + if ($truthy(self['$nan?']())) { + return self + } + if (self == 0) { + if (1 / self > 0) { + return 0; + } + else { + return Math.PI; + } + } + else if (self < 0) { + return Math.PI; + } + else { + return 0; + } + }); + + $def(self, '$bit_length', function $$bit_length() { + var self = this; - //console.error('ps2', prefix, exists) + + if (!$eqeqeq($$$('Integer'), self)) { + $Kernel.$raise($$$('NoMethodError').$new("undefined method `bit_length` for " + (self) + ":Float", "bit_length")); + } + if (self === 0 || self === -1) { + return 0; + } - if (!this.matches[index]) - this.matches[index] = Object.create(null) + var result = 0, + value = self < 0 ? ~self : self; - // If it doesn't exist, then just mark the lack of results - if (!exists) - return cb() + while (value != 0) { + result += 1; + value >>>= 1; + } - if (prefix && isAbsolute(prefix) && !this.nomount) { - var trail = /[\/\\]$/.test(prefix) - if (prefix.charAt(0) === '/') { - prefix = path.join(this.root, prefix) - } else { - prefix = path.resolve(this.root, prefix) - if (trail) - prefix += '/' - } - } + return result; + }); + + $def(self, '$ceil', function $$ceil(ndigits) { + var self = this; - if (process.platform === 'win32') - prefix = prefix.replace(/\\/g, '/') + + if (ndigits == null) ndigits = 0; + + var f = self.$to_f(); - // Mark this as a match - this._emitMatch(index, prefix) - cb() -} + if (f % 1 === 0 && ndigits >= 0) { + return f; + } -// Returns either 'DIR', 'FILE', or false -Glob.prototype._stat = function (f, cb) { - var abs = this._makeAbs(f) - var needDir = f.slice(-1) === '/' + var factor = Math.pow(10, ndigits), + result = Math.ceil(f * factor) / factor; - if (f.length > this.maxLength) - return cb() + if (f % 1 === 0) { + result = Math.round(result); + } - if (!this.stat && ownProp(this.cache, abs)) { - var c = this.cache[abs] + return result; + }, -1); + + $def(self, '$chr', function $$chr(encoding) { + var self = this; + return Opal.enc(String.fromCharCode(self), encoding || "BINARY"); }, -1); + + $def(self, '$denominator', function $$denominator() { + var $yield = $$denominator.$$p || nil, self = this; - if (Array.isArray(c)) - c = 'DIR' + $$denominator.$$p = null; + if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) { + return 1 + } else { + return $send2(self, $find_super(self, 'denominator', $$denominator, false, true), 'denominator', [], $yield) + } + }); + + $def(self, '$downto', function $$downto(stop) { + var block = $$downto.$$p || nil, self = this; - // It exists, but maybe not how we need it - if (!needDir || c === 'DIR') - return cb(null, c) + $$downto.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["downto", stop], function $$24(){var self = $$24.$$s == null ? this : $$24.$$s; - if (needDir && c === 'FILE') - return cb() + + if (!$eqeqeq($$$('Numeric'), stop)) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed"); + } if ($truthy($rb_gt(stop, self))) { + return 0 + } else { + return $rb_plus($rb_minus(self, stop), 1) + }}, {$$s: self}) + } + if (!stop.$$is_number) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed"); + } + for (var i = self; i >= stop; i--) { + block(i); + } + return self; + }); + + $def(self, '$equal?', function $Number_equal$ques$25(other) { + var self = this, $ret_or_1 = nil; - // otherwise we have to stat, because maybe c=true - // if we know it exists, but not what it is. - } + if ($truthy(($ret_or_1 = self['$=='](other)))) { + return $ret_or_1 + } else { + return isNaN(self) && isNaN(other); + } + }); + + $def(self, '$even?', function $Number_even$ques$26() { + var self = this; - var exists - var stat = this.statCache[abs] - if (stat !== undefined) { - if (stat === false) - return cb(null, stat) - else { - var type = stat.isDirectory() ? 'DIR' : 'FILE' - if (needDir && type === 'FILE') - return cb() - else - return cb(null, type, stat) - } - } + return self % 2 === 0; + }); + + $def(self, '$floor', function $$floor(ndigits) { + var self = this; - var self = this - var statcb = inflight('stat\0' + abs, lstatcb_) - if (statcb) - fs.lstat(abs, statcb) + + if (ndigits == null) ndigits = 0; + + var f = self.$to_f(); - function lstatcb_ (er, lstat) { - if (lstat && lstat.isSymbolicLink()) { - // If it's a symlink, then treat it as the target, unless - // the target does not exist, then treat it as a file. - return fs.stat(abs, function (er, stat) { - if (er) - self._stat2(f, abs, null, lstat, cb) - else - self._stat2(f, abs, er, stat, cb) - }) - } else { - self._stat2(f, abs, er, lstat, cb) - } - } -} + if (f % 1 === 0 && ndigits >= 0) { + return f; + } -Glob.prototype._stat2 = function (f, abs, er, stat, cb) { - if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) { - this.statCache[abs] = false - return cb() - } + var factor = Math.pow(10, ndigits), + result = Math.floor(f * factor) / factor; - var needDir = f.slice(-1) === '/' - this.statCache[abs] = stat + if (f % 1 === 0) { + result = Math.round(result); + } - if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) - return cb(null, false, stat) + return result; + }, -1); + + $def(self, '$gcd', function $$gcd(other) { + var self = this; - var c = true - if (stat) - c = stat.isDirectory() ? 'DIR' : 'FILE' - this.cache[abs] = this.cache[abs] || c + + if (!$eqeqeq($$$('Integer'), other)) { + $Kernel.$raise($$$('TypeError'), "not an integer"); + } + var min = Math.abs(self), + max = Math.abs(other); - if (needDir && c === 'FILE') - return cb() + while (min > 0) { + var tmp = min; - return cb(null, c, stat) -} + min = max % min; + max = tmp; + } + return max; + }); + + $def(self, '$gcdlcm', function $$gcdlcm(other) { + var self = this; -/***/ }), + return [self.$gcd(other), self.$lcm(other)] + }); + + $def(self, '$integer?', function $Number_integer$ques$27() { + var self = this; -/***/ 9010: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + return self % 1 === 0; + }); + + $def(self, '$is_a?', function $Number_is_a$ques$28(klass) { + var $yield = $Number_is_a$ques$28.$$p || nil, self = this; -module.exports = globSync -globSync.GlobSync = GlobSync + $Number_is_a$ques$28.$$p = null; + + if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) { + return true + } if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) { + return true + } if (($eqeq(klass, $$$('Float')) && ($eqeqeq($$$('Float'), self)))) { + return true + } return $send2(self, $find_super(self, 'is_a?', $Number_is_a$ques$28, false, true), 'is_a?', [klass], $yield); + }); + + $def(self, '$instance_of?', function $Number_instance_of$ques$29(klass) { + var $yield = $Number_instance_of$ques$29.$$p || nil, self = this; -var fs = __nccwpck_require__(7147) -var rp = __nccwpck_require__(6863) -var minimatch = __nccwpck_require__(3973) -var Minimatch = minimatch.Minimatch -var Glob = (__nccwpck_require__(1957).Glob) -var util = __nccwpck_require__(3837) -var path = __nccwpck_require__(1017) -var assert = __nccwpck_require__(9491) -var isAbsolute = __nccwpck_require__(8714) -var common = __nccwpck_require__(7625) -var alphasort = common.alphasort -var alphasorti = common.alphasorti -var setopts = common.setopts -var ownProp = common.ownProp -var childrenIgnored = common.childrenIgnored -var isIgnored = common.isIgnored + $Number_instance_of$ques$29.$$p = null; + + if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) { + return true + } if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) { + return true + } if (($eqeq(klass, $$$('Float')) && ($eqeqeq($$$('Float'), self)))) { + return true + } return $send2(self, $find_super(self, 'instance_of?', $Number_instance_of$ques$29, false, true), 'instance_of?', [klass], $yield); + }); + + $def(self, '$lcm', function $$lcm(other) { + var self = this; -function globSync (pattern, options) { - if (typeof options === 'function' || arguments.length === 3) - throw new TypeError('callback provided to sync glob\n'+ - 'See: https://github.com/isaacs/node-glob/issues/167') + + if (!$eqeqeq($$$('Integer'), other)) { + $Kernel.$raise($$$('TypeError'), "not an integer"); + } + if (self == 0 || other == 0) { + return 0; + } + else { + return Math.abs(self * other / self.$gcd(other)); + } + }); + + $def(self, '$next', function $$next() { + var self = this; - return new GlobSync(pattern, options).found -} + return self + 1; + }); + + $def(self, '$nobits?', function $Number_nobits$ques$30(mask) { + var self = this; -function GlobSync (pattern, options) { - if (!pattern) - throw new Error('must provide pattern') + + mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int"); + return (self & mask) == 0; }); + + $def(self, '$nonzero?', function $Number_nonzero$ques$31() { + var self = this; - if (typeof options === 'function' || arguments.length === 3) - throw new TypeError('callback provided to sync glob\n'+ - 'See: https://github.com/isaacs/node-glob/issues/167') + return self == 0 ? nil : self; + }); + + $def(self, '$numerator', function $$numerator() { + var $yield = $$numerator.$$p || nil, self = this; - if (!(this instanceof GlobSync)) - return new GlobSync(pattern, options) + $$numerator.$$p = null; + if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) { + return self + } else { + return $send2(self, $find_super(self, 'numerator', $$numerator, false, true), 'numerator', [], $yield) + } + }); + + $def(self, '$odd?', function $Number_odd$ques$32() { + var self = this; - setopts(this, pattern, options) + return self % 2 !== 0; + }); + + $def(self, '$ord', $return_self); + + $def(self, '$pow', function $$pow(b, m) { + var self = this; + + if (self == 0) { + $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0"); + } - if (this.noprocess) - return this + if (m === undefined) { + return self['$**'](b); + } else { + if (!($$$('Integer')['$==='](b))) { + $Kernel.$raise($$$('TypeError'), "Integer#pow() 2nd argument not allowed unless a 1st argument is integer"); + } - var n = this.minimatch.set.length - this.matches = new Array(n) - for (var i = 0; i < n; i ++) { - this._process(this.minimatch.set[i], i, false) - } - this._finish() -} + if (b < 0) { + $Kernel.$raise($$$('TypeError'), "Integer#pow() 1st argument cannot be negative when 2nd argument specified"); + } -GlobSync.prototype._finish = function () { - assert(this instanceof GlobSync) - if (this.realpath) { - var self = this - this.matches.forEach(function (matchset, index) { - var set = self.matches[index] = Object.create(null) - for (var p in matchset) { - try { - p = self._makeAbs(p) - var real = rp.realpathSync(p, self.realpathCache) - set[real] = true - } catch (er) { - if (er.syscall === 'stat') - set[self._makeAbs(p)] = true - else - throw er + if (!($$$('Integer')['$==='](m))) { + $Kernel.$raise($$$('TypeError'), "Integer#pow() 2nd argument not allowed unless all arguments are integers"); } - } - }) - } - common.finish(this) -} + if (m === 0) { + $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0"); + } -GlobSync.prototype._process = function (pattern, index, inGlobStar) { - assert(this instanceof GlobSync) + return self['$**'](b)['$%'](m) + } + }, -2); + + $def(self, '$pred', function $$pred() { + var self = this; - // Get the first [n] parts of pattern that are all strings. - var n = 0 - while (typeof pattern[n] === 'string') { - n ++ - } - // now n is the index of the first one that is *not* a string. + return self - 1; + }); + + $def(self, '$quo', function $$quo(other) { + var $yield = $$quo.$$p || nil, self = this; - // See if there's anything else - var prefix - switch (n) { - // if not, then this is rather simple - case pattern.length: - this._processSimple(pattern.join('/'), index) - return + $$quo.$$p = null; + if ($eqeqeq($$$('Integer'), self)) { + return $send2(self, $find_super(self, 'quo', $$quo, false, true), 'quo', [other], $yield) + } else { + return $rb_divide(self, other) + } + }); + + $def(self, '$rationalize', function $$rationalize(eps) { + var $a, $b, self = this, f = nil, n = nil; + + if (arguments.length > 1) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)"); + } + if ($eqeqeq($$$('Integer'), self)) { + return $$$('Rational').$new(self, 1) + } else if ($truthy(self['$infinite?']())) { + return $Kernel.$raise($$$('FloatDomainError'), "Infinity") + } else if ($truthy(self['$nan?']())) { + return $Kernel.$raise($$$('FloatDomainError'), "NaN") + } else if ($truthy(eps == null)) { + + $b = $$$('Math').$frexp(self), $a = $to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (n = ($a[1] == null ? nil : $a[1])); + f = $$$('Math').$ldexp(f, $$$($$$('Float'), 'MANT_DIG')).$to_i(); + n = $rb_minus(n, $$$($$$('Float'), 'MANT_DIG')); + return $$$('Rational').$new($rb_times(2, f), (1)['$<<']($rb_minus(1, n))).$rationalize($$$('Rational').$new(1, (1)['$<<']($rb_minus(1, n)))); + } else { + return self.$to_r().$rationalize(eps) + } }, -1); + + $def(self, '$remainder', function $$remainder(y) { + var self = this; - case 0: - // pattern *starts* with some non-trivial item. - // going to readdir(cwd), but not include the prefix in matches. - prefix = null - break + return $rb_minus(self, $rb_times(y, $rb_divide(self, y).$truncate())) + }); + + $def(self, '$round', function $$round(ndigits) { + var $a, $b, self = this, exp = nil; + if ($eqeqeq($$$('Integer'), self)) { + + if ($truthy(ndigits == null)) { + return self + } if (($eqeqeq($$$('Float'), ndigits) && ($truthy(ndigits['$infinite?']())))) { + $Kernel.$raise($$$('RangeError'), "Infinity"); + } ndigits = $Opal['$coerce_to!'](ndigits, $$$('Integer'), "to_int"); + if ($truthy($rb_lt(ndigits, $$$($$$('Integer'), 'MIN')))) { + $Kernel.$raise($$$('RangeError'), "out of bounds"); + } if ($truthy(ndigits >= 0)) { + return self + } ndigits = ndigits['$-@'](); + + if (0.415241 * ndigits - 0.125 > self.$size()) { + return 0; + } - default: - // pattern has some string bits in the front. - // whatever it starts with, whether that's 'absolute' like /foo/bar, - // or 'relative' like '../baz' - prefix = pattern.slice(0, n).join('/') - break - } + var f = Math.pow(10, ndigits), + x = Math.floor((Math.abs(self) + f / 2) / f) * f; - var remain = pattern.slice(n) + return self < 0 ? -x : x; + } else { + + if (($truthy(self['$nan?']()) && ($truthy(ndigits == null)))) { + $Kernel.$raise($$$('FloatDomainError'), "NaN"); + } ndigits = $Opal['$coerce_to!'](ndigits || 0, $$$('Integer'), "to_int"); + if ($truthy($rb_le(ndigits, 0))) { + if ($truthy(self['$nan?']())) { + $Kernel.$raise($$$('RangeError'), "NaN"); + } else if ($truthy(self['$infinite?']())) { + $Kernel.$raise($$$('FloatDomainError'), "Infinity"); + } + } else if ($eqeq(ndigits, 0)) { + return Math.round(self) + } else if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) { + return self + } $b = $$$('Math').$frexp(self), $a = $to_ary($b), (($a[0] == null ? nil : $a[0])), (exp = ($a[1] == null ? nil : $a[1])); + if ($truthy($rb_ge(ndigits, $rb_minus($rb_plus($$$($$$('Float'), 'DIG'), 2), ($truthy($rb_gt(exp, 0)) ? ($rb_divide(exp, 4)) : ($rb_minus($rb_divide(exp, 3), 1))))))) { + return self + } if ($truthy($rb_lt(ndigits, ($truthy($rb_gt(exp, 0)) ? ($rb_plus($rb_divide(exp, 3), 1)) : ($rb_divide(exp, 4)))['$-@']()))) { + return 0 + } return Math.round(self * Math.pow(10, ndigits)) / Math.pow(10, ndigits); } }, -1); + + $def(self, '$times', function $$times() { + var block = $$times.$$p || nil, self = this; - // get the list of entries. - var read - if (prefix === null) - read = '.' - else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) { - if (!prefix || !isAbsolute(prefix)) - prefix = '/' + prefix - read = prefix - } else - read = prefix + $$times.$$p = null; + if (!$truthy(block)) { + return $send(self, 'enum_for', ["times"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s; - var abs = this._makeAbs(read) + return self}, {$$s: self}) + } + for (var i = 0; i < self; i++) { + block(i); + } + return self; + }); + + $def(self, '$to_f', $return_self); + + $def(self, '$to_i', function $$to_i() { + var self = this; - //if ignored, skip processing - if (childrenIgnored(this, read)) - return + return self < 0 ? Math.ceil(self) : Math.floor(self); + }); + + $def(self, '$to_r', function $$to_r() { + var $a, $b, self = this, f = nil, e = nil; - var isGlobStar = remain[0] === minimatch.GLOBSTAR - if (isGlobStar) - this._processGlobStar(prefix, read, abs, remain, index, inGlobStar) - else - this._processReaddir(prefix, read, abs, remain, index, inGlobStar) -} + if ($eqeqeq($$$('Integer'), self)) { + return $$$('Rational').$new(self, 1) + } else { + + $b = $$$('Math').$frexp(self), $a = $to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (e = ($a[1] == null ? nil : $a[1])); + f = $$$('Math').$ldexp(f, $$$($$$('Float'), 'MANT_DIG')).$to_i(); + e = $rb_minus(e, $$$($$$('Float'), 'MANT_DIG')); + return $rb_times(f, $$$($$$('Float'), 'RADIX')['$**'](e)).$to_r(); + } + }); + + $def(self, '$to_s', function $$to_s(base) { + var self = this; + + if (base == null) base = 10; + base = $Opal['$coerce_to!'](base, $$$('Integer'), "to_int"); + if (($truthy($rb_lt(base, 2)) || ($truthy($rb_gt(base, 36))))) { + $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base)); + } if (($eqeq(self, 0) && ($truthy(1/self === -Infinity)))) { + return "-0.0" + } return self.toString(base); }, -1); + + $def(self, '$truncate', function $$truncate(ndigits) { + var self = this; -GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) { - var entries = this._readdir(abs, inGlobStar) + + if (ndigits == null) ndigits = 0; + + var f = self.$to_f(); - // if the abs isn't a dir, then nothing can match! - if (!entries) - return + if (f % 1 === 0 && ndigits >= 0) { + return f; + } - // It will only match dot entries if it starts with a dot, or if - // dot is set. Stuff like @(.foo|.bar) isn't allowed. - var pn = remain[0] - var negate = !!this.minimatch.negate - var rawGlob = pn._glob - var dotOk = this.dot || rawGlob.charAt(0) === '.' + var factor = Math.pow(10, ndigits), + result = parseInt(f * factor, 10) / factor; - var matchedEntries = [] - for (var i = 0; i < entries.length; i++) { - var e = entries[i] - if (e.charAt(0) !== '.' || dotOk) { - var m - if (negate && !prefix) { - m = !e.match(pn) - } else { - m = e.match(pn) + if (f % 1 === 0) { + result = Math.round(result); } - if (m) - matchedEntries.push(e) - } - } - var len = matchedEntries.length - // If there are no matched entries, then nothing matches. - if (len === 0) - return + return result; + }, -1); + + $def(self, '$digits', function $$digits(base) { + var self = this; - // if this is the last remaining pattern bit, then no need for - // an additional stat *unless* the user has specified mark or - // stat explicitly. We know they exist, since readdir returned - // them. + + if (base == null) base = 10; + if ($rb_lt(self, 0)) { + $Kernel.$raise($$$($$$('Math'), 'DomainError'), "out of domain"); + } base = $Opal['$coerce_to!'](base, $$$('Integer'), "to_int"); + if ($truthy($rb_lt(base, 2))) { + $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base)); + } + if (self != parseInt(self)) $Kernel.$raise($$$('NoMethodError'), "undefined method `digits' for " + (self.$inspect())); - if (remain.length === 1 && !this.mark && !this.stat) { - if (!this.matches[index]) - this.matches[index] = Object.create(null) + var value = self, result = []; - for (var i = 0; i < len; i ++) { - var e = matchedEntries[i] - if (prefix) { - if (prefix.slice(-1) !== '/') - e = prefix + '/' + e - else - e = prefix + e + if (self == 0) { + return [0]; } - if (e.charAt(0) === '/' && !this.nomount) { - e = path.join(this.root, e) + while (value != 0) { + result.push(value % base); + value = parseInt(value / base, 10); } - this._emitMatch(index, e) - } - // This was the last one, and no stats were needed - return - } - - // now test all matched entries as stand-ins for that part - // of the pattern. - remain.shift() - for (var i = 0; i < len; i ++) { - var e = matchedEntries[i] - var newPattern - if (prefix) - newPattern = [prefix, e] - else - newPattern = [e] - this._process(newPattern.concat(remain), index, inGlobStar) - } -} - - -GlobSync.prototype._emitMatch = function (index, e) { - if (isIgnored(this, e)) - return - var abs = this._makeAbs(e) + return result; + }, -1); + + $def(self, '$divmod', function $$divmod(other) { + var $yield = $$divmod.$$p || nil, self = this; - if (this.mark) - e = this._mark(e) + $$divmod.$$p = null; + if (($truthy(self['$nan?']()) || ($truthy(other['$nan?']())))) { + return $Kernel.$raise($$$('FloatDomainError'), "NaN") + } else if ($truthy(self['$infinite?']())) { + return $Kernel.$raise($$$('FloatDomainError'), "Infinity") + } else { + return $send2(self, $find_super(self, 'divmod', $$divmod, false, true), 'divmod', [other], $yield) + } + }); + + $def(self, '$upto', function $$upto(stop) { + var block = $$upto.$$p || nil, self = this; - if (this.absolute) { - e = abs - } + $$upto.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["upto", stop], function $$34(){var self = $$34.$$s == null ? this : $$34.$$s; - if (this.matches[index][e]) - return + + if (!$eqeqeq($$$('Numeric'), stop)) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed"); + } if ($truthy($rb_lt(stop, self))) { + return 0 + } else { + return $rb_plus($rb_minus(stop, self), 1) + }}, {$$s: self}) + } + if (!stop.$$is_number) { + $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed"); + } + for (var i = self; i <= stop; i++) { + block(i); + } + return self; + }); + + $def(self, '$zero?', function $Number_zero$ques$35() { + var self = this; - if (this.nodir) { - var c = this.cache[abs] - if (c === 'DIR' || Array.isArray(c)) - return - } + return self == 0; + }); + + $def(self, '$size', $return_val(4)); + + $def(self, '$nan?', function $Number_nan$ques$36() { + var self = this; - this.matches[index][e] = true + return isNaN(self); + }); + + $def(self, '$finite?', function $Number_finite$ques$37() { + var self = this; - if (this.stat) - this._stat(e) -} + return self != Infinity && self != -Infinity && !isNaN(self); + }); + + $def(self, '$infinite?', function $Number_infinite$ques$38() { + var self = this; + + if (self == Infinity) { + return +1; + } + else if (self == -Infinity) { + return -1; + } + else { + return nil; + } + + }); + + $def(self, '$positive?', function $Number_positive$ques$39() { + var self = this; -GlobSync.prototype._readdirInGlobStar = function (abs) { - // follow all symlinked directories forever - // just proceed as if this is a non-globstar situation - if (this.follow) - return this._readdir(abs, false) + return self != 0 && (self == Infinity || 1 / self > 0); + }); + + $def(self, '$negative?', function $Number_negative$ques$40() { + var self = this; - var entries - var lstat - var stat - try { - lstat = fs.lstatSync(abs) - } catch (er) { - if (er.code === 'ENOENT') { - // lstat failed, doesn't exist - return null + return self == -Infinity || 1 / self < 0; + }); + + function numberToUint8Array(num) { + var uint8array = new Uint8Array(8); + new DataView(uint8array.buffer).setFloat64(0, num, true); + return uint8array; } - } - var isSym = lstat && lstat.isSymbolicLink() - this.symlinks[abs] = isSym + function uint8ArrayToNumber(arr) { + return new DataView(arr.buffer).getFloat64(0, true); + } - // If it's not a symlink or a dir, then it's definitely a regular file. - // don't bother doing a readdir in that case. - if (!isSym && lstat && !lstat.isDirectory()) - this.cache[abs] = 'FILE' - else - entries = this._readdir(abs, false) + function incrementNumberBit(num) { + var arr = numberToUint8Array(num); + for (var i = 0; i < arr.length; i++) { + if (arr[i] === 0xff) { + arr[i] = 0; + } else { + arr[i]++; + break; + } + } + return uint8ArrayToNumber(arr); + } - return entries -} + function decrementNumberBit(num) { + var arr = numberToUint8Array(num); + for (var i = 0; i < arr.length; i++) { + if (arr[i] === 0) { + arr[i] = 0xff; + } else { + arr[i]--; + break; + } + } + return uint8ArrayToNumber(arr); + } + + $def(self, '$next_float', function $$next_float() { + var self = this; -GlobSync.prototype._readdir = function (abs, inGlobStar) { - var entries + + if ($eqeq(self, $$$($$$('Float'), 'INFINITY'))) { + return $$$($$$('Float'), 'INFINITY') + } if ($truthy(self['$nan?']())) { + return $$$($$$('Float'), 'NAN') + } if ($rb_ge(self, 0)) { + return incrementNumberBit(Math.abs(self)); + } else { + return decrementNumberBit(self); + } }); + + $def(self, '$prev_float', function $$prev_float() { + var self = this; - if (inGlobStar && !ownProp(this.symlinks, abs)) - return this._readdirInGlobStar(abs) + + if ($eqeq(self, $$$($$$('Float'), 'INFINITY')['$-@']())) { + return $$$($$$('Float'), 'INFINITY')['$-@']() + } if ($truthy(self['$nan?']())) { + return $$$($$$('Float'), 'NAN') + } if ($rb_gt(self, 0)) { + return decrementNumberBit(self); + } else { + return -incrementNumberBit(Math.abs(self)); + } }); + $alias(self, "arg", "angle"); + $alias(self, "eql?", "=="); + $alias(self, "fdiv", "/"); + $alias(self, "inspect", "to_s"); + $alias(self, "kind_of?", "is_a?"); + $alias(self, "magnitude", "abs"); + $alias(self, "modulo", "%"); + $alias(self, "object_id", "__id__"); + $alias(self, "phase", "angle"); + $alias(self, "succ", "next"); + return $alias(self, "to_int", "to_i"); + })('::', $$$('Numeric')); + $const_set('::', 'Fixnum', $$$('Number')); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Integer'); - if (ownProp(this.cache, abs)) { - var c = this.cache[abs] - if (!c || c === 'FILE') - return null + var $nesting = [self].concat($parent_nesting); - if (Array.isArray(c)) - return c - } + + self.$$is_number_class = true; + self.$$is_integer_class = true; + (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - try { - return this._readdirEntries(abs, fs.readdirSync(abs)) - } catch (er) { - this._readdirError(abs, er) - return null - } -} + + + $def(self, '$allocate', function $$allocate() { + var self = this; -GlobSync.prototype._readdirEntries = function (abs, entries) { - // if we haven't asked to stat everything, then just - // assume that everything in there exists, so we can avoid - // having to stat it a second time. - if (!this.mark && !this.stat) { - for (var i = 0; i < entries.length; i ++) { - var e = entries[i] - if (abs === '/') - e = abs + e - else - e = abs + '/' + e - this.cache[e] = true - } - } + return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name())) + }); + + Opal.udef(self, '$' + "new"); + $def(self, '$sqrt', function $$sqrt(n) { + + + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + + if (n < 0) { + $Kernel.$raise($$$($$$('Math'), 'DomainError'), "Numerical argument is out of domain - \"isqrt\""); + } - this.cache[abs] = entries + return parseInt(Math.sqrt(n), 10); + }); + return $def(self, '$try_convert', function $$try_convert(object) { + var self = this; - // mark and cache dir-ness - return entries -} + return $$('Opal')['$coerce_to?'](object, self, "to_int") + }); + })(Opal.get_singleton_class(self), $nesting); + $const_set(self, 'MAX', Math.pow(2, 30) - 1); + return $const_set(self, 'MIN', -Math.pow(2, 30)); + })('::', $$$('Numeric'), $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Float'); -GlobSync.prototype._readdirError = function (f, er) { - // handle errors, and cache the information - switch (er.code) { - case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205 - case 'ENOTDIR': // totally normal. means it *does* exist. - var abs = this._makeAbs(f) - this.cache[abs] = 'FILE' - if (abs === this.cwdAbs) { - var error = new Error(er.code + ' invalid cwd ' + this.cwd) - error.path = this.cwd - error.code = er.code - throw error - } - break + + self.$$is_number_class = true; + (function(self, $parent_nesting) { + + + + $def(self, '$allocate', function $$allocate() { + var self = this; - case 'ENOENT': // not terribly unusual - case 'ELOOP': - case 'ENAMETOOLONG': - case 'UNKNOWN': - this.cache[this._makeAbs(f)] = false - break + return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name())) + }); + + Opal.udef(self, '$' + "new"); return $def(self, '$===', function $eq_eq_eq$41(other) { + + return !!other.$$is_number; + }); + })(Opal.get_singleton_class(self)); + $const_set(self, 'INFINITY', Infinity); + $const_set(self, 'MAX', Number.MAX_VALUE); + $const_set(self, 'MIN', Number.MIN_VALUE); + $const_set(self, 'NAN', NaN); + $const_set(self, 'DIG', 15); + $const_set(self, 'MANT_DIG', 53); + $const_set(self, 'RADIX', 2); + return $const_set(self, 'EPSILON', Number.EPSILON || 2.2204460492503130808472633361816E-16); + })('::', $$$('Numeric')); +}; - default: // some unusual error. Treat as failure. - this.cache[this._makeAbs(f)] = false - if (this.strict) - throw er - if (!this.silent) - console.error('glob error', er) - break - } -} +Opal.modules["corelib/range"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $not = Opal.not, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $send = Opal.send, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $return_ivar = Opal.return_ivar, $rb_gt = Opal.rb_gt, $rb_minus = Opal.rb_minus, $Opal = Opal.Opal, $rb_divide = Opal.rb_divide, $rb_plus = Opal.rb_plus, $rb_times = Opal.rb_times, $rb_ge = Opal.rb_ge, $thrower = Opal.thrower, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) { + Opal.add_stubs('require,include,attr_reader,raise,nil?,<=>,include?,!,<,<=,enum_for,size,upto,to_proc,respond_to?,class,succ,==,===,exclude_end?,eql?,begin,end,last,to_a,>,-@,-,to_i,coerce_to!,ceil,/,is_a?,new,loop,+,*,>=,each_with_index,%,step,bsearch,inspect,[],hash,cover?'); + + self.$require("corelib/enumerable"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Range'); - var entries = this._readdir(abs, inGlobStar) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - // no entries means not a dir, so it can never have matches - // foo.txt/** doesn't match foo.txt - if (!entries) - return + $proto.begin = $proto.end = $proto.excl = nil; + + self.$include($$$('Enumerable')); + self.$$prototype.$$is_range = true; + self.$attr_reader("begin", "end"); + + $def(self, '$initialize', function $$initialize(first, last, exclude) { + var self = this; - // test without the globstar, and with every child both below - // and replacing the globstar. - var remainWithoutGlobStar = remain.slice(1) - var gspref = prefix ? [ prefix ] : [] - var noGlobStar = gspref.concat(remainWithoutGlobStar) + + if (exclude == null) exclude = false; + if ($truthy(self.begin)) { + $Kernel.$raise($$$('NameError'), "'initialize' called twice"); + } if (!(($truthy(first['$<=>'](last)) || ($truthy(first['$nil?']()))) || ($truthy(last['$nil?']())))) { + $Kernel.$raise($$$('ArgumentError'), "bad value for range"); + } self.begin = first; + self.end = last; + return (self.excl = exclude); + }, -3); + + $def(self, '$===', function $Range_$eq_eq_eq$1(value) { + var self = this; - // the noGlobStar pattern exits the inGlobStar state - this._process(noGlobStar, index, false) + return self['$include?'](value) + }); + + function is_infinite(self) { + if (self.begin === nil || self.end === nil || + self.begin === -Infinity || self.end === Infinity || + self.begin === Infinity || self.end === -Infinity) return true; + return false; + } + + $def(self, '$count', function $$count() { + var block = $$count.$$p || nil, self = this; - var len = entries.length - var isSym = this.symlinks[abs] + $$count.$$p = null; + if (($not((block !== nil)) && ($truthy(is_infinite(self))))) { + return $$$($$$('Float'), 'INFINITY') + } return $send2(self, $find_super(self, 'count', $$count, false, true), 'count', [], block); + }); + + $def(self, '$to_a', function $$to_a() { + var $yield = $$to_a.$$p || nil, self = this; - // If it's a symlink, and we're in a globstar, then stop - if (isSym && inGlobStar) - return + $$to_a.$$p = null; + + if ($truthy(is_infinite(self))) { + $Kernel.$raise($$$('TypeError'), "cannot convert endless range to an array"); + } return $send2(self, $find_super(self, 'to_a', $$to_a, false, true), 'to_a', [], $yield); + }); + + $def(self, '$cover?', function $Range_cover$ques$2(value) { + var self = this, beg_cmp = nil, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, end_cmp = nil; - for (var i = 0; i < len; i++) { - var e = entries[i] - if (e.charAt(0) === '.' && !this.dot) - continue + + beg_cmp = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.begin['$nil?']())) ? (-1) : ($ret_or_3)))) ? ($ret_or_2) : (self.begin['$<=>'](value))))) && ($ret_or_1)); + end_cmp = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.end['$nil?']())) ? (-1) : ($ret_or_3)))) ? ($ret_or_2) : (value['$<=>'](self.end))))) && ($ret_or_1)); + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(self.excl) ? (($truthy(($ret_or_3 = end_cmp)) ? ($rb_lt(end_cmp, 0)) : ($ret_or_3))) : ($truthy(($ret_or_3 = end_cmp)) ? ($rb_le(end_cmp, 0)) : ($ret_or_3))))) ? (beg_cmp) : ($ret_or_2))))) { + return $rb_le(beg_cmp, 0) + } else { + return $ret_or_1 + } }); + + $def(self, '$each', function $$each() { + var block = $$each.$$p || nil, self = this, current = nil, last = nil, $ret_or_1 = nil; - // these two cases enter the inGlobStar state - var instead = gspref.concat(entries[i], remainWithoutGlobStar) - this._process(instead, index, true) + $$each.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s; - var below = gspref.concat(entries[i], remain) - this._process(below, index, true) - } -} + return self.$size()}, {$$s: self}) + } + var i, limit; -GlobSync.prototype._processSimple = function (prefix, index) { - // XXX review this. Shouldn't it be doing the mounting etc - // before doing stat? kinda weird? - var exists = this._stat(prefix) + if (self.begin.$$is_number && self.end.$$is_number) { + if (self.begin % 1 !== 0 || self.end % 1 !== 0) { + $Kernel.$raise($$$('TypeError'), "can't iterate from Float"); + } - if (!this.matches[index]) - this.matches[index] = Object.create(null) + for (i = self.begin, limit = self.end + ($truthy(self.excl) ? (0) : (1)); i < limit; i++) { + block(i); + } - // If it doesn't exist, then just mark the lack of results - if (!exists) - return + return self; + } - if (prefix && isAbsolute(prefix) && !this.nomount) { - var trail = /[\/\\]$/.test(prefix) - if (prefix.charAt(0) === '/') { - prefix = path.join(this.root, prefix) - } else { - prefix = path.resolve(this.root, prefix) - if (trail) - prefix += '/' - } - } + if (self.begin.$$is_string && self.end.$$is_string) { + $send(self.begin, 'upto', [self.end, self.excl], block.$to_proc()); + return self; + } + current = self.begin; + last = self.end; + if (!$truthy(current['$respond_to?']("succ"))) { + $Kernel.$raise($$$('TypeError'), "can't iterate from " + (current.$class())); + } while ($truthy(($truthy(($ret_or_1 = self.end['$nil?']())) ? ($ret_or_1) : ($rb_lt(current['$<=>'](last), 0))))) { + + Opal.yield1(block, current); + current = current.$succ(); + } if (($not(self.excl) && ($eqeq(current, last)))) { + Opal.yield1(block, current); + } return self; + }); + + $def(self, '$eql?', function $Range_eql$ques$4(other) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; - if (process.platform === 'win32') - prefix = prefix.replace(/\\/g, '/') + + if (!$eqeqeq($$$('Range'), other)) { + return false + } if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.excl['$==='](other['$exclude_end?']()))) ? (self.begin['$eql?'](other.$begin())) : ($ret_or_2))))) { + return self.end['$eql?'](other.$end()) + } else { + return $ret_or_1 + } }); + + $def(self, '$exclude_end?', $return_ivar("excl")); + + $def(self, '$first', function $$first(n) { + var $yield = $$first.$$p || nil, self = this; - // Mark this as a match - this._emitMatch(index, prefix) -} + $$first.$$p = null; + if ($truthy(self.begin['$nil?']())) { + $Kernel.$raise($$$('RangeError'), "cannot get the minimum of beginless range"); + } if ($truthy(n == null)) { + return self.begin + } return $send2(self, $find_super(self, 'first', $$first, false, true), 'first', [n], $yield); + }, -1); + + $def(self, '$last', function $$last(n) { + var self = this; + if ($truthy(self.end['$nil?']())) { + $Kernel.$raise($$$('RangeError'), "cannot get the maximum of endless range"); + } if ($truthy(n == null)) { + return self.end + } return self.$to_a().$last(n); + }, -1); + + $def(self, '$max', function $$max() { + var $yield = $$max.$$p || nil, self = this; + + $$max.$$p = null; + if ($truthy(self.end['$nil?']())) { + return $Kernel.$raise($$$('RangeError'), "cannot get the maximum of endless range") + } else if (($yield !== nil)) { + return $send2(self, $find_super(self, 'max', $$max, false, true), 'max', [], $yield) + } else if (($not(self.begin['$nil?']()) && (($truthy($rb_gt(self.begin, self.end)) || (($truthy(self.excl) && ($eqeq(self.begin, self.end)))))))) { + return nil + } else { + return self.excl ? self.end - 1 : self.end + } + }); + + $def(self, '$min', function $$min() { + var $yield = $$min.$$p || nil, self = this; -// Returns either 'DIR', 'FILE', or false -GlobSync.prototype._stat = function (f) { - var abs = this._makeAbs(f) - var needDir = f.slice(-1) === '/' + $$min.$$p = null; + if ($truthy(self.begin['$nil?']())) { + return $Kernel.$raise($$$('RangeError'), "cannot get the minimum of beginless range") + } else if (($yield !== nil)) { + return $send2(self, $find_super(self, 'min', $$min, false, true), 'min', [], $yield) + } else if (($not(self.end['$nil?']()) && (($truthy($rb_gt(self.begin, self.end)) || (($truthy(self.excl) && ($eqeq(self.begin, self.end)))))))) { + return nil + } else { + return self.begin + } + }); + + $def(self, '$size', function $$size() { + var self = this, infinity = nil, range_begin = nil, range_end = nil; - if (f.length > this.maxLength) - return false + + infinity = $$$($$$('Float'), 'INFINITY'); + if ((($eqeq(self.begin, infinity) && ($not(self.end['$nil?']()))) || (($eqeq(self.end, infinity['$-@']()) && ($not(self.begin['$nil?']())))))) { + return 0 + } if ($truthy(is_infinite(self))) { + return infinity + } if (!($eqeqeq($$$('Numeric'), self.begin) && ($eqeqeq($$$('Numeric'), self.end)))) { + return nil + } range_begin = self.begin; + range_end = self.end; + if ($truthy(self.excl)) { + range_end = $rb_minus(range_end, 1); + } if ($truthy($rb_lt(range_end, range_begin))) { + return 0 + } return (Math.abs(range_end - range_begin) + 1).$to_i(); + }); + + $def(self, '$step', function $$step(n) { + var $yield = $$step.$$p || nil, self = this, $ret_or_1 = nil, i = nil; - if (!this.stat && ownProp(this.cache, abs)) { - var c = this.cache[abs] + $$step.$$p = null; + + function coerceStepSize() { + if (n == null) { + n = 1; + } + else if (!n.$$is_number) { + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + } - if (Array.isArray(c)) - c = 'DIR' + if (n < 0) { + $Kernel.$raise($$$('ArgumentError'), "step can't be negative"); + } else if (n === 0) { + $Kernel.$raise($$$('ArgumentError'), "step can't be 0"); + } + } - // It exists, but maybe not how we need it - if (!needDir || c === 'DIR') - return c + function enumeratorSize() { + if (!self.begin['$respond_to?']("succ")) { + return nil; + } - if (needDir && c === 'FILE') - return false + if (self.begin.$$is_string && self.end.$$is_string) { + return nil; + } - // otherwise we have to stat, because maybe c=true - // if we know it exists, but not what it is. - } + if (n % 1 === 0) { + return $rb_divide(self.$size(), n).$ceil(); + } else { + // n is a float + var begin = self.begin, end = self.end, + abs = Math.abs, floor = Math.floor, + err = (abs(begin) + abs(end) + abs(end - begin)) / abs(n) * $$$($$$('Float'), 'EPSILON'), + size; - var exists - var stat = this.statCache[abs] - if (!stat) { - var lstat - try { - lstat = fs.lstatSync(abs) - } catch (er) { - if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) { - this.statCache[abs] = false - return false - } - } + if (err > 0.5) { + err = 0.5; + } - if (lstat && lstat.isSymbolicLink()) { - try { - stat = fs.statSync(abs) - } catch (er) { - stat = lstat + if (self.excl) { + size = floor((end - begin) / n - err); + if (size * n + begin < end) { + size++; + } + } else { + size = floor((end - begin) / n + err) + 1; + } + + return size; + } } - } else { - stat = lstat - } - } + if (!($yield !== nil)) { + if (((($truthy(self.begin['$is_a?']($$('Numeric'))) || ($truthy(self.begin['$nil?']()))) && (($truthy(self.end['$is_a?']($$('Numeric'))) || ($truthy(self.end['$nil?']()))))) && ($not(($truthy(($ret_or_1 = self.begin['$nil?']())) ? (self.end['$nil?']()) : ($ret_or_1)))))) { + return $$$($$$('Enumerator'), 'ArithmeticSequence').$new(self, n, "step") + } else { + return $send(self, 'enum_for', ["step", n], function $$5(){ + + coerceStepSize(); + return enumeratorSize(); + }) + } + } coerceStepSize(); + if ($truthy(self.begin.$$is_number && self.end.$$is_number)) { + + i = 0; + (function(){try { var $t_break = $thrower('break'); return $send(self, 'loop', [], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s, current = nil; + if (self.begin == null) self.begin = nil; + if (self.excl == null) self.excl = nil; + if (self.end == null) self.end = nil; - this.statCache[abs] = stat + + current = $rb_plus(self.begin, $rb_times(i, n)); + if ($truthy(self.excl)) { + if ($truthy($rb_ge(current, self.end))) { + $t_break.$throw(); + } + } else if ($truthy($rb_gt(current, self.end))) { + $t_break.$throw(); + }; + Opal.yield1($yield, current); + return (i = $rb_plus(i, 1));}, {$$s: self})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + } else { + + + if (self.begin.$$is_string && self.end.$$is_string && n % 1 !== 0) { + $Kernel.$raise($$$('TypeError'), "no implicit conversion to float from string"); + } + $send(self, 'each_with_index', [], function $$7(value, idx){ + + if (value == null) value = nil; + if (idx == null) idx = nil; + if ($eqeq(idx['$%'](n), 0)) { + return Opal.yield1($yield, value); + } else { + return nil + }}); + } return self; + }, -1); + + $def(self, '$%', function $Range_$percent$8(n) { + var self = this; - var c = true - if (stat) - c = stat.isDirectory() ? 'DIR' : 'FILE' + if (($truthy(self.begin['$is_a?']($$('Numeric'))) && ($truthy(self.end['$is_a?']($$('Numeric')))))) { + return $$$($$$('Enumerator'), 'ArithmeticSequence').$new(self, n, "%") + } else { + return self.$step(n) + } + }); + + $def(self, '$bsearch', function $$bsearch() { + var block = $$bsearch.$$p || nil, self = this; - this.cache[abs] = this.cache[abs] || c + $$bsearch.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("bsearch") + } if ($truthy(is_infinite(self) && (self.begin.$$is_number || self.end.$$is_number))) { + $Kernel.$raise($$$('NotImplementedError'), "Can't #bsearch an infinite range"); + } if (!$truthy(self.begin.$$is_number && self.end.$$is_number)) { + $Kernel.$raise($$$('TypeError'), "can't do binary search for " + (self.begin.$class())); + } return $send(self.$to_a(), 'bsearch', [], block.$to_proc()); + }); + + $def(self, '$to_s', function $$to_s() { + var self = this, $ret_or_1 = nil; - if (needDir && c === 'FILE') - return false + return "" + (($truthy(($ret_or_1 = self.begin)) ? ($ret_or_1) : (""))) + (($truthy(self.excl) ? ("...") : (".."))) + (($truthy(($ret_or_1 = self.end)) ? ($ret_or_1) : (""))) + }); + + $def(self, '$inspect', function $$inspect() { + var self = this, $ret_or_1 = nil; - return c -} + return "" + (($truthy(($ret_or_1 = self.begin)) ? (self.begin.$inspect()) : ($ret_or_1))) + (($truthy(self.excl) ? ("...") : (".."))) + (($truthy(($ret_or_1 = self.end)) ? (self.end.$inspect()) : ($ret_or_1))) + }); + + $def(self, '$marshal_load', function $$marshal_load(args) { + var self = this; -GlobSync.prototype._mark = function (p) { - return common.mark(this, p) -} + + self.begin = args['$[]']("begin"); + self.end = args['$[]']("end"); + return (self.excl = args['$[]']("excl")); + }); + + $def(self, '$hash', function $$hash() { + var self = this; -GlobSync.prototype._makeAbs = function (f) { - return common.makeAbs(this, f) -} + return [self.begin, self.end, self.excl].$hash() + }); + $alias(self, "==", "eql?"); + $alias(self, "include?", "cover?"); + return $alias(self, "member?", "cover?"); + })('::', null, $nesting); +}; +Opal.modules["corelib/proc"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $defs = Opal.defs, $def = Opal.def, $send = Opal.send, $to_a = Opal.to_a, $return_self = Opal.return_self, $ensure_kwargs = Opal.ensure_kwargs, $Opal = Opal.Opal, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$; -/***/ }), + Opal.add_stubs('raise,proc,call,to_proc,new,source_location,coerce_to!,dup'); + return (function($base, $super) { + var self = $klass($base, $super, 'Proc'); -/***/ 8460: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + + + Opal.prop(self.$$prototype, '$$is_proc', true); + Opal.prop(self.$$prototype, '$$is_lambda', false); + $defs(self, '$new', function $Proc_new$1() { + var block = $Proc_new$1.$$p || nil; -"use strict"; + $Proc_new$1.$$p = null; + if (!$truthy(block)) { + $Kernel.$raise($$$('ArgumentError'), "tried to create a Proc object without a block"); + } return block; + }); + + $def(self, '$call', function $$call($a) { + var block = $$call.$$p || nil, $post_args, args, self = this; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Parser = void 0; -var Tokenizer_js_1 = __importStar(__nccwpck_require__(2689)); -var decode_js_1 = __nccwpck_require__(5107); -var formTags = new Set([ - "input", - "option", - "optgroup", - "select", - "button", - "datalist", - "textarea", -]); -var pTag = new Set(["p"]); -var tableSectionTags = new Set(["thead", "tbody"]); -var ddtTags = new Set(["dd", "dt"]); -var rtpTags = new Set(["rt", "rp"]); -var openImpliesClose = new Map([ - ["tr", new Set(["tr", "th", "td"])], - ["th", new Set(["th"])], - ["td", new Set(["thead", "th", "td"])], - ["body", new Set(["head", "link", "script"])], - ["li", new Set(["li"])], - ["p", pTag], - ["h1", pTag], - ["h2", pTag], - ["h3", pTag], - ["h4", pTag], - ["h5", pTag], - ["h6", pTag], - ["select", formTags], - ["input", formTags], - ["output", formTags], - ["button", formTags], - ["datalist", formTags], - ["textarea", formTags], - ["option", new Set(["option"])], - ["optgroup", new Set(["optgroup", "option"])], - ["dd", ddtTags], - ["dt", ddtTags], - ["address", pTag], - ["article", pTag], - ["aside", pTag], - ["blockquote", pTag], - ["details", pTag], - ["div", pTag], - ["dl", pTag], - ["fieldset", pTag], - ["figcaption", pTag], - ["figure", pTag], - ["footer", pTag], - ["form", pTag], - ["header", pTag], - ["hr", pTag], - ["main", pTag], - ["nav", pTag], - ["ol", pTag], - ["pre", pTag], - ["section", pTag], - ["table", pTag], - ["ul", pTag], - ["rt", rtpTags], - ["rp", rtpTags], - ["tbody", tableSectionTags], - ["tfoot", tableSectionTags], -]); -var voidElements = new Set([ - "area", - "base", - "basefont", - "br", - "col", - "command", - "embed", - "frame", - "hr", - "img", - "input", - "isindex", - "keygen", - "link", - "meta", - "param", - "source", - "track", - "wbr", -]); -var foreignContextElements = new Set(["math", "svg"]); -var htmlIntegrationElements = new Set([ - "mi", - "mo", - "mn", - "ms", - "mtext", - "annotation-xml", - "foreignobject", - "desc", - "title", -]); -var reNameEnd = /\s|\//; -var Parser = /** @class */ (function () { - function Parser(cbs, options) { - if (options === void 0) { options = {}; } - var _a, _b, _c, _d, _e; - this.options = options; - /** The start index of the last event. */ - this.startIndex = 0; - /** The end index of the last event. */ - this.endIndex = 0; - /** - * Store the start index of the current open tag, - * so we can update the start index for attributes. - */ - this.openTagStart = 0; - this.tagname = ""; - this.attribname = ""; - this.attribvalue = ""; - this.attribs = null; - this.stack = []; - this.foreignContext = []; - this.buffers = []; - this.bufferOffset = 0; - /** The index of the last written buffer. Used when resuming after a `pause()`. */ - this.writeIndex = 0; - /** Indicates whether the parser has finished running / `.end` has been called. */ - this.ended = false; - this.cbs = cbs !== null && cbs !== void 0 ? cbs : {}; - this.lowerCaseTagNames = (_a = options.lowerCaseTags) !== null && _a !== void 0 ? _a : !options.xmlMode; - this.lowerCaseAttributeNames = - (_b = options.lowerCaseAttributeNames) !== null && _b !== void 0 ? _b : !options.xmlMode; - this.tokenizer = new ((_c = options.Tokenizer) !== null && _c !== void 0 ? _c : Tokenizer_js_1.default)(this.options, this); - (_e = (_d = this.cbs).onparserinit) === null || _e === void 0 ? void 0 : _e.call(_d, this); - } - // Tokenizer event handlers - /** @internal */ - Parser.prototype.ontext = function (start, endIndex) { - var _a, _b; - var data = this.getSlice(start, endIndex); - this.endIndex = endIndex - 1; - (_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, data); - this.startIndex = endIndex; - }; - /** @internal */ - Parser.prototype.ontextentity = function (cp) { - var _a, _b; - /* - * Entities can be emitted on the character, or directly after. - * We use the section start here to get accurate indices. - */ - var index = this.tokenizer.getSectionStart(); - this.endIndex = index - 1; - (_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, (0, decode_js_1.fromCodePoint)(cp)); - this.startIndex = index; - }; - Parser.prototype.isVoidElement = function (name) { - return !this.options.xmlMode && voidElements.has(name); - }; - /** @internal */ - Parser.prototype.onopentagname = function (start, endIndex) { - this.endIndex = endIndex; - var name = this.getSlice(start, endIndex); - if (this.lowerCaseTagNames) { - name = name.toLowerCase(); - } - this.emitOpenTag(name); - }; - Parser.prototype.emitOpenTag = function (name) { - var _a, _b, _c, _d; - this.openTagStart = this.startIndex; - this.tagname = name; - var impliesClose = !this.options.xmlMode && openImpliesClose.get(name); - if (impliesClose) { - while (this.stack.length > 0 && - impliesClose.has(this.stack[this.stack.length - 1])) { - var element = this.stack.pop(); - (_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, element, true); - } - } - if (!this.isVoidElement(name)) { - this.stack.push(name); - if (foreignContextElements.has(name)) { - this.foreignContext.push(true); - } - else if (htmlIntegrationElements.has(name)) { - this.foreignContext.push(false); - } - } - (_d = (_c = this.cbs).onopentagname) === null || _d === void 0 ? void 0 : _d.call(_c, name); - if (this.cbs.onopentag) - this.attribs = {}; - }; - Parser.prototype.endOpenTag = function (isImplied) { - var _a, _b; - this.startIndex = this.openTagStart; - if (this.attribs) { - (_b = (_a = this.cbs).onopentag) === null || _b === void 0 ? void 0 : _b.call(_a, this.tagname, this.attribs, isImplied); - this.attribs = null; - } - if (this.cbs.onclosetag && this.isVoidElement(this.tagname)) { - this.cbs.onclosetag(this.tagname, true); - } - this.tagname = ""; - }; - /** @internal */ - Parser.prototype.onopentagend = function (endIndex) { - this.endIndex = endIndex; - this.endOpenTag(false); - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.onclosetag = function (start, endIndex) { - var _a, _b, _c, _d, _e, _f; - this.endIndex = endIndex; - var name = this.getSlice(start, endIndex); - if (this.lowerCaseTagNames) { - name = name.toLowerCase(); - } - if (foreignContextElements.has(name) || - htmlIntegrationElements.has(name)) { - this.foreignContext.pop(); - } - if (!this.isVoidElement(name)) { - var pos = this.stack.lastIndexOf(name); - if (pos !== -1) { - if (this.cbs.onclosetag) { - var count = this.stack.length - pos; - while (count--) { - // We know the stack has sufficient elements. - this.cbs.onclosetag(this.stack.pop(), count !== 0); - } - } - else - this.stack.length = pos; - } - else if (!this.options.xmlMode && name === "p") { - // Implicit open before close - this.emitOpenTag("p"); - this.closeCurrentTag(true); - } - } - else if (!this.options.xmlMode && name === "br") { - // We can't use `emitOpenTag` for implicit open, as `br` would be implicitly closed. - (_b = (_a = this.cbs).onopentagname) === null || _b === void 0 ? void 0 : _b.call(_a, "br"); - (_d = (_c = this.cbs).onopentag) === null || _d === void 0 ? void 0 : _d.call(_c, "br", {}, true); - (_f = (_e = this.cbs).onclosetag) === null || _f === void 0 ? void 0 : _f.call(_e, "br", false); - } - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.onselfclosingtag = function (endIndex) { - this.endIndex = endIndex; - if (this.options.xmlMode || - this.options.recognizeSelfClosing || - this.foreignContext[this.foreignContext.length - 1]) { - this.closeCurrentTag(false); - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - } - else { - // Ignore the fact that the tag is self-closing. - this.onopentagend(endIndex); - } - }; - Parser.prototype.closeCurrentTag = function (isOpenImplied) { - var _a, _b; - var name = this.tagname; - this.endOpenTag(isOpenImplied); - // Self-closing tags will be on the top of the stack - if (this.stack[this.stack.length - 1] === name) { - // If the opening tag isn't implied, the closing tag has to be implied. - (_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, name, !isOpenImplied); - this.stack.pop(); - } - }; - /** @internal */ - Parser.prototype.onattribname = function (start, endIndex) { - this.startIndex = start; - var name = this.getSlice(start, endIndex); - this.attribname = this.lowerCaseAttributeNames - ? name.toLowerCase() - : name; - }; - /** @internal */ - Parser.prototype.onattribdata = function (start, endIndex) { - this.attribvalue += this.getSlice(start, endIndex); - }; - /** @internal */ - Parser.prototype.onattribentity = function (cp) { - this.attribvalue += (0, decode_js_1.fromCodePoint)(cp); - }; - /** @internal */ - Parser.prototype.onattribend = function (quote, endIndex) { - var _a, _b; - this.endIndex = endIndex; - (_b = (_a = this.cbs).onattribute) === null || _b === void 0 ? void 0 : _b.call(_a, this.attribname, this.attribvalue, quote === Tokenizer_js_1.QuoteType.Double - ? '"' - : quote === Tokenizer_js_1.QuoteType.Single - ? "'" - : quote === Tokenizer_js_1.QuoteType.NoValue - ? undefined - : null); - if (this.attribs && - !Object.prototype.hasOwnProperty.call(this.attribs, this.attribname)) { - this.attribs[this.attribname] = this.attribvalue; - } - this.attribvalue = ""; - }; - Parser.prototype.getInstructionName = function (value) { - var index = value.search(reNameEnd); - var name = index < 0 ? value : value.substr(0, index); - if (this.lowerCaseTagNames) { - name = name.toLowerCase(); - } - return name; - }; - /** @internal */ - Parser.prototype.ondeclaration = function (start, endIndex) { - this.endIndex = endIndex; - var value = this.getSlice(start, endIndex); - if (this.cbs.onprocessinginstruction) { - var name = this.getInstructionName(value); - this.cbs.onprocessinginstruction("!".concat(name), "!".concat(value)); - } - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.onprocessinginstruction = function (start, endIndex) { - this.endIndex = endIndex; - var value = this.getSlice(start, endIndex); - if (this.cbs.onprocessinginstruction) { - var name = this.getInstructionName(value); - this.cbs.onprocessinginstruction("?".concat(name), "?".concat(value)); - } - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.oncomment = function (start, endIndex, offset) { - var _a, _b, _c, _d; - this.endIndex = endIndex; - (_b = (_a = this.cbs).oncomment) === null || _b === void 0 ? void 0 : _b.call(_a, this.getSlice(start, endIndex - offset)); - (_d = (_c = this.cbs).oncommentend) === null || _d === void 0 ? void 0 : _d.call(_c); - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.oncdata = function (start, endIndex, offset) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; - this.endIndex = endIndex; - var value = this.getSlice(start, endIndex - offset); - if (this.options.xmlMode || this.options.recognizeCDATA) { - (_b = (_a = this.cbs).oncdatastart) === null || _b === void 0 ? void 0 : _b.call(_a); - (_d = (_c = this.cbs).ontext) === null || _d === void 0 ? void 0 : _d.call(_c, value); - (_f = (_e = this.cbs).oncdataend) === null || _f === void 0 ? void 0 : _f.call(_e); + $$call.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + if (block !== nil) { + self.$$p = block; + } + + var result, $brk = self.$$brk, $ret = self.$$ret; + + if ($brk || ($ret && self.$$is_lambda)) { + try { + if (self.$$is_lambda) { + result = self.apply(null, args); + } + else { + result = Opal.yieldX(self, args); + } + } catch (err) { + if (err === $brk) { + return err.$v; + } + else if (self.$$is_lambda && err === $ret) { + return err.$v; + } + else { + throw err; + } } - else { - (_h = (_g = this.cbs).oncomment) === null || _h === void 0 ? void 0 : _h.call(_g, "[CDATA[".concat(value, "]]")); - (_k = (_j = this.cbs).oncommentend) === null || _k === void 0 ? void 0 : _k.call(_j); + } + else { + if (self.$$is_lambda) { + result = self.apply(null, args); } - // Set `startIndex` for next node - this.startIndex = endIndex + 1; - }; - /** @internal */ - Parser.prototype.onend = function () { - var _a, _b; - if (this.cbs.onclosetag) { - // Set the end index for all remaining tags - this.endIndex = this.startIndex; - for (var index = this.stack.length; index > 0; this.cbs.onclosetag(this.stack[--index], true)) - ; + else { + result = Opal.yieldX(self, args); } - (_b = (_a = this.cbs).onend) === null || _b === void 0 ? void 0 : _b.call(_a); - }; - /** - * Resets the parser to a blank state, ready to parse a new HTML document - */ - Parser.prototype.reset = function () { - var _a, _b, _c, _d; - (_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a); - this.tokenizer.reset(); - this.tagname = ""; - this.attribname = ""; - this.attribs = null; - this.stack.length = 0; - this.startIndex = 0; - this.endIndex = 0; - (_d = (_c = this.cbs).onparserinit) === null || _d === void 0 ? void 0 : _d.call(_c, this); - this.buffers.length = 0; - this.bufferOffset = 0; - this.writeIndex = 0; - this.ended = false; - }; - /** - * Resets the parser, then parses a complete document and - * pushes it to the handler. - * - * @param data Document to parse. - */ - Parser.prototype.parseComplete = function (data) { - this.reset(); - this.end(data); - }; - Parser.prototype.getSlice = function (start, end) { - while (start - this.bufferOffset >= this.buffers[0].length) { - this.shiftBuffer(); + } + + return result; + }, -1); + + $def(self, '$>>', function $Proc_$gt$gt$2(other) { + var self = this; + + $Proc_$gt$gt$2.$$p = null; + return $send($Kernel, 'proc', [], function $$3($a){var block = $$3.$$p || nil, $post_args, args, self = $$3.$$s == null ? this : $$3.$$s, out = nil; + + $$3.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + out = $send(self, 'call', $to_a(args), block.$to_proc()); + return other.$call(out);}, {$$arity: -1, $$s: self}) + }); + + $def(self, '$<<', function $Proc_$lt$lt$4(other) { + var self = this; + + $Proc_$lt$lt$4.$$p = null; + return $send($Kernel, 'proc', [], function $$5($a){var block = $$5.$$p || nil, $post_args, args, self = $$5.$$s == null ? this : $$5.$$s, out = nil; + + $$5.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + out = $send(other, 'call', $to_a(args), block.$to_proc()); + return self.$call(out);}, {$$arity: -1, $$s: self}) + }); + + $def(self, '$to_proc', $return_self); + + $def(self, '$lambda?', function $Proc_lambda$ques$6() { + var self = this; + + return !!self.$$is_lambda; + }); + + $def(self, '$arity', function $$arity() { + var self = this; + + + if (self.$$is_curried) { + return -1; + } else if (self.$$arity != null) { + return self.$$arity; + } else { + return self.length; + } + + }); + + $def(self, '$source_location', function $$source_location() { + var self = this, $ret_or_1 = nil; + + + if (self.$$is_curried) { return nil; } if ($truthy(($ret_or_1 = self.$$source_location))) { + return $ret_or_1 + } else { + return nil + } }); + + $def(self, '$binding', function $$binding() { + var self = this; + + + if (self.$$is_curried) { $Kernel.$raise($$$('ArgumentError'), "Can't create Binding"); } if ($truthy((($$$('::', 'Binding', 'skip_raise')) ? 'constant' : nil))) { + return $$$('Binding').$new(nil, [], self.$$s, self.$source_location()) + } else { + return nil + } }); + + $def(self, '$parameters', function $$parameters($kwargs) { + var lambda, self = this; + + + $kwargs = $ensure_kwargs($kwargs); + + lambda = $kwargs.$$smap["lambda"]; + if (self.$$is_curried) { + return [["rest"]]; + } else if (self.$$parameters) { + if (lambda == null ? self.$$is_lambda : lambda) { + return self.$$parameters; + } else { + var result = [], i, length; + + for (i = 0, length = self.$$parameters.length; i < length; i++) { + var parameter = self.$$parameters[i]; + + if (parameter[0] === 'req') { + // required arguments always have name + parameter = ['opt', parameter[1]]; + } + + result.push(parameter); + } + + return result; } - var slice = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset); - while (end - this.bufferOffset > this.buffers[0].length) { - this.shiftBuffer(); - slice += this.buffers[0].slice(0, end - this.bufferOffset); + } else { + return []; + } + }, -1); + + $def(self, '$curry', function $$curry(arity) { + var self = this; + + if (arity === undefined) { + arity = self.length; + } + else { + arity = $Opal['$coerce_to!'](arity, $$$('Integer'), "to_int"); + if (self.$$is_lambda && arity !== self.length) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arity) + " for " + (self.length) + ")"); } - return slice; - }; - Parser.prototype.shiftBuffer = function () { - this.bufferOffset += this.buffers[0].length; - this.writeIndex--; - this.buffers.shift(); - }; - /** - * Parses a chunk of data and calls the corresponding callbacks. - * - * @param chunk Chunk to parse. - */ - Parser.prototype.write = function (chunk) { - var _a, _b; - if (this.ended) { - (_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".write() after done!")); - return; + } + + function curried () { + var args = $slice(arguments), + length = args.length, + result; + + if (length > arity && self.$$is_lambda && !self.$$is_curried) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (length) + " for " + (arity) + ")"); } - this.buffers.push(chunk); - if (this.tokenizer.running) { - this.tokenizer.write(chunk); - this.writeIndex++; + + if (length >= arity) { + return self.$call.apply(self, args); } - }; - /** - * Parses the end of the buffer and clears the stack, calls onend. - * - * @param chunk Optional final chunk to parse. - */ - Parser.prototype.end = function (chunk) { - var _a, _b; - if (this.ended) { - (_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".end() after done!")); - return; + + result = function () { + return curried.apply(null, + args.concat($slice(arguments))); + }; + result.$$is_lambda = self.$$is_lambda; + result.$$is_curried = true; + + return result; + } + curried.$$is_lambda = self.$$is_lambda; + curried.$$is_curried = true; + return curried; + }, -1); + + $def(self, '$dup', function $$dup() { + var self = this; + + + var original_proc = self.$$original_proc || self, + proc = function () { + return original_proc.apply(this, arguments); + }; + + for (var prop in self) { + if (self.hasOwnProperty(prop)) { + proc[prop] = self[prop]; } - if (chunk) - this.write(chunk); - this.ended = true; - this.tokenizer.end(); - }; - /** - * Pauses parsing. The parser won't emit events until `resume` is called. - */ - Parser.prototype.pause = function () { - this.tokenizer.pause(); - }; - /** - * Resumes parsing after `pause` was called. - */ - Parser.prototype.resume = function () { - this.tokenizer.resume(); - while (this.tokenizer.running && - this.writeIndex < this.buffers.length) { - this.tokenizer.write(this.buffers[this.writeIndex++]); + } + + return proc; + + }); + $alias(self, "===", "call"); + $alias(self, "clone", "dup"); + $alias(self, "yield", "call"); + return $alias(self, "[]", "call"); + })('::', Function) +}; + +Opal.modules["corelib/method"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $slice = Opal.slice, $alias = Opal.alias, $Kernel = Opal.Kernel, $send = Opal.send, $to_a = Opal.to_a, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('attr_reader,arity,curry,>>,<<,new,class,join,source_location,call,raise,bind,to_proc'); + + (function($base, $super) { + var self = $klass($base, $super, 'Method'); + + var $proto = self.$$prototype; + + $proto.method = $proto.receiver = $proto.owner = $proto.name = nil; + + self.$attr_reader("owner", "receiver", "name"); + + $def(self, '$initialize', function $$initialize(receiver, owner, method, name) { + var self = this; + + + self.receiver = receiver; + self.owner = owner; + self.name = name; + return (self.method = method); + }); + + $def(self, '$arity', function $$arity() { + var self = this; + + return self.method.$arity() + }); + + $def(self, '$parameters', function $$parameters() { + var self = this; + + return self.method.$$parameters + }); + + $def(self, '$source_location', function $$source_location() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.method.$$source_location))) { + return $ret_or_1 + } else { + return ["(eval)", 0] + } + }); + + $def(self, '$comments', function $$comments() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.method.$$comments))) { + return $ret_or_1 + } else { + return [] + } + }); + + $def(self, '$call', function $$call($a) { + var block = $$call.$$p || nil, $post_args, args, self = this; + + $$call.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + + self.method.$$p = block; + + return self.method.apply(self.receiver, args); + }, -1); + + $def(self, '$curry', function $$curry(arity) { + var self = this; + return self.method.$curry(arity); + }, -1); + + $def(self, '$>>', function $Method_$gt$gt$1(other) { + var self = this; + + return self.method['$>>'](other) + }); + + $def(self, '$<<', function $Method_$lt$lt$2(other) { + var self = this; + + return self.method['$<<'](other) + }); + + $def(self, '$unbind', function $$unbind() { + var self = this; + + return $$$('UnboundMethod').$new(self.receiver.$class(), self.owner, self.method, self.name) + }); + + $def(self, '$to_proc', function $$to_proc() { + var self = this; + + + var proc = self.$call.bind(self); + proc.$$unbound = self.method; + proc.$$is_lambda = true; + proc.$$arity = self.method.$$arity == null ? self.method.length : self.method.$$arity; + proc.$$parameters = self.method.$$parameters; + return proc; + + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + return "#<" + (self.$class()) + ": " + (self.receiver.$class()) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>" + }); + $alias(self, "[]", "call"); + return $alias(self, "===", "call"); + })('::', null); + return (function($base, $super) { + var self = $klass($base, $super, 'UnboundMethod'); + + var $proto = self.$$prototype; + + $proto.method = $proto.owner = $proto.name = $proto.source = nil; + + self.$attr_reader("source", "owner", "name"); + + $def(self, '$initialize', function $$initialize(source, owner, method, name) { + var self = this; + + + self.source = source; + self.owner = owner; + self.method = method; + return (self.name = name); + }); + + $def(self, '$arity', function $$arity() { + var self = this; + + return self.method.$arity() + }); + + $def(self, '$parameters', function $$parameters() { + var self = this; + + return self.method.$$parameters + }); + + $def(self, '$source_location', function $$source_location() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.method.$$source_location))) { + return $ret_or_1 + } else { + return ["(eval)", 0] + } + }); + + $def(self, '$comments', function $$comments() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.method.$$comments))) { + return $ret_or_1 + } else { + return [] + } + }); + + $def(self, '$bind', function $$bind(object) { + var self = this; + + + if (self.owner.$$is_module || Opal.is_a(object, self.owner)) { + return $$$('Method').$new(object, self.owner, self.method, self.name); + } + else { + $Kernel.$raise($$$('TypeError'), "can't bind singleton method to a different class (expected " + (object) + ".kind_of?(" + (self.owner) + " to be true)"); + } + + }); + + $def(self, '$bind_call', function $$bind_call(object, $a) { + var block = $$bind_call.$$p || nil, $post_args, args, self = this; + + $$bind_call.$$p = null; + $post_args = $slice(arguments, 1); + args = $post_args; + return $send(self.$bind(object), 'call', $to_a(args), block.$to_proc()); + }, -2); + return $def(self, '$inspect', function $$inspect() { + var self = this; + + return "#<" + (self.$class()) + ": " + (self.source) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>" + }); + })('::', null); +}; + +Opal.modules["corelib/variables"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $gvars = Opal.gvars, $const_set = Opal.const_set, $Object = Opal.Object, $hash2 = Opal.hash2, nil = Opal.nil; + + Opal.add_stubs('new'); + + $gvars['&'] = $gvars['~'] = $gvars['`'] = $gvars["'"] = nil; + $gvars.LOADED_FEATURES = ($gvars["\""] = Opal.loaded_features); + $gvars.LOAD_PATH = ($gvars[":"] = []); + $gvars["/"] = "\n"; + $gvars[","] = nil; + $const_set('::', 'ARGV', []); + $const_set('::', 'ARGF', $Object.$new()); + $const_set('::', 'ENV', $hash2([], {})); + $gvars.VERBOSE = false; + $gvars.DEBUG = false; + return ($gvars.SAFE = 0); +}; + +Opal.modules["corelib/io"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $const_set = Opal.const_set, $not = Opal.not, $truthy = Opal.truthy, $def = Opal.def, $return_ivar = Opal.return_ivar, $return_val = Opal.return_val, $slice = Opal.slice, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $send = Opal.send, $to_a = Opal.to_a, $rb_plus = Opal.rb_plus, $neqeq = Opal.neqeq, $range = Opal.range, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $rb_gt = Opal.rb_gt, $assign_ivar_val = Opal.assign_ivar_val, $alias = Opal.alias, $a, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('attr_reader,attr_accessor,!,match?,include?,size,write,String,flatten,puts,sysread_noraise,+,!=,[],ord,getc,readchar,raise,gets,==,to_str,length,split,sub,sysread,>,to_a,each_line,enum_for,getbyte,closed_write?,closed_read?,each,eof,new,write_proc=,read_proc='); + + (function($base, $super) { + var self = $klass($base, $super, 'IO'); + + var $proto = self.$$prototype; + + $proto.read_buffer = $proto.closed = nil; + + $const_set(self, 'SEEK_SET', 0); + $const_set(self, 'SEEK_CUR', 1); + $const_set(self, 'SEEK_END', 2); + $const_set(self, 'SEEK_DATA', 3); + $const_set(self, 'SEEK_HOLE', 4); + $const_set(self, 'READABLE', 1); + $const_set(self, 'WRITABLE', 4); + self.$attr_reader("eof"); + self.$attr_accessor("read_proc", "sync", "tty", "write_proc"); + + $def(self, '$initialize', function $$initialize(fd, flags) { + var self = this; + + + if (flags == null) flags = "r"; + self.fd = fd; + self.flags = flags; + self.eof = false; + if (($truthy(flags['$include?']("r")) && ($not(flags['$match?'](/[wa+]/))))) { + return (self.closed = "write") + } else if (($truthy(flags['$match?'](/[wa]/)) && ($not(flags['$match?'](/[r+]/))))) { + return (self.closed = "read") + } else { + return nil + } }, -2); + + $def(self, '$fileno', $return_ivar("fd")); + + $def(self, '$tty?', function $IO_tty$ques$1() { + var self = this; + + return self.tty == true; + }); + + $def(self, '$write', function $$write(string) { + var self = this; + + + self.write_proc(string); + return string.$size(); + }); + + $def(self, '$flush', $return_val(nil)); + + $def(self, '$<<', function $IO_$lt$lt$2(string) { + var self = this; + + + self.$write(string); + return self; + }); + + $def(self, '$print', function $$print($a) { + var $post_args, args, self = this; + if ($gvars[","] == null) $gvars[","] = nil; + + + $post_args = $slice(arguments); + args = $post_args; + + for (var i = 0, ii = args.length; i < ii; i++) { + args[i] = $Kernel.$String(args[i]); + } + self.$write(args.join($gvars[","])); + return nil; + }, -1); + + $def(self, '$puts', function $$puts($a) { + var $post_args, args, self = this; + + + $post_args = $slice(arguments); + args = $post_args; + + var line; + if (args.length === 0) { + self.$write("\n"); + return nil; + } else { + for (var i = 0, ii = args.length; i < ii; i++) { + if (args[i].$$is_array){ + var ary = (args[i]).$flatten(); + if (ary.length > 0) $send(self, 'puts', $to_a((ary))); + } else { + if (args[i].$$is_string) { + line = args[i].valueOf(); + } else { + line = $Kernel.$String(args[i]); + } + if (!line.endsWith("\n")) line += "\n"; + self.$write(line); + } } - if (this.ended) - this.tokenizer.end(); - }; - /** - * Alias of `write`, for backwards compatibility. - * - * @param chunk Chunk to parse. - * @deprecated - */ - Parser.prototype.parseChunk = function (chunk) { - this.write(chunk); - }; - /** - * Alias of `end`, for backwards compatibility. - * - * @param chunk Optional final chunk to parse. - * @deprecated - */ - Parser.prototype.done = function (chunk) { - this.end(chunk); - }; - return Parser; -}()); -exports.Parser = Parser; -//# sourceMappingURL=Parser.js.map + } + return nil; + }, -1); + + $def(self, '$getc', function $$getc() { + var self = this, $ret_or_1 = nil, parts = nil, ret = nil; + + + self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")); + parts = ""; + do { + + self.read_buffer = $rb_plus(self.read_buffer, parts); + if ($neqeq(self.read_buffer, "")) { + + ret = self.read_buffer['$[]'](0); + self.read_buffer = self.read_buffer['$[]']($range(1, -1, false)); + return ret; + } } while ($truthy((parts = self.$sysread_noraise(1)))); return nil; + }); + + $def(self, '$getbyte', function $$getbyte() { + var $a, self = this; + + return ($a = self.$getc(), ($a === nil || $a == null) ? nil : $a.$ord()) + }); + + $def(self, '$readbyte', function $$readbyte() { + var self = this; + + return self.$readchar().$ord() + }); + + $def(self, '$readchar', function $$readchar() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.$getc()))) { + return $ret_or_1 + } else { + return $Kernel.$raise($$$('EOFError'), "end of file reached") + } + }); + + $def(self, '$readline', function $$readline($a) { + var $post_args, args, self = this, $ret_or_1 = nil; + + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy(($ret_or_1 = $send(self, 'gets', $to_a(args))))) { + return $ret_or_1 + } else { + return $Kernel.$raise($$$('EOFError'), "end of file reached") + } }, -1); + + $def(self, '$gets', function $$gets(sep, limit, opts) { + var $a, $b, self = this, orig_sep = nil, $ret_or_1 = nil, seplen = nil, data = nil, ret = nil, orig_buffer = nil; + if ($gvars["/"] == null) $gvars["/"] = nil; + + + if (sep == null) sep = false; + if (limit == null) limit = nil; + if (opts == null) opts = $hash2([], {}); + if (($truthy(sep.$$is_number) && ($not(limit)))) { + $a = [false, sep, limit], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]); + } if ((($truthy(sep.$$is_hash) && ($not(limit))) && ($eqeq(opts, $hash2([], {}))))) { + $a = [false, nil, sep], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]); + } else if (($truthy(limit.$$is_hash) && ($eqeq(opts, $hash2([], {}))))) { + $a = [sep, nil, limit], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]); + } orig_sep = sep; + if ($eqeq(sep, false)) { + sep = $gvars["/"]; + } if ($eqeq(sep, "")) { + sep = /\r?\n\r?\n/; + } sep = ($truthy(($ret_or_1 = sep)) ? ($ret_or_1) : ("")); + if (!$eqeq(orig_sep, "")) { + sep = sep.$to_str(); + } seplen = ($eqeq(orig_sep, "") ? (2) : (sep.$length())); + if ($eqeq(sep, " ")) { + sep = / /; + } self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")); + data = ""; + ret = nil; + do { + + self.read_buffer = $rb_plus(self.read_buffer, data); + if (($neqeq(sep, "") && ($truthy(($truthy(sep.$$is_regexp) ? (self.read_buffer['$match?'](sep)) : (self.read_buffer['$include?'](sep))))))) { + + orig_buffer = self.read_buffer; + $b = self.read_buffer.$split(sep, 2), $a = $to_ary($b), (ret = ($a[0] == null ? nil : $a[0])), (self.read_buffer = ($a[1] == null ? nil : $a[1])); + if ($neqeq(ret, orig_buffer)) { + ret = $rb_plus(ret, orig_buffer['$[]'](ret.$length(), seplen)); + } break; + } } while ($truthy((data = self.$sysread_noraise(($eqeq(sep, "") ? (65536) : (1)))))); if (!$truthy(ret)) { + + $a = [($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")), ""], (ret = $a[0]), (self.read_buffer = $a[1]); + if ($eqeq(ret, "")) { + ret = nil; + } } if ($truthy(ret)) { + + if ($truthy(limit)) { + + ret = ret['$[]'](Opal.Range.$new(0,limit, true)); + self.read_buffer = $rb_plus(ret['$[]'](Opal.Range.$new(limit, -1, false)), self.read_buffer); + } if ($truthy(opts['$[]']("chomp"))) { + ret = ret.$sub(/\r?\n$/, ""); + } if ($eqeq(orig_sep, "")) { + ret = ret.$sub(/^[\r\n]+/, ""); + } } if ($eqeq(orig_sep, false)) { + $gvars._ = ret; + } return ret; + }, -1); + + $def(self, '$sysread', function $$sysread(integer) { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.read_proc(integer)))) { + return $ret_or_1 + } else { + + self.eof = true; + return $Kernel.$raise($$$('EOFError'), "end of file reached"); + } + }); + + $def(self, '$sysread_noraise', function $$sysread_noraise(integer) { + var self = this; + + try { + return self.$sysread(integer) + } catch ($err) { + if (Opal.rescue($err, [$$$('EOFError')])) { + try { + return nil + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + + $def(self, '$readpartial', function $$readpartial(integer) { + var $a, self = this, $ret_or_1 = nil, part = nil, ret = nil; -/***/ }), + + self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")); + part = self.$sysread(integer); + $a = [$rb_plus(self.read_buffer, ($truthy(($ret_or_1 = part)) ? ($ret_or_1) : (""))), ""], (ret = $a[0]), (self.read_buffer = $a[1]); + if ($eqeq(ret, "")) { + ret = nil; + } return ret; + }); + + $def(self, '$read', function $$read(integer) { + var $a, self = this, $ret_or_1 = nil, parts = nil, ret = nil; -/***/ 2689: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + + if (integer == null) integer = nil; + self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")); + parts = ""; + ret = nil; + do { + + self.read_buffer = $rb_plus(self.read_buffer, parts); + if (($truthy(integer) && ($truthy($rb_gt(self.read_buffer.$length(), integer))))) { + + $a = [self.read_buffer['$[]'](Opal.Range.$new(0,integer, true)), self.read_buffer['$[]'](Opal.Range.$new(integer, -1, false))], (ret = $a[0]), (self.read_buffer = $a[1]); + return ret; + } } while ($truthy((parts = self.$sysread_noraise(($truthy(($ret_or_1 = integer)) ? ($ret_or_1) : (65536)))))); $a = [self.read_buffer, ""], (ret = $a[0]), (self.read_buffer = $a[1]); + return ret; + }, -1); + + $def(self, '$readlines', function $$readlines(separator) { + var self = this; + if ($gvars["/"] == null) $gvars["/"] = nil; -"use strict"; + + if (separator == null) separator = $gvars["/"]; + return self.$each_line(separator).$to_a(); + }, -1); + + $def(self, '$each', function $$each($a, $b) { + var block = $$each.$$p || nil, $post_args, sep, args, self = this, s = nil; + if ($gvars["/"] == null) $gvars["/"] = nil; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.QuoteType = void 0; -var decode_js_1 = __nccwpck_require__(5107); -var CharCodes; -(function (CharCodes) { - CharCodes[CharCodes["Tab"] = 9] = "Tab"; - CharCodes[CharCodes["NewLine"] = 10] = "NewLine"; - CharCodes[CharCodes["FormFeed"] = 12] = "FormFeed"; - CharCodes[CharCodes["CarriageReturn"] = 13] = "CarriageReturn"; - CharCodes[CharCodes["Space"] = 32] = "Space"; - CharCodes[CharCodes["ExclamationMark"] = 33] = "ExclamationMark"; - CharCodes[CharCodes["Number"] = 35] = "Number"; - CharCodes[CharCodes["Amp"] = 38] = "Amp"; - CharCodes[CharCodes["SingleQuote"] = 39] = "SingleQuote"; - CharCodes[CharCodes["DoubleQuote"] = 34] = "DoubleQuote"; - CharCodes[CharCodes["Dash"] = 45] = "Dash"; - CharCodes[CharCodes["Slash"] = 47] = "Slash"; - CharCodes[CharCodes["Zero"] = 48] = "Zero"; - CharCodes[CharCodes["Nine"] = 57] = "Nine"; - CharCodes[CharCodes["Semi"] = 59] = "Semi"; - CharCodes[CharCodes["Lt"] = 60] = "Lt"; - CharCodes[CharCodes["Eq"] = 61] = "Eq"; - CharCodes[CharCodes["Gt"] = 62] = "Gt"; - CharCodes[CharCodes["Questionmark"] = 63] = "Questionmark"; - CharCodes[CharCodes["UpperA"] = 65] = "UpperA"; - CharCodes[CharCodes["LowerA"] = 97] = "LowerA"; - CharCodes[CharCodes["UpperF"] = 70] = "UpperF"; - CharCodes[CharCodes["LowerF"] = 102] = "LowerF"; - CharCodes[CharCodes["UpperZ"] = 90] = "UpperZ"; - CharCodes[CharCodes["LowerZ"] = 122] = "LowerZ"; - CharCodes[CharCodes["LowerX"] = 120] = "LowerX"; - CharCodes[CharCodes["OpeningSquareBracket"] = 91] = "OpeningSquareBracket"; -})(CharCodes || (CharCodes = {})); -/** All the states the tokenizer can be in. */ -var State; -(function (State) { - State[State["Text"] = 1] = "Text"; - State[State["BeforeTagName"] = 2] = "BeforeTagName"; - State[State["InTagName"] = 3] = "InTagName"; - State[State["InSelfClosingTag"] = 4] = "InSelfClosingTag"; - State[State["BeforeClosingTagName"] = 5] = "BeforeClosingTagName"; - State[State["InClosingTagName"] = 6] = "InClosingTagName"; - State[State["AfterClosingTagName"] = 7] = "AfterClosingTagName"; - // Attributes - State[State["BeforeAttributeName"] = 8] = "BeforeAttributeName"; - State[State["InAttributeName"] = 9] = "InAttributeName"; - State[State["AfterAttributeName"] = 10] = "AfterAttributeName"; - State[State["BeforeAttributeValue"] = 11] = "BeforeAttributeValue"; - State[State["InAttributeValueDq"] = 12] = "InAttributeValueDq"; - State[State["InAttributeValueSq"] = 13] = "InAttributeValueSq"; - State[State["InAttributeValueNq"] = 14] = "InAttributeValueNq"; - // Declarations - State[State["BeforeDeclaration"] = 15] = "BeforeDeclaration"; - State[State["InDeclaration"] = 16] = "InDeclaration"; - // Processing instructions - State[State["InProcessingInstruction"] = 17] = "InProcessingInstruction"; - // Comments & CDATA - State[State["BeforeComment"] = 18] = "BeforeComment"; - State[State["CDATASequence"] = 19] = "CDATASequence"; - State[State["InSpecialComment"] = 20] = "InSpecialComment"; - State[State["InCommentLike"] = 21] = "InCommentLike"; - // Special tags - State[State["BeforeSpecialS"] = 22] = "BeforeSpecialS"; - State[State["SpecialStartSequence"] = 23] = "SpecialStartSequence"; - State[State["InSpecialTag"] = 24] = "InSpecialTag"; - State[State["BeforeEntity"] = 25] = "BeforeEntity"; - State[State["BeforeNumericEntity"] = 26] = "BeforeNumericEntity"; - State[State["InNamedEntity"] = 27] = "InNamedEntity"; - State[State["InNumericEntity"] = 28] = "InNumericEntity"; - State[State["InHexEntity"] = 29] = "InHexEntity"; -})(State || (State = {})); -function isWhitespace(c) { - return (c === CharCodes.Space || - c === CharCodes.NewLine || - c === CharCodes.Tab || - c === CharCodes.FormFeed || - c === CharCodes.CarriageReturn); -} -function isEndOfTagSection(c) { - return c === CharCodes.Slash || c === CharCodes.Gt || isWhitespace(c); -} -function isNumber(c) { - return c >= CharCodes.Zero && c <= CharCodes.Nine; -} -function isASCIIAlpha(c) { - return ((c >= CharCodes.LowerA && c <= CharCodes.LowerZ) || - (c >= CharCodes.UpperA && c <= CharCodes.UpperZ)); -} -function isHexDigit(c) { - return ((c >= CharCodes.UpperA && c <= CharCodes.UpperF) || - (c >= CharCodes.LowerA && c <= CharCodes.LowerF)); -} -var QuoteType; -(function (QuoteType) { - QuoteType[QuoteType["NoValue"] = 0] = "NoValue"; - QuoteType[QuoteType["Unquoted"] = 1] = "Unquoted"; - QuoteType[QuoteType["Single"] = 2] = "Single"; - QuoteType[QuoteType["Double"] = 3] = "Double"; -})(QuoteType = exports.QuoteType || (exports.QuoteType = {})); -/** - * Sequences used to match longer strings. - * - * We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End - * sequences with an increased offset. - */ -var Sequences = { - Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]), - CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]), - CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]), - ScriptEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74]), - StyleEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65]), - TitleEnd: new Uint8Array([0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65]), // `</title` + $$each.$$p = null; + $post_args = $slice(arguments); + + if ($post_args.length > 0) sep = $post_args.shift();if (sep == null) sep = $gvars["/"]; + args = $post_args; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each", sep].concat($to_a(args))) + } while ($truthy((s = $send(self, 'gets', [sep].concat($to_a(args)))))) { + Opal.yield1(block, s); + } return self; + }, -1); + + $def(self, '$each_byte', function $$each_byte() { + var block = $$each_byte.$$p || nil, self = this, s = nil; + + $$each_byte.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("each_byte") + } while ($truthy((s = self.$getbyte()))) { + Opal.yield1(block, s); + } return self; + }); + + $def(self, '$each_char', function $$each_char() { + var block = $$each_char.$$p || nil, self = this, s = nil; + + $$each_char.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("each_char") + } while ($truthy((s = self.$getc()))) { + Opal.yield1(block, s); + } return self; + }); + + $def(self, '$close', $assign_ivar_val("closed", "both")); + + $def(self, '$close_read', function $$close_read() { + var self = this; + + if ($eqeq(self.closed, "write")) { + return (self.closed = "both") + } else { + return (self.closed = "read") + } + }); + + $def(self, '$close_write', function $$close_write() { + var self = this; + + if ($eqeq(self.closed, "read")) { + return (self.closed = "both") + } else { + return (self.closed = "write") + } + }); + + $def(self, '$closed?', function $IO_closed$ques$3() { + var self = this; + + return self.closed['$==']("both") + }); + + $def(self, '$closed_read?', function $IO_closed_read$ques$4() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.closed['$==']("read")))) { + return $ret_or_1 + } else { + return self.closed['$==']("both") + } + }); + + $def(self, '$closed_write?', function $IO_closed_write$ques$5() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.closed['$==']("write")))) { + return $ret_or_1 + } else { + return self.closed['$==']("both") + } + }); + + $def(self, '$check_writable', function $$check_writable() { + var self = this; + + if ($truthy(self['$closed_write?']())) { + return $Kernel.$raise($$$('IOError'), "not opened for writing") + } else { + return nil + } + }); + + $def(self, '$check_readable', function $$check_readable() { + var self = this; + + if ($truthy(self['$closed_read?']())) { + return $Kernel.$raise($$$('IOError'), "not opened for reading") + } else { + return nil + } + }); + $alias(self, "each_line", "each"); + return $alias(self, "eof?", "eof"); + })('::', null); + $const_set('::', 'STDIN', ($gvars.stdin = $$$('IO').$new(0, "r"))); + $const_set('::', 'STDOUT', ($gvars.stdout = $$$('IO').$new(1, "w"))); + $const_set('::', 'STDERR', ($gvars.stderr = $$$('IO').$new(2, "w"))); + var console = Opal.global.console; + $$$('STDOUT')['$write_proc='](typeof(process) === 'object' && typeof(process.stdout) === 'object' ? function(s){process.stdout.write(s);} : function(s){console.log(s);}); + $$$('STDERR')['$write_proc='](typeof(process) === 'object' && typeof(process.stderr) === 'object' ? function(s){process.stderr.write(s);} : function(s){console.warn(s);}); + return ($a = [function(s) { var p = prompt(); if (p !== null) return p + "\n"; return nil; }], $send($$$('STDIN'), 'read_proc=', $a), $a[$a.length - 1]); }; -var Tokenizer = /** @class */ (function () { - function Tokenizer(_a, cbs) { - var _b = _a.xmlMode, xmlMode = _b === void 0 ? false : _b, _c = _a.decodeEntities, decodeEntities = _c === void 0 ? true : _c; - this.cbs = cbs; - /** The current state the tokenizer is in. */ - this.state = State.Text; - /** The read buffer. */ - this.buffer = ""; - /** The beginning of the section that is currently being read. */ - this.sectionStart = 0; - /** The index within the buffer that we are currently looking at. */ - this.index = 0; - /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */ - this.baseState = State.Text; - /** For special parsing behavior inside of script and style tags. */ - this.isSpecial = false; - /** Indicates whether the tokenizer has been paused. */ - this.running = true; - /** The offset of the current buffer. */ - this.offset = 0; - this.currentSequence = undefined; - this.sequenceIndex = 0; - this.trieIndex = 0; - this.trieCurrent = 0; - /** For named entities, the index of the value. For numeric entities, the code point. */ - this.entityResult = 0; - this.entityExcess = 0; - this.xmlMode = xmlMode; - this.decodeEntities = decodeEntities; - this.entityTrie = xmlMode ? decode_js_1.xmlDecodeTree : decode_js_1.htmlDecodeTree; - } - Tokenizer.prototype.reset = function () { - this.state = State.Text; - this.buffer = ""; - this.sectionStart = 0; - this.index = 0; - this.baseState = State.Text; - this.currentSequence = undefined; - this.running = true; - this.offset = 0; - }; - Tokenizer.prototype.write = function (chunk) { - this.offset += this.buffer.length; - this.buffer = chunk; - this.parse(); - }; - Tokenizer.prototype.end = function () { - if (this.running) - this.finish(); - }; - Tokenizer.prototype.pause = function () { - this.running = false; - }; - Tokenizer.prototype.resume = function () { - this.running = true; - if (this.index < this.buffer.length + this.offset) { - this.parse(); - } - }; - /** - * The current index within all of the written data. - */ - Tokenizer.prototype.getIndex = function () { - return this.index; - }; - /** - * The start of the current section. - */ - Tokenizer.prototype.getSectionStart = function () { - return this.sectionStart; - }; - Tokenizer.prototype.stateText = function (c) { - if (c === CharCodes.Lt || - (!this.decodeEntities && this.fastForwardTo(CharCodes.Lt))) { - if (this.index > this.sectionStart) { - this.cbs.ontext(this.sectionStart, this.index); + +Opal.modules["opal/regexp_anchors"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $nesting = []; Opal.nil; var $$$ = Opal.$$$; + + Opal.add_stubs('new'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Opal'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + $const_set(self, 'REGEXP_START', "^"); + $const_set(self, 'REGEXP_END', "$"); + $const_set(self, 'FORBIDDEN_STARTING_IDENTIFIER_CHARS', "\\u0001-\\u002F\\u003A-\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); + $const_set(self, 'FORBIDDEN_ENDING_IDENTIFIER_CHARS', "\\u0001-\\u0020\\u0022-\\u002F\\u003A-\\u003E\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); + $const_set(self, 'INLINE_IDENTIFIER_REGEXP', $$('Regexp').$new("[^" + ($$$(self, 'FORBIDDEN_STARTING_IDENTIFIER_CHARS')) + "]*[^" + ($$$(self, 'FORBIDDEN_ENDING_IDENTIFIER_CHARS')) + "]")); + $const_set(self, 'FORBIDDEN_CONST_NAME_CHARS', "\\u0001-\\u0020\\u0021-\\u002F\\u003B-\\u003F\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"); + return $const_set(self, 'CONST_NAME_REGEXP', $$('Regexp').$new("" + ($$$(self, 'REGEXP_START')) + "(::)?[A-Z][^" + ($$$(self, 'FORBIDDEN_CONST_NAME_CHARS')) + "]*" + ($$$(self, 'REGEXP_END')))); + })($nesting[0], $nesting) +}; + +Opal.modules["opal/mini"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $Object = Opal.Object; Opal.nil; + + Opal.add_stubs('require'); + + $Object.$require("opal/base"); + $Object.$require("corelib/nil"); + $Object.$require("corelib/boolean"); + $Object.$require("corelib/string"); + $Object.$require("corelib/comparable"); + $Object.$require("corelib/enumerable"); + $Object.$require("corelib/enumerator"); + $Object.$require("corelib/array"); + $Object.$require("corelib/hash"); + $Object.$require("corelib/number"); + $Object.$require("corelib/range"); + $Object.$require("corelib/proc"); + $Object.$require("corelib/method"); + $Object.$require("corelib/regexp"); + $Object.$require("corelib/variables"); + $Object.$require("corelib/io"); + return $Object.$require("opal/regexp_anchors"); +}; + +Opal.modules["corelib/kernel/format"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $coerce_to = Opal.coerce_to, $module = Opal.module, $slice = Opal.slice, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $def = Opal.def, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('respond_to?,[],==,length,coerce_to?,nil?,to_a,raise,to_int,fetch,Integer,Float,to_ary,to_str,inspect,to_s,format'); + return (function($base) { + var self = $module($base, 'Kernel'); + + + + + $def(self, '$format', function $$format(format_string, $a) { + var $post_args, args, ary = nil; + if ($gvars.DEBUG == null) $gvars.DEBUG = nil; + + + $post_args = $slice(arguments, 1); + args = $post_args; + if (($eqeq(args.$length(), 1) && ($truthy(args['$[]'](0)['$respond_to?']("to_ary"))))) { + + ary = $Opal['$coerce_to?'](args['$[]'](0), $$$('Array'), "to_ary"); + if (!$truthy(ary['$nil?']())) { + args = ary.$to_a(); + } } + var result = '', + //used for slicing: + begin_slice = 0, + end_slice, + //used for iterating over the format string: + i, + len = format_string.length, + //used for processing field values: + arg, + str, + //used for processing %g and %G fields: + exponent, + //used for keeping track of width and precision: + width, + precision, + //used for holding temporary values: + tmp_num, + //used for processing %{} and %<> fileds: + hash_parameter_key, + closing_brace_char, + //used for processing %b, %B, %o, %x, and %X fields: + base_number, + base_prefix, + base_neg_zero_regex, + base_neg_zero_digit, + //used for processing arguments: + next_arg, + seq_arg_num = 1, + pos_arg_num = 0, + //used for keeping track of flags: + flags, + FNONE = 0, + FSHARP = 1, + FMINUS = 2, + FPLUS = 4, + FZERO = 8, + FSPACE = 16, + FWIDTH = 32, + FPREC = 64, + FPREC0 = 128; + + function CHECK_FOR_FLAGS() { + if (flags&FWIDTH) { $Kernel.$raise($$$('ArgumentError'), "flag after width"); } + if (flags&FPREC0) { $Kernel.$raise($$$('ArgumentError'), "flag after precision"); } + } + + function CHECK_FOR_WIDTH() { + if (flags&FWIDTH) { $Kernel.$raise($$$('ArgumentError'), "width given twice"); } + if (flags&FPREC0) { $Kernel.$raise($$$('ArgumentError'), "width after precision"); } + } + + function GET_NTH_ARG(num) { + if (num >= args.length) { $Kernel.$raise($$$('ArgumentError'), "too few arguments"); } + return args[num]; + } + + function GET_NEXT_ARG() { + switch (pos_arg_num) { + case -1: $Kernel.$raise($$$('ArgumentError'), "unnumbered(" + (seq_arg_num) + ") mixed with numbered"); // raise + case -2: $Kernel.$raise($$$('ArgumentError'), "unnumbered(" + (seq_arg_num) + ") mixed with named"); // raise + } + pos_arg_num = seq_arg_num++; + return GET_NTH_ARG(pos_arg_num - 1); + } + + function GET_POS_ARG(num) { + if (pos_arg_num > 0) { + $Kernel.$raise($$$('ArgumentError'), "numbered(" + (num) + ") after unnumbered(" + (pos_arg_num) + ")"); + } + if (pos_arg_num === -2) { + $Kernel.$raise($$$('ArgumentError'), "numbered(" + (num) + ") after named"); + } + if (num < 1) { + $Kernel.$raise($$$('ArgumentError'), "invalid index - " + (num) + "$"); + } + pos_arg_num = -1; + return GET_NTH_ARG(num - 1); + } + + function GET_ARG() { + return (next_arg === undefined ? GET_NEXT_ARG() : next_arg); + } + + function READ_NUM(label) { + var num, str = ''; + for (;; i++) { + if (i === len) { + $Kernel.$raise($$$('ArgumentError'), "malformed format string - %*[0-9]"); + } + if (format_string.charCodeAt(i) < 48 || format_string.charCodeAt(i) > 57) { + i--; + num = parseInt(str, 10) || 0; + if (num > 2147483647) { + $Kernel.$raise($$$('ArgumentError'), "" + (label) + " too big"); } - this.state = State.BeforeTagName; - this.sectionStart = this.index; - } - else if (this.decodeEntities && c === CharCodes.Amp) { - this.state = State.BeforeEntity; + return num; + } + str += format_string.charAt(i); } - }; - Tokenizer.prototype.stateSpecialStartSequence = function (c) { - var isEnd = this.sequenceIndex === this.currentSequence.length; - var isMatch = isEnd - ? // If we are at the end of the sequence, make sure the tag name has ended - isEndOfTagSection(c) - : // Otherwise, do a case-insensitive comparison - (c | 0x20) === this.currentSequence[this.sequenceIndex]; - if (!isMatch) { - this.isSpecial = false; + } + + function READ_NUM_AFTER_ASTER(label) { + var arg, num = READ_NUM(label); + if (format_string.charAt(i + 1) === '$') { + i++; + arg = GET_POS_ARG(num); + } else { + arg = GET_NEXT_ARG(); } - else if (!isEnd) { - this.sequenceIndex++; - return; + return (arg).$to_int(); + } + + for (i = format_string.indexOf('%'); i !== -1; i = format_string.indexOf('%', i)) { + str = undefined; + + flags = FNONE; + width = -1; + precision = -1; + next_arg = undefined; + + end_slice = i; + + i++; + + switch (format_string.charAt(i)) { + case '%': + begin_slice = i; + // no-break + case '': + case '\n': + case '\0': + i++; + continue; } - this.sequenceIndex = 0; - this.state = State.InTagName; - this.stateInTagName(c); - }; - /** Look for an end tag. For <title> tags, also decode entities. */ - Tokenizer.prototype.stateInSpecialTag = function (c) { - if (this.sequenceIndex === this.currentSequence.length) { - if (c === CharCodes.Gt || isWhitespace(c)) { - var endOfText = this.index - this.currentSequence.length; - if (this.sectionStart < endOfText) { - // Spoof the index so that reported locations match up. - var actualIndex = this.index; - this.index = endOfText; - this.cbs.ontext(this.sectionStart, endOfText); - this.index = actualIndex; - } - this.isSpecial = false; - this.sectionStart = endOfText + 2; // Skip over the `</` - this.stateInClosingTagName(c); - return; // We are done; skip the rest of the function. + + format_sequence: for (; i < len; i++) { + switch (format_string.charAt(i)) { + + case ' ': + CHECK_FOR_FLAGS(); + flags |= FSPACE; + continue format_sequence; + + case '#': + CHECK_FOR_FLAGS(); + flags |= FSHARP; + continue format_sequence; + + case '+': + CHECK_FOR_FLAGS(); + flags |= FPLUS; + continue format_sequence; + + case '-': + CHECK_FOR_FLAGS(); + flags |= FMINUS; + continue format_sequence; + + case '0': + CHECK_FOR_FLAGS(); + flags |= FZERO; + continue format_sequence; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + tmp_num = READ_NUM('width'); + if (format_string.charAt(i + 1) === '$') { + if (i + 2 === len) { + str = '%'; + i++; + break format_sequence; + } + if (next_arg !== undefined) { + $Kernel.$raise($$$('ArgumentError'), "value given twice - %" + (tmp_num) + "$"); + } + next_arg = GET_POS_ARG(tmp_num); + i++; + } else { + CHECK_FOR_WIDTH(); + flags |= FWIDTH; + width = tmp_num; } - this.sequenceIndex = 0; - } - if ((c | 0x20) === this.currentSequence[this.sequenceIndex]) { - this.sequenceIndex += 1; - } - else if (this.sequenceIndex === 0) { - if (this.currentSequence === Sequences.TitleEnd) { - // We have to parse entities in <title> tags. - if (this.decodeEntities && c === CharCodes.Amp) { - this.state = State.BeforeEntity; + continue format_sequence; + + case '<': + case '\{': + closing_brace_char = (format_string.charAt(i) === '<' ? '>' : '\}'); + hash_parameter_key = ''; + + i++; + + for (;; i++) { + if (i === len) { + $Kernel.$raise($$$('ArgumentError'), "malformed name - unmatched parenthesis"); + } + if (format_string.charAt(i) === closing_brace_char) { + + if (pos_arg_num > 0) { + $Kernel.$raise($$$('ArgumentError'), "named " + (hash_parameter_key) + " after unnumbered(" + (pos_arg_num) + ")"); + } + if (pos_arg_num === -1) { + $Kernel.$raise($$$('ArgumentError'), "named " + (hash_parameter_key) + " after numbered"); + } + pos_arg_num = -2; + + if (args[0] === undefined || !args[0].$$is_hash) { + $Kernel.$raise($$$('ArgumentError'), "one hash required"); + } + + next_arg = (args[0]).$fetch(hash_parameter_key); + + if (closing_brace_char === '>') { + continue format_sequence; + } else { + str = next_arg.toString(); + if (precision !== -1) { str = str.slice(0, precision); } + if (flags&FMINUS) { + while (str.length < width) { str = str + ' '; } + } else { + while (str.length < width) { str = ' ' + str; } + } + break format_sequence; } + } + hash_parameter_key += format_string.charAt(i); } - else if (this.fastForwardTo(CharCodes.Lt)) { - // Outside of <title> tags, we can fast-forward. - this.sequenceIndex = 1; + // raise + + case '*': + i++; + CHECK_FOR_WIDTH(); + flags |= FWIDTH; + width = READ_NUM_AFTER_ASTER('width'); + if (width < 0) { + flags |= FMINUS; + width = -width; } - } - else { - // If we see a `<`, set the sequence index to 1; useful for eg. `<</script>`. - this.sequenceIndex = Number(c === CharCodes.Lt); - } - }; - Tokenizer.prototype.stateCDATASequence = function (c) { - if (c === Sequences.Cdata[this.sequenceIndex]) { - if (++this.sequenceIndex === Sequences.Cdata.length) { - this.state = State.InCommentLike; - this.currentSequence = Sequences.CdataEnd; - this.sequenceIndex = 0; - this.sectionStart = this.index + 1; + continue format_sequence; + + case '.': + if (flags&FPREC0) { + $Kernel.$raise($$$('ArgumentError'), "precision given twice"); } - } - else { - this.sequenceIndex = 0; - this.state = State.InDeclaration; - this.stateInDeclaration(c); // Reconsume the character - } - }; - /** - * When we wait for one specific character, we can speed things up - * by skipping through the buffer until we find it. - * - * @returns Whether the character was found. - */ - Tokenizer.prototype.fastForwardTo = function (c) { - while (++this.index < this.buffer.length + this.offset) { - if (this.buffer.charCodeAt(this.index - this.offset) === c) { - return true; + flags |= FPREC|FPREC0; + precision = 0; + i++; + if (format_string.charAt(i) === '*') { + i++; + precision = READ_NUM_AFTER_ASTER('precision'); + if (precision < 0) { + flags &= ~FPREC; + } + continue format_sequence; } - } - /* - * We increment the index at the end of the `parse` loop, - * so set it to `buffer.length - 1` here. - * - * TODO: Refactor `parse` to increment index before calling states. - */ - this.index = this.buffer.length + this.offset - 1; - return false; - }; - /** - * Comments and CDATA end with `-->` and `]]>`. - * - * Their common qualities are: - * - Their end sequences have a distinct character they start with. - * - That character is then repeated, so we have to check multiple repeats. - * - All characters but the start character of the sequence can be skipped. - */ - Tokenizer.prototype.stateInCommentLike = function (c) { - if (c === this.currentSequence[this.sequenceIndex]) { - if (++this.sequenceIndex === this.currentSequence.length) { - if (this.currentSequence === Sequences.CdataEnd) { - this.cbs.oncdata(this.sectionStart, this.index, 2); + precision = READ_NUM('precision'); + continue format_sequence; + + case 'd': + case 'i': + case 'u': + arg = $Kernel.$Integer(GET_ARG()); + if (arg >= 0) { + str = arg.toString(); + while (str.length < precision) { str = '0' + str; } + if (flags&FMINUS) { + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && precision === -1) { + while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0)) { str = '0' + str; } + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + } else { + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + while (str.length < width) { str = ' ' + str; } } - else { - this.cbs.oncomment(this.sectionStart, this.index, 2); + } + } else { + str = (-arg).toString(); + while (str.length < precision) { str = '0' + str; } + if (flags&FMINUS) { + str = '-' + str; + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && precision === -1) { + while (str.length < width - 1) { str = '0' + str; } + str = '-' + str; + } else { + str = '-' + str; + while (str.length < width) { str = ' ' + str; } } - this.sequenceIndex = 0; - this.sectionStart = this.index + 1; - this.state = State.Text; + } } - } - else if (this.sequenceIndex === 0) { - // Fast-forward to the first character of the sequence - if (this.fastForwardTo(this.currentSequence[0])) { - this.sequenceIndex = 1; + break format_sequence; + + case 'b': + case 'B': + case 'o': + case 'x': + case 'X': + switch (format_string.charAt(i)) { + case 'b': + case 'B': + base_number = 2; + base_prefix = '0b'; + base_neg_zero_regex = /^1+/; + base_neg_zero_digit = '1'; + break; + case 'o': + base_number = 8; + base_prefix = '0'; + base_neg_zero_regex = /^3?7+/; + base_neg_zero_digit = '7'; + break; + case 'x': + case 'X': + base_number = 16; + base_prefix = '0x'; + base_neg_zero_regex = /^f+/; + base_neg_zero_digit = 'f'; + break; } - } - else if (c !== this.currentSequence[this.sequenceIndex - 1]) { - // Allow long sequences, eg. --->, ]]]> - this.sequenceIndex = 0; - } - }; - /** - * HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name. - * - * XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar). - * We allow anything that wouldn't end the tag. - */ - Tokenizer.prototype.isTagStartChar = function (c) { - return this.xmlMode ? !isEndOfTagSection(c) : isASCIIAlpha(c); - }; - Tokenizer.prototype.startSpecial = function (sequence, offset) { - this.isSpecial = true; - this.currentSequence = sequence; - this.sequenceIndex = offset; - this.state = State.SpecialStartSequence; - }; - Tokenizer.prototype.stateBeforeTagName = function (c) { - if (c === CharCodes.ExclamationMark) { - this.state = State.BeforeDeclaration; - this.sectionStart = this.index + 1; - } - else if (c === CharCodes.Questionmark) { - this.state = State.InProcessingInstruction; - this.sectionStart = this.index + 1; - } - else if (this.isTagStartChar(c)) { - var lower = c | 0x20; - this.sectionStart = this.index; - if (!this.xmlMode && lower === Sequences.TitleEnd[2]) { - this.startSpecial(Sequences.TitleEnd, 3); + arg = $Kernel.$Integer(GET_ARG()); + if (arg >= 0) { + str = arg.toString(base_number); + while (str.length < precision) { str = '0' + str; } + if (flags&FMINUS) { + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + if (flags&FSHARP && arg !== 0) { str = base_prefix + str; } + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && precision === -1) { + while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0) - ((flags&FSHARP && arg !== 0) ? base_prefix.length : 0)) { str = '0' + str; } + if (flags&FSHARP && arg !== 0) { str = base_prefix + str; } + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + } else { + if (flags&FSHARP && arg !== 0) { str = base_prefix + str; } + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + while (str.length < width) { str = ' ' + str; } + } + } + } else { + if (flags&FPLUS || flags&FSPACE) { + str = (-arg).toString(base_number); + while (str.length < precision) { str = '0' + str; } + if (flags&FMINUS) { + if (flags&FSHARP) { str = base_prefix + str; } + str = '-' + str; + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && precision === -1) { + while (str.length < width - 1 - (flags&FSHARP ? 2 : 0)) { str = '0' + str; } + if (flags&FSHARP) { str = base_prefix + str; } + str = '-' + str; + } else { + if (flags&FSHARP) { str = base_prefix + str; } + str = '-' + str; + while (str.length < width) { str = ' ' + str; } + } + } + } else { + str = (arg >>> 0).toString(base_number).replace(base_neg_zero_regex, base_neg_zero_digit); + while (str.length < precision - 2) { str = base_neg_zero_digit + str; } + if (flags&FMINUS) { + str = '..' + str; + if (flags&FSHARP) { str = base_prefix + str; } + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && precision === -1) { + while (str.length < width - 2 - (flags&FSHARP ? base_prefix.length : 0)) { str = base_neg_zero_digit + str; } + str = '..' + str; + if (flags&FSHARP) { str = base_prefix + str; } + } else { + str = '..' + str; + if (flags&FSHARP) { str = base_prefix + str; } + while (str.length < width) { str = ' ' + str; } + } + } + } + } + if (format_string.charAt(i) === format_string.charAt(i).toUpperCase()) { + str = str.toUpperCase(); + } + break format_sequence; + + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + arg = $Kernel.$Float(GET_ARG()); + if (arg >= 0 || isNaN(arg)) { + if (arg === Infinity) { + str = 'Inf'; + } else { + switch (format_string.charAt(i)) { + case 'f': + str = arg.toFixed(precision === -1 ? 6 : precision); + break; + case 'e': + case 'E': + str = arg.toExponential(precision === -1 ? 6 : precision); + break; + case 'g': + case 'G': + str = arg.toExponential(); + exponent = parseInt(str.split('e')[1], 10); + if (!(exponent < -4 || exponent >= (precision === -1 ? 6 : precision))) { + str = arg.toPrecision(precision === -1 ? (flags&FSHARP ? 6 : undefined) : precision); + } + break; + } + } + if (flags&FMINUS) { + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && arg !== Infinity && !isNaN(arg)) { + while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0)) { str = '0' + str; } + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + } else { + if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; } + while (str.length < width) { str = ' ' + str; } + } + } + } else { + if (arg === -Infinity) { + str = 'Inf'; + } else { + switch (format_string.charAt(i)) { + case 'f': + str = (-arg).toFixed(precision === -1 ? 6 : precision); + break; + case 'e': + case 'E': + str = (-arg).toExponential(precision === -1 ? 6 : precision); + break; + case 'g': + case 'G': + str = (-arg).toExponential(); + exponent = parseInt(str.split('e')[1], 10); + if (!(exponent < -4 || exponent >= (precision === -1 ? 6 : precision))) { + str = (-arg).toPrecision(precision === -1 ? (flags&FSHARP ? 6 : undefined) : precision); + } + break; + } + } + if (flags&FMINUS) { + str = '-' + str; + while (str.length < width) { str = str + ' '; } + } else { + if (flags&FZERO && arg !== -Infinity) { + while (str.length < width - 1) { str = '0' + str; } + str = '-' + str; + } else { + str = '-' + str; + while (str.length < width) { str = ' ' + str; } + } + } } - else { - this.state = - !this.xmlMode && lower === Sequences.ScriptEnd[2] - ? State.BeforeSpecialS - : State.InTagName; + if (format_string.charAt(i) === format_string.charAt(i).toUpperCase() && arg !== Infinity && arg !== -Infinity && !isNaN(arg)) { + str = str.toUpperCase(); + } + str = str.replace(/([eE][-+]?)([0-9])$/, '$10$2'); + break format_sequence; + + case 'a': + case 'A': + // Not implemented because there are no specs for this field type. + $Kernel.$raise($$$('NotImplementedError'), "`A` and `a` format field types are not implemented in Opal yet"); + // raise + + case 'c': + arg = GET_ARG(); + if ((arg)['$respond_to?']("to_ary")) { arg = (arg).$to_ary()[0]; } + if ((arg)['$respond_to?']("to_str")) { + str = (arg).$to_str(); + } else { + str = String.fromCharCode($coerce_to(arg, $$$('Integer'), 'to_int')); + } + if (str.length !== 1) { + $Kernel.$raise($$$('ArgumentError'), "%c requires a character"); } + if (flags&FMINUS) { + while (str.length < width) { str = str + ' '; } + } else { + while (str.length < width) { str = ' ' + str; } + } + break format_sequence; + + case 'p': + str = (GET_ARG()).$inspect(); + if (precision !== -1) { str = str.slice(0, precision); } + if (flags&FMINUS) { + while (str.length < width) { str = str + ' '; } + } else { + while (str.length < width) { str = ' ' + str; } + } + break format_sequence; + + case 's': + str = (GET_ARG()).$to_s(); + if (precision !== -1) { str = str.slice(0, precision); } + if (flags&FMINUS) { + while (str.length < width) { str = str + ' '; } + } else { + while (str.length < width) { str = ' ' + str; } + } + break format_sequence; + + default: + $Kernel.$raise($$$('ArgumentError'), "malformed format string - %" + (format_string.charAt(i))); + } } - else if (c === CharCodes.Slash) { - this.state = State.BeforeClosingTagName; + + if (str === undefined) { + $Kernel.$raise($$$('ArgumentError'), "malformed format string - %"); } - else { - this.state = State.Text; - this.stateText(c); + + result += format_string.slice(begin_slice, end_slice) + str; + begin_slice = i + 1; + } + + if ($gvars.DEBUG && pos_arg_num >= 0 && seq_arg_num < args.length) { + $Kernel.$raise($$$('ArgumentError'), "too many arguments for format string"); + } + + return result + format_string.slice(begin_slice); + }, -2); + return $alias(self, "sprintf", "format"); + })('::') +}; + +Opal.modules["corelib/string/encoding"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $send = Opal.send, $defs = Opal.defs, $eqeq = Opal.eqeq, $def = Opal.def, $return_ivar = Opal.return_ivar, $return_val = Opal.return_val, $slice = Opal.slice, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $rb_lt = Opal.rb_lt, $a, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,+,[],clone,initialize,new,instance_eval,to_proc,each,const_set,tr,==,default_external,attr_accessor,singleton_class,attr_reader,raise,register,length,bytes,force_encoding,dup,bytesize,enum_for,each_byte,to_a,each_char,each_codepoint,coerce_to!,find,<,default_external='); + + self.$require("corelib/string"); + (function($base, $super) { + var self = $klass($base, $super, 'Encoding'); + + var $proto = self.$$prototype; + + $proto.name = $proto.dummy = nil; + + $defs(self, '$register', function $$register(name, options) { + var block = $$register.$$p || nil, self = this, names = nil, $ret_or_1 = nil, ascii = nil, dummy = nil, encoding = nil, register = nil; + + $$register.$$p = null; + if (options == null) options = $hash2([], {}); + names = $rb_plus([name], ($truthy(($ret_or_1 = options['$[]']("aliases"))) ? ($ret_or_1) : ([]))); + ascii = ($truthy(($ret_or_1 = options['$[]']("ascii"))) && ($ret_or_1)); + dummy = ($truthy(($ret_or_1 = options['$[]']("dummy"))) && ($ret_or_1)); + if ($truthy(options['$[]']("inherits"))) { + + encoding = options['$[]']("inherits").$clone(); + encoding.$initialize(name, names, ascii, dummy); + } else { + encoding = self.$new(name, names, ascii, dummy); + } if ((block !== nil)) { + $send(encoding, 'instance_eval', [], block.$to_proc()); + } register = Opal.encodings; + return $send(names, 'each', [], function $$1(encoding_name){var self = $$1.$$s == null ? this : $$1.$$s; + + + if (encoding_name == null) encoding_name = nil; + self.$const_set(encoding_name.$tr("-", "_"), encoding); + return register[encoding_name] = encoding;}, {$$s: self}); + }, -2); + $defs(self, '$find', function $$find(name) { + var self = this; + + + if ($eqeq(name, "default_external")) { + return self.$default_external() + } return Opal.find_encoding(name); }); + self.$singleton_class().$attr_accessor("default_external"); + self.$attr_reader("name", "names"); + + $def(self, '$initialize', function $$initialize(name, names, ascii, dummy) { + var self = this; + + + self.name = name; + self.names = names; + self.ascii = ascii; + return (self.dummy = dummy); + }); + + $def(self, '$ascii_compatible?', $return_ivar("ascii")); + + $def(self, '$dummy?', $return_ivar("dummy")); + + $def(self, '$binary?', $return_val(false)); + + $def(self, '$to_s', $return_ivar("name")); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + return "#<Encoding:" + (self.name) + (($truthy(self.dummy) ? (" (dummy)") : nil)) + ">" + }); + + $def(self, '$charsize', function $$charsize(string) { + + + var len = 0; + for (var i = 0, length = string.length; i < length; i++) { + var charcode = string.charCodeAt(i); + if (!(charcode >= 0xD800 && charcode <= 0xDBFF)) { + len++; } - }; - Tokenizer.prototype.stateInTagName = function (c) { - if (isEndOfTagSection(c)) { - this.cbs.onopentagname(this.sectionStart, this.index); - this.sectionStart = -1; - this.state = State.BeforeAttributeName; - this.stateBeforeAttributeName(c); + } + return len; + + }); + + $def(self, '$each_char', function $$each_char(string) { + var block = $$each_char.$$p || nil; + + $$each_char.$$p = null; + + var low_surrogate = ""; + for (var i = 0, length = string.length; i < length; i++) { + var charcode = string.charCodeAt(i); + var chr = string.charAt(i); + if (charcode >= 0xDC00 && charcode <= 0xDFFF) { + low_surrogate = chr; + continue; } - }; - Tokenizer.prototype.stateBeforeClosingTagName = function (c) { - if (isWhitespace(c)) { - // Ignore + else if (charcode >= 0xD800 && charcode <= 0xDBFF) { + chr = low_surrogate + chr; } - else if (c === CharCodes.Gt) { - this.state = State.Text; + if (string.encoding.name != "UTF-8") { + chr = new String(chr); + chr.encoding = string.encoding; } - else { - this.state = this.isTagStartChar(c) - ? State.InClosingTagName - : State.InSpecialComment; - this.sectionStart = this.index; + Opal.yield1(block, chr); + } + }); + + $def(self, '$each_byte', function $$each_byte($a) { + + + $slice(arguments); + return $Kernel.$raise($$$('NotImplementedError')); + }, -1); + + $def(self, '$bytesize', function $$bytesize($a) { + + + $slice(arguments); + return $Kernel.$raise($$$('NotImplementedError')); + }, -1); + $klass('::', $$$('StandardError'), 'EncodingError'); + return ($klass('::', $$$('EncodingError'), 'CompatibilityError'), nil); + })('::', null); + $send($$$('Encoding'), 'register', ["UTF-8", $hash2(["aliases", "ascii"], {"aliases": ["CP65001"], "ascii": true})], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s; + + + + $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + // Taken from: https://github.com/feross/buffer/blob/f52dffd9df0445b93c0c9065c2f8f0f46b2c729a/index.js#L1954-L2032 + var units = Infinity; + var codePoint; + var length = string.length; + var leadSurrogate = null; + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) { + Opal.yield1(block, 0xEF); + Opal.yield1(block, 0xBF); + Opal.yield1(block, 0xBD); + } + continue; + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) { + Opal.yield1(block, 0xEF); + Opal.yield1(block, 0xBF); + Opal.yield1(block, 0xBD); + } + continue; + } + + // valid lead + leadSurrogate = codePoint; + + continue; + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) { + Opal.yield1(block, 0xEF); + Opal.yield1(block, 0xBF); + Opal.yield1(block, 0xBD); + } + leadSurrogate = codePoint; + continue; + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) { + Opal.yield1(block, 0xEF); + Opal.yield1(block, 0xBF); + Opal.yield1(block, 0xBD); + } } - }; - Tokenizer.prototype.stateInClosingTagName = function (c) { - if (c === CharCodes.Gt || isWhitespace(c)) { - this.cbs.onclosetag(this.sectionStart, this.index); - this.sectionStart = -1; - this.state = State.AfterClosingTagName; - this.stateAfterClosingTagName(c); + + leadSurrogate = null; + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break; + Opal.yield1(block, codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break; + Opal.yield1(block, codePoint >> 0x6 | 0xC0); + Opal.yield1(block, codePoint & 0x3F | 0x80); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break; + Opal.yield1(block, codePoint >> 0xC | 0xE0); + Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80); + Opal.yield1(block, codePoint & 0x3F | 0x80); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break; + Opal.yield1(block, codePoint >> 0x12 | 0xF0); + Opal.yield1(block, codePoint >> 0xC & 0x3F | 0x80); + Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80); + Opal.yield1(block, codePoint & 0x3F | 0x80); + } else ; + } + }); + return $def(self, '$bytesize', function $$bytesize(string) { + + return string.$bytes().$length() + });}, {$$s: self}); + $send($$$('Encoding'), 'register', ["UTF-16LE"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s; + + + + $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var code = string.charCodeAt(i); + + Opal.yield1(block, code & 0xff); + Opal.yield1(block, code >> 8); + } + }); + return $def(self, '$bytesize', function $$bytesize(string) { + + return string.length * 2; + });}, {$$s: self}); + $send($$$('Encoding'), 'register', ["UTF-16BE", $hash2(["inherits"], {"inherits": $$$($$$('Encoding'), 'UTF_16LE')})], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s; + + return $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var code = string.charCodeAt(i); + + Opal.yield1(block, code >> 8); + Opal.yield1(block, code & 0xff); + } + })}, {$$s: self}); + $send($$$('Encoding'), 'register', ["UTF-32LE"], function $$5(){var self = $$5.$$s == null ? this : $$5.$$s; + + + + $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var code = string.charCodeAt(i); + + Opal.yield1(block, code & 0xff); + Opal.yield1(block, code >> 8); + Opal.yield1(block, 0); + Opal.yield1(block, 0); + } + }); + return $def(self, '$bytesize', function $$bytesize(string) { + + return string.length * 4; + });}, {$$s: self}); + $send($$$('Encoding'), 'register', ["UTF-32BE", $hash2(["inherits"], {"inherits": $$$($$$('Encoding'), 'UTF_32LE')})], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s; + + return $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var code = string.charCodeAt(i); + + Opal.yield1(block, 0); + Opal.yield1(block, 0); + Opal.yield1(block, code >> 8); + Opal.yield1(block, code & 0xff); + } + })}, {$$s: self}); + $send($$$('Encoding'), 'register', ["ASCII-8BIT", $hash2(["aliases", "ascii"], {"aliases": ["BINARY"], "ascii": true})], function $$7(){var self = $$7.$$s == null ? this : $$7.$$s; + + + + $def(self, '$each_char', function $$each_char(string) { + var block = $$each_char.$$p || nil; + + $$each_char.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var chr = new String(string.charAt(i)); + chr.encoding = string.encoding; + Opal.yield1(block, chr); + } + }); + + $def(self, '$charsize', function $$charsize(string) { + + return string.length; + }); + + $def(self, '$each_byte', function $$each_byte(string) { + var block = $$each_byte.$$p || nil; + + $$each_byte.$$p = null; + + for (var i = 0, length = string.length; i < length; i++) { + var code = string.charCodeAt(i); + Opal.yield1(block, code & 0xff); + } + }); + + $def(self, '$bytesize', function $$bytesize(string) { + + return string.length; + }); + return $def(self, '$binary?', $return_val(true));}, {$$s: self}); + $$$('Encoding').$register("ISO-8859-1", $hash2(["aliases", "ascii", "inherits"], {"aliases": ["ISO8859-1"], "ascii": true, "inherits": $$$($$$('Encoding'), 'ASCII_8BIT')})); + $$$('Encoding').$register("US-ASCII", $hash2(["aliases", "ascii", "inherits"], {"aliases": ["ASCII"], "ascii": true, "inherits": $$$($$$('Encoding'), 'ASCII_8BIT')})); + (function($base, $super) { + var self = $klass($base, $super, 'String'); + + var $proto = self.$$prototype; + + $proto.internal_encoding = $proto.bytes = $proto.encoding = nil; + + self.$attr_reader("encoding"); + self.$attr_reader("internal_encoding"); + Opal.prop(String.prototype, 'bytes', nil); + Opal.prop(String.prototype, 'encoding', $$$($$$('Encoding'), 'UTF_8')); + Opal.prop(String.prototype, 'internal_encoding', $$$($$$('Encoding'), 'UTF_8')); + + $def(self, '$b', function $$b() { + var self = this; + + return self.$dup().$force_encoding("binary") + }); + + $def(self, '$bytesize', function $$bytesize() { + var self = this; + + return self.internal_encoding.$bytesize(self) + }); + + $def(self, '$each_byte', function $$each_byte() { + var block = $$each_byte.$$p || nil, self = this; + + $$each_byte.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_byte"], function $$8(){var self = $$8.$$s == null ? this : $$8.$$s; + + return self.$bytesize()}, {$$s: self}) + } $send(self.internal_encoding, 'each_byte', [self], block.$to_proc()); + return self; + }); + + $def(self, '$bytes', function $$bytes() { + var self = this, $ret_or_1 = nil; + + + + if (typeof self === 'string') { + return (new String(self)).$each_byte().$to_a(); + } + self.bytes = ($truthy(($ret_or_1 = self.bytes)) ? ($ret_or_1) : (self.$each_byte().$to_a())); + return self.bytes.$dup(); + }); + + $def(self, '$each_char', function $$each_char() { + var block = $$each_char.$$p || nil, self = this; + + $$each_char.$$p = null; + if (!(block !== nil)) { + return $send(self, 'enum_for', ["each_char"], function $$9(){var self = $$9.$$s == null ? this : $$9.$$s; + + return self.$length()}, {$$s: self}) + } $send(self.encoding, 'each_char', [self], block.$to_proc()); + return self; + }); + + $def(self, '$chars', function $$chars() { + var block = $$chars.$$p || nil, self = this; + + $$chars.$$p = null; + if (!$truthy(block)) { + return self.$each_char().$to_a() + } return $send(self, 'each_char', [], block.$to_proc()); + }); + + $def(self, '$each_codepoint', function $$each_codepoint() { + var block = $$each_codepoint.$$p || nil, self = this; + + $$each_codepoint.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("each_codepoint") + } + for (var i = 0, length = self.length; i < length; i++) { + Opal.yield1(block, self.codePointAt(i)); + } + return self; + }); + + $def(self, '$codepoints', function $$codepoints() { + var block = $$codepoints.$$p || nil, self = this; + + $$codepoints.$$p = null; + if ((block !== nil)) { + return $send(self, 'each_codepoint', [], block.$to_proc()) + } return self.$each_codepoint().$to_a(); + }); + + $def(self, '$encode', function $$encode(encoding) { + var self = this; + + return Opal.enc(self, encoding); + }); + + $def(self, '$force_encoding', function $$force_encoding(encoding) { + var self = this; + + + var str = self; + + if (encoding === str.encoding) { return str; } + + encoding = $Opal['$coerce_to!'](encoding, $$$('String'), "to_s"); + encoding = $$$('Encoding').$find(encoding); + + if (encoding === str.encoding) { return str; } + + str = Opal.set_encoding(str, encoding); + + return str; + + }); + + $def(self, '$getbyte', function $$getbyte(idx) { + var self = this, string_bytes = nil; + + + string_bytes = self.$bytes(); + idx = $Opal['$coerce_to!'](idx, $$$('Integer'), "to_int"); + if ($truthy($rb_lt(string_bytes.$length(), idx))) { + return nil + } return string_bytes['$[]'](idx); + }); + + $def(self, '$initialize_copy', function $$initialize_copy(other) { + + return "\n" + " self.encoding = other.encoding;\n" + " self.internal_encoding = other.internal_encoding;\n" + " " + }); + return $def(self, '$valid_encoding?', $return_val(true)); + })('::', null); + return ($a = [$$$($$('Encoding'), 'UTF_8')], $send($$$('Encoding'), 'default_external=', $a), $a[$a.length - 1]); +}; + +Opal.modules["corelib/math"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $type_error = Opal.type_error, $module = Opal.module, $const_set = Opal.const_set, $Class = Opal.Class, $slice = Opal.slice, $Kernel = Opal.Kernel, $defs = Opal.defs, $truthy = Opal.truthy, $send = Opal.send, $def = Opal.def, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_divide = Opal.rb_divide, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('new,raise,Float,Integer,module_function,each,define_method,checked,float!,===,gamma,-,integer!,/,infinite?'); + return (function($base, $parent_nesting) { + var self = $module($base, 'Math'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + $const_set(self, 'E', Math.E); + $const_set(self, 'PI', Math.PI); + $const_set(self, 'DomainError', $Class.$new($$$('StandardError'))); + $defs(self, '$checked', function $$checked(method, $a) { + var $post_args, args; + + + $post_args = $slice(arguments, 1); + args = $post_args; + + if (isNaN(args[0]) || (args.length == 2 && isNaN(args[1]))) { + return NaN; + } + + var result = Math[method].apply(null, args); + + if (isNaN(result)) { + $Kernel.$raise($$('DomainError'), "Numerical argument is out of domain - \"" + (method) + "\""); + } + + return result; + }, -2); + $defs(self, '$float!', function $Math_float$excl$1(value) { + + try { + return $Kernel.$Float(value) + } catch ($err) { + if (Opal.rescue($err, [$$$('ArgumentError')])) { + try { + return $Kernel.$raise($type_error(value, $$$('Float'))) + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + $defs(self, '$integer!', function $Math_integer$excl$2(value) { + + try { + return $Kernel.$Integer(value) + } catch ($err) { + if (Opal.rescue($err, [$$$('ArgumentError')])) { + try { + return $Kernel.$raise($type_error(value, $$$('Integer'))) + } finally { Opal.pop_exception(); } + } else { throw $err; } + } + }); + self.$module_function(); + if (!$truthy((typeof(Math.erf) !== "undefined"))) { + + Opal.prop(Math, 'erf', function(x) { + var A1 = 0.254829592, + A2 = -0.284496736, + A3 = 1.421413741, + A4 = -1.453152027, + A5 = 1.061405429, + P = 0.3275911; + + var sign = 1; + + if (x < 0) { + sign = -1; } - }; - Tokenizer.prototype.stateAfterClosingTagName = function (c) { - // Skip everything until ">" - if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { - this.state = State.Text; - this.baseState = State.Text; - this.sectionStart = this.index + 1; + + x = Math.abs(x); + + var t = 1.0 / (1.0 + P * x); + var y = 1.0 - (((((A5 * t + A4) * t) + A3) * t + A2) * t + A1) * t * Math.exp(-x * x); + + return sign * y; + }); + + } if (!$truthy((typeof(Math.erfc) !== "undefined"))) { + + Opal.prop(Math, 'erfc', function(x) { + var z = Math.abs(x), + t = 1.0 / (0.5 * z + 1.0); + + var A1 = t * 0.17087277 + -0.82215223, + A2 = t * A1 + 1.48851587, + A3 = t * A2 + -1.13520398, + A4 = t * A3 + 0.27886807, + A5 = t * A4 + -0.18628806, + A6 = t * A5 + 0.09678418, + A7 = t * A6 + 0.37409196, + A8 = t * A7 + 1.00002368, + A9 = t * A8, + A10 = -z * z - 1.26551223 + A9; + + var a = t * Math.exp(A10); + + if (x < 0.0) { + return 2.0 - a; } - }; - Tokenizer.prototype.stateBeforeAttributeName = function (c) { - if (c === CharCodes.Gt) { - this.cbs.onopentagend(this.index); - if (this.isSpecial) { - this.state = State.InSpecialTag; - this.sequenceIndex = 0; - } - else { - this.state = State.Text; - } - this.baseState = this.state; - this.sectionStart = this.index + 1; + else { + return a; } - else if (c === CharCodes.Slash) { - this.state = State.InSelfClosingTag; + }); + + } $send(["acos", "acosh", "asin", "asinh", "atan", "atanh", "cbrt", "cos", "cosh", "erf", "erfc", "exp", "sin", "sinh", "sqrt", "tanh"], 'each', [], function $Math$3(method){var self = $Math$3.$$s == null ? this : $Math$3.$$s; + + + if (method == null) method = nil; + return $send(self, 'define_method', [method], function $$4(x){ + + if (x == null) x = nil; + return $$$('Math').$checked(method, $$$('Math')['$float!'](x));});}, {$$s: self}); + + $def(self, '$atan2', function $$atan2(y, x) { + + return $$$('Math').$checked("atan2", $$$('Math')['$float!'](y), $$$('Math')['$float!'](x)) + }); + + $def(self, '$hypot', function $$hypot(x, y) { + + return $$$('Math').$checked("hypot", $$$('Math')['$float!'](x), $$$('Math')['$float!'](y)) + }); + + $def(self, '$frexp', function $$frexp(x) { + + + x = $$('Math')['$float!'](x); + + if (isNaN(x)) { + return [NaN, 0]; + } + + var ex = Math.floor(Math.log(Math.abs(x)) / Math.log(2)) + 1, + frac = x / Math.pow(2, ex); + + return [frac, ex]; + }); + + $def(self, '$gamma', function $$gamma(n) { + + + n = $$('Math')['$float!'](n); + + var i, t, x, value, result, twoN, threeN, fourN, fiveN; + + var G = 4.7421875; + + var P = [ + 0.99999999999999709182, + 57.156235665862923517, + -59.597960355475491248, + 14.136097974741747174, + -0.49191381609762019978, + 0.33994649984811888699e-4, + 0.46523628927048575665e-4, + -0.98374475304879564677e-4, + 0.15808870322491248884e-3, + -0.21026444172410488319e-3, + 0.21743961811521264320e-3, + -0.16431810653676389022e-3, + 0.84418223983852743293e-4, + -0.26190838401581408670e-4, + 0.36899182659531622704e-5 + ]; + + + if (isNaN(n)) { + return NaN; + } + + if (n === 0 && 1 / n < 0) { + return -Infinity; + } + + if (n === -1 || n === -Infinity) { + $Kernel.$raise($$('DomainError'), "Numerical argument is out of domain - \"gamma\""); + } + + if ($$('Integer')['$==='](n)) { + if (n <= 0) { + return isFinite(n) ? Infinity : NaN; } - else if (!isWhitespace(c)) { - this.state = State.InAttributeName; - this.sectionStart = this.index; + + if (n > 171) { + return Infinity; } - }; - Tokenizer.prototype.stateInSelfClosingTag = function (c) { - if (c === CharCodes.Gt) { - this.cbs.onselfclosingtag(this.index); - this.state = State.Text; - this.baseState = State.Text; - this.sectionStart = this.index + 1; - this.isSpecial = false; // Reset special state, in case of self-closing special tags + + value = n - 2; + result = n - 1; + + while (value > 1) { + result *= value; + value--; } - else if (!isWhitespace(c)) { - this.state = State.BeforeAttributeName; - this.stateBeforeAttributeName(c); + + if (result == 0) { + result = 1; } - }; - Tokenizer.prototype.stateInAttributeName = function (c) { - if (c === CharCodes.Eq || isEndOfTagSection(c)) { - this.cbs.onattribname(this.sectionStart, this.index); - this.sectionStart = -1; - this.state = State.AfterAttributeName; - this.stateAfterAttributeName(c); + + return result; + } + + if (n < 0.5) { + return Math.PI / (Math.sin(Math.PI * n) * $$$('Math').$gamma($rb_minus(1, n))); + } + + if (n >= 171.35) { + return Infinity; + } + + if (n > 85.0) { + twoN = n * n; + threeN = twoN * n; + fourN = threeN * n; + fiveN = fourN * n; + + return Math.sqrt(2 * Math.PI / n) * Math.pow((n / Math.E), n) * + (1 + 1 / (12 * n) + 1 / (288 * twoN) - 139 / (51840 * threeN) - + 571 / (2488320 * fourN) + 163879 / (209018880 * fiveN) + + 5246819 / (75246796800 * fiveN * n)); + } + + n -= 1; + x = P[0]; + + for (i = 1; i < P.length; ++i) { + x += P[i] / (n + i); + } + + t = n + G + 0.5; + + return Math.sqrt(2 * Math.PI) * Math.pow(t, n + 0.5) * Math.exp(-t) * x; + }); + + $def(self, '$ldexp', function $$ldexp(mantissa, exponent) { + + + mantissa = $$('Math')['$float!'](mantissa); + exponent = $$('Math')['$integer!'](exponent); + + if (isNaN(exponent)) { + $Kernel.$raise($$$('RangeError'), "float NaN out of range of integer"); + } + + return mantissa * Math.pow(2, exponent); + }); + + $def(self, '$lgamma', function $$lgamma(n) { + + + if (n == -1) { + return [Infinity, 1]; + } + else { + return [Math.log(Math.abs($$$('Math').$gamma(n))), $$$('Math').$gamma(n) < 0 ? -1 : 1]; + } + + }); + + $def(self, '$log', function $$log(x, base) { + if ($eqeqeq($$$('String'), x)) { + $Kernel.$raise($type_error(x, $$$('Float'))); + } if ($truthy(base == null)) { + return $$$('Math').$checked("log", $$$('Math')['$float!'](x)) + } else { + + if ($eqeqeq($$$('String'), base)) { + $Kernel.$raise($type_error(base, $$$('Float'))); + } return $rb_divide($$$('Math').$checked("log", $$$('Math')['$float!'](x)), $$$('Math').$checked("log", $$$('Math')['$float!'](base))); + } }, -2); + + $def(self, '$log10', function $$log10(x) { + + + if ($eqeqeq($$$('String'), x)) { + $Kernel.$raise($type_error(x, $$$('Float'))); + } return $$$('Math').$checked("log10", $$$('Math')['$float!'](x)); + }); + + $def(self, '$log2', function $$log2(x) { + + + if ($eqeqeq($$$('String'), x)) { + $Kernel.$raise($type_error(x, $$$('Float'))); + } return $$$('Math').$checked("log2", $$$('Math')['$float!'](x)); + }); + return $def(self, '$tan', function $$tan(x) { + + + x = $$$('Math')['$float!'](x); + if ($truthy(x['$infinite?']())) { + return $$$($$$('Float'), 'NAN') + } return $$$('Math').$checked("tan", $$$('Math')['$float!'](x)); + }); + })('::', $nesting) +}; + +Opal.modules["corelib/complex/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $truthy = Opal.truthy, $def = Opal.def, $klass = Opal.klass, $nesting = [], nil = Opal.nil; + + Opal.add_stubs('new,from_string'); + + (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + return $def(self, '$Complex', function $$Complex(real, imag) { + + + if (imag == null) imag = nil; + if ($truthy(imag)) { + return $$('Complex').$new(real, imag) + } else { + return $$('Complex').$new(real, 0) + } }, -2) + })('::', $nesting); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'String'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + return $def(self, '$to_c', function $$to_c() { + var self = this; + + return $$('Complex').$from_string(self) + }) + })('::', null, $nesting); +}; + +Opal.modules["corelib/complex"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $defs = Opal.defs, $rb_times = Opal.rb_times, $def = Opal.def, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_divide = Opal.rb_divide, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $rb_gt = Opal.rb_gt, $neqeq = Opal.neqeq, $return_val = Opal.return_val, $const_set = Opal.const_set, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,real?,===,raise,new,*,cos,sin,attr_reader,freeze,class,==,real,imag,Complex,-@,+,__coerced__,-,nan?,/,conj,abs2,quo,polar,exp,log,>,!=,divmod,**,hypot,atan2,lcm,denominator,finite?,infinite?,numerator,abs,arg,rationalize,to_f,to_i,to_r,inspect,zero?,positive?,Rational,rect,angle'); + + self.$require("corelib/numeric"); + self.$require("corelib/complex/base"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Complex'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + + $proto.real = $proto.imag = nil; + + $defs(self, '$rect', function $$rect(real, imag) { + var self = this; + + + if (imag == null) imag = 0; + if (!((($eqeqeq($$$('Numeric'), real) && ($truthy(real['$real?']()))) && ($eqeqeq($$$('Numeric'), imag))) && ($truthy(imag['$real?']())))) { + $Kernel.$raise($$$('TypeError'), "not a real"); + } return self.$new(real, imag); + }, -2); + $defs(self, '$polar', function $$polar(r, theta) { + var self = this; + + + if (theta == null) theta = 0; + if (!((($eqeqeq($$$('Numeric'), r) && ($truthy(r['$real?']()))) && ($eqeqeq($$$('Numeric'), theta))) && ($truthy(theta['$real?']())))) { + $Kernel.$raise($$$('TypeError'), "not a real"); + } return self.$new($rb_times(r, $$$('Math').$cos(theta)), $rb_times(r, $$$('Math').$sin(theta))); + }, -2); + self.$attr_reader("real", "imag"); + + $def(self, '$initialize', function $$initialize(real, imag) { + var self = this; + + + if (imag == null) imag = 0; + self.real = real; + self.imag = imag; + return self.$freeze(); + }, -2); + + $def(self, '$coerce', function $$coerce(other) { + var self = this; + + if ($eqeqeq($$$('Complex'), other)) { + return [other, self] + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + return [$$$('Complex').$new(other, 0), self] + } else { + return $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Complex") + } + }); + + $def(self, '$==', function $Complex_$eq_eq$1(other) { + var self = this, $ret_or_1 = nil; + + if ($eqeqeq($$$('Complex'), other)) { + if ($truthy(($ret_or_1 = self.real['$=='](other.$real())))) { + return self.imag['$=='](other.$imag()) + } else { + return $ret_or_1 } - }; - Tokenizer.prototype.stateAfterAttributeName = function (c) { - if (c === CharCodes.Eq) { - this.state = State.BeforeAttributeValue; + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + if ($truthy(($ret_or_1 = self.real['$=='](other)))) { + return self.imag['$=='](0) + } else { + return $ret_or_1 } - else if (c === CharCodes.Slash || c === CharCodes.Gt) { - this.cbs.onattribend(QuoteType.NoValue, this.index); - this.state = State.BeforeAttributeName; - this.stateBeforeAttributeName(c); + } else { + return other['$=='](self) + } + }); + + $def(self, '$-@', function $Complex_$minus$$2() { + var self = this; + + return $Kernel.$Complex(self.real['$-@'](), self.imag['$-@']()) + }); + + $def(self, '$+', function $Complex_$plus$3(other) { + var self = this; + + if ($eqeqeq($$$('Complex'), other)) { + return $Kernel.$Complex($rb_plus(self.real, other.$real()), $rb_plus(self.imag, other.$imag())) + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + return $Kernel.$Complex($rb_plus(self.real, other), self.imag) + } else { + return self.$__coerced__("+", other) + } + }); + + $def(self, '$-', function $Complex_$minus$4(other) { + var self = this; + + if ($eqeqeq($$$('Complex'), other)) { + return $Kernel.$Complex($rb_minus(self.real, other.$real()), $rb_minus(self.imag, other.$imag())) + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + return $Kernel.$Complex($rb_minus(self.real, other), self.imag) + } else { + return self.$__coerced__("-", other) + } + }); + + $def(self, '$*', function $Complex_$$5(other) { + var self = this; + + if ($eqeqeq($$$('Complex'), other)) { + return $Kernel.$Complex($rb_minus($rb_times(self.real, other.$real()), $rb_times(self.imag, other.$imag())), $rb_plus($rb_times(self.real, other.$imag()), $rb_times(self.imag, other.$real()))) + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + return $Kernel.$Complex($rb_times(self.real, other), $rb_times(self.imag, other)) + } else { + return self.$__coerced__("*", other) + } + }); + + $def(self, '$/', function $Complex_$slash$6(other) { + var self = this; + + if ($eqeqeq($$$('Complex'), other)) { + if ((((($eqeqeq($$$('Number'), self.real) && ($truthy(self.real['$nan?']()))) || (($eqeqeq($$$('Number'), self.imag) && ($truthy(self.imag['$nan?']()))))) || (($eqeqeq($$$('Number'), other.$real()) && ($truthy(other.$real()['$nan?']()))))) || (($eqeqeq($$$('Number'), other.$imag()) && ($truthy(other.$imag()['$nan?']())))))) { + return $$$('Complex').$new($$$($$$('Float'), 'NAN'), $$$($$$('Float'), 'NAN')) + } else { + return $rb_divide($rb_times(self, other.$conj()), other.$abs2()) } - else if (!isWhitespace(c)) { - this.cbs.onattribend(QuoteType.NoValue, this.index); - this.state = State.InAttributeName; - this.sectionStart = this.index; + } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) { + return $Kernel.$Complex(self.real.$quo(other), self.imag.$quo(other)) + } else { + return self.$__coerced__("/", other) + } + }); + + $def(self, '$**', function $Complex_$$$7(other) { + var $a, $b, self = this, r = nil, theta = nil, ore = nil, oim = nil, nr = nil, ntheta = nil, x = nil, z = nil, n = nil, div = nil, mod = nil; + + + if ($eqeq(other, 0)) { + return $$$('Complex').$new(1, 0) + } if ($eqeqeq($$$('Complex'), other)) { + + $b = self.$polar(), $a = $to_ary($b), (r = ($a[0] == null ? nil : $a[0])), (theta = ($a[1] == null ? nil : $a[1])); + ore = other.$real(); + oim = other.$imag(); + nr = $$$('Math').$exp($rb_minus($rb_times(ore, $$$('Math').$log(r)), $rb_times(oim, theta))); + ntheta = $rb_plus($rb_times(theta, ore), $rb_times(oim, $$$('Math').$log(r))); + return $$$('Complex').$polar(nr, ntheta); + } else if ($eqeqeq($$$('Integer'), other)) { + if ($truthy($rb_gt(other, 0))) { + + x = self; + z = x; + n = $rb_minus(other, 1); + while ($neqeq(n, 0)) { + + $b = n.$divmod(2), $a = $to_ary($b), (div = ($a[0] == null ? nil : $a[0])), (mod = ($a[1] == null ? nil : $a[1])); + while ($eqeq(mod, 0)) { + + x = $Kernel.$Complex($rb_minus($rb_times(x.$real(), x.$real()), $rb_times(x.$imag(), x.$imag())), $rb_times($rb_times(2, x.$real()), x.$imag())); + n = div; + $b = n.$divmod(2), $a = $to_ary($b), (div = ($a[0] == null ? nil : $a[0])), (mod = ($a[1] == null ? nil : $a[1])); + } z = $rb_times(z, x); + n = $rb_minus(n, 1); + } return z; + } else { + return $rb_divide($$$('Rational').$new(1, 1), self)['$**'](other['$-@']()) } - }; - Tokenizer.prototype.stateBeforeAttributeValue = function (c) { - if (c === CharCodes.DoubleQuote) { - this.state = State.InAttributeValueDq; - this.sectionStart = this.index + 1; + } else if (($eqeqeq($$$('Float'), other) || ($eqeqeq($$$('Rational'), other)))) { + + $b = self.$polar(), $a = $to_ary($b), (r = ($a[0] == null ? nil : $a[0])), (theta = ($a[1] == null ? nil : $a[1])); + return $$$('Complex').$polar(r['$**'](other), $rb_times(theta, other)); + } else { + return self.$__coerced__("**", other) + } }); + + $def(self, '$abs', function $$abs() { + var self = this; + + return $$$('Math').$hypot(self.real, self.imag) + }); + + $def(self, '$abs2', function $$abs2() { + var self = this; + + return $rb_plus($rb_times(self.real, self.real), $rb_times(self.imag, self.imag)) + }); + + $def(self, '$angle', function $$angle() { + var self = this; + + return $$$('Math').$atan2(self.imag, self.real) + }); + + $def(self, '$conj', function $$conj() { + var self = this; + + return $Kernel.$Complex(self.real, self.imag['$-@']()) + }); + + $def(self, '$denominator', function $$denominator() { + var self = this; + + return self.real.$denominator().$lcm(self.imag.$denominator()) + }); + + $def(self, '$eql?', function $Complex_eql$ques$8(other) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; + + if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = $$('Complex')['$==='](other))) ? (self.real.$class()['$=='](self.imag.$class())) : ($ret_or_2))))) { + return self['$=='](other) + } else { + return $ret_or_1 + } + }); + + $def(self, '$fdiv', function $$fdiv(other) { + var self = this; + + + if (!$eqeqeq($$$('Numeric'), other)) { + $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Complex"); + } return $rb_divide(self, other); + }); + + $def(self, '$finite?', function $Complex_finite$ques$9() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.real['$finite?']()))) { + return self.imag['$finite?']() + } else { + return $ret_or_1 + } + }); + + $def(self, '$hash', function $$hash() { + var self = this; + + return "Complex:" + (self.real) + ":" + (self.imag) + }); + + $def(self, '$infinite?', function $Complex_infinite$ques$10() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.real['$infinite?']()))) { + return $ret_or_1 + } else { + return self.imag['$infinite?']() + } + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + return "(" + (self) + ")" + }); + + $def(self, '$numerator', function $$numerator() { + var self = this, d = nil; + + + d = self.$denominator(); + return $Kernel.$Complex($rb_times(self.real.$numerator(), $rb_divide(d, self.real.$denominator())), $rb_times(self.imag.$numerator(), $rb_divide(d, self.imag.$denominator()))); + }); + + $def(self, '$polar', function $$polar() { + var self = this; + + return [self.$abs(), self.$arg()] + }); + + $def(self, '$rationalize', function $$rationalize(eps) { + var self = this; + + if (arguments.length > 1) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)"); + } + if ($neqeq(self.imag, 0)) { + $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Rational"); + } return self.$real().$rationalize(eps); + }, -1); + + $def(self, '$real?', $return_val(false)); + + $def(self, '$rect', function $$rect() { + var self = this; + + return [self.real, self.imag] + }); + + $def(self, '$to_f', function $$to_f() { + var self = this; + + + if (!$eqeq(self.imag, 0)) { + $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Float"); + } return self.real.$to_f(); + }); + + $def(self, '$to_i', function $$to_i() { + var self = this; + + + if (!$eqeq(self.imag, 0)) { + $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Integer"); + } return self.real.$to_i(); + }); + + $def(self, '$to_r', function $$to_r() { + var self = this; + + + if (!$eqeq(self.imag, 0)) { + $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Rational"); + } return self.real.$to_r(); + }); + + $def(self, '$to_s', function $$to_s() { + var self = this, result = nil; + + + result = self.real.$inspect(); + result = $rb_plus(result, (((($eqeqeq($$$('Number'), self.imag) && ($truthy(self.imag['$nan?']()))) || ($truthy(self.imag['$positive?']()))) || ($truthy(self.imag['$zero?']()))) ? ("+") : ("-"))); + result = $rb_plus(result, self.imag.$abs().$inspect()); + if (($eqeqeq($$$('Number'), self.imag) && (($truthy(self.imag['$nan?']()) || ($truthy(self.imag['$infinite?']())))))) { + result = $rb_plus(result, "*"); + } return $rb_plus(result, "i"); + }); + $const_set($nesting[0], 'I', self.$new(0, 1)); + $defs(self, '$from_string', function $$from_string(str) { + + + var re = /[+-]?[\d_]+(\.[\d_]+)?(e\d+)?/; + str.match(re); + var real, imag; + + function isFloat() { + return re.test(str); + } + + function cutFloat() { + var match = str.match(re); + var number = match[0]; + str = str.slice(number.length); + return number.replace(/_/g, ''); + } + + // handles both floats and rationals + function cutNumber() { + if (isFloat()) { + var numerator = parseFloat(cutFloat()); + + if (str[0] === '/') { + // rational real part + str = str.slice(1); + + if (isFloat()) { + var denominator = parseFloat(cutFloat()); + return $Kernel.$Rational(numerator, denominator); + } else { + // reverting '/' + str = '/' + str; + return numerator; + } + } else { + // float real part, no denominator + return numerator; + } + } else { + return null; } - else if (c === CharCodes.SingleQuote) { - this.state = State.InAttributeValueSq; - this.sectionStart = this.index + 1; + } + + real = cutNumber(); + + if (!real) { + if (str[0] === 'i') { + // i => Complex(0, 1) + return $Kernel.$Complex(0, 1); } - else if (!isWhitespace(c)) { - this.sectionStart = this.index; - this.state = State.InAttributeValueNq; - this.stateInAttributeValueNoQuotes(c); // Reconsume token + if (str[0] === '-' && str[1] === 'i') { + // -i => Complex(0, -1) + return $Kernel.$Complex(0, -1); } - }; - Tokenizer.prototype.handleInAttributeValue = function (c, quote) { - if (c === quote || - (!this.decodeEntities && this.fastForwardTo(quote))) { - this.cbs.onattribdata(this.sectionStart, this.index); - this.sectionStart = -1; - this.cbs.onattribend(quote === CharCodes.DoubleQuote - ? QuoteType.Double - : QuoteType.Single, this.index); - this.state = State.BeforeAttributeName; + if (str[0] === '+' && str[1] === 'i') { + // +i => Complex(0, 1) + return $Kernel.$Complex(0, 1); } - else if (this.decodeEntities && c === CharCodes.Amp) { - this.baseState = this.state; - this.state = State.BeforeEntity; + // anything => Complex(0, 0) + return $Kernel.$Complex(0, 0); + } + + imag = cutNumber(); + if (!imag) { + if (str[0] === 'i') { + // 3i => Complex(0, 3) + return $Kernel.$Complex(0, real); + } else { + // 3 => Complex(3, 0) + return $Kernel.$Complex(real, 0); } - }; - Tokenizer.prototype.stateInAttributeValueDoubleQuotes = function (c) { - this.handleInAttributeValue(c, CharCodes.DoubleQuote); - }; - Tokenizer.prototype.stateInAttributeValueSingleQuotes = function (c) { - this.handleInAttributeValue(c, CharCodes.SingleQuote); - }; - Tokenizer.prototype.stateInAttributeValueNoQuotes = function (c) { - if (isWhitespace(c) || c === CharCodes.Gt) { - this.cbs.onattribdata(this.sectionStart, this.index); - this.sectionStart = -1; - this.cbs.onattribend(QuoteType.Unquoted, this.index); - this.state = State.BeforeAttributeName; - this.stateBeforeAttributeName(c); + } else { + // 3+2i => Complex(3, 2) + return $Kernel.$Complex(real, imag); + } + + }); + (function(self, $parent_nesting) { + + return $alias(self, "rectangular", "rect") + })(Opal.get_singleton_class(self)); + $alias(self, "arg", "angle"); + $alias(self, "conjugate", "conj"); + $alias(self, "divide", "/"); + $alias(self, "imaginary", "imag"); + $alias(self, "magnitude", "abs"); + $alias(self, "phase", "arg"); + $alias(self, "quo", "/"); + $alias(self, "rectangular", "rect"); + + Opal.udef(self, '$' + "negative?"); + Opal.udef(self, '$' + "positive?"); + + Opal.udef(self, '$' + "step"); return nil; })('::', $$$('Numeric'), $nesting); +}; + +Opal.modules["corelib/rational/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $def = Opal.def, $klass = Opal.klass; Opal.nil; var $$$ = Opal.$$$; + + Opal.add_stubs('convert,from_string'); + + (function($base) { + var self = $module($base, 'Kernel'); + + + return $def(self, '$Rational', function $$Rational(numerator, denominator) { + + + if (denominator == null) denominator = 1; + return $$$('Rational').$convert(numerator, denominator); + }, -2) + })('::'); + return (function($base, $super) { + var self = $klass($base, $super, 'String'); + + + return $def(self, '$to_r', function $$to_r() { + var self = this; + + return $$$('Rational').$from_string(self) + }) + })('::', null); +}; + +Opal.modules["corelib/rational"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $eqeq = Opal.eqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_divide = Opal.rb_divide, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $not = Opal.not, $Opal = Opal.Opal, $def = Opal.def, $return_ivar = Opal.return_ivar, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $rb_plus = Opal.rb_plus, $rb_gt = Opal.rb_gt, $rb_le = Opal.rb_le, $return_self = Opal.return_self, $alias = Opal.alias, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,to_i,==,raise,<,-@,new,gcd,/,nil?,===,reduce,to_r,!,equal?,coerce_to!,freeze,to_f,numerator,denominator,<=>,-,*,__coerced__,+,Rational,>,**,abs,ceil,with_precision,floor,<=,truncate,send'); + + self.$require("corelib/numeric"); + self.$require("corelib/rational/base"); + return (function($base, $super) { + var self = $klass($base, $super, 'Rational'); + + var $proto = self.$$prototype; + + $proto.num = $proto.den = nil; + + $defs(self, '$reduce', function $$reduce(num, den) { + var self = this, gcd = nil; + + + num = num.$to_i(); + den = den.$to_i(); + if ($eqeq(den, 0)) { + $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0"); + } else if ($truthy($rb_lt(den, 0))) { + + num = num['$-@'](); + den = den['$-@'](); + } else if ($eqeq(den, 1)) { + return self.$new(num, den) + } gcd = num.$gcd(den); + return self.$new($rb_divide(num, gcd), $rb_divide(den, gcd)); + }); + $defs(self, '$convert', function $$convert(num, den) { + var self = this; + + + if (($truthy(num['$nil?']()) || ($truthy(den['$nil?']())))) { + $Kernel.$raise($$$('TypeError'), "cannot convert nil into Rational"); + } if (($eqeqeq($$$('Integer'), num) && ($eqeqeq($$$('Integer'), den)))) { + return self.$reduce(num, den) + } if ((($eqeqeq($$$('Float'), num) || ($eqeqeq($$$('String'), num))) || ($eqeqeq($$$('Complex'), num)))) { + num = num.$to_r(); + } if ((($eqeqeq($$$('Float'), den) || ($eqeqeq($$$('String'), den))) || ($eqeqeq($$$('Complex'), den)))) { + den = den.$to_r(); + } if (($truthy(den['$equal?'](1)) && ($not($$$('Integer')['$==='](num))))) { + return $Opal['$coerce_to!'](num, $$$('Rational'), "to_r") + } else if (($eqeqeq($$$('Numeric'), num) && ($eqeqeq($$$('Numeric'), den)))) { + return $rb_divide(num, den) + } else { + return self.$reduce(num, den) + } }); + + $def(self, '$initialize', function $$initialize(num, den) { + var self = this; + + + self.num = num; + self.den = den; + return self.$freeze(); + }); + + $def(self, '$numerator', $return_ivar("num")); + + $def(self, '$denominator', $return_ivar("den")); + + $def(self, '$coerce', function $$coerce(other) { + var self = this, $ret_or_1 = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + return [other, self] + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + return [other.$to_r(), self] + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return [other, self.$to_f()] + } else { + return nil + } + }); + + $def(self, '$==', function $Rational_$eq_eq$1(other) { + var self = this, $ret_or_1 = nil, $ret_or_2 = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + if ($truthy(($ret_or_2 = self.num['$=='](other.$numerator())))) { + return self.den['$=='](other.$denominator()) + } else { + return $ret_or_2 } - else if (this.decodeEntities && c === CharCodes.Amp) { - this.baseState = this.state; - this.state = State.BeforeEntity; + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + if ($truthy(($ret_or_2 = self.num['$=='](other)))) { + return self.den['$=='](1) + } else { + return $ret_or_2 } - }; - Tokenizer.prototype.stateBeforeDeclaration = function (c) { - if (c === CharCodes.OpeningSquareBracket) { - this.state = State.CDATASequence; - this.sequenceIndex = 0; + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return self.$to_f()['$=='](other) + } else { + return other['$=='](self) + } + }); + + $def(self, '$<=>', function $Rational_$lt_eq_gt$2(other) { + var self = this, $ret_or_1 = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + return $rb_minus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator()))['$<=>'](0) + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + return $rb_minus(self.num, $rb_times(self.den, other))['$<=>'](0) + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return self.$to_f()['$<=>'](other) + } else { + return self.$__coerced__("<=>", other) + } + }); + + $def(self, '$+', function $Rational_$plus$3(other) { + var self = this, $ret_or_1 = nil, num = nil, den = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + + num = $rb_plus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator())); + den = $rb_times(self.den, other.$denominator()); + return $Kernel.$Rational(num, den); + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + return $Kernel.$Rational($rb_plus(self.num, $rb_times(other, self.den)), self.den) + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return $rb_plus(self.$to_f(), other) + } else { + return self.$__coerced__("+", other) + } + }); + + $def(self, '$-', function $Rational_$minus$4(other) { + var self = this, $ret_or_1 = nil, num = nil, den = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + + num = $rb_minus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator())); + den = $rb_times(self.den, other.$denominator()); + return $Kernel.$Rational(num, den); + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + return $Kernel.$Rational($rb_minus(self.num, $rb_times(other, self.den)), self.den) + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return $rb_minus(self.$to_f(), other) + } else { + return self.$__coerced__("-", other) + } + }); + + $def(self, '$*', function $Rational_$$5(other) { + var self = this, $ret_or_1 = nil, num = nil, den = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + + num = $rb_times(self.num, other.$numerator()); + den = $rb_times(self.den, other.$denominator()); + return $Kernel.$Rational(num, den); + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + return $Kernel.$Rational($rb_times(self.num, other), self.den) + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return $rb_times(self.$to_f(), other) + } else { + return self.$__coerced__("*", other) + } + }); + + $def(self, '$/', function $Rational_$slash$6(other) { + var self = this, $ret_or_1 = nil, num = nil, den = nil; + + if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) { + + num = $rb_times(self.num, other.$denominator()); + den = $rb_times(self.den, other.$numerator()); + return $Kernel.$Rational(num, den); + } else if ($eqeqeq($$$('Integer'), $ret_or_1)) { + if ($eqeq(other, 0)) { + return $rb_divide(self.$to_f(), 0.0) + } else { + return $Kernel.$Rational(self.num, $rb_times(self.den, other)) } - else { - this.state = - c === CharCodes.Dash - ? State.BeforeComment - : State.InDeclaration; + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return $rb_divide(self.$to_f(), other) + } else { + return self.$__coerced__("/", other) + } + }); + + $def(self, '$**', function $Rational_$$$7(other) { + var self = this, $ret_or_1 = nil; + + if ($eqeqeq($$$('Integer'), ($ret_or_1 = other))) { + if (($eqeq(self, 0) && ($truthy($rb_lt(other, 0))))) { + return $$$($$$('Float'), 'INFINITY') + } else if ($truthy($rb_gt(other, 0))) { + return $Kernel.$Rational(self.num['$**'](other), self.den['$**'](other)) + } else if ($truthy($rb_lt(other, 0))) { + return $Kernel.$Rational(self.den['$**'](other['$-@']()), self.num['$**'](other['$-@']())) + } else { + return $Kernel.$Rational(1, 1) } - }; - Tokenizer.prototype.stateInDeclaration = function (c) { - if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { - this.cbs.ondeclaration(this.sectionStart, this.index); - this.state = State.Text; - this.sectionStart = this.index + 1; + } else if ($eqeqeq($$$('Float'), $ret_or_1)) { + return self.$to_f()['$**'](other) + } else if ($eqeqeq($$$('Rational'), $ret_or_1)) { + if ($eqeq(other, 0)) { + return $Kernel.$Rational(1, 1) + } else if ($eqeq(other.$denominator(), 1)) { + if ($truthy($rb_lt(other, 0))) { + return $Kernel.$Rational(self.den['$**'](other.$numerator().$abs()), self.num['$**'](other.$numerator().$abs())) + } else { + return $Kernel.$Rational(self.num['$**'](other.$numerator()), self.den['$**'](other.$numerator())) + } + } else if (($eqeq(self, 0) && ($truthy($rb_lt(other, 0))))) { + return $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0") + } else { + return self.$to_f()['$**'](other) } - }; - Tokenizer.prototype.stateInProcessingInstruction = function (c) { - if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { - this.cbs.onprocessinginstruction(this.sectionStart, this.index); - this.state = State.Text; - this.sectionStart = this.index + 1; + } else { + return self.$__coerced__("**", other) + } + }); + + $def(self, '$abs', function $$abs() { + var self = this; + + return $Kernel.$Rational(self.num.$abs(), self.den.$abs()) + }); + + $def(self, '$ceil', function $$ceil(precision) { + var self = this; + + + if (precision == null) precision = 0; + if ($eqeq(precision, 0)) { + return $rb_divide(self.num['$-@'](), self.den)['$-@']().$ceil() + } else { + return self.$with_precision("ceil", precision) + } }, -1); + + $def(self, '$floor', function $$floor(precision) { + var self = this; + + + if (precision == null) precision = 0; + if ($eqeq(precision, 0)) { + return $rb_divide(self.num['$-@'](), self.den)['$-@']().$floor() + } else { + return self.$with_precision("floor", precision) + } }, -1); + + $def(self, '$hash', function $$hash() { + var self = this; + + return "Rational:" + (self.num) + ":" + (self.den) + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + return "(" + (self) + ")" + }); + + $def(self, '$rationalize', function $$rationalize(eps) { + var self = this; + + if (arguments.length > 1) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)"); + } + + if (eps == null) { + return self; + } + + var e = eps.$abs(), + a = $rb_minus(self, e), + b = $rb_plus(self, e); + + var p0 = 0, + p1 = 1, + q0 = 1, + q1 = 0, + p2, q2; + + var c, k, t; + + while (true) { + c = (a).$ceil(); + + if ($rb_le(c, b)) { + break; } - }; - Tokenizer.prototype.stateBeforeComment = function (c) { - if (c === CharCodes.Dash) { - this.state = State.InCommentLike; - this.currentSequence = Sequences.CommentEnd; - // Allow short comments (eg. <!-->) - this.sequenceIndex = 2; - this.sectionStart = this.index + 1; + + k = c - 1; + p2 = k * p1 + p0; + q2 = k * q1 + q0; + t = $rb_divide(1, $rb_minus(b, k)); + b = $rb_divide(1, $rb_minus(a, k)); + a = t; + + p0 = p1; + q0 = q1; + p1 = p2; + q1 = q2; + } + + return $Kernel.$Rational(c * p1 + p0, c * q1 + q0); + }, -1); + + $def(self, '$round', function $$round(precision) { + var self = this, num = nil, den = nil, approx = nil; + + + if (precision == null) precision = 0; + if (!$eqeq(precision, 0)) { + return self.$with_precision("round", precision) + } if ($eqeq(self.num, 0)) { + return 0 + } if ($eqeq(self.den, 1)) { + return self.num + } num = $rb_plus($rb_times(self.num.$abs(), 2), self.den); + den = $rb_times(self.den, 2); + approx = $rb_divide(num, den).$truncate(); + if ($truthy($rb_lt(self.num, 0))) { + return approx['$-@']() + } else { + return approx + } }, -1); + + $def(self, '$to_f', function $$to_f() { + var self = this; + + return $rb_divide(self.num, self.den) + }); + + $def(self, '$to_i', function $$to_i() { + var self = this; + + return self.$truncate() + }); + + $def(self, '$to_r', $return_self); + + $def(self, '$to_s', function $$to_s() { + var self = this; + + return "" + (self.num) + "/" + (self.den) + }); + + $def(self, '$truncate', function $$truncate(precision) { + var self = this; + + + if (precision == null) precision = 0; + if ($eqeq(precision, 0)) { + if ($truthy($rb_lt(self.num, 0))) { + return self.$ceil() + } else { + return self.$floor() } - else { - this.state = State.InDeclaration; + } else { + return self.$with_precision("truncate", precision) + } }, -1); + + $def(self, '$with_precision', function $$with_precision(method, precision) { + var self = this, p = nil, s = nil; + + + if (!$eqeqeq($$$('Integer'), precision)) { + $Kernel.$raise($$$('TypeError'), "not an Integer"); + } p = (10)['$**'](precision); + s = $rb_times(self, p); + if ($truthy($rb_lt(precision, 1))) { + return $rb_divide(s.$send(method), p).$to_i() + } else { + return $Kernel.$Rational(s.$send(method), p) + } }); + $defs(self, '$from_string', function $$from_string(string) { + + + var str = string.trimLeft(), + re = /^[+-]?[\d_]+(\.[\d_]+)?/; + str.match(re); + var numerator, denominator; + + function isFloat() { + return re.test(str); + } + + function cutFloat() { + var match = str.match(re); + var number = match[0]; + str = str.slice(number.length); + return number.replace(/_/g, ''); + } + + if (isFloat()) { + numerator = parseFloat(cutFloat()); + + if (str[0] === '/') { + // rational real part + str = str.slice(1); + + if (isFloat()) { + denominator = parseFloat(cutFloat()); + return $Kernel.$Rational(numerator, denominator); + } else { + return $Kernel.$Rational(numerator, 1); + } + } else { + return $Kernel.$Rational(numerator, 1); } - }; - Tokenizer.prototype.stateInSpecialComment = function (c) { - if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) { - this.cbs.oncomment(this.sectionStart, this.index, 0); - this.state = State.Text; - this.sectionStart = this.index + 1; + } else { + return $Kernel.$Rational(0, 1); + } + + }); + $alias(self, "divide", "/"); + return $alias(self, "quo", "/"); + })('::', $$$('Numeric')); +}; + +Opal.modules["corelib/time"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $slice = Opal.slice, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_divide = Opal.rb_divide, $rb_minus = Opal.rb_minus, $range = Opal.range, $neqeq = Opal.neqeq, $rb_le = Opal.rb_le, $eqeq = Opal.eqeq, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,include,===,raise,coerce_to!,respond_to?,to_str,to_i,_parse_offset,new,<=>,to_f,nil?,>,<,strftime,each,define_method,year,month,day,+,round,/,-,copy_instance_variables,initialize_dup,is_a?,zero?,wday,utc?,mon,yday,hour,min,sec,rjust,ljust,zone,to_s,[],cweek_cyear,jd,to_date,format,isdst,!=,<=,==,ceil,local,gm,asctime,getgm,gmt_offset,inspect,usec,gmtime,gmt?'); + + self.$require("corelib/comparable"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Time'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + self.$include($$$('Comparable')); + + var days_of_week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], + short_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], + short_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + long_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + $defs(self, '$at', function $$at(seconds, frac) { + + var result; + + if ($$$('Time')['$==='](seconds)) { + if (frac !== undefined) { + $Kernel.$raise($$$('TypeError'), "can't convert Time into an exact number"); } - }; - Tokenizer.prototype.stateBeforeSpecialS = function (c) { - var lower = c | 0x20; - if (lower === Sequences.ScriptEnd[3]) { - this.startSpecial(Sequences.ScriptEnd, 4); + result = new Date(seconds.getTime()); + result.timezone = seconds.timezone; + return result; + } + + if (!seconds.$$is_number) { + seconds = $Opal['$coerce_to!'](seconds, $$$('Integer'), "to_int"); + } + + if (frac === undefined) { + return new Date(seconds * 1000); + } + + if (!frac.$$is_number) { + frac = $Opal['$coerce_to!'](frac, $$$('Integer'), "to_int"); + } + + return new Date(seconds * 1000 + (frac / 1000)); + }, -2); + + function time_params(year, month, day, hour, min, sec) { + if (year.$$is_string) { + year = parseInt(year, 10); + } else { + year = $Opal['$coerce_to!'](year, $$$('Integer'), "to_int"); + } + + if (month === nil) { + month = 1; + } else if (!month.$$is_number) { + if ((month)['$respond_to?']("to_str")) { + month = (month).$to_str(); + switch (month.toLowerCase()) { + case 'jan': month = 1; break; + case 'feb': month = 2; break; + case 'mar': month = 3; break; + case 'apr': month = 4; break; + case 'may': month = 5; break; + case 'jun': month = 6; break; + case 'jul': month = 7; break; + case 'aug': month = 8; break; + case 'sep': month = 9; break; + case 'oct': month = 10; break; + case 'nov': month = 11; break; + case 'dec': month = 12; break; + default: month = (month).$to_i(); + } + } else { + month = $Opal['$coerce_to!'](month, $$$('Integer'), "to_int"); } - else if (lower === Sequences.StyleEnd[3]) { - this.startSpecial(Sequences.StyleEnd, 4); + } + + if (month < 1 || month > 12) { + $Kernel.$raise($$$('ArgumentError'), "month out of range: " + (month)); + } + month = month - 1; + + if (day === nil) { + day = 1; + } else if (day.$$is_string) { + day = parseInt(day, 10); + } else { + day = $Opal['$coerce_to!'](day, $$$('Integer'), "to_int"); + } + + if (day < 1 || day > 31) { + $Kernel.$raise($$$('ArgumentError'), "day out of range: " + (day)); + } + + if (hour === nil) { + hour = 0; + } else if (hour.$$is_string) { + hour = parseInt(hour, 10); + } else { + hour = $Opal['$coerce_to!'](hour, $$$('Integer'), "to_int"); + } + + if (hour < 0 || hour > 24) { + $Kernel.$raise($$$('ArgumentError'), "hour out of range: " + (hour)); + } + + if (min === nil) { + min = 0; + } else if (min.$$is_string) { + min = parseInt(min, 10); + } else { + min = $Opal['$coerce_to!'](min, $$$('Integer'), "to_int"); + } + + if (min < 0 || min > 59) { + $Kernel.$raise($$$('ArgumentError'), "min out of range: " + (min)); + } + + if (sec === nil) { + sec = 0; + } else if (!sec.$$is_number) { + if (sec.$$is_string) { + sec = parseInt(sec, 10); + } else { + sec = $Opal['$coerce_to!'](sec, $$$('Integer'), "to_int"); } - else { - this.state = State.InTagName; - this.stateInTagName(c); // Consume the token again + } + + if (sec < 0 || sec > 60) { + $Kernel.$raise($$$('ArgumentError'), "sec out of range: " + (sec)); + } + + return [year, month, day, hour, min, sec]; + } + $defs(self, '$new', function $Time_new$1(year, month, day, hour, min, sec, utc_offset) { + var self = this; + if (month == null) month = nil; + if (day == null) day = nil; + if (hour == null) hour = nil; + if (min == null) min = nil; + if (sec == null) sec = nil; + if (utc_offset == null) utc_offset = nil; + + var args, result, timezone, utc_date; + + if (year === undefined) { + return new Date(); + } + + args = time_params(year, month, day, hour, min, sec); + year = args[0]; + month = args[1]; + day = args[2]; + hour = args[3]; + min = args[4]; + sec = args[5]; + + if (utc_offset === nil) { + result = new Date(year, month, day, hour, min, 0, sec * 1000); + if (year < 100) { + result.setFullYear(year); } - }; - Tokenizer.prototype.stateBeforeEntity = function (c) { - // Start excess with 1 to include the '&' - this.entityExcess = 1; - this.entityResult = 0; - if (c === CharCodes.Number) { - this.state = State.BeforeNumericEntity; + return result; + } + + timezone = self.$_parse_offset(utc_offset); + utc_date = new Date(Date.UTC(year, month, day, hour, min, 0, sec * 1000)); + if (year < 100) { + utc_date.setUTCFullYear(year); + } + + result = new Date(utc_date.getTime() - timezone * 3600000); + result.timezone = timezone; + + return result; + }, -1); + $defs(self, '$_parse_offset', function $$_parse_offset(utc_offset) { + + + var timezone; + if (utc_offset.$$is_string) { + if (utc_offset == 'UTC') { + timezone = 0; } - else if (c === CharCodes.Amp) { - // We have two `&` characters in a row. Stay in the current state. + else if(/^[+-]\d\d:[0-5]\d$/.test(utc_offset)) { + var sign, hours, minutes; + sign = utc_offset[0]; + hours = +(utc_offset[1] + utc_offset[2]); + minutes = +(utc_offset[4] + utc_offset[5]); + + timezone = (sign == '-' ? -1 : 1) * (hours + minutes / 60); } else { - this.trieIndex = 0; - this.trieCurrent = this.entityTrie[0]; - this.state = State.InNamedEntity; - this.stateInNamedEntity(c); - } - }; - Tokenizer.prototype.stateInNamedEntity = function (c) { - this.entityExcess += 1; - this.trieIndex = (0, decode_js_1.determineBranch)(this.entityTrie, this.trieCurrent, this.trieIndex + 1, c); - if (this.trieIndex < 0) { - this.emitNamedEntity(); - this.index--; - return; - } - this.trieCurrent = this.entityTrie[this.trieIndex]; - var masked = this.trieCurrent & decode_js_1.BinTrieFlags.VALUE_LENGTH; - // If the branch is a value, store it and continue - if (masked) { - // The mask is the number of bytes of the value, including the current byte. - var valueLength = (masked >> 14) - 1; - // If we have a legacy entity while parsing strictly, just skip the number of bytes - if (!this.allowLegacyEntity() && c !== CharCodes.Semi) { - this.trieIndex += valueLength; - } - else { - // Add 1 as we have already incremented the excess - var entityStart = this.index - this.entityExcess + 1; - if (entityStart > this.sectionStart) { - this.emitPartial(this.sectionStart, entityStart); - } - // If this is a surrogate pair, consume the next two bytes - this.entityResult = this.trieIndex; - this.trieIndex += valueLength; - this.entityExcess = 0; - this.sectionStart = this.index + 1; - if (valueLength === 0) { - this.emitNamedEntity(); - } - } + // Unsupported: "A".."I","K".."Z" + $Kernel.$raise($$$('ArgumentError'), "\"+HH:MM\", \"-HH:MM\", \"UTC\" expected for utc_offset: " + (utc_offset)); } - }; - Tokenizer.prototype.emitNamedEntity = function () { - this.state = this.baseState; - if (this.entityResult === 0) { - return; + } + else if (utc_offset.$$is_number) { + timezone = utc_offset / 3600; + } + else { + $Kernel.$raise($$$('ArgumentError'), "Opal doesn't support other types for a timezone argument than Integer and String"); + } + return timezone; + + }); + $defs(self, '$local', function $$local(year, month, day, hour, min, sec, millisecond, _dummy1, _dummy2, _dummy3) { + + + if (month == null) month = nil; + if (day == null) day = nil; + if (hour == null) hour = nil; + if (min == null) min = nil; + if (sec == null) sec = nil; + if (millisecond == null) millisecond = nil; + if (_dummy1 == null) _dummy1 = nil; + if (_dummy2 == null) _dummy2 = nil; + if (_dummy3 == null) _dummy3 = nil; + + var args, result; + + if (arguments.length === 10) { + args = $slice(arguments); + year = args[5]; + month = args[4]; + day = args[3]; + hour = args[2]; + min = args[1]; + sec = args[0]; + } + + args = time_params(year, month, day, hour, min, sec); + year = args[0]; + month = args[1]; + day = args[2]; + hour = args[3]; + min = args[4]; + sec = args[5]; + + result = new Date(year, month, day, hour, min, 0, sec * 1000); + if (year < 100) { + result.setFullYear(year); + } + return result; + }, -2); + $defs(self, '$gm', function $$gm(year, month, day, hour, min, sec, millisecond, _dummy1, _dummy2, _dummy3) { + + + if (month == null) month = nil; + if (day == null) day = nil; + if (hour == null) hour = nil; + if (min == null) min = nil; + if (sec == null) sec = nil; + if (millisecond == null) millisecond = nil; + if (_dummy1 == null) _dummy1 = nil; + if (_dummy2 == null) _dummy2 = nil; + if (_dummy3 == null) _dummy3 = nil; + + var args, result; + + if (arguments.length === 10) { + args = $slice(arguments); + year = args[5]; + month = args[4]; + day = args[3]; + hour = args[2]; + min = args[1]; + sec = args[0]; + } + + args = time_params(year, month, day, hour, min, sec); + year = args[0]; + month = args[1]; + day = args[2]; + hour = args[3]; + min = args[4]; + sec = args[5]; + + result = new Date(Date.UTC(year, month, day, hour, min, 0, sec * 1000)); + if (year < 100) { + result.setUTCFullYear(year); + } + result.timezone = 0; + return result; + }, -2); + $defs(self, '$now', function $$now() { + var self = this; + + return self.$new() + }); + + $def(self, '$+', function $Time_$plus$2(other) { + var self = this; + + + if ($eqeqeq($$$('Time'), other)) { + $Kernel.$raise($$$('TypeError'), "time + time?"); + } + if (!other.$$is_number) { + other = $Opal['$coerce_to!'](other, $$$('Integer'), "to_int"); + } + var result = new Date(self.getTime() + (other * 1000)); + result.timezone = self.timezone; + return result; + }); + + $def(self, '$-', function $Time_$minus$3(other) { + var self = this; + + + if ($eqeqeq($$$('Time'), other)) { + return (self.getTime() - other.getTime()) / 1000 + } + if (!other.$$is_number) { + other = $Opal['$coerce_to!'](other, $$$('Integer'), "to_int"); + } + var result = new Date(self.getTime() - (other * 1000)); + result.timezone = self.timezone; + return result; + }); + + $def(self, '$<=>', function $Time_$lt_eq_gt$4(other) { + var self = this, r = nil; + + if ($eqeqeq($$$('Time'), other)) { + return self.$to_f()['$<=>'](other.$to_f()) + } else { + + r = other['$<=>'](self); + if ($truthy(r['$nil?']())) { + return nil + } else if ($truthy($rb_gt(r, 0))) { + return -1 + } else if ($truthy($rb_lt(r, 0))) { + return 1 + } else { + return 0 + } } + }); + + $def(self, '$==', function $Time_$eq_eq$5(other) { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = $$$('Time')['$==='](other)))) { + return self.$to_f() === other.$to_f() + } else { + return $ret_or_1 + } + }); + + $def(self, '$asctime', function $$asctime() { + var self = this; + + return self.$strftime("%a %b %e %H:%M:%S %Y") + }); + $send([["year", "getFullYear", "getUTCFullYear"], ["mon", "getMonth", "getUTCMonth", 1], ["wday", "getDay", "getUTCDay"], ["day", "getDate", "getUTCDate"], ["hour", "getHours", "getUTCHours"], ["min", "getMinutes", "getUTCMinutes"], ["sec", "getSeconds", "getUTCSeconds"]], 'each', [], function $Time$6(method, getter, utcgetter, difference){var self = $Time$6.$$s == null ? this : $Time$6.$$s; + + + if (method == null) method = nil; + if (getter == null) getter = nil; + if (utcgetter == null) utcgetter = nil; + if (difference == null) difference = 0; + return $send(self, 'define_method', [method], function $$7(){var self = $$7.$$s == null ? this : $$7.$$s; + + + return difference + ((self.timezone != null) ? + (new Date(self.getTime() + self.timezone * 3600000))[utcgetter]() : + self[getter]()) + }, {$$s: self});}, {$$arity: -4, $$s: self}); + + $def(self, '$yday', function $$yday() { + var self = this, start_of_year = nil, start_of_day = nil, one_day = nil; + + + start_of_year = $$('Time').$new(self.$year()).$to_i(); + start_of_day = $$('Time').$new(self.$year(), self.$month(), self.$day()).$to_i(); + one_day = 86400; + return $rb_plus($rb_divide($rb_minus(start_of_day, start_of_year), one_day).$round(), 1); + }); + + $def(self, '$isdst', function $$isdst() { + var self = this; + + + var jan = new Date(self.getFullYear(), 0, 1), + jul = new Date(self.getFullYear(), 6, 1); + return self.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); + + }); + + $def(self, '$dup', function $$dup() { + var self = this, copy = nil; + + + copy = new Date(self.getTime()); + copy.$copy_instance_variables(self); + copy.$initialize_dup(self); + return copy; + }); + + $def(self, '$eql?', function $Time_eql$ques$8(other) { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = other['$is_a?']($$$('Time'))))) { + return self['$<=>'](other)['$zero?']() + } else { + return $ret_or_1 + } + }); + $send([["sunday?", 0], ["monday?", 1], ["tuesday?", 2], ["wednesday?", 3], ["thursday?", 4], ["friday?", 5], ["saturday?", 6]], 'each', [], function $Time$9(method, weekday){var self = $Time$9.$$s == null ? this : $Time$9.$$s; + + + if (method == null) method = nil; + if (weekday == null) weekday = nil; + return $send(self, 'define_method', [method], function $$10(){var self = $$10.$$s == null ? this : $$10.$$s; + + return self.$wday() === weekday}, {$$s: self});}, {$$s: self}); + + $def(self, '$hash', function $$hash() { + var self = this; + + return 'Time:' + self.getTime(); + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + if ($truthy(self['$utc?']())) { + return self.$strftime("%Y-%m-%d %H:%M:%S UTC") + } else { + return self.$strftime("%Y-%m-%d %H:%M:%S %z") + } + }); + + $def(self, '$succ', function $$succ() { + var self = this; + + + var result = new Date(self.getTime() + 1000); + result.timezone = self.timezone; + return result; + + }); + + $def(self, '$usec', function $$usec() { + var self = this; + + return self.getMilliseconds() * 1000; + }); + + $def(self, '$zone', function $$zone() { + var self = this; + + + if (self.timezone === 0) return "UTC"; + else if (self.timezone != null) return nil; + + var string = self.toString(), + result; + + if (string.indexOf('(') == -1) { + result = string.match(/[A-Z]{3,4}/)[0]; + } + else { + result = string.match(/\((.+)\)(?:\s|$)/)[1]; + } + + if (result == "GMT" && /(GMT\W*\d{4})/.test(string)) { + return RegExp.$1; + } + else { + return result; + } + + }); + + $def(self, '$getgm', function $$getgm() { + var self = this; + + + var result = new Date(self.getTime()); + result.timezone = 0; + return result; + + }); + + $def(self, '$gmtime', function $$gmtime() { + var self = this; + + + if (self.timezone !== 0) { + $deny_frozen_access(self); + self.timezone = 0; + } + return self; + + }); + + $def(self, '$gmt?', function $Time_gmt$ques$11() { + var self = this; + + return self.timezone === 0; + }); + + $def(self, '$gmt_offset', function $$gmt_offset() { + var self = this; + + return (self.timezone != null) ? self.timezone * 60 : -self.getTimezoneOffset() * 60; + }); + + $def(self, '$strftime', function $$strftime(format) { + var self = this; + + + return format.replace(/%([\-_#^0]*:{0,2})(\d+)?([EO]*)(.)/g, function(full, flags, width, _, conv) { + var result = "", jd, c, s, + zero = flags.indexOf('0') !== -1, + pad = flags.indexOf('-') === -1, + blank = flags.indexOf('_') !== -1, + upcase = flags.indexOf('^') !== -1, + invert = flags.indexOf('#') !== -1, + colons = (flags.match(':') || []).length; + + width = parseInt(width, 10); + + if (zero && blank) { + if (flags.indexOf('0') < flags.indexOf('_')) { + zero = false; + } + else { + blank = false; + } } - var valueLength = (this.entityTrie[this.entityResult] & decode_js_1.BinTrieFlags.VALUE_LENGTH) >> - 14; - switch (valueLength) { - case 1: { - this.emitCodePoint(this.entityTrie[this.entityResult] & - ~decode_js_1.BinTrieFlags.VALUE_LENGTH); - break; - } - case 2: { - this.emitCodePoint(this.entityTrie[this.entityResult + 1]); - break; + + switch (conv) { + case 'Y': + result += self.$year(); + break; + + case 'C': + zero = !blank; + result += Math.round(self.$year() / 100); + break; + + case 'y': + zero = !blank; + result += (self.$year() % 100); + break; + + case 'm': + zero = !blank; + result += self.$mon(); + break; + + case 'B': + result += long_months[self.$mon() - 1]; + break; + + case 'b': + case 'h': + blank = !zero; + result += short_months[self.$mon() - 1]; + break; + + case 'd': + zero = !blank; + result += self.$day(); + break; + + case 'e': + blank = !zero; + result += self.$day(); + break; + + case 'j': + zero = !blank; + width = isNaN(width) ? 3 : width; + result += self.$yday(); + break; + + case 'H': + zero = !blank; + result += self.$hour(); + break; + + case 'k': + blank = !zero; + result += self.$hour(); + break; + + case 'I': + zero = !blank; + result += (self.$hour() % 12 || 12); + break; + + case 'l': + blank = !zero; + result += (self.$hour() % 12 || 12); + break; + + case 'P': + result += (self.$hour() >= 12 ? "pm" : "am"); + break; + + case 'p': + result += (self.$hour() >= 12 ? "PM" : "AM"); + break; + + case 'M': + zero = !blank; + result += self.$min(); + break; + + case 'S': + zero = !blank; + result += self.$sec(); + break; + + case 'L': + zero = !blank; + width = isNaN(width) ? 3 : width; + result += self.getMilliseconds(); + break; + + case 'N': + width = isNaN(width) ? 9 : width; + result += (self.getMilliseconds().toString()).$rjust(3, "0"); + result = (result).$ljust(width, "0"); + break; + + case 'z': + var offset = (self.timezone == null) ? self.getTimezoneOffset() : (-self.timezone * 60), + hours = Math.floor(Math.abs(offset) / 60), + minutes = Math.abs(offset) % 60; + + result += offset < 0 ? "+" : "-"; + result += hours < 10 ? "0" : ""; + result += hours; + + if (colons > 0) { + result += ":"; } - case 3: { - this.emitCodePoint(this.entityTrie[this.entityResult + 1]); - this.emitCodePoint(this.entityTrie[this.entityResult + 2]); + + result += minutes < 10 ? "0" : ""; + result += minutes; + + if (colons > 1) { + result += ":00"; } - } - }; - Tokenizer.prototype.stateBeforeNumericEntity = function (c) { - if ((c | 0x20) === CharCodes.LowerX) { - this.entityExcess++; - this.state = State.InHexEntity; - } - else { - this.state = State.InNumericEntity; - this.stateInNumericEntity(c); - } - }; - Tokenizer.prototype.emitNumericEntity = function (strict) { - var entityStart = this.index - this.entityExcess - 1; - var numberStart = entityStart + 2 + Number(this.state === State.InHexEntity); - if (numberStart !== this.index) { - // Emit leading data if any - if (entityStart > this.sectionStart) { - this.emitPartial(this.sectionStart, entityStart); + + break; + + case 'Z': + result += self.$zone(); + break; + + case 'A': + result += days_of_week[self.$wday()]; + break; + + case 'a': + result += short_days[self.$wday()]; + break; + + case 'u': + result += (self.$wday() + 1); + break; + + case 'w': + result += self.$wday(); + break; + + case 'V': + result += self.$cweek_cyear()['$[]'](0).$to_s().$rjust(2, "0"); + break; + + case 'G': + result += self.$cweek_cyear()['$[]'](1); + break; + + case 'g': + result += self.$cweek_cyear()['$[]'](1)['$[]']($range(-2, -1, false)); + break; + + case 's': + result += self.$to_i(); + break; + + case 'n': + result += "\n"; + break; + + case 't': + result += "\t"; + break; + + case '%': + result += "%"; + break; + + case 'c': + result += self.$strftime("%a %b %e %T %Y"); + break; + + case 'D': + case 'x': + result += self.$strftime("%m/%d/%y"); + break; + + case 'F': + result += self.$strftime("%Y-%m-%d"); + break; + + case 'v': + result += self.$strftime("%e-%^b-%4Y"); + break; + + case 'r': + result += self.$strftime("%I:%M:%S %p"); + break; + + case 'R': + result += self.$strftime("%H:%M"); + break; + + case 'T': + case 'X': + result += self.$strftime("%H:%M:%S"); + break; + + // Non-standard: JIS X 0301 date format + case 'J': + jd = self.$to_date().$jd(); + if (jd < 2405160) { + result += self.$strftime("%Y-%m-%d"); + break; } - this.sectionStart = this.index + Number(strict); - this.emitCodePoint((0, decode_js_1.replaceCodePoint)(this.entityResult)); - } - this.state = this.baseState; - }; - Tokenizer.prototype.stateInNumericEntity = function (c) { - if (c === CharCodes.Semi) { - this.emitNumericEntity(true); + else if (jd < 2419614) + c = 'M', s = 1867; + else if (jd < 2424875) + c = 'T', s = 1911; + else if (jd < 2447535) + c = 'S', s = 1925; + else if (jd < 2458605) + c = 'H', s = 1988; + else + c = 'R', s = 2018; + + result += self.$format("%c%02d", c, $rb_minus(self.$year(), s)); + result += self.$strftime("-%m-%d"); + break; + + default: + return full; } - else if (isNumber(c)) { - this.entityResult = this.entityResult * 10 + (c - CharCodes.Zero); - this.entityExcess++; + + if (upcase) { + result = result.toUpperCase(); } - else { - if (this.allowLegacyEntity()) { - this.emitNumericEntity(false); - } - else { - this.state = this.baseState; - } - this.index--; + + if (invert) { + result = result.replace(/[A-Z]/, function(c) { c.toLowerCase(); }). + replace(/[a-z]/, function(c) { c.toUpperCase(); }); } - }; - Tokenizer.prototype.stateInHexEntity = function (c) { - if (c === CharCodes.Semi) { - this.emitNumericEntity(true); + + if (pad && (zero || blank)) { + result = (result).$rjust(isNaN(width) ? 2 : width, blank ? " " : "0"); } - else if (isNumber(c)) { - this.entityResult = this.entityResult * 16 + (c - CharCodes.Zero); - this.entityExcess++; + + return result; + }); + + }); + + $def(self, '$to_a', function $$to_a() { + var self = this; + + return [self.$sec(), self.$min(), self.$hour(), self.$day(), self.$month(), self.$year(), self.$wday(), self.$yday(), self.$isdst(), self.$zone()] + }); + + $def(self, '$to_f', function $$to_f() { + var self = this; + + return self.getTime() / 1000; + }); + + $def(self, '$to_i', function $$to_i() { + var self = this; + + return parseInt(self.getTime() / 1000, 10); + }); + + $def(self, '$cweek_cyear', function $$cweek_cyear() { + var self = this, jan01 = nil, jan01_wday = nil, year = nil, offset = nil, week = nil, dec31 = nil, dec31_wday = nil; + + + jan01 = $$$('Time').$new(self.$year(), 1, 1); + jan01_wday = jan01.$wday(); + year = self.$year(); + if (($truthy($rb_le(jan01_wday, 4)) && ($neqeq(jan01_wday, 0)))) { + offset = $rb_minus(jan01_wday, 1); + } else { + + offset = $rb_minus($rb_minus(jan01_wday, 7), 1); + if ($eqeq(offset, -8)) { + offset = -1; + } } week = $rb_divide($rb_plus(self.$yday(), offset), 7.0).$ceil(); + if ($truthy($rb_le(week, 0))) { + return $$$('Time').$new($rb_minus(self.$year(), 1), 12, 31).$cweek_cyear() + } else if ($eqeq(week, 53)) { + + dec31 = $$$('Time').$new(self.$year(), 12, 31); + dec31_wday = dec31.$wday(); + if (($truthy($rb_le(dec31_wday, 3)) && ($neqeq(dec31_wday, 0)))) { + + week = 1; + year = $rb_plus(year, 1); + } } return [week, year]; + }); + (function(self, $parent_nesting) { + + + $alias(self, "mktime", "local"); + return $alias(self, "utc", "gm"); + })(Opal.get_singleton_class(self)); + $alias(self, "ctime", "asctime"); + $alias(self, "dst?", "isdst"); + $alias(self, "getutc", "getgm"); + $alias(self, "gmtoff", "gmt_offset"); + $alias(self, "mday", "day"); + $alias(self, "month", "mon"); + $alias(self, "to_s", "inspect"); + $alias(self, "tv_sec", "to_i"); + $alias(self, "tv_usec", "usec"); + $alias(self, "utc", "gmtime"); + $alias(self, "utc?", "gmt?"); + return $alias(self, "utc_offset", "gmt_offset"); + })('::', Date, $nesting); +}; + +Opal.modules["corelib/struct"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $truthy = Opal.truthy, $neqeq = Opal.neqeq, $eqeq = Opal.eqeq, $Opal = Opal.Opal, $send = Opal.send, $Class = Opal.Class, $to_a = Opal.to_a, $def = Opal.def, $defs = Opal.defs, $Kernel = Opal.Kernel, $hash2 = Opal.hash2, $rb_gt = Opal.rb_gt, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_lt = Opal.rb_lt, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('require,include,!=,upcase,[],==,class,unshift,const_name!,map,coerce_to!,new,each,define_struct_attribute,allocate,initialize,alias_method,module_eval,to_proc,const_set,raise,<<,members,define_method,instance_eval,last,>,length,-,keys,any?,join,[]=,each_with_index,hash,===,<,-@,size,>=,include?,to_sym,instance_of?,__id__,eql?,enum_for,+,name,each_pair,inspect,to_h,args,each_with_object,flatten,to_a,respond_to?,dig'); + + self.$require("corelib/enumerable"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Struct'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + self.$include($$$('Enumerable')); + $defs(self, '$new', function $Struct_new$1(const_name, $a, $b) { + var block = $Struct_new$1.$$p || nil, $post_args, $kwargs, args, keyword_init, self = this, klass = nil; + + $Struct_new$1.$$p = null; + $post_args = $slice(arguments, 1); + $kwargs = $extract_kwargs($post_args); + $kwargs = $ensure_kwargs($kwargs); + args = $post_args; + + keyword_init = $kwargs.$$smap["keyword_init"];if (keyword_init == null) keyword_init = false; + if ($truthy(const_name)) { + if (($eqeq(const_name.$class(), $$$('String')) && ($neqeq(const_name['$[]'](0).$upcase(), const_name['$[]'](0))))) { + + args.$unshift(const_name); + const_name = nil; + } else { + + try { + const_name = $Opal['$const_name!'](const_name); + } catch ($err) { + if (Opal.rescue($err, [$$$('TypeError'), $$$('NameError')])) { + try { + + args.$unshift(const_name); + const_name = nil; + } finally { Opal.pop_exception(); } + } else { throw $err; } + } } + } $send(args, 'map', [], function $$2(arg){ + + if (arg == null) arg = nil; + return $Opal['$coerce_to!'](arg, $$$('String'), "to_str");}); + klass = $send($Class, 'new', [self], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s; + + + $send(args, 'each', [], function $$4(arg){var self = $$4.$$s == null ? this : $$4.$$s; + + + if (arg == null) arg = nil; + return self.$define_struct_attribute(arg);}, {$$s: self}); + return (function(self, $parent_nesting) { + + + + $def(self, '$new', function $new$5($a) { + var $post_args, args, self = this, instance = nil; + + + $post_args = $slice(arguments); + args = $post_args; + instance = self.$allocate(); + instance.$$data = {}; + $send(instance, 'initialize', $to_a(args)); + return instance; + }, -1); + return self.$alias_method("[]", "new"); + })(Opal.get_singleton_class(self));}, {$$s: self}); + if ($truthy(block)) { + $send(klass, 'module_eval', [], block.$to_proc()); + } klass.$$keyword_init = keyword_init; + if ($truthy(const_name)) { + $$$('Struct').$const_set(const_name, klass); + } return klass; + }, -2); + $defs(self, '$define_struct_attribute', function $$define_struct_attribute(name) { + var self = this; + + + if ($eqeq(self, $$$('Struct'))) { + $Kernel.$raise($$$('ArgumentError'), "you cannot define attributes to the Struct class"); + } self.$members()['$<<'](name); + $send(self, 'define_method', [name], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s; + + return self.$$data[name];}, {$$s: self}); + return $send(self, 'define_method', ["" + (name) + "="], function $$7(value){var self = $$7.$$s == null ? this : $$7.$$s; + + + if (value == null) value = nil; + return self.$$data[name] = value;}, {$$s: self}); + }); + $defs(self, '$members', function $$members() { + var self = this, $ret_or_1 = nil; + if (self.members == null) self.members = nil; + + + if ($eqeq(self, $$$('Struct'))) { + $Kernel.$raise($$$('ArgumentError'), "the Struct class has no members"); + } return (self.members = ($truthy(($ret_or_1 = self.members)) ? ($ret_or_1) : ([]))); + }); + $defs(self, '$inherited', function $$inherited(klass) { + var self = this, members = nil; + if (self.members == null) self.members = nil; + + + members = self.members; + return $send(klass, 'instance_eval', [], function $$8(){var self = $$8.$$s == null ? this : $$8.$$s; + + return (self.members = members)}, {$$s: self}); + }); + + $def(self, '$initialize', function $$initialize($a) { + var $post_args, args, self = this, kwargs = nil, $ret_or_1 = nil, extra = nil; + + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy(self.$class().$$keyword_init)) { + + kwargs = ($truthy(($ret_or_1 = args.$last())) ? ($ret_or_1) : ($hash2([], {}))); + if (($truthy($rb_gt(args.$length(), 1)) || ($truthy((args.length === 1 && !kwargs.$$is_hash))))) { + $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$length()) + ", expected 0)"); + } extra = $rb_minus(kwargs.$keys(), self.$class().$members()); + if ($truthy(extra['$any?']())) { + $Kernel.$raise($$$('ArgumentError'), "unknown keywords: " + (extra.$join(", "))); + } return $send(self.$class().$members(), 'each', [], function $$9(name){var $b, self = $$9.$$s == null ? this : $$9.$$s; + + + if (name == null) name = nil; + return ($b = [name, kwargs['$[]'](name)], $send(self, '[]=', $b), $b[$b.length - 1]);}, {$$s: self}); + } else { + + if ($truthy($rb_gt(args.$length(), self.$class().$members().$length()))) { + $Kernel.$raise($$$('ArgumentError'), "struct size differs"); + } return $send(self.$class().$members(), 'each_with_index', [], function $$10(name, index){var $b, self = $$10.$$s == null ? this : $$10.$$s; + + + if (name == null) name = nil; + if (index == null) index = nil; + return ($b = [name, args['$[]'](index)], $send(self, '[]=', $b), $b[$b.length - 1]);}, {$$s: self}); + } }, -1); + + $def(self, '$initialize_copy', function $$initialize_copy(from) { + var self = this; + + + self.$$data = {}; + var keys = Object.keys(from.$$data), i, max, name; + for (i = 0, max = keys.length; i < max; i++) { + name = keys[i]; + self.$$data[name] = from.$$data[name]; + } + + }); + $defs(self, '$keyword_init?', function $Struct_keyword_init$ques$11() { + var self = this; + + return self.$$keyword_init; + }); + + $def(self, '$members', function $$members() { + var self = this; + + return self.$class().$members() + }); + + $def(self, '$hash', function $$hash() { + var self = this; + + return $$('Hash').$new(self.$$data).$hash() + }); + + $def(self, '$[]', function $Struct_$$$12(name) { + var self = this; + + + if ($eqeqeq($$$('Integer'), name)) { + + if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) { + $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")"); + } if ($truthy($rb_ge(name, self.$class().$members().$size()))) { + $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")"); + } name = self.$class().$members()['$[]'](name); + } else if ($eqeqeq($$$('String'), name)) { + + if(!self.$$data.hasOwnProperty(name)) { + $Kernel.$raise($$$('NameError').$new("no member '" + (name) + "' in struct", name)); } - else if (isHexDigit(c)) { - this.entityResult = - this.entityResult * 16 + ((c | 0x20) - CharCodes.LowerA + 10); - this.entityExcess++; + + } else { + $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + (name.$class()) + " into Integer"); + } name = $Opal['$coerce_to!'](name, $$$('String'), "to_str"); + return self.$$data[name]; }); + + $def(self, '$[]=', function $Struct_$$$eq$13(name, value) { + var self = this; + + + if ($eqeqeq($$$('Integer'), name)) { + + if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) { + $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")"); + } if ($truthy($rb_ge(name, self.$class().$members().$size()))) { + $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")"); + } name = self.$class().$members()['$[]'](name); + } else if ($eqeqeq($$$('String'), name)) { + if (!$truthy(self.$class().$members()['$include?'](name.$to_sym()))) { + $Kernel.$raise($$$('NameError').$new("no member '" + (name) + "' in struct", name)); } - else { - if (this.allowLegacyEntity()) { - this.emitNumericEntity(false); + } else { + $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + (name.$class()) + " into Integer"); + } name = $Opal['$coerce_to!'](name, $$$('String'), "to_str"); + return self.$$data[name] = value; }); + + $def(self, '$==', function $Struct_$eq_eq$14(other) { + var self = this; + + + if (!$truthy(other['$instance_of?'](self.$class()))) { + return false + } + var recursed1 = {}, recursed2 = {}; + + function _eqeq(struct, other) { + var key, a, b; + + recursed1[(struct).$__id__()] = true; + recursed2[(other).$__id__()] = true; + + for (key in struct.$$data) { + a = struct.$$data[key]; + b = other.$$data[key]; + + if ($$$('Struct')['$==='](a)) { + if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) { + if (!_eqeq(a, b)) { + return false; + } } - else { - this.state = this.baseState; + } else { + if (!(a)['$=='](b)) { + return false; } - this.index--; + } } - }; - Tokenizer.prototype.allowLegacyEntity = function () { - return (!this.xmlMode && - (this.baseState === State.Text || - this.baseState === State.InSpecialTag)); - }; - /** - * Remove data that has already been consumed from the buffer. - */ - Tokenizer.prototype.cleanup = function () { - // If we are inside of text or attributes, emit what we already have. - if (this.running && this.sectionStart !== this.index) { - if (this.state === State.Text || - (this.state === State.InSpecialTag && this.sequenceIndex === 0)) { - this.cbs.ontext(this.sectionStart, this.index); - this.sectionStart = this.index; + + return true; + } + + return _eqeq(self, other); + }); + + $def(self, '$eql?', function $Struct_eql$ques$15(other) { + var self = this; + + + if (!$truthy(other['$instance_of?'](self.$class()))) { + return false + } + var recursed1 = {}, recursed2 = {}; + + function _eqeq(struct, other) { + var key, a, b; + + recursed1[(struct).$__id__()] = true; + recursed2[(other).$__id__()] = true; + + for (key in struct.$$data) { + a = struct.$$data[key]; + b = other.$$data[key]; + + if ($$$('Struct')['$==='](a)) { + if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) { + if (!_eqeq(a, b)) { + return false; + } } - else if (this.state === State.InAttributeValueDq || - this.state === State.InAttributeValueSq || - this.state === State.InAttributeValueNq) { - this.cbs.onattribdata(this.sectionStart, this.index); - this.sectionStart = this.index; + } else { + if (!(a)['$eql?'](b)) { + return false; } + } } - }; - Tokenizer.prototype.shouldContinue = function () { - return this.index < this.buffer.length + this.offset && this.running; - }; - /** - * Iterates through the buffer, calling the function corresponding to the current state. - * - * States that are more likely to be hit are higher up, as a performance improvement. - */ - Tokenizer.prototype.parse = function () { - while (this.shouldContinue()) { - var c = this.buffer.charCodeAt(this.index - this.offset); - switch (this.state) { - case State.Text: { - this.stateText(c); - break; - } - case State.SpecialStartSequence: { - this.stateSpecialStartSequence(c); - break; - } - case State.InSpecialTag: { - this.stateInSpecialTag(c); - break; - } - case State.CDATASequence: { - this.stateCDATASequence(c); - break; - } - case State.InAttributeValueDq: { - this.stateInAttributeValueDoubleQuotes(c); - break; - } - case State.InAttributeName: { - this.stateInAttributeName(c); - break; - } - case State.InCommentLike: { - this.stateInCommentLike(c); - break; - } - case State.InSpecialComment: { - this.stateInSpecialComment(c); - break; - } - case State.BeforeAttributeName: { - this.stateBeforeAttributeName(c); - break; - } - case State.InTagName: { - this.stateInTagName(c); - break; - } - case State.InClosingTagName: { - this.stateInClosingTagName(c); - break; - } - case State.BeforeTagName: { - this.stateBeforeTagName(c); - break; - } - case State.AfterAttributeName: { - this.stateAfterAttributeName(c); - break; - } - case State.InAttributeValueSq: { - this.stateInAttributeValueSingleQuotes(c); - break; - } - case State.BeforeAttributeValue: { - this.stateBeforeAttributeValue(c); - break; - } - case State.BeforeClosingTagName: { - this.stateBeforeClosingTagName(c); - break; - } - case State.AfterClosingTagName: { - this.stateAfterClosingTagName(c); - break; - } - case State.BeforeSpecialS: { - this.stateBeforeSpecialS(c); - break; - } - case State.InAttributeValueNq: { - this.stateInAttributeValueNoQuotes(c); - break; - } - case State.InSelfClosingTag: { - this.stateInSelfClosingTag(c); - break; - } - case State.InDeclaration: { - this.stateInDeclaration(c); - break; - } - case State.BeforeDeclaration: { - this.stateBeforeDeclaration(c); - break; - } - case State.BeforeComment: { - this.stateBeforeComment(c); - break; - } - case State.InProcessingInstruction: { - this.stateInProcessingInstruction(c); - break; - } - case State.InNamedEntity: { - this.stateInNamedEntity(c); - break; - } - case State.BeforeEntity: { - this.stateBeforeEntity(c); - break; - } - case State.InHexEntity: { - this.stateInHexEntity(c); - break; - } - case State.InNumericEntity: { - this.stateInNumericEntity(c); - break; - } - default: { - // `this._state === State.BeforeNumericEntity` - this.stateBeforeNumericEntity(c); - } - } - this.index++; + + return true; + } + + return _eqeq(self, other); + }); + + $def(self, '$each', function $$each() { + var $yield = $$each.$$p || nil, self = this; + + $$each.$$p = null; + + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["each"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s; + + return self.$size()}, {$$s: self}) + } $send(self.$class().$members(), 'each', [], function $$17(name){var self = $$17.$$s == null ? this : $$17.$$s; + + + if (name == null) name = nil; + return Opal.yield1($yield, self['$[]'](name));}, {$$s: self}); + return self; + }); + + $def(self, '$each_pair', function $$each_pair() { + var $yield = $$each_pair.$$p || nil, self = this; + + $$each_pair.$$p = null; + + if (!($yield !== nil)) { + return $send(self, 'enum_for', ["each_pair"], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s; + + return self.$size()}, {$$s: self}) + } $send(self.$class().$members(), 'each', [], function $$19(name){var self = $$19.$$s == null ? this : $$19.$$s; + + + if (name == null) name = nil; + return Opal.yield1($yield, [name, self['$[]'](name)]);}, {$$s: self}); + return self; + }); + + $def(self, '$length', function $$length() { + var self = this; + + return self.$class().$members().$length() + }); + + $def(self, '$to_a', function $$to_a() { + var self = this; + + return $send(self.$class().$members(), 'map', [], function $$20(name){var self = $$20.$$s == null ? this : $$20.$$s; + + + if (name == null) name = nil; + return self['$[]'](name);}, {$$s: self}) + }); + var inspect_stack = []; + + $def(self, '$inspect', function $$inspect() { + var self = this, result = nil, pushed = nil; + + return (function() { try { + + result = "#<struct "; + if ($truthy((inspect_stack)['$include?'](self.$__id__()))) { + return $rb_plus(result, ":...>") + } else { + + (inspect_stack)['$<<'](self.$__id__()); + pushed = true; + if (($eqeqeq($$$('Struct'), self) && ($truthy(self.$class().$name())))) { + result = $rb_plus(result, "" + (self.$class()) + " "); + }; + result = $rb_plus(result, $send(self.$each_pair(), 'map', [], function $$21(name, value){ + + if (name == null) name = nil; + if (value == null) value = nil; + return "" + (name) + "=" + ($$('Opal').$inspect(value));}).$join(", ")); + result = $rb_plus(result, ">"); + return result; + }; + } finally { + ($truthy(pushed) ? (inspect_stack.pop()) : nil); + } })() + }); + + $def(self, '$to_h', function $$to_h() { + var block = $$to_h.$$p || nil, self = this; + + $$to_h.$$p = null; + if ((block !== nil)) { + return $send($send(self, 'map', [], block.$to_proc()), 'to_h', $to_a(self.$args())) + } return $send(self.$class().$members(), 'each_with_object', [$hash2([], {})], function $$22(name, h){var $a, self = $$22.$$s == null ? this : $$22.$$s; + + + if (name == null) name = nil; + if (h == null) h = nil; + return ($a = [name, self['$[]'](name)], $send(h, '[]=', $a), $a[$a.length - 1]);}, {$$s: self}); + }); + + $def(self, '$values_at', function $$values_at($a) { + var $post_args, args, self = this; + + + $post_args = $slice(arguments); + args = $post_args; + args = $send(args, 'map', [], function $$23(arg){ + + if (arg == null) arg = nil; + return arg.$$is_range ? arg.$to_a() : arg;}).$flatten(); + + var result = []; + for (var i = 0, len = args.length; i < len; i++) { + if (!args[i].$$is_number) { + $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + ((args[i]).$class()) + " into Integer"); } - this.cleanup(); - }; - Tokenizer.prototype.finish = function () { - if (this.state === State.InNamedEntity) { - this.emitNamedEntity(); + result.push(self['$[]'](args[i])); + } + return result; + }, -1); + + $def(self, '$dig', function $$dig(key, $a) { + var $post_args, keys, self = this, item = nil; + + + $post_args = $slice(arguments, 1); + keys = $post_args; + item = ($truthy(key.$$is_string && self.$$data.hasOwnProperty(key)) ? (self.$$data[key] || nil) : nil); + + if (item === nil || keys.length === 0) { + return item; + } + if (!$truthy(item['$respond_to?']("dig"))) { + $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method"); + } return $send(item, 'dig', $to_a(keys)); + }, -2); + $alias(self, "size", "length"); + $alias(self, "to_s", "inspect"); + return $alias(self, "values", "to_a"); + })('::', null, $nesting); +}; + +Opal.modules["corelib/set"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $hash2 = Opal.hash2, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $send = Opal.send, $def = Opal.def, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('include,new,nil?,===,raise,each,add,merge,class,respond_to?,subtract,dup,join,to_a,equal?,instance_of?,==,instance_variable_get,size,is_a?,all?,include?,[]=,enum_for,[],<<,replace,compare_by_identity,name,compare_by_identity?,delete,select,frozen?,freeze,reject,delete_if,to_proc,keep_if,each_key,empty?,eql?,instance_eval,clear,<,<=,any?,!,intersect?,keys,|,proper_subset?,subset?,proper_superset?,superset?,-,select!,collect!'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Set'); + + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $ret_or_1 = nil, $proto = self.$$prototype; + + $proto.hash = nil; + + self.$include($$$('Enumerable')); + $defs(self, '$[]', function $Set_$$$1($a) { + var $post_args, ary, self = this; + + + $post_args = $slice(arguments); + ary = $post_args; + return self.$new(ary); + }, -1); + + $def(self, '$initialize', function $$initialize(enum$) { + var block = $$initialize.$$p || nil, self = this; + + $$initialize.$$p = null; + if (enum$ == null) enum$ = nil; + self.hash = $hash2([], {}); + if ($truthy(enum$['$nil?']())) { + return nil + } if (!$eqeqeq($$$('Enumerable'), enum$)) { + $Kernel.$raise($$$('ArgumentError'), "value must be enumerable"); + } if ($truthy(block)) { + return $send(enum$, 'each', [], function $$2(item){var self = $$2.$$s == null ? this : $$2.$$s; + + + if (item == null) item = nil; + return self.$add(Opal.yield1(block, item));}, {$$s: self}) + } else { + return self.$merge(enum$) + } }, -1); + + $def(self, '$dup', function $$dup() { + var self = this, result = nil; + + + result = self.$class().$new(); + return result.$merge(self); + }); + + $def(self, '$-', function $Set_$minus$3(enum$) { + var self = this; + + + if (!$truthy(enum$['$respond_to?']("each"))) { + $Kernel.$raise($$$('ArgumentError'), "value must be enumerable"); + } return self.$dup().$subtract(enum$); + }); + + $def(self, '$inspect', function $$inspect() { + var self = this; + + return "#<Set: {" + (self.$to_a().$join(",")) + "}>" + }); + + $def(self, '$==', function $Set_$eq_eq$4(other) { + var self = this; + + if ($truthy(self['$equal?'](other))) { + return true + } else if ($truthy(other['$instance_of?'](self.$class()))) { + return self.hash['$=='](other.$instance_variable_get("@hash")) + } else if (($truthy(other['$is_a?']($$$('Set'))) && ($eqeq(self.$size(), other.$size())))) { + return $send(other, 'all?', [], function $$5(o){var self = $$5.$$s == null ? this : $$5.$$s; + if (self.hash == null) self.hash = nil; + + + if (o == null) o = nil; + return self.hash['$include?'](o);}, {$$s: self}) + } else { + return false + } + }); + + $def(self, '$add', function $$add(o) { + var self = this; + + + self.hash['$[]='](o, true); + return self; + }); + + $def(self, '$classify', function $$classify() { + var block = $$classify.$$p || nil, self = this, result = nil; + + $$classify.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("classify") + } result = $send($$$('Hash'), 'new', [], function $$6(h, k){var $a, self = $$6.$$s == null ? this : $$6.$$s; + + + if (h == null) h = nil; + if (k == null) k = nil; + return ($a = [k, self.$class().$new()], $send(h, '[]=', $a), $a[$a.length - 1]);}, {$$s: self}); + $send(self, 'each', [], function $$7(item){ + + if (item == null) item = nil; + return result['$[]'](Opal.yield1(block, item)).$add(item);}); + return result; + }); + + $def(self, '$collect!', function $Set_collect$excl$8() { + var block = $Set_collect$excl$8.$$p || nil, self = this, result = nil; + + $Set_collect$excl$8.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("collect!") + } result = self.$class().$new(); + $send(self, 'each', [], function $$9(item){ + + if (item == null) item = nil; + return result['$<<'](Opal.yield1(block, item));}); + return self.$replace(result); + }); + + $def(self, '$compare_by_identity', function $$compare_by_identity() { + var self = this; + + if ($truthy(self.hash['$respond_to?']("compare_by_identity"))) { + + self.hash.$compare_by_identity(); + return self; + } else { + return self.$raise($$('NotImplementedError'), "" + (self.$class().$name()) + "#" + ("compare_by_identity") + " is not implemented") + } + }); + + $def(self, '$compare_by_identity?', function $Set_compare_by_identity$ques$10() { + var self = this, $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = self.hash['$respond_to?']("compare_by_identity?")))) { + return self.hash['$compare_by_identity?']() + } else { + return $ret_or_1 + } + }); + + $def(self, '$delete', function $Set_delete$11(o) { + var self = this; + + + self.hash.$delete(o); + return self; + }); + + $def(self, '$delete?', function $Set_delete$ques$12(o) { + var self = this; + + if ($truthy(self['$include?'](o))) { + + self.$delete(o); + return self; + } else { + return nil + } + }); + + $def(self, '$delete_if', function $$delete_if() { + var $yield = $$delete_if.$$p || nil, self = this; + + $$delete_if.$$p = null; + + if (!($yield !== nil)) { + return self.$enum_for("delete_if") + } $send($send(self, 'select', [], function $$13(o){ + + if (o == null) o = nil; + return Opal.yield1($yield, o);}), 'each', [], function $$14(o){var self = $$14.$$s == null ? this : $$14.$$s; + if (self.hash == null) self.hash = nil; + + + if (o == null) o = nil; + return self.hash.$delete(o);}, {$$s: self}); + return self; + }); + + $def(self, '$freeze', function $$freeze() { + var self = this; + + + if ($truthy(self['$frozen?']())) { + return self + } self.hash.$freeze(); + return $freeze(self); }); + + $def(self, '$keep_if', function $$keep_if() { + var $yield = $$keep_if.$$p || nil, self = this; + + $$keep_if.$$p = null; + + if (!($yield !== nil)) { + return self.$enum_for("keep_if") + } $send($send(self, 'reject', [], function $$15(o){ + + if (o == null) o = nil; + return Opal.yield1($yield, o);}), 'each', [], function $$16(o){var self = $$16.$$s == null ? this : $$16.$$s; + if (self.hash == null) self.hash = nil; + + + if (o == null) o = nil; + return self.hash.$delete(o);}, {$$s: self}); + return self; + }); + + $def(self, '$reject!', function $Set_reject$excl$17() { + var block = $Set_reject$excl$17.$$p || nil, self = this, before = nil; + + $Set_reject$excl$17.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("reject!") + } before = self.$size(); + $send(self, 'delete_if', [], block.$to_proc()); + if ($eqeq(self.$size(), before)) { + return nil + } else { + return self + } }); + + $def(self, '$select!', function $Set_select$excl$18() { + var block = $Set_select$excl$18.$$p || nil, self = this, before = nil; + + $Set_select$excl$18.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("select!") + } before = self.$size(); + $send(self, 'keep_if', [], block.$to_proc()); + if ($eqeq(self.$size(), before)) { + return nil + } else { + return self + } }); + + $def(self, '$add?', function $Set_add$ques$19(o) { + var self = this; + + if ($truthy(self['$include?'](o))) { + return nil + } else { + return self.$add(o) + } + }); + + $def(self, '$each', function $$each() { + var block = $$each.$$p || nil, self = this; + + $$each.$$p = null; + if (!(block !== nil)) { + return self.$enum_for("each") + } $send(self.hash, 'each_key', [], block.$to_proc()); + return self; + }); + + $def(self, '$empty?', function $Set_empty$ques$20() { + var self = this; + + return self.hash['$empty?']() + }); + + $def(self, '$eql?', function $Set_eql$ques$21(other) { + var self = this; + + return self.hash['$eql?']($send(other, 'instance_eval', [], function $$22(){var self = $$22.$$s == null ? this : $$22.$$s; + if (self.hash == null) self.hash = nil; + + return self.hash}, {$$s: self})) + }); + + $def(self, '$clear', function $$clear() { + var self = this; + + + self.hash.$clear(); + return self; + }); + + $def(self, '$include?', function $Set_include$ques$23(o) { + var self = this; + + return self.hash['$include?'](o) + }); + + $def(self, '$merge', function $$merge(enum$) { + var self = this; + + + $send(enum$, 'each', [], function $$24(item){var self = $$24.$$s == null ? this : $$24.$$s; + + + if (item == null) item = nil; + return self.$add(item);}, {$$s: self}); + return self; + }); + + $def(self, '$replace', function $$replace(enum$) { + var self = this; + + + self.$clear(); + self.$merge(enum$); + return self; + }); + + $def(self, '$size', function $$size() { + var self = this; + + return self.hash.$size() + }); + + $def(self, '$subtract', function $$subtract(enum$) { + var self = this; + + + $send(enum$, 'each', [], function $$25(item){var self = $$25.$$s == null ? this : $$25.$$s; + + + if (item == null) item = nil; + return self.$delete(item);}, {$$s: self}); + return self; + }); + + $def(self, '$|', function $Set_$$26(enum$) { + var self = this; + + + if (!$truthy(enum$['$respond_to?']("each"))) { + $Kernel.$raise($$$('ArgumentError'), "value must be enumerable"); + } return self.$dup().$merge(enum$); + }); + + function is_set(set) { + ($truthy(($ret_or_1 = (set)['$is_a?']($$$('Set')))) ? ($ret_or_1) : ($Kernel.$raise($$$('ArgumentError'), "value must be a set"))); + } + + $def(self, '$superset?', function $Set_superset$ques$27(set) { + var self = this; + + + is_set(set); + if ($truthy($rb_lt(self.$size(), set.$size()))) { + return false + } return $send(set, 'all?', [], function $$28(o){var self = $$28.$$s == null ? this : $$28.$$s; + + + if (o == null) o = nil; + return self['$include?'](o);}, {$$s: self}); + }); + + $def(self, '$proper_superset?', function $Set_proper_superset$ques$29(set) { + var self = this; + + + is_set(set); + if ($truthy($rb_le(self.$size(), set.$size()))) { + return false + } return $send(set, 'all?', [], function $$30(o){var self = $$30.$$s == null ? this : $$30.$$s; + + + if (o == null) o = nil; + return self['$include?'](o);}, {$$s: self}); + }); + + $def(self, '$subset?', function $Set_subset$ques$31(set) { + var self = this; + + + is_set(set); + if ($truthy($rb_lt(set.$size(), self.$size()))) { + return false + } return $send(self, 'all?', [], function $$32(o){ + + if (o == null) o = nil; + return set['$include?'](o);}); + }); + + $def(self, '$proper_subset?', function $Set_proper_subset$ques$33(set) { + var self = this; + + + is_set(set); + if ($truthy($rb_le(set.$size(), self.$size()))) { + return false + } return $send(self, 'all?', [], function $$34(o){ + + if (o == null) o = nil; + return set['$include?'](o);}); + }); + + $def(self, '$intersect?', function $Set_intersect$ques$35(set) { + var self = this; + + + is_set(set); + if ($truthy($rb_lt(self.$size(), set.$size()))) { + return $send(self, 'any?', [], function $$36(o){ + + if (o == null) o = nil; + return set['$include?'](o);}) + } else { + return $send(set, 'any?', [], function $$37(o){var self = $$37.$$s == null ? this : $$37.$$s; + + + if (o == null) o = nil; + return self['$include?'](o);}, {$$s: self}) + } }); + + $def(self, '$disjoint?', function $Set_disjoint$ques$38(set) { + var self = this; + + return self['$intersect?'](set)['$!']() + }); + + $def(self, '$to_a', function $$to_a() { + var self = this; + + return self.hash.$keys() + }); + $alias(self, "+", "|"); + $alias(self, "<", "proper_subset?"); + $alias(self, "<<", "add"); + $alias(self, "<=", "subset?"); + $alias(self, ">", "proper_superset?"); + $alias(self, ">=", "superset?"); + $alias(self, "difference", "-"); + $alias(self, "filter!", "select!"); + $alias(self, "length", "size"); + $alias(self, "map!", "collect!"); + $alias(self, "member?", "include?"); + return $alias(self, "union", "|"); + })('::', null, $nesting) +}; + +Opal.modules["corelib/dir"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('[],pwd'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Dir'); + + return (function(self, $parent_nesting) { + + + + $def(self, '$chdir', function $$chdir(dir) { + var $yield = $$chdir.$$p || nil, prev_cwd = nil; + + $$chdir.$$p = null; + return (function() { try { + + prev_cwd = Opal.current_dir; + Opal.current_dir = dir; + return Opal.yieldX($yield, []);; + } finally { + Opal.current_dir = prev_cwd; + } })() + }); + + $def(self, '$pwd', function $$pwd() { + + return Opal.current_dir || '.'; + }); + + $def(self, '$home', function $$home() { + var $ret_or_1 = nil; + + if ($truthy(($ret_or_1 = $$$('ENV')['$[]']("HOME")))) { + return $ret_or_1 + } else { + return "." } - // If there is remaining data, emit it in a reasonable way - if (this.sectionStart < this.index) { - this.handleTrailingData(); + }); + return $alias(self, "getwd", "pwd"); + })(Opal.get_singleton_class(self)) + })('::', null) +}; + +Opal.modules["corelib/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $klass = Opal.klass, $const_set = Opal.const_set, $Opal = Opal.Opal, $regexp = Opal.regexp, $rb_plus = Opal.rb_plus, $def = Opal.def, $Kernel = Opal.Kernel, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $range = Opal.range, $send = Opal.send, $slice = Opal.slice, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; + + Opal.add_stubs('respond_to?,to_path,coerce_to!,pwd,split,sub,+,unshift,join,home,raise,start_with?,absolute_path,==,<,dirname,-,basename,empty?,rindex,[],length,nil?,gsub,find,=~,map,each_with_index,flatten,reject,to_proc,end_with?,expand_path,exist?'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'File'); + + var $nesting = [self].concat($parent_nesting), windows_root_rx = nil; + + + $const_set($nesting[0], 'Separator', $const_set($nesting[0], 'SEPARATOR', "/")); + $const_set($nesting[0], 'ALT_SEPARATOR', nil); + $const_set($nesting[0], 'PATH_SEPARATOR', ":"); + $const_set($nesting[0], 'FNM_SYSCASE', 0); + windows_root_rx = /^[a-zA-Z]:(?:\\|\/)/; + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); + + + + $def(self, '$absolute_path', function $$absolute_path(path, basedir) { + var sep = nil, sep_chars = nil, new_parts = nil, $ret_or_1 = nil, path_abs = nil, basedir_abs = nil, parts = nil, leading_sep = nil, abs = nil, new_path = nil; + + + if (basedir == null) basedir = nil; + sep = $$('SEPARATOR'); + sep_chars = $sep_chars(); + new_parts = []; + path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path)); + path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); + basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$$('Dir').$pwd())); + path_abs = path.substr(0, sep.length) === sep || windows_root_rx.test(path); + basedir_abs = basedir.substr(0, sep.length) === sep || windows_root_rx.test(basedir); + if ($truthy(path_abs)) { + + parts = path.$split($regexp(["[", sep_chars, "]"])); + leading_sep = windows_root_rx.test(path) ? '' : path.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + abs = true; + } else { + + parts = $rb_plus(basedir.$split($regexp(["[", sep_chars, "]"])), path.$split($regexp(["[", sep_chars, "]"]))); + leading_sep = windows_root_rx.test(basedir) ? '' : basedir.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + abs = basedir_abs; + } + var part; + for (var i = 0, ii = parts.length; i < ii; i++) { + part = parts[i]; + + if ( + (part === nil) || + (part === '' && ((new_parts.length === 0) || abs)) || + (part === '.' && ((new_parts.length === 0) || abs)) + ) { + continue; + } + if (part === '..') { + new_parts.pop(); + } else { + new_parts.push(part); + } } - this.cbs.onend(); - }; - /** Handle any trailing data. */ - Tokenizer.prototype.handleTrailingData = function () { - var endIndex = this.buffer.length + this.offset; - if (this.state === State.InCommentLike) { - if (this.currentSequence === Sequences.CdataEnd) { - this.cbs.oncdata(this.sectionStart, endIndex, 0); - } - else { - this.cbs.oncomment(this.sectionStart, endIndex, 0); - } + + if (!abs && parts[0] !== '.') { + new_parts.$unshift("."); } - else if (this.state === State.InNumericEntity && - this.allowLegacyEntity()) { - this.emitNumericEntity(false); - // All trailing data will have been consumed + new_path = new_parts.$join(sep); + if ($truthy(abs)) { + new_path = $rb_plus(leading_sep, new_path); + } return new_path; + }, -2); + + $def(self, '$expand_path', function $$expand_path(path, basedir) { + var self = this, sep = nil, sep_chars = nil, home = nil, leading_sep = nil, home_path_regexp = nil; + + + if (basedir == null) basedir = nil; + sep = $$('SEPARATOR'); + sep_chars = $sep_chars(); + if ($truthy(path[0] === '~' || (basedir && basedir[0] === '~'))) { + + home = $$('Dir').$home(); + if (!$truthy(home)) { + $Kernel.$raise($$$('ArgumentError'), "couldn't find HOME environment -- expanding `~'"); + } leading_sep = windows_root_rx.test(home) ? '' : home.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + if (!$truthy(home['$start_with?'](leading_sep))) { + $Kernel.$raise($$$('ArgumentError'), "non-absolute home"); + } home = $rb_plus(home, sep); + home_path_regexp = $regexp(["^\\~(?:", sep, "|$)"]); + path = path.$sub(home_path_regexp, home); + if ($truthy(basedir)) { + basedir = basedir.$sub(home_path_regexp, home); + } } return self.$absolute_path(path, basedir); + }, -2); + + // Coerce a given path to a path string using #to_path and #to_str + function $coerce_to_path(path) { + if ($truthy((path)['$respond_to?']("to_path"))) { + path = path.$to_path(); } - else if (this.state === State.InHexEntity && - this.allowLegacyEntity()) { - this.emitNumericEntity(false); - // All trailing data will have been consumed + + path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); + + return path; + } + + // Return a RegExp compatible char class + function $sep_chars() { + if ($$('ALT_SEPARATOR') === nil) { + return Opal.escape_regexp($$('SEPARATOR')); + } else { + return Opal.escape_regexp($rb_plus($$('SEPARATOR'), $$('ALT_SEPARATOR'))); } - else if (this.state === State.InTagName || - this.state === State.BeforeAttributeName || - this.state === State.BeforeAttributeValue || - this.state === State.AfterAttributeName || - this.state === State.InAttributeName || - this.state === State.InAttributeValueSq || - this.state === State.InAttributeValueDq || - this.state === State.InAttributeValueNq || - this.state === State.InClosingTagName) { - /* - * If we are currently in an opening or closing tag, us not calling the - * respective callback signals that the tag should be ignored. - */ + } + + $def(self, '$dirname', function $$dirname(path, level) { + var self = this, sep_chars = nil; + + + if (level == null) level = 1; + if ($eqeq(level, 0)) { + return path + } if ($truthy($rb_lt(level, 0))) { + $Kernel.$raise($$$('ArgumentError'), "level can't be negative"); + } sep_chars = $sep_chars(); + path = $coerce_to_path(path); + + var absolute = path.match(new RegExp("^[" + (sep_chars) + "]")), out; + + path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove trailing separators + path = path.replace(new RegExp("[^" + (sep_chars) + "]+$"), ''); // remove trailing basename + path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove final trailing separators + + if (path === '') { + out = absolute ? '/' : '.'; } else { - this.cbs.ontext(this.sectionStart, endIndex); + out = path; } - }; - Tokenizer.prototype.emitPartial = function (start, endIndex) { - if (this.baseState !== State.Text && - this.baseState !== State.InSpecialTag) { - this.cbs.onattribdata(start, endIndex); + + if (level == 1) { + return out; } else { - this.cbs.ontext(start, endIndex); + return self.$dirname(out, $rb_minus(level, 1)) } - }; - Tokenizer.prototype.emitCodePoint = function (cp) { - if (this.baseState !== State.Text && - this.baseState !== State.InSpecialTag) { - this.cbs.onattribentity(cp); + }, -2); + + $def(self, '$basename', function $$basename(name, suffix) { + var sep_chars = nil; + + + if (suffix == null) suffix = nil; + sep_chars = $sep_chars(); + name = $coerce_to_path(name); + + if (name.length == 0) { + return name; } - else { - this.cbs.ontextentity(cp); + + if (suffix !== nil) { + suffix = $Opal['$coerce_to!'](suffix, $$$('String'), "to_str"); + } else { + suffix = null; } - }; - return Tokenizer; -}()); -exports["default"] = Tokenizer; -//# sourceMappingURL=Tokenizer.js.map -/***/ }), + name = name.replace(new RegExp("(.)[" + (sep_chars) + "]*$"), '$1'); + name = name.replace(new RegExp("^(?:.*[" + (sep_chars) + "])?([^" + (sep_chars) + "]+)$"), '$1'); -/***/ 2928: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + if (suffix === ".*") { + name = name.replace(/\.[^\.]+$/, ''); + } else if(suffix !== null) { + suffix = Opal.escape_regexp(suffix); + name = name.replace(new RegExp("" + (suffix) + "$"), ''); + } -"use strict"; + return name; + }, -2); + + $def(self, '$extname', function $$extname(path) { + var self = this, filename = nil, last_dot_idx = nil; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; + + path = $coerce_to_path(path); + filename = self.$basename(path); + if ($truthy(filename['$empty?']())) { + return "" + } last_dot_idx = filename['$[]']($range(1, -1, false)).$rindex("."); + if (($truthy(last_dot_idx['$nil?']()) || ($eqeq($rb_plus(last_dot_idx, 1), $rb_minus(filename.$length(), 1))))) { + return "" + } else { + return filename['$[]'](Opal.Range.$new($rb_plus(last_dot_idx, 1), -1, false)) + } }); + + $def(self, '$exist?', function $exist$ques$1(path) { + + return Opal.modules[path] != null + }); + + $def(self, '$directory?', function $directory$ques$2(path) { + var files = nil; + + + files = []; + + for (var key in Opal.modules) { + files.push(key); + } + path = path.$gsub($regexp(["(^.", $$('SEPARATOR'), "+|", $$('SEPARATOR'), "+$)"])); + return $send(files, 'find', [], function $$3(f){ + + if (f == null) f = nil; + return f['$=~']($regexp(["^", path]));}); + }); + + $def(self, '$join', function $$join($a) { + var $post_args, paths, result = nil; + + + $post_args = $slice(arguments); + paths = $post_args; + if ($truthy(paths['$empty?']())) { + return "" + } result = ""; + paths = $send(paths.$flatten().$each_with_index(), 'map', [], function $$4(item, index){ + + if (item == null) item = nil; + if (index == null) index = nil; + if (($eqeq(index, 0) && ($truthy(item['$empty?']())))) { + return $$('SEPARATOR') + } else if (($eqeq(paths.$length(), $rb_plus(index, 1)) && ($truthy(item['$empty?']())))) { + return $$('SEPARATOR') + } else { + return item + }}); + paths = $send(paths, 'reject', [], "empty?".$to_proc()); + $send(paths, 'each_with_index', [], function $$5(item, index){var next_item = nil; + + + if (item == null) item = nil; + if (index == null) index = nil; + next_item = paths['$[]']($rb_plus(index, 1)); + if ($truthy(next_item['$nil?']())) { + return (result = "" + (result) + (item)) + } else { + + if (($truthy(item['$end_with?']($$('SEPARATOR'))) && ($truthy(next_item['$start_with?']($$('SEPARATOR')))))) { + item = item.$sub($regexp([$$('SEPARATOR'), "+$"]), ""); + } return (result = (($truthy(item['$end_with?']($$('SEPARATOR'))) || ($truthy(next_item['$start_with?']($$('SEPARATOR'))))) ? ("" + (result) + (item)) : ("" + (result) + (item) + ($$('SEPARATOR'))))); + }}); + return result; + }, -1); + + $def(self, '$split', function $$split(path) { + + return path.$split($$('SEPARATOR')) + }); + $alias(self, "realpath", "expand_path"); + return $alias(self, "exists?", "exist?"); + })(Opal.get_singleton_class(self), $nesting); + })('::', $$$('IO'), $nesting) }; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DomUtils = exports.parseFeed = exports.getFeed = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DefaultHandler = exports.DomHandler = exports.Parser = void 0; -var Parser_js_1 = __nccwpck_require__(8460); -var Parser_js_2 = __nccwpck_require__(8460); -Object.defineProperty(exports, "Parser", ({ enumerable: true, get: function () { return Parser_js_2.Parser; } })); -var domhandler_1 = __nccwpck_require__(4038); -var domhandler_2 = __nccwpck_require__(4038); -Object.defineProperty(exports, "DomHandler", ({ enumerable: true, get: function () { return domhandler_2.DomHandler; } })); -// Old name for DomHandler -Object.defineProperty(exports, "DefaultHandler", ({ enumerable: true, get: function () { return domhandler_2.DomHandler; } })); -// Helper methods -/** - * Parses the data, returns the resulting document. - * - * @param data The data that should be parsed. - * @param options Optional options for the parser and DOM builder. - */ -function parseDocument(data, options) { - var handler = new domhandler_1.DomHandler(undefined, options); - new Parser_js_1.Parser(handler, options).end(data); - return handler.root; -} -exports.parseDocument = parseDocument; -/** - * Parses data, returns an array of the root nodes. - * - * Note that the root nodes still have a `Document` node as their parent. - * Use `parseDocument` to get the `Document` node instead. - * - * @param data The data that should be parsed. - * @param options Optional options for the parser and DOM builder. - * @deprecated Use `parseDocument` instead. - */ -function parseDOM(data, options) { - return parseDocument(data, options).children; -} -exports.parseDOM = parseDOM; -/** - * Creates a parser instance, with an attached DOM handler. - * - * @param callback A callback that will be called once parsing has been completed. - * @param options Optional options for the parser and DOM builder. - * @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM. - */ -function createDomStream(callback, options, elementCallback) { - var handler = new domhandler_1.DomHandler(callback, options, elementCallback); - return new Parser_js_1.Parser(handler, options); -} -exports.createDomStream = createDomStream; -var Tokenizer_js_1 = __nccwpck_require__(2689); -Object.defineProperty(exports, "Tokenizer", ({ enumerable: true, get: function () { return __importDefault(Tokenizer_js_1).default; } })); -/* - * All of the following exports exist for backwards-compatibility. - * They should probably be removed eventually. - */ -exports.ElementType = __importStar(__nccwpck_require__(3944)); -var domutils_1 = __nccwpck_require__(1754); -var domutils_2 = __nccwpck_require__(1754); -Object.defineProperty(exports, "getFeed", ({ enumerable: true, get: function () { return domutils_2.getFeed; } })); -var parseFeedDefaultOptions = { xmlMode: true }; -/** - * Parse a feed. - * - * @param feed The feed that should be parsed, as a string. - * @param options Optionally, options for parsing. When using this, you should set `xmlMode` to `true`. - */ -function parseFeed(feed, options) { - if (options === void 0) { options = parseFeedDefaultOptions; } - return (0, domutils_1.getFeed)(parseDOM(feed, options)); -} -exports.parseFeed = parseFeed; -exports.DomUtils = __importStar(__nccwpck_require__(1754)); -//# sourceMappingURL=index.js.map -/***/ }), +Opal.modules["corelib/process/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $return_val = Opal.return_val, nil = Opal.nil; -/***/ 2492: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + + (function($base, $super) { + var self = $klass($base, $super, 'Signal'); -var wrappy = __nccwpck_require__(2940) -var reqs = Object.create(null) -var once = __nccwpck_require__(1223) + + return $defs(self, '$trap', function $$trap($a) { -module.exports = wrappy(inflight) + + $slice(arguments); + return nil; + }, -1) + })('::', null); + return (function($base, $super) { + var self = $klass($base, $super, 'GC'); -function inflight (key, cb) { - if (reqs[key]) { - reqs[key].push(cb) - return null - } else { - reqs[key] = [cb] - return makeres(key) - } -} + + return $defs(self, '$start', $return_val(nil)) + })('::', null); +}; -function makeres (key) { - return once(function RES () { - var cbs = reqs[key] - var len = cbs.length - var args = slice(arguments) +Opal.modules["corelib/process"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $defs = Opal.defs, $truthy = Opal.truthy, $return_val = Opal.return_val, $Kernel = Opal.Kernel, nil = Opal.nil, $$$ = Opal.$$$; - // XXX It's somewhat ambiguous whether a new callback added in this - // pass should be queued for later execution if something in the - // list of callbacks throws, or if it should just be discarded. - // However, it's such an edge case that it hardly matters, and either - // choice is likely as surprising as the other. - // As it happens, we do go ahead and schedule it for later execution. - try { - for (var i = 0; i < len; i++) { - cbs[i].apply(null, args) - } - } finally { - if (cbs.length > len) { - // added more in the interim. - // de-zalgo, just in case, but don't call again. - cbs.splice(0, len) - process.nextTick(function () { - RES.apply(null, args) - }) - } else { - delete reqs[key] - } + Opal.add_stubs('const_set,size,<<,__register_clock__,to_f,now,new,[],raise'); + return (function($base) { + var self = $module($base, 'Process'); + + var monotonic = nil; + + + self.__clocks__ = []; + $defs(self, '$__register_clock__', function $$__register_clock__(name, func) { + var self = this; + if (self.__clocks__ == null) self.__clocks__ = nil; + + + self.$const_set(name, self.__clocks__.$size()); + return self.__clocks__['$<<'](func); + }); + self.$__register_clock__("CLOCK_REALTIME", function() { return Date.now() }); + monotonic = false; + + if (Opal.global.performance) { + monotonic = function() { + return performance.now() + }; } - }) -} + else if (Opal.global.process && process.hrtime) { + // let now be the base to get smaller numbers + var hrtime_base = process.hrtime(); -function slice (args) { - var length = args.length - var array = [] + monotonic = function() { + var hrtime = process.hrtime(hrtime_base); + var us = (hrtime[1] / 1000) | 0; // cut below microsecs; + return ((hrtime[0] * 1000) + (us / 1000)); + }; + } + if ($truthy(monotonic)) { + self.$__register_clock__("CLOCK_MONOTONIC", monotonic); + } $defs(self, '$pid', $return_val(0)); + $defs(self, '$times', function $$times() { + var t = nil; - for (var i = 0; i < length; i++) array[i] = args[i] - return array -} + + t = $$$('Time').$now().$to_f(); + return $$$($$$('Benchmark'), 'Tms').$new(t, t, t, t, t); + }); + return $defs(self, '$clock_gettime', function $$clock_gettime(clock_id, unit) { + var self = this, clock = nil; + if (self.__clocks__ == null) self.__clocks__ = nil; + + if (unit == null) unit = "float_second"; + if ($truthy(((clock = self.__clocks__['$[]'](clock_id))))) ; else { + $Kernel.$raise($$$($$$('Errno'), 'EINVAL'), "clock_gettime(" + (clock_id) + ") " + (self.__clocks__['$[]'](clock_id))); + } + var ms = clock(); + switch (unit) { + case 'float_second': return (ms / 1000); // number of seconds as a float (default) + case 'float_millisecond': return (ms / 1); // number of milliseconds as a float + case 'float_microsecond': return (ms * 1000); // number of microseconds as a float + case 'second': return ((ms / 1000) | 0); // number of seconds as an integer + case 'millisecond': return ((ms / 1) | 0); // number of milliseconds as an integer + case 'microsecond': return ((ms * 1000) | 0); // number of microseconds as an integer + case 'nanosecond': return ((ms * 1000000) | 0); // number of nanoseconds as an integer + default: $Kernel.$raise($$$('ArgumentError'), "unexpected unit: " + (unit)); + } + }, -2); + })('::') +}; -/***/ }), +Opal.modules["corelib/random/formatter"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $module = Opal.module, $def = Opal.def, $range = Opal.range, $send = Opal.send, $rb_divide = Opal.rb_divide, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/***/ 4124: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + Opal.add_stubs('_verify_count,bytes,encode,strict_encode64,random_bytes,urlsafe_encode64,split,hex,[]=,[],map,to_proc,join,times,<<,|,ord,/,abs,random_float,raise,coerce_to!,flatten,new,random_number,length,include,extend'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Random'); -try { - var util = __nccwpck_require__(3837); - /* istanbul ignore next */ - if (typeof util.inherits !== 'function') throw ''; - module.exports = util.inherits; -} catch (e) { - /* istanbul ignore next */ - module.exports = __nccwpck_require__(8544); -} + var $nesting = [self].concat($parent_nesting); + + (function($base, $parent_nesting) { + var self = $module($base, 'Formatter'); -/***/ }), + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -/***/ 8544: -/***/ ((module) => { + + + $def(self, '$hex', function $$hex(count) { + var self = this; -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true + + if (count == null) count = nil; + count = $$$('Random').$_verify_count(count); + + var bytes = self.$bytes(count); + var out = ""; + for (var i = 0; i < count; i++) { + out += bytes.charCodeAt(i).toString(16).padStart(2, '0'); } - }) - } - }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } - } -} + return (out).$encode("US-ASCII"); + }, -1); + + $def(self, '$random_bytes', function $$random_bytes(count) { + var self = this; + + + if (count == null) count = nil; + return self.$bytes(count); + }, -1); + + $def(self, '$base64', function $$base64(count) { + var self = this; + + if (count == null) count = nil; + return $$$('Base64').$strict_encode64(self.$random_bytes(count)).$encode("US-ASCII"); + }, -1); + + $def(self, '$urlsafe_base64', function $$urlsafe_base64(count, padding) { + var self = this; -/***/ }), + + if (count == null) count = nil; + if (padding == null) padding = false; + return $$$('Base64').$urlsafe_encode64(self.$random_bytes(count), padding).$encode("US-ASCII"); + }, -1); + + $def(self, '$uuid', function $$uuid() { + var self = this, str = nil; -/***/ 3973: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + + str = self.$hex(16).$split(""); + str['$[]='](12, "4"); + str['$[]='](16, (parseInt(str['$[]'](16), 16) & 3 | 8).toString(16)); + str = [str['$[]']($range(0, 8, true)), str['$[]']($range(8, 12, true)), str['$[]']($range(12, 16, true)), str['$[]']($range(16, 20, true)), str['$[]']($range(20, 32, true))]; + str = $send(str, 'map', [], "join".$to_proc()); + return str.$join("-"); + }); + + $def(self, '$random_float', function $$random_float() { + var self = this, bs = nil, num = nil; -module.exports = minimatch -minimatch.Minimatch = Minimatch + + bs = self.$bytes(4); + num = 0; + $send((4), 'times', [], function $$1(i){ + + if (i == null) i = nil; + num = num['$<<'](8); + return (num = num['$|'](bs['$[]'](i).$ord()));}); + return $rb_divide(num.$abs(), 2147483647); + }); + + $def(self, '$random_number', function $$random_number(limit) { + var self = this; + + function randomFloat() { + return self.$random_float(); + } -var path = (function () { try { return __nccwpck_require__(1017) } catch (e) {}}()) || { - sep: '/' -} -minimatch.sep = path.sep + function randomInt(max) { + return Math.floor(randomFloat() * max); + } -var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {} -var expand = __nccwpck_require__(3717) + function randomRange() { + var min = limit.begin, + max = limit.end; -var plTypes = { - '!': { open: '(?:(?!(?:', close: '))[^/]*?)'}, - '?': { open: '(?:', close: ')?' }, - '+': { open: '(?:', close: ')+' }, - '*': { open: '(?:', close: ')*' }, - '@': { open: '(?:', close: ')' } -} + if (min === nil || max === nil) { + return nil; + } -// any single thing other than / -// don't need to escape / when using new RegExp() -var qmark = '[^/]' + var length = max - min; -// * => any number of characters -var star = qmark + '*?' + if (length < 0) { + return nil; + } -// ** when dots are allowed. Anything goes, except .. and . -// not (^ or / followed by one or two dots followed by $ or /), -// followed by anything, any number of times. -var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?' + if (length === 0) { + return min; + } -// not a ^ or / followed by a dot, -// followed by anything, any number of times. -var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?' + if (max % 1 === 0 && min % 1 === 0 && !limit.excl) { + length++; + } -// characters that need to be escaped in RegExp. -var reSpecials = charSet('().*{}+?[]^$\\!') + return randomInt(length) + min; + } -// "abc" -> { a:true, b:true, c:true } -function charSet (s) { - return s.split('').reduce(function (set, c) { - set[c] = true - return set - }, {}) -} + if (limit == null) { + return randomFloat(); + } else if (limit.$$is_range) { + return randomRange(); + } else if (limit.$$is_number) { + if (limit <= 0) { + $Kernel.$raise($$$('ArgumentError'), "invalid argument - " + (limit)); + } -// normalizes slashes. -var slashSplit = /\/+/ + if (limit % 1 === 0) { + // integer + return randomInt(limit); + } else { + return randomFloat() * limit; + } + } else { + limit = $Opal['$coerce_to!'](limit, $$$('Integer'), "to_int"); -minimatch.filter = filter -function filter (pattern, options) { - options = options || {} - return function (p, i, list) { - return minimatch(p, pattern, options) - } -} + if (limit <= 0) { + $Kernel.$raise($$$('ArgumentError'), "invalid argument - " + (limit)); + } -function ext (a, b) { - b = b || {} - var t = {} - Object.keys(a).forEach(function (k) { - t[k] = a[k] - }) - Object.keys(b).forEach(function (k) { - t[k] = b[k] - }) - return t -} + return randomInt(limit); + } + }, -1); + return $def(self, '$alphanumeric', function $$alphanumeric(count) { + var self = this, map = nil; -minimatch.defaults = function (def) { - if (!def || typeof def !== 'object' || !Object.keys(def).length) { - return minimatch - } + + if (count == null) count = nil; + count = $$('Random').$_verify_count(count); + map = $send([$range("0", "9", false), $range("a", "z", false), $range("A", "Z", false)], 'map', [], "to_a".$to_proc()).$flatten(); + return $send($$$('Array'), 'new', [count], function $$2(i){var self = $$2.$$s == null ? this : $$2.$$s; + return map['$[]'](self.$random_number(map.$length()));}, {$$s: self}).$join(); + }, -1); + })(self, $nesting); + self.$include($$$($$$('Random'), 'Formatter')); + return self.$extend($$$($$$('Random'), 'Formatter')); + })('::', null, $nesting) +}; - var orig = minimatch +Opal.modules["corelib/random/mersenne_twister"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, nil = Opal.nil, $$$ = Opal.$$$, mersenne_twister = nil; - var m = function minimatch (p, pattern, options) { - return orig(p, pattern, ext(def, options)) - } + Opal.add_stubs('generator='); + + mersenne_twister = (function() { + /* Period parameters */ + var N = 624; + var M = 397; + var MATRIX_A = 0x9908b0df; /* constant vector a */ + var UMASK = 0x80000000; /* most significant w-r bits */ + var LMASK = 0x7fffffff; /* least significant r bits */ + var MIXBITS = function(u,v) { return ( ((u) & UMASK) | ((v) & LMASK) ); }; + var TWIST = function(u,v) { return (MIXBITS((u),(v)) >>> 1) ^ ((v & 0x1) ? MATRIX_A : 0x0); }; - m.Minimatch = function Minimatch (pattern, options) { - return new orig.Minimatch(pattern, ext(def, options)) - } - m.Minimatch.defaults = function defaults (options) { - return orig.defaults(ext(def, options)).Minimatch + function init(s) { + var mt = {left: 0, next: N, state: new Array(N)}; + init_genrand(mt, s); + return mt; } - m.filter = function filter (pattern, options) { - return orig.filter(pattern, ext(def, options)) + /* initializes mt[N] with a seed */ + function init_genrand(mt, s) { + var j; + mt.state[0] = s >>> 0; + for (j=1; j<N; j++) { + mt.state[j] = (1812433253 * ((mt.state[j-1] ^ (mt.state[j-1] >> 30) >>> 0)) + j); + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array state[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + mt.state[j] &= 0xffffffff; /* for >32 bit machines */ + } + mt.left = 1; + mt.next = N; } - m.defaults = function defaults (options) { - return orig.defaults(ext(def, options)) + /* generate N words at one time */ + function next_state(mt) { + var p = 0, _p = mt.state; + var j; + + mt.left = N; + mt.next = 0; + + for (j=N-M+1; --j; p++) + _p[p] = _p[p+(M)] ^ TWIST(_p[p+(0)], _p[p+(1)]); + + for (j=M; --j; p++) + _p[p] = _p[p+(M-N)] ^ TWIST(_p[p+(0)], _p[p+(1)]); + + _p[p] = _p[p+(M-N)] ^ TWIST(_p[p+(0)], _p[0]); } - m.makeRe = function makeRe (pattern, options) { - return orig.makeRe(pattern, ext(def, options)) + /* generates a random number on [0,0xffffffff]-interval */ + function genrand_int32(mt) { + /* mt must be initialized */ + var y; + + if (--mt.left <= 0) next_state(mt); + y = mt.state[mt.next++]; + + /* Tempering */ + y ^= (y >>> 11); + y ^= (y << 7) & 0x9d2c5680; + y ^= (y << 15) & 0xefc60000; + y ^= (y >>> 18); + + return y >>> 0; } - m.braceExpand = function braceExpand (pattern, options) { - return orig.braceExpand(pattern, ext(def, options)) + function int_pair_to_real_exclusive(a, b) { + a >>>= 5; + b >>>= 6; + return (a*67108864.0+b)*(1.0/9007199254740992.0); } - m.match = function (list, pattern, options) { - return orig.match(list, pattern, ext(def, options)) + // generates a random number on [0,1) with 53-bit resolution + function genrand_real(mt) { + /* mt must be initialized */ + var a = genrand_int32(mt), b = genrand_int32(mt); + return int_pair_to_real_exclusive(a, b); } - return m -} + return { genrand_real: genrand_real, init: init }; +})(); + return (function($base, $super) { + var self = $klass($base, $super, 'Random'); -Minimatch.defaults = function (def) { - return minimatch.defaults(def).Minimatch -} + var $a; -function minimatch (p, pattern, options) { - assertValidPattern(pattern) + + var MAX_INT = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + $const_set(self, 'MERSENNE_TWISTER_GENERATOR', { + new_seed: function() { return Math.round(Math.random() * MAX_INT); }, + reseed: function(seed) { return mersenne_twister.init(seed); }, + rand: function(mt) { return mersenne_twister.genrand_real(mt); } + }); + return ($a = [$$$(self, 'MERSENNE_TWISTER_GENERATOR')], $send(self, 'generator=', $a), $a[$a.length - 1]); + })('::', null); +}; - if (!options) options = {} +Opal.modules["corelib/random"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $klass = Opal.klass, $Kernel = Opal.Kernel, $defs = Opal.defs, $Opal = Opal.Opal, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $send = Opal.send, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$; - // shortcut: comments match nothing. - if (!options.nocomment && pattern.charAt(0) === '#') { - return false - } + Opal.add_stubs('require,attr_reader,to_int,raise,new_seed,coerce_to!,reseed,rand,seed,bytes,===,==,state,_verify_count,encode,join,new,chr,random_number,random_float,const_defined?,const_set'); + + self.$require("corelib/random/formatter"); + (function($base, $super) { + var self = $klass($base, $super, 'Random'); - return new Minimatch(pattern, options).match(p) -} + + + self.$attr_reader("seed", "state"); + $defs(self, '$_verify_count', function $$_verify_count(count) { + + + if (!$truthy(count)) count = 16; + if (typeof count !== "number") count = (count).$to_int(); + if (count < 0) $Kernel.$raise($$$('ArgumentError'), "negative string size (or size too big)"); + count = Math.floor(count); + return count; + + }); + + $def(self, '$initialize', function $$initialize(seed) { + var self = this; -function Minimatch (pattern, options) { - if (!(this instanceof Minimatch)) { - return new Minimatch(pattern, options) - } + + if (seed == null) seed = $$$('Random').$new_seed(); + seed = $Opal['$coerce_to!'](seed, $$$('Integer'), "to_int"); + self.state = seed; + return self.$reseed(seed); + }, -1); + + $def(self, '$reseed', function $$reseed(seed) { + var self = this; - assertValidPattern(pattern) + + self.seed = seed; + return self.$rng = Opal.$$rand.reseed(seed); }); + $defs(self, '$new_seed', function $$new_seed() { + + return Opal.$$rand.new_seed(); + }); + $defs(self, '$rand', function $$rand(limit) { + var self = this; + return $$$(self, 'DEFAULT').$rand(limit); + }, -1); + $defs(self, '$srand', function $$srand(n) { + var self = this, previous_seed = nil; - if (!options) options = {} + + if (n == null) n = $$$('Random').$new_seed(); + n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int"); + previous_seed = $$$(self, 'DEFAULT').$seed(); + $$$(self, 'DEFAULT').$reseed(n); + return previous_seed; + }, -1); + $defs(self, '$urandom', function $$urandom(size) { + + return $$$('SecureRandom').$bytes(size) + }); + + $def(self, '$==', function $Random_$eq_eq$1(other) { + var self = this, $ret_or_1 = nil; - pattern = pattern.trim() + + if (!$eqeqeq($$$('Random'), other)) { + return false + } if ($truthy(($ret_or_1 = self.$seed()['$=='](other.$seed())))) { + return self.$state()['$=='](other.$state()) + } else { + return $ret_or_1 + } }); + + $def(self, '$bytes', function $$bytes(length) { + var self = this; - // windows support: need to use /, not \ - if (!options.allowWindowsEscape && path.sep !== '/') { - pattern = pattern.split(path.sep).join('/') - } + + length = $$$('Random').$_verify_count(length); + return $send($$$('Array'), 'new', [length], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s; - this.options = options - this.set = [] - this.pattern = pattern - this.regexp = null - this.negate = false - this.comment = false - this.empty = false - this.partial = !!options.partial + return self.$rand(255).$chr()}, {$$s: self}).$join().$encode("ASCII-8BIT"); + }); + $defs(self, '$bytes', function $$bytes(length) { + var self = this; - // make the set of regexps etc. - this.make() -} + return $$$(self, 'DEFAULT').$bytes(length) + }); + + $def(self, '$rand', function $$rand(limit) { + var self = this; + return self.$random_number(limit); + }, -1); + + $def(self, '$random_float', function $$random_float() { + var self = this; + + + self.state++; + return Opal.$$rand.rand(self.$rng); + + }); + $defs(self, '$random_float', function $$random_float() { + var self = this; -Minimatch.prototype.debug = function () {} + return $$$(self, 'DEFAULT').$random_float() + }); + return $defs(self, '$generator=', function $Random_generator$eq$3(generator) { + var self = this; + + + Opal.$$rand = generator; + if ($truthy(self['$const_defined?']("DEFAULT"))) { + return $$$(self, 'DEFAULT').$reseed() + } else { + return self.$const_set("DEFAULT", self.$new(self.$new_seed())) + } }); + })('::', null); + return self.$require("corelib/random/mersenne_twister"); +}; -Minimatch.prototype.make = make -function make () { - var pattern = this.pattern - var options = this.options +Opal.modules["corelib/unsupported"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $Kernel = Opal.Kernel, $klass = Opal.klass, $send = Opal.send, $slice = Opal.slice, $module = Opal.module, $def = Opal.def, $return_val = Opal.return_val, $alias = Opal.alias, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // empty patterns and comments match nothing. - if (!options.nocomment && pattern.charAt(0) === '#') { - this.comment = true - return + Opal.add_stubs('raise,warn,each,define_method,%,public,private_method_defined?,private_class_method,instance_method,instance_methods,method_defined?,private_methods'); + + + var warnings = {}; + + function handle_unsupported_feature(message) { + switch (Opal.config.unsupported_features_severity) { + case 'error': + $Kernel.$raise($$$('NotImplementedError'), message); + break; + case 'warning': + warn(message); + break; + // noop + } } - if (!pattern) { - this.empty = true - return + + function warn(string) { + if (warnings[string]) { + return; + } + + warnings[string] = true; + self.$warn(string); } + (function($base, $super) { + var self = $klass($base, $super, 'String'); - // step 1: figure out negation, etc. - this.parseNegate() + + + var ERROR = "String#%s not supported. Mutable String methods are not supported in Opal."; + return $send(["<<", "capitalize!", "chomp!", "chop!", "downcase!", "gsub!", "lstrip!", "next!", "reverse!", "slice!", "squeeze!", "strip!", "sub!", "succ!", "swapcase!", "tr!", "tr_s!", "upcase!", "prepend", "[]=", "clear", "encode!", "unicode_normalize!"], 'each', [], function $String$1(method_name){var self = $String$1.$$s == null ? this : $String$1.$$s; - // step 2: expand braces - var set = this.globSet = this.braceExpand() + + if (method_name == null) method_name = nil; + return $send(self, 'define_method', [method_name], function $$2($a){ + + $slice(arguments); + return $Kernel.$raise($$$('NotImplementedError'), (ERROR)['$%'](method_name));}, -1);}, {$$s: self}); + })('::', null); + (function($base) { + var self = $module($base, 'Kernel'); - if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) } + + + var ERROR = "Object tainting is not supported by Opal"; + + $def(self, '$taint', function $$taint() { + var self = this; - this.debug(this.pattern, set) + + handle_unsupported_feature(ERROR); + return self; + }); + + $def(self, '$untaint', function $$untaint() { + var self = this; - // step 3: now we have a set, so turn each one into a series of path-portion - // matching patterns. - // These will be regexps, except in the case of "**", which is - // set to the GLOBSTAR object for globstar behavior, - // and will not contain any / characters - set = this.globParts = set.map(function (s) { - return s.split(slashSplit) - }) + + handle_unsupported_feature(ERROR); + return self; + }); + return $def(self, '$tainted?', function $Kernel_tainted$ques$3() { + + + handle_unsupported_feature(ERROR); + return false; + }); + })('::'); + (function($base, $super) { + var self = $klass($base, $super, 'Module'); - this.debug(this.pattern, set) + + + + $def(self, '$public', function $Module_public$4($a) { + var $post_args, methods, self = this; - // glob --> regexps - set = set.map(function (s, si, set) { - return s.map(this.parse, this) - }, this) + + $post_args = $slice(arguments); + methods = $post_args; + + if (methods.length === 0) { + self.$$module_function = false; + return nil; + } + return (methods.length === 1) ? methods[0] : methods; + }, -1); + + $def(self, '$private_class_method', function $$private_class_method($a) { + var $post_args, methods; - this.debug(this.pattern, set) + + $post_args = $slice(arguments); + methods = $post_args; + return (methods.length === 1) ? methods[0] : methods; }, -1); + + $def(self, '$private_method_defined?', $return_val(false)); + + $def(self, '$private_constant', function $$private_constant($a) { - // filter out everything that didn't compile properly. - set = set.filter(function (s) { - return s.indexOf(false) === -1 - }) + + $slice(arguments); + return nil; + }, -1); + $alias(self, "nesting", "public"); + $alias(self, "private", "public"); + $alias(self, "protected", "public"); + $alias(self, "protected_method_defined?", "private_method_defined?"); + $alias(self, "public_class_method", "private_class_method"); + $alias(self, "public_instance_method", "instance_method"); + $alias(self, "public_instance_methods", "instance_methods"); + return $alias(self, "public_method_defined?", "method_defined?"); + })('::', null); + (function($base) { + var self = $module($base, 'Kernel'); - this.debug(this.pattern, set) + + + + $def(self, '$private_methods', function $$private_methods($a) { - this.set = set -} + + $slice(arguments); + return []; + }, -1); + $alias(self, "protected_methods", "private_methods"); + $alias(self, "private_instance_methods", "private_methods"); + return $alias(self, "protected_instance_methods", "private_methods"); + })('::'); + (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); -Minimatch.prototype.parseNegate = parseNegate -function parseNegate () { - var pattern = this.pattern - var negate = false - var options = this.options - var negateOffset = 0 + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - if (options.nonegate) return + return $def(self, '$eval', function $Kernel_eval$5($a) { - for (var i = 0, l = pattern.length - ; i < l && pattern.charAt(i) === '!' - ; i++) { - negate = !negate - negateOffset++ - } + + $slice(arguments); + return $Kernel.$raise($$$('NotImplementedError'), "To use Kernel#eval, you must first require 'opal-parser'. " + ("See https://github.com/opal/opal/blob/" + ($$('RUBY_ENGINE_VERSION')) + "/docs/opal_parser.md for details.")); + }, -1) + })('::', $nesting); + $defs(self, '$public', function $public$6($a) { + var $post_args, methods; - if (negateOffset) this.pattern = pattern.substr(negateOffset) - this.negate = negate -} + + $post_args = $slice(arguments); + methods = $post_args; + return (methods.length === 1) ? methods[0] : methods; }, -1); + return $defs(self, '$private', function $private$7($a) { + var $post_args, methods; -// Brace expansion: -// a{b,c}d -> abd acd -// a{b,}c -> abc ac -// a{0..3}d -> a0d a1d a2d a3d -// a{b,c{d,e}f}g -> abg acdfg acefg -// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg -// -// Invalid sets are not expanded. -// a{2..}b -> a{2..}b -// a{b}c -> a{b}c -minimatch.braceExpand = function (pattern, options) { - return braceExpand(pattern, options) -} + + $post_args = $slice(arguments); + methods = $post_args; + return (methods.length === 1) ? methods[0] : methods; }, -1); +}; -Minimatch.prototype.braceExpand = braceExpand +Opal.queue(function(Opal) {/* Generated by Opal 1.7.3 */ + var $Object = Opal.Object; Opal.nil; -function braceExpand (pattern, options) { - if (!options) { - if (this instanceof Minimatch) { - options = this.options - } else { - options = {} - } - } + Opal.add_stubs('require,autoload'); + + $Object.$require("opal/base"); + $Object.$require("opal/mini"); + $Object.$require("corelib/kernel/format"); + $Object.$require("corelib/string/encoding"); + $Object.$autoload("Math", "corelib/math"); + $Object.$require("corelib/complex/base"); + $Object.$autoload("Complex", "corelib/complex"); + $Object.$require("corelib/rational/base"); + $Object.$autoload("Rational", "corelib/rational"); + $Object.$require("corelib/time"); + $Object.$autoload("Struct", "corelib/struct"); + $Object.$autoload("Set", "corelib/set"); + $Object.$autoload("Dir", "corelib/dir"); + $Object.$autoload("File", "corelib/file"); + $Object.$require("corelib/process/base"); + $Object.$autoload("Process", "corelib/process"); + $Object.$autoload("Random", "corelib/random"); + return $Object.$require("corelib/unsupported"); +}); - pattern = typeof pattern === 'undefined' - ? this.pattern : pattern - assertValidPattern(pattern) +var Opal$1 = Opal; - // Thanks to Yeting Li <https://github.com/yetingli> for - // improving this regexp to avoid a ReDOS vulnerability. - if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { - // shortcut. no need to expand. - return [pattern] - } +Opal.modules["nodejs/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $const_set = Opal.const_set, $eqeq = Opal.eqeq, $lambda = Opal.lambda, $send = Opal.send, $a, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; - return expand(pattern) -} + Opal.add_stubs('==,first,shift,write_proc=,read_proc=,tty='); + + (function($base, $parent_nesting) { + var self = $module($base, 'NodeJS'); -var MAX_PATTERN_LENGTH = 1024 * 64 -var assertValidPattern = function (pattern) { - if (typeof pattern !== 'string') { - throw new TypeError('invalid pattern') - } + var $nesting = [self].concat($parent_nesting); - if (pattern.length > MAX_PATTERN_LENGTH) { - throw new TypeError('pattern is too long') + return $const_set($nesting[0], 'VERSION', process.version) + })($nesting[0], $nesting); + Opal.exit = process.exit; + $const_set($nesting[0], 'ARGV', process.argv.slice(2)); + if ($eqeq($$('ARGV').$first(), "--")) { + $$('ARGV').$shift(); + } $$('STDOUT')['$write_proc=']($lambda(function $$1(string){ + + if (string == null) string = nil; + return process.stdout.write(string);})); + $$('STDERR')['$write_proc=']($lambda(function $$2(string){ + + if (string == null) string = nil; + return process.stderr.write(string);})); + $$('STDIN')['$read_proc='](function(_count) { + // Ignore count, return as much as we can get + var buf = Buffer.alloc(65536), count; + try { + count = __fs__.readSync(this.fd, buf, 0, 65536, null); } -} + catch (e) { // Windows systems may raise EOF + return nil; + } + if (count == 0) return nil; + return buf.toString('utf8', 0, count); +}); + $$('STDIN')['$tty='](true); + $$('STDOUT')['$tty='](true); + return ($a = [true], $send($$('STDERR'), 'tty=', $a), $a[$a.length - 1]); +}; -// parse a component of the expanded set. -// At this point, no pattern may contain "/" in it -// so we're going to return a 2d array, where each entry is the full -// pattern, split on '/', and then turned into a regular expression. -// A regexp is made at the end which joins each array with an -// escaped /, and another full one which joins each regexp with |. -// -// Following the lead of Bash 4.1, note that "**" only has special meaning -// when it is the *only* thing in a path portion. Otherwise, any series -// of * is equivalent to a single *. Globstar behavior is enabled by -// default, and can be disabled by setting options.noglobstar. -Minimatch.prototype.parse = parse -var SUBPARSE = {} -function parse (pattern, isSub) { - assertValidPattern(pattern) +Opal.modules["corelib/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $klass = Opal.klass, $const_set = Opal.const_set, $Opal = Opal.Opal, $regexp = Opal.regexp, $rb_plus = Opal.rb_plus, $def = Opal.def, $Kernel = Opal.Kernel, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $range = Opal.range, $send = Opal.send, $slice = Opal.slice, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - var options = this.options + Opal.add_stubs('respond_to?,to_path,coerce_to!,pwd,split,sub,+,unshift,join,home,raise,start_with?,absolute_path,==,<,dirname,-,basename,empty?,rindex,[],length,nil?,gsub,find,=~,map,each_with_index,flatten,reject,to_proc,end_with?,expand_path,exist?'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'File'); - // shortcuts - if (pattern === '**') { - if (!options.noglobstar) - return GLOBSTAR - else - pattern = '*' - } - if (pattern === '') return '' - - var re = '' - var hasMagic = !!options.nocase - var escaping = false - // ? => one single character - var patternListStack = [] - var negativeLists = [] - var stateChar - var inClass = false - var reClassStart = -1 - var classStart = -1 - // . and .. never match anything that doesn't start with ., - // even when options.dot is set. - var patternStart = pattern.charAt(0) === '.' ? '' // anything - // not (start or / followed by . or .. followed by / or end) - : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' - : '(?!\\.)' - var self = this + var $nesting = [self].concat($parent_nesting), windows_root_rx = nil; - function clearStateChar () { - if (stateChar) { - // we had some state-tracking character - // that wasn't consumed by this pass. - switch (stateChar) { - case '*': - re += star - hasMagic = true - break - case '?': - re += qmark - hasMagic = true - break - default: - re += '\\' + stateChar - break - } - self.debug('clearStateChar %j %j', stateChar, re) - stateChar = false - } - } + + $const_set($nesting[0], 'Separator', $const_set($nesting[0], 'SEPARATOR', "/")); + $const_set($nesting[0], 'ALT_SEPARATOR', nil); + $const_set($nesting[0], 'PATH_SEPARATOR', ":"); + $const_set($nesting[0], 'FNM_SYSCASE', 0); + windows_root_rx = /^[a-zA-Z]:(?:\\|\/)/; + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - for (var i = 0, len = pattern.length, c - ; (i < len) && (c = pattern.charAt(i)) - ; i++) { - this.debug('%s\t%s %s %j', pattern, i, re, c) + + + $def(self, '$absolute_path', function $$absolute_path(path, basedir) { + var sep = nil, sep_chars = nil, new_parts = nil, $ret_or_1 = nil, path_abs = nil, basedir_abs = nil, parts = nil, leading_sep = nil, abs = nil, new_path = nil; - // skip over any that are escaped. - if (escaping && reSpecials[c]) { - re += '\\' + c - escaping = false - continue - } + + if (basedir == null) basedir = nil; + sep = $$('SEPARATOR'); + sep_chars = $sep_chars(); + new_parts = []; + path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path)); + path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); + basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$$('Dir').$pwd())); + path_abs = path.substr(0, sep.length) === sep || windows_root_rx.test(path); + basedir_abs = basedir.substr(0, sep.length) === sep || windows_root_rx.test(basedir); + if ($truthy(path_abs)) { + + parts = path.$split($regexp(["[", sep_chars, "]"])); + leading_sep = windows_root_rx.test(path) ? '' : path.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + abs = true; + } else { + + parts = $rb_plus(basedir.$split($regexp(["[", sep_chars, "]"])), path.$split($regexp(["[", sep_chars, "]"]))); + leading_sep = windows_root_rx.test(basedir) ? '' : basedir.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + abs = basedir_abs; + } + var part; + for (var i = 0, ii = parts.length; i < ii; i++) { + part = parts[i]; - switch (c) { - /* istanbul ignore next */ - case '/': { - // completely not allowed, even escaped. - // Should already be path-split by now. - return false - } + if ( + (part === nil) || + (part === '' && ((new_parts.length === 0) || abs)) || + (part === '.' && ((new_parts.length === 0) || abs)) + ) { + continue; + } + if (part === '..') { + new_parts.pop(); + } else { + new_parts.push(part); + } + } - case '\\': - clearStateChar() - escaping = true - continue + if (!abs && parts[0] !== '.') { + new_parts.$unshift("."); + } + new_path = new_parts.$join(sep); + if ($truthy(abs)) { + new_path = $rb_plus(leading_sep, new_path); + } return new_path; + }, -2); + + $def(self, '$expand_path', function $$expand_path(path, basedir) { + var self = this, sep = nil, sep_chars = nil, home = nil, leading_sep = nil, home_path_regexp = nil; - // the various stateChar values - // for the "extglob" stuff. - case '?': - case '*': - case '+': - case '@': - case '!': - this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c) - - // all of those are literals inside a class, except that - // the glob [!a] means [^a] in regexp - if (inClass) { - this.debug(' in class') - if (c === '!' && i === classStart + 1) c = '^' - re += c - continue + + if (basedir == null) basedir = nil; + sep = $$('SEPARATOR'); + sep_chars = $sep_chars(); + if ($truthy(path[0] === '~' || (basedir && basedir[0] === '~'))) { + + home = $$('Dir').$home(); + if (!$truthy(home)) { + $Kernel.$raise($$$('ArgumentError'), "couldn't find HOME environment -- expanding `~'"); + } leading_sep = windows_root_rx.test(home) ? '' : home.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); + if (!$truthy(home['$start_with?'](leading_sep))) { + $Kernel.$raise($$$('ArgumentError'), "non-absolute home"); + } home = $rb_plus(home, sep); + home_path_regexp = $regexp(["^\\~(?:", sep, "|$)"]); + path = path.$sub(home_path_regexp, home); + if ($truthy(basedir)) { + basedir = basedir.$sub(home_path_regexp, home); + } } return self.$absolute_path(path, basedir); + }, -2); + + // Coerce a given path to a path string using #to_path and #to_str + function $coerce_to_path(path) { + if ($truthy((path)['$respond_to?']("to_path"))) { + path = path.$to_path(); } - // if we already have a stateChar, then it means - // that there was something like ** or +? in there. - // Handle the stateChar, then proceed with this one. - self.debug('call clearStateChar %j', stateChar) - clearStateChar() - stateChar = c - // if extglob is disabled, then +(asdf|foo) isn't a thing. - // just clear the statechar *now*, rather than even diving into - // the patternList stuff. - if (options.noext) clearStateChar() - continue + path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); - case '(': - if (inClass) { - re += '(' - continue - } + return path; + } - if (!stateChar) { - re += '\\(' - continue + // Return a RegExp compatible char class + function $sep_chars() { + if ($$('ALT_SEPARATOR') === nil) { + return Opal.escape_regexp($$('SEPARATOR')); + } else { + return Opal.escape_regexp($rb_plus($$('SEPARATOR'), $$('ALT_SEPARATOR'))); } + } + + $def(self, '$dirname', function $$dirname(path, level) { + var self = this, sep_chars = nil; - patternListStack.push({ - type: stateChar, - start: i - 1, - reStart: re.length, - open: plTypes[stateChar].open, - close: plTypes[stateChar].close - }) - // negation is (?:(?!js)[^/]*) - re += stateChar === '!' ? '(?:(?!(?:' : '(?:' - this.debug('plType %j %j', stateChar, re) - stateChar = false - continue + + if (level == null) level = 1; + if ($eqeq(level, 0)) { + return path + } if ($truthy($rb_lt(level, 0))) { + $Kernel.$raise($$$('ArgumentError'), "level can't be negative"); + } sep_chars = $sep_chars(); + path = $coerce_to_path(path); + + var absolute = path.match(new RegExp("^[" + (sep_chars) + "]")), out; - case ')': - if (inClass || !patternListStack.length) { - re += '\\)' - continue + path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove trailing separators + path = path.replace(new RegExp("[^" + (sep_chars) + "]+$"), ''); // remove trailing basename + path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove final trailing separators + + if (path === '') { + out = absolute ? '/' : '.'; + } + else { + out = path; } - clearStateChar() - hasMagic = true - var pl = patternListStack.pop() - // negation is (?:(?!js)[^/]*) - // The others are (?:<pattern>)<type> - re += pl.close - if (pl.type === '!') { - negativeLists.push(pl) + if (level == 1) { + return out; } - pl.reEnd = re.length - continue + else { + return self.$dirname(out, $rb_minus(level, 1)) + } + }, -2); + + $def(self, '$basename', function $$basename(name, suffix) { + var sep_chars = nil; - case '|': - if (inClass || !patternListStack.length || escaping) { - re += '\\|' - escaping = false - continue + + if (suffix == null) suffix = nil; + sep_chars = $sep_chars(); + name = $coerce_to_path(name); + + if (name.length == 0) { + return name; } - clearStateChar() - re += '|' - continue + if (suffix !== nil) { + suffix = $Opal['$coerce_to!'](suffix, $$$('String'), "to_str"); + } else { + suffix = null; + } - // these are mostly the same in regexp and glob - case '[': - // swallow any state-tracking char before the [ - clearStateChar() + name = name.replace(new RegExp("(.)[" + (sep_chars) + "]*$"), '$1'); + name = name.replace(new RegExp("^(?:.*[" + (sep_chars) + "])?([^" + (sep_chars) + "]+)$"), '$1'); - if (inClass) { - re += '\\' + c - continue + if (suffix === ".*") { + name = name.replace(/\.[^\.]+$/, ''); + } else if(suffix !== null) { + suffix = Opal.escape_regexp(suffix); + name = name.replace(new RegExp("" + (suffix) + "$"), ''); } - inClass = true - classStart = i - reClassStart = re.length - re += c - continue + return name; + }, -2); + + $def(self, '$extname', function $$extname(path) { + var self = this, filename = nil, last_dot_idx = nil; - case ']': - // a right bracket shall lose its special - // meaning and represent itself in - // a bracket expression if it occurs - // first in the list. -- POSIX.2 2.8.3.2 - if (i === classStart + 1 || !inClass) { - re += '\\' + c - escaping = false - continue - } + + path = $coerce_to_path(path); + filename = self.$basename(path); + if ($truthy(filename['$empty?']())) { + return "" + } last_dot_idx = filename['$[]']($range(1, -1, false)).$rindex("."); + if (($truthy(last_dot_idx['$nil?']()) || ($eqeq($rb_plus(last_dot_idx, 1), $rb_minus(filename.$length(), 1))))) { + return "" + } else { + return filename['$[]'](Opal.Range.$new($rb_plus(last_dot_idx, 1), -1, false)) + } }); + + $def(self, '$exist?', function $exist$ques$1(path) { + + return Opal.modules[path] != null + }); + + $def(self, '$directory?', function $directory$ques$2(path) { + var files = nil; - // handle the case where we left a class open. - // "[z-a]" is valid, equivalent to "\[z-a\]" - // split where the last [ was, make sure we don't have - // an invalid re. if so, re-walk the contents of the - // would-be class to re-translate any characters that - // were passed through as-is - // TODO: It would probably be faster to determine this - // without a try/catch and a new RegExp, but it's tricky - // to do safely. For now, this is safe and works. - var cs = pattern.substring(classStart + 1, i) - try { - RegExp('[' + cs + ']') - } catch (er) { - // not a valid class! - var sp = this.parse(cs, SUBPARSE) - re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]' - hasMagic = hasMagic || sp[1] - inClass = false - continue + + files = []; + + for (var key in Opal.modules) { + files.push(key); } + path = path.$gsub($regexp(["(^.", $$('SEPARATOR'), "+|", $$('SEPARATOR'), "+$)"])); + return $send(files, 'find', [], function $$3(f){ + + if (f == null) f = nil; + return f['$=~']($regexp(["^", path]));}); + }); + + $def(self, '$join', function $$join($a) { + var $post_args, paths, result = nil; - // finish up the class. - hasMagic = true - inClass = false - re += c - continue + + $post_args = $slice(arguments); + paths = $post_args; + if ($truthy(paths['$empty?']())) { + return "" + } result = ""; + paths = $send(paths.$flatten().$each_with_index(), 'map', [], function $$4(item, index){ + + if (item == null) item = nil; + if (index == null) index = nil; + if (($eqeq(index, 0) && ($truthy(item['$empty?']())))) { + return $$('SEPARATOR') + } else if (($eqeq(paths.$length(), $rb_plus(index, 1)) && ($truthy(item['$empty?']())))) { + return $$('SEPARATOR') + } else { + return item + }}); + paths = $send(paths, 'reject', [], "empty?".$to_proc()); + $send(paths, 'each_with_index', [], function $$5(item, index){var next_item = nil; - default: - // swallow any state char that wasn't consumed - clearStateChar() - - if (escaping) { - // no need - escaping = false - } else if (reSpecials[c] - && !(c === '^' && inClass)) { - re += '\\' - } + + if (item == null) item = nil; + if (index == null) index = nil; + next_item = paths['$[]']($rb_plus(index, 1)); + if ($truthy(next_item['$nil?']())) { + return (result = "" + (result) + (item)) + } else { + + if (($truthy(item['$end_with?']($$('SEPARATOR'))) && ($truthy(next_item['$start_with?']($$('SEPARATOR')))))) { + item = item.$sub($regexp([$$('SEPARATOR'), "+$"]), ""); + } return (result = (($truthy(item['$end_with?']($$('SEPARATOR'))) || ($truthy(next_item['$start_with?']($$('SEPARATOR'))))) ? ("" + (result) + (item)) : ("" + (result) + (item) + ($$('SEPARATOR'))))); + }}); + return result; + }, -1); + + $def(self, '$split', function $$split(path) { + + return path.$split($$('SEPARATOR')) + }); + $alias(self, "realpath", "expand_path"); + return $alias(self, "exists?", "exist?"); + })(Opal.get_singleton_class(self), $nesting); + })('::', $$$('IO'), $nesting) +}; - re += c +Opal.modules["nodejs/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $truthy = Opal.truthy, $const_set = Opal.const_set, $defs = Opal.defs, $alias = Opal.alias, $slice = Opal.slice, $send = Opal.send, $neqeq = Opal.neqeq, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $assign_ivar = Opal.assign_ivar, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$; - } // switch - } // for + Opal.add_stubs('require,constants,raise,warn,const_get,new,size,delete,respond_to?,path,join,call,map,to_proc,start_with?,first,exist?,realpath,!=,close,to_path,pwd,to_str,include?,match?,sub,attr_reader'); + + self.$require("corelib/file"); + + var warnings = {}, errno_codes = $$('Errno').$constants(); - // handle the case where we left a class open. - // "[abc" is valid, equivalent to "\[abc" - if (inClass) { - // split where the last [ was, and escape it - // this is a huge pita. We now have to re-walk - // the contents of the would-be class to re-translate - // any characters that were passed through as-is - cs = pattern.substr(classStart + 1) - sp = this.parse(cs, SUBPARSE) - re = re.substr(0, reClassStart) + '\\[' + sp[0] - hasMagic = hasMagic || sp[1] + function handle_unsupported_feature(message) { + switch (Opal.config.unsupported_features_severity) { + case 'error': + $$('Kernel').$raise($$('NotImplementedError'), message); + break; + case 'warning': + warn(message); + break; + // noop + } } + function warn(string) { + if (warnings[string]) { + return; + } + warnings[string] = true; + self.$warn(string); + } + function is_utf8(bytes) { + var i = 0; + while (i < bytes.length) { + if ((// ASCII + bytes[i] === 0x09 || + bytes[i] === 0x0A || + bytes[i] === 0x0D || + (0x20 <= bytes[i] && bytes[i] <= 0x7E) + ) + ) { + i += 1; + continue; + } + + if ((// non-overlong 2-byte + (0xC2 <= bytes[i] && bytes[i] <= 0xDF) && + (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) + ) + ) { + i += 2; + continue; + } + + if ((// excluding overlongs + bytes[i] === 0xE0 && + (0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) + ) || + (// straight 3-byte + ((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || + bytes[i] === 0xEE || + bytes[i] === 0xEF) && + (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) + ) || + (// excluding surrogates + bytes[i] === 0xED && + (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x9F) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) + ) + ) { + i += 3; + continue; + } - // handle the case where we had a +( thing at the *end* - // of the pattern. - // each pattern list stack adds 3 chars, and we need to go through - // and escape any | chars that were passed through as-is for the regexp. - // Go through and escape them, taking care not to double-escape any - // | chars that were already escaped. - for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) { - var tail = re.slice(pl.reStart + pl.open.length) - this.debug('setting tail', re, pl) - // maybe some even number of \, then maybe 1 \, followed by a | - tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) { - if (!$2) { - // the | isn't already escaped, so escape it. - $2 = '\\' - } - - // need to escape all those slashes *again*, without escaping the - // one that we need for escaping the | character. As it works out, - // escaping an even number of slashes can be done by simply repeating - // it exactly after itself. That's why this trick works. - // - // I am sorry that you have to see this. - return $1 + $1 + $2 + '|' - }) + if ((// planes 1-3 + bytes[i] === 0xF0 && + (0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && + (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) + ) || + (// planes 4-15 + (0xF1 <= bytes[i] && bytes[i] <= 0xF3) && + (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && + (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) + ) || + (// plane 16 + bytes[i] === 0xF4 && + (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && + (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && + (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) + ) + ) { + i += 4; + continue; + } - this.debug('tail=%j\n %s', tail, tail, pl, re) - var t = pl.type === '*' ? star - : pl.type === '?' ? qmark - : '\\' + pl.type + return false; + } - hasMagic = true - re = re.slice(0, pl.reStart) + t + '\\(' + tail + return true; } - - // handle trailing things that only matter at the very end. - clearStateChar() - if (escaping) { - // trailing \\ - re += '\\\\' + function executeIOAction(action) { + try { + return action(); + } catch (error) { + if (errno_codes.indexOf(error.code) >= 0) { + var error_class = $$('Errno').$const_get(error.code); + $$('Kernel').$raise((error_class).$new(error.message)); + } + $$('Kernel').$raise(error); + } } + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'File'); - // only need to apply the nodot start if the re starts with - // something that could conceivably capture a dot - var addPatternStart = false - switch (re.charAt(0)) { - case '[': case '.': case '(': addPatternStart = true - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + if (self.__fs__ == null) self.__fs__ = nil; + if (self.__path__ == null) self.__path__ = nil; + if (self.__util__ == null) self.__util__ = nil; - // Hack to work around lack of negative lookbehind in JS - // A pattern like: *.!(x).!(y|z) needs to ensure that a name - // like 'a.xyz.yz' doesn't match. So, the first negative - // lookahead, has to look ALL the way ahead, to the end of - // the pattern. - for (var n = negativeLists.length - 1; n > -1; n--) { - var nl = negativeLists[n] + $proto.eof = $proto.binary_flag = $proto.path = $proto.fd = nil; + + self.__fs__ = __fs__; + self.__path__ = __path__; + self.__util__ = __util__; + var __TextEncoder__ = typeof TextEncoder !== 'undefined' ? TextEncoder : __util__.TextEncoder; + var __TextDecoder__ = typeof TextDecoder !== 'undefined' ? TextDecoder : __util__.TextDecoder; + var __utf8TextDecoder__ = new __TextDecoder__('utf8'); + var __textEncoder__ = new __TextEncoder__(); + if ($truthy(__path__.sep !== $$('Separator'))) { + $const_set($nesting[0], 'ALT_SEPARATOR', __path__.sep); + } $defs(self, '$read', function $$read(path) { + + return executeIOAction(function(){return __fs__.readFileSync(path).toString()}) + }); + $defs(self, '$write', function $$write(path, data) { + + + executeIOAction(function(){return __fs__.writeFileSync(path, data)}); + return data.$size(); + }); + $defs(self, '$symlink', function $$symlink(path, new_path) { + + + executeIOAction(function(){return __fs__.symlinkSync(path, new_path)}); + return 0; + }); + $defs(self, '$delete', function $File_delete$1(path) { + + return executeIOAction(function(){return __fs__.unlinkSync(path)}) + }); + (function(self, $parent_nesting) { + + return $alias(self, "unlink", "delete") + })(Opal.get_singleton_class(self)); + $defs(self, '$exist?', function $File_exist$ques$2(path) { + + + if ($truthy(path['$respond_to?']("path"))) { + path = path.$path(); + } return executeIOAction(function(){return __fs__.existsSync(path)}); + }); + $defs(self, '$realpath', function $$realpath(pathname, dir_string, cache) { + var block = $$realpath.$$p || nil, self = this; - var nlBefore = re.slice(0, nl.reStart) - var nlFirst = re.slice(nl.reStart, nl.reEnd - 8) - var nlLast = re.slice(nl.reEnd - 8, nl.reEnd) - var nlAfter = re.slice(nl.reEnd) + $$realpath.$$p = null; + if (dir_string == null) dir_string = nil; + if (cache == null) cache = nil; + if ($truthy(dir_string)) { + pathname = self.$join(dir_string, pathname); + } if ((block !== nil)) { + + __fs__.realpath(pathname, cache, function(error, realpath){ + if (error) Opal.IOError.$new(error.message); + else block.$call(realpath); + }); + + } else { + return executeIOAction(function(){return __fs__.realpathSync(pathname, cache)}) + } }, -2); + $defs(self, '$join', function $$join($a) { + var $post_args, paths, $b, prefix = nil; + + + $post_args = $slice(arguments); + paths = $post_args; + paths = $send(paths, 'map', [], "to_s".$to_proc()); + prefix = ($truthy(($b = paths.$first(), ($b === nil || $b == null) ? nil : $b['$start_with?']("//"))) ? ("/") : ("")); + return prefix + __path__.posix.join.apply(__path__, paths); + }, -1); + $defs(self, '$directory?', function $File_directory$ques$3(path) { + var self = this, result = nil, realpath = nil; - nlLast += nlAfter + + if (!$truthy(self['$exist?'](path))) { + return false + } result = executeIOAction(function(){return !!__fs__.lstatSync(path).isDirectory()}); + if (!$truthy(result)) { + + realpath = self.$realpath(path); + if ($neqeq(realpath, path)) { + result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isDirectory()}); + } } return result; + }); + $defs(self, '$file?', function $File_file$ques$4(path) { + var self = this, result = nil, realpath = nil; - // Handle nested stuff like *(*.js|!(*.json)), where open parens - // mean that we should *not* include the ) in the bit that is considered - // "after" the negated section. - var openParensBefore = nlBefore.split('(').length - 1 - var cleanAfter = nlAfter - for (i = 0; i < openParensBefore; i++) { - cleanAfter = cleanAfter.replace(/\)[+*?]?/, '') - } - nlAfter = cleanAfter + + if (!$truthy(self['$exist?'](path))) { + return false + } result = executeIOAction(function(){return !!__fs__.lstatSync(path).isFile()}); + if (!$truthy(result)) { + + realpath = self.$realpath(path); + if ($neqeq(realpath, path)) { + result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isFile()}); + } } return result; + }); + $defs(self, '$readable?', function $File_readable$ques$5(path) { + var self = this; - var dollar = '' - if (nlAfter === '' && isSub !== SUBPARSE) { - dollar = '$' - } - var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast - re = newRe - } + + if (!$truthy(self['$exist?'](path))) { + return false + } return "\n" + " try {\n" + " __fs__.accessSync(path, __fs__.R_OK);\n" + " return true;\n" + " } catch (error) {\n" + " return false;\n" + " }\n" + " "; + }); + $defs(self, '$size', function $$size(path) { + + return executeIOAction(function(){return __fs__.lstatSync(path).size}); + }); + $defs(self, '$open', function $$open(path, mode) { + var $yield = $$open.$$p || nil, self = this, file = nil; - // if the re is not "" at this point, then we need to make sure - // it doesn't match against an empty path part. - // Otherwise a/* will match a/, which it should not. - if (re !== '' && hasMagic) { - re = '(?=.)' + re - } + $$open.$$p = null; + + if (mode == null) mode = "r"; + file = self.$new(path, mode); + if (($yield !== nil)) { + + return (function() { try { + return Opal.yield1($yield, file); + } finally { + file.$close(); + } })(); + } else { + return file + } }, -2); + $defs(self, '$stat', function $$stat(path) { + + + if ($truthy(path['$respond_to?']("path"))) { + path = path.$path(); + } return $$$($$('File'), 'Stat').$new(path); + }); + $defs(self, '$mtime', function $$mtime(path) { + + return executeIOAction(function(){return __fs__.statSync(path).mtime}) + }); + $defs(self, '$symlink?', function $File_symlink$ques$6(path) { + + return executeIOAction(function(){return __fs__.lstatSync(path).isSymbolicLink()}) + }); + $defs(self, '$absolute_path', function $$absolute_path(path, basedir) { + var $ret_or_1 = nil; - if (addPatternStart) { - re = patternStart + re - } + + if (basedir == null) basedir = nil; + path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path)); + basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$('Dir').$pwd())); + return __path__.normalize(__path__.resolve(basedir.$to_str(), path.$to_str())).split(__path__.sep).join(__path__.posix.sep); + }, -2); + + $def(self, '$initialize', function $$initialize(path, flags) { + var self = this, encoding_option_rx = nil, fd = nil; - // parsing just a piece of a larger pattern. - if (isSub === SUBPARSE) { - return [re, hasMagic] - } + $$initialize.$$p = null; + + if (flags == null) flags = "r"; + self.binary_flag = flags['$include?']("b"); + flags = flags.$delete("b"); + encoding_option_rx = /:(.*)/; + if ($truthy(encoding_option_rx['$match?'](flags))) { + + handle_unsupported_feature("Encoding option (:encoding) is unsupported by Node.js openSync method and will be removed."); + flags = flags.$sub(encoding_option_rx, ""); + } self.path = path; + fd = executeIOAction(function(){return __fs__.openSync(path, flags)}); + return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [fd, flags], null); + }, -2); + self.$attr_reader("path"); + + $def(self, '$sysread', function $$sysread(bytes) { + var self = this, res = nil; - // skip the regexp for non-magical patterns - // unescape anything in it, though, so that it'll be - // an exact match against a file etc. - if (!hasMagic) { - return globUnescape(pattern) - } + if ($truthy(self.eof)) { + return self.$raise($$('EOFError'), "end of file reached") + } else { + + if ($truthy(self.binary_flag)) { + + + var buf = executeIOAction(function(){return __fs__.readFileSync(self.path)}); + var content; + if (is_utf8(buf)) { + content = buf.toString('utf8'); + } else { + // coerce to utf8 + content = __utf8TextDecoder__.decode(__textEncoder__.encode(buf.toString('binary'))); + } + res = content; + } else { + res = executeIOAction(function(){return __fs__.readFileSync(self.path).toString('utf8')}); + } self.eof = true; + self.lineno = res.$size(); + return res; + } + }); + + $def(self, '$write', function $$write(string) { + var self = this; - var flags = options.nocase ? 'i' : '' - try { - var regExp = new RegExp('^' + re + '$', flags) - } catch (er) /* istanbul ignore next - should be impossible */ { - // If it was an invalid regular expression, then it can't match - // anything. This trick looks for a character after the end of - // the string, which is of course impossible, except in multi-line - // mode, but it's not a /m regex. - return new RegExp('$.') - } + return executeIOAction(function(){return __fs__.writeSync(self.fd, string)}) + }); + + $def(self, '$flush', function $$flush() { + var self = this; - regExp._glob = pattern - regExp._src = re + return executeIOAction(function(){return __fs__.fsyncSync(self.fd)}) + }); + + $def(self, '$close', function $$close() { + var $yield = $$close.$$p || nil, self = this; - return regExp -} + $$close.$$p = null; + + executeIOAction(function(){return __fs__.closeSync(self.fd)}); + return $send2(self, $find_super(self, 'close', $$close, false, true), 'close', [], $yield); + }); + return $def(self, '$mtime', function $$mtime() { + var self = this; -minimatch.makeRe = function (pattern, options) { - return new Minimatch(pattern, options || {}).makeRe() -} + return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) + }); + })($nesting[0], $$('IO'), $nesting); + return (function($base, $super) { + var self = $klass($base, $super, 'Stat'); -Minimatch.prototype.makeRe = makeRe -function makeRe () { - if (this.regexp || this.regexp === false) return this.regexp + var $proto = self.$$prototype; + if (self.__fs__ == null) self.__fs__ = nil; - // at this point, this.set is a 2d array of partial - // pattern strings, or "**". - // - // It's better to use .match(). This function shouldn't - // be used, really, but it's pretty convenient sometimes, - // when you just want to work with a regex. - var set = this.set + $proto.path = nil; + + self.__fs__ = __fs__; + + $def(self, '$initialize', $assign_ivar("path")); + + $def(self, '$file?', function $Stat_file$ques$7() { + var self = this; - if (!set.length) { - this.regexp = false - return this.regexp - } - var options = this.options + return executeIOAction(function(){return __fs__.statSync(self.path).isFile()}) + }); + + $def(self, '$directory?', function $Stat_directory$ques$8() { + var self = this; - var twoStar = options.noglobstar ? star - : options.dot ? twoStarDot - : twoStarNoDot - var flags = options.nocase ? 'i' : '' + return executeIOAction(function(){return __fs__.statSync(self.path).isDirectory()}) + }); + + $def(self, '$mtime', function $$mtime() { + var self = this; - var re = set.map(function (pattern) { - return pattern.map(function (p) { - return (p === GLOBSTAR) ? twoStar - : (typeof p === 'string') ? regExpEscape(p) - : p._src - }).join('\\\/') - }).join('|') + return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) + }); + + $def(self, '$readable?', function $Stat_readable$ques$9() { + var self = this; - // must match entire pattern - // ending in a * or ** will make it less strict. - re = '^(?:' + re + ')$' + return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.R_OK)}) + }); + + $def(self, '$writable?', function $Stat_writable$ques$10() { + var self = this; - // can match anything, as long as it's not this. - if (this.negate) re = '^(?!' + re + ').*$' + return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.W_OK)}) + }); + return $def(self, '$executable?', function $Stat_executable$ques$11() { + var self = this; - try { - this.regexp = new RegExp(re, flags) - } catch (ex) /* istanbul ignore next - should be impossible */ { - this.regexp = false - } - return this.regexp -} + return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.X_OK)}) + }); + })($$('File'), null); +}; -minimatch.match = function (list, pattern, options) { - options = options || {} - var mm = new Minimatch(pattern, options) - list = list.filter(function (f) { - return mm.match(f) - }) - if (mm.options.nonull && !list.length) { - list.push(pattern) - } - return list -} +Opal.modules["nodejs/dir"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $send = Opal.send, $Opal = Opal.Opal, $alias = Opal.alias, $nesting = [], nil = Opal.nil; -Minimatch.prototype.match = function match (f, partial) { - if (typeof partial === 'undefined') partial = this.partial - this.debug('match', f, this.pattern) - // short-circuit in the case of busted things. - // comments, etc. - if (this.comment) return false - if (this.empty) return f === '' + Opal.add_stubs('respond_to?,flat_map,to_path,coerce_to!,pwd'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Dir'); - if (f === '/' && partial) return true + var $nesting = [self].concat($parent_nesting); + if (self.__glob__ == null) self.__glob__ = nil; + if (self.__fs__ == null) self.__fs__ = nil; + if (self.__path__ == null) self.__path__ = nil; + if (self.__os__ == null) self.__os__ = nil; - var options = this.options + + self.__glob__ = __glob__; + self.__fs__ = __fs__; + self.__path__ = __path__; + self.__os__ = __os__; + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // windows: need to use /, not \ - if (path.sep !== '/') { - f = f.split(path.sep).join('/') - } + + + $def(self, '$[]', function $$$1(glob) { + + return __glob__.sync(glob) + }); + + $def(self, '$pwd', function $$pwd() { + + return process.cwd().split(__path__.sep).join(__path__.posix.sep); + }); + + $def(self, '$home', function $$home() { + + return __os__.homedir(); + }); + + $def(self, '$chdir', function $$chdir(path) { + + return process.chdir(path) + }); + + $def(self, '$mkdir', function $$mkdir(path) { + + return __fs__.mkdirSync(path) + }); + + $def(self, '$entries', function $$entries(dirname) { + + + var result = []; + var entries = __fs__.readdirSync(dirname); + for (var i = 0, ii = entries.length; i < ii; i++) { + result.push(entries[i]); + } + return result; + + }); + + $def(self, '$glob', function $$glob(pattern) { + + + if (!$truthy(pattern['$respond_to?']("each"))) { + pattern = [pattern]; + } return $send(pattern, 'flat_map', [], function $$2(subpattern){ + + if (subpattern == null) subpattern = nil; + if ($truthy(subpattern['$respond_to?']("to_path"))) { + subpattern = subpattern.$to_path(); + } subpattern = $Opal['$coerce_to!'](subpattern, $$('String'), "to_str"); + return __glob__.sync(subpattern);}); + }); + return $alias(self, "getwd", "pwd"); + })(Opal.get_singleton_class(self), $nesting); + })($nesting[0], null, $nesting) +}; - // treat the test path as a set of pathparts. - f = f.split(slashSplit) - this.debug(this.pattern, 'split', f) +Opal.modules["nodejs/io"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $alias = Opal.alias, $def = Opal.def, $defs = Opal.defs, self = Opal.top, $nesting = []; Opal.nil; - // just ONE of the pattern sets in this.set needs to match - // in order for it to be valid. If negating, then just one - // match means that we have failed. - // Either way, return on the first hit. + Opal.add_stubs('require,attr_reader,initialize,initialize_before_node_io,write,read'); + + self.$require("nodejs/file"); + + function executeIOAction(action) { + try { + return action(); + } catch (error) { + if (error.code === 'EACCES' || + error.code === 'EISDIR' || + error.code === 'EMFILE' || + error.code === 'ENOENT' || + error.code === 'EPERM') { + throw Opal.IOError.$new(error.message) + } + throw error; + } + } + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'IO'); - var set = this.set - this.debug(this.pattern, 'set', set) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Find the basename of the path by looking for the last non-empty segment - var filename - var i - for (i = f.length - 1; i >= 0; i--) { - filename = f[i] - if (filename) break - } + + self.__fs__ = __fs__; + self.$attr_reader("lineno"); + $alias(self, "initialize_before_node_io", "initialize"); + + $def(self, '$initialize', function $$initialize(fd, flags) { + var self = this; - for (i = 0; i < set.length; i++) { - var pattern = set[i] - var file = f - if (options.matchBase && pattern.length === 1) { - file = [filename] - } - var hit = this.matchOne(file, pattern, partial) - if (hit) { - if (options.flipNegate) return true - return !this.negate - } - } + + if (flags == null) flags = "r"; + self.lineno = 0; + return self.$initialize_before_node_io(fd, flags); + }, -2); + $defs(self, '$write', function $$write(path, data) { + + return $$('File').$write(path, data) + }); + $defs(self, '$read', function $$read(path) { + + return $$('File').$read(path) + }); + return $defs(self, '$binread', function $$binread(path) { + + return executeIOAction(function(){return __fs__.readFileSync(path).toString('binary')}) + }); + })($nesting[0], null, $nesting); +}; - // didn't get any hits. this is success if it's a negative - // pattern, failure otherwise. - if (options.flipNegate) return false - return this.negate -} +Opal.modules["nodejs/argf"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $const_set = Opal.const_set, $return_val = Opal.return_val, $def = Opal.def, $eqeq = Opal.eqeq, $gvars = Opal.gvars, $truthy = Opal.truthy, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_gt = Opal.rb_gt, $thrower = Opal.thrower, $not = Opal.not, $alias = Opal.alias, $a, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; -// set partial to true to test if, for example, -// "/a/b" matches the start of "/*/b/*/d" -// Partial means, if you run out of file before you run -// out of pattern, then that's fine, as long as all -// the parts match. -Minimatch.prototype.matchOne = function (file, pattern, partial) { - var options = this.options + Opal.add_stubs('new,include,filename,==,open,argv,shift,close,file,closed?,enum_for,gets,nil?,+,loop,read,-,length,>,to_a,each,attr_accessor,rewind,!,fileno,eof?,lineno='); + + $const_set($nesting[0], 'ARGF', $$('Object').$new()); + (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - this.debug('matchOne', - { 'this': this, file: file, pattern: pattern }) + + self.$include($$('Enumerable')); + + $def(self, '$inspect', $return_val("ARGF")); + + $def(self, '$argv', function $$argv() { + + return $$('ARGV') + }); + + $def(self, '$file', function $$file() { + var self = this, fn = nil, $ret_or_1 = nil; + if (self.file == null) self.file = nil; + if ($gvars.stdin == null) $gvars.stdin = nil; - this.debug('matchOne', file.length, pattern.length) + + fn = self.$filename(); + if ($eqeq(fn, "-")) { + return $gvars.stdin + } else { + return (self.file = ($truthy(($ret_or_1 = self.file)) ? ($ret_or_1) : ($$('File').$open(fn, "r")))) + } }); + + $def(self, '$filename', function $$filename() { + var self = this, $ret_or_1 = nil; + if (self.filename == null) self.filename = nil; + if (self.last_filename == null) self.last_filename = nil; - for (var fi = 0, - pi = 0, - fl = file.length, - pl = pattern.length - ; (fi < fl) && (pi < pl) - ; fi++, pi++) { - this.debug('matchOne loop') - var p = pattern[pi] - var f = file[fi] - - this.debug(pattern, p, f) - - // should be impossible. - // some invalid regexp stuff in the set. - /* istanbul ignore if */ - if (p === false) return false - - if (p === GLOBSTAR) { - this.debug('GLOBSTAR', [pattern, p, f]) - - // "**" - // a/**/b/**/c would match the following: - // a/b/x/y/z/c - // a/x/y/z/b/c - // a/b/x/b/x/c - // a/b/c - // To do this, take the rest of the pattern after - // the **, and see if it would match the file remainder. - // If so, return success. - // If not, the ** "swallows" a segment, and try again. - // This is recursively awful. - // - // a/**/b/**/c matching a/b/x/y/z/c - // - a matches a - // - doublestar - // - matchOne(b/x/y/z/c, b/**/c) - // - b matches b - // - doublestar - // - matchOne(x/y/z/c, c) -> no - // - matchOne(y/z/c, c) -> no - // - matchOne(z/c, c) -> no - // - matchOne(c, c) yes, hit - var fr = fi - var pr = pi + 1 - if (pr === pl) { - this.debug('** at the end') - // a ** at the end will just swallow the rest. - // We have found a match. - // however, it will not swallow /.x, unless - // options.dot is set. - // . and .. are *never* matched by **, for explosively - // exponential reasons. - for (; fi < fl; fi++) { - if (file[fi] === '.' || file[fi] === '..' || - (!options.dot && file[fi].charAt(0) === '.')) return false + + if ($truthy(self.filename)) { + return self.filename + } if ($eqeq(self.$argv(), ["-"])) { + return "-" + } else if ($eqeq(self.$argv(), [])) { + if ($truthy(($ret_or_1 = self.last_filename))) { + return $ret_or_1 + } else { + return "-" } - return true - } + } else { + + self.file = nil; + return (self.filename = (self.last_filename = self.$argv().$shift())); + } }); + + $def(self, '$close', function $$close() { + var self = this; - // ok, let's see if we can swallow whatever we can. - while (fr < fl) { - var swallowee = file[fr] + + self.$file().$close(); + self.filename = nil; + return self; + }); + + $def(self, '$closed?', function $closed$ques$1() { + var self = this; - this.debug('\nglobstar while', file, fr, pattern, pr, swallowee) + return self.$file()['$closed?']() + }); + + $def(self, '$each', function $$each($a) { + var block = $$each.$$p || nil, $post_args, args, self = this, l = nil; - // XXX remove this slice. Just pass the start index. - if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) { - this.debug('globstar found match!', fr, fl, swallowee) - // found a match. - return true - } else { - // can't swallow "." or ".." ever. - // can only swallow ".foo" when explicitly asked. - if (swallowee === '.' || swallowee === '..' || - (!options.dot && swallowee.charAt(0) === '.')) { - this.debug('dot detected!', file, fr, pattern, pr) - break - } + $$each.$$p = null; + $post_args = $slice(arguments); + args = $post_args; + if (!(block !== nil)) { + return self.$enum_for("each") + } while ($truthy((l = $send(self, 'gets', $to_a(args))))) { + Opal.yield1(block, l); + } }, -1); + + $def(self, '$gets', function $$gets($a) { + var $post_args, args, self = this, s = nil; + if (self.lineno == null) self.lineno = nil; - // ** swallows a segment, and continue. - this.debug('globstar swallow a segment, and continue') - fr++ - } - } + + $post_args = $slice(arguments); + args = $post_args; + s = $send(self.$file(), 'gets', $to_a(args)); + if ($truthy(s['$nil?']())) { + + self.$close(); + s = $send(self.$file(), 'gets', $to_a(args)); + } if ($truthy(s)) { + self.lineno = $rb_plus(self.lineno, 1); + } return s; + }, -1); + + $def(self, '$read', function $$read(len) { + var self = this, buf = nil; - // no match was found. - // However, in partial mode, we can't say this is necessarily over. - // If there's more *pattern* left, then - /* istanbul ignore if */ - if (partial) { - // ran out of file - this.debug('\n>>> no match, partial?', file, fr, pattern, pr) - if (fr === fl) return true - } - return false - } + + if (len == null) len = nil; + buf = ""; + return (function(){try { var $t_break = $thrower('break'); return $send(self, 'loop', [], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s, r = nil; + if (self.filename == null) self.filename = nil; - // something other than ** - // non-magic patterns just have to match exactly - // patterns with magic have been turned into regexps. - var hit - if (typeof p === 'string') { - hit = f === p - this.debug('string match', p, f, hit) - } else { - hit = f.match(p) - this.debug('pattern match', p, f, hit) - } + + r = self.$file().$read(len); + if ($truthy(r)) { + + buf = $rb_plus(buf, r); + len = $rb_minus(len, r.$length()); + }; + self.$file().$close(); + if ((($truthy(len) && ($truthy($rb_gt(len, 0)))) && ($truthy(self.filename)))) { + $t_break.$throw(); + } else { + return nil + };}, {$$s: self})} catch($e) { + if ($e === $t_break) return $e.$v; + throw $e; + }})(); + }, -1); + + $def(self, '$readlines', function $$readlines($a) { + var $post_args, args, self = this; - if (!hit) return false - } + + $post_args = $slice(arguments); + args = $post_args; + return $send(self, 'each', $to_a(args)).$to_a(); + }, -1); + self.$attr_accessor("lineno"); + + $def(self, '$rewind', function $$rewind() { + var self = this, f = nil; - // Note: ending in / means that we'll get a final "" - // at the end of the pattern. This can only match a - // corresponding "" at the end of the file. - // If the file ends in /, then it can only match a - // a pattern that ends in /, unless the pattern just - // doesn't have any more for it. But, a/b/ should *not* - // match "a/b/*", even though "" matches against the - // [^/]*? pattern, except in partial mode, where it might - // simply not be reached yet. - // However, a/b/ should still satisfy a/* + + self.lineno = 1; + f = self.$file(); + + try { + f.$rewind(); + } catch ($err) { + if (Opal.rescue($err, [$$('StandardError')])) { + try { + nil; + } finally { Opal.pop_exception(); } + } else { throw $err; } + } return 0; + }); + + $def(self, '$fileno', function $$fileno() { + var self = this; + if (self.last_filename == null) self.last_filename = nil; + if (self.filename == null) self.filename = nil; - // now either we fell off the end of the pattern, or we're done. - if (fi === fl && pi === pl) { - // ran out of pattern and filename at the same time. - // an exact hit! - return true - } else if (fi === fl) { - // ran out of file, but still had pattern left. - // this is ok if we're doing the match as part of - // a glob fs traversal. - return partial - } else /* istanbul ignore else */ if (pi === pl) { - // ran out of pattern, still have file left. - // this is only acceptable if we're on the very last - // empty segment of a file with a trailing slash. - // a/* should match a/b/ - return (fi === fl - 1) && (file[fi] === '') - } - - // should be unreachable. - /* istanbul ignore next */ - throw new Error('wtf?') -} + + if (($not(self.filename) && ($truthy(self.last_filename)))) { + return 0 + } return self.$file().$fileno(); + }); + + $def(self, '$eof?', function $eof$ques$3() { + var self = this; -// replace stuff like \* with * -function globUnescape (s) { - return s.replace(/\\(.)/g, '$1') -} + return self.$file()['$eof?']() + }); + $alias(self, "each_line", "each"); + $alias(self, "eof", "eof?"); + $alias(self, "path", "filename"); + $alias(self, "skip", "close"); + $alias(self, "to_i", "fileno"); + return $alias(self, "to_io", "file"); + })(Opal.get_singleton_class($$('ARGF')), $nesting); + return ($a = [1], $send($$('ARGF'), 'lineno=', $a), $a[$a.length - 1]); +}; -function regExpEscape (s) { - return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') -} +Opal.modules["nodejs/open-uri"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $module = Opal.module, $defs = Opal.defs, $nesting = [], nil = Opal.nil; + return (function($base) { + var self = $module($base, 'OpenURI'); -/***/ }), + if (self.__xmlhttprequest__ == null) self.__xmlhttprequest__ = nil; -/***/ 1223: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + + self.__xmlhttprequest__ = __xmlhttprequest__; + var __XMLHttpRequest__ = self.__xmlhttprequest__.XMLHttpRequest; + $defs(self, '$request', function $$request(uri) { + + + var xhr = new __XMLHttpRequest__(); + xhr.open('GET', uri, false); + xhr.responseType = 'arraybuffer'; + xhr.send(); + return xhr; + + }); + return $defs(self, '$data', function $$data(req) { + + + var arrayBuffer = req.response; + var byteArray = new Uint8Array(arrayBuffer); + var result = []; + for (var i = 0; i < byteArray.byteLength; i++) { + result.push(byteArray[i]); + } + return result; + + }); + })($nesting[0]) +}; -var wrappy = __nccwpck_require__(2940) -module.exports = wrappy(once) -module.exports.strict = wrappy(onceStrict) +Opal.modules["corelib/comparable"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $module = Opal.module, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $def = Opal.def, nil = Opal.nil, $$$ = Opal.$$$; -once.proto = once(function () { - Object.defineProperty(Function.prototype, 'once', { - value: function () { - return once(this) - }, - configurable: true - }) + Opal.add_stubs('>,<,===,raise,class,<=>,equal?'); + return (function($base) { + var self = $module($base, 'Comparable'); - Object.defineProperty(Function.prototype, 'onceStrict', { - value: function () { - return onceStrict(this) - }, - configurable: true - }) -}) + var $ret_or_1 = nil; -function once (fn) { - var f = function () { - if (f.called) return f.value - f.called = true - return f.value = fn.apply(this, arguments) - } - f.called = false - return f -} + + + function normalize(what) { + if (Opal.is_a(what, Opal.Integer)) { return what; } -function onceStrict (fn) { - var f = function () { - if (f.called) - throw new Error(f.onceError) - f.called = true - return f.value = fn.apply(this, arguments) - } - var name = fn.name || 'Function wrapped with `once`' - f.onceError = name + " shouldn't be called more than once" - f.called = false - return f -} + if ($rb_gt(what, 0)) { return 1; } + if ($rb_lt(what, 0)) { return -1; } + return 0; + } + function fail_comparison(lhs, rhs) { + var class_name; + (($eqeqeq(nil, ($ret_or_1 = rhs)) || (($eqeqeq(true, $ret_or_1) || (($eqeqeq(false, $ret_or_1) || (($eqeqeq($$$('Integer'), $ret_or_1) || ($eqeqeq($$$('Float'), $ret_or_1))))))))) ? (class_name = rhs.$inspect()) : (class_name = rhs.$$class)); + $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((lhs).$class()) + " with " + (class_name) + " failed"); + } -/***/ }), + function cmp_or_fail(lhs, rhs) { + var cmp = (lhs)['$<=>'](rhs); + if (!$truthy(cmp)) fail_comparison(lhs, rhs); + return normalize(cmp); + } + + $def(self, '$==', function $Comparable_$eq_eq$1(other) { + var self = this, cmp = nil; -/***/ 8714: -/***/ ((module) => { + + if ($truthy(self['$equal?'](other))) { + return true + } + if (self["$<=>"] == Opal.Kernel["$<=>"]) { + return false; + } -"use strict"; + // check for infinite recursion + if (self.$$comparable) { + self.$$comparable = false; + return false; + } + if (!$truthy((cmp = self['$<=>'](other)))) { + return false + } return normalize(cmp) == 0; }); + + $def(self, '$>', function $Comparable_$gt$2(other) { + var self = this; + + return cmp_or_fail(self, other) > 0; + }); + + $def(self, '$>=', function $Comparable_$gt_eq$3(other) { + var self = this; + return cmp_or_fail(self, other) >= 0; + }); + + $def(self, '$<', function $Comparable_$lt$4(other) { + var self = this; -function posix(path) { - return path.charAt(0) === '/'; -} + return cmp_or_fail(self, other) < 0; + }); + + $def(self, '$<=', function $Comparable_$lt_eq$5(other) { + var self = this; -function win32(path) { - // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56 - var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; - var result = splitDeviceRe.exec(path); - var device = result[1] || ''; - var isUnc = Boolean(device && device.charAt(1) !== ':'); + return cmp_or_fail(self, other) <= 0; + }); + + $def(self, '$between?', function $Comparable_between$ques$6(min, max) { + var self = this; - // UNC paths are always absolute - return Boolean(result[2] || isUnc); -} + + if ($rb_lt(self, min)) { + return false + } if ($rb_gt(self, max)) { + return false + } return true; + }); + return $def(self, '$clamp', function $$clamp(min, max) { + var self = this; -module.exports = process.platform === 'win32' ? win32 : posix; -module.exports.posix = posix; -module.exports.win32 = win32; + + if (max == null) max = nil; + + var c, excl; + if (max === nil) { + // We are dealing with a new Ruby 2.7 behaviour that we are able to + // provide a single Range argument instead of 2 Comparables. -/***/ }), + if (!Opal.is_a(min, Opal.Range)) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (min.$class()) + " (expected Range)"); + } -/***/ 4315: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + excl = min.excl; + max = min.end; + min = min.begin; -/** - * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. - * - * This can be used with JS designed for browsers to improve reuse of code and - * allow the use of existing libraries. - * - * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. - * - * @author Dan DeFelippi <dan@driverdan.com> - * @contributor David Ellis <d.f.ellis@ieee.org> - * @contributor Guillaume Grossetie <ggrossetie@yuzutech.fr> - * @license MIT - */ -const Url = __nccwpck_require__(7310) -const fs = __nccwpck_require__(7147) -const path = __nccwpck_require__(1017) + if (max !== nil && excl) { + $Kernel.$raise($$$('ArgumentError'), "cannot clamp with an exclusive range"); + } + } -exports.XMLHttpRequest = function () { - 'use strict' + if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) { + $Kernel.$raise($$$('ArgumentError'), "min argument must be smaller than max argument"); + } - /** - * Private variables - */ - const self = this - const http = __nccwpck_require__(3685) - const https = __nccwpck_require__(5687) + if (min !== nil) { + c = cmp_or_fail(self, min); - // Holds http.js objects - let request - let response + if (c == 0) return self; + if (c < 0) return min; + } - // Request settings - let settings = {} + if (max !== nil) { + c = cmp_or_fail(self, max); - // Disable header blacklist. - // Not part of XHR specs. - let disableHeaderCheck = false + if (c > 0) return max; + } - // Set some default headers - const defaultHeaders = { - 'User-Agent': 'node-XMLHttpRequest', - 'Accept': '*/*' - } + return self; + }, -2); + })('::') +}; - let headers = {} - const headersCase = {} +Opal.modules["pathname"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $const_set = Opal.const_set, $regexp = Opal.regexp, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $def = Opal.def, $defs = Opal.defs, $to_ary = Opal.to_ary, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $return_ivar = Opal.return_ivar, $neqeq = Opal.neqeq, $rb_plus = Opal.rb_plus, $not = Opal.not, $thrower = Opal.thrower, $alias = Opal.alias, $module = Opal.module, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; - // These headers are not user setable. - // The following are allowed but banned in the spec: - // * user-agent - const forbiddenRequestHeaders = [ - 'accept-charset', - 'accept-encoding', - 'access-control-request-headers', - 'access-control-request-method', - 'connection', - 'content-length', - 'content-transfer-encoding', - 'cookie', - 'cookie2', - 'date', - 'expect', - 'host', - 'keep-alive', - 'origin', - 'referer', - 'te', - 'trailer', - 'transfer-encoding', - 'upgrade', - 'via' - ] + Opal.add_stubs('require,include,quote,===,to_s,path,respond_to?,to_path,is_a?,nil?,raise,class,==,new,pwd,attr_reader,!,relative?,chop_basename,basename,=~,source,[],rindex,sub,absolute?,expand_path,plus,unshift,length,!=,empty?,first,shift,+,join,dirname,pop,reverse_each,directory?,extname,<=>,nonzero?,proc,casecmp,cleanpath,inspect,include?,fill,map,entries'); + + self.$require("corelib/comparable"); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Pathname'); - // These request methods are not allowed - const forbiddenRequestMethods = [ - 'TRACE', - 'TRACK', - 'CONNECT' - ] + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - // Send flag - let sendFlag = false - // Error flag, used when errors occur or abort is called - let errorFlag = false + $proto.path = nil; + + self.$include($$('Comparable')); + $const_set($nesting[0], 'SEPARATOR_PAT', $regexp([$$('Regexp').$quote($$$($$('File'), 'SEPARATOR'))])); + + $def(self, '$initialize', function $$initialize(path) { + var self = this; - // Event listeners - const listeners = {} + + if ($eqeqeq($$('Pathname'), path)) { + self.path = path.$path().$to_s(); + } else if ($truthy(path['$respond_to?']("to_path"))) { + self.path = path.$to_path(); + } else if ($truthy(path['$is_a?']($$('String')))) { + self.path = path; + } else if ($truthy(path['$nil?']())) { + self.$raise($$('TypeError'), "no implicit conversion of nil into String"); + } else { + self.$raise($$('TypeError'), "no implicit conversion of " + (path.$class()) + " into String"); + } if ($eqeq(self.path, "\u0000")) { + return self.$raise($$('ArgumentError')) + } else { + return nil + } }); + $defs(self, '$pwd', function $$pwd() { + var self = this; - /** - * Constants - */ + return self.$new($$('Dir').$pwd()) + }); + self.$attr_reader("path"); + + $def(self, '$==', function $Pathname_$eq_eq$1(other) { + var self = this; - this.UNSENT = 0 - this.OPENED = 1 - this.HEADERS_RECEIVED = 2 - this.LOADING = 3 - this.DONE = 4 + return other.$path()['$=='](self.path) + }); + + $def(self, '$absolute?', function $Pathname_absolute$ques$2() { + var self = this; - /** - * Public vars - */ + return self['$relative?']()['$!']() + }); + + $def(self, '$relative?', function $Pathname_relative$ques$3() { + var $a, $b, self = this, path = nil, r = nil; - // Current state - this.readyState = this.UNSENT + + path = self.path; + while ($truthy((r = self.$chop_basename(path)))) { + $b = r, $a = $to_ary($b), (path = ($a[0] == null ? nil : $a[0])); + } return path['$=='](""); + }); + + $def(self, '$chop_basename', function $$chop_basename(path) { + var base = nil; - // default ready state change handler in case one is not set or is set late - this.onreadystatechange = null + + base = $$('File').$basename(path); + if ($truthy($$('Regexp').$new("^" + ($$$($$('Pathname'), 'SEPARATOR_PAT').$source()) + "?$")['$=~'](base))) { + return nil + } else { + return [path['$[]'](0, path.$rindex(base)), base] + } }); + + $def(self, '$root?', function $Pathname_root$ques$4() { + var self = this; - // Result & response - this.responseText = '' - this.responseXML = '' - this.status = null - this.statusText = null + return self.path['$==']("/") + }); + + $def(self, '$parent', function $$parent() { + var self = this, new_path = nil; - // Whether cross-site Access-Control requests should be made using - // credentials such as cookies or authorization headers - this.withCredentials = false - // "text", "arraybuffer", "blob", or "document", depending on your data needs. - // Note, setting xhr.responseType = '' (or omitting) will default the response to "text". - this.responseType = '' + + new_path = self.path.$sub(/\/([^\/]+\/?$)/, ""); + if ($eqeq(new_path, "")) { + new_path = ($truthy(self['$absolute?']()) ? ("/") : (".")); + } return $$('Pathname').$new(new_path); + }); + + $def(self, '$sub', function $$sub($a) { + var $post_args, args, self = this; - /** - * Private methods - */ + + $post_args = $slice(arguments); + args = $post_args; + return $$('Pathname').$new($send(self.path, 'sub', $to_a(args))); + }, -1); + + $def(self, '$cleanpath', function $$cleanpath() { + var self = this; - /** - * Check if the specified header is allowed. - * - * @param header - {string} Header to validate - * @return {boolean} - False if not allowed, otherwise true - */ - const isAllowedHttpHeader = function (header) { - return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1) - } + return Opal.normalize(self.path) + }); + + $def(self, '$to_path', $return_ivar("path")); + + $def(self, '$hash', $return_ivar("path")); + + $def(self, '$expand_path', function $$expand_path() { + var self = this; - /** - * Check if the specified method is allowed. - * - * @param method - {string} Request method to validate - * @return {boolean} - False if not allowed, otherwise true - */ - const isAllowedHttpMethod = function (method) { - return (method && forbiddenRequestMethods.indexOf(method) === -1) - } + return $$('Pathname').$new($$('File').$expand_path(self.path)) + }); + + $def(self, '$+', function $Pathname_$plus$5(other) { + var self = this; - /** - * Public methods - */ + + if (!$eqeqeq($$('Pathname'), other)) { + other = $$('Pathname').$new(other); + } return $$('Pathname').$new(self.$plus(self.path, other.$to_s())); + }); + + $def(self, '$plus', function $$plus(path1, path2) { + var $a, $b, self = this, prefix2 = nil, index_list2 = nil, basename_list2 = nil, r2 = nil, basename2 = nil, prefix1 = nil, $ret_or_1 = nil, r1 = nil, basename1 = nil, suffix2 = nil; - /** - * Open the connection. Currently supports local server requests. - * - * @param method - {string} Connection method (eg GET, POST) - * @param url - {string} URL for the connection. - * @param async - {boolean} Asynchronous connection. Default is true. - * @param user - {string} Username for basic authentication (optional) - * @param password - {string} Password for basic authentication (optional) - */ - this.open = function (method, url, async, user, password) { - this.abort() - errorFlag = false + + prefix2 = path2; + index_list2 = []; + basename_list2 = []; + while ($truthy((r2 = self.$chop_basename(prefix2)))) { + + $b = r2, $a = $to_ary($b), (prefix2 = ($a[0] == null ? nil : $a[0])), (basename2 = ($a[1] == null ? nil : $a[1])); + index_list2.$unshift(prefix2.$length()); + basename_list2.$unshift(basename2); + } if ($neqeq(prefix2, "")) { + return path2 + } prefix1 = path1; + while ($truthy(true)) { + + while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$=='](".")) : ($ret_or_1)))) { + + index_list2.$shift(); + basename_list2.$shift(); + } if (!$truthy((r1 = self.$chop_basename(prefix1)))) { + break + } $b = r1, $a = $to_ary($b), (prefix1 = ($a[0] == null ? nil : $a[0])), (basename1 = ($a[1] == null ? nil : $a[1])); + if ($eqeq(basename1, ".")) { + continue + } if ((($eqeq(basename1, "..") || ($truthy(basename_list2['$empty?']()))) || ($neqeq(basename_list2.$first(), "..")))) { + + prefix1 = $rb_plus(prefix1, basename1); + break; + } index_list2.$shift(); + basename_list2.$shift(); + } r1 = self.$chop_basename(prefix1); + if (($not(r1) && ($truthy($regexp([$$('SEPARATOR_PAT')])['$=~']($$('File').$basename(prefix1)))))) { + while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$==']("..")) : ($ret_or_1)))) { + + index_list2.$shift(); + basename_list2.$shift(); + } + } if ($not(basename_list2['$empty?']())) { + + suffix2 = path2['$[]'](Opal.Range.$new(index_list2.$first(), -1, false)); + if ($truthy(r1)) { + return $$('File').$join(prefix1, suffix2) + } else { + return $rb_plus(prefix1, suffix2) + } } else if ($truthy(r1)) { + return prefix1 + } else { + return $$('File').$dirname(prefix1) + } }); + + $def(self, '$join', function $$join($a) {try { var $t_return = $thrower('return'); + var $post_args, args, self = this, result = nil; - // Check for valid request method - if (!isAllowedHttpMethod(method)) { - throw new Error('SecurityError: Request method not allowed') - } + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy(args['$empty?']())) { + return self + }; + result = args.$pop(); + if (!$eqeqeq($$('Pathname'), result)) { + result = $$('Pathname').$new(result); + }; + if ($truthy(result['$absolute?']())) { + return result + }; + $send(args, 'reverse_each', [], function $$6(arg){ + + if (arg == null) arg = nil; + if (!$eqeqeq($$('Pathname'), arg)) { + arg = $$('Pathname').$new(arg); + }; + result = $rb_plus(arg, result); + if ($truthy(result['$absolute?']())) { + $t_return.$throw(result); + } else { + return nil + };}, {$$ret: $t_return}); + return $rb_plus(self, result);} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + + $def(self, '$split', function $$split() { + var self = this; - settings = { - 'method': method, - 'url': url.toString(), - 'async': (typeof async !== 'boolean' ? true : async), - 'user': user || null, - 'password': password || null - } + return [self.$dirname(), self.$basename()] + }); + + $def(self, '$dirname', function $$dirname() { + var self = this; - setState(this.OPENED) - } + return $$('Pathname').$new($$('File').$dirname(self.path)) + }); + + $def(self, '$basename', function $$basename() { + var self = this; - /** - * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. - * This does not conform to the W3C spec. - * - * @param state - {boolean} Enable or disable header checking. - */ - this.setDisableHeaderCheck = function (state) { - disableHeaderCheck = state - } + return $$('Pathname').$new($$('File').$basename(self.path)) + }); + + $def(self, '$directory?', function $Pathname_directory$ques$7() { + var self = this; - /** - * Sets a header for the request or appends the value if one is already set. - * - * @param header - {string} Header name - * @param value - {string} Header value - */ - this.setRequestHeader = function (header, value) { - if (this.readyState !== this.OPENED) { - throw new Error('INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN') - } - if (!isAllowedHttpHeader(header)) { - console.warn('Refused to set unsafe header "' + header + '"') - return - } - if (sendFlag) { - throw new Error('INVALID_STATE_ERR: send flag is true') - } - header = headersCase[header.toLowerCase()] || header - headersCase[header.toLowerCase()] = header - headers[header] = headers[header] ? headers[header] + ', ' + value : value - } + return $$('File')['$directory?'](self.path) + }); + + $def(self, '$extname', function $$extname() { + var self = this; - /** - * Gets a header from the server response. - * - * @param header - {string} Name of header to get. - * @return {Object} - Text of the header or null if it doesn't exist. - */ - this.getResponseHeader = function (header) { - if (typeof header === 'string' && - this.readyState > this.OPENED && - response && - response.headers && - response.headers[header.toLowerCase()] && - !errorFlag - ) { - return response.headers[header.toLowerCase()] - } + return $$('File').$extname(self.path) + }); + + $def(self, '$<=>', function $Pathname_$lt_eq_gt$8(other) { + var self = this; - return null - } + return self.$path()['$<=>'](other.$path()) + }); + $const_set($nesting[0], 'SAME_PATHS', ($truthy($$$($$('File'), 'FNM_SYSCASE')['$nonzero?']()) ? ($send(self, 'proc', [], function $Pathname$9(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a.$casecmp(b)['$=='](0);})) : ($send(self, 'proc', [], function $Pathname$10(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$=='](b);})))); + + $def(self, '$relative_path_from', function $$relative_path_from(base_directory) { + var $a, $b, self = this, dest_directory = nil, dest_prefix = nil, dest_names = nil, r = nil, basename = nil, base_prefix = nil, base_names = nil, $ret_or_1 = nil, $ret_or_2 = nil, relpath_names = nil; - /** - * Gets all the response headers. - * - * @return string A string with all response headers separated by CR+LF - */ - this.getAllResponseHeaders = function () { - if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { - return '' - } - let result = '' + + dest_directory = self.$cleanpath().$to_s(); + base_directory = base_directory.$cleanpath().$to_s(); + dest_prefix = dest_directory; + dest_names = []; + while ($truthy((r = self.$chop_basename(dest_prefix)))) { + + $b = r, $a = $to_ary($b), (dest_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])); + if ($neqeq(basename, ".")) { + dest_names.$unshift(basename); + } } base_prefix = base_directory; + base_names = []; + while ($truthy((r = self.$chop_basename(base_prefix)))) { + + $b = r, $a = $to_ary($b), (base_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])); + if ($neqeq(basename, ".")) { + base_names.$unshift(basename); + } } if (!$truthy($$('SAME_PATHS')['$[]'](dest_prefix, base_prefix))) { + self.$raise($$('ArgumentError'), "different prefix: " + (dest_prefix.$inspect()) + " and " + (base_directory.$inspect())); + } while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = dest_names['$empty?']()['$!']())) ? (base_names['$empty?']()['$!']()) : ($ret_or_2)))) ? ($$('SAME_PATHS')['$[]'](dest_names.$first(), base_names.$first())) : ($ret_or_1)))) { + + dest_names.$shift(); + base_names.$shift(); + } if ($truthy(base_names['$include?'](".."))) { + self.$raise($$('ArgumentError'), "base_directory has ..: " + (base_directory.$inspect())); + } base_names.$fill(".."); + relpath_names = $rb_plus(base_names, dest_names); + if ($truthy(relpath_names['$empty?']())) { + return $$('Pathname').$new(".") + } else { + return $$('Pathname').$new($send($$('File'), 'join', $to_a(relpath_names))) + } }); + + $def(self, '$entries', function $$entries() { + var self = this; - for (let i in response.headers) { - // Cookie headers are excluded - if (i !== 'set-cookie' && i !== 'set-cookie2') { - result += i + ': ' + response.headers[i] + '\r\n' - } - } - return result.substr(0, result.length - 2) - } + return $send($$('Dir').$entries(self.path), 'map', [], function $$11(f){var self = $$11.$$s == null ? this : $$11.$$s; - /** - * Gets a request header - * - * @param name - {string} Name of header to get - * @return {string} Returns the request header or empty string if not set - */ - this.getRequestHeader = function (name) { - if (typeof name === 'string' && headersCase[name.toLowerCase()]) { - return headers[headersCase[name.toLowerCase()]] - } + + if (f == null) f = nil; + return self.$class().$new(f);}, {$$s: self}) + }); + $alias(self, "===", "=="); + $alias(self, "eql?", "=="); + $alias(self, "to_s", "to_path"); + return $alias(self, "to_str", "to_path"); + })($nesting[0], null, $nesting); + return (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); - return '' - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - /** - * Sends the request to the server. - * - * @param data - {string} Optional data to send as request body. - */ - this.send = function (data) { - if (this.readyState !== this.OPENED) { - throw new Error('INVALID_STATE_ERR: connection must be opened before send() is called') - } + return $def(self, '$Pathname', function $$Pathname(path) { + + return $$('Pathname').$new(path) + }) + })($nesting[0], $nesting); +}; - if (sendFlag) { - throw new Error('INVALID_STATE_ERR: send has already been called') - } - let ssl = false - let local = false - const url = Url.parse(settings.url) - let host - // Determine the server - switch (url.protocol) { - case 'https:': - ssl = true - host = url.hostname - break - case 'http:': - host = url.hostname - break - case 'file:': - local = true - break - case undefined: - case null: - case '': - host = 'localhost' - break - default: - throw new Error('Protocol not supported.') - } +Opal.modules["nodejs/pathname"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $def = Opal.def, $return_ivar = Opal.return_ivar, self = Opal.top, $nesting = [], nil = Opal.nil; - // Load files off the local filesystem (file://) - if (local) { - if (settings.method !== 'GET') { - throw new Error('XMLHttpRequest: Only GET method is supported') - } + Opal.add_stubs('require,include,to_str,!,absolute?'); + + self.$require("pathname"); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Pathname'); - if (settings.async) { - fs.readFile(url.pathname, 'utf8', function (error, data) { - if (error) { - self.handleError(error) - } else { - self.status = 200 - self.responseText = data - setState(self.DONE) - } - }) - } else { - try { - this.responseText = fs.readFileSync(url.pathname, 'utf8') - this.status = 200 - setState(self.DONE) - } catch (e) { - this.handleError(e) - } - } + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; + if (self.__path__ == null) self.__path__ = nil; - return - } + $proto.path = nil; + + self.$include($$('Comparable')); + self.__path__ = __path__; + + $def(self, '$absolute?', function $Pathname_absolute$ques$1() { + var self = this; - // Default to port 80. If accessing localhost on another port be sure - // to use http://localhost:port/path - const port = url.port || (ssl ? 443 : 80) - // Add query string if one is used - const uri = url.pathname + (url.search ? url.search : '') + return __path__.isAbsolute(self.path.$to_str()) + }); + + $def(self, '$relative?', function $Pathname_relative$ques$2() { + var self = this; - // Set the defaults if they haven't been set - for (let name in defaultHeaders) { - if (!headersCase[name.toLowerCase()]) { - headers[name] = defaultHeaders[name] - } - } + return self['$absolute?']()['$!']() + }); + return $def(self, '$to_path', $return_ivar("path")); + })($nesting[0], null, $nesting); +}; - // Set the Host header or the server may reject the request - headers.Host = host - // IPv6 addresses must be escaped with brackets - if (url.host[0] === '[') { - headers.Host = '[' + headers.Host + ']' - } - if (!((ssl && port === 443) || port === 80)) { - headers.Host += ':' + url.port - } +Opal.modules["nodejs/env"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $const_set = Opal.const_set, $def = Opal.def, $truthy = Opal.truthy, $return_val = Opal.return_val, $send = Opal.send, $alias = Opal.alias, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; - // Set Basic Auth if necessary - if (settings.user) { - if (typeof settings.password === 'undefined') { - settings.password = '' - } - const authBuf = Buffer.from(settings.user + ':' + settings.password) - headers.Authorization = 'Basic ' + authBuf.toString('base64') - } + Opal.add_stubs('new,to_s,key?,[],raise,to_h,keys,merge'); + + $const_set($nesting[0], 'ENV', $$('Object').$new()); + return (function(self, $parent_nesting) { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); - // Set content length header - if (settings.method === 'GET' || settings.method === 'HEAD') { - data = null - } else if (data) { - headers['Content-Length'] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data) + + + $def(self, '$[]', function $$$1(name) { + + return process.env[name] || nil + }); + + $def(self, '$[]=', function $$$eq$2(name, value) { + + return process.env[name.$to_s()] = value.$to_s() + }); + + $def(self, '$key?', function $key$ques$3(name) { + + return process.env.hasOwnProperty(name) + }); + + $def(self, '$empty?', function $empty$ques$4() { + + return Object.keys(process.env).length === 0; + }); + + $def(self, '$keys', function $$keys() { + + return Object.keys(process.env); + }); + + $def(self, '$delete', function $delete$5(name) { + + + var value = process.env[name] || nil; + delete process.env[name]; + return value; + + }); + + $def(self, '$fetch', function $$fetch(key, default_value) { + var block = $$fetch.$$p || nil, self = this; - if (!this.getRequestHeader('Content-Type')) { - headers['Content-Type'] = 'text/plain;charset=UTF-8' - } - } else if (settings.method === 'POST') { - // For a post with no data set Content-Length: 0. - // This is required by buggy servers that don't meet the specs. - headers['Content-Length'] = 0 - } + $$fetch.$$p = null; + if ($truthy(self['$key?'](key))) { + return self['$[]'](key) + } if ((block !== nil)) { + return Opal.yield1(block, key) + } if (!$truthy(typeof(default_value) === 'undefined')) { + return default_value + } return self.$raise($$('KeyError'), "key not found"); + }, -2); + + $def(self, '$to_s', $return_val("ENV")); + + $def(self, '$to_h', function $$to_h() { + var self = this; - const options = { - host: host, - port: port, - path: uri, - method: settings.method, - headers: headers, - agent: false, - withCredentials: self.withCredentials - } + return $send(self.$keys(), 'to_h', [], function $$6(k){var self = $$6.$$s == null ? this : $$6.$$s; - const responseType = this.responseType || 'text' + + if (k == null) k = nil; + return [k, self['$[]'](k)];}, {$$s: self}) + }); + + $def(self, '$merge', function $$merge(keys) { + var self = this; - // Reset error flag - errorFlag = false + return self.$to_h().$merge(keys) + }); + $alias(self, "has_key?", "key?"); + $alias(self, "include?", "key?"); + $alias(self, "inspect", "to_s"); + $alias(self, "member?", "key?"); + return $alias(self, "to_hash", "to_h"); + })(Opal.get_singleton_class($$('ENV')), $nesting); +}; - // Handle async requests - if (settings.async) { - // Use the proper protocol - var doRequest = ssl ? https.request : http.request +Opal.modules["nodejs"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var self = Opal.top; Opal.nil; - // Request is being sent, set send flag - sendFlag = true + Opal.add_stubs('require'); + + self.$require("nodejs/base"); + self.$require("nodejs/file"); + self.$require("nodejs/dir"); + self.$require("nodejs/io"); + self.$require("nodejs/argf"); + self.$require("nodejs/open-uri"); + self.$require("nodejs/pathname"); + return self.$require("nodejs/env"); +}; - // As per spec, this is called here for historical reasons. - self.dispatchEvent('readystatechange') +Opal.modules["corelib/comparable"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $truthy = Opal.truthy, $module = Opal.module, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $def = Opal.def, nil = Opal.nil, $$$ = Opal.$$$; - // Handler for the response - const responseHandler = function responseHandler (resp) { - // Set response var to the response we got back - // This is so it remains accessable outside this scope - response = resp - // Check for redirect - // @TODO Prevent looped redirects - if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { - // Change URL to the redirect location - settings.url = response.headers.location - const url = Url.parse(settings.url) - // Set host var in case it's used later - host = url.hostname - // Options for the new request - const newOptions = { - hostname: url.hostname, - port: url.port, - path: url.path, - method: response.statusCode === 303 ? 'GET' : settings.method, - headers: headers, - withCredentials: self.withCredentials - } + Opal.add_stubs('>,<,===,raise,class,<=>,equal?'); + return (function($base) { + var self = $module($base, 'Comparable'); - // Issue the new request - request = doRequest(newOptions, responseHandler).on('error', errorHandler) - request.end() - // @TODO Check if an XHR event needs to be fired here - return - } + var $ret_or_1 = nil; - response.setEncoding('utf8') + + + function normalize(what) { + if (Opal.is_a(what, Opal.Integer)) { return what; } - setState(self.HEADERS_RECEIVED) - self.status = response.statusCode + if ($rb_gt(what, 0)) { return 1; } + if ($rb_lt(what, 0)) { return -1; } + return 0; + } - response.on('data', function (chunk) { - // Make sure there's some data - if (chunk) { - self.responseText += chunk - } - // Don't emit state changes if the connection has been aborted. - if (sendFlag) { - setState(self.LOADING) - } - }) + function fail_comparison(lhs, rhs) { + var class_name; + (($eqeqeq(nil, ($ret_or_1 = rhs)) || (($eqeqeq(true, $ret_or_1) || (($eqeqeq(false, $ret_or_1) || (($eqeqeq($$$('Integer'), $ret_or_1) || ($eqeqeq($$$('Float'), $ret_or_1))))))))) ? (class_name = rhs.$inspect()) : (class_name = rhs.$$class)); + $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((lhs).$class()) + " with " + (class_name) + " failed"); + } - response.on('end', function () { - if (sendFlag) { - // Discard the end event if the connection has been aborted - setState(self.DONE) - sendFlag = false - } - }) + function cmp_or_fail(lhs, rhs) { + var cmp = (lhs)['$<=>'](rhs); + if (!$truthy(cmp)) fail_comparison(lhs, rhs); + return normalize(cmp); + } + + $def(self, '$==', function $Comparable_$eq_eq$1(other) { + var self = this, cmp = nil; - response.on('error', function (error) { - self.handleError(error) - }) + + if ($truthy(self['$equal?'](other))) { + return true + } + if (self["$<=>"] == Opal.Kernel["$<=>"]) { + return false; } - // Error handler for the request - const errorHandler = function errorHandler (error) { - self.handleError(error) + // check for infinite recursion + if (self.$$comparable) { + self.$$comparable = false; + return false; } + if (!$truthy((cmp = self['$<=>'](other)))) { + return false + } return normalize(cmp) == 0; }); + + $def(self, '$>', function $Comparable_$gt$2(other) { + var self = this; - // Create the request - request = doRequest(options, responseHandler).on('error', errorHandler) - - // Node 0.4 and later won't accept empty data. Make sure it's needed. - if (data) { - request.write(data) - } + return cmp_or_fail(self, other) > 0; + }); + + $def(self, '$>=', function $Comparable_$gt_eq$3(other) { + var self = this; - request.end() + return cmp_or_fail(self, other) >= 0; + }); + + $def(self, '$<', function $Comparable_$lt$4(other) { + var self = this; - self.dispatchEvent('loadstart') - } else { // Synchronous - const encoding = responseType === 'text' ? 'utf8' : 'binary' - const output = (__nccwpck_require__(2081).execSync)(`"${process.argv[0]}" "${__dirname}/request.js" \ ---ssl="${ssl}" \ ---encoding="${encoding}" \ ---request-options=${JSON.stringify(JSON.stringify(options))}`, { stdio: 'pipe' }) - const result = JSON.parse(output.toString('utf8')) - if (result.error) { - self.handleError(result.error) - } else { - response = result.data - self.status = result.data.statusCode - if (encoding === 'binary') { - self.response = Uint8Array.from(result.data.binary.data).buffer - } else { - self.responseText = result.data.text - } - setState(self.DONE) - } - } - } + return cmp_or_fail(self, other) < 0; + }); + + $def(self, '$<=', function $Comparable_$lt_eq$5(other) { + var self = this; - /** - * Called when an error is encountered to deal with it. - */ - this.handleError = function (error) { - this.status = 0 - this.statusText = error - this.responseText = error.stack - errorFlag = true - setState(this.DONE) - this.dispatchEvent('error') - } + return cmp_or_fail(self, other) <= 0; + }); + + $def(self, '$between?', function $Comparable_between$ques$6(min, max) { + var self = this; - /** - * Aborts a request. - */ - this.abort = function () { - if (request) { - request.abort() - request = null - } + + if ($rb_lt(self, min)) { + return false + } if ($rb_gt(self, max)) { + return false + } return true; + }); + return $def(self, '$clamp', function $$clamp(min, max) { + var self = this; - headers = defaultHeaders - this.status = 0 - this.responseText = '' - this.responseXML = '' + + if (max == null) max = nil; + + var c, excl; - errorFlag = true + if (max === nil) { + // We are dealing with a new Ruby 2.7 behaviour that we are able to + // provide a single Range argument instead of 2 Comparables. - if (this.readyState !== this.UNSENT && - (this.readyState !== this.OPENED || sendFlag) && - this.readyState !== this.DONE) { - sendFlag = false - setState(this.DONE) - } - this.readyState = this.UNSENT - this.dispatchEvent('abort') - } + if (!Opal.is_a(min, Opal.Range)) { + $Kernel.$raise($$$('TypeError'), "wrong argument type " + (min.$class()) + " (expected Range)"); + } - /** - * Adds an event listener. Preferred method of binding to events. - */ - this.addEventListener = function (event, callback) { - if (!(event in listeners)) { - listeners[event] = [] - } - // Currently allows duplicate callbacks. Should it? - listeners[event].push(callback) - } + excl = min.excl; + max = min.end; + min = min.begin; - /** - * Remove an event callback that has already been bound. - * Only works on the matching funciton, cannot be a copy. - */ - this.removeEventListener = function (event, callback) { - if (event in listeners) { - // Filter will return a new array with the callback removed - listeners[event] = listeners[event].filter(function (ev) { - return ev !== callback - }) - } - } + if (max !== nil && excl) { + $Kernel.$raise($$$('ArgumentError'), "cannot clamp with an exclusive range"); + } + } - /** - * Dispatch any events, including both "on" methods and events attached using addEventListener. - */ - this.dispatchEvent = function (event) { - if (typeof self['on' + event] === 'function') { - self['on' + event]() - } - if (event in listeners) { - for (let i = 0, len = listeners[event].length; i < len; i++) { - listeners[event][i].call(self) + if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) { + $Kernel.$raise($$$('ArgumentError'), "min argument must be smaller than max argument"); } - } - } - /** - * Changes readyState and calls onreadystatechange. - * - * @param state - {Number} New state - */ - const setState = function (state) { - if (state === self.LOADING || self.readyState !== state) { - self.readyState = state + if (min !== nil) { + c = cmp_or_fail(self, min); - if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { - self.dispatchEvent('readystatechange') + if (c == 0) return self; + if (c < 0) return min; } - if (self.readyState === self.DONE && !errorFlag) { - self.dispatchEvent('load') - // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) - self.dispatchEvent('loadend') + if (max !== nil) { + c = cmp_or_fail(self, max); + + if (c > 0) return max; } - } - } -} + return self; + }, -2); + })('::') +}; -/***/ }), +Opal.modules["pathname"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $const_set = Opal.const_set, $regexp = Opal.regexp, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $def = Opal.def, $defs = Opal.defs, $to_ary = Opal.to_ary, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $return_ivar = Opal.return_ivar, $neqeq = Opal.neqeq, $rb_plus = Opal.rb_plus, $not = Opal.not, $thrower = Opal.thrower, $alias = Opal.alias, $module = Opal.module, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; -/***/ 2940: -/***/ ((module) => { + Opal.add_stubs('require,include,quote,===,to_s,path,respond_to?,to_path,is_a?,nil?,raise,class,==,new,pwd,attr_reader,!,relative?,chop_basename,basename,=~,source,[],rindex,sub,absolute?,expand_path,plus,unshift,length,!=,empty?,first,shift,+,join,dirname,pop,reverse_each,directory?,extname,<=>,nonzero?,proc,casecmp,cleanpath,inspect,include?,fill,map,entries'); + + self.$require("corelib/comparable"); + (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'Pathname'); -// Returns a wrapper function that returns a wrapped callback -// The wrapper function should do some stuff, and return a -// presumably different callback function. -// This makes sure that own properties are retained, so that -// decorations and such are not lost along the way. -module.exports = wrappy -function wrappy (fn, cb) { - if (fn && cb) return wrappy(fn)(cb) + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; - if (typeof fn !== 'function') - throw new TypeError('need wrapper function') + $proto.path = nil; + + self.$include($$('Comparable')); + $const_set($nesting[0], 'SEPARATOR_PAT', $regexp([$$('Regexp').$quote($$$($$('File'), 'SEPARATOR'))])); + + $def(self, '$initialize', function $$initialize(path) { + var self = this; - Object.keys(fn).forEach(function (k) { - wrapper[k] = fn[k] - }) + + if ($eqeqeq($$('Pathname'), path)) { + self.path = path.$path().$to_s(); + } else if ($truthy(path['$respond_to?']("to_path"))) { + self.path = path.$to_path(); + } else if ($truthy(path['$is_a?']($$('String')))) { + self.path = path; + } else if ($truthy(path['$nil?']())) { + self.$raise($$('TypeError'), "no implicit conversion of nil into String"); + } else { + self.$raise($$('TypeError'), "no implicit conversion of " + (path.$class()) + " into String"); + } if ($eqeq(self.path, "\u0000")) { + return self.$raise($$('ArgumentError')) + } else { + return nil + } }); + $defs(self, '$pwd', function $$pwd() { + var self = this; - return wrapper + return self.$new($$('Dir').$pwd()) + }); + self.$attr_reader("path"); + + $def(self, '$==', function $Pathname_$eq_eq$1(other) { + var self = this; - function wrapper() { - var args = new Array(arguments.length) - for (var i = 0; i < args.length; i++) { - args[i] = arguments[i] - } - var ret = fn.apply(this, args) - var cb = args[args.length-1] - if (typeof ret === 'function' && ret !== cb) { - Object.keys(cb).forEach(function (k) { - ret[k] = cb[k] - }) - } - return ret - } -} + return other.$path()['$=='](self.path) + }); + + $def(self, '$absolute?', function $Pathname_absolute$ques$2() { + var self = this; + return self['$relative?']()['$!']() + }); + + $def(self, '$relative?', function $Pathname_relative$ques$3() { + var $a, $b, self = this, path = nil, r = nil; -/***/ }), + + path = self.path; + while ($truthy((r = self.$chop_basename(path)))) { + $b = r, $a = $to_ary($b), (path = ($a[0] == null ? nil : $a[0])); + } return path['$=='](""); + }); + + $def(self, '$chop_basename', function $$chop_basename(path) { + var base = nil; -/***/ 9491: -/***/ ((module) => { + + base = $$('File').$basename(path); + if ($truthy($$('Regexp').$new("^" + ($$$($$('Pathname'), 'SEPARATOR_PAT').$source()) + "?$")['$=~'](base))) { + return nil + } else { + return [path['$[]'](0, path.$rindex(base)), base] + } }); + + $def(self, '$root?', function $Pathname_root$ques$4() { + var self = this; -"use strict"; -module.exports = require("assert"); + return self.path['$==']("/") + }); + + $def(self, '$parent', function $$parent() { + var self = this, new_path = nil; -/***/ }), + + new_path = self.path.$sub(/\/([^\/]+\/?$)/, ""); + if ($eqeq(new_path, "")) { + new_path = ($truthy(self['$absolute?']()) ? ("/") : (".")); + } return $$('Pathname').$new(new_path); + }); + + $def(self, '$sub', function $$sub($a) { + var $post_args, args, self = this; -/***/ 2081: -/***/ ((module) => { + + $post_args = $slice(arguments); + args = $post_args; + return $$('Pathname').$new($send(self.path, 'sub', $to_a(args))); + }, -1); + + $def(self, '$cleanpath', function $$cleanpath() { + var self = this; -"use strict"; -module.exports = require("child_process"); + return Opal.normalize(self.path) + }); + + $def(self, '$to_path', $return_ivar("path")); + + $def(self, '$hash', $return_ivar("path")); + + $def(self, '$expand_path', function $$expand_path() { + var self = this; -/***/ }), + return $$('Pathname').$new($$('File').$expand_path(self.path)) + }); + + $def(self, '$+', function $Pathname_$plus$5(other) { + var self = this; -/***/ 2361: -/***/ ((module) => { + + if (!$eqeqeq($$('Pathname'), other)) { + other = $$('Pathname').$new(other); + } return $$('Pathname').$new(self.$plus(self.path, other.$to_s())); + }); + + $def(self, '$plus', function $$plus(path1, path2) { + var $a, $b, self = this, prefix2 = nil, index_list2 = nil, basename_list2 = nil, r2 = nil, basename2 = nil, prefix1 = nil, $ret_or_1 = nil, r1 = nil, basename1 = nil, suffix2 = nil; -"use strict"; -module.exports = require("events"); + + prefix2 = path2; + index_list2 = []; + basename_list2 = []; + while ($truthy((r2 = self.$chop_basename(prefix2)))) { + + $b = r2, $a = $to_ary($b), (prefix2 = ($a[0] == null ? nil : $a[0])), (basename2 = ($a[1] == null ? nil : $a[1])); + index_list2.$unshift(prefix2.$length()); + basename_list2.$unshift(basename2); + } if ($neqeq(prefix2, "")) { + return path2 + } prefix1 = path1; + while ($truthy(true)) { + + while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$=='](".")) : ($ret_or_1)))) { + + index_list2.$shift(); + basename_list2.$shift(); + } if (!$truthy((r1 = self.$chop_basename(prefix1)))) { + break + } $b = r1, $a = $to_ary($b), (prefix1 = ($a[0] == null ? nil : $a[0])), (basename1 = ($a[1] == null ? nil : $a[1])); + if ($eqeq(basename1, ".")) { + continue + } if ((($eqeq(basename1, "..") || ($truthy(basename_list2['$empty?']()))) || ($neqeq(basename_list2.$first(), "..")))) { + + prefix1 = $rb_plus(prefix1, basename1); + break; + } index_list2.$shift(); + basename_list2.$shift(); + } r1 = self.$chop_basename(prefix1); + if (($not(r1) && ($truthy($regexp([$$('SEPARATOR_PAT')])['$=~']($$('File').$basename(prefix1)))))) { + while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$==']("..")) : ($ret_or_1)))) { + + index_list2.$shift(); + basename_list2.$shift(); + } + } if ($not(basename_list2['$empty?']())) { + + suffix2 = path2['$[]'](Opal.Range.$new(index_list2.$first(), -1, false)); + if ($truthy(r1)) { + return $$('File').$join(prefix1, suffix2) + } else { + return $rb_plus(prefix1, suffix2) + } } else if ($truthy(r1)) { + return prefix1 + } else { + return $$('File').$dirname(prefix1) + } }); + + $def(self, '$join', function $$join($a) {try { var $t_return = $thrower('return'); + var $post_args, args, self = this, result = nil; -/***/ }), + + $post_args = $slice(arguments); + args = $post_args; + if ($truthy(args['$empty?']())) { + return self + }; + result = args.$pop(); + if (!$eqeqeq($$('Pathname'), result)) { + result = $$('Pathname').$new(result); + }; + if ($truthy(result['$absolute?']())) { + return result + }; + $send(args, 'reverse_each', [], function $$6(arg){ + + if (arg == null) arg = nil; + if (!$eqeqeq($$('Pathname'), arg)) { + arg = $$('Pathname').$new(arg); + }; + result = $rb_plus(arg, result); + if ($truthy(result['$absolute?']())) { + $t_return.$throw(result); + } else { + return nil + };}, {$$ret: $t_return}); + return $rb_plus(self, result);} catch($e) { + if ($e === $t_return) return $e.$v; + throw $e; + } + }, -1); + + $def(self, '$split', function $$split() { + var self = this; -/***/ 7147: -/***/ ((module) => { + return [self.$dirname(), self.$basename()] + }); + + $def(self, '$dirname', function $$dirname() { + var self = this; -"use strict"; -module.exports = require("fs"); + return $$('Pathname').$new($$('File').$dirname(self.path)) + }); + + $def(self, '$basename', function $$basename() { + var self = this; -/***/ }), + return $$('Pathname').$new($$('File').$basename(self.path)) + }); + + $def(self, '$directory?', function $Pathname_directory$ques$7() { + var self = this; -/***/ 3685: -/***/ ((module) => { + return $$('File')['$directory?'](self.path) + }); + + $def(self, '$extname', function $$extname() { + var self = this; -"use strict"; -module.exports = require("http"); + return $$('File').$extname(self.path) + }); + + $def(self, '$<=>', function $Pathname_$lt_eq_gt$8(other) { + var self = this; -/***/ }), + return self.$path()['$<=>'](other.$path()) + }); + $const_set($nesting[0], 'SAME_PATHS', ($truthy($$$($$('File'), 'FNM_SYSCASE')['$nonzero?']()) ? ($send(self, 'proc', [], function $Pathname$9(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a.$casecmp(b)['$=='](0);})) : ($send(self, 'proc', [], function $Pathname$10(a, b){ + + if (a == null) a = nil; + if (b == null) b = nil; + return a['$=='](b);})))); + + $def(self, '$relative_path_from', function $$relative_path_from(base_directory) { + var $a, $b, self = this, dest_directory = nil, dest_prefix = nil, dest_names = nil, r = nil, basename = nil, base_prefix = nil, base_names = nil, $ret_or_1 = nil, $ret_or_2 = nil, relpath_names = nil; -/***/ 5687: -/***/ ((module) => { + + dest_directory = self.$cleanpath().$to_s(); + base_directory = base_directory.$cleanpath().$to_s(); + dest_prefix = dest_directory; + dest_names = []; + while ($truthy((r = self.$chop_basename(dest_prefix)))) { + + $b = r, $a = $to_ary($b), (dest_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])); + if ($neqeq(basename, ".")) { + dest_names.$unshift(basename); + } } base_prefix = base_directory; + base_names = []; + while ($truthy((r = self.$chop_basename(base_prefix)))) { + + $b = r, $a = $to_ary($b), (base_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])); + if ($neqeq(basename, ".")) { + base_names.$unshift(basename); + } } if (!$truthy($$('SAME_PATHS')['$[]'](dest_prefix, base_prefix))) { + self.$raise($$('ArgumentError'), "different prefix: " + (dest_prefix.$inspect()) + " and " + (base_directory.$inspect())); + } while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = dest_names['$empty?']()['$!']())) ? (base_names['$empty?']()['$!']()) : ($ret_or_2)))) ? ($$('SAME_PATHS')['$[]'](dest_names.$first(), base_names.$first())) : ($ret_or_1)))) { + + dest_names.$shift(); + base_names.$shift(); + } if ($truthy(base_names['$include?'](".."))) { + self.$raise($$('ArgumentError'), "base_directory has ..: " + (base_directory.$inspect())); + } base_names.$fill(".."); + relpath_names = $rb_plus(base_names, dest_names); + if ($truthy(relpath_names['$empty?']())) { + return $$('Pathname').$new(".") + } else { + return $$('Pathname').$new($send($$('File'), 'join', $to_a(relpath_names))) + } }); + + $def(self, '$entries', function $$entries() { + var self = this; -"use strict"; -module.exports = require("https"); + return $send($$('Dir').$entries(self.path), 'map', [], function $$11(f){var self = $$11.$$s == null ? this : $$11.$$s; -/***/ }), + + if (f == null) f = nil; + return self.$class().$new(f);}, {$$s: self}) + }); + $alias(self, "===", "=="); + $alias(self, "eql?", "=="); + $alias(self, "to_s", "to_path"); + return $alias(self, "to_str", "to_path"); + })($nesting[0], null, $nesting); + return (function($base, $parent_nesting) { + var self = $module($base, 'Kernel'); -/***/ 2037: -/***/ ((module) => { + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); -"use strict"; -module.exports = require("os"); + return $def(self, '$Pathname', function $$Pathname(path) { + + return $$('Pathname').$new(path) + }) + })($nesting[0], $nesting); +}; -/***/ }), +Opal.modules["stringio"] = function(Opal) {/* Generated by Opal 1.7.3 */ + var $klass = Opal.klass, $defs = Opal.defs, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $rb_ge = Opal.rb_ge, $rb_gt = Opal.rb_gt, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $return_ivar = Opal.return_ivar, $eqeq = Opal.eqeq, $alias = Opal.alias, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$; -/***/ 1017: -/***/ ((module) => { + Opal.add_stubs('new,call,close,attr_accessor,check_readable,==,length,===,>=,raise,>,+,-,seek,check_writable,String,[],eof?,write,read,tell'); + return (function($base, $super, $parent_nesting) { + var self = $klass($base, $super, 'StringIO'); -"use strict"; -module.exports = require("path"); + var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; -/***/ }), + $proto.position = $proto.string = nil; + + $defs(self, '$open', function $$open(string, mode) { + var block = $$open.$$p || nil, self = this, io = nil, res = nil; -/***/ 7310: -/***/ ((module) => { + $$open.$$p = null; + if (string == null) string = ""; + if (mode == null) mode = nil; + io = self.$new(string, mode); + res = block.$call(io); + io.$close(); + return res; + }, -1); + self.$attr_accessor("string"); + + $def(self, '$initialize', function $$initialize(string, mode) { + var self = this; -"use strict"; -module.exports = require("url"); + $$initialize.$$p = null; + + if (string == null) string = ""; + if (mode == null) mode = "rw"; + self.string = string; + self.position = 0; + return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [nil, mode], null); + }, -1); + + $def(self, '$eof?', function $StringIO_eof$ques$1() { + var self = this; -/***/ }), + + self.$check_readable(); + return self.position['$=='](self.string.$length()); + }); + + $def(self, '$seek', function $$seek(pos, whence) { + var self = this, $ret_or_1 = nil; -/***/ 3837: -/***/ ((module) => { + + if (whence == null) whence = $$$($$('IO'), 'SEEK_SET'); + self.read_buffer = ""; + if ($eqeqeq($$$($$('IO'), 'SEEK_SET'), ($ret_or_1 = whence))) { + + if (!$truthy($rb_ge(pos, 0))) { + self.$raise($$$($$('Errno'), 'EINVAL')); + } self.position = pos; + } else if ($eqeqeq($$$($$('IO'), 'SEEK_CUR'), $ret_or_1)) { + if ($truthy($rb_gt($rb_plus(self.position, pos), self.string.$length()))) { + self.position = self.string.$length(); + } else { + self.position = $rb_plus(self.position, pos); + } + } else if ($eqeqeq($$$($$('IO'), 'SEEK_END'), $ret_or_1)) { + if ($truthy($rb_gt(pos, self.string.$length()))) { + self.position = 0; + } else { + self.position = $rb_minus(self.position, pos); + } + } else ; return 0; + }, -2); + + $def(self, '$tell', $return_ivar("position")); + + $def(self, '$rewind', function $$rewind() { + var self = this; + + return self.$seek(0) + }); + + $def(self, '$write', function $$write(string) { + var self = this, before = nil, after = nil; + + + self.$check_writable(); + self.read_buffer = ""; + string = self.$String(string); + if ($eqeq(self.string.$length(), self.position)) { + + self.string = $rb_plus(self.string, string); + return (self.position = $rb_plus(self.position, string.$length())); + } else { + + before = self.string['$[]'](Opal.Range.$new(0, $rb_minus(self.position, 1), false)); + after = self.string['$[]'](Opal.Range.$new($rb_plus(self.position, string.$length()), -1, false)); + self.string = $rb_plus($rb_plus(before, string), after); + return (self.position = $rb_plus(self.position, string.$length())); + } }); + + $def(self, '$read', function $$read(length, outbuf) { + var self = this, string = nil, str = nil; + + + if (length == null) length = nil; + if (outbuf == null) outbuf = nil; + self.$check_readable(); + if ($truthy(self['$eof?']())) { + return nil + } string = ($truthy(length) ? (((str = self.string['$[]'](self.position, length)), (self.position = $rb_plus(self.position, length)), ($truthy($rb_gt(self.position, self.string.$length())) ? ((self.position = self.string.$length())) : nil), str)) : (((str = self.string['$[]'](Opal.Range.$new(self.position, -1, false))), (self.position = self.string.$length()), str))); + if ($truthy(outbuf)) { + return outbuf.$write(string) + } else { + return string + } }, -1); + + $def(self, '$sysread', function $$sysread(length) { + var self = this; + + + self.$check_readable(); + return self.$read(length); + }); + $alias(self, "eof", "eof?"); + $alias(self, "pos", "tell"); + $alias(self, "pos=", "seek"); + return $alias(self, "readpartial", "read"); + })($nesting[0], $$('IO'), $nesting) +}; + +module.exports = Opal$1; -"use strict"; -module.exports = require("util"); /***/ }), -/***/ 8656: +/***/ 8243: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; @@ -58404,8 +56433,8 @@ module.exports = require("util"); Object.defineProperty(exports, "__esModule", ({ value: true })); -var domhandler = __nccwpck_require__(4038); -var selderee = __nccwpck_require__(5178); +var domhandler = __nccwpck_require__(7792); +var selderee = __nccwpck_require__(8171); function hp2Builder(nodes) { return new selderee.Picker(handleArray(nodes)); @@ -58498,7 +56527,7 @@ exports.hp2Builder = hp2Builder; /***/ }), -/***/ 3012: +/***/ 4527: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; @@ -58507,11 +56536,11 @@ var __webpack_unused_export__; __webpack_unused_export__ = ({ value: true }); -var pluginHtmlparser2 = __nccwpck_require__(8656); -var htmlparser2 = __nccwpck_require__(2928); -var selderee = __nccwpck_require__(5178); -var merge = __nccwpck_require__(6323); -var domSerializer = __nccwpck_require__(8621); +var pluginHtmlparser2 = __nccwpck_require__(8243); +var htmlparser2 = __nccwpck_require__(5368); +var selderee = __nccwpck_require__(8171); +var merge = __nccwpck_require__(2569); +var domSerializer = __nccwpck_require__(9943); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } @@ -60658,13 +58687,13 @@ function handleDeprecatedOptions (options) { } __webpack_unused_export__ = compile; -exports.OQ = convert; +exports.C6 = convert; __webpack_unused_export__ = convert; /***/ }), -/***/ 6549: +/***/ 3703: /***/ ((__unused_webpack_module, exports) => { "use strict"; @@ -60673,7 +58702,7 @@ Object.defineProperty(exports, "__esModule", ({value:!0}));const e=/\n/g;functio /***/ }), -/***/ 2425: +/***/ 1647: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; @@ -60681,8 +58710,8 @@ Object.defineProperty(exports, "__esModule", ({value:!0}));const e=/\n/g;functio Object.defineProperty(exports, "__esModule", ({ value: true })); -var leac = __nccwpck_require__(6549); -var p = __nccwpck_require__(6986); +var leac = __nccwpck_require__(3703); +var p = __nccwpck_require__(2983); function _interopNamespace(e) { if (e && e.__esModule) return e; @@ -60992,7 +59021,7 @@ exports.serialize = serialize; /***/ }), -/***/ 6986: +/***/ 2983: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; @@ -61000,7 +59029,7 @@ exports.serialize = serialize; Object.defineProperty(exports, "__esModule", ({ value: true })); -var util = __nccwpck_require__(124); +var util = __nccwpck_require__(7306); function emit(value) { return (data, i) => ({ @@ -61447,7 +59476,7 @@ exports.tryParse = tryParse; /***/ }), -/***/ 124: +/***/ 7306: /***/ ((__unused_webpack_module, exports) => { "use strict"; @@ -61468,7 +59497,7 @@ exports.escapeWhitespace = escapeWhitespace; /***/ }), -/***/ 5178: +/***/ 8171: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; @@ -61476,7 +59505,7 @@ exports.escapeWhitespace = escapeWhitespace; Object.defineProperty(exports, "__esModule", ({ value: true })); -var parseley = __nccwpck_require__(2425); +var parseley = __nccwpck_require__(1647); function _interopNamespace(e) { if (e && e.__esModule) return e; @@ -61969,60 +59998,57 @@ exports.Types = Types; /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/compat */ -/******/ +/******/ /* webpack/runtime/asset-relocator-loader */ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. -(() => { // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -let Asciidoctor = __nccwpck_require__(853); -let convert = (__nccwpck_require__(3012)/* .convert */ .OQ); +let Asciidoctor = __nccwpck_require__(7695) +let convert = (__nccwpck_require__(4527)/* .convert */ .C6) -const asciidoc = Asciidoctor(); +const asciidoc = Asciidoctor() const parse = (content) => { - const doc = asciidoc.load(content); + const doc = asciidoc.load(content) const sections = doc .getSections() .map((section) => formatSection(section, content)) - .reduce((acc, prev) => [...acc, ...prev], []); + .reduce((acc, prev) => [...acc, ...prev], []) const title = doc.getTitle() return { - title: (title || "") - .replace("RFD", "") - .replace("# ", "") - .replace("= ", "") + title: (title || '') + .replace('RFD', '') + .replace('# ', '') + .replace('= ', '') .trim() .split(' ') .slice(1) .join(' '), - sections - }; -}; + sections, + } +} const formatSection = (section, content) => { - const formattedSections = []; + const formattedSections = [] for (const s of section.getSections()) { - formattedSections.push(...formatSection(s, content)); + formattedSections.push(...formatSection(s, content)) } - const parentSections = []; - let level = section.getLevel() - 1; - let currSection = section.getParent(); + const parentSections = [] + let level = section.getLevel() - 1 + let currSection = section.getParent() while (level-- && currSection) { if (typeof currSection.getName === 'function') { - parentSections.push(currSection.getName()); + parentSections.push(currSection.getName()) } - currSection = currSection.getParent(); + currSection = currSection.getParent() } return [ @@ -62032,19 +60058,18 @@ const formatSection = (section, content) => { content: convert( section .getBlocks() - .filter((block) => block.context !== "section") + .filter((block) => block.context !== 'section') .map((block) => block.convert()) - .join("") + .join(''), ), - parents: parentSections + parents: parentSections, }, ...formattedSections, - ]; -}; + ] +} -let content = (__nccwpck_require__(7147).readFileSync)(0, 'utf-8'); +let content = (__nccwpck_require__(9896).readFileSync)(0, 'utf-8') console.log(JSON.stringify(parse(content))) -})(); module.exports = __webpack_exports__; /******/ })()