human-machine-swapper 1.0.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.
- package/AGENTS.md +80 -0
- package/LICENSE +202 -0
- package/README.md +278 -0
- package/llms.txt +81 -0
- package/package.json +56 -0
- package/src/human-machine-swapper.js +524 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# human-machine-swapper
|
|
2
|
+
|
|
3
|
+
Instructions for coding agents adding this component to a site.
|
|
4
|
+
|
|
5
|
+
## What it is
|
|
6
|
+
|
|
7
|
+
A dependency-free web component that adds a Human / Machine pill. Machine shows the site's
|
|
8
|
+
`llms.txt` rendered in place. One script tag, one custom element, no build step.
|
|
9
|
+
|
|
10
|
+
## Install it in three steps, all three required
|
|
11
|
+
|
|
12
|
+
1. **Load the script.**
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<script src="https://unpkg.com/human-machine-swapper" defer></script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or `npm install human-machine-swapper` and `import "human-machine-swapper"`.
|
|
19
|
+
|
|
20
|
+
2. **Mount the element**, anywhere in `<body>`. It is `position: fixed`, so placement in the
|
|
21
|
+
DOM does not affect where it appears.
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<human-machine-swapper data-position="bottom-center"></human-machine-swapper>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
3. **Add this CSS.** Not optional.
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
human-machine-swapper:not(:defined) { display: none; }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Without it, the element is laid out in flow at ~50px tall until the script loads and pushes
|
|
34
|
+
the rest of the page down.
|
|
35
|
+
|
|
36
|
+
## The site must have an llms.txt
|
|
37
|
+
|
|
38
|
+
The component renders **nothing** if it cannot find one. If the site has no `/llms.txt`, write
|
|
39
|
+
one before adding the component, or the change will look broken.
|
|
40
|
+
|
|
41
|
+
Point at it so the component does not have to probe:
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<link rel="llms" href="/llms.txt" />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A minimal `llms.txt`:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
# Site Name
|
|
51
|
+
|
|
52
|
+
> One sentence on what this site is.
|
|
53
|
+
|
|
54
|
+
## About
|
|
55
|
+
|
|
56
|
+
A paragraph or two a model can quote.
|
|
57
|
+
|
|
58
|
+
## Key facts
|
|
59
|
+
|
|
60
|
+
Q: What is <Site Name>?
|
|
61
|
+
A: ...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Do not
|
|
65
|
+
|
|
66
|
+
- Do not wrap it in a client component or a portal. It is a custom element; mount it directly.
|
|
67
|
+
- Do not style it from the host page beyond the `:not(:defined)` rule. It renders in a shadow
|
|
68
|
+
root and takes its colours from `data-accent`.
|
|
69
|
+
- Do not add `rel="nofollow"` or otherwise alter the reader's credit link.
|
|
70
|
+
- Do not set `data-llms` to a URL that does not exist. The component will render the pill and
|
|
71
|
+
the reader will fail over to a navigation.
|
|
72
|
+
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
`data-position` (`bottom-center` | `top-center`), `data-llms` (`auto` | URL), `data-accent`
|
|
76
|
+
(CSS colour), `data-labels-human`, `data-labels-machine`.
|
|
77
|
+
|
|
78
|
+
## Docs
|
|
79
|
+
|
|
80
|
+
<https://advancelabs.dev/human-machine-swapper>
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# Human/Machine view
|
|
2
|
+
|
|
3
|
+
A web component that puts a **Human / Machine** pill on any website. Machine shows the site's
|
|
4
|
+
`llms.txt` — the plain-text reading written for language models — rendered in place, without
|
|
5
|
+
leaving the page. One file, about 6 KB gzipped.
|
|
6
|
+
|
|
7
|
+
No dependencies. No build step. No sign-up. Works on any stack, because it is one script tag
|
|
8
|
+
and one custom element.
|
|
9
|
+
|
|
10
|
+
```html
|
|
11
|
+
<script src="https://unpkg.com/human-machine-swapper" defer></script>
|
|
12
|
+
<human-machine-swapper data-position="bottom-center"></human-machine-swapper>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
### Script tag
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://unpkg.com/human-machine-swapper" defer></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or pin a version: `https://unpkg.com/human-machine-swapper@1.0.0`.
|
|
26
|
+
|
|
27
|
+
### npm
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install human-machine-swapper
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import "human-machine-swapper";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Required setup
|
|
40
|
+
|
|
41
|
+
Three things. Skip any one of them and the pill will not appear, or will appear broken.
|
|
42
|
+
|
|
43
|
+
### 1. Publish an `llms.txt`
|
|
44
|
+
|
|
45
|
+
The component's only job is to hand a reader the machine reading of your site. **If you do not
|
|
46
|
+
have one, the pill does not render** and the console explains why.
|
|
47
|
+
|
|
48
|
+
Put a plain-text file at `/llms.txt`. A minimal one:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
# Your Company
|
|
52
|
+
|
|
53
|
+
> One sentence on what you do.
|
|
54
|
+
|
|
55
|
+
## About
|
|
56
|
+
|
|
57
|
+
Two or three paragraphs a model can quote.
|
|
58
|
+
|
|
59
|
+
## Key facts
|
|
60
|
+
|
|
61
|
+
Q: What does Your Company do?
|
|
62
|
+
A: ...
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
See <https://llmstxt.org> for the convention.
|
|
66
|
+
|
|
67
|
+
### 2. Point at it
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<link rel="llms" href="/llms.txt" />
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Optional but recommended. Without it the component probes `/llms.txt` then `/llms-full.txt`,
|
|
74
|
+
which costs one `HEAD` request on first load (cached per tab afterwards).
|
|
75
|
+
|
|
76
|
+
### 3. Add the `:defined` guard
|
|
77
|
+
|
|
78
|
+
```css
|
|
79
|
+
human-machine-swapper:not(:defined) {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**This one is not optional.** Until the script loads, the browser treats
|
|
85
|
+
`<human-machine-swapper>` as an unknown element and lays it out in normal flow, where it
|
|
86
|
+
measures about 50px tall and pushes whatever follows it down the page. On a slow connection
|
|
87
|
+
that is a visible jump; on a fixed-height layout it is broken geometry. A page cannot be styled
|
|
88
|
+
by a script that has not loaded yet, so this is the one thing the component cannot do for
|
|
89
|
+
itself.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Framework snippets
|
|
94
|
+
|
|
95
|
+
### Plain HTML
|
|
96
|
+
|
|
97
|
+
```html
|
|
98
|
+
<!doctype html>
|
|
99
|
+
<html>
|
|
100
|
+
<head>
|
|
101
|
+
<link rel="llms" href="/llms.txt" />
|
|
102
|
+
<style>
|
|
103
|
+
human-machine-swapper:not(:defined) {
|
|
104
|
+
display: none;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
107
|
+
<script src="https://unpkg.com/human-machine-swapper" defer></script>
|
|
108
|
+
</head>
|
|
109
|
+
<body>
|
|
110
|
+
<!-- your page -->
|
|
111
|
+
<human-machine-swapper data-position="bottom-center"></human-machine-swapper>
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Next.js (App Router)
|
|
117
|
+
|
|
118
|
+
`app/layout.js`:
|
|
119
|
+
|
|
120
|
+
```jsx
|
|
121
|
+
import Script from "next/script";
|
|
122
|
+
|
|
123
|
+
export default function RootLayout({ children }) {
|
|
124
|
+
return (
|
|
125
|
+
<html lang="en">
|
|
126
|
+
<head>
|
|
127
|
+
<link rel="llms" href="/llms.txt" />
|
|
128
|
+
</head>
|
|
129
|
+
<body>
|
|
130
|
+
{children}
|
|
131
|
+
<human-machine-swapper data-position="bottom-center" />
|
|
132
|
+
<Script src="https://unpkg.com/human-machine-swapper" strategy="afterInteractive" />
|
|
133
|
+
</body>
|
|
134
|
+
</html>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`app/globals.css`:
|
|
140
|
+
|
|
141
|
+
```css
|
|
142
|
+
human-machine-swapper:not(:defined) {
|
|
143
|
+
display: none;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Put `llms.txt` in `public/`.
|
|
148
|
+
|
|
149
|
+
### Astro
|
|
150
|
+
|
|
151
|
+
```astro
|
|
152
|
+
---
|
|
153
|
+
---
|
|
154
|
+
<link rel="llms" href="/llms.txt" slot="head" />
|
|
155
|
+
<human-machine-swapper data-position="bottom-center"></human-machine-swapper>
|
|
156
|
+
<script src="https://unpkg.com/human-machine-swapper"></script>
|
|
157
|
+
<style is:global>
|
|
158
|
+
human-machine-swapper:not(:defined) { display: none; }
|
|
159
|
+
</style>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### WordPress
|
|
163
|
+
|
|
164
|
+
Add to your theme's `footer.php` before `</body>`, and the CSS to Customizer → Additional CSS.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Options
|
|
169
|
+
|
|
170
|
+
| Attribute | Value | What it does |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| `data-position` | `bottom-center` \| `top-center` | Where the pill sits, fixed to the viewport. Default `bottom-center`. |
|
|
173
|
+
| `data-llms` | `auto` \| URL | The machine reading to show. `auto` reads `link rel="llms"`, then probes `/llms.txt` and `/llms-full.txt`. |
|
|
174
|
+
| `data-accent` | CSS color | Accent for the current dot and hover. Default `#a8f326`. |
|
|
175
|
+
| `data-labels-human` | text | Override the Human label. |
|
|
176
|
+
| `data-labels-machine` | text | Override the Machine label. |
|
|
177
|
+
|
|
178
|
+
### Positioning it yourself
|
|
179
|
+
|
|
180
|
+
`data-position` picks an edge and a sensible inset. When that edge is occupied — a nav at the
|
|
181
|
+
top, a tab bar at the bottom, which on a phone is often both — set the offsets yourself. These
|
|
182
|
+
are custom properties, so they cross the shadow boundary and work from your own stylesheet:
|
|
183
|
+
|
|
184
|
+
```css
|
|
185
|
+
/* On phones this site has a 48px nav and a 58px bottom tab bar,
|
|
186
|
+
so neither default edge is free. Sit above the tab bar. */
|
|
187
|
+
@media (max-width: 899px) {
|
|
188
|
+
human-machine-swapper {
|
|
189
|
+
--hms-top: auto;
|
|
190
|
+
--hms-bottom: 70px;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
| Property | Default |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| `--hms-top` | `calc(14px + env(safe-area-inset-top))` when `data-position="top-center"`, else `auto` |
|
|
198
|
+
| `--hms-bottom` | `calc(20px + env(safe-area-inset-bottom))` when `data-position="bottom-center"`, else `auto` |
|
|
199
|
+
|
|
200
|
+
Set both when you override, so the edge you are moving away from is released.
|
|
201
|
+
|
|
202
|
+
### Hiding it during an intro animation
|
|
203
|
+
|
|
204
|
+
The element is styled by the host page like any other, and outer styles win over the
|
|
205
|
+
component's own. If your page has an opening sequence, hide it until that finishes:
|
|
206
|
+
|
|
207
|
+
```css
|
|
208
|
+
html.intro human-machine-swapper {
|
|
209
|
+
opacity: 0;
|
|
210
|
+
pointer-events: none;
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Only scope the rule to your loading state. If you set `opacity` unconditionally you override
|
|
215
|
+
the component's own reveal, and the pill will appear before it knows whether it has anything
|
|
216
|
+
to show.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## How it behaves
|
|
221
|
+
|
|
222
|
+
- **Machine renders in place.** The file is fetched and shown over the page, with the pill still
|
|
223
|
+
on screen. Human, <kbd>Escape</kbd>, or the browser's back button all return you.
|
|
224
|
+
- **Machine is a real link.** It is an `<a href>` pointing at the file, so crawlers follow it,
|
|
225
|
+
cmd-click and middle-click open the raw text in a new tab, and it works with JavaScript off.
|
|
226
|
+
Only an unmodified left click is upgraded to the in-page reader.
|
|
227
|
+
- **It hides itself when it has nothing to show.** No `llms.txt` means no pill, plus a console
|
|
228
|
+
warning telling you how to publish one. A visible control that does nothing is worse than no
|
|
229
|
+
control.
|
|
230
|
+
- **It never touches your content.** The component adds nothing to your page and removes
|
|
231
|
+
nothing from it. Everything a crawler sees is what you already shipped.
|
|
232
|
+
- **Shadow DOM.** The pill renders in a closed-off shadow root, so it cannot collide with your
|
|
233
|
+
CSS and your CSS cannot collide with it.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Why this exists
|
|
238
|
+
|
|
239
|
+
Sites increasingly publish two readings: one for people, one for models. The second is usually
|
|
240
|
+
an `llms.txt` at a URL nobody guesses and nothing links to. This makes it one click away, and
|
|
241
|
+
tells a visitor it exists.
|
|
242
|
+
|
|
243
|
+
Built by [Advance Labs](https://advancelabs.dev). The reader's header credits us; there is no
|
|
244
|
+
badge on your page.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Pinning and integrity
|
|
249
|
+
|
|
250
|
+
`https://unpkg.com/human-machine-swapper` always serves the latest release, which means you get
|
|
251
|
+
fixes automatically and you are trusting the CDN. If you would rather pin, use an exact version
|
|
252
|
+
and a Subresource Integrity hash:
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<script
|
|
256
|
+
src="https://unpkg.com/human-machine-swapper@1.0.0/src/human-machine-swapper.js"
|
|
257
|
+
integrity="sha384-REPLACE_WITH_THE_HASH_FOR_THIS_VERSION"
|
|
258
|
+
crossorigin="anonymous"
|
|
259
|
+
defer
|
|
260
|
+
></script>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Generate the hash yourself, so you are trusting the bytes you checked rather than our word:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
curl -s https://unpkg.com/human-machine-swapper@1.0.0/src/human-machine-swapper.js \
|
|
267
|
+
| openssl dgst -sha384 -binary | openssl base64 -A
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
A pinned build does not update, so you take on watching for releases. Self-hosting the file is
|
|
271
|
+
the third option and works identically: it is one dependency-free script with no network calls
|
|
272
|
+
of its own beyond reading your `llms.txt`.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Licence
|
|
277
|
+
|
|
278
|
+
Apache-2.0.
|
package/llms.txt
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# human-machine-swapper
|
|
2
|
+
|
|
3
|
+
> A dependency-free web component that adds a Human / Machine pill to any website, one file
|
|
4
|
+
> of about 6 KB gzipped. Machine
|
|
5
|
+
> shows the site's llms.txt, the plain-text reading written for language models, rendered in
|
|
6
|
+
> place without leaving the page. One script tag and one custom element, no build step.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
<script src="https://unpkg.com/human-machine-swapper" defer></script>
|
|
11
|
+
<human-machine-swapper data-position="bottom-center"></human-machine-swapper>
|
|
12
|
+
|
|
13
|
+
Or: npm install human-machine-swapper
|
|
14
|
+
|
|
15
|
+
## Required, all three
|
|
16
|
+
|
|
17
|
+
1. Load the script (above), or import "human-machine-swapper".
|
|
18
|
+
2. Mount <human-machine-swapper> anywhere in <body>. It is position:fixed.
|
|
19
|
+
3. Add this CSS, which is NOT optional:
|
|
20
|
+
|
|
21
|
+
human-machine-swapper:not(:defined) { display: none; }
|
|
22
|
+
|
|
23
|
+
Without step 3 the element is laid out in flow at about 50px tall until the script loads, and
|
|
24
|
+
pushes the rest of the page down.
|
|
25
|
+
|
|
26
|
+
## The site must have an llms.txt
|
|
27
|
+
|
|
28
|
+
The component renders nothing if it cannot find one, and writes a console warning explaining
|
|
29
|
+
how to publish one. Write the llms.txt first, or the change will look broken.
|
|
30
|
+
|
|
31
|
+
Point at it so the component does not have to probe for it:
|
|
32
|
+
|
|
33
|
+
<link rel="llms" href="/llms.txt" />
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
data-position bottom-center | top-center. Default bottom-center.
|
|
38
|
+
data-llms auto | URL. auto reads link rel=llms, then probes /llms.txt and /llms-full.txt.
|
|
39
|
+
data-accent CSS colour for the current dot and hover. Default #a8f326.
|
|
40
|
+
data-labels-human, data-labels-machine Override the two labels.
|
|
41
|
+
|
|
42
|
+
## Behaviour
|
|
43
|
+
|
|
44
|
+
- Machine renders the file in place, over the page, with the pill still on screen. Human,
|
|
45
|
+
Escape, and the browser back button all return the reader to the page.
|
|
46
|
+
- Machine is a real <a href> to the file: crawlers follow it, cmd-click and middle-click open
|
|
47
|
+
the raw text in a new tab, and it works with JavaScript off. Only an unmodified left click is
|
|
48
|
+
upgraded to the in-page reader.
|
|
49
|
+
- The component adds nothing to the host page's content and removes nothing from it.
|
|
50
|
+
- The pill renders in a shadow root, so it cannot collide with the host site's CSS.
|
|
51
|
+
|
|
52
|
+
## Key facts
|
|
53
|
+
|
|
54
|
+
Q: What is human-machine-swapper?
|
|
55
|
+
A: An Apache-2.0 web component published by Advance Labs Inc. that puts a Human / Machine
|
|
56
|
+
toggle on a website, where Machine shows the site's llms.txt rendered in place.
|
|
57
|
+
|
|
58
|
+
Q: How do I add a human machine toggle to a website?
|
|
59
|
+
A: Add the script tag, add the <human-machine-swapper> element, add the
|
|
60
|
+
human-machine-swapper:not(:defined){display:none} CSS rule, and make sure the site serves an
|
|
61
|
+
llms.txt.
|
|
62
|
+
|
|
63
|
+
Q: Why is the pill not showing up?
|
|
64
|
+
A: Almost always because the site has no llms.txt. The component hides itself when it has
|
|
65
|
+
nothing to switch to. Check the browser console for the warning.
|
|
66
|
+
|
|
67
|
+
Q: Does it put a badge on my site?
|
|
68
|
+
A: No. There is no visible credit on the host page. The reader's own header says "rendered by
|
|
69
|
+
Advance Labs", and a schema.org WebApplication node is added to the head.
|
|
70
|
+
|
|
71
|
+
Q: Does it work without JavaScript?
|
|
72
|
+
A: The pill needs JavaScript to render. The llms.txt it points at is a plain file at a stable
|
|
73
|
+
URL, so nothing is lost for crawlers.
|
|
74
|
+
|
|
75
|
+
## Links
|
|
76
|
+
|
|
77
|
+
- Docs: https://advancelabs.dev/human-machine-swapper
|
|
78
|
+
- Source: https://github.com/Advance-Labs/human-machine-swapper
|
|
79
|
+
- npm: https://www.npmjs.com/package/human-machine-swapper
|
|
80
|
+
- llms.txt convention: https://llmstxt.org
|
|
81
|
+
- Publisher: Advance Labs Inc., London, Ontario, Canada. https://advancelabs.dev
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "human-machine-swapper",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A web component that adds a Human / Machine pill to any website. Machine shows the site's llms.txt, the plain-text reading written for language models, rendered in place. One file, about 6 KB gzipped, no dependencies and no build step.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"llms.txt",
|
|
7
|
+
"llmstxt",
|
|
8
|
+
"web-component",
|
|
9
|
+
"custom-element",
|
|
10
|
+
"aeo",
|
|
11
|
+
"geo",
|
|
12
|
+
"answer-engine-optimization",
|
|
13
|
+
"ai-search",
|
|
14
|
+
"machine-readable",
|
|
15
|
+
"toggle",
|
|
16
|
+
"switcher",
|
|
17
|
+
"agent",
|
|
18
|
+
"llm"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://advancelabs.dev/human-machine-swapper",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Advance-Labs/human-machine-swapper.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Advance-Labs/human-machine-swapper/issues"
|
|
27
|
+
},
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"author": "Advance Labs Inc. (https://advancelabs.dev)",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "src/human-machine-swapper.js",
|
|
32
|
+
"module": "src/human-machine-swapper.js",
|
|
33
|
+
"unpkg": "src/human-machine-swapper.js",
|
|
34
|
+
"jsdelivr": "src/human-machine-swapper.js",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./src/human-machine-swapper.js",
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"llms.txt",
|
|
42
|
+
"AGENTS.md",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"sideEffects": true,
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "node --test test/*.test.mjs"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
if (typeof window === "undefined") return;
|
|
3
|
+
if (customElements.get("human-machine-swapper")) return;
|
|
4
|
+
|
|
5
|
+
const EMBED_URL = "https://advancelabs.dev/human-machine-swapper";
|
|
6
|
+
const CREDIT_ID = "https://advancelabs.dev/human-machine-swapper#component";
|
|
7
|
+
// Tried in order: an explicit data-llms wins, then the site's own discovery link, then
|
|
8
|
+
// these conventional paths, probed for real. Only when all of that comes back empty do
|
|
9
|
+
// we conclude the site has no machine reading to switch to.
|
|
10
|
+
const PROBE_PATHS = ["/llms.txt", "/llms-full.txt"];
|
|
11
|
+
|
|
12
|
+
let creditInjected = false;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The credit lives in the markup, not on the screen. A model reading this page gets a
|
|
16
|
+
* WebApplication node saying what this control is and who made it; a person reading
|
|
17
|
+
* view-source gets the comment. The node carries its own @id and never claims to be the
|
|
18
|
+
* host page, so it cannot collide with the site's own schema.
|
|
19
|
+
*/
|
|
20
|
+
function injectCredit() {
|
|
21
|
+
if (creditInjected) return;
|
|
22
|
+
creditInjected = true;
|
|
23
|
+
try {
|
|
24
|
+
if (document.getElementById("hms-credit")) return;
|
|
25
|
+
const script = document.createElement("script");
|
|
26
|
+
script.id = "hms-credit";
|
|
27
|
+
script.type = "application/ld+json";
|
|
28
|
+
script.textContent = JSON.stringify({
|
|
29
|
+
"@context": "https://schema.org",
|
|
30
|
+
"@type": "WebApplication",
|
|
31
|
+
"@id": CREDIT_ID,
|
|
32
|
+
name: "Human/Machine view",
|
|
33
|
+
alternateName: "Human machine switcher",
|
|
34
|
+
applicationCategory: "BrowserApplication",
|
|
35
|
+
url: EMBED_URL,
|
|
36
|
+
description:
|
|
37
|
+
"A control that switches a web page between its human reading and its machine reading (llms.txt).",
|
|
38
|
+
creator: {
|
|
39
|
+
"@type": "Organization",
|
|
40
|
+
name: "Advance Labs Inc.",
|
|
41
|
+
url: "https://advancelabs.dev",
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
document.head.appendChild(script);
|
|
45
|
+
document.head.appendChild(
|
|
46
|
+
document.createComment(" Human/Machine view by Advance Labs - " + EMBED_URL + " ")
|
|
47
|
+
);
|
|
48
|
+
} catch (error) {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function linkedHref() {
|
|
52
|
+
const link = document.querySelector('link[rel="llms"]');
|
|
53
|
+
return link ? link.getAttribute("href") : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the machine reading's URL, or null when the site genuinely has none. The
|
|
58
|
+
* probe result is cached per tab: a control that appears on every page of a site must
|
|
59
|
+
* not cost a request on every page of a site.
|
|
60
|
+
*/
|
|
61
|
+
async function resolveLlms(specified) {
|
|
62
|
+
if (specified && specified !== "auto") return specified;
|
|
63
|
+
const linked = linkedHref();
|
|
64
|
+
if (linked) return linked;
|
|
65
|
+
|
|
66
|
+
const cacheKey = "hms-llms-probe";
|
|
67
|
+
try {
|
|
68
|
+
const cached = window.sessionStorage.getItem(cacheKey);
|
|
69
|
+
if (cached !== null) return cached === "" ? null : cached;
|
|
70
|
+
} catch (error) {}
|
|
71
|
+
|
|
72
|
+
for (const path of PROBE_PATHS) {
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(path, { method: "HEAD", credentials: "omit" });
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
try {
|
|
77
|
+
window.sessionStorage.setItem(cacheKey, path);
|
|
78
|
+
} catch (error) {}
|
|
79
|
+
return path;
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {}
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
window.sessionStorage.setItem(cacheKey, "");
|
|
85
|
+
} catch (error) {}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function warnMissing() {
|
|
90
|
+
if (window.__hmsWarned) return;
|
|
91
|
+
window.__hmsWarned = true;
|
|
92
|
+
console.warn(
|
|
93
|
+
[
|
|
94
|
+
"[human-machine-swapper] No machine reading found, so the switcher is hidden.",
|
|
95
|
+
"",
|
|
96
|
+
"This control's whole job is to hand an agent the machine reading of this page.",
|
|
97
|
+
"Without one there is nothing to switch to.",
|
|
98
|
+
"",
|
|
99
|
+
"To turn it on:",
|
|
100
|
+
" 1. Publish an llms.txt at the root of this site.",
|
|
101
|
+
" 2. Point at it so it can be discovered:",
|
|
102
|
+
' <link rel="llms" href="/llms.txt">',
|
|
103
|
+
"",
|
|
104
|
+
"Or name the URL directly on the element:",
|
|
105
|
+
' <human-machine-swapper data-llms="/my-machine-view.md">',
|
|
106
|
+
"",
|
|
107
|
+
"What llms.txt is and how to write one: " + EMBED_URL,
|
|
108
|
+
].join("\n")
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class HumanMachineSwapper extends HTMLElement {
|
|
113
|
+
constructor() {
|
|
114
|
+
super();
|
|
115
|
+
this._root = this.attachShadow({ mode: "open" });
|
|
116
|
+
this._mode = "human";
|
|
117
|
+
this._text = null;
|
|
118
|
+
this._pushed = false;
|
|
119
|
+
this._onKey = (event) => {
|
|
120
|
+
if (event.key === "Escape") this._close(true);
|
|
121
|
+
};
|
|
122
|
+
this._onPop = () => {
|
|
123
|
+
this._pushed = false;
|
|
124
|
+
this._close(false);
|
|
125
|
+
};
|
|
126
|
+
this._onResize = () => this._syncThumb();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get labels() {
|
|
130
|
+
return {
|
|
131
|
+
human: this.getAttribute("data-labels-human") || "Human",
|
|
132
|
+
machine: this.getAttribute("data-labels-machine") || "Machine",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
connectedCallback() {
|
|
137
|
+
window.addEventListener("keydown", this._onKey);
|
|
138
|
+
window.addEventListener("popstate", this._onPop);
|
|
139
|
+
window.addEventListener("resize", this._onResize);
|
|
140
|
+
this._render();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
disconnectedCallback() {
|
|
144
|
+
window.removeEventListener("keydown", this._onKey);
|
|
145
|
+
window.removeEventListener("popstate", this._onPop);
|
|
146
|
+
window.removeEventListener("resize", this._onResize);
|
|
147
|
+
this._lockScroll(false);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async _render() {
|
|
151
|
+
const href = await resolveLlms(this.getAttribute("data-llms"));
|
|
152
|
+
if (!this.isConnected) return;
|
|
153
|
+
if (!href) {
|
|
154
|
+
warnMissing();
|
|
155
|
+
this._root.innerHTML = "";
|
|
156
|
+
this.setAttribute("data-hms-state", "unavailable");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const accent = this.getAttribute("data-accent") || "#a8f326";
|
|
161
|
+
const position = this.getAttribute("data-position") || "bottom-center";
|
|
162
|
+
const labels = this.labels;
|
|
163
|
+
|
|
164
|
+
this._root.innerHTML = "";
|
|
165
|
+
const style = document.createElement("style");
|
|
166
|
+
style.textContent = `
|
|
167
|
+
:host {
|
|
168
|
+
position: fixed;
|
|
169
|
+
left: 50%;
|
|
170
|
+
z-index: 60;
|
|
171
|
+
--hms-accent: ${accent};
|
|
172
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
173
|
+
line-height: 1;
|
|
174
|
+
-webkit-font-smoothing: antialiased;
|
|
175
|
+
opacity: 0;
|
|
176
|
+
transition: opacity 200ms ease;
|
|
177
|
+
}
|
|
178
|
+
/* Host-positionable on purpose. A droppable control cannot know what chrome a site
|
|
179
|
+
has at each breakpoint: on a phone the top edge may be a nav and the bottom edge a
|
|
180
|
+
tab bar, leaving neither default usable. Custom properties cross the shadow
|
|
181
|
+
boundary, so the host sets --hms-top / --hms-bottom in its own media query and the
|
|
182
|
+
component stops guessing. env() keeps it off the notch and the home indicator. */
|
|
183
|
+
:host([data-position="top-center"]) {
|
|
184
|
+
top: var(--hms-top, calc(14px + env(safe-area-inset-top)));
|
|
185
|
+
bottom: var(--hms-bottom, auto);
|
|
186
|
+
}
|
|
187
|
+
:host([data-position="bottom-center"]) {
|
|
188
|
+
bottom: var(--hms-bottom, calc(20px + env(safe-area-inset-bottom)));
|
|
189
|
+
top: var(--hms-top, auto);
|
|
190
|
+
}
|
|
191
|
+
:host([data-hms-state="ready"]) { opacity: 1; }
|
|
192
|
+
|
|
193
|
+
/* Opaque, not blurred: this floats over copy on a page we do not control. */
|
|
194
|
+
.hms__group {
|
|
195
|
+
position: relative;
|
|
196
|
+
z-index: 2;
|
|
197
|
+
transform: translateX(-50%);
|
|
198
|
+
display: inline-flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 2px;
|
|
201
|
+
padding: 3px;
|
|
202
|
+
border-radius: 9999px;
|
|
203
|
+
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
204
|
+
background: rgba(10, 10, 11, 0.92);
|
|
205
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
|
|
206
|
+
}
|
|
207
|
+
/* One thumb that slides, rather than two backgrounds that cut. The pill is the only
|
|
208
|
+
thing on screen that does not move during a swap, so it has to carry the change. */
|
|
209
|
+
.hms__thumb {
|
|
210
|
+
position: absolute;
|
|
211
|
+
/* left:0 is load-bearing. Without it the thumb falls back to its static position,
|
|
212
|
+
which already sits inside the border and padding, and then _syncThumb adds
|
|
213
|
+
offsetLeft, which is measured from the same padding box. The padding gets counted
|
|
214
|
+
twice and the thumb lands 3px right of its label: invisible under Human, and a
|
|
215
|
+
1px edge gap under Machine against 4px under Human. */
|
|
216
|
+
left: 0;
|
|
217
|
+
top: 3px;
|
|
218
|
+
bottom: 3px;
|
|
219
|
+
border-radius: 9999px;
|
|
220
|
+
background: rgba(255, 255, 255, 0.08);
|
|
221
|
+
transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
|
|
222
|
+
width 260ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
223
|
+
pointer-events: none;
|
|
224
|
+
}
|
|
225
|
+
/* Human is a <button>, so the user-agent stylesheet has to be turned off explicitly.
|
|
226
|
+
Shadow DOM isolates this from the HOST's css, not from the browser's own: without
|
|
227
|
+
these four lines the button renders with a grey background and an outset border,
|
|
228
|
+
which reads as the selected state and fights the thumb. */
|
|
229
|
+
.hms__btn {
|
|
230
|
+
appearance: none;
|
|
231
|
+
border: 0;
|
|
232
|
+
background: transparent;
|
|
233
|
+
cursor: pointer;
|
|
234
|
+
display: inline-flex;
|
|
235
|
+
align-items: center;
|
|
236
|
+
gap: 6px;
|
|
237
|
+
height: 26px;
|
|
238
|
+
padding: 0 12px;
|
|
239
|
+
color: rgba(255, 255, 255, 0.55);
|
|
240
|
+
font-family: inherit;
|
|
241
|
+
font-size: 12px;
|
|
242
|
+
letter-spacing: 0.02em;
|
|
243
|
+
border-radius: 9999px;
|
|
244
|
+
text-decoration: none;
|
|
245
|
+
white-space: nowrap;
|
|
246
|
+
transition: background 150ms ease, color 150ms ease;
|
|
247
|
+
}
|
|
248
|
+
.hms__btn:hover { color: rgba(255, 255, 255, 0.9); }
|
|
249
|
+
.hms__btn:focus-visible {
|
|
250
|
+
outline: 2px solid var(--hms-accent);
|
|
251
|
+
outline-offset: -1px;
|
|
252
|
+
}
|
|
253
|
+
.hms__btn {
|
|
254
|
+
position: relative;
|
|
255
|
+
z-index: 1;
|
|
256
|
+
}
|
|
257
|
+
.hms__btn[aria-current] {
|
|
258
|
+
color: #fff;
|
|
259
|
+
}
|
|
260
|
+
.hms__dot {
|
|
261
|
+
display: inline-block;
|
|
262
|
+
width: 6px;
|
|
263
|
+
height: 6px;
|
|
264
|
+
border-radius: 9999px;
|
|
265
|
+
background: rgba(255, 255, 255, 0.25);
|
|
266
|
+
transition: background 150ms ease;
|
|
267
|
+
}
|
|
268
|
+
.hms__btn[aria-current] .hms__dot { background: var(--hms-accent); }
|
|
269
|
+
.hms__btn:hover .hms__dot { background: var(--hms-accent); }
|
|
270
|
+
|
|
271
|
+
/* The machine reading, rendered in place. It is the same bytes the link points at,
|
|
272
|
+
so the link stays honest; this only spares the reader a trip to a dead end where
|
|
273
|
+
the control that brought them there does not exist. */
|
|
274
|
+
.hms__reader {
|
|
275
|
+
position: fixed;
|
|
276
|
+
inset: 0;
|
|
277
|
+
z-index: 1;
|
|
278
|
+
overflow-y: auto;
|
|
279
|
+
overscroll-behavior: contain;
|
|
280
|
+
/* Fully opaque, not 0.98. At 0.98 the host page's display type ghosted through
|
|
281
|
+
the machine copy, which is text over text: a contrast failure, not a nice touch. */
|
|
282
|
+
background: #09090a;
|
|
283
|
+
opacity: 0;
|
|
284
|
+
visibility: hidden;
|
|
285
|
+
transition: opacity 260ms ease, visibility 0s linear 260ms;
|
|
286
|
+
}
|
|
287
|
+
.hms__reader[data-open="true"] {
|
|
288
|
+
opacity: 1;
|
|
289
|
+
visibility: visible;
|
|
290
|
+
transition: opacity 260ms ease, visibility 0s;
|
|
291
|
+
}
|
|
292
|
+
.hms__sheet {
|
|
293
|
+
max-width: 52rem;
|
|
294
|
+
margin: 0 auto;
|
|
295
|
+
padding: 92px 24px 96px;
|
|
296
|
+
transform: translateY(10px);
|
|
297
|
+
transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
298
|
+
}
|
|
299
|
+
.hms__reader[data-open="true"] .hms__sheet { transform: none; }
|
|
300
|
+
:host([data-position="top-center"]) .hms__sheet { padding-top: 76px; }
|
|
301
|
+
.hms__meta {
|
|
302
|
+
margin: 0 0 18px;
|
|
303
|
+
font-size: 11px;
|
|
304
|
+
letter-spacing: 0.08em;
|
|
305
|
+
text-transform: uppercase;
|
|
306
|
+
color: rgba(255, 255, 255, 0.38);
|
|
307
|
+
}
|
|
308
|
+
.hms__meta a { text-decoration: none; }
|
|
309
|
+
.hms__meta a:hover { text-decoration: underline; }
|
|
310
|
+
.hms__path { color: var(--hms-accent); }
|
|
311
|
+
.hms__credit { color: rgba(255, 255, 255, 0.52); }
|
|
312
|
+
.hms__credit:hover { color: rgba(255, 255, 255, 0.85); }
|
|
313
|
+
.hms__pre {
|
|
314
|
+
margin: 0;
|
|
315
|
+
white-space: pre-wrap;
|
|
316
|
+
overflow-wrap: anywhere;
|
|
317
|
+
font-family: inherit;
|
|
318
|
+
font-size: 13px;
|
|
319
|
+
line-height: 1.75;
|
|
320
|
+
color: rgba(255, 255, 255, 0.82);
|
|
321
|
+
}
|
|
322
|
+
@media (prefers-reduced-motion: reduce) {
|
|
323
|
+
.hms__thumb, .hms__sheet, .hms__reader { transition-duration: 1ms; }
|
|
324
|
+
}
|
|
325
|
+
`;
|
|
326
|
+
this._root.appendChild(style);
|
|
327
|
+
|
|
328
|
+
// The reader comes first in the DOM so the pill paints over it without a z-index race.
|
|
329
|
+
const reader = document.createElement("div");
|
|
330
|
+
reader.className = "hms__reader";
|
|
331
|
+
reader.setAttribute("data-open", "false");
|
|
332
|
+
reader.setAttribute("role", "region");
|
|
333
|
+
reader.setAttribute("aria-label", "Machine reading");
|
|
334
|
+
reader.hidden = false;
|
|
335
|
+
const sheet = document.createElement("div");
|
|
336
|
+
sheet.className = "hms__sheet";
|
|
337
|
+
const meta = document.createElement("p");
|
|
338
|
+
meta.className = "hms__meta";
|
|
339
|
+
const pre = document.createElement("pre");
|
|
340
|
+
pre.className = "hms__pre";
|
|
341
|
+
sheet.appendChild(meta);
|
|
342
|
+
sheet.appendChild(pre);
|
|
343
|
+
reader.appendChild(sheet);
|
|
344
|
+
this._root.appendChild(reader);
|
|
345
|
+
this._reader = reader;
|
|
346
|
+
this._meta = meta;
|
|
347
|
+
this._pre = pre;
|
|
348
|
+
|
|
349
|
+
const group = document.createElement("div");
|
|
350
|
+
group.className = "hms__group";
|
|
351
|
+
group.setAttribute("role", "group");
|
|
352
|
+
group.setAttribute("aria-label", "View mode");
|
|
353
|
+
|
|
354
|
+
const thumb = document.createElement("span");
|
|
355
|
+
thumb.className = "hms__thumb";
|
|
356
|
+
thumb.setAttribute("aria-hidden", "true");
|
|
357
|
+
group.appendChild(thumb);
|
|
358
|
+
this._thumb = thumb;
|
|
359
|
+
|
|
360
|
+
// Human is a button now, because with the reader open it is the way back.
|
|
361
|
+
const human = document.createElement("button");
|
|
362
|
+
human.type = "button";
|
|
363
|
+
human.className = "hms__btn";
|
|
364
|
+
human.setAttribute("aria-current", "true");
|
|
365
|
+
human.appendChild(this._dot());
|
|
366
|
+
human.appendChild(document.createTextNode(labels.human));
|
|
367
|
+
human.addEventListener("click", () => this._close(true));
|
|
368
|
+
group.appendChild(human);
|
|
369
|
+
|
|
370
|
+
// Still a real <a href>: crawlable, middle-clickable, and it works with no JavaScript
|
|
371
|
+
// at all. A plain left click is upgraded to the in-page reader; every other kind of
|
|
372
|
+
// click is left alone, so cmd-click still opens the raw file in a new tab.
|
|
373
|
+
const machine = document.createElement("a");
|
|
374
|
+
machine.className = "hms__btn";
|
|
375
|
+
machine.href = href;
|
|
376
|
+
machine.title = "Read this site the way an agent does";
|
|
377
|
+
machine.appendChild(this._dot());
|
|
378
|
+
machine.appendChild(document.createTextNode(labels.machine));
|
|
379
|
+
machine.addEventListener("click", (event) => {
|
|
380
|
+
if (event.defaultPrevented) return;
|
|
381
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
382
|
+
return;
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
this._open(href);
|
|
385
|
+
});
|
|
386
|
+
group.appendChild(machine);
|
|
387
|
+
|
|
388
|
+
this._human = human;
|
|
389
|
+
this._machine = machine;
|
|
390
|
+
this._group = group;
|
|
391
|
+
this._root.appendChild(group);
|
|
392
|
+
this._fillMeta(href);
|
|
393
|
+
this.setAttribute("data-position", position);
|
|
394
|
+
this.setAttribute("data-hms-state", "ready");
|
|
395
|
+
this._syncThumb();
|
|
396
|
+
// Only once the control is really on the page. Claiming credit in the markup of a
|
|
397
|
+
// site where the pill rendered nothing would be a claim about nothing.
|
|
398
|
+
injectCredit();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The reader's header: which file this is, and who made the thing rendering it.
|
|
403
|
+
*
|
|
404
|
+
* Built at render, not when the reader opens. A credit that only comes into existence
|
|
405
|
+
* after somebody clicks is a credit nothing automated ever sees, and the reader is where
|
|
406
|
+
* the attribution belongs precisely because it costs the host page nothing.
|
|
407
|
+
*/
|
|
408
|
+
_fillMeta(href) {
|
|
409
|
+
const path = document.createElement("a");
|
|
410
|
+
path.href = href;
|
|
411
|
+
path.className = "hms__path";
|
|
412
|
+
try {
|
|
413
|
+
path.textContent = new URL(href, location.href).pathname;
|
|
414
|
+
} catch (error) {
|
|
415
|
+
path.textContent = href;
|
|
416
|
+
}
|
|
417
|
+
const credit = document.createElement("a");
|
|
418
|
+
credit.href = EMBED_URL;
|
|
419
|
+
credit.className = "hms__credit";
|
|
420
|
+
credit.target = "_blank";
|
|
421
|
+
credit.rel = "noopener";
|
|
422
|
+
credit.textContent = "Advance Labs";
|
|
423
|
+
|
|
424
|
+
this._meta.textContent = "";
|
|
425
|
+
this._meta.appendChild(document.createTextNode("Machine reading · "));
|
|
426
|
+
this._meta.appendChild(path);
|
|
427
|
+
this._meta.appendChild(document.createTextNode(" · rendered by "));
|
|
428
|
+
this._meta.appendChild(credit);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Parks the thumb behind whichever label is current.
|
|
433
|
+
*
|
|
434
|
+
* Measured with getBoundingClientRect, not offsetLeft/offsetWidth: those round to whole
|
|
435
|
+
* pixels, and these labels are fractional (88.27px becomes 88). That lost .27 showed up
|
|
436
|
+
* as a 4px gap on the Human side against 4.59px on the Machine side - small, but the pill
|
|
437
|
+
* is a symmetrical object and the eye reads the difference as lopsided padding.
|
|
438
|
+
* left:0 puts the thumb's origin on the group's padding box, so the offset is measured
|
|
439
|
+
* from the same edge.
|
|
440
|
+
*/
|
|
441
|
+
_syncThumb() {
|
|
442
|
+
const target = this._mode === "machine" ? this._machine : this._human;
|
|
443
|
+
if (!target || !this._thumb || !this._group) return;
|
|
444
|
+
const group = this._group.getBoundingClientRect();
|
|
445
|
+
const label = target.getBoundingClientRect();
|
|
446
|
+
if (!label.width) return;
|
|
447
|
+
const border = parseFloat(getComputedStyle(this._group).borderLeftWidth) || 0;
|
|
448
|
+
this._thumb.style.width = label.width + "px";
|
|
449
|
+
this._thumb.style.transform = "translateX(" + (label.left - group.left - border) + "px)";
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
_setMode(mode) {
|
|
453
|
+
this._mode = mode;
|
|
454
|
+
const current = mode === "machine" ? this._machine : this._human;
|
|
455
|
+
const other = mode === "machine" ? this._human : this._machine;
|
|
456
|
+
current.setAttribute("aria-current", "true");
|
|
457
|
+
other.removeAttribute("aria-current");
|
|
458
|
+
this._syncThumb();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
async _open(href) {
|
|
462
|
+
if (this._mode === "machine") return;
|
|
463
|
+
this._setMode("machine");
|
|
464
|
+
if (!this._text) this._pre.textContent = "Loading...";
|
|
465
|
+
this._reader.setAttribute("data-open", "true");
|
|
466
|
+
this._lockScroll(true);
|
|
467
|
+
// Back closes the reader instead of leaving the site.
|
|
468
|
+
try {
|
|
469
|
+
history.pushState({ hms: "machine" }, "", location.href);
|
|
470
|
+
this._pushed = true;
|
|
471
|
+
} catch (error) {}
|
|
472
|
+
|
|
473
|
+
if (!this._text) {
|
|
474
|
+
try {
|
|
475
|
+
const response = await fetch(href, { credentials: "omit" });
|
|
476
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
477
|
+
this._text = await response.text();
|
|
478
|
+
} catch (error) {
|
|
479
|
+
// Could not read it here, so hand the reader to the file itself rather than
|
|
480
|
+
// leave them looking at an apology.
|
|
481
|
+
this._close(false);
|
|
482
|
+
location.href = href;
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
this._pre.textContent = this._text;
|
|
487
|
+
this._reader.scrollTop = 0;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
_close(popHistory) {
|
|
491
|
+
if (this._mode !== "machine") return;
|
|
492
|
+
this._setMode("human");
|
|
493
|
+
this._reader.setAttribute("data-open", "false");
|
|
494
|
+
this._lockScroll(false);
|
|
495
|
+
if (popHistory && this._pushed) {
|
|
496
|
+
this._pushed = false;
|
|
497
|
+
try {
|
|
498
|
+
history.back();
|
|
499
|
+
} catch (error) {}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** The host page must not scroll behind the reader, and must get its own value back. */
|
|
504
|
+
_lockScroll(on) {
|
|
505
|
+
try {
|
|
506
|
+
if (on) {
|
|
507
|
+
this._priorOverflow = document.body.style.overflow;
|
|
508
|
+
document.body.style.overflow = "hidden";
|
|
509
|
+
} else {
|
|
510
|
+
document.body.style.overflow = this._priorOverflow || "";
|
|
511
|
+
}
|
|
512
|
+
} catch (error) {}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
_dot() {
|
|
516
|
+
const dot = document.createElement("span");
|
|
517
|
+
dot.className = "hms__dot";
|
|
518
|
+
dot.setAttribute("aria-hidden", "true");
|
|
519
|
+
return dot;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
customElements.define("human-machine-swapper", HumanMachineSwapper);
|
|
524
|
+
})();
|