larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

145
webGl/my-threejs-test/node_modules/posthtml/lib/api.js generated vendored Normal file
View File

@@ -0,0 +1,145 @@
'use strict'
/**
* # API
*
* @author Ivan Voischev (@voischev),
* Anton Winogradov (@awinogradov),
* Alexej Yaroshevich (@zxqfox),
* Vasiliy (@Yeti-or)
*
* @namespace tree
*/
function Api () {
this.walk = walk
this.match = match
}
/**
* Walks the tree and passes all nodes via a callback
*
* @memberof tree
*
* @param {Function} cb Callback
* @return {Function} Callback(node)
*
*@example
* ```js
* export const walk = (tree) => {
* tree.walk((node) => {
* let classes = node.attrs && node.attrs.class.split(' ') || []
*
* if (classes.includes(className)) return cb(node)
* return node
* })
* }
* ```
*/
function walk (cb) {
return traverse(this, cb)
}
/**
* Matches an expression to search for nodes in the tree
*
* @memberof tree
*
* @param {String|RegExp|Object|Array} expression - Matcher(s) to search
* @param {Function} cb Callback
*
* @return {Function} Callback(node)
*
* @example
* ```js
* export const match = (tree) => {
* // Single matcher
* tree.match({ tag: 'custom-tag' }, (node) => {
* let tag = node.tag
*
* Object.assign(node, { tag: 'div', attrs: {class: tag} })
*
* return node
* })
* // Multiple matchers
* tree.match([{ tag: 'b' }, { tag: 'strong' }], (node) => {
* let style = 'font-weight: bold;'
*
* node.tag = 'span'
*
* node.attrs
* ? ( node.attrs.style
* ? ( node.attrs.style += style )
* : node.attrs.style = style
* )
* : node.attrs = { style: style }
*
* return node
* })
* }
* ```
*/
function match (expression, cb) {
return Array.isArray(expression)
? traverse(this, node => {
for (let i = 0; i < expression.length; i++) {
if (compare(expression[i], node)) return cb(node)
}
return node
})
: traverse(this, node => {
if (compare(expression, node)) return cb(node)
return node
})
}
module.exports = Api
module.exports.match = match
module.exports.walk = walk
/** @private */
function traverse (tree, cb) {
if (Array.isArray(tree)) {
for (let i = 0; i < tree.length; i++) {
tree[i] = traverse(cb(tree[i]), cb)
}
} else if (
tree &&
typeof tree === 'object' &&
Object.prototype.hasOwnProperty.call(tree, 'content')
) traverse(tree.content, cb)
return tree
}
/** @private */
function compare (expected, actual) {
if (expected instanceof RegExp) {
if (typeof actual === 'object') return false
if (typeof actual === 'string') return expected.test(actual)
}
if (typeof expected !== typeof actual) return false
if (typeof expected !== 'object' || expected === null) {
return expected === actual
}
if (Array.isArray(expected)) {
return expected.every(exp => [].some.call(actual, act => compare(exp, act)))
}
return Object.keys(expected).every(key => {
const ao = actual[key]
const eo = expected[key]
if (typeof eo === 'object' && eo !== null && ao !== null) {
return compare(eo, ao)
}
if (typeof eo === 'boolean') {
return eo !== (ao == null)
}
return ao === eo
})
}

View File

