diff --git a/.gitignore b/.gitignore index 75e871a..3e2e84b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -*.swp -bin/ +build/ node_modules/ -.DS_Store diff --git a/Gruntfile.coffee b/Gruntfile.coffee deleted file mode 100644 index 6eed79e..0000000 --- a/Gruntfile.coffee +++ /dev/null @@ -1,72 +0,0 @@ -module.exports = (grunt) -> - pkg = require './package.json' - grunt.initConfig - pkg: pkg - - coffee: - compile: - options: - join: true - bare: true - files: [ - 'bin/ficdown.js': ['src/*.coffee'] - ] - - stylus: - compile: - options: - compress: true - expand: true - files: [ - 'bin/example/player.css': ['src/example/*.styl'] - ] - - uglify: - js: - files: - 'bin/ficdown.min.js': [ - 'bin/ficdown.js' - ] - - copy: - static: - files: [ - expand: true - flatten: true - src: ['src/*.html'] - dest: 'bin/' - ] - example: - files: [ - expand: true - flatten: true - src: ['src/example/*.html', 'src/example/*.png', 'src/example/*.md', 'bin/ficdown.min.js'] - dest: 'bin/example/' - ] - - watch: - js: - files: ['src/**/*.coffee'] - tasks: ['build:js', 'copy:example'] - css: - files: ['src/**/*.styl'] - tasks: ['stylus:compile'] - static: - files: ['src/**/*.html','src/**/*.js','src/**/*.md'] - tasks: ['copy:static', 'copy:example'] - - for name of pkg.devDependencies when name.substring(0, 6) is 'grunt-' - grunt.loadNpmTasks name - - grunt.registerTask 'build:js', [ - 'coffee:compile' - 'uglify:js' - ] - - grunt.registerTask 'default', [ - 'coffee:compile' - 'uglify:js' - 'stylus:compile' - 'copy:static' - 'copy:example' - ] diff --git a/package-lock.json b/package-lock.json index 84aa4d4..45fd003 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,1012 +1,97 @@ { "name": "ficdown.js", - "version": "0.9.0", + "version": "0.9.1", "lockfileVersion": 1, "requires": true, "dependencies": { - "abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "dev": true - }, - "align-text": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", - "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", + "@types/jquery": { + "version": "3.3.29", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.29.tgz", + "integrity": "sha512-FhJvBninYD36v3k6c+bVk1DSZwh7B5Dpb/Pyk3HKVsiohn0nhbefZZ+3JXbWQhFyt0MxSl2jRDdGQPHeOHFXrQ==", "dev": true, "requires": { - "kind-of": "3.2.2", - "longest": "1.0.1", - "repeat-string": "1.6.1" + "@types/sizzle": "*" } }, - "ansi-regex": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-0.2.1.tgz", - "integrity": "sha1-DY6UaWej2BQ/k+JOKYUl/BsiNfk=", + "@types/linkify-it": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-2.1.0.tgz", + "integrity": "sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==", "dev": true }, - "ansi-styles": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz", - "integrity": "sha1-yxAt8cVvUSPquLZ817mAJ6AnkXg=", + "@types/markdown-it": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-0.0.7.tgz", + "integrity": "sha512-WyL6pa76ollQFQNEaLVa41ZUUvDvPY+qAUmlsphnrpL6I9p1m868b26FyeoOmo7X3/Ta/S9WKXcEYXUSHnxoVQ==", + "dev": true, + "requires": { + "@types/linkify-it": "*" + } + }, + "@types/sizzle": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz", + "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==", "dev": true }, "argparse": { - "version": "0.1.16", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz", - "integrity": "sha1-z9AeD7uj1srtBJ+9dY1A9lGW9Xw=", - "dev": true, - "requires": { - "underscore": "1.7.0", - "underscore.string": "2.4.0" - }, - "dependencies": { - "underscore.string": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz", - "integrity": "sha1-jN2PusTi0uoefi6Al8QvRCKA+Fs=", - "dev": true - } - } - }, - "async": { - "version": "0.1.22", - "resolved": "https://registry.npmjs.org/async/-/async-0.1.22.tgz", - "integrity": "sha1-D8GqoIig4+8Ovi2IMbqw3PiEUGE=", - "dev": true - }, - "browserify-zlib": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.1.4.tgz", - "integrity": "sha1-uzX4pRn2AOD6a4SFJByXnQFB+y0=", - "dev": true, - "requires": { - "pako": "0.2.9" - } - }, - "camelcase": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", - "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", - "dev": true - }, - "center-align": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", - "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", - "dev": true, - "requires": { - "align-text": "0.1.4", - "lazy-cache": "1.0.4" - } - }, - "chalk": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz", - "integrity": "sha1-UZmj3c0MHv4jvAjBsCewYXbgxk8=", - "dev": true, - "requires": { - "ansi-styles": "1.0.0", - "has-color": "0.1.7", - "strip-ansi": "0.1.1" - } - }, - "cliui": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", - "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", - "dev": true, - "requires": { - "center-align": "0.1.3", - "right-align": "0.1.3", - "wordwrap": "0.0.2" - } - }, - "coffee-script": { - "version": "1.12.7", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz", - "integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==", - "dev": true - }, - "colors": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz", - "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=", - "dev": true - }, - "concat-stream": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", - "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", - "dev": true, - "requires": { - "inherits": "2.0.3", - "readable-stream": "2.3.3", - "typedarray": "0.0.6" - } - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, - "css-parse": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/css-parse/-/css-parse-1.7.0.tgz", - "integrity": "sha1-Mh9s9zeCpv91ERE5D8BeLGV9jJs=", - "dev": true - }, - "dateformat": { - "version": "1.0.2-1.2.3", - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz", - "integrity": "sha1-sCIMAt6YYXQztyhRz0fePfLNvuk=", - "dev": true - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "esprima": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz", - "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0=", - "dev": true - }, - "eventemitter2": { - "version": "0.4.14", - "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz", - "integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas=", - "dev": true - }, - "exit": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", - "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", - "dev": true - }, - "faye-websocket": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.4.4.tgz", - "integrity": "sha1-wUxbO/FNdBf/v9mQwKdJXNnzN7w=", - "dev": true - }, - "figures": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", - "integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=", - "dev": true, - "requires": { - "escape-string-regexp": "1.0.5", - "object-assign": "4.1.1" - } - }, - "findup-sync": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz", - "integrity": "sha1-fz56l7gjksZTvwZYm9hRkOk8NoM=", - "dev": true, - "requires": { - "glob": "3.2.11", - "lodash": "2.4.2" - }, - "dependencies": { - "glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", - "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", - "dev": true, - "requires": { - "inherits": "2.0.3", - "minimatch": "0.3.0" - } - }, - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - }, - "minimatch": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", - "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", - "dev": true, - "requires": { - "lru-cache": "2.7.3", - "sigmund": "1.0.1" - } - } - } - }, - "gaze": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/gaze/-/gaze-0.5.2.tgz", - "integrity": "sha1-QLcJU30k0dRXZ9takIaJ3+aaxE8=", - "dev": true, - "requires": { - "globule": "0.1.0" - } - }, - "getobject": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/getobject/-/getobject-0.1.0.tgz", - "integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw=", - "dev": true - }, - "glob": { - "version": "3.1.21", - "resolved": "https://registry.npmjs.org/glob/-/glob-3.1.21.tgz", - "integrity": "sha1-0p4KBV3qUTj00H7UDomC6DwgZs0=", - "dev": true, - "requires": { - "graceful-fs": "1.2.3", - "inherits": "1.0.2", - "minimatch": "0.2.14" - }, - "dependencies": { - "inherits": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-1.0.2.tgz", - "integrity": "sha1-ykMJ2t7mtUzAuNJH6NfHoJdb3Js=", - "dev": true - } - } - }, - "globule": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/globule/-/globule-0.1.0.tgz", - "integrity": "sha1-2cjt3h2nnRJaFRt5UzuXhnY0auU=", - "dev": true, - "requires": { - "glob": "3.1.21", - "lodash": "1.0.2", - "minimatch": "0.2.14" - }, - "dependencies": { - "lodash": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-1.0.2.tgz", - "integrity": "sha1-j1dWDIO1n8JwvT1WG2kAQ0MOJVE=", - "dev": true - } - } - }, - "graceful-fs": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.2.3.tgz", - "integrity": "sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q=", - "dev": true - }, - "grunt": { - "version": "0.4.5", - "resolved": "https://registry.npmjs.org/grunt/-/grunt-0.4.5.tgz", - "integrity": "sha1-VpN81RlDJK3/bSB2MYMqnWuk5/A=", - "dev": true, - "requires": { - "async": "0.1.22", - "coffee-script": "1.3.3", - "colors": "0.6.2", - "dateformat": "1.0.2-1.2.3", - "eventemitter2": "0.4.14", - "exit": "0.1.2", - "findup-sync": "0.1.3", - "getobject": "0.1.0", - "glob": "3.1.21", - "grunt-legacy-log": "0.1.3", - "grunt-legacy-util": "0.2.0", - "hooker": "0.2.3", - "iconv-lite": "0.2.11", - "js-yaml": "2.0.5", - "lodash": "0.9.2", - "minimatch": "0.2.14", - "nopt": "1.0.10", - "rimraf": "2.2.8", - "underscore.string": "2.2.1", - "which": "1.0.9" - }, - "dependencies": { - "coffee-script": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.3.3.tgz", - "integrity": "sha1-FQ1rTLUiiUNp7+1qIQHCC8f0pPQ=", - "dev": true - } - } - }, - "grunt-contrib-coffee": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/grunt-contrib-coffee/-/grunt-contrib-coffee-0.10.1.tgz", - "integrity": "sha1-7SLGgp9FiqjqR/hnaEM+mBMUAYY=", - "dev": true, - "requires": { - "chalk": "0.4.0", - "coffee-script": "1.7.1", - "lodash": "2.4.2" - }, - "dependencies": { - "coffee-script": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.7.1.tgz", - "integrity": "sha1-YplqhheAx15tUGnROCJyO3NAS/w=", - "dev": true, - "requires": { - "mkdirp": "0.3.5" - } - }, - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - } - } - }, - "grunt-contrib-copy": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/grunt-contrib-copy/-/grunt-contrib-copy-0.5.0.tgz", - "integrity": "sha1-QQB1rEWlhWuhkbHMclclRQ1KAhU=", - "dev": true - }, - "grunt-contrib-stylus": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/grunt-contrib-stylus/-/grunt-contrib-stylus-0.17.0.tgz", - "integrity": "sha1-W9hRlO5Kttar98ShlQbHCLYr8EE=", - "dev": true, - "requires": { - "async": "0.8.0", - "chalk": "0.4.0", - "lodash": "2.4.2", - "nib": "1.0.4", - "stylus": "0.46.3" - }, - "dependencies": { - "async": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/async/-/async-0.8.0.tgz", - "integrity": "sha1-7mXsdymML/FFa8RBigUtDwZDURI=", - "dev": true - }, - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - } - } - }, - "grunt-contrib-uglify": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-0.5.1.tgz", - "integrity": "sha1-FfCqXo6LpCGuqYCHnuUFvHErbN4=", - "dev": true, - "requires": { - "chalk": "0.5.1", - "lodash": "2.4.2", - "maxmin": "0.2.2", - "uglify-js": "2.8.29" - }, - "dependencies": { - "ansi-styles": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.1.0.tgz", - "integrity": "sha1-6uy/Zs1waIJ2Cy9GkVgrj1XXp94=", - "dev": true - }, - "chalk": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.5.1.tgz", - "integrity": "sha1-Zjs6ZItotV0EaQ1JFnqoN4WPIXQ=", - "dev": true, - "requires": { - "ansi-styles": "1.1.0", - "escape-string-regexp": "1.0.5", - "has-ansi": "0.1.0", - "strip-ansi": "0.3.0", - "supports-color": "0.2.0" - } - }, - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - }, - "strip-ansi": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.3.0.tgz", - "integrity": "sha1-JfSOoiynkYfzF0pNuHWTR7sSYiA=", - "dev": true, - "requires": { - "ansi-regex": "0.2.1" - } - } - } - }, - "grunt-contrib-watch": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/grunt-contrib-watch/-/grunt-contrib-watch-0.6.1.tgz", - "integrity": "sha1-ZP3LolpjX1tNobbOb5DaCutuPxU=", - "dev": true, - "requires": { - "async": "0.2.10", - "gaze": "0.5.2", - "lodash": "2.4.2", - "tiny-lr-fork": "0.0.5" - }, - "dependencies": { - "async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", - "dev": true - }, - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - } - } - }, - "grunt-legacy-log": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-0.1.3.tgz", - "integrity": "sha1-7ClCboAwIa9ZAp+H0vnNczWgVTE=", - "dev": true, - "requires": { - "colors": "0.6.2", - "grunt-legacy-log-utils": "0.1.1", - "hooker": "0.2.3", - "lodash": "2.4.2", - "underscore.string": "2.3.3" - }, - "dependencies": { - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - }, - "underscore.string": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", - "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", - "dev": true - } - } - }, - "grunt-legacy-log-utils": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-0.1.1.tgz", - "integrity": "sha1-wHBrndkGThFvNvI/5OawSGcsD34=", - "dev": true, - "requires": { - "colors": "0.6.2", - "lodash": "2.4.2", - "underscore.string": "2.3.3" - }, - "dependencies": { - "lodash": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", - "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", - "dev": true - }, - "underscore.string": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", - "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", - "dev": true - } - } - }, - "grunt-legacy-util": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-0.2.0.tgz", - "integrity": "sha1-kzJIhNv343qf98Am3/RR2UqeVUs=", - "dev": true, - "requires": { - "async": "0.1.22", - "exit": "0.1.2", - "getobject": "0.1.0", - "hooker": "0.2.3", - "lodash": "0.9.2", - "underscore.string": "2.2.1", - "which": "1.0.9" - } - }, - "gzip-size": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-0.2.0.tgz", - "integrity": "sha1-46KhkSBf5W7jJvXCcUNd+uz7Phw=", - "dev": true, - "requires": { - "browserify-zlib": "0.1.4", - "concat-stream": "1.6.0" - } - }, - "has-ansi": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-0.1.0.tgz", - "integrity": "sha1-hPJlqujA5qiKEtcCKJS3VoiUxi4=", - "dev": true, - "requires": { - "ansi-regex": "0.2.1" - } - }, - "has-color": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/has-color/-/has-color-0.1.7.tgz", - "integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=", - "dev": true - }, - "hooker": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz", - "integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk=", - "dev": true - }, - "iconv-lite": { - "version": "0.2.11", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.2.11.tgz", - "integrity": "sha1-HOYKOleGSiktEyH/RgnKS7llrcg=", - "dev": true - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "is-buffer": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", - "dev": true - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "js-yaml": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.0.5.tgz", - "integrity": "sha1-olrmUJmZ6X3yeMZxnaEb0Gh3Q6g=", - "dev": true, - "requires": { - "argparse": "0.1.16", - "esprima": "1.0.4" - } - }, - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "1.1.6" - } - }, - "lazy-cache": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", - "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", - "dev": true - }, - "lodash": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-0.9.2.tgz", - "integrity": "sha1-jzSZxSRdNG1oLlsNO0B2fgnxqSw=", - "dev": true - }, - "longest": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", - "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true - }, - "lru-cache": { - "version": "2.7.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", - "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", - "dev": true - }, - "maxmin": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/maxmin/-/maxmin-0.2.2.tgz", - "integrity": "sha1-o2ztjMIuOrzRCM+3l6OktAJ1WT8=", - "dev": true, - "requires": { - "chalk": "0.5.1", - "figures": "1.7.0", - "gzip-size": "0.2.0", - "pretty-bytes": "0.1.2" - }, - "dependencies": { - "ansi-styles": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.1.0.tgz", - "integrity": "sha1-6uy/Zs1waIJ2Cy9GkVgrj1XXp94=", - "dev": true - }, - "chalk": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.5.1.tgz", - "integrity": "sha1-Zjs6ZItotV0EaQ1JFnqoN4WPIXQ=", - "dev": true, - "requires": { - "ansi-styles": "1.1.0", - "escape-string-regexp": "1.0.5", - "has-ansi": "0.1.0", - "strip-ansi": "0.3.0", - "supports-color": "0.2.0" - } - }, - "strip-ansi": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.3.0.tgz", - "integrity": "sha1-JfSOoiynkYfzF0pNuHWTR7sSYiA=", - "dev": true, - "requires": { - "ansi-regex": "0.2.1" - } - } - } - }, - "minimatch": { - "version": "0.2.14", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", - "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", - "dev": true, - "requires": { - "lru-cache": "2.7.3", - "sigmund": "1.0.1" - } - }, - "mkdirp": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", - "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", - "dev": true - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "nib": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/nib/-/nib-1.0.4.tgz", - "integrity": "sha1-A9OXwnojHzyaWhkOqmjl154vA0U=", - "dev": true, - "requires": { - "stylus": "0.45.1" - }, - "dependencies": { - "glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", - "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", - "dev": true, - "requires": { - "inherits": "2.0.3", - "minimatch": "0.3.0" - } - }, - "minimatch": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", - "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", - "dev": true, - "requires": { - "lru-cache": "2.7.3", - "sigmund": "1.0.1" - } - }, - "stylus": { - "version": "0.45.1", - "resolved": "https://registry.npmjs.org/stylus/-/stylus-0.45.1.tgz", - "integrity": "sha1-72n2LJhKSArcDJ1KqvsjgqOJ5FM=", - "dev": true, - "requires": { - "css-parse": "1.7.0", - "debug": "3.1.0", - "glob": "3.2.11", - "mkdirp": "0.3.5", - "sax": "0.5.8" - } - } - } - }, - "nopt": { "version": "1.0.10", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", - "integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=", - "dev": true, + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "requires": { - "abbrev": "1.1.1" + "sprintf-js": "~1.0.2" } }, - "noptify": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/noptify/-/noptify-0.0.3.tgz", - "integrity": "sha1-WPZUpz2XU98MUdlobckhBKZ/S7s=", - "dev": true, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + }, + "jquery": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.0.tgz", + "integrity": "sha512-ggRCXln9zEqv6OqAGXFEcshF5dSBvCkzj6Gm2gzuR5fWawaX8t7cxKVkkygKODrDAzKdoYw3l/e3pm3vlT4IbQ==" + }, + "linkify-it": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz", + "integrity": "sha512-4REs8/062kV2DSHxNfq5183zrqXMl7WP0WzABH9IeJI+NLm429FgE1PDecltYfnOoFDFlZGh2T8PfZn0r+GTRg==", "requires": { - "nopt": "2.0.0" - }, - "dependencies": { - "nopt": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-2.0.0.tgz", - "integrity": "sha1-ynQW8gpeP5w7hhgPlilfo9C1Lg0=", - "dev": true, - "requires": { - "abbrev": "1.1.1" - } - } + "uc.micro": "^1.0.1" } }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true - }, - "pako": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", - "integrity": "sha1-8/dSL073gjSNqBYbrZ7P1Rv4OnU=", - "dev": true - }, - "pretty-bytes": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-0.1.2.tgz", - "integrity": "sha1-zZApTVihyk6KXQ+5yCJZmIgazwA=", - "dev": true - }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", - "dev": true - }, - "qs": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/qs/-/qs-0.5.6.tgz", - "integrity": "sha1-MbGtBYVnZRxSaSFQa5qHk5EaA4Q=", - "dev": true - }, - "readable-stream": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", - "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", - "dev": true, + "markdown-it": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", - "util-deprecate": "1.0.2" + "argparse": "^1.0.7", + "entities": "~1.1.1", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" } }, - "repeat-string": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", - "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", - "dev": true - }, - "right-align": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", - "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", - "dev": true, - "requires": { - "align-text": "0.1.4" - } - }, - "rimraf": { - "version": "2.2.8", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", - "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=", - "dev": true - }, - "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true - }, - "sax": { - "version": "0.5.8", - "resolved": "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz", - "integrity": "sha1-1HLbIo6zMcJQaw6MFVJK25OdEsE=", - "dev": true - }, - "sigmund": { + "mdurl": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", - "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", - "dev": true + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=" }, - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true - }, - "string_decoder": { + "sprintf-js": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, - "strip-ansi": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz", - "integrity": "sha1-OeipjQRNFQZgq+SmgIrPcLt7yZE=", + "typescript": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", + "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", "dev": true }, - "stylus": { - "version": "0.46.3", - "resolved": "https://registry.npmjs.org/stylus/-/stylus-0.46.3.tgz", - "integrity": "sha1-C7XWAvY/qAiK0/iv+6LB65JcTXA=", - "dev": true, - "requires": { - "css-parse": "1.7.0", - "debug": "3.1.0", - "glob": "3.2.11", - "mkdirp": "0.3.5", - "sax": "0.5.8" - }, - "dependencies": { - "glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", - "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", - "dev": true, - "requires": { - "inherits": "2.0.3", - "minimatch": "0.3.0" - } - }, - "minimatch": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", - "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", - "dev": true, - "requires": { - "lru-cache": "2.7.3", - "sigmund": "1.0.1" - } - } - } - }, - "supports-color": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-0.2.0.tgz", - "integrity": "sha1-2S3iaU6z9nMjlz1649i1W0wiGQo=", - "dev": true - }, - "tiny-lr-fork": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/tiny-lr-fork/-/tiny-lr-fork-0.0.5.tgz", - "integrity": "sha1-Hpnh4qhGm3NquX2X7vqYxx927Qo=", - "dev": true, - "requires": { - "debug": "0.7.4", - "faye-websocket": "0.4.4", - "noptify": "0.0.3", - "qs": "0.5.6" - }, - "dependencies": { - "debug": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz", - "integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk=", - "dev": true - } - } - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true - }, - "uglify-js": { - "version": "2.8.29", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", - "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", - "dev": true, - "requires": { - "source-map": "0.5.7", - "uglify-to-browserify": "1.0.2", - "yargs": "3.10.0" - } - }, - "uglify-to-browserify": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", - "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", - "dev": true, - "optional": true - }, - "underscore": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", - "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=", - "dev": true - }, - "underscore.string": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.2.1.tgz", - "integrity": "sha1-18D6KvXVoaZ/QlPa7pgTLnM/Dxk=", - "dev": true - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true - }, - "which": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz", - "integrity": "sha1-RgwdoPgQED0DIam2M6+eV15kSG8=", - "dev": true - }, - "window-size": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", - "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", - "dev": true - }, - "wordwrap": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", - "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", - "dev": true - }, - "yargs": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", - "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", - "dev": true, - "requires": { - "camelcase": "1.2.1", - "cliui": "2.1.0", - "decamelize": "1.2.0", - "window-size": "0.1.0" - } + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==" } } } diff --git a/package.json b/package.json index 2a10f49..7f7d044 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,13 @@ "name": "ficdown.js", "version": "0.9.1", "description": "A parser and player for Interactive Fiction written in Ficdown", - "dependencies": {}, + "dependencies": { + "jquery": "^3.4.0", + "markdown-it": "^8.4.2" + }, "devDependencies": { - "coffee-script": "^1.7.1", - "grunt": "^0.4.5", - "grunt-contrib-coffee": "^0.10.1", - "grunt-contrib-uglify": "^0.5.0", - "grunt-contrib-copy": "^0.5.0", - "grunt-contrib-watch": "^0.6.1", - "grunt-contrib-stylus": "^0.17.0" + "@types/jquery": "^3.3.29", + "@types/markdown-it": "0.0.7", + "typescript": "^3.4.5" } } diff --git a/src/Model/Action.ts b/src/Model/Action.ts new file mode 100644 index 0000000..df8755b --- /dev/null +++ b/src/Model/Action.ts @@ -0,0 +1,5 @@ +export type Action = { + lineNumber: number, + state: string, + description: string, +} diff --git a/src/Model/AltText.ts b/src/Model/AltText.ts new file mode 100644 index 0000000..16283d6 --- /dev/null +++ b/src/Model/AltText.ts @@ -0,0 +1,4 @@ +export type AltText = { + passed: string, + failed: string, +} diff --git a/src/Model/Anchor.ts b/src/Model/Anchor.ts new file mode 100644 index 0000000..6e73b9f --- /dev/null +++ b/src/Model/Anchor.ts @@ -0,0 +1,6 @@ +export type Anchor = { + anchor: string, + text: string, + href: string, + title: string, +} diff --git a/src/Model/Block.ts b/src/Model/Block.ts new file mode 100644 index 0000000..935665f --- /dev/null +++ b/src/Model/Block.ts @@ -0,0 +1,14 @@ +import { Line } from './'; + +export enum BlockType { + Action, + Scene, + Story, +} + +export type Block = { + lineNumber: number, + type: BlockType, + name: string, + lines: Line[], +} diff --git a/src/Model/BoolHash.ts b/src/Model/BoolHash.ts new file mode 100644 index 0000000..dd78024 --- /dev/null +++ b/src/Model/BoolHash.ts @@ -0,0 +1 @@ +export type BoolHash = { [name: string]: boolean } diff --git a/src/Model/Href.ts b/src/Model/Href.ts new file mode 100644 index 0000000..77e6343 --- /dev/null +++ b/src/Model/Href.ts @@ -0,0 +1,5 @@ +export type Href = { + target: string, + conditions: string, + toggles: string, +} diff --git a/src/Model/Line.ts b/src/Model/Line.ts new file mode 100644 index 0000000..f105e38 --- /dev/null +++ b/src/Model/Line.ts @@ -0,0 +1,4 @@ +export type Line = { + lineNumber: number, + text: string, +} diff --git a/src/Model/ParseError.ts b/src/Model/ParseError.ts new file mode 100644 index 0000000..571ba4b --- /dev/null +++ b/src/Model/ParseError.ts @@ -0,0 +1,5 @@ +export class ParseError extends Error { + constructor(message: string, public lineNumber: number) { + super(message); + } +} diff --git a/src/Model/PlayerOptions.ts b/src/Model/PlayerOptions.ts new file mode 100644 index 0000000..08c03f2 --- /dev/null +++ b/src/Model/PlayerOptions.ts @@ -0,0 +1,6 @@ +export type PlayerOptions = { + source: string, + id: string, + startText?: string, + endText?: string, +} diff --git a/src/Model/Scene.ts b/src/Model/Scene.ts new file mode 100644 index 0000000..7dc701e --- /dev/null +++ b/src/Model/Scene.ts @@ -0,0 +1,10 @@ +import { BoolHash } from './'; + +export type Scene = { + lineNumber: number, + name: string, + key: string, + description: string, + conditions?: BoolHash, + id?: string; +} diff --git a/src/Model/Story.ts b/src/Model/Story.ts new file mode 100644 index 0000000..74dcf8a --- /dev/null +++ b/src/Model/Story.ts @@ -0,0 +1,9 @@ +import { Scene, Action } from './'; + +export type Story = { + name: string, + description: string, + firstScene: string, + scenes: { [key: string]: Scene[] }, + actions: { [key: string]: Action }, +} diff --git a/src/Model/index.ts b/src/Model/index.ts new file mode 100644 index 0000000..45cdc35 --- /dev/null +++ b/src/Model/index.ts @@ -0,0 +1,11 @@ +export * from './Action'; +export * from './AltText'; +export * from './Anchor'; +export * from './Block'; +export * from './BoolHash'; +export * from './Href'; +export * from './Line'; +export * from './ParseError'; +export * from './PlayerOptions'; +export * from './Scene'; +export * from './Story'; diff --git a/src/Parser.ts b/src/Parser.ts new file mode 100644 index 0000000..1a83f29 --- /dev/null +++ b/src/Parser.ts @@ -0,0 +1,117 @@ +import { + Action, + Block, + BlockType, + BoolHash, + Line, + ParseError, + Scene, + Story, +} from './Model'; +import { Util } from './Util'; + +export class Parser { + public static parse(source: string): Story { + const lines = source.split(/\n|\r\n/); + const blocks = this.extractBlocks(lines); + return this.parseBlocks(blocks); + } + + private static getBlockType(hashCount: 1 | 2 | 3): BlockType { + switch(hashCount) { + case 1: return BlockType.Story; + case 2: return BlockType.Scene; + case 3: return BlockType.Action; + } + } + + private static extractBlocks(lines: string[]): Block[] { + const blocks: Block[] = []; + let currentBlock: Block | undefined = undefined; + for(let i = 0; i < lines.length; i++) { + const match = lines[i].match(/^(#{1,3})\s+([^#].*)$/); + if(match) { + if(currentBlock) blocks.push(currentBlock); + currentBlock = { + lineNumber: i, + type: this.getBlockType(<1 | 2 | 3>match[1].length), + name: match[2], + lines: [], + }; + } else if(currentBlock) { + currentBlock.lines.push({ lineNumber: i, text: lines[i] }); + } + } + if(currentBlock) blocks.push(currentBlock); + return blocks; + } + + private static parseBlocks(blocks: Block[]): Story { + let storyBlock: Block | undefined = + blocks.find(b => b.type === BlockType.Story); + + if(!storyBlock) throw new ParseError('no story block', 0); + const storyName = Util.matchAnchor(storyBlock.name); + if(!storyName) throw new ParseError('no story name', storyBlock.lineNumber); + const storyHref = Util.matchHref(storyName.href); + if(!storyHref) throw new ParseError('no link to first scene', storyBlock.lineNumber); + + const story: Story = { + name: storyName.text, + description: Util.trimText(storyBlock.lines.join("\n")), + firstScene: storyHref.target, + scenes: {}, + actions: {}, + }; + + for(let block of blocks) { + switch(block.type) { + case BlockType.Scene: + const scene = this.blockToScene(block); + if(!story.scenes[scene.key]) story.scenes[scene.key] = []; + story.scenes[scene.key].push(scene); + break; + case BlockType.Action: + const action = this.blockToAction(block); + story.actions[action.state] = action; + break; + } + } + + return story; + } + + private static blockToScene(block: Block): Scene { + const sceneName = Util.matchAnchor(block.name); + let name: string | undefined = undefined; + let key: string; + let conditions: BoolHash | undefined = undefined; + if(sceneName) { + name = sceneName.title + ? Util.trimText(sceneName.title) + : Util.trimText(sceneName.text); + key = Util.normalize(sceneName.text); + const href = Util.matchHref(sceneName.href); + if(href && href.conditions) conditions = + Util.toBoolHash(href.conditions.split('&')); + } else { + name = Util.trimText(block.name); + key = Util.normalize(block.name); + } + return { + name, + key, + conditions, + description: Util.trimText(block.lines.join("\n")), + lineNumber: block.lineNumber, + }; + } + + private static blockToAction(block: Block): Action { + return { + state: Util.normalize(block.name), + description: Util.trimText(block.lines.join("\n")), + lineNumber: block.lineNumber, + }; + } +} diff --git a/src/Player.ts b/src/Player.ts new file mode 100644 index 0000000..8b72b98 --- /dev/null +++ b/src/Player.ts @@ -0,0 +1,30 @@ +import { + BoolHash, + PlayerOptions, + Scene, + Story, +} from './Model'; +import { Parser } from './Parser'; +import * as Markdown from 'markdown-it'; +import * as $ from 'jquery'; + +export class Player { + private static converter = new Markdown(); + private container: JQuery; + private playerState: BoolHash = {}; + private visitedScenes: BoolHash = {}; + private currentScene?: Scene; + private moveCounter: number = 0; + private story: Story; + + constructor(private options: PlayerOptions) { + this.story = Parser.parse(options.source); + let i = 0; + for(let [key, scenes] of Object.entries(this.story.scenes)) { + for(let scene of scenes) scene.id = `#s${ ++i }`; + } + this.container = $(`#${ options.id }`); + this.container.addClass('ficdown').data('player', this); + } + +} diff --git a/src/Util.ts b/src/Util.ts new file mode 100644 index 0000000..1f910f1 --- /dev/null +++ b/src/Util.ts @@ -0,0 +1,97 @@ +import { Anchor, Href, BoolHash, AltText } from './Model'; + +export class Util { + private static regexLib: { [name: string]: RegExp } = { + anchors: /(\[((?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[\])*\])*\])*\])*\])*\])*)\]\([ ]*((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\(\))*\))*\))*\))*\))*\))*)[ ]*((['"])(.*?)\5[ ]*)?\))/gm, + + href: /^(?:\/([a-zA-Z](?:-?[a-zA-Z0-9])*))?(?:\?((?:!?[a-zA-Z](?:-?[a-zA-Z0-9])*)(?:&!?[a-zA-Z](?:-?[a-zA-Z0-9])*)*)?)?(?:#((?:[a-zA-Z](?:-?[a-zA-Z0-9])*)(?:\+[a-zA-Z](?:-?[a-zA-Z0-9])*)*))?$/, + + trim: /^\s+|\s+$/g, + + altText: /^((?:[^|\\]|\\.)*)(?:\|((?:[^|\\]|\\.)+))?$/, + + escapeChar: /\\(?=[^\\])/g, + + emptyListItem: /^[ ]*-\s*([\r\n]+|$)/gm, + }; + + private static matchToAnchor(match: RegExpExecArray): Anchor { + const result: Anchor = { + anchor: match[1], + text: match[2], + href: match[3], + title: match[6], + }; + if(result.href.indexOf('"') === 0) { + result.title = result.href.substring(1, result.href.length - 1); + result.href = ''; + } + return result; + } + + public static matchAnchor(text: string): Anchor | undefined { + const match = this.regexLib.anchors.exec(text); + if(match) return this.matchToAnchor(match); + } + + public static matchAnchors(text: string): Anchor[] { + let match: RegExpExecArray | null; + const anchors: Anchor[] = []; + while(match = this.regexLib.anchors.exec(text)) { + anchors.push(this.matchToAnchor(match)); + } + return anchors; + } + + public static matchHref(text: string): Href | undefined { + const match = this.regexLib.href.exec(text); + if(match) { + return { + target: match[1], + conditions: match[2], + toggles: match[3], + }; + } + } + + public static trimText(text: string): string { + return text.replace(this.regexLib.trim, ''); + } + + public static normalize(text: string): string { + return text.toLowerCase().replace(/^\W+|\W+$/g, '').replace(/\W+/g, '-'); + } + + public static toBoolHash(names: string[]): BoolHash | undefined { + if(names) { + const hash: BoolHash = {}; + for(let name of names) { + if(name.indexOf('!') === 0) { + hash[name.substring(1, name.length)] = false; + } else { + hash[name] = true; + } + } + return hash; + } + } + + public static conditionsMet(state: BoolHash, conditions: BoolHash): boolean { + for(let [cond, val] of Object.entries(conditions)) { + if((val && !state[cond]) || (!val && state[cond])) { + return false; + } + } + return true; + } + + public static splitAltText(text: string): AltText | undefined { + const match = this.regexLib.altText.exec(text); + if(match) { + return { + passed: match[0], + failed: match[1], + }; + } + } +} diff --git a/src/parser.coffee b/src/parser.coffee deleted file mode 100644 index 7aefa68..0000000 --- a/src/parser.coffee +++ /dev/null @@ -1,76 +0,0 @@ -parseText = (text) -> - lines = text.split /\n|\r\n/ - blocks = extractBlocks lines - story = parseBlocks blocks - -getBlockType = (hashCount) -> - switch hashCount - when 1 then 'story' - when 2 then 'scene' - when 3 then 'action' - -extractBlocks = (lines) -> - blocks = [] - currentBlock = null - for line in lines - match = line.match /^(#{1,3})\s+([^#].*)$/ - if match? - if currentBlock != null - blocks.push currentBlock - currentBlock = - type: getBlockType match[1].length - name: match[2] - lines: [] - else - currentBlock.lines.push line - if currentBlock != null - blocks.push currentBlock - return blocks - -parseBlocks = (blocks) -> - storyBlock = null - for block in blocks - if block.type == 'story' - storyBlock = block - break - storyName = matchAnchor storyBlock.name - storyHref = matchHref storyName.href - story = - name: storyName.text - description: trimText storyBlock.lines.join "\n" - firstScene: storyHref.target - scenes: {} - actions: {} - for block in blocks - switch block.type - when 'scene' - scene = blockToScene block - if !story.scenes[scene.key] - story.scenes[scene.key] = [] - story.scenes[scene.key].push scene - when 'action' - action = blockToAction block - story.actions[action.state] = action - return story - -blockToScene = (block) -> - sceneName = matchAnchor block.name - if sceneName? - title = if sceneName.title? then trimText sceneName.title else trimText sceneName.text - key = normalize sceneName.text - href = matchHref sceneName.href - if href?.conditions? - conditions = toBoolHash href.conditions.split '&' - else - title = trimText block.name - key = normalize block.name - scene = - name: if title != '' then title else null - key: key - description: trimText block.lines.join "\n" - conditions: if conditions? then conditions else null - -blockToAction = (block) -> - action = - state: normalize block.name - description: trimText block.lines.join "\n" diff --git a/src/util.coffee b/src/util.coffee deleted file mode 100644 index b84b6be..0000000 --- a/src/util.coffee +++ /dev/null @@ -1,89 +0,0 @@ -regexLib = - - anchors: /(\[((?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[(?:[^\[\]]+|\[\])*\])*\])*\])*\])*\])*)\]\([ ]*((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\((?:[^()\s]+|\(\))*\))*\))*\))*\))*\))*)[ ]*((['"])(.*?)\5[ ]*)?\))/gm - - href: /^(?:\/([a-zA-Z](?:-?[a-zA-Z0-9])*))?(?:\?((?:!?[a-zA-Z](?:-?[a-zA-Z0-9])*)(?:&!?[a-zA-Z](?:-?[a-zA-Z0-9])*)*)?)?(?:#((?:[a-zA-Z](?:-?[a-zA-Z0-9])*)(?:\+[a-zA-Z](?:-?[a-zA-Z0-9])*)*))?$/ - - trim: /^\s+|\s+$/g - - altText: /^((?:[^|\\]|\\.)*)(?:\|((?:[^|\\]|\\.)+))?$/ - - escapeChar: /\\(?=[^\\])/g - - emptyListItem: /^[ ]*-\s*([\r\n]+|$)/gm - -matchAnchor = (text) -> - re = new RegExp regexLib.anchors - match = re.exec text - if match? - result = - anchor: match[1] - text: match[2] - href: match[3] - title: match[6] - if result.href.indexOf('"') == 0 - result.title = result.href.substring 1, result.href.length - 1 - result.href = '' - return result - return match - -matchAnchors = (text) -> - re = new RegExp regexLib.anchors - anchors = [] - while match = re.exec text - anchor = - anchor: match[1] - text: match[2] - href: match[3] - title: match[6] - if anchor.href.indexOf('"') == 0 - anchor.title = anchor.href.substring 1, anchor.href.length - 1 - anchor.href = '' - anchors.push anchor - return anchors - -trimText = (text) -> - text.replace regexLib.trim, '' - -matchHref = (href) -> - re = new RegExp regexLib.href - match = re.exec href - if match? - result = - target: match[1] - conditions: match[2] - toggles: match[3] - return result - return match - -normalize = (text) -> - text.toLowerCase().replace(/^\W+|\W+$/g, '').replace /\W+/g, '-' - -toBoolHash = (names) -> - if !names? - return null - hash = {} - for name in names - if name.indexOf('!') == 0 - hash[name.substring 1, name.length] = false - else - hash[name] = true - return hash - -conditionsMet = (state, conditions) -> - met = true - for cond, val of conditions - if (val and !state[cond]) or (!val and state[cond]) - met = false - break - return met - -splitAltText = (text) -> - re = new RegExp regexLib.altText - match = re.exec text - if match? - result = - passed: match[1] - failed: match[2] - return result - return diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1c9bb3f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "lib": [ "es2017" ], + "target": "es6", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "./build", + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "strict": true, + "sourceMap": true + } +}