heartbeat-monitor/node_modules/motion-dom/dist/es/effects/attr/index.mjs.map

1 line
2.9 KiB
Plaintext

{"version":3,"file":"index.mjs","sources":["../../../../src/effects/attr/index.ts"],"sourcesContent":["import { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction canSetAsProperty(element: HTMLElement | SVGElement, name: string) {\n if (!(name in element)) return false\n\n const descriptor =\n Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), name) ||\n Object.getOwnPropertyDescriptor(element, name)\n\n // Check if it has a setter\n return descriptor && typeof descriptor.set === \"function\"\n}\n\nexport const addAttrValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n const isProp = canSetAsProperty(element, key)\n const name = isProp\n ? key\n : key.startsWith(\"data\") || key.startsWith(\"aria\")\n ? camelToDash(key)\n : key\n\n /**\n * Set attribute directly via property if available\n */\n const render = isProp\n ? () => {\n ;(element as any)[name] = state.latest[key]\n }\n : () => {\n const v = state.latest[key]\n if (v === null || v === undefined) {\n element.removeAttribute(name)\n } else {\n element.setAttribute(name, String(v))\n }\n }\n\n return state.set(key, value, render)\n}\n\nexport const attrEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addAttrValue)\n)\n"],"names":[],"mappings":";;;;AAMA,SAAS,gBAAgB,CAAC,OAAiC,EAAE,IAAY,EAAA;AACrE,IAAA,IAAI,EAAE,IAAI,IAAI,OAAO,CAAC;AAAE,QAAA,OAAO,KAAK,CAAA;AAEpC,IAAA,MAAM,UAAU,GACZ,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;AACrE,QAAA,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;;IAGl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