@excom/provider-orientation 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-orientation.apply-exports.chunks.jsonl +1 -0
  2. package/.rush/temp/chunked-rush-logs/provider-orientation.build_docs.chunks.jsonl +1 -0
  3. package/.rush/temp/chunked-rush-logs/provider-orientation.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-orientation.ts +225 -0
  18. package/rush-logs/provider-orientation.apply-exports.cache.log +1 -0
  19. package/rush-logs/provider-orientation.apply-exports.log +1 -0
  20. package/rush-logs/provider-orientation.build_docs.cache.log +1 -0
  21. package/rush-logs/provider-orientation.build_docs.log +1 -0
  22. package/rush-logs/provider-orientation.build_package-metas.cache.log +1 -0
  23. package/rush-logs/provider-orientation.build_package-metas.log +1 -0
  24. package/support/custom-elements.json +208 -0
  25. package/support/demos/request.html +14 -0
  26. package/support/dist-docs/provider-orientation.md +126 -0
  27. package/support/docs/README.md +52 -0
  28. package/support/package-meta.json +127 -0
  29. package/support/tests/provider-orientation.test.ts +624 -0
  30. package/support/tests/request.view.test.ts +39 -0
  31. package/tsconfig.json +5 -0
@@ -0,0 +1,126 @@
1
+ # provider-orientation
2
+
3
+ Declarative device orientation / compass — request a heading, read the
4
+ normalized bearing from attributes/state.
5
+
6
+ ## Features
7
+
8
+ - **Attribute-driven** Request + read a compass heading through attributes
9
+ - **Normalized bearing** `0`–`360°` from magnetic north on both iOS and
10
+ Android, one shape either way
11
+ - **Throttled updates** `compass-throttle-ms` caps update frequency
12
+ (Android can fire 60-200 Hz)
13
+ - **iOS-aware** Works with the required user-gesture permission flow
14
+
15
+ ## Installation
16
+
17
+
18
+ `@excom/provider-orientation` v0.1.0
19
+
20
+ ```bash
21
+ pnpm add @excom/provider-orientation
22
+ ```
23
+
24
+ ```bash
25
+ npm install @excom/provider-orientation
26
+ ```
27
+
28
+ ```bash
29
+ yarn add @excom/provider-orientation
30
+ ```
31
+
32
+ ### Import
33
+
34
+ ```ts
35
+ import "@excom/provider-orientation";
36
+ ```
37
+
38
+
39
+
40
+ ## Usage
41
+
42
+ **Requires a user gesture on iOS.** `DeviceOrientationEvent
43
+ .requestPermission()` must run synchronously inside a click handler or
44
+ Safari denies it — so set `is-paused` and invoke the `--request` command
45
+ from a button rather than relying on the connect-time auto-request (the
46
+ handler runs in a microtask of the click, inside its user activation):
47
+
48
+ ```html
49
+ <button type="button" command="--request" commandfor="compass">
50
+ Enable compass
51
+ </button>
52
+ <provider-orientation id="compass" is-paused></provider-orientation>
53
+ ```
54
+
55
+ ```css
56
+ compass-needle {
57
+ transform: rotate(calc(var(--bearing, 0) * 1deg));
58
+ }
59
+ ```
60
+
61
+ Android and desktop browsers with a sensor don't require permission and
62
+ will start listening as soon as the request fires; browsers with no
63
+ sensor at all simply never report a reading.
64
+
65
+ ### API Reference
66
+
67
+
68
+ #### Attributes
69
+
70
+ | Name | Surface | Type | Default | Values | Description |
71
+ | --- | --- | --- | --- | --- | --- |
72
+ | `is-paused` | option | `boolean` | | | Skip requesting on connect. On iOS this is effectively required (a connect-time request happens outside a user gesture and will be denied) — pair with `provider-orientation-request` from a click handler instead (see class docs). |
73
+ | `compass-throttle-ms` | option | `number` | `100` | | Minimum ms between `provider-orientation-success` updates. Android can fire `deviceorientationabsolute` at 60-200 Hz; without throttling that floods listeners and CSS/Quark bindings. |
74
+ | `is-requesting` | state | `boolean` | | | iOS only: the permission request is pending (between `provider-orientation-request` and the user's response). |
75
+ | `is-success` | state | `boolean` | | | Listening for orientation updates (permission granted where required). Stays set across updates. |
76
+ | `is-error` | state | `boolean` | | | The permission request was denied, or listening failed to start. |
77
+
78
+ #### Provision
79
+
80
+ | Name | Type | Description |
81
+ | --- | --- | --- |
82
+ | `provision` | `ProviderOrientationSuccess` (`{ bearing: number; alpha: number \| null; }`) | Latest reading: `{ bearing, alpha }` on success, or the error on failure. Not reflected as an attribute. |
83
+
84
+ #### Fires
85
+
86
+ | Name | Type | Description |
87
+ | --- | --- | --- |
88
+ | `provider-orientation-success` | `ProviderOrientationSuccessEvent` (`CustomEvent & { type: "provider-orientation-success"; detail: { bearing: number; alpha: number \| null; }; bubbles: true; cancelable: true; composed: true }`) | Dispatched on every compass update (throttled by `compass-throttle-ms`). `bearing` is normalized 0-360°; `alpha` is the raw `DeviceOrientationEvent.alpha` where available. |
89
+ | `provider-orientation-error` | `ProviderOrientationErrorEvent` (`CustomEvent & { type: "provider-orientation-error"; detail: string \| Error; bubbles: true; cancelable: true; composed: true }`) | Dispatched when the permission request is denied, or fails for any other reason. |
90
+
91
+ #### Commands
92
+
93
+ | Command | Action |
94
+ | --- | --- |
95
+ | `--request` | Requests permission (iOS) and starts listening for orientation updates. Invoke it from a button (`<button command="--request" commandfor="…">`) so the user activation is there. |
96
+
97
+ #### Default actions
98
+
99
+ | Event | Default behavior (unless preventDefault() is called) |
100
+ | --- | --- |
101
+ | `provider-orientation-success` | Stores `{ bearing, alpha }` in `provision` and sets `is-success` (clearing `is-requesting` / `is-error`). |
102
+ | `provider-orientation-error` | Stores the error in `provision` and sets `is-error` (clearing `is-requesting` / `is-success`). |
103
+
104
+
105
+
106
+ ### Examples
107
+
108
+ #### Request on click
109
+
110
+
111
+ ```html
112
+ <div id="orient-demo">
113
+ <button type="button" command="--request" commandfor="orient">
114
+ Enable compass
115
+ </button>
116
+ <provider-orientation id="orient" is-paused></provider-orientation>
117
+ <p class="status">No reading yet — click above. Requires a device
118
+ sensor (desktop browsers usually have none).</p>
119
+ <output>Waiting…</output>
120
+ <quark-sheet>
121
+ @use "/demo-utils" as *;
122
+
123
+ #orient-demo { @on neutron-provision (handle: setOutputFromElementData); }
124
+ </quark-sheet>
125
+ </div>
126
+ ```
@@ -0,0 +1,52 @@
1
+ # provider-orientation
2
+
3
+ Declarative device orientation / compass — request a heading, read the
4
+ normalized bearing from attributes/state.
5
+
6
+ ## Features
7
+
8
+ - **Attribute-driven** Request + read a compass heading through attributes
9
+ - **Normalized bearing** `0`–`360°` from magnetic north on both iOS and
10
+ Android, one shape either way
11
+ - **Throttled updates** `compass-throttle-ms` caps update frequency
12
+ (Android can fire 60-200 Hz)
13
+ - **iOS-aware** Works with the required user-gesture permission flow
14
+
15
+ ## Installation
16
+
17
+ <include-content is-active template-ref="/views/install-section/install-section.html"></include-content>
18
+
19
+ ## Usage
20
+
21
+ **Requires a user gesture on iOS.** `DeviceOrientationEvent
22
+ .requestPermission()` must run synchronously inside a click handler or
23
+ Safari denies it — so set `is-paused` and invoke the `--request` command
24
+ from a button rather than relying on the connect-time auto-request (the
25
+ handler runs in a microtask of the click, inside its user activation):
26
+
27
+ ```html
28
+ <button type="button" command="--request" commandfor="compass">
29
+ Enable compass
30
+ </button>
31
+ <provider-orientation id="compass" is-paused></provider-orientation>
32
+ ```
33
+
34
+ ```css
35
+ compass-needle {
36
+ transform: rotate(calc(var(--bearing, 0) * 1deg));
37
+ }
38
+ ```
39
+
40
+ Android and desktop browsers with a sensor don't require permission and
41
+ will start listening as soon as the request fires; browsers with no
42
+ sensor at all simply never report a reading.
43
+
44
+ ### API Reference
45
+
46
+ <include-content is-active template-ref="/views/api-reference/api-reference.html"></include-content>
47
+
48
+ ### Examples
49
+
50
+ #### Request on click
51
+
52
+ <include-content data-demo="request"></include-content>
@@ -0,0 +1,127 @@
1
+ {
2
+ "shortName": "provider-orientation",
3
+ "package": {
4
+ "name": "@excom/provider-orientation",
5
+ "version": "0.1.0",
6
+ "description": "<provider-orientation> custom element",
7
+ "peerDependencies": {},
8
+ "excom": {
9
+ "packageType": "kit-element"
10
+ }
11
+ },
12
+ "demos": {
13
+ "request": "<div id=\"orient-demo\">\n <button type=\"button\" command=\"--request\" commandfor=\"orient\">\n Enable compass\n </button>\n <provider-orientation id=\"orient\" is-paused></provider-orientation>\n <p class=\"status\">No reading yet — click above. Requires a device\n sensor (desktop browsers usually have none).</p>\n <output>Waiting…</output>\n <quark-sheet>\n @use \"/demo-utils\" as *;\n\n #orient-demo { @on neutron-provision (handle: setOutputFromElementData); }\n </quark-sheet>\n</div>\n"
14
+ },
15
+ "readme": "<h1 id=\"md-provider-orientation\">provider-orientation</h1>\n<p>Declarative device orientation / compass — request a heading, read the\nnormalized bearing from attributes/state.</p>\n<h2 id=\"md-features\">Features</h2>\n<ul>\n<li><strong>Attribute-driven</strong> Request + read a compass heading through attributes</li>\n<li><strong>Normalized bearing</strong> <code>0</code>–<code>360°</code> from magnetic north on both iOS and\nAndroid, one shape either way</li>\n<li><strong>Throttled updates</strong> <code>compass-throttle-ms</code> caps update frequency\n(Android can fire 60-200 Hz)</li>\n<li><strong>iOS-aware</strong> Works with the required user-gesture permission flow</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><strong>Requires a user gesture on iOS.</strong> <code>DeviceOrientationEvent .requestPermission()</code> must run synchronously inside a click handler or\nSafari denies it — so set <code>is-paused</code> and invoke the <code>--request</code> command\nfrom a button rather than relying on the connect-time auto-request (the\nhandler runs in a microtask of the click, inside its user activation):</p>\n<include-content data-language=\"html\"><template>&lt;button type=\"button\" command=\"--request\" commandfor=\"compass\"&gt;\n Enable compass\n&lt;/button&gt;\n&lt;provider-orientation id=\"compass\" is-paused&gt;&lt;/provider-orientation&gt;</template></include-content>\n<include-content data-language=\"css\"><template>compass-needle {\n transform: rotate(calc(var(--bearing, 0) * 1deg));\n}</template></include-content>\n<p>Android and desktop browsers with a sensor don&#39;t require permission and\nwill start listening as soon as the request fires; browsers with no\nsensor at all simply never report a reading.</p>\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<h3 id=\"md-examples\">Examples</h3>\n<h4 id=\"md-request-on-click\">Request on click</h4>\n<p><include-content data-demo=\"request\"></include-content></p>\n",
16
+ "docs": {
17
+ "readme": "<h1 id=\"md-provider-orientation\">provider-orientation</h1>\n<p>Declarative device orientation / compass — request a heading, read the\nnormalized bearing from attributes/state.</p>\n<h2 id=\"md-features\">Features</h2>\n<ul>\n<li><strong>Attribute-driven</strong> Request + read a compass heading through attributes</li>\n<li><strong>Normalized bearing</strong> <code>0</code>–<code>360°</code> from magnetic north on both iOS and\nAndroid, one shape either way</li>\n<li><strong>Throttled updates</strong> <code>compass-throttle-ms</code> caps update frequency\n(Android can fire 60-200 Hz)</li>\n<li><strong>iOS-aware</strong> Works with the required user-gesture permission flow</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><strong>Requires a user gesture on iOS.</strong> <code>DeviceOrientationEvent .requestPermission()</code> must run synchronously inside a click handler or\nSafari denies it — so set <code>is-paused</code> and invoke the <code>--request</code> command\nfrom a button rather than relying on the connect-time auto-request (the\nhandler runs in a microtask of the click, inside its user activation):</p>\n<include-content data-language=\"html\"><template>&lt;button type=\"button\" command=\"--request\" commandfor=\"compass\"&gt;\n Enable compass\n&lt;/button&gt;\n&lt;provider-orientation id=\"compass\" is-paused&gt;&lt;/provider-orientation&gt;</template></include-content>\n<include-content data-language=\"css\"><template>compass-needle {\n transform: rotate(calc(var(--bearing, 0) * 1deg));\n}</template></include-content>\n<p>Android and desktop browsers with a sensor don&#39;t require permission and\nwill start listening as soon as the request fires; browsers with no\nsensor at all simply never report a reading.</p>\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<h3 id=\"md-examples\">Examples</h3>\n<h4 id=\"md-request-on-click\">Request on click</h4>\n<p><include-content data-demo=\"request\"></include-content></p>\n"
18
+ },
19
+ "installation": {
20
+ "name": "@excom/provider-orientation",
21
+ "shortName": "provider-orientation",
22
+ "version": "0.1.0",
23
+ "description": "<provider-orientation> 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-orientation@0.1.0/dist/index.umd.min.js\"></script>",
26
+ "install": {
27
+ "npm": "npm install @excom/provider-orientation"
28
+ },
29
+ "imports": {
30
+ "js": "import \"@excom/provider-orientation\";",
31
+ "html": "<!-- import path to `node_modules` will depend on your build setup -->\n<script type=\"module\" src=\"/node_modules/@excom/provider-orientation\"></script>\n<link rel=\"stylesheet\" href=\"/node_modules/@excom/provider-orientation\">"
32
+ },
33
+ "peerDependencies": []
34
+ },
35
+ "elementApis": [
36
+ {
37
+ "tag": "provider-orientation",
38
+ "kind": "class",
39
+ "attributes": [
40
+ {
41
+ "name": "compass-throttle-ms",
42
+ "type": "number",
43
+ "description": "Minimum ms between <code>provider-orientation-success</code> updates. Android can fire <code>deviceorientationabsolute</code> at 60-200 Hz; without throttling that floods listeners and CSS/Quark bindings.",
44
+ "fieldName": "compassThrottleMs",
45
+ "surface": "option",
46
+ "default": "100"
47
+ },
48
+ {
49
+ "name": "is-paused",
50
+ "type": "boolean",
51
+ "description": "Skip requesting on connect. On iOS this is effectively required (a connect-time request happens outside a user gesture and will be denied) — pair with <code>provider-orientation-request</code> from a click handler instead (see class docs).",
52
+ "fieldName": "isPaused",
53
+ "surface": "option"
54
+ },
55
+ {
56
+ "name": "is-error",
57
+ "type": "boolean",
58
+ "description": "The permission request was denied, or listening failed to start.",
59
+ "fieldName": "isError",
60
+ "surface": "state"
61
+ },
62
+ {
63
+ "name": "is-requesting",
64
+ "type": "boolean",
65
+ "description": "iOS only: the permission request is pending (between <code>provider-orientation-request</code> and the user&#39;s response).",
66
+ "fieldName": "isRequesting",
67
+ "surface": "state"
68
+ },
69
+ {
70
+ "name": "is-success",
71
+ "type": "boolean",
72
+ "description": "Listening for orientation updates (permission granted where required). Stays set across updates.",
73
+ "fieldName": "isSuccess",
74
+ "surface": "state"
75
+ }
76
+ ],
77
+ "events": [
78
+ {
79
+ "name": "provider-orientation-error",
80
+ "description": "Dispatched when the permission request is denied, or fails for any other reason.",
81
+ "type": "ProviderOrientationErrorEvent",
82
+ "typeExpanded": "CustomEvent & { type: \"provider-orientation-error\"; detail: string | Error; bubbles: true; cancelable: true; composed: true }",
83
+ "defaultAction": "Stores the error in <code>provision</code> and sets <code>is-error</code> (clearing <code>is-requesting</code> / <code>is-success</code>)."
84
+ },
85
+ {
86
+ "name": "provider-orientation-success",
87
+ "description": "Dispatched on every compass update (throttled by <code>compass-throttle-ms</code>). <code>bearing</code> is normalized 0-360°; <code>alpha</code> is the raw <code>DeviceOrientationEvent.alpha</code> where available.",
88
+ "type": "ProviderOrientationSuccessEvent",
89
+ "typeExpanded": "CustomEvent & { type: \"provider-orientation-success\"; detail: { bearing: number; alpha: number | null; }; bubbles: true; cancelable: true; composed: true }",
90
+ "defaultAction": "Stores <code>{ bearing, alpha }</code> in <code>provision</code> and sets <code>is-success</code> (clearing <code>is-requesting</code> / <code>is-error</code>)."
91
+ }
92
+ ],
93
+ "slots": [],
94
+ "cssProperties": [],
95
+ "cssClasses": [],
96
+ "cssAliases": [],
97
+ "listens": [],
98
+ "commands": [
99
+ {
100
+ "name": "--request",
101
+ "description": "Requests permission (iOS) and starts listening for orientation updates. Invoke it from a button (<code>&lt;button command=&quot;--request&quot; commandfor=&quot;…&quot;&gt;</code>) so the user activation is there."
102
+ }
103
+ ],
104
+ "defaultActions": [
105
+ {
106
+ "name": "provider-orientation-error",
107
+ "description": "Stores the error in <code>provision</code> and sets <code>is-error</code> (clearing <code>is-requesting</code> / <code>is-success</code>)."
108
+ },
109
+ {
110
+ "name": "provider-orientation-success",
111
+ "description": "Stores <code>{ bearing, alpha }</code> in <code>provision</code> and sets <code>is-success</code> (clearing <code>is-requesting</code> / <code>is-error</code>)."
112
+ }
113
+ ],
114
+ "expectedChildren": [],
115
+ "provisions": [
116
+ {
117
+ "name": "provision",
118
+ "type": "ProviderOrientationSuccess",
119
+ "typeExpanded": "{ bearing: number; alpha: number | null; }",
120
+ "description": "Latest reading: <code>{ bearing, alpha }</code> on success, or the error on failure. Not reflected as an attribute.",
121
+ "fieldName": "provision"
122
+ }
123
+ ]
124
+ }
125
+ ],
126
+ "exportedFiles": {}
127
+ }