@point-grab/angular 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Nacho Labs LLC
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nacho Labs LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PointGrabAPI, PointGrabOptions, Plugin, ClassFilter, HtmlCleaner } from '
|
|
1
|
+
import { PointGrabAPI, PointGrabOptions, Plugin, ClassFilter, HtmlCleaner } from '@point-grab/core';
|
|
2
2
|
import { InjectionToken, EnvironmentProviders } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Initialize
|
|
5
|
+
* Initialize point-grab with Angular-specific resolvers and filters.
|
|
6
6
|
* Idempotent -- subsequent calls return the same instance.
|
|
7
7
|
*/
|
|
8
8
|
declare function initPointGrabAngular(options?: Partial<PointGrabOptions>): PointGrabAPI;
|
|
@@ -10,12 +10,12 @@ declare function initPointGrabAngular(options?: Partial<PointGrabOptions>): Poin
|
|
|
10
10
|
declare function getPointGrabApi(): PointGrabAPI | null;
|
|
11
11
|
/** Register a plugin on the current instance. */
|
|
12
12
|
declare function registerPointGrabPlugin(plugin: Plugin): void;
|
|
13
|
-
/** Tear down the
|
|
13
|
+
/** Tear down the point-grab instance. */
|
|
14
14
|
declare function disposePointGrab(): void;
|
|
15
15
|
|
|
16
|
-
declare const
|
|
16
|
+
declare const POINT_GRAB_API: InjectionToken<PointGrabAPI>;
|
|
17
17
|
/**
|
|
18
|
-
* Angular DI provider that initializes
|
|
18
|
+
* Angular DI provider that initializes point-grab at environment bootstrap.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
@@ -49,4 +49,4 @@ declare const angularClassFilter: ClassFilter;
|
|
|
49
49
|
/** Strips _nghost-* and _ngcontent-* attributes from serialized HTML. */
|
|
50
50
|
declare const angularHtmlCleaners: HtmlCleaner[];
|
|
51
51
|
|
|
52
|
-
export {
|
|
52
|
+
export { POINT_GRAB_API, angularClassFilter, angularHtmlCleaners, disposePointGrab, getPointGrabApi, initPointGrabAngular, providePointGrab, registerPointGrabPlugin, resolveComponent, resolveSource, resolveSourceForComponent };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/init.ts
|
|
2
|
-
import { init, createNoopApi } from "
|
|
2
|
+
import { init, createNoopApi } from "@point-grab/core";
|
|
3
3
|
|
|
4
4
|
// src/resolvers/ng-utils.ts
|
|
5
5
|
function getNgApi() {
|
|
@@ -70,7 +70,7 @@ function resolveComponent(element) {
|
|
|
70
70
|
|
|
71
71
|
// src/resolvers/source-resolver.ts
|
|
72
72
|
function getSourceMap() {
|
|
73
|
-
return globalThis.
|
|
73
|
+
return globalThis.__POINT_GRAB_SOURCE_MAP__ ?? null;
|
|
74
74
|
}
|
|
75
75
|
function resolveSource(element) {
|
|
76
76
|
const sourceMap = getSourceMap();
|
|
@@ -149,18 +149,18 @@ import {
|
|
|
149
149
|
makeEnvironmentProviders,
|
|
150
150
|
provideEnvironmentInitializer
|
|
151
151
|
} from "@angular/core";
|
|
152
|
-
var
|
|
152
|
+
var POINT_GRAB_API = new InjectionToken("POINT_GRAB_API");
|
|
153
153
|
function providePointGrab(options) {
|
|
154
154
|
return makeEnvironmentProviders([
|
|
155
155
|
{
|
|
156
|
-
provide:
|
|
156
|
+
provide: POINT_GRAB_API,
|
|
157
157
|
useFactory: () => initPointGrabAngular(options)
|
|
158
158
|
},
|
|
159
159
|
provideEnvironmentInitializer(() => initPointGrabAngular(options))
|
|
160
160
|
]);
|
|
161
161
|
}
|
|
162
162
|
export {
|
|
163
|
-
|
|
163
|
+
POINT_GRAB_API,
|
|
164
164
|
angularClassFilter,
|
|
165
165
|
angularHtmlCleaners,
|
|
166
166
|
disposePointGrab,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts","../src/resolvers/ng-utils.ts","../src/resolvers/component-resolver.ts","../src/resolvers/source-resolver.ts","../src/filters.ts","../src/provide.ts"],"sourcesContent":["import { init, createNoopApi } from 'pointgrab';\nimport type { PointGrabAPI, PointGrabOptions, Plugin } from 'pointgrab';\nimport { resolveComponent } from './resolvers/component-resolver';\nimport { resolveSource } from './resolvers/source-resolver';\nimport { angularClassFilter, angularHtmlCleaners } from './filters';\n\ndeclare const ngDevMode: boolean | undefined;\n\nlet instance: PointGrabAPI | null = null;\n\n/**\n * Initialize pointgrab with Angular-specific resolvers and filters.\n * Idempotent -- subsequent calls return the same instance.\n */\nexport function initPointGrabAngular(options?: Partial<PointGrabOptions>): PointGrabAPI {\n if (instance) return instance;\n\n // No-op in Angular production builds\n if (options?.devOnly !== false && typeof ngDevMode !== 'undefined' && !ngDevMode) {\n instance = createNoopApi();\n return instance;\n }\n\n instance = init(options);\n instance.setComponentResolver((el) => resolveComponent(el));\n instance.setSourceResolver((el) => resolveSource(el));\n instance.setOptions({\n classFilters: [angularClassFilter],\n htmlCleaners: angularHtmlCleaners,\n });\n\n return instance;\n}\n\n/** Returns the current API instance, or null if not yet initialized. */\nexport function getPointGrabApi(): PointGrabAPI | null {\n return instance;\n}\n\n/** Register a plugin on the current instance. */\nexport function registerPointGrabPlugin(plugin: Plugin): void {\n instance?.registerPlugin(plugin);\n}\n\n/** Tear down the pointgrab instance. */\nexport function disposePointGrab(): void {\n instance?.dispose();\n instance = null;\n}\n","export interface NgDebugApi {\n getComponent<T>(element: Element): T | null;\n getOwningComponent<T>(element: Element): T | null;\n getDirectives(element: Element): unknown[];\n}\n\nexport function getNgApi(): NgDebugApi | null {\n if (typeof window === 'undefined') return null;\n return (window as unknown as Record<string, unknown>).ng as NgDebugApi | undefined ?? null;\n}\n\nexport function cleanComponentName(name: string): string {\n return name.startsWith('_') ? name.slice(1) : name;\n}\n","import { getNgApi, cleanComponentName } from './ng-utils';\n\ninterface ComponentResult {\n name: string | null;\n hostElement: Element | null;\n stack: Array<{ name: string; hostElement: Element | null }>;\n}\n\nexport function resolveComponent(element: Element): ComponentResult {\n const ng = getNgApi();\n if (!ng) return { name: null, hostElement: null, stack: [] };\n\n const stack: Array<{ name: string; hostElement: Element | null }> = [];\n const seen = new Set<object>();\n\n // Walk up the DOM collecting every Angular component host\n let current: Element | null = element;\n while (current) {\n const comp = ng.getComponent(current);\n if (comp && typeof comp === 'object' && !seen.has(comp)) {\n seen.add(comp);\n stack.push({\n name: cleanComponentName(comp.constructor.name),\n hostElement: current,\n });\n }\n current = current.parentElement;\n }\n\n // If no direct component found, try getOwningComponent for the original element\n if (stack.length === 0) {\n let walk: Element | null = element;\n while (walk) {\n const owning = ng.getOwningComponent(walk);\n if (owning && typeof owning === 'object' && !seen.has(owning)) {\n seen.add(owning);\n\n // Find the host element for the owning component\n let host: Element | null = walk.parentElement;\n while (host) {\n if (ng.getComponent(host) === owning) break;\n host = host.parentElement;\n }\n\n stack.push({\n name: cleanComponentName(owning.constructor.name),\n hostElement: host ?? walk.parentElement,\n });\n\n // Continue walking from the host to collect parent components\n current = host?.parentElement ?? walk.parentElement?.parentElement ?? null;\n while (current) {\n const comp = ng.getComponent(current);\n if (comp && typeof comp === 'object' && !seen.has(comp)) {\n seen.add(comp);\n stack.push({\n name: cleanComponentName(comp.constructor.name),\n hostElement: current,\n });\n }\n current = current.parentElement;\n }\n break;\n }\n walk = walk.parentElement;\n }\n }\n\n const closest = stack.length > 0 ? stack[0] : { name: null, hostElement: null };\n\n return {\n name: closest.name,\n hostElement: closest.hostElement,\n stack,\n };\n}\n","import { getNgApi, cleanComponentName } from './ng-utils';\nimport type { NgDebugApi } from './ng-utils';\n\ninterface SourceMapEntry {\n file: string;\n line: number;\n}\n\nfunction getSourceMap(): Record<string, SourceMapEntry> | null {\n return (globalThis as unknown as Record<string, unknown>).__POINTGRAB_SOURCE_MAP__ as\n Record<string, SourceMapEntry> | undefined ?? null;\n}\n\ninterface SourceResult {\n filePath: string | null;\n line: number | null;\n column: number | null;\n}\n\nexport function resolveSource(element: Element): SourceResult {\n const sourceMap = getSourceMap();\n if (!sourceMap) return { filePath: null, line: null, column: null };\n\n const ng = getNgApi();\n if (!ng) return { filePath: null, line: null, column: null };\n\n const componentName = findComponentName(element, ng);\n if (!componentName) return { filePath: null, line: null, column: null };\n\n const entry = sourceMap[componentName];\n if (!entry) return { filePath: null, line: null, column: null };\n\n return { filePath: entry.file, line: entry.line, column: null };\n}\n\nexport function resolveSourceForComponent(componentName: string): SourceResult {\n const sourceMap = getSourceMap();\n if (!sourceMap) return { filePath: null, line: null, column: null };\n\n const entry = sourceMap[componentName];\n if (!entry) return { filePath: null, line: null, column: null };\n\n return { filePath: entry.file, line: entry.line, column: null };\n}\n\nfunction findComponentName(element: Element, ng: NgDebugApi): string | null {\n const direct = ng.getComponent(element);\n if (direct && typeof direct === 'object') {\n return cleanComponentName(direct.constructor.name);\n }\n\n let current: Element | null = element;\n while (current) {\n const owning = ng.getOwningComponent(current);\n if (owning && typeof owning === 'object') {\n return cleanComponentName(owning.constructor.name);\n }\n current = current.parentElement;\n }\n\n return null;\n}\n","import type { ClassFilter, HtmlCleaner } from 'pointgrab';\n\n/** Drops Angular-generated classes: ng-*, _ng* */\nexport const angularClassFilter: ClassFilter = (className: string) =>\n !className.startsWith('ng-') && !className.startsWith('_ng');\n\nconst NG_ATTR_QUOTED_RE = /\\s_ng(?:host|content)-[a-z0-9-]+=\"[^\"]*\"/gi;\nconst NG_ATTR_BARE_RE = /\\s_ng(?:host|content)-[a-z0-9-]+/gi;\n\n/** Strips _nghost-* and _ngcontent-* attributes from serialized HTML. */\nexport const angularHtmlCleaners: HtmlCleaner[] = [\n { pattern: NG_ATTR_QUOTED_RE, replacement: '' },\n { pattern: NG_ATTR_BARE_RE, replacement: '' },\n];\n","import {\n InjectionToken,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n type EnvironmentProviders,\n} from '@angular/core';\nimport type { PointGrabAPI, PointGrabOptions } from 'pointgrab';\nimport { initPointGrabAngular } from './init';\n\nexport const POINTGRAB_API = new InjectionToken<PointGrabAPI>('POINTGRAB_API');\n\n/**\n * Angular DI provider that initializes pointgrab at environment bootstrap.\n *\n * @example\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [providePointGrab()],\n * });\n * ```\n */\nexport function providePointGrab(\n options?: Partial<PointGrabOptions>,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: POINTGRAB_API,\n useFactory: () => initPointGrabAngular(options),\n },\n provideEnvironmentInitializer(() => initPointGrabAngular(options)),\n ]);\n}\n"],"mappings":";AAAA,SAAS,MAAM,qBAAqB;;;ACM7B,SAAS,WAA8B;AAC5C,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,SAAQ,OAA8C,MAAgC;AACxF;AAEO,SAAS,mBAAmB,MAAsB;AACvD,SAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;AAChD;;;ACLO,SAAS,iBAAiB,SAAmC;AAClE,QAAM,KAAK,SAAS;AACpB,MAAI,CAA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AAA,IACA,8BAA8B,MAAM,qBAAqB,OAAO,CAAC;AAAA,EACnE,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/resolvers/ng-utils.ts","../src/resolvers/component-resolver.ts","../src/resolvers/source-resolver.ts","../src/filters.ts","../src/provide.ts"],"sourcesContent":["import { init, createNoopApi } from '@point-grab/core';\nimport type { PointGrabAPI, PointGrabOptions, Plugin } from '@point-grab/core';\nimport { resolveComponent } from './resolvers/component-resolver';\nimport { resolveSource } from './resolvers/source-resolver';\nimport { angularClassFilter, angularHtmlCleaners } from './filters';\n\ndeclare const ngDevMode: boolean | undefined;\n\nlet instance: PointGrabAPI | null = null;\n\n/**\n * Initialize point-grab with Angular-specific resolvers and filters.\n * Idempotent -- subsequent calls return the same instance.\n */\nexport function initPointGrabAngular(options?: Partial<PointGrabOptions>): PointGrabAPI {\n if (instance) return instance;\n\n // No-op in Angular production builds\n if (options?.devOnly !== false && typeof ngDevMode !== 'undefined' && !ngDevMode) {\n instance = createNoopApi();\n return instance;\n }\n\n instance = init(options);\n instance.setComponentResolver((el) => resolveComponent(el));\n instance.setSourceResolver((el) => resolveSource(el));\n instance.setOptions({\n classFilters: [angularClassFilter],\n htmlCleaners: angularHtmlCleaners,\n });\n\n return instance;\n}\n\n/** Returns the current API instance, or null if not yet initialized. */\nexport function getPointGrabApi(): PointGrabAPI | null {\n return instance;\n}\n\n/** Register a plugin on the current instance. */\nexport function registerPointGrabPlugin(plugin: Plugin): void {\n instance?.registerPlugin(plugin);\n}\n\n/** Tear down the point-grab instance. */\nexport function disposePointGrab(): void {\n instance?.dispose();\n instance = null;\n}\n","export interface NgDebugApi {\r\n getComponent<T>(element: Element): T | null;\r\n getOwningComponent<T>(element: Element): T | null;\r\n getDirectives(element: Element): unknown[];\r\n}\r\n\r\nexport function getNgApi(): NgDebugApi | null {\r\n if (typeof window === 'undefined') return null;\r\n return (window as unknown as Record<string, unknown>).ng as NgDebugApi | undefined ?? null;\r\n}\r\n\r\nexport function cleanComponentName(name: string): string {\r\n return name.startsWith('_') ? name.slice(1) : name;\r\n}\r\n","import { getNgApi, cleanComponentName } from './ng-utils';\r\n\r\ninterface ComponentResult {\r\n name: string | null;\r\n hostElement: Element | null;\r\n stack: Array<{ name: string; hostElement: Element | null }>;\r\n}\r\n\r\nexport function resolveComponent(element: Element): ComponentResult {\r\n const ng = getNgApi();\r\n if (!ng) return { name: null, hostElement: null, stack: [] };\r\n\r\n const stack: Array<{ name: string; hostElement: Element | null }> = [];\r\n const seen = new Set<object>();\r\n\r\n // Walk up the DOM collecting every Angular component host\r\n let current: Element | null = element;\r\n while (current) {\r\n const comp = ng.getComponent(current);\r\n if (comp && typeof comp === 'object' && !seen.has(comp)) {\r\n seen.add(comp);\r\n stack.push({\r\n name: cleanComponentName(comp.constructor.name),\r\n hostElement: current,\r\n });\r\n }\r\n current = current.parentElement;\r\n }\r\n\r\n // If no direct component found, try getOwningComponent for the original element\r\n if (stack.length === 0) {\r\n let walk: Element | null = element;\r\n while (walk) {\r\n const owning = ng.getOwningComponent(walk);\r\n if (owning && typeof owning === 'object' && !seen.has(owning)) {\r\n seen.add(owning);\r\n\r\n // Find the host element for the owning component\r\n let host: Element | null = walk.parentElement;\r\n while (host) {\r\n if (ng.getComponent(host) === owning) break;\r\n host = host.parentElement;\r\n }\r\n\r\n stack.push({\r\n name: cleanComponentName(owning.constructor.name),\r\n hostElement: host ?? walk.parentElement,\r\n });\r\n\r\n // Continue walking from the host to collect parent components\r\n current = host?.parentElement ?? walk.parentElement?.parentElement ?? null;\r\n while (current) {\r\n const comp = ng.getComponent(current);\r\n if (comp && typeof comp === 'object' && !seen.has(comp)) {\r\n seen.add(comp);\r\n stack.push({\r\n name: cleanComponentName(comp.constructor.name),\r\n hostElement: current,\r\n });\r\n }\r\n current = current.parentElement;\r\n }\r\n break;\r\n }\r\n walk = walk.parentElement;\r\n }\r\n }\r\n\r\n const closest = stack.length > 0 ? stack[0] : { name: null, hostElement: null };\r\n\r\n return {\r\n name: closest.name,\r\n hostElement: closest.hostElement,\r\n stack,\r\n };\r\n}\r\n","import { getNgApi, cleanComponentName } from './ng-utils';\nimport type { NgDebugApi } from './ng-utils';\n\ninterface SourceMapEntry {\n file: string;\n line: number;\n}\n\nfunction getSourceMap(): Record<string, SourceMapEntry> | null {\n return (globalThis as unknown as Record<string, unknown>).__POINT_GRAB_SOURCE_MAP__ as\n Record<string, SourceMapEntry> | undefined ?? null;\n}\n\ninterface SourceResult {\n filePath: string | null;\n line: number | null;\n column: number | null;\n}\n\nexport function resolveSource(element: Element): SourceResult {\n const sourceMap = getSourceMap();\n if (!sourceMap) return { filePath: null, line: null, column: null };\n\n const ng = getNgApi();\n if (!ng) return { filePath: null, line: null, column: null };\n\n const componentName = findComponentName(element, ng);\n if (!componentName) return { filePath: null, line: null, column: null };\n\n const entry = sourceMap[componentName];\n if (!entry) return { filePath: null, line: null, column: null };\n\n return { filePath: entry.file, line: entry.line, column: null };\n}\n\nexport function resolveSourceForComponent(componentName: string): SourceResult {\n const sourceMap = getSourceMap();\n if (!sourceMap) return { filePath: null, line: null, column: null };\n\n const entry = sourceMap[componentName];\n if (!entry) return { filePath: null, line: null, column: null };\n\n return { filePath: entry.file, line: entry.line, column: null };\n}\n\nfunction findComponentName(element: Element, ng: NgDebugApi): string | null {\n const direct = ng.getComponent(element);\n if (direct && typeof direct === 'object') {\n return cleanComponentName(direct.constructor.name);\n }\n\n let current: Element | null = element;\n while (current) {\n const owning = ng.getOwningComponent(current);\n if (owning && typeof owning === 'object') {\n return cleanComponentName(owning.constructor.name);\n }\n current = current.parentElement;\n }\n\n return null;\n}\n","import type { ClassFilter, HtmlCleaner } from '@point-grab/core';\n\n/** Drops Angular-generated classes: ng-*, _ng* */\nexport const angularClassFilter: ClassFilter = (className: string) =>\n !className.startsWith('ng-') && !className.startsWith('_ng');\n\nconst NG_ATTR_QUOTED_RE = /\\s_ng(?:host|content)-[a-z0-9-]+=\"[^\"]*\"/gi;\nconst NG_ATTR_BARE_RE = /\\s_ng(?:host|content)-[a-z0-9-]+/gi;\n\n/** Strips _nghost-* and _ngcontent-* attributes from serialized HTML. */\nexport const angularHtmlCleaners: HtmlCleaner[] = [\n { pattern: NG_ATTR_QUOTED_RE, replacement: '' },\n { pattern: NG_ATTR_BARE_RE, replacement: '' },\n];\n","import {\n InjectionToken,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n type EnvironmentProviders,\n} from '@angular/core';\nimport type { PointGrabAPI, PointGrabOptions } from '@point-grab/core';\nimport { initPointGrabAngular } from './init';\n\nexport const POINT_GRAB_API = new InjectionToken<PointGrabAPI>('POINT_GRAB_API');\n\n/**\n * Angular DI provider that initializes point-grab at environment bootstrap.\n *\n * @example\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [providePointGrab()],\n * });\n * ```\n */\nexport function providePointGrab(\n options?: Partial<PointGrabOptions>,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: POINT_GRAB_API,\n useFactory: () => initPointGrabAngular(options),\n },\n provideEnvironmentInitializer(() => initPointGrabAngular(options)),\n ]);\n}\n"],"mappings":";AAAA,SAAS,MAAM,qBAAqB;;;ACM7B,SAAS,WAA8B;AAC5C,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,SAAQ,OAA8C,MAAgC;AACxF;AAEO,SAAS,mBAAmB,MAAsB;AACvD,SAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;AAChD;;;ACLO,SAAS,iBAAiB,SAAmC;AAClE,QAAM,KAAK,SAAS;AACpB,MAAI,CAAC,GAAI,QAAO,EAAE,MAAM,MAAM,aAAa,MAAM,OAAO,CAAC,EAAE;AAE3D,QAAM,QAA8D,CAAC;AACrE,QAAM,OAAO,oBAAI,IAAY;AAG7B,MAAI,UAA0B;AAC9B,SAAO,SAAS;AACd,UAAM,OAAO,GAAG,aAAa,OAAO;AACpC,QAAI,QAAQ,OAAO,SAAS,YAAY,CAAC,KAAK,IAAI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AW,KAAK,KAAK,CAAC,UAAU,WAAW,KAAK;AAE7D,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AAGjB,IAAM,sBAAqC;AAAA,EAChD,EAAE,SAAS,mBAAmB,aAAa,GAAG;AAAA,EAC9C,EAAE,SAAS,iBAAiB,aAAa,GAAG;AAC9C;;;AJLA,IAAI,WAAgC;AAM7B,SAAS,qBAAqB,SAAmD;AACtF,MAAI,SAAU,QAAO;AAGrB,MAAI,SAAS,YAAY,SAAS,OAAO,cAAc,eAAe,CAAC,WAAW;AAChF,eAAW,cAAc;AACzB,WAAO;AAAA,EACT;AAEA,aAAW,KAAK,OAAO;AACvB,WAAS,qBAAqB,CAAC,OAAO,iBAAiB,EAAE,CAAC;AAC1D,WAAS,kBAAkB,CAAC,OAAO,cAAc,EAAE,CAAC;AACpD,WAAS,WAAW;AAAA,IAClB,cAAc,CAAC,kBAAkB;AAAA,IACjC,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AACT;AAGO,SAAS,kBAAuC;AACrD,SAAO;AACT;AAGO,SAAS,wBAAwB,QAAsB;AAC5D,YAAU,eAAe,MAAM;AACjC;AAGO,SAAS,mBAAyB;AACvC,YAAU,QAAQ;AAClB,aAAW;AACb;;;AKhDA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAIA,IAAM,iBAAiB,IAAI,eAA6B,gBAAgB;AAYxE,SAAS,iBACd,SACsB;AACtB,SAAO,yBAAyB;AAAA,IAC9B;AAAA,MACE,SAAS;AAAA,MACT,YAAY,MAAM,qBAAqB,OAAO;AAAA,IAChD;AAAA,IACA,8BAA8B,MAAM,qBAAqB,OAAO,CAAC;AAAA,EACnE,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@point-grab/angular",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Angular adapter for
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Angular adapter for point-grab",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Nate Richardson",
|
|
7
|
-
"email": "hello@
|
|
7
|
+
"email": "hello@nacholabs.net",
|
|
8
8
|
"url": "https://github.com/naterchrdsn"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"keywords": [
|
|
31
|
-
"
|
|
31
|
+
"point-grab",
|
|
32
32
|
"angular",
|
|
33
33
|
"element-picker",
|
|
34
34
|
"developer-tools",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@angular/core": ">=17.0.0",
|
|
39
|
-
"
|
|
39
|
+
"@point-grab/core": "0.1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@angular/core": {
|