tildefriends/apps/api/app.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
99 KiB
JavaScript
Raw Normal View History

import * as docs from 'docs.js';
/* commonmark 0.30 https://github.com/commonmark/commonmark.js @license BSD3 */
let self = {};
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).commonmark={})}(this,function(e){"use strict";function i(e){switch(e._type){case"document":case"block_quote":case"list":case"item":case"paragraph":case"heading":case"emph":case"strong":case"link":case"image":case"custom_inline":case"custom_block":return!0;default:return!1}}function r(e,r){this.current=e,this.entering=!0===r}function t(){var e=this.current,r=this.entering;if(null===e)return null;var t=i(e);return r&&t?e._firstChild?(this.current=e._firstChild,this.entering=!0):this.entering=!1:e===this.root?this.current=null:null===e._next?(this.current=e._parent,this.entering=!1):(this.current=e._next,this.entering=!0),{entering:r,node:e}}function n(e){return{current:e,root:e,entering:!0,next:t,resumeAt:r}}function b(e,r){this._type=e,this._parent=null,this._firstChild=null,this._lastChild=null,this._prev=null,this._next=null,this._sourcepos=r,this._lastLineBlank=!1,this._lastLineChecked=!1,this._open=!0,this._string_content=null,this._literal=null,this._listData={},this._info=null,this._destination=null,this._title=null,this._isFenced=!1,this._fenceChar=null,this._fenceLength=0,this._fenceOffset=null,this._level=null,this._onEnter=null,this._onExit=null}var a=b.prototype;Object.defineProperty(a,"isContainer",{get:function(){return i(this)}}),Object.defineProperty(a,"type",{get:function(){return this._type}}),Object.defineProperty(a,"firstChild",{get:function(){return this._firstChild}}),Object.defineProperty(a,"lastChild",{get:function(){return this._lastChild}}),Object.defineProperty(a,"next",{get:function(){return this._next}}),Object.defineProperty(a,"prev",{get:function(){return this._prev}}),Object.defineProperty(a,"parent",{get:function(){return this._parent}}),Object.defineProperty(a,"sourcepos",{get:function(){return this._sourcepos}}),Object.defineProperty(a,"literal",{get:function(){return this._literal},set:function(e){this._literal=e}}),Object.defineProperty(a,"destination",{get:function(){return this._destination},set:function(e){this._destination=e}}),Object.defineProperty(a,"title",{get:function(){return this._title},set:function(e){this._title=e}}),Object.defineProperty(a,"info",{get:function(){return this._info},set:function(e){this._info=e}}),Object.defineProperty(a,"level",{get:function(){return this._level},set:function(e){this._level=e}}),Object.defineProperty(a,"listType",{get:function(){return this._listData.type},set:function(e){this._listData.type=e}}),Object.defineProperty(a,"listTight",{get:function(){return this._listData.tight},set:function(e){this._listData.tight=e}}),Object.defineProperty(a,"listStart",{get:function(){return this._listData.start},set:function(e){this._listData.start=e}}),Object.defineProperty(a,"listDelimiter",{get:function(){return this._listData.delimiter},set:function(e){this._listData.delimiter=e}}),Object.defineProperty(a,"onEnter",{get:function(){return this._onEnter},set:function(e){this._onEnter=e}}),Object.defineProperty(a,"onExit",{get:function(){return this._onExit},set:function(e){this._onExit=e}}),b.prototype.appendChild=function(e){e.unlink(),(e._parent=this)._lastChild?(this._lastChild._next=e)._prev=this._lastChild:this._firstChild=e,this._lastChild=e},b.prototype.prependChild=function(e){e.unlink(),(e._parent=this)._firstChild?((this._firstChild._prev=e)._next=this._firstChild,this._firstChild=e):(this._firstChild=e,this._lastChild=e)},b.prototype.unlink=function(){this._prev?this._prev._next=this._next:this._parent&&(this._parent._firstChild=this._next),this._next?this._next._prev=this._prev:this._parent&&(this._parent._lastChild=this._prev),this._parent=null,this._next=null,this._prev=null},b.prototype.insertAfter=function(e){e.unlink(),e._next=this._next,e._next&&(e._next._prev=e),((e._prev=this)._next=e)._parent=this._parent,e._next||(e._parent._lastChild=e)},b.prototype.insertBefore=function(e){e.unlink(),e._prev=this._prev,e._prev&&(e._prev._next=e),((e._next=this)._prev=e)._parent=this._parent,e._p
let commonmark = self.commonmark;
function* treeify(prefix, o) {
if (typeof(o) == 'object') {
for (let [k, v] of Object.entries(o)) {
for (let e of treeify(`${prefix ? prefix + '.' : ''}${k}`, v)) {
yield e;
}
}
} else if (typeof(o) == 'function') {
yield prefix + '()';
} else if (typeof(o) == 'string' || typeof(o) == 'number') {
yield `${prefix} = ${o}`;
}
}
function markdown(md) {
let parsed = new commonmark.Parser().parse(md ?? '*undocumented*');
return new commonmark.HtmlRenderer().render(parsed);
}
function document(api) {
let doc = markdown(docs.docs[api.split(' = ')[0]]);
return `
<a name="${api}"></a>
<h2 style="color: #aaf">${api}</h2>
<div>${doc}</div>
`;
}
app.setDocument(`<head>
<base target="_top">
<style type="text/css">
a:link {
color: #268bd2;
}
a:visited {
color: #6c71c4;
}
a:hover {
color: #859900;
}
a:active {
color: #2aa198;
}
</style>
</head>
<body style="color:#fff">
${markdown(docs.docs.global)}
${[...treeify('', globalThis)].map(x => document(x)).join('\n')}
<a id="Database"></a>
${markdown(docs.docs.database)}
${['database.get()', 'database.set()', 'database.exchange()', 'database.remove()', 'database.getAll()', 'database.getLike()'].map(x => document(x)).join('\n')}
${markdown(docs.docs.tfrpc)}
${['tfrpc.register()', 'tfrpc.rpc.*()'].map(x => document(x)).join('\n')}
<script>
window.onload = function() {
console.log('load');
for (let tag of document.getElementsByTagName('a')) {
console.log(tag.href);
tag.onclick = function() {
document.getElementById(tag.href.split('#')[1]).scrollIntoView();
return false;
}
delete tag.href;
}
}
</script>
</body>`);