@@ -0,0 +1,323 @@
const pkg = require('../package.json')
const Api = require('./api.js')
let { parser } = require('posthtml-parser')
let { render } = require('posthtml-render')
/**
* @author Ivan Voischev (@voischev),
* Ivan Demidov (@scrum)
*
* @requires api
* @requires posthtml-parser
* @requires posthtml-render
*
* @constructor PostHTML
* @param {Array} plugins - An array of PostHTML plugins
*/
class PostHTML {
constructor (plugins) {
/**
* PostHTML Instance
*
* @prop plugins
* @prop options
*/
this.version = pkg.version
this.name = pkg.name
this.plugins = typeof plugins === 'function' ? [plugins] : plugins || []
this.source = ''
/**
* Tree messages to store and pass metadata between plugins
*
* @memberof tree
* @type {Array} messages
*
* @example
* ```js
* export default function plugin (options = {}) {
* return function (tree) {
* tree.messages.push({
* type: 'dependency',
* file: 'path/to/dependency.html',
* from: tree.options.from
* })
*
* return tree
* }
* }
* ```
*/
this.messages = []
/**
* Tree method parsing string inside plugins.
*
* @memberof tree
* @type {Function} parser
*
* @example
* ```js
* export default function plugin (options = {}) {
* return function (tree) {
* tree.match({ tag: 'include' }, function(node) {
* node.tag = false;
* node.content = tree.parser(fs.readFileSync(node.attr.src))
* return node
* })
*
* return tree
* }
* }
* ```
*/
this.parser = parser
/**
* Tree method rendering tree to string inside plugins.
*
* @memberof tree
* @type {Function} render
*
* @example
* ```js
* export default function plugin (options = {}) {
* return function (tree) {
* var outherTree = ['\n', {tag: 'div', content: ['1']}, '\n\t', {tag: 'div', content: ['2']}, '\n'];
* var htmlWitchoutSpaceless = tree.render(outherTree).replace(/[\n|\t]/g, '');
* return tree.parser(htmlWitchoutSpaceless)
* }
* }
* ```
*/
this.render = render
// extend api methods
Api.call(this)
}
/**
* @this posthtml
* @param {Function} plugin - A PostHTML plugin
* @returns {Constructor} - this(PostHTML)
*
* **Usage**
* ```js
* ph.use((tree) => { tag: 'div', content: tree })
* .process('<html>..</html>', {})
* .then((result) => result))
* ```
*/
use (...args) {
this.plugins.push(...args)
return this
}
/**
* @param {String} html - Input (HTML)
* @param {?Object} options - PostHTML Options
* @returns {Object<{html: String, tree: PostHTMLTree}>} - Sync Mode
* @returns {Promise<{html: String, tree: PostHTMLTree}>} - Async Mode (default)
*
* **Usage**
*
* **Sync**
* ```js
* ph.process('<html>..</html>', { sync: true }).html
* ```
*
* **Async**
* ```js
* ph.process('<html>..</html>', {}).then((result) => result))
* ```
*/
process (tree, options = {}) {
/**
* ## PostHTML Options
*
* @type {Object}
* @prop {?Boolean} options.sync - enables sync mode, plugins will run synchronously, throws an error when used with async plugins
* @prop {?Function} options.parser - use custom parser, replaces default (posthtml-parser)
* @prop {?Function} options.render - use custom render, replaces default (posthtml-render)
* @prop {?Boolean} options.skipParse - disable parsing
* @prop {?Array} options.directives - Adds processing of custom [directives](https://github.com/posthtml/posthtml-parser#directives).
*/
this.options = options
this.source = tree
if (options.parser) parser = this.parser = options.parser
if (options.render) render = this.render = options.render
tree = options.skipParse
? tree || []
: parser(tree, options)
tree = [].concat(tree)
// sync mode
if (options.sync === true) {
this.plugins.forEach((plugin, index) => {
_treeExtendApi(tree, this)
let result
if (plugin.length === 2 || isPromise(result = plugin(tree))) {
throw new Error(
`Cant process contents in sync mode because of async plugin: ${plugin.name}`
)
}
// clearing the tree of options
if (index !== this.plugins.length - 1 && !options.skipParse) {
tree = [].concat(tree)
}
// return the previous tree unless result is fulfilled
tree = result || tree
})
return lazyResult(render, tree)
}
// async mode
let i = 0
const next = (result, cb) => {
_treeExtendApi(result, this)
// all plugins called
if (this.plugins.length <= i) {
cb(null, result)
return
}
// little helper to go to the next iteration
function _next (res) {
if (res && !options.skipParse) {
res = [].concat(res)
}
return next(res || result, cb)
}
// call next
const plugin = this.plugins[i++]
if (plugin.length === 2) {
plugin(result, (err, res) => {
if (err) return cb(err)
_next(res)
})
return
}
// sync and promised plugins
let err = null
const res = tryCatch(() => plugin(result), e => {
err = e
return e
})
if (err) {
cb(err)
return
}
if (isPromise(res)) {
res.then(_next).catch(cb)
return
}
_next(res)
}
return new Promise((resolve, reject) => {
next(tree, (err, tree) => {
if (err) reject(err)
else resolve(lazyResult(render, tree))
})
})
}
}
/**
* @exports posthtml
*
* @param {Array} plugins
* @return {Function} posthtml
*
* **Usage**
* ```js
* import posthtml from 'posthtml'
* import plugin from 'posthtml-plugin'
*
* const ph = posthtml([ plugin() ])
* ```
*/
module.exports = plugins => new PostHTML(plugins)
/**
* Extension of options tree
*
* @private
*
* @param {Array} tree
* @param {Object} PostHTML
* @returns {?*}
*/
function _treeExtendApi (t, _t) {
if (typeof t === 'object') {
t = Object.assign(t, _t)
}
}
/**
* Checks if parameter is a Promise (or thenable) object.
*
* @private
*
* @param {*} promise - Target `{}` to test
* @returns {Boolean}
*/
function isPromise (promise) {
return !!promise && typeof promise.then === 'function'
}
/**
* Simple try/catch helper, if exists, returns result
*
* @private
*
* @param {Function} tryFn - try block
* @param {Function} catchFn - catch block
* @returns {?*}
*/
function tryCatch (tryFn, catchFn) {
try {
return tryFn()
} catch (err) {
catchFn(err)
}
}
/**
* Wraps the PostHTMLTree within an object using a getter to render HTML on demand.
*
* @private
*
* @param {Function} render
* @param {Array} tree
* @returns {Object<{html: String, tree: Array}>}
*/
function lazyResult (render, tree) {
return {
get html () {
return render(tree, tree.options)
},
tree,
messages: tree.messages
}
}

