UNPKG

6.34 kBSource Map (JSON)View Raw
1{"version":3,"file":"positioning.service.js","sourceRoot":"","sources":["../../../../src/positioning/positioning.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,uBAAuB,EAAE,OAAO,EAAc,MAAM,MAAM,CAAC;;AAuC1F,MAAM,OAAO,kBAAkB;IAO7B,YACE,MAAc,EACd,eAAiC,EACZ,UAAkB;QARjC,aAAQ,GAAG,IAAI,OAAO,EAAQ,CAAC;QAC/B,qBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAE7B,eAAU,GAAG,KAAK,CAAC;QAQzB,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE;YACjC,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE;gBAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CACxB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAC9C,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EACpC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,EACxC,IAAI,CAAC,QAAQ,CACd,CAAC;gBAEF,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,EAAE;oBAChC,IAAI,IAAI,CAAC,UAAU,EAAE;wBACnB,OAAO;qBACR;oBAED,IAAI,CAAC,gBAAgB;wBACrB,8DAA8D;yBAC3D,OAAO,CAAC,CAAC,eAAoB,EAAE,EAAE;wBAChC,gBAAgB,CACd,eAAe,CAAC,eAAe,CAAC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CAAC,CAAC;KACxC;IAED,IAAI,OAAO,YAAY,UAAU,EAAE;QACjC,OAAO,OAAO,CAAC,aAAa,CAAC;KAC9B;IAED,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import { Injectable, ElementRef, RendererFactory2, Inject, PLATFORM_ID, NgZone } from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\n\nimport { positionElements } from './ng-positioning';\n\nimport { fromEvent, merge, of, animationFrameScheduler, Subject, Observable } from 'rxjs';\nimport { Options } from './models';\n\n\nexport interface PositioningOptions {\n /** The DOM element, ElementRef, or a selector string of an element which will be moved */\n element?: HTMLElement | ElementRef | string;\n\n /** The DOM element, ElementRef, or a selector string of an element which the element will be attached to */\n target?: HTMLElement | ElementRef | string;\n\n /**\n * A string of the form 'vert-attachment horiz-attachment' or 'placement'\n * - placement can be \"top\", \"bottom\", \"left\", \"right\"\n * not yet supported:\n * - vert-attachment can be any of 'top', 'middle', 'bottom'\n * - horiz-attachment can be any of 'left', 'center', 'right'\n */\n attachment?: string;\n\n /** A string similar to `attachment`. The one difference is that, if it's not provided,\n * `targetAttachment` will assume the mirror image of `attachment`.\n */\n targetAttachment?: string;\n\n /** A string of the form 'vert-offset horiz-offset'\n * - vert-offset and horiz-offset can be of the form \"20px\" or \"55%\"\n */\n offset?: string;\n\n /** A string similar to `offset`, but referring to the offset of the target */\n targetOffset?: string;\n\n /** If true component will be attached to body */\n appendToBody?: boolean;\n}\n\n\n@Injectable({providedIn: 'root'})\nexport class PositioningService {\n private options?: Options;\n private update$$ = new Subject<null>();\n private positionElements = new Map();\n private triggerEvent$?: Observable<number|Event|null>;\n private isDisabled = false;\n\n constructor(\n ngZone: NgZone,\n rendererFactory: RendererFactory2,\n @Inject(PLATFORM_ID) platformId: number\n ) {\n\n if (isPlatformBrowser(platformId)) {\n ngZone.runOutsideAngular(() => {\n this.triggerEvent$ = merge(\n fromEvent(window, 'scroll', { passive: true }),\n fromEvent(window, 'resize', { passive: true }),\n of(0, animationFrameScheduler),\n this.update$$\n );\n\n this.triggerEvent$.subscribe(() => {\n if (this.isDisabled) {\n return;\n }\n\n this.positionElements\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .forEach((positionElement: any) => {\n positionElements(\n _getHtmlElement(positionElement.target),\n _getHtmlElement(positionElement.element),\n positionElement.attachment,\n positionElement.appendToBody,\n this.options,\n rendererFactory.createRenderer(null, null)\n );\n });\n });\n });\n }\n }\n\n position(options: PositioningOptions): void {\n this.addPositionElement(options);\n }\n\n get event$(): Observable<number|Event|null>|undefined {\n return this.triggerEvent$;\n }\n\n disable(): void {\n this.isDisabled = true;\n }\n\n enable(): void {\n this.isDisabled = false;\n }\n\n addPositionElement(options: PositioningOptions): void {\n this.positionElements.set(_getHtmlElement(options.element), options);\n }\n\n calcPosition(): void {\n this.update$$.next();\n }\n\n deletePositionElement(elRef: ElementRef): void {\n this.positionElements.delete(_getHtmlElement(elRef));\n }\n\n setOptions(options: Options) {\n this.options = options;\n }\n}\n\nfunction _getHtmlElement(element?: HTMLElement | ElementRef | string): HTMLElement | null {\n // it means that we got a selector\n if (typeof element === 'string') {\n return document.querySelector(element);\n }\n\n if (element instanceof ElementRef) {\n return element.nativeElement;\n }\n\n return element ?? null;\n}\n"]}
\No newline at end of file