UNPKG

@pixi/react

Version:

Write PixiJS applications using React declarative style.

1 lines 2.43 kB
{"version":3,"file":"insertBefore.mjs","sources":["../../src/helpers/insertBefore.ts"],"sourcesContent":["import {\n Container,\n Filter,\n} from 'pixi.js';\nimport { type HostConfig } from '../typedefs/HostConfig';\nimport { attach } from './attach';\nimport { detach } from './detach';\nimport { invariant } from './invariant';\nimport { log } from './log';\n\nexport function insertBefore(\n parentInstance: HostConfig['containerInstance'],\n childInstance: HostConfig['instance'],\n beforeChildInstance: HostConfig['instance'],\n)\n{\n log('info', 'lifecycle::insertBefore');\n\n invariant(childInstance !== beforeChildInstance, 'Cannot insert node before itself');\n\n if (childInstance instanceof Container)\n {\n const childContainerInstance = childInstance as HostConfig['containerInstance'];\n const childContainer = childInstance as unknown as Container;\n const beforeChildContainer = beforeChildInstance as unknown as Container;\n\n if (childContainerInstance.parent === parentInstance)\n {\n parentInstance.removeChild(childContainer);\n }\n\n const index = parentInstance.getChildIndex(beforeChildContainer);\n\n parentInstance.addChildAt(childContainer, index);\n }\n else if (childInstance instanceof Filter)\n {\n const childFilterInstance = childInstance;\n const instanceState = childFilterInstance.__pixireact;\n\n const targetIndex = instanceState.filters.indexOf(beforeChildInstance as unknown as Filter);\n\n detach(childInstance);\n attach(parentInstance, childInstance, targetIndex);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAUgB,SAAA,YAAA,CACZ,cACA,EAAA,aAAA,EACA,mBAEJ,EAAA;AACI,EAAA,GAAA,CAAI,QAAQ,yBAAyB,CAAA;AAErC,EAAU,SAAA,CAAA,aAAA,KAAkB,qBAAqB,kCAAkC,CAAA;AAEnF,EAAA,IAAI,yBAAyB,SAC7B,EAAA;AACI,IAAA,MAAM,sBAAyB,GAAA,aAAA;AAC/B,IAAA,MAAM,cAAiB,GAAA,aAAA;AACvB,IAAA,MAAM,oBAAuB,GAAA,mBAAA;AAE7B,IAAI,IAAA,sBAAA,CAAuB,WAAW,cACtC,EAAA;AACI,MAAA,cAAA,CAAe,YAAY,cAAc,CAAA;AAAA;AAG7C,IAAM,MAAA,KAAA,GAAQ,cAAe,CAAA,aAAA,CAAc,oBAAoB,CAAA;AAE/D,IAAe,cAAA,CAAA,UAAA,CAAW,gBAAgB,KAAK,CAAA;AAAA,GACnD,MAAA,IACS,yBAAyB,MAClC,EAAA;AACI,IAAA,MAAM,mBAAsB,GAAA,aAAA;AAC5B,IAAA,MAAM,gBAAgB,mBAAoB,CAAA,WAAA;AAE1C,IAAA,MAAM,WAAc,GAAA,aAAA,CAAc,OAAQ,CAAA,OAAA,CAAQ,mBAAwC,CAAA;AAE1F,IAAA,MAAA,CAAO,aAAa,CAAA;AACpB,IAAO,MAAA,CAAA,cAAA,EAAgB,eAAe,WAAW,CAAA;AAAA;AAEzD;;;;"}