UNPKG

motion-dom

Version:
1 lines • 2.8 kB
{"version":3,"file":"visual-element.mjs","sources":["../../../src/layout/visual-element.ts"],"sourcesContent":["import { handOffElementState } from \"../animation/animate/element\"\nimport { hasTransform } from \"../projection/utils/has-transform\"\nimport { HTMLVisualElement } from \"../render/html/HTMLVisualElement\"\nimport { visualElementStore } from \"../render/store\"\n\n/**\n * Get the VisualElement that imperative APIs like animateLayout() and\n * drag() render an element with, creating one if it has none, ready for\n * a projection node to be attached.\n */\nexport function resolveVisualElement(element: HTMLElement): HTMLVisualElement {\n let visualElement = visualElementStore.get(element) as\n | HTMLVisualElement\n | undefined\n\n if (!visualElement) {\n visualElement = new HTMLVisualElement(\n {\n props: {},\n presenceContext: null,\n visualState: {\n latestValues: {},\n renderState: {\n transform: {},\n transformOrigin: {},\n style: {},\n vars: {},\n },\n },\n },\n { allowProjection: true }\n )\n\n /**\n * Values animate() has been rendering on this element move to\n * the VisualElement, so the layout animation composes with\n * them instead of overwriting them.\n */\n handOffElementState(element, visualElement)\n }\n\n /**\n * A first-time element may carry a projection transform in its\n * inline style (e.g. it was cloned from an element mid-animation).\n * That transform isn't tracked in latestValues so the engine can't\n * reset it before measuring - clear it now so the first layout\n * measurement isn't inflated.\n */\n if (element.style.transform && !hasTransform(visualElement.latestValues)) {\n element.style.transform = \"\"\n }\n\n return visualElement\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,OAAoB,EAAA;IACrD,IAAI,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAEnC;IAEf,IAAI,CAAC,aAAa,EAAE;QAChB,aAAa,GAAG,IAAI,iBAAiB,CACjC;AACI,YAAA,KAAK,EAAE,EAAE;AACT,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,WAAW,EAAE;AACT,gBAAA,YAAY,EAAE,EAAE;AAChB,gBAAA,WAAW,EAAE;AACT,oBAAA,SAAS,EAAE,EAAE;AACb,oBAAA,eAAe,EAAE,EAAE;AACnB,oBAAA,KAAK,EAAE,EAAE;AACT,oBAAA,IAAI,EAAE,EAAE;AACX,iBAAA;AACJ,aAAA;AACJ,SAAA,EACD,EAAE,eAAe,EAAE,IAAI,EAAE,CAC5B;AAED;;;;AAIG;AACH,QAAA,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC;IAC/C;AAEA;;;;;;AAMG;AACH,IAAA,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE;AACtE,QAAA,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE;IAChC;AAEA,IAAA,OAAO,aAAa;AACxB;;;;"}