diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 09:35:01 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 09:37:12 -0300 |
commit | ec25e5f8c208c22a3847d5294aa0c698faea5ffc (patch) | |
tree | 6f1ebb8ae972f232e3a5a7ad042f9e383f4d8647 | |
parent | bf4c680ec16267e4757e773317cc56c5603bbb68 (diff) |
html: chunkwrap interface stub
-rw-r--r-- | src/util/html.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/util/html.js b/src/util/html.js index c7157a8b..28ee50d7 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -82,6 +82,13 @@ export const noEdgeWhitespace = Symbol(); // character). export const blockwrap = Symbol(); +// Don't pass this directly, use html.metatag('chunkwrap') instead. +// Causes *contained* content to be split by the metatag's "split" attribute, +// and each chunk to be considered its own unit for word wrapping. All these +// units are *not* wrapped in any containing element, so only the chunks are +// considered wrappable units, not the entire element! +export const chunkwrap = Symbol(); + // Recursive helper function for isBlank, which basically flattens an array // and returns as soon as it finds any content - a non-blank case - and doesn't // traverse templates of its own accord. If it doesn't find directly non-blank @@ -273,7 +280,7 @@ export function metatag(identifier, ...args) { args[0] instanceof Tag || args[0] instanceof Template) ) { - opts = args[0]; /* eslint-disable-line no-unused-vars */ + opts = args[0]; content = args[1]; } else { content = args[0]; @@ -283,6 +290,9 @@ export function metatag(identifier, ...args) { case 'blockwrap': return new Tag(null, {[blockwrap]: true}, content); + case 'chunkwrap': + return new Tag(null, {[chunkwrap]: true, ...opts}, content); + default: throw new Error(`Unknown metatag "${identifier}"`); } @@ -479,6 +489,21 @@ export class Tag { return this.#getAttributeFlag(blockwrap); } + set chunkwrap(value) { + this.#setAttributeFlag(chunkwrap, value); + + try { + this.content = content; + } catch (error) { + this.#setAttributeFlag(chunkwrap, false); + throw error; + } + } + + get chunkwrap() { + return this.#getAttributeFlag(chunkwrap); + } + toString() { if (this.onlyIfContent && isBlank(this.content)) { return ''; |