21
webGl/my-threejs-test/node_modules/posthtml/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2015 PostHTML
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.

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var i=class{constructor(t){this.source=t,this.lastPosition={line:1,column:1},this.lastIndex=0}getPosition(t){if(t<this.lastIndex)throw new Error("Source indices must be monotonic");for(;this.lastIndex<t;)this.source.charCodeAt(this.lastIndex)===10?(this.lastPosition.line++,this.lastPosition.column=1):this.lastPosition.column++,this.lastIndex++;return{line:this.lastPosition.line,column:this.lastPosition.column}}};exports.a = i;

View File

@@ -0,0 +1,27 @@
import { ParserOptions } from 'htmlparser2';
import { SourceLocation } from './location-tracker';
declare type Directive = {
name: string | RegExp;
start: string;
end: string;
};
declare type Options = {
directives?: Directive[];
sourceLocations?: boolean;
recognizeNoValueAttribute?: boolean;
} & ParserOptions;
declare type Tag = string | boolean;
declare type Attributes = Record<string, string | number | boolean>;
declare type Content = NodeText | Array<Node | Node[]>;
declare type NodeText = string | number;
declare type NodeTag = {
tag?: Tag;
attrs?: Attributes;
content?: Content;
location?: SourceLocation;
};
declare type Node = NodeText | NodeTag;
declare const parser: (html: string, options?: Options) => Node[];
export { Attributes, Content, Directive, Node, NodeTag, NodeText, Options, Tag, parser };

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk2UQLUWPHjs = require('./chunk.2UQLUWPH.js');var _htmlparser2 = require('htmlparser2');var I={lowerCaseTags:!1,lowerCaseAttributeNames:!1,decodeEntities:!1},P=[{name:"!doctype",start:"<",end:">"}],w= exports.parser =(g,c={})=>{let a=new (0, _chunk2UQLUWPHjs.a)(g),i=[],s=[],p=0,f={};function u(){return i[i.length-1]}function y(n,t){return n.name instanceof RegExp?new RegExp(n.name.source,"i").test(t):t===n.name}function x(n){let t={};return Object.keys(n).forEach(e=>{let o={};o[e]=String(n[e]).replace(/&quot;/g,'"'),c.recognizeNoValueAttribute&&f[e]&&(o[e]=!0),Object.assign(t,o)}),t}function A(n,t){var l;let e=P.concat((l=c.directives)!=null?l:[]),o=u();for(let d of e){let b=d.start+t+d.end;if(y(d,n.toLowerCase())){if(o===void 0){s.push(b);return}typeof o=="object"&&(o.content===void 0&&(o.content=[]),Array.isArray(o.content)&&o.content.push(b))}}}function N(n){let t=u(),e=`<!--${n}-->`;if(t===void 0){s.push(e);return}typeof t=="object"&&(t.content===void 0&&(t.content=[]),Array.isArray(t.content)&&t.content.push(e))}function m(n,t,e){e===void 0&&(f[n]=!0)}function h(n,t){let e={tag:n};c.sourceLocations&&(e.location={start:a.getPosition(r.startIndex),end:a.getPosition(r.endIndex)},p=r.endIndex),Object.keys(t).length>0&&(e.attrs=x(t)),f={},i.push(e)}function T(n,t){let e=i.pop();if(e&&typeof e=="object"&&e.location&&r.endIndex!==null&&(t?p<r.startIndex&&(e.location.end=a.getPosition(r.startIndex-1)):e.location.end=a.getPosition(r.endIndex)),e){let o=u();if(i.length<=0){s.push(e);return}typeof o=="object"&&(o.content===void 0&&(o.content=[]),Array.isArray(o.content)&&o.content.push(e))}}function v(n){let t=u();if(t===void 0){s.push(n);return}if(typeof t=="object"){if(t.content&&Array.isArray(t.content)&&t.content.length>0){let e=t.content[t.content.length-1];if(typeof e=="string"&&!e.startsWith("<!--")){t.content[t.content.length-1]=`${e}${n}`;return}}t.content===void 0&&(t.content=[]),Array.isArray(t.content)&&t.content.push(n)}}let r=new (0, _htmlparser2.Parser)({onprocessinginstruction:A,oncomment:N,onattribute:m,onopentag:h,onclosetag:T,ontext:v},{...I,...c});return r.write(g),r.end(),s};exports.parser = w;

