update to 2.0

I overreached on the getter / setters sharing the same names, and everything
_seemed_ to work OK at first, but then when I tried to import it...
This commit is contained in:
2025-09-06 21:46:50 -04:00
parent d11e4e963c
commit 35058fe201
16 changed files with 1801 additions and 676 deletions

View File

@@ -1,25 +1,25 @@
// @license magnet:?xt=urn:btih:723febf9f6185544f57f0660a41489c7d6b4931b&dn=wtfpl.txt
const version = "1.1.0";
const isFluentDomObject = (value) => !!value.fluentDom;
const isHTMLElement = (value) => !!value.nodeType;
const isNumber = (value) => typeof value === "number";
const isString = (value) => typeof value === "string";
/**
* fluent-dom-esm v1.1.0
* fluent-dom-esm v2.0.0
*
* Fluent DOM Manipulation, adapted to ESM and cranked up to v1.1(.0).
* Fluent DOM Manipulation, adapted to ESM and cranked up to v2.0(.0).
*
* https://git.itsericwoodward.com/eric/fluent-dom-esm
*
* v1.1.0 Copyright (c) 2025 Eric Woodward
* v2.0.0 Copyright (c) 2025 Eric Woodward
* Original copyright (c) 2009 Tommy Montgomery (https://glacius.tmont.com/articles/fluent-dom-manipulation-in-javascript)
*
* Released under the WTFPL (Do What the Fuck You Want to Public License)
*
* @author Eric Woodward (v1.1.0 update)
* @author Eric Woodward (v2.0.0 update)
* @author Tommy Montgomery (original)
* @license http://sam.zoy.org/wtfpl/
*/
const APP_VERSION = "2.0.0";
const fluentDomEsm = (function() {
const FluentDom = function(node) {
return new FluentDomInternal(node);
@@ -31,12 +31,11 @@ const fluentDomEsm = (function() {
};
const FluentDomInternal = function(node) {
let root = node || null;
this.fluentDom = version;
this.fluentDom = APP_VERSION;
this.a = this.attr = function(name, value) {
if (!root || value && !root.setAttribute) {
if (!root || typeof name === "undefined" || typeof value === "undefined") {
throw new Error("Cannot set an attribute on a non-element");
}
if (!value) return root.getAttribute(name);
root.setAttribute(name, value);
return this;
};
@@ -76,8 +75,8 @@ const fluentDomEsm = (function() {
root = null;
return this;
};
this.h = this.href = function(link) {
return this.attr("href", link);
this.h = this.href = function(url) {
return this.attr("href", url);
};
this.html = function(content) {
if (!root) {
@@ -85,7 +84,6 @@ const fluentDomEsm = (function() {
"Cannot get or set innerHTML for a non-element"
);
}
if (!content) return root.innerHTML;
root.innerHTML = content;
return this;
};
@@ -99,26 +97,14 @@ const fluentDomEsm = (function() {
root.addEventListener(...props);
return this;
};
this.ohtml = function(content) {
if (!root) {
throw new Error(
"Cannot get or set outerHTML for a non-element"
);
}
if (!content) return root.outerHTML;
root.outerHTML = content;
return this;
};
this.s = this.style = function(prop, value) {
function styleFunction(prop, value) {
if (!root) {
throw new Error("Cannot get or set style for a non-element");
}
if (typeof prop === "undefined") return root.style;
if (typeof value !== "undefined") {
if (typeof prop === "string" && typeof value !== "undefined") {
root.style[prop] = value;
return this;
}
if (typeof prop === "string") return root.style[prop];
if (typeof prop !== "object") {
throw new Error(
`Invalid argument: "prop" must be string or object (found ${typeof prop})`
@@ -128,23 +114,23 @@ const fluentDomEsm = (function() {
root.style[key] = prop[key];
});
return this;
};
}
this.s = this.style = styleFunction;
this.t = this.text = function(text) {
if (!root) {
throw new Error(
"Cannot get or set innerText for a non-element"
);
}
if (typeof text === "undefined") return root.innerText;
return this.append(text);
};
this.title = function(value) {
this.title = function(title) {
if (!root) {
throw new Error(
"Cannot get or set outerHTML for a non-element"
);
}
return this.attr("title", value);
return this.attr("title", title);
};
this.toDom = function() {
return root;