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C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;iBAC5B;qBAAM;oBACH,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;iBACnC;aACJ;SACJ;IACL,CAAC;CACJ;AAED,MAAa,UAAc,SAAQ,MAAM;IACrC;QACI,KAAK,EAAE,CAAC;QACP,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,KAAK,CAAC;CACf;AAND,gCAMC;AAGD,MAAa,aAAiB,SAAQ,SAAS;IAC3C;QACI,KAAK,EAAE,CAAC;QACP,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC;IACnC,CAAC;CACJ;AALD,sCAKC;AAGD,SAAS,WAAW,CAAC,WAAgB,EAAE,YAAmB;IACtD,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC9B,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC5D,IAAI,IAAI,KAAK,aAAa,EAAE;gBACxB,MAAM,CAAC,cAAc,CACjB,WAAW,CAAC,SAAS,EACrB,IAAI,EACJ,MAAM,CAAC,wBAAwB,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAE,CAC7D,CAAC;aACL;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,WAAW,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AACxC,WAAW,CAAC,aAAa,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC","file":"","sourceRoot":"/","sourcesContent":["import { Emitter } from \"simba-eventkit\";\nimport { View, PureView, Subview, PureSubview, OnSubviewCreated } from \"./ViewBase\";\n\ntype PickKeysForType<T extends {}, U> = {\n [P in keyof T]: T[P] extends U ? P : never\n}[keyof T];\n\nclass CCViewBase extends cc.Component {\n protected _emitter: Emitter = new Emitter;\n protected _showed = false;\n private _isHidden = false;\n get isHidden() { return this._isHidden || !this.node.active }\n\n onShow = this._emitter.createEvent<() => void>();\n onHide = this._emitter.createEvent<() => void>();\n\n private _posX: number;\n\n show(): void {\n if (!this.node.parent || !this.isHidden) return;\n if (this.isHidden) {\n this.node.active = true;\n this._isHidden = false;\n this.node.opacity = 255;\n if (this._posX !== undefined)\n this.node.x = this._posX;\n this.onShow.emit();\n }\n }\n\n hide(): void {\n if (!this.node.parent || this.isHidden) return;\n if (!this.isHidden) {\n this._isHidden = true;\n this._posX = this.node.x;\n this.node.opacity = 0;\n this.node.x = 10000;\n this.onHide.emit();\n }\n }\n}\n\nexport class CCView extends CCViewBase implements View {\n readonly _type: \"View\" = \"View\";\n onClose = this._emitter.createEvent<(destroy?: boolean) => void>();\n\n open(parent: CCView) {\n this.node.parent = parent.node;\n }\n\n close(destroy?: boolean): void {\n if (!this.node.parent) return;\n if (destroy) {\n this.node.destroy();\n } else {\n this.node.removeFromParent(false);\n }\n this.onClose.emit(destroy);\n }\n}\n\nexport class CCSubview extends CCViewBase implements Subview {\n readonly _type: \"Subview\" = \"Subview\";\n\n constructor() {\n super();\n\n OnSubviewCreated.emit(this);\n }\n\n onLoad() {\n this.name = this.node.name;\n }\n\n attachParent(parent: CCView) {\n this.node.parent = parent.node;\n }\n}\n\nabstract class PureViewBase<P> implements PureViewBase<P> {\n protected _prevProps: Readonly<P>;\n protected _props: Readonly<P>;\n private _tempProps: Readonly<P>;\n private _prepareUpdate = false;\n private _propBinder: { [key: string]: { target: object | Function, prop: string }[] } = {};\n\n abstract scheduleOnce(callback: Function, delay?: number): void;\n\n setProps(props: P) {\n this._tempProps = props;\n if (!this._props) {\n this._setProps();\n } else {\n if (!this._prepareUpdate) {\n this._prepareUpdate = true;\n this.scheduleOnce(() => { // delay one frame, update at most once per frame\n this._setProps();\n });\n }\n }\n }\n\n protected _setProps() {\n this._prepareUpdate = false;\n this._prevProps = this._props;\n this._props = { ...this._tempProps };\n delete this._tempProps;\n this.onPropsReceive();\n if (!this._prevProps) {\n this.onPropsLoad(this._props);\n } else {\n let keys = new Set([...Object.keys(this._prevProps), ...Object.keys(this._props)]);\n for (let key of keys) {\n if (this._props[key] !== this._prevProps[key]) {\n this.onPropChange(key as Extract<keyof P, string>);\n }\n }\n }\n }\n\n updateProps(props: Partial<P>) {\n if (!this._props) throw new Error(\"setProps first.\");\n let fullProps = this._tempProps ? { ...this._tempProps, ...props } : { ...this._props, ...props };\n this.setProps(fullProps);\n }\n\n /**\n * onLoad() {\n * this.bindProp(\"title\", this.titleLabel, \"string\");\n * this.bindProp(\"percent\", (value) => this.percentLabel.string = value + \"%\");\n * }\n */\n protected bindProp<T extends {}, K extends keyof P>(key: Extract<K, string>, target: (v: P[K]) => void): void;\n protected bindProp<T extends {}, K extends keyof P>(key: Extract<K, string>, target: T, propName: Extract<PickKeysForType<T, P[K]>, string>): void;\n protected bindProp(key: string, target, prop?) {\n if (!this._propBinder[key]) this._propBinder[key] = [];\n this._propBinder[key].push({ target, prop });\n }\n\n protected onPropsReceive(): void {\n\n }\n\n protected onPropsLoad(props: Readonly<P>) {\n for (let key in props) {\n if (this._propBinder[key]) {\n for (const { target, prop } of this._propBinder[key]) {\n if (typeof target === \"function\") {\n target(this._props[key]);\n } else {\n target[prop] = this._props[key];\n }\n }\n }\n }\n }\n\n protected onPropChange(key: Extract<keyof P, string>) {\n if (this._propBinder[key]) {\n for (const { target, prop } of this._propBinder[key]) {\n if (typeof target === \"function\") {\n target(this._props[key]);\n } else {\n target[prop] = this._props[key];\n }\n }\n }\n }\n}\n\nexport class CCPureView<P> extends CCView {\n constructor() {\n super();\n (this as any)._propBinder = {};\n }\n onLoad() { }\n}\nexport interface CCPureView<P> extends PureViewBase<P> { }\n\nexport class CCPureSubview<P> extends CCSubview {\n constructor() {\n super();\n (this as any)._propBinder = {};\n }\n}\nexport interface CCPureSubview<P> extends PureViewBase<P> { }\n\nfunction applyMixins(derivedCtor: any, constructors: any[]) {\n constructors.forEach((baseCtor) => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {\n if (name !== \"constructor\") {\n Object.defineProperty(\n derivedCtor.prototype,\n name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name)!\n );\n }\n });\n });\n}\n\napplyMixins(CCPureView, [PureViewBase]);\napplyMixins(CCPureSubview, [PureViewBase]);\n"]}