View File

@@ -0,0 +1,17 @@
declare type SourceLocation = {
start: Position;
end: Position;
};
declare type Position = {
line: number;
column: number;
};
declare class LocationTracker {
private readonly source;
private lastPosition;
private lastIndex;
constructor(source: string);
getPosition(index: number): Position;
}
export { LocationTracker, Position, SourceLocation };

View File

@@ -0,0 +1 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk2UQLUWPHjs = require('./chunk.2UQLUWPH.js');exports.LocationTracker = _chunk2UQLUWPHjs.a;

View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2015 Ivan Voischev <voischev.ivan@ya.ru>
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.

View File

@@ -0,0 +1,69 @@
{
"name": "posthtml-parser",
"version": "0.11.0",
"description": "Parse HTML/XML to PostHTMLTree",
"license": "MIT",
"repository": "posthtml/posthtml-parser",
"homepage": "https://github.com/posthtml/posthtml-parser#readme",
"bugs": {
"url": "https://github.com/posthtml/posthtml-parser/issues"
},
"author": "Ivan Voischev <voischev@posthtml.org>",
"contributors": [
{
"name": "Ivan Voischev",
"email": "voischev@posthtml.org"
},
{
"name": "Ivan Demidov",
"email": "scrum@posthtml.org"
}
],
"main": "dist",
"engines": {
"node": ">=12"
},
"scripts": {
"version": "conventional-changelog -i changelog.md -s -r 0 && git add changelog.md",
"build": "rm -rf dist && tsup src/*.ts --dts --minify",
"dev": "npm run build -- --watch",
"test": "xo && c8 ava",
"pretest": "clinton",
"prepare": "npm run build"
},
"files": [
"dist"
],
"keywords": [
"html",
"xml",
"parser",
"posthtml",
"posthtmltree"
],
"dependencies": {
"htmlparser2": "^7.1.1"
},
"devDependencies": {
"@antfu/eslint-config-ts": "^0.4.3",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-angular": "^11.0.0",
"@types/node": "^14.14.25",
"ava": "^3.13.0",
"c8": "^7.5.0",
"clinton": "^0.14.0",
"conventional-changelog-cli": "^2.0.34",
"esbuild-register": "^2.0.0",
"eslint": "^7.19.0",
"esm": "^3.2.25",
"husky": "^4.3.8",
"lint-staged": "^10.5.3",
"rewire": "^5.0.0",
"rimraf": "^3.0.0",
"ts-node": "^9.0.0",
"tsup": "^3.7.1",
"typescript": "^4.0.5",
"xo": "^0.37.1"
},
"types": "dist/index.d.ts"
}

View File

