aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-08-11 21:21:31 +0530
committerAkshay Nair <phenax5@gmail.com>2023-08-11 21:23:36 +0530
commit5a9942fde65787b35d4eb8e3441af6fe68819612 (patch)
tree011e8087b200a793e154b6e6bbf96e8e1b1c8c20 /src/index.ts
parente0cc82460c0fec4336037996c23947ab39ba4015 (diff)
downloadcss-everything-5a9942fde65787b35d4eb8e3441af6fe68819612.tar.gz
css-everything-5a9942fde65787b35d4eb8e3441af6fe68819612.zip
feat: adds text and inner html properties
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/index.ts b/src/index.ts
index 88347df..b48b1d8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,6 +9,12 @@ const EVENT_HANDLERS = {
submit: '--cssx-on-submit',
}
+const PROPERTIES = [
+ '--cssx-children',
+ '--cssx-text',
+ '--cssx-disgustingly-set-innerhtml'
+]
+
const injectStyles = () => {
const STYLE_TAG_CLASS = 'cssx-style-root'
if (document.querySelector(`.${STYLE_TAG_CLASS}`)) return
@@ -16,7 +22,7 @@ const injectStyles = () => {
const $style = document.createElement('style')
$style.className = STYLE_TAG_CLASS
- const properties = ['--cssx-children', ...Object.values(EVENT_HANDLERS)]
+ const properties = [...PROPERTIES, ...Object.values(EVENT_HANDLERS)]
$style.textContent = `.cssx-layer {
${properties.map((p) => `${p}: ${UNSET_PROPERTY_VALUE};`).join(' ')}
@@ -105,8 +111,14 @@ const manageElement = async ($element: Element, isNewElement: boolean = false) =
if (nodeCount++ > 100) return // NOTE: Temporary. To prevent infinite rec
await handleEvents($element, isNewElement)
- const childrenIds = getChildrenIds($element)
+ const text = getPropertyValue($element, '--cssx-text')
+ if (text) $element.textContent = text
+
+ const html = getPropertyValue($element, '--cssx-disgustingly-set-innerhtml')
+ if (html) $element.innerHTML = html
+
+ const childrenIds = getChildrenIds($element)
if (childrenIds.length > 0) {
const LAYER_CLASS = 'cssx-layer'
const $childrenRoot =