1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.isHammerJsUsedInTemplate = void 0;
|
---|
11 | const schematics_1 = require("@angular/cdk/schematics");
|
---|
12 | /** List of known events which are supported by the "HammerGesturesPlugin". */
|
---|
13 | const STANDARD_HAMMERJS_EVENTS = [
|
---|
14 | // Events supported by the "HammerGesturesPlugin". See:
|
---|
15 | // angular/angular/blob/0119f46d/packages/platform-browser/src/dom/events/hammer_gestures.ts#L19
|
---|
16 | 'pan', 'panstart', 'panmove', 'panend', 'pancancel', 'panleft',
|
---|
17 | 'panright', 'panup', 'pandown', 'pinch', 'pinchstart', 'pinchmove',
|
---|
18 | 'pinchend', 'pinchcancel', 'pinchin', 'pinchout', 'press', 'pressup',
|
---|
19 | 'rotate', 'rotatestart', 'rotatemove', 'rotateend', 'rotatecancel', 'swipe',
|
---|
20 | 'swipeleft', 'swiperight', 'swipeup', 'swipedown', 'tap',
|
---|
21 | ];
|
---|
22 | /** List of events which are provided by the deprecated Angular Material "GestureConfig". */
|
---|
23 | const CUSTOM_MATERIAL_HAMMERJS_EVENS = ['longpress', 'slide', 'slidestart', 'slideend', 'slideright', 'slideleft'];
|
---|
24 | /**
|
---|
25 | * Parses the specified HTML and searches for elements with Angular outputs listening to
|
---|
26 | * one of the known HammerJS events. This check naively assumes that the bindings never
|
---|
27 | * match on a component output, but only on the Hammer plugin.
|
---|
28 | */
|
---|
29 | function isHammerJsUsedInTemplate(html) {
|
---|
30 | const document = schematics_1.parse5.parseFragment(html, { sourceCodeLocationInfo: true });
|
---|
31 | let customEvents = false;
|
---|
32 | let standardEvents = false;
|
---|
33 | const visitNodes = (nodes) => {
|
---|
34 | nodes.forEach(node => {
|
---|
35 | if (!isElement(node)) {
|
---|
36 | return;
|
---|
37 | }
|
---|
38 | for (let attr of node.attrs) {
|
---|
39 | if (!customEvents && CUSTOM_MATERIAL_HAMMERJS_EVENS.some(e => `(${e})` === attr.name)) {
|
---|
40 | customEvents = true;
|
---|
41 | }
|
---|
42 | if (!standardEvents && STANDARD_HAMMERJS_EVENTS.some(e => `(${e})` === attr.name)) {
|
---|
43 | standardEvents = true;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | // Do not continue traversing the AST if both type of HammerJS
|
---|
47 | // usages have been detected already.
|
---|
48 | if (!customEvents || !standardEvents) {
|
---|
49 | visitNodes(node.childNodes);
|
---|
50 | }
|
---|
51 | });
|
---|
52 | };
|
---|
53 | visitNodes(document.childNodes);
|
---|
54 | return { customEvents, standardEvents };
|
---|
55 | }
|
---|
56 | exports.isHammerJsUsedInTemplate = isHammerJsUsedInTemplate;
|
---|
57 | function isElement(node) {
|
---|
58 | return !!node.attrs;
|
---|
59 | }
|
---|
60 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFtbWVyLXRlbXBsYXRlLWNoZWNrLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL3NjaGVtYXRpY3MvbmctdXBkYXRlL21pZ3JhdGlvbnMvaGFtbWVyLWdlc3R1cmVzLXY5L2hhbW1lci10ZW1wbGF0ZS1jaGVjay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCx3REFBK0M7QUFFL0MsOEVBQThFO0FBQzlFLE1BQU0sd0JBQXdCLEdBQUc7SUFDL0IsdURBQXVEO0lBQ3ZELGdHQUFnRztJQUNoRyxLQUFLLEVBQVEsVUFBVSxFQUFLLFNBQVMsRUFBSyxRQUFRLEVBQUssV0FBVyxFQUFLLFNBQVM7SUFDaEYsVUFBVSxFQ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