@@ -0,0 +1,130 @@
# posthtml-parser
[![npm version](https://badge.fury.io/js/posthtml-parser.svg)](http://badge.fury.io/js/posthtml-parser)
[![Build Status](https://travis-ci.org/posthtml/posthtml-parser.svg?branch=master)](https://travis-ci.org/posthtml/posthtml-parser?branch=master)
[![Coverage Status](https://coveralls.io/repos/posthtml/posthtml-parser/badge.svg?branch=master)](https://coveralls.io/r/posthtml/posthtml-parser?branch=master)
Parse HTML/XML to [PostHTML AST](https://github.com/posthtml/posthtml-parser#posthtml-ast-format).
More about [PostHTML](https://github.com/posthtml/posthtml#readme)
## Install
[NPM](http://npmjs.com) install
```
$ npm install posthtml-parser
```
## Usage
#### Input HTML
```html
<a class="animals" href="#">
<span class="animals__cat" style="background: url(cat.png)">Cat</span>
</a>
```
```js
import { parser } from 'posthtml-parser'
import fs from 'fs'
const html = fs.readFileSync('path/to/input.html', 'utf-8')
console.log(parser(html)) // Logs a PostHTML AST
```
#### input HTML
```html
<a class="animals" href="#">
<span class="animals__cat" style="background: url(cat.png)">Cat</span>
</a>
```
#### Result PostHTMLTree
```js
[{
tag: 'a',
attrs: {
class: 'animals',
href: '#'
},
content: [
'\n ',
{
tag: 'span',
attrs: {
class: 'animals__cat',
style: 'background: url(cat.png)'
},
content: ['Cat']
},
'\n'
]
}]
```
## PostHTML AST Format
Any parser being used with PostHTML should return a standard PostHTML [Abstract Syntax Tree](https://www.wikiwand.com/en/Abstract_syntax_tree) (AST). Fortunately, this is a very easy format to produce and understand. The AST is an array that can contain strings and objects. Any strings represent plain text content to be written to the output. Any objects represent HTML tags.
Tag objects generally look something like this:
```js
{
tag: 'div',
attrs: {
class: 'foo'
},
content: ['hello world!']
}
```
Tag objects can contain three keys. The `tag` key takes the name of the tag as the value. This can include custom tags. The optional `attrs` key takes an object with key/value pairs representing the attributes of the html tag. A boolean attribute has an empty string as its value. Finally, the optional `content` key takes an array as its value, which is a PostHTML AST. In this manner, the AST is a tree that should be walked recursively.
## Options
### `directives`
Type: `Array`
Default: `[{name: '!doctype', start: '<', end: '>'}]`
Description: *Adds processing of custom directives. Note: The property ```name``` in custom directives can be ```String``` or ```RegExp``` type*
### `xmlMode`
Type: `Boolean`
Default: `false`
Description: *Indicates whether special tags (`<script>` and `<style>`) should get special treatment and if "empty" tags (eg. `<br>`) can have children. If false, the content of special tags will be text only. For feeds and other XML content (documents that don't consist of HTML), set this to true.*
### `decodeEntities`
Type: `Boolean`
Default: `false`
Description: *If set to true, entities within the document will be decoded.*
### `lowerCaseTags`
Type: `Boolean`
Default: `false`
Description: *If set to true, all tags will be lowercased. If `xmlMode` is disabled.*
### `lowerCaseAttributeNames`
Type: `Boolean`
Default: `false`
Description: *If set to true, all attribute names will be lowercased. This has noticeable impact on speed.*
### `recognizeCDATA`
Type: `Boolean`
Default: `false`
Description: *If set to true, CDATA sections will be recognized as text even if the `xmlMode` option is not enabled. NOTE: If `xmlMode` is set to `true` then CDATA sections will always be recognized as text.*
### `recognizeSelfClosing`
Type: `Boolean`
Default: `false`
Description: *If set to true, self-closing tags will trigger the `onclosetag` event even if `xmlMode` is not set to `true`. NOTE: If `xmlMode` is set to `true` then self-closing tags will always be recognized.*
### `sourceLocations`
Type: `Boolean`
Default: `false`
Description: *If set to true, AST nodes will have a `location` property containing the `start` and `end` line and column position of the node.*
### `recognizeNoValueAttribute`
Type: `Boolean`
Default: `false`
Description: *If set to true, AST nodes will recognize attribute with no value and mark as `true` which will be correctly rendered by `posthtml-render` package*
## License
[MIT](LICENSE)

View File

@@ -0,0 +1,64 @@
{
"name": "posthtml",
"version": "0.16.6",
"description": "HTML/XML processor",
"keywords": [
"html",
"xml",
"postproccessor",
"parser",
"transform",
"transformations",
"manipulation",
"preprocessor",
"processor"
],
"main": "lib",
"types": "types/posthtml.d.ts",
"files": [
"types",
"lib"
],
"engines": {
"node": ">=12.0.0"
},
"dependencies": {
"posthtml-parser": "^0.11.0",
"posthtml-render": "^3.0.0"
},
"devDependencies": {
"@commitlint/cli": "^16.2.1",
"@commitlint/config-angular": "^16.2.1",
"c8": "^7.7.3",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"conventional-changelog-cli": "^2.1.1",
"husky": "^7.0.1",
"jsdoc-to-markdown": "^7.0.1",
"lint-staged": "^12.3.4",
"mocha": "^9.0.3",
"standard": "^16.0.2"
},
"scripts": {
"version": "conventional-changelog -i changelog.md -s -r 0 && git add changelog.md",
"test": "c8 mocha",
"docs:api": "jsdoc2md lib/api.js > docs/api.md",
"docs:core": "jsdoc2md lib/index.js > docs/core.md"
},
"author": "Ivan Voischev <voischev.ivan@ya.ru>",
"contributors": [
{
"name": "Ivan Voischev",
"email": "voischev.ivan@ya.ru"
},
{
"name": "Ivan Demidov",
"email": "scrum@list.ru"
}
],
"homepage": "https://posthtml.org",
"repository": "https://github.com/posthtml/posthtml.git",
"bugs": "https://github.com/posthtml/posthtml/issues",
"license": "MIT"
}

412
webGl/my-threejs-test/node_modules/posthtml/readme.md generated vendored Normal file
View File

@@ -0,0 +1,412 @@
[![NPM][npm]][npm-url]
[![Deps][deps]][deps-url]
[![Tests][build]][build-url]
[![Coverage][cover]][cover-url]
[![Standard Code Style][code-style]][code-style-url]
[![Twitter][twitter]][twitter-url]
# PostHTML <img align="right" width="220" height="200" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg">
PostHTML is a tool for transforming HTML/XML with JS plugins. PostHTML itself is very small. It includes only a HTML parser, a HTML node tree API and a node tree stringifier.
All HTML transformations are made by plugins. And these plugins are just small plain JS functions, which receive a HTML node tree, transform it, and return a modified tree.
For more detailed information about PostHTML in general take a look at the [docs][docs-url].
### Dependencies
| Name | Status | Description |
|:----:|:------:|:-----------:|
|[posthtml-parser][parser]|[![npm][parser-badge]][parser-npm]| Parser HTML/XML to PostHTMLTree |
|[posthtml-render][render]|[![npm][render-badge]][render-npm]| Render PostHTMLTree to HTML/XML |
[docs]: https://github.com/posthtml/posthtml/blob/master/docs
[parser]: https://github.com/posthtml/posthtml-parser
[parser-badge]: https://img.shields.io/npm/v/posthtml-parser.svg
[parser-npm]: https://npmjs.com/package/posthtml-parser
[render]: https://github.com/posthtml/posthtml-render
[render-badge]: https://img.shields.io/npm/v/posthtml-render.svg
[render-npm]: https://npmjs.com/package/posthtml-render
## Create to your project
```bash
npm init posthtml
```
## Install
```bash
npm i -D posthtml
```
## Usage
### API
**Sync**
```js
import posthtml from 'posthtml'
const html = `
<component>
<title>Super Title</title>
<text>Awesome Text</text>
</component>
`
const result = posthtml()
.use(require('posthtml-custom-elements')())
.process(html, { sync: true })
.html
console.log(result)
```
```html
<div class="component">
<div class="title">Super Title</div>
<div class="text">Awesome Text</div>
</div>
```
> :warning: Async Plugins can't be used in sync mode and will throw an Error. It's recommended to use PostHTML asynchronously whenever possible.
**Async**
```js
import posthtml from 'posthtml'
const html = `
<html>
<body>
<p class="wow">OMG</p>
</body>
</html>
`
posthtml(
[
require('posthtml-to-svg-tags')(),
require('posthtml-extend-attrs')({
attrsTree: {
'.wow' : {
id: 'wow_id',
fill: '#4A83B4',
'fill-rule': 'evenodd',
'font-family': 'Verdana'
}
}
})
])
.process(html/*, options */)
.then((result) => console.log(result.html))
```
```html
<svg xmlns="http://www.w3.org/2000/svg">
<text
class="wow"
id="wow_id"
fill="#4A83B4"
fill-rule="evenodd" font-family="Verdana">
OMG
</text>
</svg>
```
**Directives**
```js
import posthtml from 'posthtml'
const php = `
<component>
<title><?php echo $title; ?></title>
<text><?php echo $article; ?></text>
</component>
`
const result = posthtml()
.use(require('posthtml-custom-elements')())
.process(html, {
directives: [
{ name: '?php', start: '<', end: '>' }
]
})
.html
console.log(result)
```
```html
<div class="component">
<div class="title"><?php echo $title; ?></div>
<div class="text"><?php echo $article; ?></div>
</div>
```
### [CLI](https://npmjs.com/package/posthtml-cli)
```bash
npm i posthtml-cli
```
```json
"scripts": {
"posthtml": "posthtml -o output.html -i input.html -c config.json"
}
```
```bash
npm run posthtml
```
### [Gulp](https://gulpjs.com)
```bash
npm i -D gulp-posthtml
```
```js
import tap from 'gulp-tap'
import posthtml from 'gulp-posthtml'
import { task, src, dest } from 'gulp'
task('html', () => {
let path
const plugins = [ require('posthtml-include')({ root: `${path}` }) ]
const options = {}
src('src/**/*.html')
.pipe(tap((file) => path = file.path))
.pipe(posthtml(plugins, options))
.pipe(dest('build/'))
})
```
Check [project-stub](https://github.com/posthtml/project-stub) for an example with Gulp
### [Grunt](https://gruntjs.com)
```bash
npm i -D grunt-posthtml
```
```js
posthtml: {
options: {
use: [
require('posthtml-doctype')({ doctype: 'HTML 5' }),
require('posthtml-include')({ root: './', encoding: 'utf-8' })
]
},
build: {
files: [
{
dot: true,
cwd: 'html/',
src: ['*.html'],
dest: 'tmp/',
expand: true,
}
]
}
}
```
### [Webpack](https://webpack.js.org)
```bash
npm i -D html-loader posthtml-loader
```
#### v1.x
**webpack.config.js**
```js
const config = {
module: {
loaders: [
{
test: /\.html$/,
loader: 'html!posthtml'
}
]
},
posthtml: (ctx) => ({
parser: require('posthtml-pug'),
plugins: [
require('posthtml-bem')()
]
})
}
export default config
```
#### v2.x
**webpack.config.js**
```js
import { LoaderOptionsPlugin } from 'webpack'
const config = {
module: {
rules: [
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true }
},
{
loader: 'posthtml-loader'
}
]
}
]
},
plugins: [
new LoaderOptionsPlugin({
options: {
posthtml(ctx) {
return {
parser: require('posthtml-pug'),
plugins: [
require('posthtml-bem')()
]
}
}
}
})
]
}
export default config
```
### [Rollup](https://rollupjs.org/)
```bash
$ npm i rollup-plugin-posthtml -D
# or
$ npm i rollup-plugin-posthtml-template -D
```
```js
import { join } from 'path';
import posthtml from 'rollup-plugin-posthtml-template';
// or
// import posthtml from 'rollup-plugin-posthtml';
import sugarml from 'posthtml-sugarml'; // npm i posthtml-sugarml -D
import include from 'posthtml-include'; // npm i posthtml-include -D
export default {
entry: join(__dirname, 'main.js'),
dest: join(__dirname, 'bundle.js'),
format: 'iife',
plugins: [
posthtml({
parser: sugarml(),
plugins: [include()],
template: true // only rollup-plugin-posthtml-template
})
]
};
```
## Parser
```js
import pug from 'posthtml-pug'
posthtml().process(html, { parser: pug(options) }).then((result) => result.html)
```
| Name |Status|Description|
|:-----|:-----|:----------|
|[posthtml-pug][pug]|[![npm][pug-badge]][pug-npm]|Pug Parser|
|[sugarml][sugar]|[![npm][sugar-badge]][sugar-npm]|SugarML Parser|
[pug]: https://github.com/posthtml/posthtml-pug
[pug-badge]: https://img.shields.io/npm/v/posthtml-pug.svg
[pug-npm]: https://npmjs.com/package/posthtml-pug
[sugar]: https://github.com/posthtml/sugarml
[sugar-badge]: https://img.shields.io/npm/v/sugarml.svg
[sugar-npm]: https://npmjs.com/package/sugarml
## Plugins
In case you want to develop your own plugin, we recommend using [posthtml-plugin-starter][plugin] to get started.
- [posthtml-plugins](http://maltsev.github.io/posthtml-plugins)
- [awesome-posthtml](https://github.com/posthtml/awesome-posthtml)
[plugin]: https://github.com/posthtml/posthtml-plugin-starter
## Maintainers
<table>
<tbody>
<tr>
<td align="center">
<img width="150 height="150"
src="https://avatars0.githubusercontent.com/u/2789192?s=460&v=4">
<br />
<a href="https://github.com/scrum">Ivan Demidov</a>
</td>
<td align="center">
<img width="150 height="150"
src="https://avatars.githubusercontent.com/u/1510217?v=3&s=150">
<br />
<a href="https://github.com/voischev">Ivan Voischev</a>
</td>
</tr>
<tbody>
</table>
## Contributors
<a href="https://github.com/posthtml/posthtml/graphs/contributors"><img src="https://opencollective.com/posthtml/contributors.svg?width=890&button=false" /></a>
## Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/posthtml#backer)]
<a href="https://opencollective.com/posthtml#backers" target="_blank"><img src="https://opencollective.com/posthtml/backers.svg?width=885&button=false"></a>
[npm]: https://img.shields.io/npm/v/posthtml.svg
[npm-url]: https://npmjs.com/package/posthtml
[deps]: https://david-dm.org/posthtml/posthtml.svg
[deps-url]: https://david-dm.org/posthtml/posthtml
[build]: https://github.com/posthtml/posthtml/workflows/Actions%20Status/badge.svg?style=flat-square
[build-url]: https://github.com/posthtml/posthtml/actions?query=workflow%3A%22CI+tests%22
[cover]: https://coveralls.io/repos/posthtml/posthtml/badge.svg?branch=master
[cover-url]: https://coveralls.io/r/posthtml/posthtml?branch=master
[code-style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[code-style-url]: http://standardjs.com/
[twitter]: https://badgen.net/twitter/follow/posthtml
[twitter-url]: https://twitter.com/PostHTML
[chat]: https://badges.gitter.im/posthtml/PostHTML.svg
[chat-url]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"
[docs-url]: https://github.com/posthtml/posthtml/tree/master/docs

View File

@@ -0,0 +1,108 @@
type Maybe<T> = void | T;
type MaybeArray<T> = T | T[];
declare namespace PostHTML {
type StringMatcher = string | RegExp;
type AttrMatcher = Record<string, StringMatcher>;
type ContentMatcher =
| StringMatcher[]
| {
tag?: StringMatcher;
attrs?: AttrMatcher;
content?: ContentMatcher[];
};
export type Matcher<
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>
> =
| StringMatcher
| {
tag?: TTag;
attrs?: TAttrs;
content?: ContentMatcher[];
};
export type Expression<
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>
> = MaybeArray<Matcher<TTag, TAttrs>>;
export type NodeCallback<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> = (node: Node<TTag, TAttrs>) => MaybeArray<Node | RawNode>;
export type NodeAttributes = Record<string, Maybe<string>>;
interface NodeAPI {
walk: (cb: NodeCallback) => Node;
match: <
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>,
TTagResult extends Maybe<string> = TTag extends string
? TTag
: TTag extends void
? Maybe<string>
: string,
TAttrResult extends Maybe<NodeAttributes> = TAttrs extends void
? Maybe<NodeAttributes>
: {
[P in keyof TAttrs]: string;
} &
NodeAttributes
>(
expression: Expression<TTag, TAttrs>,
cb: NodeCallback<TTagResult, TAttrResult>
) => Node<TTagResult, TAttrResult>[];
}
export interface RawNode<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> {
tag: TTag;
attrs: TAttrs;
content?: Array<string | RawNode>;
}
export interface Node<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> extends NodeAPI, RawNode<TTag, TAttrs> {
content?: Array<string | Node>;
options?: Options;
}
export interface Options {
sync?: boolean;
parser?: Function;
render?: Function;
skipParse?: boolean;
}
export type Plugin<TThis> = (
tree: Node
) => void | Node | RawNode | ThisType<TThis>;
export interface Result<TMessage> {
html: string;
tree: Node;
messages: TMessage[];
}
export interface PostHTML<TThis, TMessage> {
version: string;
name: "";
plugins: Plugin<TThis>[];
messages: TMessage[];
use<TThis>(plugins: MaybeArray<Plugin<TThis>>): this;
process(html: string, options?: Options): Promise<Result<TMessage>>;
}
}
declare function PostHTML<TThis, TMessage>(
plugins?: PostHTML.Plugin<TThis>[]
): PostHTML.PostHTML<TThis, TMessage>;
export = PostHTML;