@excom/provider-geolocation 0.1.0

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.
Files changed (31) hide show
  1. package/.rush/temp/chunked-rush-logs/provider-geolocation.apply-exports.chunks.jsonl +1 -0
  2. package/.rush/temp/chunked-rush-logs/provider-geolocation.build_docs.chunks.jsonl +1 -0
  3. package/.rush/temp/chunked-rush-logs/provider-geolocation.build_package-metas.chunks.jsonl +1 -0
  4. package/.rush/temp/operation/apply-exports/all.log +1 -0
  5. package/.rush/temp/operation/apply-exports/log-chunks.jsonl +1 -0
  6. package/.rush/temp/operation/apply-exports/state.json +3 -0
  7. package/.rush/temp/operation/build_docs/all.log +1 -0
  8. package/.rush/temp/operation/build_docs/log-chunks.jsonl +1 -0
  9. package/.rush/temp/operation/build_docs/state.json +3 -0
  10. package/.rush/temp/operation/build_package-metas/all.log +1 -0
  11. package/.rush/temp/operation/build_package-metas/log-chunks.jsonl +1 -0
  12. package/.rush/temp/operation/build_package-metas/state.json +3 -0
  13. package/.rush/temp/shrinkwrap-deps.json +3 -0
  14. package/config/rig.json +5 -0
  15. package/index.ts +18 -0
  16. package/package.json +42 -0
  17. package/provider-geolocation.ts +222 -0
  18. package/rush-logs/provider-geolocation.apply-exports.cache.log +1 -0
  19. package/rush-logs/provider-geolocation.apply-exports.log +1 -0
  20. package/rush-logs/provider-geolocation.build_docs.cache.log +1 -0
  21. package/rush-logs/provider-geolocation.build_docs.log +1 -0
  22. package/rush-logs/provider-geolocation.build_package-metas.cache.log +1 -0
  23. package/rush-logs/provider-geolocation.build_package-metas.log +1 -0
  24. package/support/custom-elements.json +271 -0
  25. package/support/demos/request.html +12 -0
  26. package/support/dist-docs/provider-geolocation.md +108 -0
  27. package/support/docs/README.md +34 -0
  28. package/support/package-meta.json +148 -0
  29. package/support/tests/provider-geolocation.test.ts +563 -0
  30. package/support/tests/request.view.test.ts +38 -0
  31. package/tsconfig.json +5 -0
