@angular-wave/angular.ts 0.0.1
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/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
package/src/public.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { $CompileProvider } from "./core/compile";
|
|
2
|
+
import { htmlAnchorDirective } from "./directive/a";
|
|
3
|
+
import {
|
|
4
|
+
inputDirective,
|
|
5
|
+
ngValueDirective,
|
|
6
|
+
hiddenInputBrowserCacheDirective,
|
|
7
|
+
} from "./directive/input";
|
|
8
|
+
import { formDirective, ngFormDirective } from "./directive/form";
|
|
9
|
+
import { scriptDirective } from "./directive/script";
|
|
10
|
+
import { selectDirective, optionDirective } from "./directive/select";
|
|
11
|
+
import {
|
|
12
|
+
ngBindDirective,
|
|
13
|
+
ngBindHtmlDirective,
|
|
14
|
+
ngBindTemplateDirective,
|
|
15
|
+
} from "./directive/bind";
|
|
16
|
+
import {
|
|
17
|
+
ngClassDirective,
|
|
18
|
+
ngClassEvenDirective,
|
|
19
|
+
ngClassOddDirective,
|
|
20
|
+
} from "./directive/ngClass";
|
|
21
|
+
import { ngCloakDirective } from "./directive/cloak";
|
|
22
|
+
import { ngControllerDirective } from "./directive/ngController";
|
|
23
|
+
import { ngHideDirective, ngShowDirective } from "./directive/ngShowHide";
|
|
24
|
+
import { ngIfDirective } from "./directive/ngIf";
|
|
25
|
+
import {
|
|
26
|
+
ngIncludeDirective,
|
|
27
|
+
ngIncludeFillContentDirective,
|
|
28
|
+
} from "./directive/ngInclude";
|
|
29
|
+
import { ngInitDirective } from "./directive/init";
|
|
30
|
+
import { ngNonBindableDirective } from "./directive/non-bindable";
|
|
31
|
+
import { ngRefDirective } from "./directive/ngRef";
|
|
32
|
+
import { ngRepeatDirective } from "./directive/ngRepeat";
|
|
33
|
+
import { ngStyleDirective } from "./directive/style";
|
|
34
|
+
import {
|
|
35
|
+
ngSwitchDirective,
|
|
36
|
+
ngSwitchWhenDirective,
|
|
37
|
+
ngSwitchDefaultDirective,
|
|
38
|
+
} from "./directive/ngSwitch";
|
|
39
|
+
import { ngOptionsDirective } from "./directive/ngOptions";
|
|
40
|
+
import { ngTranscludeDirective } from "./directive/ngTransclude";
|
|
41
|
+
import { ngModelDirective } from "./directive/ngModel";
|
|
42
|
+
import { ngListDirective } from "./directive/list";
|
|
43
|
+
import { ngChangeDirective } from "./directive/change";
|
|
44
|
+
import {
|
|
45
|
+
maxlengthDirective,
|
|
46
|
+
minlengthDirective,
|
|
47
|
+
patternDirective,
|
|
48
|
+
requiredDirective,
|
|
49
|
+
} from "./directive/validators";
|
|
50
|
+
import { ngModelOptionsDirective } from "./directive/ngModelOptions";
|
|
51
|
+
import { ngAttributeAliasDirectives } from "./directive/attrs";
|
|
52
|
+
import { ngEventDirectives } from "./directive/events";
|
|
53
|
+
import { AnchorScrollProvider } from "./services/anchorScroll";
|
|
54
|
+
import {
|
|
55
|
+
AnimateProvider,
|
|
56
|
+
CoreAnimateJsProvider,
|
|
57
|
+
CoreAnimateQueueProvider,
|
|
58
|
+
} from "./core/animate";
|
|
59
|
+
import { BrowserProvider } from "./services/browser";
|
|
60
|
+
import { CoreAnimateCssProvider } from "./core/animateCss";
|
|
61
|
+
import { CookieReaderProvider } from "./services/cookieReader";
|
|
62
|
+
import {
|
|
63
|
+
AnimateAsyncRunFactoryProvider,
|
|
64
|
+
AnimateRunnerFactoryProvider,
|
|
65
|
+
} from "./core/animateRunner";
|
|
66
|
+
import {
|
|
67
|
+
CacheFactoryProvider,
|
|
68
|
+
TemplateCacheProvider,
|
|
69
|
+
} from "./services/cacheFactory";
|
|
70
|
+
import { $ControllerProvider } from "./core/controller";
|
|
71
|
+
import {
|
|
72
|
+
$DocumentProvider,
|
|
73
|
+
$$IsDocumentHiddenProvider,
|
|
74
|
+
} from "./services/document";
|
|
75
|
+
import { $ExceptionHandlerProvider } from "./core/exceptionHandler";
|
|
76
|
+
import { $FilterProvider } from "./core/filter";
|
|
77
|
+
import { $IntervalProvider } from "./core/interval";
|
|
78
|
+
import { $InterpolateProvider } from "./core/interpolate";
|
|
79
|
+
import { $$IntervalFactoryProvider } from "./core/intervalFactory";
|
|
80
|
+
import {
|
|
81
|
+
$HttpProvider,
|
|
82
|
+
$HttpParamSerializerProvider,
|
|
83
|
+
$HttpParamSerializerJQLikeProvider,
|
|
84
|
+
} from "./services/http";
|
|
85
|
+
import {
|
|
86
|
+
$HttpBackendProvider,
|
|
87
|
+
$xhrFactoryProvider,
|
|
88
|
+
} from "./services/httpBackend";
|
|
89
|
+
import { $LocationProvider } from "./core/location";
|
|
90
|
+
import { $LogProvider } from "./services/log";
|
|
91
|
+
import { $ParseProvider } from "./core/parser/parse";
|
|
92
|
+
import { $RootScopeProvider } from "./core/rootScope";
|
|
93
|
+
import { $QProvider, $$QProvider } from "./core/q";
|
|
94
|
+
import { $SceProvider, $SceDelegateProvider } from "./core/sce";
|
|
95
|
+
import { $$TaskTrackerFactoryProvider } from "./core/taskTrackerFactory";
|
|
96
|
+
import { TemplateRequestProvider } from "./services/templateRequest";
|
|
97
|
+
import { $TimeoutProvider } from "./core/timeout";
|
|
98
|
+
import { SanitizeUriProvider } from "./core/sanitizeUri";
|
|
99
|
+
import { setupModuleLoader } from "./loader";
|
|
100
|
+
import { initAnimateModule } from "./animations/module";
|
|
101
|
+
import { initMessageModule } from "./exts/messages";
|
|
102
|
+
import { initAriaModule } from "./exts/aria";
|
|
103
|
+
|
|
104
|
+
export function publishExternalAPI() {
|
|
105
|
+
const module = setupModuleLoader(window);
|
|
106
|
+
const ng = module(
|
|
107
|
+
"ng",
|
|
108
|
+
[],
|
|
109
|
+
[
|
|
110
|
+
"$provide",
|
|
111
|
+
function ngModule($provide) {
|
|
112
|
+
// $$sanitizeUriProvider needs to be before $compileProvider as it is used by it.
|
|
113
|
+
$provide.provider({
|
|
114
|
+
$$sanitizeUri: SanitizeUriProvider,
|
|
115
|
+
});
|
|
116
|
+
$provide
|
|
117
|
+
.provider("$compile", $CompileProvider)
|
|
118
|
+
.directive({
|
|
119
|
+
a: htmlAnchorDirective,
|
|
120
|
+
input: inputDirective,
|
|
121
|
+
textarea: inputDirective,
|
|
122
|
+
form: formDirective,
|
|
123
|
+
script: scriptDirective,
|
|
124
|
+
select: selectDirective,
|
|
125
|
+
option: optionDirective,
|
|
126
|
+
ngBind: ngBindDirective,
|
|
127
|
+
ngBindHtml: ngBindHtmlDirective,
|
|
128
|
+
ngBindTemplate: ngBindTemplateDirective,
|
|
129
|
+
ngClass: ngClassDirective,
|
|
130
|
+
ngClassEven: ngClassEvenDirective,
|
|
131
|
+
ngClassOdd: ngClassOddDirective,
|
|
132
|
+
ngCloak: ngCloakDirective,
|
|
133
|
+
ngController: ngControllerDirective,
|
|
134
|
+
ngForm: ngFormDirective,
|
|
135
|
+
ngHide: ngHideDirective,
|
|
136
|
+
ngIf: ngIfDirective,
|
|
137
|
+
ngInclude: ngIncludeDirective,
|
|
138
|
+
ngInit: ngInitDirective,
|
|
139
|
+
ngNonBindable: ngNonBindableDirective,
|
|
140
|
+
ngRef: ngRefDirective,
|
|
141
|
+
ngRepeat: ngRepeatDirective,
|
|
142
|
+
ngShow: ngShowDirective,
|
|
143
|
+
ngStyle: ngStyleDirective,
|
|
144
|
+
ngSwitch: ngSwitchDirective,
|
|
145
|
+
ngSwitchWhen: ngSwitchWhenDirective,
|
|
146
|
+
ngSwitchDefault: ngSwitchDefaultDirective,
|
|
147
|
+
ngOptions: ngOptionsDirective,
|
|
148
|
+
ngTransclude: ngTranscludeDirective,
|
|
149
|
+
ngModel: ngModelDirective,
|
|
150
|
+
ngList: ngListDirective,
|
|
151
|
+
ngChange: ngChangeDirective,
|
|
152
|
+
pattern: patternDirective,
|
|
153
|
+
ngPattern: patternDirective,
|
|
154
|
+
required: requiredDirective,
|
|
155
|
+
ngRequired: requiredDirective,
|
|
156
|
+
ngMinlength: minlengthDirective,
|
|
157
|
+
minlength: minlengthDirective,
|
|
158
|
+
ngMaxlength: maxlengthDirective,
|
|
159
|
+
maxlength: maxlengthDirective,
|
|
160
|
+
ngValue: ngValueDirective,
|
|
161
|
+
ngModelOptions: ngModelOptionsDirective,
|
|
162
|
+
})
|
|
163
|
+
.directive({
|
|
164
|
+
ngInclude: ngIncludeFillContentDirective,
|
|
165
|
+
input: hiddenInputBrowserCacheDirective,
|
|
166
|
+
})
|
|
167
|
+
.directive(ngAttributeAliasDirectives)
|
|
168
|
+
.directive(ngEventDirectives);
|
|
169
|
+
$provide.provider({
|
|
170
|
+
$anchorScroll: AnchorScrollProvider,
|
|
171
|
+
$animate: AnimateProvider,
|
|
172
|
+
$animateCss: CoreAnimateCssProvider,
|
|
173
|
+
$$animateJs: CoreAnimateJsProvider,
|
|
174
|
+
$$animateQueue: CoreAnimateQueueProvider,
|
|
175
|
+
$$AnimateRunner: AnimateRunnerFactoryProvider,
|
|
176
|
+
$$animateAsyncRun: AnimateAsyncRunFactoryProvider,
|
|
177
|
+
$browser: BrowserProvider,
|
|
178
|
+
$cacheFactory: CacheFactoryProvider,
|
|
179
|
+
$controller: $ControllerProvider,
|
|
180
|
+
$document: $DocumentProvider,
|
|
181
|
+
$$isDocumentHidden: $$IsDocumentHiddenProvider,
|
|
182
|
+
$exceptionHandler: $ExceptionHandlerProvider,
|
|
183
|
+
$filter: $FilterProvider,
|
|
184
|
+
$interpolate: $InterpolateProvider,
|
|
185
|
+
$interval: $IntervalProvider,
|
|
186
|
+
$$intervalFactory: $$IntervalFactoryProvider,
|
|
187
|
+
$http: $HttpProvider,
|
|
188
|
+
$httpParamSerializer: $HttpParamSerializerProvider,
|
|
189
|
+
$httpParamSerializerJQLike: $HttpParamSerializerJQLikeProvider,
|
|
190
|
+
$httpBackend: $HttpBackendProvider,
|
|
191
|
+
$xhrFactory: $xhrFactoryProvider,
|
|
192
|
+
$location: $LocationProvider,
|
|
193
|
+
$log: $LogProvider,
|
|
194
|
+
$parse: $ParseProvider,
|
|
195
|
+
$rootScope: $RootScopeProvider,
|
|
196
|
+
$q: $QProvider,
|
|
197
|
+
$$q: $$QProvider,
|
|
198
|
+
$sce: $SceProvider,
|
|
199
|
+
$sceDelegate: $SceDelegateProvider,
|
|
200
|
+
$$taskTrackerFactory: $$TaskTrackerFactoryProvider,
|
|
201
|
+
$templateCache: TemplateCacheProvider,
|
|
202
|
+
$templateRequest: TemplateRequestProvider,
|
|
203
|
+
$timeout: $TimeoutProvider,
|
|
204
|
+
$$cookieReader: CookieReaderProvider,
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
).info({ angularVersion: '"NG_VERSION_FULL"' });
|
|
209
|
+
|
|
210
|
+
initAnimateModule();
|
|
211
|
+
initMessageModule();
|
|
212
|
+
initAriaModule();
|
|
213
|
+
|
|
214
|
+
return ng;
|
|
215
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} path - The path to parse. (It is assumed to have query and hash stripped off.)
|
|
3
|
+
* @param {Object} opts - Options.
|
|
4
|
+
* @return {Object} - An object containing an array of path parameter names (`keys`) and a regular
|
|
5
|
+
* expression (`regexp`) that can be used to identify a matching URL and extract the path
|
|
6
|
+
* parameter values.
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Parses the given path, extracting path parameter names and a regular expression to match URLs.
|
|
10
|
+
*
|
|
11
|
+
* Originally inspired by `pathRexp` in `visionmedia/express/lib/utils.js`.
|
|
12
|
+
*/
|
|
13
|
+
export function routeToRegExp(path, opts) {
|
|
14
|
+
const keys = [];
|
|
15
|
+
|
|
16
|
+
let pattern = path
|
|
17
|
+
.replace(/([().])/g, "\\$1")
|
|
18
|
+
.replace(/(\/)?:(\w+)(\*\?|[?*])?/g, (_, slash, key, option) => {
|
|
19
|
+
const optional = option === "?" || option === "*?";
|
|
20
|
+
const star = option === "*" || option === "*?";
|
|
21
|
+
keys.push({ name: key, optional });
|
|
22
|
+
return (
|
|
23
|
+
(optional ? `(?:${slash || ""}` : `${slash || ""}(?:`) +
|
|
24
|
+
(star ? "(.+?)" : "([^/]+)") +
|
|
25
|
+
(optional ? "?)?" : ")")
|
|
26
|
+
);
|
|
27
|
+
})
|
|
28
|
+
.replace(/([/$*])/g, "\\$1");
|
|
29
|
+
|
|
30
|
+
if (opts.ignoreTrailingSlashes) {
|
|
31
|
+
pattern = `${pattern.replace(/\/+$/, "")}/*`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
keys,
|
|
36
|
+
regexp: new RegExp(
|
|
37
|
+
`^${pattern}(?:[?#]|$)`,
|
|
38
|
+
opts.caseInsensitiveMatch ? "i" : "",
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isElement,
|
|
3
|
+
isFunction,
|
|
4
|
+
isNumber,
|
|
5
|
+
isString,
|
|
6
|
+
nodeName_,
|
|
7
|
+
} from "../core/utils";
|
|
8
|
+
|
|
9
|
+
export function AnchorScrollProvider() {
|
|
10
|
+
let autoScrollingEnabled = true;
|
|
11
|
+
|
|
12
|
+
this.disableAutoScrolling = () => {
|
|
13
|
+
autoScrollingEnabled = false;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
this.$get = [
|
|
17
|
+
"$location",
|
|
18
|
+
"$rootScope",
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {angular.IRootScopeService} $location
|
|
22
|
+
* @param {*} $rootScope
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function ($location, $rootScope) {
|
|
26
|
+
const { document } = window;
|
|
27
|
+
|
|
28
|
+
// Helper function to get first anchor from a NodeList
|
|
29
|
+
// (using `Array#some()` instead of `angular#forEach()` since it's more performant
|
|
30
|
+
// and working in all supported browsers.)
|
|
31
|
+
function getFirstAnchor(list) {
|
|
32
|
+
let result = null;
|
|
33
|
+
Array.prototype.some.call(list, (element) => {
|
|
34
|
+
if (nodeName_(element) === "a") {
|
|
35
|
+
result = element;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getYOffset() {
|
|
43
|
+
let offset = scroll.yOffset;
|
|
44
|
+
|
|
45
|
+
if (isFunction(offset)) {
|
|
46
|
+
offset = offset();
|
|
47
|
+
} else if (isElement(offset)) {
|
|
48
|
+
const elem = offset[0];
|
|
49
|
+
const style = window.getComputedStyle(elem);
|
|
50
|
+
if (style.position !== "fixed") {
|
|
51
|
+
offset = 0;
|
|
52
|
+
} else {
|
|
53
|
+
offset = elem.getBoundingClientRect().bottom;
|
|
54
|
+
}
|
|
55
|
+
} else if (!isNumber(offset)) {
|
|
56
|
+
offset = 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return offset;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function scrollTo(elem) {
|
|
63
|
+
if (elem) {
|
|
64
|
+
elem.scrollIntoView();
|
|
65
|
+
|
|
66
|
+
const offset = getYOffset();
|
|
67
|
+
|
|
68
|
+
if (offset) {
|
|
69
|
+
// `offset` is the number of pixels we should scroll UP in order to align `elem` properly.
|
|
70
|
+
// This is true ONLY if the call to `elem.scrollIntoView()` initially aligns `elem` at the
|
|
71
|
+
// top of the viewport.
|
|
72
|
+
//
|
|
73
|
+
// IF the number of pixels from the top of `elem` to the end of the page's content is less
|
|
74
|
+
// than the height of the viewport, then `elem.scrollIntoView()` will align the `elem` some
|
|
75
|
+
// way down the page.
|
|
76
|
+
//
|
|
77
|
+
// This is often the case for elements near the bottom of the page.
|
|
78
|
+
//
|
|
79
|
+
// In such cases we do not need to scroll the whole `offset` up, just the difference between
|
|
80
|
+
// the top of the element and the offset, which is enough to align the top of `elem` at the
|
|
81
|
+
// desired position.
|
|
82
|
+
const elemTop = elem.getBoundingClientRect().top;
|
|
83
|
+
window.scrollBy(0, elemTop - offset);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
window.scrollTo(0, 0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function scroll(hash) {
|
|
91
|
+
// Allow numeric hashes
|
|
92
|
+
hash = isString(hash)
|
|
93
|
+
? hash
|
|
94
|
+
: isNumber(hash)
|
|
95
|
+
? hash.toString()
|
|
96
|
+
: $location.hash();
|
|
97
|
+
let elm;
|
|
98
|
+
|
|
99
|
+
// empty hash, scroll to the top of the page
|
|
100
|
+
if (!hash) scrollTo(null);
|
|
101
|
+
// element with given id
|
|
102
|
+
else if ((elm = document.getElementById(hash))) scrollTo(elm);
|
|
103
|
+
// first anchor with given name :-D
|
|
104
|
+
else if ((elm = getFirstAnchor(document.getElementsByName(hash))))
|
|
105
|
+
scrollTo(elm);
|
|
106
|
+
// no element and hash === 'top', scroll to the top of the page
|
|
107
|
+
else if (hash === "top") scrollTo(null);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// does not scroll when user clicks on anchor link that is currently on
|
|
111
|
+
// (no url change, no $location.hash() change), browser native does scroll
|
|
112
|
+
if (autoScrollingEnabled) {
|
|
113
|
+
$rootScope.$watch(
|
|
114
|
+
() => $location.hash(),
|
|
115
|
+
(newVal, oldVal) => {
|
|
116
|
+
// skip the initial scroll if $location.hash is empty
|
|
117
|
+
if (newVal === oldVal && newVal === "") return;
|
|
118
|
+
|
|
119
|
+
const action = () => $rootScope.$evalAsync(scroll);
|
|
120
|
+
if (window.document.readyState === "complete") {
|
|
121
|
+
// Force the action to be run async for consistent behavior
|
|
122
|
+
// from the action's point of view
|
|
123
|
+
// i.e. it will definitely not be in a $apply
|
|
124
|
+
window.setTimeout(() => action());
|
|
125
|
+
} else {
|
|
126
|
+
window.addEventListener("load", () => action());
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return scroll;
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
}
|