diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..943f5e9f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,8 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # not working due missing www. +open_collective: hyperHTML +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +custom: https://www.patreon.com/webreflection diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..58f187be --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 00000000..73cf8d65 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: build + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm test + - run: npm run coverage --if-present + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 58b805fe..3cb01d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store -node_modules/ \ No newline at end of file +node_modules/ +coverage/ + diff --git a/.npmignore b/.npmignore index 9e31fc7d..2b02e166 100644 --- a/.npmignore +++ b/.npmignore @@ -1,14 +1,14 @@ coverage/* -dist/* -docs/* +esm/.eslintrc logo/* node_modules/* -repl/* test/* _config.yml .DS_Store .gitignore .travis.yml -bundler.js -hyperhtml.js -package-lock.json \ No newline at end of file +.github/ISSUE_TEMPLATE.md +babel-plugins.json +CHANGELOG.md +package-lock.json +rollup.config.js diff --git a/.travis.yml b/.travis.yml index 69660b1f..cc127136 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: node_js node_js: - - 8 + - stable git: depth: 1 branches: only: - master + - /^greenkeeper/.*$/ after_success: - - "npm run coveralls" \ No newline at end of file + - "npm run coveralls" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..60ac2164 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,147 @@ +# hyper(html) Changelog + +### v.2.23 + * monkey patched rollup generated code to export once the same module shared within sub-modules + +### v2.22 + * using latest domtagger + +### v2.21 + * refactored out all dependencies + +### v2.20 + * re-tested every single supported browser nd fixed few outstanding issues with the 2.19 release + +### v2.19 + * refactored out most of the code + * finally managed to have coveralls show coverage stats + * attributes can have spaces around as per DOM standard - [#244](https://github.com/WebReflection/hyperHTML/issues/224) + * fixed SVG (non-critical) errors when interpolations are used for numerically expected values + * fixed minor issues with Edge attributes + * changed the unique id so if any of your logic was trusting `_hyper: ....;` comments you need to update your logic - [#300](https://github.com/WebReflection/hyperHTML/issues/300) + +### v2.16.8 + * improved MutationObserver and fallback so that double `dis/connected` events won't happen again + * exposed `observe` utility for 3rd parts so that it is possible to observe any node, not only those defined via template literals. Once observed, a node can have `connected` and `disconnected` listeners that will be triggered automatically. + +### v2.16 + * modified `Wire` class to better handle "_same target_" case, making the `haunted.html` demo work same way as if it was bound to the node, through `valueOf()` invoke which would result in just exactly the same node if the wired content produced a node instead of a fragment. While regular users won't be affected, this is an implementation detail that changes a lot for libraries integrating `hyperHTML.wire` in their logic, making wires as fast as `bind` in most component related use cases. + +### v2.15 + * added [invokable slots](https://github.com/WebReflection/hyperHTML/pull/282#issuecomment-433614081) to let developers explore patterns through callbacks that will receive a unique live node for weak references while rendered. + +### v2.14 + * updated [domdiff](https://github.com/WebReflection/domdiff#domdiff) to match [petit-dom](https://github.com/yelouafi/petit-dom) performance + * up to 3X performance on huge lists + * improved reliability over random changes + * unfortunately there's a +0.6K overall size increase due amount of extra logic involved + +### v2.13.2 + * added support for custom CSS properties as object keys. + +### v2.13.1 + * worked around [TypeScript transpilation bug with Template Literals](https://twitter.com/WebReflection/status/1038115439539363840). + +### v2.13 + * added the ability to define custom attributes via `hyperHTML.define("hyper-attribute", callback)`, so that `
` would invoke `callback(target, anyValue)` where `p` would be the target.
+
+### v2.12
+ * added `hyper.Component#dispatch(type, detail)` method to simplify events dispatching between lightweight components, bubbling a cancelable Custom Event with a `.component` property that points at the dispatcher, while the `event.currentTarget` will be the first node found within the component render.
+
+### v2.11
+ * updated [domdiff](https://github.com/WebReflection/domdiff#domdiff) to v1.0
+
+### v2.10.12
+ * patched missing `.children` in SVG node in IE / Edge https://github.com/WebReflection/hyperHTML/issues/244
+
+### v2.10.10
+ * updated [domdiff](https://github.com/WebReflection/domdiff#domdiff) to solve issue #243 (breaking with some sorted list)
+
+### v2.10.5
+ * various fixes and changes after [changes applied to ECMAScript 2015](https://github.com/tc39/ecma262/pull/890)
+
+### v2.8.0
+ * updated [domdiff](https://github.com/WebReflection/domdiff#domdiff) engine to boost performance with segments and lists
+
+### v2.7.2
+ * fixed #218 which was a variant of #200
+
+### v2.7.0
+ * the `Component.for(obj)` is now created first time via `new Component(obj)` - #216
+
+### v2.6.0
+ * declarative hyper.Component via `Component.for(context, uid?)` - #202
+ * hyperHTML TypeScript information - #201
+
+### v2.5.12
+ * fixed #200: textarea/style with initial undefined value
+
+### v2.5.11
+ * fixed #198: connected/disconnected events for nested components
+
+### v2.5.10
+ * more rigid / explicit RegExp to avoid glitches with self-closing tags
+
+### v2.5.8
+ * improved `VOID_ELEMENTS` regular expression (aligned with the _viperHTML_ one)
+
+### v2.5.7
+ * fixed `no.js` patch when wrong count of args is passed
+
+### v2.5.6
+ * added `no.js` file for environments without the ability to use modern JS or based on other languages such Dart.
+
+### v2.5.5
+ * build runs on macOS too
+ * added umd.js file
+
+### v2.5.2
+ * fixed weird SVG case (see #172)
+
+### v2.5.1
+ * improved self-closing reliability recycling and sharing attributes RegExp
+
+### v2.5.0
+ * updated `domdiff` library to the latest version
+ * implemented self-closing tags (and after various tests)
+
+### v2.4.3
+ * ensure attributes values are updated when different from previous one
+ * avoid the usage of the word `global` in the whole code
+
+### v2.4.2
+ * fix scripts with actual content too.
+
+### v2.4.1
+ * fix a bug with scripts that don't trigger network requests in both Firefox and Safari (see bug #152)
+
+### v2.4.0
+ * created a `Wire` class to handle via `domdiff` multiple wired nodes.
+ * brought back multi nodes per wire, a feature lost since **v2.0**
+ * simplified `Component` handling too, making it compatible again with multi wired content.
+ * fixed some check to make IE9+ tests green again
+
+### v2.3.0
+ * dropped the `engine` already. Too complex, no real benefits, refactored the whole internal logic to use [domdiff](https://github.com/WebReflection/domdiff) instead. Deprecated [hyperhtml-majinbuu](https://github.com/WebReflection/hyperhtml-majinbuu) and solved diffing "_forever_".
+
+### v2.2.0
+ * the whole `hyperHTML.engine` has been refactored to use [dom-splicer](https://github.com/WebReflection/dom-splicer) as an effort to make engine development easier
+
+### v2.1.3
+ * the MutationObserver is installed only once and only if there are components that have _on(dis)?connect_ handlers.
+
+### v2.1.2
+ * using a new folders convention with `esm/index.js` as main module and `cjs/index.js` as transformed artifact. This plays very well with bundlers when you `import {hyper} from 'hyperhtml/esm'` or `const {hyper} = require('hyperhtml/cjs');`
+
+### v2.1.1
+ * fast changes where prepending or appending same lists; now dropping upfront or removing at the end are part of the fast path too.
+
+### v2.1.0
+
+ * created a simple default merge engine focused on performance
+ * remove majinbuu as core dependency, created [hyperhtml-majinbuu](https://github.com/WebReflection/hyperhtml-majinbuu) project to swap it back via `hyperHTML.engine = require('hyperhtml-majinbuu')` or as ESM
+ * reduced final bundle size down to 4.1K via brotli
+
+## v2.0.0
+
+Refactoring following ticket #140
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..fb3f291f
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,67 @@
+# Contribute
+
+## Introduction
+
+First, thank you for considering contributing to hyperhtml! It's people like you that make the open source community such a great community! ๐
+
+We welcome any type of contribution, not only code. You can help with
+- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
+- **Marketing**: writing blog posts, howto's, printing stickers, ...
+- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
+- **Code**: take a look at the [open issues](issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them.
+- **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/hyperhtml).
+
+## Your First Contribution
+
+Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
+
+## Submitting code
+
+Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests.
+
+## Code review process
+
+The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.
+It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you?
+
+## Financial contributions
+
+We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/hyperhtml).
+Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.
+
+## Questions
+
+If you have any questions, create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!).
+You can also reach us at hello@hyperhtml.opencollective.com.
+
+## Credits
+
+### Contributors
+
+Thank you to all the people who have already contributed to hyperhtml!
+
+
+
+### Backers
+
+Thank you to all our backers! [[Become a backer](https://opencollective.com/hyperhtml#backer)]
+
+
+
+
+### Sponsors
+
+Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/hyperhtml#sponsor))
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HELPERS.md b/HELPERS.md
new file mode 100644
index 00000000..d0f8aefb
--- /dev/null
+++ b/HELPERS.md
@@ -0,0 +1,57 @@
+## [babel-plugin-remove-ungap]
+
+Remove the [@ungap ponyfill modules] from your bundle. This will decrease the size of
+your bundle if you are targeting modern browsers only or if your build already includes
+other polyfills. This has been tested with [hyperHTML] and [lighterhtml] bundles.
+
+
+## [babel-plugin-template-html-minifier]
+
+Run [html-minifier] on hyperHTML templates.
+
+
+## [babel-plugin-bare-import-rewrite]
+
+This can be used as an alternative to [rollup-plugin-node-resolve], or can be used with certain node.js
+web servers to allow browsing live from source.
+
+Known web server integrations:
+* [fastify-babel] plugin for [fastify] enables running any babel plugins, generally expects `payload.filename` as set by [fastify-static]
+* [express-transform-bare-module-specifiers] for [express] servers
+
+
+## [vinyl-rollup]
+
+This module copies the output of rollup builds to a stream of vinyl-fs objects for [gulp].
+In addition it optionally adds files from modules that were bundled into the stream. This
+makes it easy to ensure that LICENSE and package.json files associated with bundled modules
+are published on the web server without publishing node.js server-side dependencies to the web.
+This can also be used to copy complete modules if required for licensing or if bundled code
+requires additional assets that are not part of the bundled JS (images for example).
+
+
+## [babel-plugin-bundled-import-meta]
+
+If `node_modules/some-web-component/index.js` uses `import.meta.url` to calculate the actual
+path to `node_modules/some-web-components/image.png`, rollup does not compensate. This babel
+plugin rewrites references to `import.meta.url` so it points to the original location where
+it is expected that the additional assets (images and such) can be found. This plugin works
+well with `vinyl-rollup` with `copyModules: true`.
+
+
+[babel-plugin-remove-ungap]: https://github.com/cfware/babel-plugin-remove-ungap#readme
+[@ungap ponyfill modules]: https://github.com/ungap/ungap.github.io#readme
+[hyperHTML]: https://github.com/WebReflection/hyperHTML#readme
+[lighterhtml]: https://github.com/WebReflection/lighterhtml#readme
+[babel-plugin-template-html-minifier]: https://github.com/cfware/babel-plugin-template-html-minifier#readme
+[html-minifier]: https://github.com/kangax/html-minifier#readme
+[babel-plugin-bare-import-rewrite]: https://github.com/cfware/babel-plugin-bare-import-rewrite#readme
+[rollup-plugin-node-resolve]: https://github.com/rollup/rollup-plugin-node-resolve#readme
+[fastify]: https://github.com/fastify/fastify#readme
+[fastify-babel]: https://github.com/cfware/fastify-babel#readme
+[fastify-static]: https://github.com/fastify/fastify-static#readme
+[express-transform-bare-module-specifiers]: https://github.com/nodecg/express-transform-bare-module-specifiers#readme
+[express]: https://github.com/expressjs/express#readme
+[vinyl-rollup]: https://github.com/cfware/vinyl-rollup#readme
+[gulp]: https://github.com/gulpjs/gulp#readme
+[babel-plugin-bundled-import-meta]: https://github.com/cfware/babel-plugin-bundled-import-meta#readme
diff --git a/README.md b/README.md
index 6ebe2ca3..72f7e51a 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,120 @@
# hyper(HTML)
-[](https://opensource.org/licenses/ISC) [](https://travis-ci.org/WebReflection/hyperHTML) [](https://coveralls.io/github/WebReflection/hyperHTML?branch=master) [](https://github.com/WebReflection/donate)
+### Maintainance Only
+This module is great, works great, and served me greatly, but there's a pletora of modern, faster, more capable alternatives me, among many other OSS developers, offer so that if obvious bugs are proven to exist, these will be fixed, but there won't be a major release and I won't remove legacy support for stuff that, as previously mentioned, works just fine and it's battle-tested from IE to the latest Chrome.
+
+Removing that legacy support brings pretty much nothing in terms of size too: this module is already smaller than 90% of alternatives out there, dropping 0.xK so that there's less code that, behind feature detection, is not even used in modern browsers, won't benefit anyone.
+
+Thansk for your understanding and for not opening PRs which goal is to drop a check for legacy browsers ... these won't likely be merged ever as that'd be a major release update and I don't think anyone is interested in that.
+
+### ๐ฃ Community Announcement
+
+Please ask questions in the [dedicated discussions repository](https://github.com/WebReflection/discussions), to help the community around this project grow โฅ
+
+- - -
-A **Fast & Light Virtual DOM Alternative** available for [NodeJS](https://viperhtml.js.org/viper.html) and [NativeScript](https://viperhtml.js.org/native.html) too.
+A **Fast & Light Virtual DOM Alternative**.
+
- - -
-### Warning
+[](https://github.com/WebReflection/donate) [](#backers) [](#sponsors) 
+
+[](https://coveralls.io/github/WebReflection/hyperHTML?branch=master)
+[](https://travis-ci.org/WebReflection/hyperHTML)
+[](https://opensource.org/licenses/ISC)
+[](https://greenkeeper.io/) 
+
+- - -
+
+Following an overview of projects related, or inspired by, _hyperHTML_. For a deep comparison of current libraries, feel free to [check this gist out](https://gist.github.com/WebReflection/761052d6dae7c8207d2fcba7cdede295).
+
+
+## ยตhtml
+
+The latest, smallest, iteration of all best concept from this library since 2017, have been packaged in _~2.5K_. If it's extreme minimalism and great _DX_ that you are after, check [uhtml](https://github.com/WebReflection/uhtml#readme) out.
+
+
+## hypersimple
+
+If you've just started with template literals based projects and you like components, or you'd like to understand what's _hyperHTML_ capable of, give [hypersimple](https://github.com/WebReflection/hypersimple#readme) a try ๐
+
+
+## lighterhtml ๐ก
+
+This little brother is "_showing off_" these days, claiming better performance and unprecedented ease of use.
+
+[GitHub Repository](https://github.com/WebReflection/lighterhtml)
+
+
+## Neverland ๐๐ฆ
+
+If you like React hooks concept, don't miss this little wrap that adds 0._something_ overhead to the already lightweight hyperHTML, bringing in very similar concepts.
+
+[Blog Post](https://medium.com/@WebReflection/neverland-the-hyperhtmls-hook-a0c3e11324bb)
+
+[GitHub Repository](https://github.com/WebReflection/neverland)
+
+## Haunted ๐ฆ ๐
+
+If you also like React hooks mechanism and you'd like to combine these via hyperHTML or [HyperHTMLElement](https://github.com/WebReflection/hyperHTML-Element), try [haunted](https://github.com/matthewp/haunted#haunted--) out!
+
+
+## Bundlers
+
+You can require or import _hyperHTML_ with any bundler and in different ways.
+
+If requiring or importing from `"hyperhtml"` doesn't work, try requiring from `"hyperhtml/cjs"` for CommonJS friendly bundlers (WebPack), or `"hyperhtml/esm"` for ESM compatible bundlers (Rollup).
+
+See [HELPERS.md](./HELPERS.md) for a list of additional tools which can be helpful for building hyperHTML based web applications.
+
+- - -
+
+## Sponsors
+
+Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/hyperhtml#sponsor)]
-Current **master** branch is currently under heavy refactoring.
+
-Please use the [official site](https://viperhtml.js.org) to check examples on Code Pen and/or read the documentation.
+## Backers
+
+Thank you to all our backers! ๐ [[Become a backer](https://opencollective.com/hyperhtml#backer)]
+
+
+
+## Contributors
+
+This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
+
+
+- - -
+
+### 2.34 Highlights
+
+ * the new `?boolean=${value}` syntax from [ยตhtml](https://github.com/WebReflection/uhtml#readme) has landed in *hyperHTML* too. Feel free to [read this long discussion](https://github.com/WebReflection/discussions/discussions/13) to better understand *why* this syntax is necessary.
+
+### V2.5 Highlights
+
+ * `
that's it
`; } + // used to distinguish better than instanceof + ELEMENT_NODE: {value: 1}, + nodeType: {value: -1} } ); diff --git a/cjs/classes/Path.js b/cjs/classes/Path.js deleted file mode 100644 index 7069424a..00000000 --- a/cjs/classes/Path.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; -const { - ATTRIBUTE_NODE, - COMMENT_NODE, - DOCUMENT_FRAGMENT_NODE, - ELEMENT_NODE -} = require('../shared/constants.js'); - -const {children} = require('../shared/utils.js'); - -const createPath = node => { - const path = []; - let parentNode; - switch (node.nodeType) { - case ELEMENT_NODE: - case DOCUMENT_FRAGMENT_NODE: - parentNode = node; - break; - case COMMENT_NODE: - parentNode = node.parentNode; - path.unshift( - 'childNodes', - path.indexOf.call(parentNode.childNodes, node) - ); - break; - case ATTRIBUTE_NODE: - default: // jsdom here does not provide a nodeType 2 ... - parentNode = node.ownerElement; - path.unshift('attributes', node.name); - break; - } - for ( - node = parentNode; - (parentNode = parentNode.parentNode); - node = parentNode - ) { - path.unshift('children', path.indexOf.call(children(parentNode), node)); - } - return path; -}; - -function Path(type, node, name) { - return {type, name, path: createPath(node)}; -} -Object.defineProperty(exports, '__esModule', {value: true}).default = Path \ No newline at end of file diff --git a/cjs/hyper/render.js b/cjs/hyper/render.js new file mode 100644 index 00000000..a401a66b --- /dev/null +++ b/cjs/hyper/render.js @@ -0,0 +1,39 @@ +'use strict'; +const WeakMap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/weakmap')); +const tta = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/template-tag-arguments')); + +const {OWNER_SVG_ELEMENT} = require('../shared/constants.js'); +const {Tagger} = require('../objects/Updates.js'); + +// a weak collection of contexts that +// are already known to hyperHTML +const bewitched = new WeakMap; + +// better known as hyper.bind(node), the render is +// the main tag function in charge of fully upgrading +// or simply updating, contexts used as hyperHTML targets. +// The `this` context is either a regular DOM node or a fragment. +function render() { + const wicked = bewitched.get(this); + const args = tta.apply(null, arguments); + if (wicked && wicked.template === args[0]) { + wicked.tagger.apply(null, args); + } else { + upgrade.apply(this, args); + } + return this; +} + +// an upgrade is in charge of collecting template info, +// parse it once, if unknown, to map all interpolations +// as single DOM callbacks, relate such template +// to the current context, and render it after cleaning the context up +function upgrade(template) { + const type = OWNER_SVG_ELEMENT in this ? 'svg' : 'html'; + const tagger = new Tagger(type); + bewitched.set(this, {tagger, template: template}); + this.textContent = ''; + this.appendChild(tagger.apply(null, arguments)); +} + +Object.defineProperty(exports, '__esModule', {value: true}).default = render; diff --git a/cjs/hyper/wire.js b/cjs/hyper/wire.js index 638f8a06..139eaaba 100644 --- a/cjs/hyper/wire.js +++ b/cjs/hyper/wire.js @@ -1,4 +1,84 @@ 'use strict'; -const wire = {}; +const WeakMap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/weakmap')); +const tta = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/template-tag-arguments')); +const Wire = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('hyperhtml-wire')); + +const {Tagger} = require('../objects/Updates.js'); + +// all wires used per each context +const wires = new WeakMap; + +// A wire is a callback used as tag function +// to lazily relate a generic object to a template literal. +// hyper.wire(user)`${{user}}
`; + define: (intent, callback) => { + if (intent.indexOf('-') < 0) { + if (!(intent in intents)) { + length = keys.push(intent); + } + intents[intent] = callback; + } else { + attributes[intent] = callback; + } + }, + + // this method is used internally as last resort + // to retrieve a value out of an object + invoke: (object, callback) => { + for (let i = 0; i < length; i++) { + let key = keys[i]; + if (hasOwnProperty.call(object, key)) { + return intents[key](object[key], callback); + } + } + } +}; diff --git a/cjs/objects/Updates.js b/cjs/objects/Updates.js new file mode 100644 index 00000000..0df2e324 --- /dev/null +++ b/cjs/objects/Updates.js @@ -0,0 +1,377 @@ +'use strict'; +const CustomEvent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/custom-event')); +const WeakSet = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/essential-weakset')); +const isArray = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/is-array')); +const createContent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/create-content')); + +const disconnected = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('disconnected')); +const domdiff = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('domdiff')); +const domtagger = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('domtagger')); +const hyperStyle = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('hyperhtml-style')); +const Wire = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('hyperhtml-wire')); + +const { + CONNECTED, DISCONNECTED, DOCUMENT_FRAGMENT_NODE, OWNER_SVG_ELEMENT +} = require('../shared/constants.js'); + +const Component = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('../classes/Component.js')); +const Intent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('./Intent.js')); + +const componentType = Component.prototype.nodeType; +const wireType = Wire.prototype.nodeType; + +const observe = disconnected({Event: CustomEvent, WeakSet}); + +exports.Tagger = Tagger; +exports.observe = observe; + +// returns an intent to explicitly inject content as html +const asHTML = html => ({html}); + +// returns nodes from wires and components +const asNode = (item, i) => { + switch (item.nodeType) { + case wireType: + // in the Wire case, the content can be + // removed, post-pended, inserted, or pre-pended and + // all these cases are handled by domdiff already + /* istanbul ignore next */ + return (1 / i) < 0 ? + (i ? item.remove(true) : item.lastChild) : + (i ? item.valueOf(true) : item.firstChild); + case componentType: + return asNode(item.render(), i); + default: + return item; + } +} + +// returns true if domdiff can handle the value +const canDiff = value => 'ELEMENT_NODE' in value; + +// borrowed from uhandlers +// https://github.com/WebReflection/uhandlers +const booleanSetter = (node, key, oldValue) => newValue => { + if (oldValue !== !!newValue) { + if ((oldValue = !!newValue)) + node.setAttribute(key, ''); + else + node.removeAttribute(key); + } +}; + +const hyperSetter = (node, name, svg) => svg ? + value => { + try { + node[name] = value; + } + catch (nope) { + node.setAttribute(name, value); + } + } : + value => { + node[name] = value; + }; + +// when a Promise is used as interpolation value +// its result must be parsed once resolved. +// This callback is in charge of understanding what to do +// with a returned value once the promise is resolved. +const invokeAtDistance = (value, callback) => { + callback(value.placeholder); + if ('text' in value) { + Promise.resolve(value.text).then(String).then(callback); + } else if ('any' in value) { + Promise.resolve(value.any).then(callback); + } else if ('html' in value) { + Promise.resolve(value.html).then(asHTML).then(callback); + } else { + Promise.resolve(Intent.invoke(value, callback)).then(callback); + } +}; + +// quick and dirty way to check for Promise/ish values +const isPromise_ish = value => value != null && 'then' in value; + +// list of attributes that should not be directly assigned +const readOnly = /^(?:form|list)$/i; + +// reused every slice time +const slice = [].slice; + +// simplifies text node creation +const text = (node, text) => node.ownerDocument.createTextNode(text); + +function Tagger(type) { + this.type = type; + return domtagger(this); +} + +Tagger.prototype = { + + // there are four kind of attributes, and related behavior: + // * events, with a name starting with `on`, to add/remove event listeners + // * special, with a name present in their inherited prototype, accessed directly + // * regular, accessed through get/setAttribute standard DOM methods + // * style, the only regular attribute that also accepts an object as value + // so that you can style=${{width: 120}}. In this case, the behavior has been + // fully inspired by Preact library and its simplicity. + attribute(node, name, original) { + const isSVG = OWNER_SVG_ELEMENT in node; + let oldValue; + // if the attribute is the style one + // handle it differently from others + if (name === 'style') + return hyperStyle(node, original, isSVG); + // direct accessors for and friends + else if (name.slice(0, 1) === '.') + return hyperSetter(node, name.slice(1), isSVG); + // boolean accessors for and friends + else if (name.slice(0, 1) === '?') + return booleanSetter(node, name.slice(1)); + // the name is an event one, + // add/remove event listeners accordingly + else if (/^on/.test(name)) { + let type = name.slice(2); + if (type === CONNECTED || type === DISCONNECTED) { + observe(node); + } + else if (name.toLowerCase() + in node) { + type = type.toLowerCase(); + } + return newValue => { + if (oldValue !== newValue) { + if (oldValue) + node.removeEventListener(type, oldValue, false); + oldValue = newValue; + if (newValue) + node.addEventListener(type, newValue, false); + } + }; + } + // the attribute is special ('value' in input) + // and it's not SVG *or* the name is exactly data, + // in this case assign the value directly + else if ( + name === 'data' || + (!isSVG && name in node && !readOnly.test(name)) + ) { + return newValue => { + if (oldValue !== newValue) { + oldValue = newValue; + if (node[name] !== newValue && newValue == null) { + // cleanup on null to avoid silly IE/Edge bug + node[name] = ''; + node.removeAttribute(name); + } + else + node[name] = newValue; + } + }; + } + else if (name in Intent.attributes) { + oldValue; + return any => { + const newValue = Intent.attributes[name](node, any); + if (oldValue !== newValue) { + oldValue = newValue; + if (newValue == null) + node.removeAttribute(name); + else + node.setAttribute(name, newValue); + } + }; + } + // in every other case, use the attribute node as it is + // update only the value, set it as node only when/if needed + else { + let owner = false; + const attribute = original.cloneNode(true); + return newValue => { + if (oldValue !== newValue) { + oldValue = newValue; + if (attribute.value !== newValue) { + if (newValue == null) { + if (owner) { + owner = false; + node.removeAttributeNode(attribute); + } + attribute.value = newValue; + } else { + attribute.value = newValue; + if (!owner) { + owner = true; + node.setAttributeNode(attribute); + } + } + } + } + }; + } + }, + + // in a hyper(node)`| File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
|---|---|---|---|---|---|---|---|---|---|
| index.js | -100% | -695/695 | -100% | -384/384 | -100% | -112/112 | -100% | -682/682 | -
| 1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 -355 -356 -357 -358 -359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 -490 -491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 -505 -506 -507 -508 -509 -510 -511 -512 -513 -514 -515 -516 -517 -518 -519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 -531 -532 -533 -534 -535 -536 -537 -538 -539 -540 -541 -542 -543 -544 -545 -546 -547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 -560 -561 -562 -563 -564 -565 -566 -567 -568 -569 -570 -571 -572 -573 -574 -575 -576 -577 -578 -579 -580 -581 -582 -583 -584 -585 -586 -587 -588 -589 -590 -591 -592 -593 -594 -595 -596 -597 -598 -599 -600 -601 -602 -603 -604 -605 -606 -607 -608 -609 -610 -611 -612 -613 -614 -615 -616 -617 -618 -619 -620 -621 -622 -623 -624 -625 -626 -627 -628 -629 -630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 -646 -647 -648 -649 -650 -651 -652 -653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 -664 -665 -666 -667 -668 -669 -670 -671 -672 -673 -674 -675 -676 -677 -678 -679 -680 -681 -682 -683 -684 -685 -686 -687 -688 -689 -690 -691 -692 -693 -694 -695 -696 -697 -698 -699 -700 -701 -702 -703 -704 -705 -706 -707 -708 -709 -710 -711 -712 -713 -714 -715 -716 -717 -718 -719 -720 -721 -722 -723 -724 -725 -726 -727 -728 -729 -730 -731 -732 -733 -734 -735 -736 -737 -738 -739 -740 -741 -742 -743 -744 -745 -746 -747 -748 -749 -750 -751 -752 -753 -754 -755 -756 -757 -758 -759 -760 -761 -762 -763 -764 -765 -766 -767 -768 -769 -770 -771 -772 -773 -774 -775 -776 -777 -778 -779 -780 -781 -782 -783 -784 -785 -786 -787 -788 -789 -790 -791 -792 -793 -794 -795 -796 -797 -798 -799 -800 -801 -802 -803 -804 -805 -806 -807 -808 -809 -810 -811 -812 -813 -814 -815 -816 -817 -818 -819 -820 -821 -822 -823 -824 -825 -826 -827 -828 -829 -830 -831 -832 -833 -834 -835 -836 -837 -838 -839 -840 -841 -842 -843 -844 -845 -846 -847 -848 -849 -850 -851 -852 -853 -854 -855 -856 -857 -858 -859 -860 -861 -862 -863 -864 -865 -866 -867 -868 -869 -870 -871 -872 -873 -874 -875 -876 -877 -878 -879 -880 -881 -882 -883 -884 -885 -886 -887 -888 -889 -890 -891 -892 -893 -894 -895 -896 -897 -898 -899 -900 -901 -902 -903 -904 -905 -906 -907 -908 -909 -910 -911 -912 -913 -914 -915 -916 -917 -918 -919 -920 -921 -922 -923 -924 -925 -926 -927 -928 -929 -930 -931 -932 -933 -934 -935 -936 -937 -938 -939 -940 -941 -942 -943 -944 -945 -946 -947 -948 -949 -950 -951 -952 -953 -954 -955 -956 -957 -958 -959 -960 -961 -962 -963 -964 -965 -966 -967 -968 -969 -970 -971 -972 -973 -974 -975 -976 -977 -978 -979 -980 -981 -982 -983 -984 -985 -986 -987 -988 -989 -990 -991 -992 -993 -994 -995 -996 -997 -998 -999 -1000 -1001 -1002 -1003 -1004 -1005 -1006 -1007 -1008 -1009 -1010 -1011 -1012 -1013 -1014 -1015 -1016 -1017 -1018 -1019 -1020 -1021 -1022 -1023 -1024 -1025 -1026 -1027 -1028 -1029 -1030 -1031 -1032 -1033 -1034 -1035 -1036 -1037 -1038 -1039 -1040 -1041 -1042 -1043 -1044 -1045 -1046 -1047 -1048 -1049 -1050 -1051 -1052 -1053 -1054 -1055 -1056 -1057 -1058 -1059 -1060 -1061 -1062 -1063 -1064 -1065 -1066 -1067 -1068 -1069 -1070 -1071 -1072 -1073 -1074 -1075 -1076 -1077 -1078 -1079 -1080 -1081 -1082 -1083 -1084 -1085 -1086 -1087 -1088 -1089 -1090 -1091 -1092 -1093 -1094 -1095 -1096 -1097 -1098 -1099 -1100 -1101 -1102 -1103 -1104 -1105 -1106 -1107 -1108 -1109 -1110 -1111 -1112 -1113 -1114 -1115 -1116 -1117 -1118 -1119 -1120 -1121 -1122 -1123 -1124 -1125 -1126 -1127 -1128 -1129 -1130 -1131 -1132 -1133 -1134 -1135 -1136 -1137 -1138 -1139 -1140 -1141 -1142 -1143 -1144 -1145 -1146 -1147 -1148 -1149 -1150 -1151 -1152 -1153 -1154 -1155 -1156 -1157 -1158 -1159 -1160 -1161 -1162 -1163 -1164 -1165 -1166 -1167 -1168 -1169 -1170 -1171 -1172 -1173 -1174 -1175 -1176 -1177 -1178 -1179 -1180 -1181 -1182 -1183 -1184 -1185 -1186 -1187 -1188 -1189 -1190 -1191 -1192 -1193 -1194 -1195 -1196 -1197 -1198 -1199 -1200 -1201 -1202 -1203 -1204 -1205 -1206 -1207 -1208 -1209 -1210 -1211 -1212 -1213 -1214 -1215 -1216 -1217 -1218 -1219 -1220 -1221 -1222 -1223 -1224 -1225 -1226 -1227 -1228 -1229 -1230 -1231 -1232 -1233 -1234 -1235 -1236 -1237 -1238 -1239 -1240 -1241 -1242 -1243 -1244 -1245 -1246 -1247 -1248 -1249 -1250 -1251 -1252 -1253 -1254 -1255 -1256 -1257 -1258 -1259 -1260 -1261 -1262 -1263 -1264 -1265 -1266 -1267 -1268 -1269 -1270 -1271 -1272 -1273 -1274 -1275 -1276 -1277 -1278 -1279 -1280 -1281 -1282 -1283 -1284 -1285 -1286 -1287 -1288 -1289 -1290 -1291 -1292 -1293 -1294 -1295 -1296 -1297 -1298 -1299 -1300 -1301 -1302 -1303 -1304 -1305 -1306 -1307 -1308 -1309 -1310 -1311 -1312 -1313 -1314 -1315 -1316 -1317 -1318 -1319 -1320 -1321 -1322 -1323 -1324 -1325 -1326 -1327 -1328 -1329 -1330 -1331 -1332 -1333 -1334 -1335 -1336 -1337 -1338 -1339 -1340 -1341 -1342 -1343 -1344 -1345 -1346 -1347 -1348 -1349 -1350 -1351 -1352 -1353 -1354 -1355 -1356 -1357 -1358 -1359 -1360 -1361 -1362 -1363 -1364 -1365 -1366 -1367 -1368 -1369 -1370 -1371 -1372 -1373 -1374 -1375 -1376 -1377 -1378 -1379 -1380 -1381 -1382 -1383 -1384 -1385 -1386 -1387 -1388 -1389 -1390 -1391 -1392 -1393 -1394 -1395 -1396 -1397 -1398 -1399 -1400 -1401 -1402 -1403 -1404 -1405 -1406 -1407 -1408 -1409 -1410 -1411 -1412 -1413 -1414 -1415 -1416 -1417 -1418 -1419 -1420 -1421 -1422 -1423 -1424 -1425 -1426 -1427 -1428 -1429 -1430 -1431 -1432 -1433 -1434 -1435 -1436 -1437 -1438 -1439 -1440 -1441 -1442 -1443 -1444 -1445 -1446 -1447 -1448 -1449 -1450 -1451 -1452 -1453 -1454 -1455 -1456 -1457 -1458 -1459 -1460 -1461 -1462 -1463 -1464 -1465 -1466 -1467 -1468 -1469 -1470 -1471 -1472 -1473 -1474 -1475 -1476 -1477 -1478 -1479 -1480 -1481 -1482 -1483 -1484 -1485 -1486 -1487 -1488 -1489 -1490 -1491 -1492 -1493 -1494 -1495 -1496 -1497 -1498 -1499 -1500 -1501 -1502 -1503 -1504 -1505 -1506 -1507 -1508 -1509 -1510 -1511 -1512 -1513 -1514 -1515 -1516 -1517 -1518 -1519 -1520 -1521 -1522 -1523 -1524 -1525 -1526 -1527 -1528 -1529 -1530 -1531 -1532 -1533 -1534 -1535 -1536 -1537 -1538 -1539 -1540 -1541 -1542 -1543 -1544 -1545 -1546 -1547 -1548 -1549 -1550 -1551 -1552 -1553 -1554 -1555 -1556 -1557 -1558 -1559 -1560 -1561 -1562 -1563 -1564 -1565 -1566 -1567 -1568 -1569 -1570 -1571 -1572 -1573 -1574 -1575 -1576 -1577 -1578 -1579 -1580 -1581 -1582 -1583 -1584 -1585 -1586 -1587 -1588 -1589 -1590 -1591 -1592 -1593 -1594 -1595 -1596 -1597 -1598 -1599 -1600 | 2ร - - - - - - - - - -2ร - - -2ร - -1ร -20ร - - - - - - - - - - - - - - - - - - - - -2ร -28ร -32ร -32ร -32ร -32ร - - - - - -2ร -229ร - - -2ร -4ร -2ร - -4ร - - - - -2ร -2ร - - - - -2ร -1ร -73ร - - - - - - - - - - - -2ร -1ร -2ร - - - - - -9ร -9ร - - - - - - - - - -5ร - -4ร - - -5ร -5ร -9ร -5ร - - - - - - - - - - - - - - - - -2ร -2ร -2ร -2ร -2ร - - -2ร -2ร - -2ร -2ร -2ร -2ร -2ร - - - - - -1ร -113ร -113ร -113ร - - -2ร -95ร - - - - - - - - - - -53ร - -53ร -48ร - - -95ร -95ร -95ร -53ร -38ร - -15ร -15ร -41ร - - -53ร - -95ร - - - - - - - -1ร -311ร -311ร - - - -170ร - -141ร - -309ร - - - - - - -1ร -59ร - - - - - - - - - - - -59ร -24ร -24ร -16ร -2ร - -14ร -12ร - - - -59ร -22ร -4ร -4ร -2ร - - -2ร -2ร -3ร - - - -2ร - -4ร - - -2ร -2ร - - - -22ร -31ร -25ร -20ร - - -20ร - - - -16ร - - -4ร -4ร - -12ร - - - - -6ร -6ร -6ร - - - -59ร - -32ร -20ร -20ร -20ร - - - - - -65ร -47ร - - -47ร -43ร -4ร - -2ร -2ร - - -39ร -39ร -2ร -2ร - - - - - - - - - -1ร -4ร -4ร -6ร -4ร -4ร - - - - - - -1ร -113ร -113ร -308ร - - - -126ร -126ร - - - -51ร -28ร -28ร - - -75ร -75ร -2ร - -73ร - - - - - -126ร - -4ร -4ร - - -178ร -8ร -8ร -8ร -170ร -2ร - - -170ร -170ร -84ร -84ร -5ร - -79ร - - - -24ร -24ร - -10ร -10ร -12ร - -10ร -10ร - -45ร -12ร - -45ร -4ร -4ร - -41ร -88ร -4ร - - - - -41ร -41ร - - -86ร -24ร - - - - - -62ร -4ร -58ร -10ร -48ร -4ร -44ร -4ร -40ร -28ร -28ร -28ร -28ร -28ร -12ร -4ร - -8ร - -170ร - - - - - - - - - -1ร -128ร - - - - - - - -65ร -65ร -57ร - -57ร - - - -1ร - -1ร - -1ร - -1ร - -1ร - -56ร -56ร - - -56ร -56ร - - - - - - -1ร -247ร - - - - - -345ร -345ร - -128ร -128ร -128ร - -70ร -68ร -68ร - -70ร - -147ร - - - -4ร -4ร - -147ร - - - - - - - - - - - - - - - - - -2ร - - - - -2ร - - - - - -2ร -2ร -2ร -2ร - - - - -2ร - - - - -2ร -2ร -229ร -2ร - - - - - - - -2ร - - -2ร - - - - - - -1ร -4ร - - - -1ร -2ร - - - -1ร -69ร - - - - - - - -102ร -102ร - - - -73ร - - -69ร - - - -1ร -155ร - - - - -1ร -147ร - - - - - - - -1ร -145ร -145ร -145ร - - - - - - - - -145ร -145ร -145ร - -69ร - - - - - - -69ร - -145ร - - - -1ร -1ร -1ร - -144ร -144ร -76ร - - -68ร - - -145ร - - - -1ร -2ร -2ร -2ร -1ร -1ร -1ร - -1ร -1ร -1ร - -2ร - - - -1ร -79ร - - - -1ร -7ร - - - - - -5ร - -5ร -5ร - - - - - -1ร - -5ร -3ร - -2ร -1ร - - -2ร - - - - -1ร - - -5ร - - - - -1ร -6ร -6ร -6ร - - - - -1ร -57ร -57ร -6ร -6ร - -57ร - - - -1ร -10ร -10ร -2ร -8ร -2ร -6ร -2ร - -4ร - - - - -1ร -12ร -10ร -10ร -8ร - - - - - -1ร -86ร - - - -1ร -107ร - - - - -1ร -6ร -6ร - -38ร - - -16ร - - - - - -1ร -65ร -65ร -44ร - -21ร -19ร -9ร -9ร - - - - - - -1ร -170ร -24ร - - - - -1ร -176ร -176ร - - -113ร -113ร - -59ร -59ร - -4ร -4ร - -176ร - - - -1ร -128ร - - - - - - -2ร -2ร -2ร - -2ร -2ร -1ร - -1ร -3ร -3ร -3ร - - - -2ร -2ร -2ร -2ร -2ร -2ร - - - -1ร -1ร - -1ร -2ร - - - - -2ร - - - -4ร -1ร -187ร -1ร - -100ร - - - - - - - - -2ร - -1ร - - -1ร -1ร -2ร - - - - - -2ร - -1ร -1ร - -85ร - - - - - -60ร - - - - - - - - -2ร - -1ร - - -1ร -1ร -109ร - - - - -2ร -25ร - - - - - - -2ร - - -2ร -2ร - - -2ร -1ร -228ร -228ร - - - - -2ร - -74ร - - -5ร - - - - -6ร - - - - -2ร - -180ร - - - - - - -432ร -432ร -223ร - -180ร - -109ร - - - -2ร - -90ร -154ร -154ร - -70ร -70ร - -84ร -84ร - - -90ร - - -94ร -161ร - -94ร - - - -2ร -2ร -2ร -2ร -44ร - - -2ร -57ร - - - -2ร - - -2ร - - -2ร - - -2ร - - -2ร - - -2ร - - - -2ร -2ร -2ร -2ร - -232ร - - - - - -163ร - -232ร - - -69ร - - - - - - - - -2ร - -21ร -15ร - -15ร - -21ร - -2ร - -18ร -12ร - -14ร - -18ร - - -1ร -40ร -40ร -10ร -10ร - - - - -1ร -36ร -10ร - -26ร - - - - - -1ร -46ร - - - - - - - - -82ร - -8ร -8ร -6ร - -8ร -8ร - -36ร -36ร -36ร -36ร -36ร -36ร -36ร -36ร - - - - - -26ร -26ร - - -4ร - - -10ร -10ร - -36ร - - - -36ร -6ร - - - - - -30ร - - - - - -36ร -30ร - -36ร - - -38ร - - - - - -38ร -38ร - - -46ร - - - -1ร -32ร - - - - - - -46ร -46ร -46ร - - - - - - -32ร -32ร - - - - - - - - -1ร -119ร -119ร -119ร -119ร -119ร -119ร - - - - - -1ร -128ร -128ร -128ร - - -4ร -4ร - -68ร -68ร - - - -68ร - - -56ร -56ร -56ร - -128ร - - - - -107ร - -128ร - - - - - -1ร -138ร - - - - - - -130ร -130ร - - - - - - -138ร -138ร - - - -1ร -311ร -347ร - - - - - -1ร -170ร -170ร -170ร - -170ร -138ร -138ร -138ร -138ร -137ร -137ร - -32ร -32ร -32ร - - - - - - - - -1ร -67ร - -1ร -67ร -67ร - - -67ร - - -1ร -103ร -69ร -69ร -8ร - -69ร - -103ร - - -67ร - -14ร -14ร -14ร -10ร -10ร -10ร -14ร -10ร -2ร -2ร - - - - -2ร - -8ร -8ร - - -14ร -14ร - - -14ร - - -90ร -90ร -59ร -59ร -59ร - -90ร -89ร - - - - -1ร -56ร -56ร -56ร -56ร -12ร -12ร - -56ร -29ร -29ร - -56ร - - - - - - - - - - - -2ร - - - - -2ร - - - - - - -2ร - - - - - - -1ร -53ร - - - - -53ร - -26ร -26ร - -26ร - -27ร -4ร -4ร - -23ร - - - - - - - - - - - -2ร -113ร -113ร -95ร -95ร -95ร -95ร - -113ร - - -2ร - - - - - - - -1ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -23ร -42ร -23ร -38ร -38ร -38ร -38ร -38ร -75ร -75ร -75ร -75ร - - - - -75ร - -38ร - -23ร - - - -1ร -32ร - - - - - - - - - -1ร -23ร - - - - - - - - -23ร -43ร -43ร -43ร -43ร -43ร -43ร -43ร -33ร -33ร -33ร -18ร - - -10ร -7ร -7ร - - -3ร -3ร - - -23ร -2ร - -23ร -2ร - -23ร - - - -1ร -23ร - - - - - - -23ร -23ร -23ร -9ร -9ร -2ร -2ร - -7ร -7ร - - -7ร - -9ร - -23ร - - - - - - - - - - - - - - - - - - -2ร | var hyperHTML = (function (globalDocument, majinbuu) {'use strict';
-
- /*! (c) 2017 Andrea Giammarchi @WebReflection, (ISC) */
-
- // ---------------------------------------------
- // hyperHTML Public API
- // ---------------------------------------------
-
- // The document must be swap-able at runtime.
- // Needed by both basicHTML and nativeHTML
- hyper.document = globalDocument;
-
- // friendly destructuring
- hyper.hyper = hyper;
-
- function hyper(HTML) {
- return arguments.length < 2 ?
- (HTML == null ?
- wireContent('html') :
- (typeof HTML === 'string' ?
- wire(null, HTML) :
- ('raw' in HTML ?
- wireContent('html')(HTML) :
- ('nodeType' in HTML ?
- bind(HTML) :
- wireWeakly(HTML, 'html')
- )
- )
- )) :
- ('raw' in HTML ?
- wireContent('html') : wire
- ).apply(null, arguments);
- }
-
- // hyper.adopt(el) ๐ฃ
- // import an already live DOM structure
- // described as TL
- hyper.adopt = function adopt(node) {
- return function () {
- notAdopting = false;
- render.apply(node, arguments);
- notAdopting = true;
- return node;
- };
- };
-
- // hyper.bind(el) โก๏ธ
- // render TL inside a DOM node used as context
- hyper.bind = bind;
- function bind(context) { return render.bind(context); }
-
- // hyper.define('transformer', callback) ๐
- hyper.define = function define(transformer, callback) {
- if (!(transformer in transformers)) {
- transformersKeys.push(transformer);
- }
- transformers[transformer] = callback;
- // TODO: else throw ? console.warn ? who cares ?
- };
-
- // hyper.escape('<html>') => '<text>' ๐
- hyper.escape = function escape(html) {
- return html.replace(/[&<>'"]/g, fnEscape);
- };
-
- // hyper.wire(obj, 'type:ID') โฐ
- // relate a renderer to a generic object
- hyper.wire = wire;
- function wire(obj, type) {
- return arguments.length < 1 ?
- wireContent('html') :
- (obj == null ?
- wireContent(type || 'html') :
- wireWeakly(obj, type || 'html')
- );
- }
-
- // hyper.Component([initialState]) ๐ป
- // An overly-simplified Component class.
- // For full Custom Elements support
- // see HyperHTMLElement instead.
- hyper.Component = Component;
- function Component() {}
- Object.defineProperties(
- Component.prototype,
- {
- // same as HyperHTMLElement handleEvent
- handleEvent: {value: function (e) {
- // both IE < 11 and JSDOM lack dataset
- var ct = e.currentTarget;
- this[
- ('getAttribute' in ct && ct.getAttribute('data-call')) ||
- ('on' + e.type)
- ](e);
- }},
- // returns its own HTML wire or create it once on comp.render()
- html: lazyGetter('html', wireContent),
- // returns its own SVG wire or create it once on comp.render()
- svg: lazyGetter('svg', wireContent),
- // same as HyperHTMLElement state
- state: lazyGetter('state', function () { return this.defaultState; }),
- // same as HyperHTMLElement get defaultState
- defaultState: {get: function () { return {}; }},
- // same as HyperHTMLElement setState
- setState: {value: function (state) {
- var target = this.state;
- var source = typeof state === 'function' ? state.call(this, target) : state;
- for (var key in source) target[key] = source[key];
- this.render();
- }}
- // the render must be defined when extending hyper.Component
- // the render **must** return either comp.html or comp.svg wire
- // render() { return this.html`<p>that's it</p>`; }
- }
- );
-
- // - - - - - - - - - - - - - - - - - - - - - - -
-
- // ---------------------------------------------
- // Constants
- // ---------------------------------------------
-
- // Node.CONSTANTS
- // without assuming Node is globally available
- // since this project is used on the backend too
- var ELEMENT_NODE = 1;
- var ATTRIBUTE_NODE = 2;
- var TEXT_NODE = 3;
- var COMMENT_NODE = 8;
- var DOCUMENT_FRAGMENT_NODE = 11;
-
- // SVG related
- var OWNER_SVG_ELEMENT = 'ownerSVGElement';
- var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
-
- var SHOULD_USE_ATTRIBUTE = /^style$/i;
- var SHOULD_USE_TEXT_CONTENT = /^style|textarea$/i;
- var EXPANDO = '_hyper: ';
- var UID = EXPANDO + ((Math.random() * new Date) | 0) + ';';
- var UIDC = '<!--' + UID + '-->';
-
- // ---------------------------------------------
- // DOM Manipulation
- // ---------------------------------------------
-
- function Aura(node, childNodes) {
- this.node = node;
- this.childNodes = childNodes;
- return majinbuu.aura(this, childNodes);
- }
-
- Aura.prototype.splice = function splice(start) {
- for (var
- tmp,
- ph = this.node,
- cn = this.childNodes,
- target = cn[start + (arguments[1] || 0)] || ph,
- result = cn.splice.apply(cn, arguments),
- pn = ph.parentNode,
- i = 0,
- length = result.length;
- i < length; i++
- ) {
- tmp = result[i];
- // TODO: this is not optimal (but necessary)
- if (cn.indexOf(tmp) < 0) {
- pn.removeChild(tmp);
- }
- }
- i = 2;
- length = arguments.length;
- if (i < length) {
- if ((length - i) === 1) {
- tmp = arguments[i];
- } else {
- tmp = createDocumentFragment(pn.ownerDocument);
- while (i < length) {
- tmp.appendChild(arguments[i++]);
- }
- }
- pn.insertBefore(tmp, target);
- }
- return result;
- };
-
- // ---------------------------------------------
- // hyperHTML Operations
- // ---------------------------------------------
-
- // entry point for all TL => DOM operations
- function render(template) {
- var hyper = hypers.get(this);
- if (
- !hyper ||
- hyper.template !== TL(template)
- ) {
- upgrade.apply(this, arguments);
- } else {
- update.apply(hyper.updates, arguments);
- }
- return this;
- }
-
- // `<div class="${'attr'}"></div>`
- // `<div onclick="${function () {... }}"></div>`
- // `<div onclick="${{handleEvent(){ ... }}}"></div>`
- // `<div contenteditable="${true}"></div>`
- function setAttribute(attribute, removeAttributes, name) {
- var
- node = attribute.ownerElement,
- isData = name === 'data',
- isEvent = !isData && /^on/.test(name),
- isSpecial = isData ||
- (isSpecialAttribute(node, name) &&
- !SHOULD_USE_ATTRIBUTE.test(name)),
- type = isEvent ? name.slice(2) : '',
- noOwner = isSpecial || isEvent,
- wontUpgrade = isSpecial && (isData || name in node),
- oldValue, specialAttr, upgrade
- ;
- if (isEvent || wontUpgrade) {
- removeAttributes.push(node, name);
- if (isEvent) {
- if (type === CONNECTED || type === DISCONNECTED) {
- components.add(node);
- }
- else if (name.toLowerCase() in node) {
- type = type.toLowerCase();
- }
- }
- }
- if (isSpecial) {
- if (!wontUpgrade) {
- upgrade = toBeUpgraded.get(node);
- if (!upgrade) {
- upgrade = {
- _: Object.create(null),
- $: function () {
- toBeUpgraded.delete(node);
- for (var name in this._) {
- this._[name].$();
- }
- }
- };
- toBeUpgraded.set(node, upgrade);
- }
- upgrade._[name] = {
- _: null,
- $: function () {
- wontUpgrade = true;
- specialAttr(this._);
- }
- };
- }
- specialAttr = function specialAttr(newValue) {
- if (wontUpgrade) {
- if (oldValue !== newValue) {
- oldValue = newValue;
- // WebKit moves the cursor if input.value
- // is set again, even if same value
- if (node[name] !== newValue) {
- // let the browser handle the case
- // input.value = null;
- // input.value; // ''
- if (newValue == null) {
- // reflect the null intent,
- // do not pass undefined!
- node[name] = null;
- node.removeAttribute(name);
- } else {
- node[name] = newValue;
- }
- }
- }
- } else {
- attribute.value = newValue;
- upgrade._[name]._ = newValue;
- if (name in node) upgrade.$();
- }
- };
- }
- return isEvent ?
- function eventAttr(newValue) {
- if (oldValue !== newValue) {
- if (oldValue) node.removeEventListener(type, oldValue, false);
- oldValue = newValue;
- if (newValue) node.addEventListener(type, newValue, false);
- }
- } :
- (isSpecial ?
- specialAttr :
- function normalAttr(newValue) {
- if (oldValue !== newValue) {
- oldValue = newValue;
- // avoid triggering again attributeChangeCallback
- // if the value was identical
- if (attribute.value !== newValue) {
- if (newValue == null) {
- if (!noOwner) {
- // TODO: should attribute.value = null here?
- noOwner = true;
- node.removeAttributeNode(attribute);
- }
- } else {
- attribute.value = newValue;
- if (noOwner) {
- noOwner = false;
- node.setAttributeNode(attribute);
- }
- }
- }
- }
- }
- );
- }
-
- // `<style>${'text'}</style>`
- function setTextContent(node) {
- var oldValue;
- return function (value) {
- if (value !== oldValue) {
- oldValue = value;
- node.textContent = value;
- }
- };
- }
-
- // `<p>${'any'}</p>`
- // `<li>a</li>${'virtual'}<li>c</li>`
- function setAnyContent(node, childNodes, aura) {
- var oldValue;
- return function anyContent(value) {
- switch (typeof value) {
- case 'string':
- case 'number':
- case 'boolean':
- var length = childNodes.length;
- if (
- length === 1 &&
- childNodes[0].nodeType === TEXT_NODE
- ) {
- if (oldValue !== value) {
- oldValue = value;
- childNodes[0].textContent = value;
- }
- } else {
- oldValue = value;
- if (length) {
- aura.splice(0, length, createText(node, value));
- } else {
- childNodes[0] = node.parentNode.insertBefore(
- createText(node, value),
- node
- );
- }
- }
- break;
- case 'function':
- anyContent(value(node.parentNode, childNodes, 0));
- break;
- case 'object':
- case 'undefined':
- if (value == null) {
- oldValue = value;
- anyContent('');
- break;
- } else if (value instanceof Component) {
- value = value.render();
- }
- default:
- oldValue = value;
- if (isArray(value)) {
- var length = value.length;
- if (length === 0) {
- aura.splice(0);
- } else {
- switch (typeof value[0]) {
- case 'string':
- case 'number':
- case 'boolean':
- anyContent({html: value});
- break;
- case 'function':
- var parentNode = node.parentNode;
- for (var i = 0; i < length; i++) {
- value[i] = value[i](parentNode, childNodes, i);
- }
- anyContent(value.concat.apply([], value));
- break;
- case 'object':
- if (isArray(value[0])) {
- value = value.concat.apply([], value);
- }
- if (isPromise_ish(value[0])) {
- Promise.all(value).then(anyContent);
- break;
- } else {
- for (var i = 0, length = value.length; i < length; i++) {
- if (value[i] instanceof Component) {
- value[i] = value[i].render();
- }
- }
- }
- default:
- optimist(aura, value);
- break;
- }
- }
- } else if (isNode_ish(value)) {
- optimist(
- aura,
- value.nodeType === DOCUMENT_FRAGMENT_NODE ?
- slice.call(value.childNodes) :
- [value]
- );
- } else if (isPromise_ish(value)) {
- value.then(anyContent);
- } else if ('placeholder' in value) {
- invokeAtDistance(value, anyContent);
- } else if ('text' in value) {
- anyContent(String(value.text));
- } else if ('any' in value) {
- anyContent(value.any);
- } else if ('html' in value) {
- var html = [].concat(value.html).join('');
- aura.splice(0);
- var fragment = createFragment(node, html);
- childNodes.push.apply(childNodes, fragment.childNodes);
- node.parentNode.insertBefore(fragment, node);
- } else if ('length' in value) {
- anyContent(slice.call(value));
- } else {
- anyContent(invokeTransformer(value, anyContent));
- }
- break;
- }
- };
- }
-
- // ---------------------------------------------
- // DOM Traversing
- // ---------------------------------------------
-
- // look for attributes that contains the comment text
- function attributesSeeker(node, paths, parts) {
- for (var
- name, realName, attrs,
- attribute,
- cache = Object.create(null),
- attributes = node.attributes,
- i = 0, length = attributes.length;
- i < length; i++
- ) {
- attribute = attributes[i];
- if (attribute.value === UID) {
- name = attribute.name;
- // this is an IE < 11 thing only
- if (name in cache) {
- // attributes with unrecognized values
- // are duplicated, even if same attribute, across the node
- // to fix it, you need to remove it
- node.removeAttributeNode(attribute);
- // put a value that won't (hopefully) bother IE
- cache[name].value = '';
- // and place the node back
- node.setAttributeNode(cache[name]);
- // this will decrease attributes count by 1
- length--;
- // so the loop should be decreased by 1 too
- i--;
- } else {
- realName = parts.shift().replace(/^(?:|[\S\s]*?\s)(\S+?)=['"]?$/, '$1');
- attrs = node.attributes;
- // fallback is needed in both jsdom
- // and in not-so-standard browsers/engines
- cache[name] = attrs[realName] || attrs[realName.toLowerCase()];
- paths.push(Path('attr', cache[name], realName));
- }
- }
- }
- }
-
- // walk the fragment tree in search of comments
- function hyperSeeker(node, paths, parts) {
- for (var
- child,
- childNodes = node.childNodes,
- length = childNodes.length,
- i = 0; i < length; i++
- ) {
- child = childNodes[i];
- switch (child.nodeType) {
- case ELEMENT_NODE:
- attributesSeeker(child, paths, parts);
- hyperSeeker(child, paths, parts);
- break;
- case COMMENT_NODE:
- if (child.textContent === UID) {
- parts.shift();
- paths.push(Path('any', child));
- }
- break;
- case TEXT_NODE:
- if (
- SHOULD_USE_TEXT_CONTENT.test(node.nodeName) &&
- trim.call(child.textContent) === UIDC
- ) {
- parts.shift();
- paths.push(Path('text', node));
- }
- break;
- }
- }
- }
-
- // ---------------------------------------------
- // Features detection / ugly UA sniffs
- // ---------------------------------------------
- /*
- var importNode = 'importNode' in globalDocument ?
- function (doc, node) {
- return doc.importNode(node, true);
- } :
- function (doc, node) {
- return node;
- };
- */
-
- var featureFragment = createDocumentFragment(globalDocument);
-
- // Firefox < 55 has non standard template literals.
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1108941
- // TODO: is there any better way to feature detect this ?
- var FF = typeof navigator === 'object' &&
- /Firefox\/(\d+)/.test(navigator.userAgent) &&
- parseFloat(RegExp.$1) < 55;
-
- // If attributes order is shuffled, threat the browser differently
- // Usually this is a well known IE only limitation but some older FF does the same.
- var IE = (function () {
- var p = globalDocument.createElement('p');
- p.innerHTML = '<i data-i="" class=""></i>';
- return /class/i.test(p.firstChild.attributes[0].name);
- }());
-
-
- // beside IE, old WebKit browsers don't have `children` in DocumentFragment
- var WK = !('children' in featureFragment);
-
- // both Firefox < 55 and TypeScript have issues with template literals
- // this lazy defined callback should spot issues right away
- // and in the best case scenario become a no-op
- var TL = function (template) {
- if (template.propertyIsEnumerable('raw') || FF) TL = unique;
- else TL = function (t) { return t; };
- return TL(template);
- };
-
- // ---------------------------------------------
- // Helpers
- // ---------------------------------------------
-
- // used to convert childNodes to Array
- var slice = [].slice;
-
- // used to sanitize html
- var oEscape = {
- '&': '&',
- '<': '<',
- '>': '>',
- "'": ''',
- '"': '"'
- };
- function fnEscape(m) {
- return oEscape[m];
- }
-
- // return content as html
- function asHTML(html) {
- return {html: html};
- }
-
- // return a single node or an Array or nodes
- function createContent(node) {
- for (var
- child,
- content = [],
- childNodes = node.childNodes,
- i = 0,
- length = childNodes.length;
- i < length; i++
- ) {
- child = childNodes[i];
- if (
- child.nodeType === ELEMENT_NODE ||
- trim.call(child.textContent).length !== 0
- ) {
- content.push(child);
- }
- }
- return content.length === 1 ? content[0] : content;
- }
-
- // just a minifier friendly indirection
- function createDocumentFragment(document) {
- return document.createDocumentFragment();
- }
-
- // given a node, inject some html and return
- // the resulting template document fragment
- function createFragment(node, html) {
- return (
- OWNER_SVG_ELEMENT in node ?
- createSVGFragment :
- createHTMLFragment
- )(node, html.replace(no, comments));
- }
-
- // create fragment for HTML
- function createHTMLFragment(node, html) {
- var fragment;
- var document = node.ownerDocument;
- var container = document.createElement(
- // TODO: this is a work around for A-Frame V0 based components
- // see: https://stackoverflow.com/questions/46797635/aframe-content-not-rendering-on-chrome-with-hyperhtml/46817370
- // TODO: the following RegExp breaks: https://github.com/WebReflection/hyperHTML/issues/135
- // /<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)[\s\S]*?>[\s\S]*?<\/\1>/i.test(html) ?
- /<(a-\w+)[\s\S]*?>[\s\S]*?<\/\1>/.test(html) ?
- 'div' : 'template'
- );
- // var container = document.createElement('template');
- var hasContent = 'content' in container;
- var needsTableWrap = false;
- if (!hasContent) {
- // DO NOT MOVE THE FOLLOWING LINE ELSEWHERE
- fragment = createDocumentFragment(document);
- // (a jsdom + nodejs tests coverage gotcha)
-
- // el.innerHTML = '<td></td>'; is not possible
- // if the content is a partial internal table content
- // it needs to be wrapped around once injected.
- // HTMLTemplateElement does not suffer this issue.
- needsTableWrap = /^[^\S]*?<(col(?:group)?|t(?:head|body|foot|r|d|h))/i.test(html);
- }
- if (needsTableWrap) {
- // secure the RegExp.$1 result ASAP to avoid issues
- // in case a non-browser DOM library uses RegExp internally
- // when HTML content is injected (basicHTML / jsdom / others...)
- var selector = RegExp.$1;
- container.innerHTML = '<table>' + html + '</table>';
- appendNodes(fragment, slice.call(container.querySelectorAll(selector)));
- } else {
- container.innerHTML = html;
- if (hasContent) {
- fragment = container.content;
- // fragment = importNode(document, container.content);
- } else {
- appendNodes(fragment, slice.call(container.childNodes));
- }
- }
- return fragment;
- }
-
- // create a fragment for SVG
- function createSVGFragment(node, html) {
- var document = node.ownerDocument;
- var fragment = createDocumentFragment(document);
- if (IE || WK) {
- var container = document.createElement('div');
- container.innerHTML = '<svg xmlns="' + SVG_NAMESPACE + '">' + html + '</svg>';
- appendNodes(fragment, slice.call(container.firstChild.childNodes));
- } else {
- var container = document.createElementNS(SVG_NAMESPACE, 'svg');
- container.innerHTML = html;
- appendNodes(fragment, slice.call(container.childNodes));
- }
- return fragment;
- }
-
- // given a node, it does what is says
- function createText(node, text) {
- return node.ownerDocument.createTextNode(text);
- }
-
- // dispatch same event through a list of nodes
- function dispatchAll(nodes, type) {
- for (var
- e, node,
- isConnected = type === CONNECTED,
- i = 0, length = nodes.length;
- i < length; i++
- ) {
- node = nodes[i];
- /* istanbul ignore else */
- Eif (node.nodeType === ELEMENT_NODE) {
- e = dispatchTarget(node, isConnected, type, e);
- }
- }
- }
-
- // per each inserted element, check initialization
- function dispatchTarget(node, isConnected, type, e) {
- /* istanbul ignore next */
- if (components.has(node)) {
- node.dispatchEvent(e || (e = new $Event(type)));
- }
- else Iif (isConnected && toBeUpgraded.has(node)) {
- toBeUpgraded.get(node).$();
- }
- else {
- for (var
- nodes = getChildren(node),
- i = 0, length = nodes.length;
- i < length; i++
- ) {
- e = dispatchTarget(nodes[i], isConnected, type, e);
- }
- }
- return e;
- }
-
- // returns current customElements reference
- // compatible with basicHTML too
- function getCEClass(node) {
- var doc = hyper.document;
- var ce = doc.customElements || doc.defaultView.customElements;
- return ce && ce.get(node.nodeName.toLowerCase());
- }
-
- // verify that an attribute has
- // a special meaning for the node
- function isSpecialAttribute(node, name) {
- var notSVG = !(OWNER_SVG_ELEMENT in node);
- if (notSVG && /-/.test(node.nodeName)) {
- var Class = getCEClass(node);
- if (Class) node = Class.prototype;
- }
- return notSVG && name in node;
- }
-
- // use a placeholder and resolve with the right callback
- function invokeAtDistance(value, callback) {
- callback(value.placeholder);
- if ('text' in value) {
- Promise.resolve(value.text).then(String).then(callback);
- } else if ('any' in value) {
- Promise.resolve(value.any).then(callback);
- } else if ('html' in value) {
- Promise.resolve(value.html).then(asHTML).then(callback);
- } else {
- Promise.resolve(invokeTransformer(value, callback)).then(callback);
- }
- }
-
- // last attempt to transform content
- function invokeTransformer(object, callback) {
- for (var key, i = 0, length = transformersKeys.length; i < length; i++) {
- key = transformersKeys[i];
- if (object.hasOwnProperty(key)) {
- return transformers[key](object[key], callback);
- }
- }
- }
-
- // quick and dirty Node check
- function isNode_ish(value) {
- return 'ELEMENT_NODE' in value;
- }
-
- // quick and dirty Promise check
- function isPromise_ish(value) {
- return value != null && 'then' in value;
- }
-
- // return a descriptor that lazily initialize a property
- // unless it hasn't be previously set directly
- function lazyGetter(type, fn) {
- var secret = '_' + type + '$';
- return {
- get: function () {
- return this[secret] || (this[type] = fn.call(this, type));
- },
- set: function (value) {
- defineProperty(this, secret, {configurable: true, value: value});
- }
- };
- }
-
- // uses majinbuu only if the two lists are different
- function optimist(aura, value) {
- var i = 0, length = aura.length;
- if (value.length !== length) {
- majinbuu(aura, value, hyper.MAX_LIST_SIZE);
- } else {
- for (; i < length--; i++) {
- if (aura[length] !== value[length] || aura[i] !== value[i]) {
- majinbuu(aura, value, hyper.MAX_LIST_SIZE);
- return;
- }
- }
- }
- }
-
- // remove a list of [node, attribute]
- function removeAttributeList(list) {
- for (var i = 0, length = list.length; i < length; i++) {
- list[i++].removeAttribute(list[i]);
- }
- }
-
- // specify the content to update
- function setContent(info, target, removeAttributes, childNodes) {
- var update;
- switch (info.type) {
- case 'any':
- // TODO: don't pass the target, it shouldn't be needed
- update = setAnyContent(target, childNodes, new Aura(target, childNodes));
- break;
- case 'attr':
- update = setAttribute(target, removeAttributes, info.name);
- break;
- case 'text':
- update = setTextContent(target);
- break;
- }
- return update;
- }
-
- // used for common path creation.
- function Path(type, node, name) {
- return {type: type, path: createPath(node), name: name};
- }
-
- // ---------------------------------------------
- // Hybrid Shims
- // ---------------------------------------------
-
- var CONNECTED = 'connected';
- var DISCONNECTED = 'dis' + CONNECTED;
- var $Event;
-
- try {
- new Event(CONNECTED);
- $Event = Event;
- } catch(o_O) {
- $Event = function (type) {
- var e = hyper.document.createEvent('Event');
- e.initEvent(type, false, false);
- return e;
- };
- }
-
- try {
- (new MutationObserver(function (records) {
- for (var record, i = 0, length = records.length; i < length; i++) {
- record = records[i];
- dispatchAll(record.removedNodes, DISCONNECTED);
- dispatchAll(record.addedNodes, CONNECTED);
- }
- })).observe(globalDocument, {subtree: true, childList: true});
- } catch(o_O) {
- globalDocument.addEventListener('DOMNodeInserted', function (e) {
- dispatchAll([e.target], CONNECTED);
- }, false);
- globalDocument.addEventListener('DOMNodeRemoved', function (e) {
- dispatchAll([e.target], DISCONNECTED);
- }, false);
- }
-
- // WeakMap with partial UID fallback
- var $WeakMap = typeof WeakMap === typeof $WeakMap ?
- function () {
- // NOT A POLYFILL: simplified ad-hoc for this library cases
- /* istanbul ignore next */
- return {
- delete: function (obj) { delete obj[UID]; },
- get: function (obj) { return obj[UID]; },
- has: function (obj) { return UID in obj; },
- set: function (obj, value) {
- Object.defineProperty(obj, UID, {
- configurable: true,
- value: value
- });
- }
- };
- } :
- WeakMap;
-
- var $WeakSet = typeof WeakSet === typeof $WeakSet ?
- function () {
- var wm = new $WeakMap;
- // NOT A POLYFILL: simplified ad-hoc for this library cases
- /* istanbul ignore next */
- return {
- add: function (obj) { wm.set(obj, true); },
- has: function (obj) { return wm.get(obj) === true; }
- };
- } :
- WeakSet;
-
- // Map with partial double Array fallback
- var $Map = typeof Map === typeof $Map ?
- function () {
- var k = [], v = [];
- return {
- get: function (obj) {
- return v[k.indexOf(obj)];
- },
- // being used with unique template literals
- // there is never a case when a value is overwritten
- // no need to check upfront for the indexOf
- set: function (obj, value) {
- v[k.push(obj) - 1] = value;
- }
- };
- } :
- Map;
-
- // TODO: which browser needs these partial polyfills here?
-
- // BB7 and webOS need this
- var isArray = Array.isArray ||
- (function () {
- var toString = {}.toString;
- // I once had an engine returning [array Array]
- // and I've got scared since!
- var s = toString.call([]);
- return function (a) {
- return toString.call(a) === s;
- };
- }());
-
- // older WebKit need this
- var trim = EXPANDO.trim ||
- function () { return this.replace(/^\s+|\s+$/g, ''); };
-
- // ---------------------------------------------
- // Shared variables
- // ---------------------------------------------
-
- // recycled defineProperty shortcut
- var defineProperty = Object.defineProperty;
-
- // transformers registry
- var transformers = {};
- var transformersKeys = [];
-
- // normalize Firefox issue with template literals
- var templateObjects = {}, unique;
- function unique(template) {
- var key = '_' + template.join(UIDC);
- return templateObjects[key] ||
- (templateObjects[key] = template);
- }
-
- // use native .append(...childNodes) where available
- var appendNodes = 'append' in featureFragment ?
- function (node, childNodes) {
- node.append.apply(node, childNodes);
- } :
- function appendNodes(node, childNodes) {
- for (var
- i = 0,
- length = childNodes.length;
- i < length; i++
- ) {
- node.appendChild(childNodes[i]);
- }
- };
-
- // returns children or retrieve them in IE/Edge
- var getChildren = WK || IE ?
- function (node) {
- for (var
- child,
- children = [],
- childNodes = node.childNodes,
- j = 0, i = 0, length = childNodes.length;
- i < length; i++
- ) {
- child = childNodes[i];
- if (child.nodeType === ELEMENT_NODE)
- children[j++] = child;
- }
- return children;
- } :
- function (node) { return node.children; };
-
- // return the correct node walking through a path
- // fixes IE/Edge issues with attributes and children (fixes old WebKit too)
- var getNode = IE || WK ?
- function (parentNode, path) {
- for (var name, i = 0, length = path.length; i < length; i++) {
- name = path[i++];
- switch (name) {
- case 'children':
- parentNode = getChildren(parentNode)[path[i]];
- break;
- default:
- parentNode = parentNode[name][path[i]];
- break;
- }
- }
- return parentNode;
- } :
- function (parentNode, path) {
- for (var i = 0, length = path.length; i < length; i++) {
- parentNode = parentNode[path[i++]][path[i]];
- }
- return parentNode;
- };
-
- // sanitizes interpolations as comments
- var attrName = '[^\\S]+[^ \\f\\n\\r\\t\\/>"\'=]+';
- var no = new RegExp('(<[a-z]+[a-z0-9:_-]*)((?:' + attrName + '(?:=(?:\'.*?\'|".*?"|<.+?>|\\S+))?)+)([^\\S]*\/?>)', 'gi');
- var findAttributes = new RegExp('(' + attrName + '=)([\'"]?)' + UIDC + '\\2', 'gi');
- var comments = function ($0, $1, $2, $3) {
- return $1 + $2.replace(findAttributes, replaceAttributes) + $3;
- };
-
- var replaceAttributes = function ($0, $1, $2) {
- return $1 + ($2 || '"') + UID + ($2 || '"');
- };
-
- // list of components with connected/disconnected
- var components = new $WeakSet;
-
- // [element] = {template, updates};
- var hypers = new $WeakMap;
-
- // [element] = {template, updates};
- var wires = new $WeakMap;
-
- // [template] = {fragment, paths};
- var templates = new $Map;
-
- // [node] = onupgrade
- var toBeUpgraded = new $WeakMap;
-
- // internal signal to switch adoption
- var notAdopting = true;
-
- // IE 11 has problems with cloning templates too
- // it "forgets" empty childNodes
- var cloneNode = (function () {
- featureFragment.appendChild(createText(featureFragment, 'g'));
- featureFragment.appendChild(createText(featureFragment, ''));
- return featureFragment.cloneNode(true).childNodes.length === 1 ?
- function (node) {
- for (var
- clone = node.cloneNode(),
- childNodes = node.childNodes || [],
- i = 0, length = childNodes.length;
- i < length; i++
- ) {
- clone.appendChild(cloneNode(childNodes[i]));
- }
- return clone;
- } :
- function (fragment) {
- return fragment.cloneNode(true);
- };
- }());
-
- // ---------------------------------------------
- // Adopting Nodes
- // ---------------------------------------------
-
- // IE/Edge gotcha with comment nodes
- var nextElementSibling = IE ?
- function (node) {
- while (node = node.nextSibling) {
- if (node.nodeType === ELEMENT_NODE) return node;
- }
- return undefined;
- } :
- function (node) { return node.nextElementSibling; };
-
- var previousElementSibling = IE ?
- function (node) {
- while (node = node.previousSibling) {
- if (node.nodeType === ELEMENT_NODE) return node;
- }
- return undefined;
- } :
- function (node) { return node.previousElementSibling; };
-
- // remove all text nodes from a virtual space
- function removePreviousText(parentNode, node) {
- var previousSibling = node.previousSibling;
- if (previousSibling && previousSibling.nodeType === TEXT_NODE) {
- parentNode.removeChild(previousSibling);
- removePreviousText(parentNode, node);
- }
- }
-
- // avoid errors on obsolete platforms
- function insertBefore(parentNode, target, after) {
- if (after) {
- parentNode.insertBefore(target, after);
- } else {
- parentNode.appendChild(target);
- }
- }
-
- // given an info, tries to find out the best option
- // to replace or update the content
- function discoverNode(parentNode, virtual, info, childNodes) {
- for (var
- target = parentNode,
- document = parentNode.ownerDocument,
- path = info.path,
- virtualNode = getNode(virtual, path),
- i = 0,
- length = path.length;
- i < length; i++
- ) {
- switch (path[i++]) {
- case 'attributes':
- var name = virtualNode.name;
- if (!parentNode.hasAttribute(name)) {
- parentNode.setAttribute(name, '');
- }
- target = parentNode.attributes[name];
- break;
- case 'childNodes':
- var children = getChildren(parentNode);
- var virtualChildren = getChildren(virtualNode.parentNode);
- target = previousElementSibling(virtualNode);
- var before = target ? (path.indexOf.call(virtualChildren, target) + 1) : -1;
- target = nextElementSibling(virtualNode);
- var after = target ? path.indexOf.call(virtualChildren, target) : -1;
- target = document.createComment(UID);
- switch (true) {
- // `${'virtual'}` is actually resolved as `${'any'}`
- // case before < 0 && after < 0: before = 0;
-
- // `</a>${'virtual'}`
- case after < 0:
- after = children.length;
- break;
- // `${'virtual'}<b>`
- case before < 0:
- before = 0;
- // `</a>${'virtual'}<b>`
- default:
- after = -(virtualChildren.length - after);
- break;
- }
- childNodes.push.apply(
- childNodes,
- slice.call(children, before, after)
- );
- if (childNodes.length) {
- insertBefore(
- parentNode,
- target,
- nextElementSibling(childNodes[childNodes.length - 1])
- );
- } else {
- insertBefore(
- parentNode,
- target,
- slice.call(children, after)[0]
- );
- }
- if (childNodes.length === 0) {
- removePreviousText(parentNode, target);
- }
- break;
- default:
- // if the node is not there, create it
- target = getChildren(parentNode)[path[i]] ||
- parentNode.appendChild(
- parentNode.ownerDocument.createElement(
- getNode(virtual, path.slice(0, i + 1)).nodeName
- )
- );
- parentNode = target;
- break;
- }
- }
- return target;
- }
-
- // like createUpdates but for nodes with already a content
- function discoverUpdates(fragment, paths) {
- for (var
- info, childNodes,
- updates = [],
- removeAttributes = [],
- i = 0, length = paths.length;
- i < length; i++
- ) {
- childNodes = [];
- info = paths[i];
- updates[i] = setContent(
- info,
- discoverNode(this, fragment, info, childNodes),
- removeAttributes,
- childNodes
- );
- }
- removeAttributeList(removeAttributes);
- return updates;
- }
-
- // ---------------------------------------------
- // Template related utilities
- // ---------------------------------------------
-
- // given a unique template object
- // create, parse, and store retrieved info
- function createTemplate(template) {
- var paths = [];
- var fragment = createFragment(this, template.join(UIDC));
- var info = {fragment: fragment, paths: paths};
- hyperSeeker(fragment, paths, template.slice());
- templates.set(template, info);
- return info;
- }
-
- // given a generic node, returns a path capable
- // of retrieving such path back again.
- // TODO: worth passing the index when available ?
- function createPath(node) {
- var path = [];
- var parentNode;
- switch(node.nodeType) {
- case ELEMENT_NODE:
- case DOCUMENT_FRAGMENT_NODE:
- parentNode = node;
- break;
- case COMMENT_NODE:
- parentNode = node.parentNode;
- path.unshift(
- 'childNodes',
- path.indexOf.call(parentNode.childNodes, node)
- );
- break;
- case ATTRIBUTE_NODE:
- default: // jsdom here does not provide a nodeType 2 ...
- parentNode = node.ownerElement;
- path.unshift('attributes', node.name);
- break;
- }
- for (
- node = parentNode;
- parentNode = parentNode.parentNode;
- node = parentNode
- ) {
- path.unshift('children', path.indexOf.call(getChildren(parentNode), node));
- }
- return path;
- }
-
- // given a root node and a list of paths
- // creates an array of updates to invoke
- // whenever the next interpolation happens
- function createUpdates(fragment, paths) {
- for (var
- info,
- updates = [],
- removeAttributes = [],
- i = 0, length = paths.length;
- i < length; i++
- ) {
- info = paths[i];
- updates[i] = setContent(
- info,
- getNode(fragment, info.path),
- removeAttributes,
- []
- );
- }
- removeAttributeList(removeAttributes);
- return updates;
- }
-
- // invokes each update function passing interpolated value
- function update() {
- for (var i = 1, length = arguments.length; i < length; i++) {
- this[i - 1](arguments[i]);
- }
- }
-
- // create a template, if unknown
- // upgrade a node to use such template for future updates
- function upgrade(template) {
- template = TL(template);
- var updates;
- var info = templates.get(template) ||
- createTemplate.call(this, template);
- if (notAdopting) {
- var fragment = cloneNode(info.fragment);
- updates = createUpdates.call(this, fragment, info.paths);
- hypers.set(this, {template: template, updates: updates});
- update.apply(updates, arguments);
- this.textContent = '';
- this.appendChild(fragment);
- } else {
- updates = discoverUpdates.call(this, info.fragment, info.paths);
- hypers.set(this, {template: template, updates: updates});
- update.apply(updates, arguments);
- }
- }
-
- // ---------------------------------------------
- // Wires
- // ---------------------------------------------
-
- // create a new wire for generic DOM content
- function wireContent(type) {
- var adopter, content, container, fragment, render, setup, template;
-
- function before(document) {
- fragment = createDocumentFragment(document);
- container = type === 'svg' ?
- document.createElementNS(SVG_NAMESPACE, 'svg') :
- fragment;
- render = bind(container);
- }
-
- function after() {
- if (setup) {
- setup = false;
- if (type === 'svg') {
- appendNodes(fragment, slice.call(container.childNodes));
- }
- content = createContent(fragment);
- }
- return content;
- }
-
- return type === 'adopt' ?
- function adopt(statics) {
- var args = arguments;
- statics = TL(statics);
- if (template !== statics) {
- setup = true;
- template = statics;
- adopter = function (parentNode, children, i) {
- if (setup) {
- if (i < children.length) {
- container = children[i];
- fragment = {
- ownerDocument: container.ownerDocument,
- childNodes: [container],
- children: [container]
- };
- render = hyper.adopt(fragment);
- } else {
- if (OWNER_SVG_ELEMENT in parentNode) type = 'svg';
- before(parentNode.ownerDocument);
- }
- }
- render.apply(null, args);
- return after();
- };
- }
- return adopter;
- } :
- function update(statics) {
- statics = TL(statics);
- if (template !== statics) {
- setup = true;
- template = statics;
- before(hyper.document);
- }
- render.apply(null, arguments);
- return after();
- };
- }
-
- // setup a weak reference if needed and return a wire by ID
- function wireWeakly(obj, type) {
- var wire = wires.get(obj);
- var i = type.indexOf(':');
- var id = type;
- if (-1 < i) {
- id = type.slice(i + 1);
- type = type.slice(0, i) || 'html';
- }
- if (!wire) {
- wire = {};
- wires.set(obj, wire);
- }
- return wire[id] || (wire[id] = wireContent(type));
- }
-
- // avoid processing too many nodes
- // this is about the algorithm used
- // to calculate the least amount of DOM
- // changes needed to show the a new list
- // where there was another one.
- // There is a limit, in terms of performance,
- // on how big can the optimal computation be,
- // so if you change this value be sure your
- // target hardware is good enough.
- hyper.MAX_LIST_SIZE = 1000;
-
- // ---------------------------------------------
- // โก๏ธ ๏ธ๏ธThe End โฐ
- // ---------------------------------------------
- return hyper;
-
-}(document, function () {'use strict';
-
- /*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */
-
- // grid operations
- var
- DELETE = 'del',
- INSERT = 'ins',
- SUBSTITUTE = 'sub',
- TypedArray = /^u/.test(typeof Int32Array) ? Array : Int32Array
- ;
-
- function majinbuu(from, to, MAX_SIZE) {
- var
- fromLength = from.length,
- toLength = to.length,
- TOO_MANY = (MAX_SIZE || Infinity) < Math.sqrt((fromLength || 1) * (toLength || 1))
- ;
- if (fromLength < 1 || TOO_MANY) {
- /* istanbul ignore next */
- Eif (toLength || TOO_MANY) {
- from.splice.apply(from, [0, fromLength].concat(to));
- }
- return;
- }
- if (toLength < 1) {
- from.splice(0);
- return;
- }
- performOperations(
- from,
- getOperations(from, to, levenstein(from, to))
- );
- }
-
- // given an object that would like to intercept
- // all splice operations performed through a list,
- // wraps the list.splice method to delegate such object
- // and it puts back original splice right before
- // every invocation.
- // Note: do not use the same list in two different aura
- majinbuu.aura = function aura(splicer, list) {
- var splice = list.splice;
- list.splice = function hodor() {
- list.splice = splice;
- var result = splicer.splice.apply(splicer, arguments);
- list.splice = hodor;
- return result;
- };
- return list;
- };
-
- return majinbuu;
-
- // Helpers - - - - - - - - - - - - - - - - - - - - - -
-
- // originally readapted from:
- // http://webreflection.blogspot.co.uk/2009/02/levenshtein-algorithm-revisited-25.html
- // then rewritten in C for Emscripten (see levenstein.c)
- // then "screw you ASM" due no much gain but very bloated code
- function levenstein(from, to) {
- var fromLength = from.length + 1;
- var toLength = to.length + 1;
- var size = fromLength * toLength;
- var x = 0;
- var y = 0;
- var X = 0;
- var Y = 0;
- var crow = 0;
- var prow = 0;
- var del, ins, sub;
- var grid = new TypedArray(size);
- grid[0] = 0;
- while (++x < toLength) grid[x] = x;
- while (++y < fromLength) {
- X = x = 0;
- prow = crow;
- crow = y * toLength;
- grid[crow + x] = y;
- while (++x < toLength) {
- del = grid[prow + x] + 1;
- ins = grid[crow + X] + 1;
- sub = grid[prow + X] + (from[Y] == to[X] ? 0 : 1);
- grid[crow + x] = del < ins ?
- (del < sub ?
- del : sub) :
- (ins < sub ?
- ins : sub);
- ++X;
- };
- Y = y;
- }
- return grid;
- }
-
- // add operations (in reversed order)
- function addOperation(list, type, x, y, count, items) {
- list.unshift({
- type: type,
- x: x,
- y: y,
- count: count,
- items: items
- });
- }
-
- // walk the Levenshtein grid bottom -> up
- function getOperations(Y, X, grid) {
- var
- list = [],
- YL = Y.length + 1,
- XL = X.length + 1,
- y = YL - 1,
- x = XL - 1,
- cell, top, left, diagonal,
- crow, prow
- ;
- while (x && y) {
- crow = y * XL + x;
- prow = crow - XL;
- cell = grid[crow];
- top = grid[prow];
- left = grid[crow - 1];
- diagonal = grid[prow - 1];
- if (diagonal <= left && diagonal <= top && diagonal <= cell) {
- x--;
- y--;
- if (diagonal < cell) {
- addOperation(list, SUBSTITUTE, x, y, 1, [X[x]]);
- }
- }
- else if (left <= top && left <= cell) {
- x--;
- addOperation(list, INSERT, x, y, 0, [X[x]]);
- }
- else {
- y--;
- addOperation(list, DELETE, x, y, 1, []);
- }
- }
- while (x--) {
- addOperation(list, INSERT, x, y, 0, [X[x]]);
- }
- while (y--) {
- addOperation(list, DELETE, x, y, 1, []);
- }
- return list;
- }
-
- /* grouped operations */
- function performOperations(target, operations) {
- var
- diff = 0,
- i = 1,
- length = operations.length,
- curr, prev, op
- ;
- /* istanbul ignore else */
- Eif (length) {
- op = (prev = operations[0]);
- while (i < length) {
- curr = operations[i++];
- if (prev.type === curr.type && (curr.x - prev.x) <= 1 && (curr.y - prev.y) <= 1) {
- op.count += curr.count;
- op.items = op.items.concat(curr.items);
- } else {
- target.splice.apply(target, [op.y + diff, op.count].concat(op.items));
- diff += op.type === INSERT ?
- op.items.length : (op.type === DELETE ?
- -op.count : 0);
- op = curr;
- }
- prev = curr;
- }
- target.splice.apply(target, [op.y + diff, op.count].concat(op.items));
- }
- }
-
- /* one-by-one operation (testing purpose)
- function performOperations(target, operations) {
- for (var op, diff = 0, i = 0, length = operations.length; i < length; i++) {
- op = operations[i];
- target.splice.apply(target, [op.y + diff, op.count].concat(op.items));
- diff += op.type === INSERT ?
- op.items.length : (op.type === DELETE ?
- -op.count : 0);
- }
- }
- // */
-
-}()));
-
-// umd.KISS
-try { module.exports = hyperHTML; } catch(o_O) {} |
| 1 -2 | 1ร -28ร | var hyperHTML=function(){"use strict";/*! (C) 2017 Andrea Giammarchi @WebReflection (MIT) */
-function e(e){return C in this&&this[C].s===e?y.apply(this,arguments):b.apply(this,arguments)}function t(e,t){for(var n,r=k?T:x,i=E.call(e.attributes),c=0,a=i.length;c<a;c++)n=i[c],n.value===r&&t.push(o(e,k?e.getAttributeNode(N.shift()):n))}function n(e,o){for(var a,l,u=E.call(e.childNodes),s=u.length,h=0;h<s;h++)switch(a=u[h],a.nodeType){case 1:t(a,o),n(a,o);break;case 8:a.textContent===T&&(1===s?(o.push(r(e)),e.removeChild(a)):!(h<1||1===u[h-1].nodeType)||h+1!==s&&1!==u[h+1].nodeType?(l=e.ownerDocument.createTextNode(""),o.push(c(l)),e.replaceChild(l,a)):o.push(i(a)));break;case 3:"STYLE"===e.nodeName&&a.textContent===x&&o.push(c(e))}}function r(e){return function t(n){switch(typeof n){case"string":e.innerHTML=n;break;case"number":case"boolean":e.textContent=n;break;default:if(Array.isArray(n))Iif(1===n.length)t(n[0]);else Iif("string"==typeof n[0])t(n.join(""));else{var r=l(e.childNodes,n);-1<r&&p(e,n,r)}else s(e,n)}}}function o(e,t){var n,r=t.name,o="on"===r.slice(0,2),i=r in e&&!w.test(r);return i&&e.removeAttribute(r),i?function(t){n!==t&&(n=t,e[r]=o&&"handleEvent"in t?t.handleEvent.bind(t):t)}:function(e){n!==e&&(t.value=n=e)}}function i(e){var t=document.createDocumentFragment(),n=[];return function r(o){var i,c=e.parentNode;switch(typeof o){case"string":case"number":case"boolean":h(n,0),u(t,o),n=E.call(t.childNodes),c.insertBefore(t,e);break;default:Array.isArray(o)?0===o.length?r(o[0]):"string"==typeof o[0]?r(o.join("")):-1<(i=l(n,o))&&(h(n,i),o=o.slice(i),a(t,o),c.insertBefore(t,e),n.push.apply(n,o)):(h(n,0),n=11===o.nodeType?E.call(o.childNodes):[o],c.insertBefore(o,e))}}}function c(e){var t;return function(n){t!==n&&(e.textContent=t=n)}}function a(e,t){for(var n=0,r=t.length;n<r;n++)e.appendChild(t[n])}function l(e,t){Iif(e===t)return-1;for(var n=0,r=e.length,o=t.length;n<r;){if(!(n<o&&e[n]===t[n]))return n;n++}return n===o?-1:n}function u(e,t){var n=k&&/^[^\S]*?<(t(?:head|body|foot|r|d|h))/i.test(t),r=e.ownerDocument.createElement("template");r.innerHTML=n?"<table>"+t+"</table>":t,n&&(r={childNodes:r.querySelectorAll(RegExp.$1)}),a(e,E.call((r.content||r).childNodes))}function s(e,t){switch(t.nodeType){case 1:var n=e.childNodes;if(0<n.length&&n[0]===t){h(n,1);break}d(e,t);break;case 11:-1<l(e.childNodes,t.childNodes)&&d(e,t);break;case 3:e.textContent=t.textContent}}function h(e,t){for(var n,r=e.length;t<r--;)n=e[r],n.parentNode.removeChild(n)}function d(e,t){e.textContent="",e.appendChild(t)}function f(e){for(var t,n=[],r=e.childNodes,o=0,i=r.length;o<i;o++)t=r[o],(1===t.nodeType||0<D.call(t.textContent).length)&&n.push(t);return i=n.length,i<2?(t=i<1?e:n[0],function(){return t}):function(){return n}}function p(e,t,n){var r=e.ownerDocument.createDocumentFragment();0<n?(h(e.childNodes,n),a(r,t.slice(n)),e.appendChild(r)):(a(r,t),d(e,r))}function g(t){var n,r,o,i,c,l;return function(u){return l!==u&&(c=!0,l=u,o=document.createDocumentFragment(),r="svg"===t?document.createElementNS("http://www.w3.org/2000/svg","svg"):o,i=e.bind(r)),i.apply(null,arguments),c&&(c=!1,"svg"===t&&a(o,E.call(r.childNodes)),n=f(o)),n()}}function m(e,t,n){return e[t]||(e[t]=g(n))}function v(e,t){var n=L.get(e)||(L.set(e,n={}),n),r=t.indexOf(":");return r<0?m(n,t,t):m(n,t.slice(r+1),t.slice(0,r)||"html")}function y(){for(var e=1,t=arguments.length,n=this[C].u;e<t;e++)n[e-1](arguments[e]);return this}function b(e){var t=[],r=e.join(x);return k?(N=[],u(this,r.replace(M,A))):1===this.nodeType?this.innerHTML=r:u(this,r),n(this,t),this[C]={s:e,u:t},y.apply(this,arguments)}e.wire=function(e,t){return arguments.length<1?g("html"):null==e?g(t||"html"):v(e,t||"html")};var N,w=/^style$/i,C="_hyper_html: ",T=C+(Math.random()*new Date|0)+";",x="<!--"+T+"-->",k="documentMode"in document,M=k&&new RegExp("([^\\S][a-z]+[a-z0-9_-]*=)(['\"])"+x+"\\2","g"),A=k&&function(e,t,n){return N.push(t.slice(1,-1)),t+n+T+n},D=C.trim||function(){return this.replace(/^\s+|\s+$/g,"")},E=[].slice,L=typeof WeakMap==typeof L?{get:function(e){return e[C]},set:function(e,t){Object.defineProperty(e,C,{configurable:!0,value:t})}}:new WeakMap;return e}();try{module.exports=hyperHTML}catch(e){} |
| File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
|---|---|---|---|---|---|---|---|---|---|
| hyperHTML/ | -100% | -695/695 | -100% | -384/384 | -100% | -112/112 | -100% | -682/682 | -