@@ -0,0 +1,108 @@
1
+ # provider-geolocation
2
+
3
+ Declarative Geolocation API — request a position, read the result from
4
+ attributes/state.
5
+
6
+
7
+ ```html
8
+ <div id="geo-request-demo">
9
+ <button type="button" command="--request" commandfor="geo-request">
10
+ Request my location
11
+ </button>
12
+ <provider-geolocation id="geo-request" is-paused></provider-geolocation>
13
+ <output>Click above — your browser will prompt for permission.</output>
14
+ <quark-sheet>
15
+ @use "/demo-utils" as *;
16
+
17
+ #geo-request-demo { @on neutron-provision (handle: setOutputFromElementData); }
18
+ </quark-sheet>
19
+ </div>
20
+ ```
21
+
22
+
23
+ ## Features
24
+
25
+ - **Attribute-driven** Request + read a position through attributes
26
+ - **User-gesture requests** `is-paused` + the `--request` command
27
+ so permission prompts follow a click
28
+ - **One-shot or watch** `watch-position` streams updates instead of a
29
+ single read
30
+
31
+ ## Installation
32
+
33
+
34
+ `@excom/provider-geolocation` v0.1.0
35
+
36
+ ```bash
37
+ pnpm add @excom/provider-geolocation
38
+ ```
39
+
40
+ ```bash
41
+ npm install @excom/provider-geolocation
42
+ ```
43
+
44
+ ```bash
45
+ yarn add @excom/provider-geolocation
46
+ ```
47
+
48
+ ### Import
49
+
50
+ ```ts
51
+ import "@excom/provider-geolocation";
52
+ ```
53
+
54
+
55
+
56
+ ## Usage
57
+
58
+ Requesting location on page load is poor UX (an unsolicited permission
59
+ prompt) — gate it behind a user gesture with `is-paused` and a trigger:
60
+
61
+ ```html
62
+ <button type="button" command="--request" commandfor="geo">
63
+ Share my location
64
+ </button>
65
+ <provider-geolocation id="geo" is-paused></provider-geolocation>
66
+ ```
67
+
68
+ ### API Reference
69
+
70
+
71
+ #### Attributes
72
+
73
+ | Name | Surface | Type | Default | Values | Description |
74
+ | --- | --- | --- | --- | --- | --- |
75
+ | `is-paused` | option | `boolean` | | | Skip making a request on connect. `provider-geolocation-request` still works while paused. |
76
+ | `high-accuracy` | option | `boolean` | | | Request the most accurate position available (more battery / time cost). |
77
+ | `geo-timeout` | option | `number` | `"Infinity"` | | Give up and fire `provider-geolocation-error` after this many ms. |
78
+ | `maximum-age` | option | `number` | | | Accept a cached position up to this many ms old instead of requesting a fresh one. Ignored when `watch-position` is set (always `0`, i.e. no caching). |
79
+ | `watch-position` | option | `boolean` | | | Keep requesting — `provider-geolocation-success` fires on every position update instead of once. Uses `navigator.geolocation.watchPosition` under the hood. |
80
+ | `is-requesting` | state | `boolean` | | | A position request is currently pending. |
81
+ | `is-success` | state | `boolean` | | | The most recent request resolved successfully. With `watch-position`, stays set across updates. |
82
+ | `is-error` | state | `boolean` | | | The most recent request failed. Fires with the `error` event. |
83
+
84
+ #### Provision
85
+
86
+ | Name | Type | Description |
87
+ | --- | --- | --- |
88
+ | `provision` | `GeoSuccess` (`{ coords: { longitude: number; latitude: number; altitude?: number; accuracy?: number; altitudeAccuracy?: number; heading?: number; speed?: number; timestamp?: number; }; }`) | Latest result: the coords object on success, or the `GeolocationPositionError` (or thrown error) on failure. Not reflected as an attribute. |
89
+
90
+ #### Fires
91
+
92
+ | Name | Type | Description |
93
+ | --- | --- | --- |
94
+ | `provider-geolocation-success` | `ProviderGeolocationSuccessEvent` (`CustomEvent & { type: "provider-geolocation-success"; detail: { coords: { longitude: number; latitude: number; altitude?: number; accuracy?: number; altitudeAccuracy?: number; heading?: number; speed?: number; timestamp?: number; }; }; bubbles: true; cancelable: true; composed: true }`) | Dispatched on every successful position read (including each update while `watch-position` is set). |
95
+ | `provider-geolocation-error` | `ProviderGeolocationErrorEvent` (`CustomEvent & { type: "provider-geolocation-error"; detail: GeolocationPositionError; bubbles: true; cancelable: true; composed: true }`) | Dispatched when the request fails (permission denied, timeout, position unavailable, or a thrown error). |
96
+
97
+ #### Commands
98
+
99
+ | Command | Action |
100
+ | --- | --- |
101
+ | `--request` | (Re)requests the position on demand — the standard way to request from a button (`<button command="--request" commandfor="…">`) while `is-paused` is set, or to force a fresh read at any time. |
102
+
103
+ #### Default actions
104
+
105
+ | Event | Default behavior (unless preventDefault() is called) |
106
+ | --- | --- |
107
+ | `provider-geolocation-success` | Stores the result in `provision` and sets `is-success` (clearing `is-requesting` / `is-error`). |
108
+ | `provider-geolocation-error` | Stores the error in `provision` and sets `is-error` (clearing `is-requesting` / `is-success`). |
@@ -0,0 +1,34 @@
1
+ # provider-geolocation
2
+
3
+ Declarative Geolocation API — request a position, read the result from
4
+ attributes/state.
5
+
6
+ <include-content data-demo="request"></include-content>
7
+
8
+ ## Features
9
+
10
+ - **Attribute-driven** Request + read a position through attributes
11
+ - **User-gesture requests** `is-paused` + the `--request` command
12
+ so permission prompts follow a click
13
+ - **One-shot or watch** `watch-position` streams updates instead of a
14
+ single read
15
+
16
+ ## Installation
17
+
18
+ <include-content is-active template-ref="/views/install-section/install-section.html"></include-content>
19
+
20
+ ## Usage
21
+
22
+ Requesting location on page load is poor UX (an unsolicited permission
23
+ prompt) — gate it behind a user gesture with `is-paused` and a trigger:
24
+
25
+ ```html
26
+ <button type="button" command="--request" commandfor="geo">
27
+ Share my location
28
+ </button>
29
+ <provider-geolocation id="geo" is-paused></provider-geolocation>
30
+ ```
31
+
32
+ ### API Reference
33
+
34
+ <include-content is-active template-ref="/views/api-reference/api-reference.html"></include-content>
@@ -0,0 +1,148 @@
1
+ {
2
+ "shortName": "provider-geolocation",
3
+ "package": {
4
+ "name": "@excom/provider-geolocation",
5
+ "version": "0.1.0",
6
+ "description": "<provider-geolocation> custom element",
7
+ "peerDependencies": {},
8
+ "excom": {
9
+ "packageType": "kit-element"
10
+ }
11
+ },
12
+ "demos": {
13
+ "request": "<div id=\"geo-request-demo\">\n <button type=\"button\" command=\"--request\" commandfor=\"geo-request\">\n Request my location\n </button>\n <provider-geolocation id=\"geo-request\" is-paused></provider-geolocation>\n <output>Click above — your browser will prompt for permission.</output>\n <quark-sheet>\n @use \"/demo-utils\" as *;\n\n #geo-request-demo { @on neutron-provision (handle: setOutputFromElementData); }\n </quark-sheet>\n</div>\n"
14
+ },
15
+ "readme": "<h1 id=\"md-provider-geolocation\">provider-geolocation</h1>\n<p>Declarative Geolocation API — request a position, read the result from\nattributes/state.</p>\n<p><include-content data-demo=\"request\"></include-content></p>\n<h2 id=\"md-features\">Features</h2>\n<ul>\n<li><strong>Attribute-driven</strong> Request + read a position through attributes</li>\n<li><strong>User-gesture requests</strong> <code>is-paused</code> + the <code>--request</code> command\nso permission prompts follow a click</li>\n<li><strong>One-shot or watch</strong> <code>watch-position</code> streams updates instead of a\nsingle read</li>\n</ul>\n<h2 id=\"md-installation\">Installation</h2>\n<p><include-content is-active template-ref=\"/views/install-section/install-section.html\"></include-content></p>\n<h2 id=\"md-usage\">Usage</h2>\n<p>Requesting location on page load is poor UX (an unsolicited permission\nprompt) — gate it behind a user gesture with <code>is-paused</code> and a trigger:</p>\n<include-content data-language=\"html\"><template>&lt;button type=\"button\" command=\"--request\" commandfor=\"geo\"&gt;\n Share my location\n&lt;/button&gt;\n&lt;provider-geolocation id=\"geo\" is-paused&gt;&lt;/provider-geolocation&gt;</template></include-content>\n<h3 id=\"md-api-reference\">API Reference</h3>\n<p><include-content is-active template-ref=\"/views/api-reference/api-reference.html\"></include-content></p>\n",
16
+ "docs": {
17
+ "readme": "<h1 id=\"md-provider-geolocation\">provider-geolocation</h1>\n<p>Declarative Geolocation API — request a position, read the result from\nattributes/state.</p>\n<p><include-content data-demo=\"request\"></include-content></p>\n<h2 id=\"md-features\">Features</h2>\n<ul>\n<li><strong>Attribute-driven</strong> Request + read a position through attributes</li>\n<li><strong>User-gesture requests</strong> <code>is-paused</code> + the <code>--request</code> command\nso permission prompts follow a click</li>\n<li><strong>One-shot or watch</strong> <code>watch-position</code> streams updates instead of a\nsingle read</li>\n</ul>\n<h2 id=\"md-installation\">Installation</h2>\n<p><include-content is-active template-ref=\"/views/install-section/install-section.html\"></include-content></p>\n<h2 id=\"md-usage\">Usage</h2>\n<p>Requesting location on page load is poor UX (an unsolicited permission\nprompt) — gate it behind a user gesture with <code>is-paused</code> and a trigger:</p>\n<include-content data-language=\"html\"><template>&lt;button type=\"button\" command=\"--request\" commandfor=\"geo\"&gt;\n Share my location\n&lt;/button&gt;\n&lt;provider-geolocation id=\"geo\" is-paused&gt;&lt;/provider-geolocation&gt;</template></include-content>\n<h3 id=\"md-api-reference\">API Reference</h3>\n<p><include-content is-active template-ref=\"/views/api-reference/api-reference.html\"></include-content></p>\n"
18
+ },
19
+ "installation": {
20
+ "name": "@excom/provider-geolocation",
21
+ "shortName": "provider-geolocation",
22
+ "version": "0.1.0",
23
+ "description": "<provider-geolocation> custom element",
24
+ "packageType": "kit-element",
25
+ "cdn": "<script src=\"https://unpkg.com/@excom/kit-utils/dist/index.umd.min.js\"></script>\n<script src=\"https://unpkg.com/@excom/neutron/dist/index.umd.min.js\"></script>\n<script src=\"https://unpkg.com/@excom/provider-geolocation@0.1.0/dist/index.umd.min.js\"></script>",
26
+ "install": {
27
+ "npm": "npm install @excom/provider-geolocation"
28
+ },
29
+ "imports": {
30
+ "js": "import \"@excom/provider-geolocation\";",
31
+ "html": "<!-- import path to `node_modules` will depend on your build setup -->\n<script type=\"module\" src=\"/node_modules/@excom/provider-geolocation\"></script>\n<link rel=\"stylesheet\" href=\"/node_modules/@excom/provider-geolocation\">"
32
+ },
33
+ "peerDependencies": []
34
+ },
35
+ "elementApis": [
36
+ {
37
+ "tag": "provider-geolocation",
38
+ "kind": "class",
39
+ "attributes": [
40
+ {
41
+ "name": "geo-timeout",
42
+ "type": "number",
43
+ "description": "Give up and fire <code>provider-geolocation-error</code> after this many ms.",
44
+ "fieldName": "geoTimeout",
45
+ "surface": "option",
46
+ "default": "\"Infinity\""
47
+ },
48
+ {
49
+ "name": "high-accuracy",
50
+ "type": "boolean",
51
+ "description": "Request the most accurate position available (more battery / time cost).",
52
+ "fieldName": "highAccuracy",
53
+ "surface": "option"
54
+ },
55
+ {
56
+ "name": "is-paused",
57
+ "type": "boolean",
58
+ "description": "Skip making a request on connect. <code>provider-geolocation-request</code> still works while paused.",
59
+ "fieldName": "isPaused",
60
+ "surface": "option"
61
+ },
62
+ {
63
+ "name": "maximum-age",
64
+ "type": "number",
65
+ "description": "Accept a cached position up to this many ms old instead of requesting a fresh one. Ignored when <code>watch-position</code> is set (always <code>0</code>, i.e. no caching).",
66
+ "fieldName": "maximumAge",
67
+ "surface": "option"
68
+ },
69
+ {
70
+ "name": "watch-position",
71
+ "type": "boolean",
72
+ "description": "Keep requesting — <code>provider-geolocation-success</code> fires on every position update instead of once. Uses <code>navigator.geolocation.watchPosition</code> under the hood.",
73
+ "fieldName": "watchPosition",
74
+ "surface": "option"
75
+ },
76
+ {
77
+ "name": "is-error",
78
+ "type": "boolean",
79
+ "description": "The most recent request failed. Fires with the <code>error</code> event.",
80
+ "fieldName": "isError",
81
+ "surface": "state"
82
+ },
83
+ {
84
+ "name": "is-requesting",
85
+ "type": "boolean",
86
+ "description": "A position request is currently pending.",
87
+ "fieldName": "isRequesting",
88
+ "surface": "state"
89
+ },
90
+ {
91
+ "name": "is-success",
92
+ "type": "boolean",
93
+ "description": "The most recent request resolved successfully. With <code>watch-position</code>, stays set across updates.",
94
+ "fieldName": "isSuccess",
95
+ "surface": "state"
96
+ }
97
+ ],
98
+ "events": [
99
+ {
100
+ "name": "provider-geolocation-error",
101
+ "description": "Dispatched when the request fails (permission denied, timeout, position unavailable, or a thrown error).",
102
+ "type": "ProviderGeolocationErrorEvent",
103
+ "typeExpanded": "CustomEvent & { type: \"provider-geolocation-error\"; detail: GeolocationPositionError; bubbles: true; cancelable: true; composed: true }",
104
+ "defaultAction": "Stores the error in <code>provision</code> and sets <code>is-error</code> (clearing <code>is-requesting</code> / <code>is-success</code>)."
105
+ },
106
+ {
107
+ "name": "provider-geolocation-success",
108
+ "description": "Dispatched on every successful position read (including each update while <code>watch-position</code> is set).",
109
+ "type": "ProviderGeolocationSuccessEvent",
110
+ "typeExpanded": "CustomEvent & { type: \"provider-geolocation-success\"; detail: { coords: { longitude: number; latitude: number; altitude?: number; accuracy?: number; altitudeAccuracy?: number; heading?: number; speed?: number; timestamp?: number; }; }; bubbles: true; cancelable: true; composed: true }",
111
+ "defaultAction": "Stores the result in <code>provision</code> and sets <code>is-success</code> (clearing <code>is-requesting</code> / <code>is-error</code>)."
112
+ }
113
+ ],
114
+ "slots": [],
115
+ "cssProperties": [],
116
+ "cssClasses": [],
117
+ "cssAliases": [],
118
+ "listens": [],
119
+ "commands": [
120
+ {
121
+ "name": "--request",
122
+ "description": "(Re)requests the position on demand — the standard way to request from a button (<code>&lt;button command=&quot;--request&quot; commandfor=&quot;…&quot;&gt;</code>) while <code>is-paused</code> is set, or to force a fresh read at any time."
123
+ }
124
+ ],
125
+ "defaultActions": [
126
+ {
127
+ "name": "provider-geolocation-error",
128
+ "description": "Stores the error in <code>provision</code> and sets <code>is-error</code> (clearing <code>is-requesting</code> / <code>is-success</code>)."
129
+ },
130
+ {
131
+ "name": "provider-geolocation-success",
132
+ "description": "Stores the result in <code>provision</code> and sets <code>is-success</code> (clearing <code>is-requesting</code> / <code>is-error</code>)."
133
+ }
134
+ ],
135
+ "expectedChildren": [],
136
+ "provisions": [
137
+ {
138
+ "name": "provision",
139
+ "type": "GeoSuccess",
140
+ "typeExpanded": "{ coords: { longitude: number; latitude: number; altitude?: number; accuracy?: number; altitudeAccuracy?: number; heading?: number; speed?: number; timestamp?: number; }; }",
141
+ "description": "Latest result: the coords object on success, or the <code>GeolocationPositionError</code> (or thrown error) on failure. Not reflected as an attribute.",
142
+ "fieldName": "provision"
143
+ }
144
+ ]
145
+ }
146
+ ],
147
+ "exportedFiles": {}
148
+ }