aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-08-13 18:35:31 +0530
committerAkshay Nair <phenax5@gmail.com>2023-08-13 18:35:31 +0530
commit2f3de513168ac8a912e4b6540907492437a5f834 (patch)
tree957c286eb8b0806d82279d7596f5f47425d3a9a8 /src/index.ts
parent95602d1b1ac5668772d5d400270b4209ee19057b (diff)
downloadcss-everything-2f3de513168ac8a912e4b6540907492437a5f834.tar.gz
css-everything-2f3de513168ac8a912e4b6540907492437a5f834.zip
feat: adds checked test case + implements pure actions flag + minor changes
Diffstat (limited to '')
-rw-r--r--src/index.ts44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/index.ts b/src/index.ts
index acbb360..af8eb23 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -2,7 +2,6 @@ import { EvalActions, evalExpr } from './eval'
import {
extractDeclaration,
DeclarationEval,
- Declaration,
expressionsToDeclrs,
} from './declarations'
import { parse } from './parser'
@@ -61,30 +60,32 @@ const getEvalActions = (
removeClass: async (id, cls) =>
document.getElementById(id)?.classList.remove(cls),
delay: delay => new Promise(res => setTimeout(res, delay)),
- jsEval: async js => (0, eval)(js),
+ jsEval: async js => !pure && (0, eval)(js),
loadCssx: async (id, url) =>
- new Promise((resolve, reject) => {
- const $link = Object.assign(document.createElement('link'), {
- href: url,
- rel: 'stylesheet',
- })
- $link.onload = () => {
- const $el = document.getElementById(id)
- if ($el) {
- manageElement($el)
- resolve(id)
- } else {
- console.error(`[CSSX] Unable to find root for ${id}`)
- reject(`[CSSX] Unable to find root for ${id}`)
- }
- }
- document.body.appendChild($link)
- }),
+ pure
+ ? ''
+ : new Promise((resolve, reject) => {
+ const $link = Object.assign(document.createElement('link'), {
+ href: url,
+ rel: 'stylesheet',
+ })
+ $link.onload = () => {
+ const $el = document.getElementById(id)
+ if ($el) {
+ manageElement($el)
+ resolve(id)
+ } else {
+ console.error(`[CSSX] Unable to find root for ${id}`)
+ reject(`[CSSX] Unable to find root for ${id}`)
+ }
+ }
+ document.body.appendChild($link)
+ }),
getVariable: async varName => getPropertyValue($element, varName),
updateVariable: async (targetId, varName, value) => {
- const $el = document.getElementById(targetId)
+ const $el = targetId ? document.getElementById(targetId) : $element
if ($el) {
- $el.style.setProperty(varName, JSON.stringify(value))
+ ;($el as any).style.setProperty(varName, JSON.stringify(value))
}
},
setAttribute: async (id, name, value) => {
@@ -108,6 +109,7 @@ const getEvalActions = (
? new FormData($element as HTMLFormElement)
: undefined,
sendRequest: async ({ url, method, data }) => {
+ if (pure) return
await fetch(url, { method, body: data })
// TODO: Handle response?
},