@embedpdf/viewer-chrome 3.0.0-next.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/LICENSE +215 -0
- package/README.md +317 -0
- package/dist/chrome.cjs +228 -0
- package/dist/chrome.cjs.map +1 -0
- package/dist/chrome.d.cts +36 -0
- package/dist/chrome.d.ts +36 -0
- package/dist/chrome.js +224 -0
- package/dist/chrome.js.map +1 -0
- package/dist/commands.cjs +497 -0
- package/dist/commands.cjs.map +1 -0
- package/dist/commands.d.cts +22 -0
- package/dist/commands.d.ts +22 -0
- package/dist/commands.js +494 -0
- package/dist/commands.js.map +1 -0
- package/dist/es-C5084JO6.cjs +166 -0
- package/dist/es-C5084JO6.cjs.map +1 -0
- package/dist/es-D0PzYE9Z.js +166 -0
- package/dist/es-D0PzYE9Z.js.map +1 -0
- package/dist/index.cjs +3700 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +3529 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
- package/src/styles.css +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
REPOSITORY LICENSING NOTICE
|
|
2
|
+
|
|
3
|
+
This repository contains code under more than one license.
|
|
4
|
+
|
|
5
|
+
The Apache License 2.0 below applies only to the portions identified as
|
|
6
|
+
Apache-2.0 in LICENSING.md. It does not apply to cloudpdf/server, which is
|
|
7
|
+
licensed under the Fair Core License, FCL-1.0-ALv2. The authoritative terms
|
|
8
|
+
for that component are in cloudpdf/server/LICENSE.
|
|
9
|
+
|
|
10
|
+
Website content may have separate terms as described in LICENSING.md.
|
|
11
|
+
|
|
12
|
+
This notice describes the scope of the licenses and does not modify the
|
|
13
|
+
Apache License 2.0 text below.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including
|
|
63
|
+
the original version of the Work and any modifications or additions
|
|
64
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable
|
|
93
|
+
by such Contributor that are necessarily infringed by their
|
|
94
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
+
institute patent litigation against any entity (including a
|
|
97
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
+
or contributory patent infringement, then any patent licenses
|
|
100
|
+
granted to You under this License for that Work shall terminate
|
|
101
|
+
as of the date such litigation is filed.
|
|
102
|
+
|
|
103
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
+
modifications, and in Source or Object form, provided that You
|
|
106
|
+
meet the following conditions:
|
|
107
|
+
|
|
108
|
+
(a) You must give any other recipients of the Work or
|
|
109
|
+
Derivative Works a copy of this License; and
|
|
110
|
+
|
|
111
|
+
(b) You must cause any modified files to carry prominent notices
|
|
112
|
+
stating that You changed the files; and
|
|
113
|
+
|
|
114
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
+
that You distribute, all copyright, patent, trademark, and
|
|
116
|
+
attribution notices from the Source form of the Work,
|
|
117
|
+
excluding those notices that do not pertain to any part of
|
|
118
|
+
the Derivative Works; and
|
|
119
|
+
|
|
120
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
+
distribution, then any Derivative Works that You distribute must
|
|
122
|
+
include a readable copy of the attribution notices contained
|
|
123
|
+
within such NOTICE file, excluding those notices that do not
|
|
124
|
+
pertain to any part of the Derivative Works, in at least one
|
|
125
|
+
of the following places: within a NOTICE text file distributed
|
|
126
|
+
as part of the Derivative Works; within the Source form or
|
|
127
|
+
documentation, if provided along with the Derivative Works; or,
|
|
128
|
+
within a display generated by the Derivative Works, if and
|
|
129
|
+
wherever such third-party notices normally appear. The contents
|
|
130
|
+
of the NOTICE file are for informational purposes only and
|
|
131
|
+
do not modify the License. You may add Your own attribution
|
|
132
|
+
notices within Derivative Works that You distribute, alongside
|
|
133
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
+
that such additional attribution notices cannot be construed
|
|
135
|
+
as modifying the License.
|
|
136
|
+
|
|
137
|
+
You may add Your own copyright statement to Your modifications and
|
|
138
|
+
may provide additional or different license terms and conditions
|
|
139
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
+
the conditions stated in this License.
|
|
143
|
+
|
|
144
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
+
this License, without any additional terms or conditions.
|
|
148
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
+
the terms of any separate license agreement you may have executed
|
|
150
|
+
with Licensor regarding such Contributions.
|
|
151
|
+
|
|
152
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
+
except as required for reasonable and customary use in describing the
|
|
155
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
+
|
|
157
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
+
implied, including, without limitation, any warranties or conditions
|
|
162
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
+
appropriateness of using or redistributing the Work and assume any
|
|
165
|
+
risks associated with Your exercise of permissions under this License.
|
|
166
|
+
|
|
167
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
+
unless required by applicable law (such as deliberate and grossly
|
|
170
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
+
liable to You for damages, including any direct, indirect, special,
|
|
172
|
+
incidental, or consequential damages of any character arising as a
|
|
173
|
+
result of this License or out of the use or inability to use the
|
|
174
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
+
other commercial damages or losses), even if such Contributor
|
|
177
|
+
has been advised of the possibility of such damages.
|
|
178
|
+
|
|
179
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
+
or other liability obligations and/or rights consistent with this
|
|
183
|
+
License. However, in accepting such obligations, You may act only
|
|
184
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
+
defend, and hold each Contributor harmless for any liability
|
|
187
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
+
of your accepting any such warranty or additional liability.
|
|
189
|
+
|
|
190
|
+
END OF TERMS AND CONDITIONS
|
|
191
|
+
|
|
192
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
193
|
+
|
|
194
|
+
To apply the Apache License to your work, attach the following
|
|
195
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
196
|
+
replaced with your own identifying information. (Don't include
|
|
197
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
198
|
+
comment syntax for the file format. We also recommend that a
|
|
199
|
+
file or class name and description of purpose be included on the
|
|
200
|
+
same "printed page" as the copyright notice for easier
|
|
201
|
+
identification within third-party archives.
|
|
202
|
+
|
|
203
|
+
Copyright [yyyy] [name of copyright owner]
|
|
204
|
+
|
|
205
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
206
|
+
you may not use this file except in compliance with the License.
|
|
207
|
+
You may obtain a copy of the License at
|
|
208
|
+
|
|
209
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
210
|
+
|
|
211
|
+
Unless required by applicable law or agreed to in writing, software
|
|
212
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
213
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
214
|
+
See the License for the specific language governing permissions and
|
|
215
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# @embedpdf/viewer-chrome
|
|
2
|
+
|
|
3
|
+
The full viewer, as one React component. This package is the **single
|
|
4
|
+
implementation** of the snippet UI — the measured toolbar, mode bands, panels,
|
|
5
|
+
tab bar, theme — consumed by `@embedpdf/viewer` (the Preact-compiled
|
|
6
|
+
`<embedpdf-viewer>` custom element) and every framework wrapper. It is private:
|
|
7
|
+
apps install a delivery package, not the chrome.
|
|
8
|
+
|
|
9
|
+
The customization surface below is **the** contract: the same object shape
|
|
10
|
+
later powers `EmbedPDF.init({ ... })` and every wrapper's props, because all of
|
|
11
|
+
it is plain data — nothing here is React-specific except the component itself.
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { FullViewer } from '@embedpdf/viewer-chrome';
|
|
17
|
+
import '@embedpdf/viewer-chrome/styles.css';
|
|
18
|
+
import { localEngine } from '@embedpdf/engine';
|
|
19
|
+
|
|
20
|
+
<FullViewer
|
|
21
|
+
engine={() => localEngine()}
|
|
22
|
+
initialDocuments={[{ name: 'Report', source: reportBytes }]}
|
|
23
|
+
/>;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Everything renders at t≈0; only the pages wait on the wasm engine.
|
|
27
|
+
|
|
28
|
+
## Customizing
|
|
29
|
+
|
|
30
|
+
Two kinds of surface, two deliberate semantics:
|
|
31
|
+
|
|
32
|
+
- **Registries** (`commands`, `icons`, `strings`) are **additive**: your
|
|
33
|
+
entries merge over the defaults by id; a colliding id overrides. Safe,
|
|
34
|
+
order-independent, upgrade-friendly.
|
|
35
|
+
- **Structure** (`chrome`) is a **value you own**: take the default, transform
|
|
36
|
+
it, or write your own. It is never merged — there is no patch grammar to
|
|
37
|
+
learn, because the schema is small enough to read.
|
|
38
|
+
|
|
39
|
+
### Remove features
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
<FullViewer engine={engine} disabledCategories={['form', 'redaction']} />
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A disabled category vanishes everywhere at once — toolbar, menus, overflow,
|
|
46
|
+
shortcuts — because every surface is a projection of the same command registry.
|
|
47
|
+
|
|
48
|
+
### Add a button
|
|
49
|
+
|
|
50
|
+
The 90% case, end to end — one command, one icon, one string, one placement:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<FullViewer
|
|
54
|
+
engine={engine}
|
|
55
|
+
icons={{
|
|
56
|
+
// 24×24 stroke path data — Tabler/Lucide icons paste in verbatim.
|
|
57
|
+
send: [
|
|
58
|
+
'M10 14L21 3',
|
|
59
|
+
'M21 3l-6.5 18a.5.5 0 0 1-1 0L10 14l-7-3.5a.5.5 0 0 1 0-1L21 3z',
|
|
60
|
+
],
|
|
61
|
+
}}
|
|
62
|
+
strings={{
|
|
63
|
+
en: { 'acme.send': 'Send for signature' },
|
|
64
|
+
nl: { 'acme.send': 'Verstuur ter ondertekening' },
|
|
65
|
+
}}
|
|
66
|
+
commands={[
|
|
67
|
+
{
|
|
68
|
+
id: 'acme:send',
|
|
69
|
+
labelKey: 'acme.send',
|
|
70
|
+
icon: 'send',
|
|
71
|
+
shortcut: 'Mod+Shift+S',
|
|
72
|
+
enabled: (ctx) => ctx.documentId !== null,
|
|
73
|
+
run: (ctx) => {
|
|
74
|
+
void fetch(`/api/sign/${ctx.documentId}`, { method: 'POST' });
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
chrome={(base, h) =>
|
|
79
|
+
h.addItem(base, {
|
|
80
|
+
bar: 'main',
|
|
81
|
+
section: 'end',
|
|
82
|
+
group: 'panels',
|
|
83
|
+
item: 'acme:send',
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
That one registration is a button that degrades responsively (`importance` is
|
|
90
|
+
the only responsive knob — there are no breakpoints to edit), drops into the
|
|
91
|
+
derived overflow menu on narrow screens, has a working keyboard shortcut, and
|
|
92
|
+
is localized. Referencing an unknown command or icon logs a dev-mode warning
|
|
93
|
+
naming the exact id.
|
|
94
|
+
|
|
95
|
+
`chrome` accepts the schema **value** or a **transform** of the default. The
|
|
96
|
+
helpers come in as the second argument so simple edits need no imports:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
chrome={(base, h) =>
|
|
100
|
+
h.removeItems(
|
|
101
|
+
h.replaceItem(base, 'panel:comment', { command: 'acme:chat', importance: 5 }),
|
|
102
|
+
['annotation:add-squiggly'],
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- `h.addItem(schema, { bar, section, group, item, at? })` — `bar` is a bar id
|
|
108
|
+
(`'main'`, a mode bar like `'annotate'`, or a strip); a new `group` id
|
|
109
|
+
creates that group at the end of the section.
|
|
110
|
+
- `h.removeItems(schema, ids)` — purges the commands from every bar, mode bar,
|
|
111
|
+
strip, and menu; emptied groups disappear.
|
|
112
|
+
- `h.replaceItem(schema, id, item)` — swaps a command in place, everywhere.
|
|
113
|
+
- Plus the authoring sugar (`h.item`, `h.group`, `h.custom`, `h.defineChrome`)
|
|
114
|
+
for building bigger pieces inline.
|
|
115
|
+
|
|
116
|
+
### Own the structure
|
|
117
|
+
|
|
118
|
+
For real restructuring, don't patch — write the value. It is the complete
|
|
119
|
+
structural definition of the viewer, and it is small:
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
import {
|
|
123
|
+
FullViewer,
|
|
124
|
+
defineChrome,
|
|
125
|
+
group,
|
|
126
|
+
custom,
|
|
127
|
+
defaultChrome,
|
|
128
|
+
} from '@embedpdf/viewer-chrome';
|
|
129
|
+
|
|
130
|
+
// A minimal "reading room": zoom, search, download. Nothing else.
|
|
131
|
+
const chrome = defineChrome({
|
|
132
|
+
bars: {
|
|
133
|
+
main: {
|
|
134
|
+
id: 'main',
|
|
135
|
+
sections: {
|
|
136
|
+
start: [
|
|
137
|
+
group('zoom', [
|
|
138
|
+
custom('zoom-controls', {
|
|
139
|
+
variants: ['inline', 'button'],
|
|
140
|
+
terminal: 'zoom:menu',
|
|
141
|
+
}),
|
|
142
|
+
]),
|
|
143
|
+
],
|
|
144
|
+
end: [group('actions', ['panel:search', 'document:download'])],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
menus: { zoom: defaultChrome.menus.zoom },
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
<FullViewer engine={engine} chrome={chrome} />;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Adding an entry under `chrome.modeBars` adds a whole mode: the mode tab strip
|
|
155
|
+
is derived from `modeBars` keys, so a custom review workflow is one command
|
|
156
|
+
(the mode surface) plus one bar schema — not a special case.
|
|
157
|
+
|
|
158
|
+
Your stability, your choice: pass no `chrome` and you track our default (new
|
|
159
|
+
features appear on upgrade); own the value and your toolbar never moves — new
|
|
160
|
+
EmbedPDF features arrive as new command ids you opt into by adding a line.
|
|
161
|
+
|
|
162
|
+
### Locale
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
<FullViewer engine={engine} locale="es" /> // fixed
|
|
166
|
+
<FullViewer engine={engine} locale="auto" /> // negotiate from the browser (default)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`strings` may target any locale code, with dotted keys (`'acme.send'`)
|
|
170
|
+
expanding into the pack. A code with no built-in pack becomes a new locale that
|
|
171
|
+
falls back to English for everything you didn't provide.
|
|
172
|
+
|
|
173
|
+
### Slots — your component inside the measured toolbar
|
|
174
|
+
|
|
175
|
+
Reserve a socket in the chrome (`custom()` with a `terminal` command), then —
|
|
176
|
+
through `<embedpdf-viewer>` or any wrapper — supply a child with the matching
|
|
177
|
+
`slot` attribute:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
// @embedpdf/viewer-react
|
|
181
|
+
<PDFViewer
|
|
182
|
+
src="/report.pdf"
|
|
183
|
+
commands={[{ id: 'acme:status', labelKey: 'acme.status', run: () => {} }]}
|
|
184
|
+
chrome={(base, h) =>
|
|
185
|
+
h.addItem(base, {
|
|
186
|
+
bar: 'main',
|
|
187
|
+
section: 'start',
|
|
188
|
+
group: 'workspace',
|
|
189
|
+
item: h.custom('doc-status', { terminal: 'acme:status' }),
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
>
|
|
193
|
+
<DocStatus slot="doc-status" />
|
|
194
|
+
</PDFViewer>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The child stays in YOUR world — light DOM, your framework's tree, your page
|
|
198
|
+
CSS — while the browser projects it into the toolbar. The socket is measured
|
|
199
|
+
live, so the solver budgets its true width; when it no longer fits, the
|
|
200
|
+
`terminal` command represents it in the derived overflow menu. An unfilled
|
|
201
|
+
socket displays its terminal command as native slot fallback, so the same
|
|
202
|
+
chrome works with and without the child (and outside shadow DOM entirely —
|
|
203
|
+
this package's own React consumers see the fallback).
|
|
204
|
+
|
|
205
|
+
Slot names must be unique across the chrome (one `<slot name>` per shadow
|
|
206
|
+
tree wins projection).
|
|
207
|
+
|
|
208
|
+
### The frame — regions: arrangement, visibility, replacement
|
|
209
|
+
|
|
210
|
+
Regions are a FIXED vocabulary (`header`, `tabs`, the toolbar band — each
|
|
211
|
+
carries semantics the shell owns: measurement physics, the document gate,
|
|
212
|
+
aria). Three independent knobs on each:
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
// 1. ARRANGE + HIDE — part of the chrome value, because it is structure:
|
|
216
|
+
chrome={(base) => ({
|
|
217
|
+
...base,
|
|
218
|
+
frame: { toolbar: 'bottom', tabs: 'multiple', header: false },
|
|
219
|
+
})}
|
|
220
|
+
|
|
221
|
+
// 2. REPLACE — regions are sockets; the built-in is the slot fallback:
|
|
222
|
+
<PDFViewer documents={docs} onReady={setViewer}>
|
|
223
|
+
<AcmeTabBar slot="tabs" viewer={viewer} />
|
|
224
|
+
</PDFViewer>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`header` is the one region with **no** built-in: the viewer ships no brand
|
|
228
|
+
row, locale picker or theme switch, because that chrome belongs to your app,
|
|
229
|
+
not to the PDF. The socket is there so yours can sit inside the frame:
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
<PDFViewer documents={docs}>
|
|
233
|
+
<AcmeHeader slot="header" />
|
|
234
|
+
</PDFViewer>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Left unfilled it renders nothing, and `frame: { header: false }` drops the
|
|
238
|
+
socket entirely. Theme and locale stay under your control as props —
|
|
239
|
+
`theme={{ preference, tokens }}` and `locale` (`'auto'` negotiates from the
|
|
240
|
+
browser) — so a switch in your own header is a state change on your side.
|
|
241
|
+
|
|
242
|
+
A replacement region is fully functional through the handle — the kernel's
|
|
243
|
+
document registry IS the tab model (`viewer.documents.list()/activeId()/
|
|
244
|
+
setActive()/close()` + `viewer.watch`). A region hidden by the frame hides
|
|
245
|
+
its socket too: visibility outranks slotted content. The mode band rides the
|
|
246
|
+
main toolbar's content side (below a top bar, above a bottom bar).
|
|
247
|
+
|
|
248
|
+
### Drive — control the viewer from code
|
|
249
|
+
|
|
250
|
+
The handle (`el.viewer` on the custom element, `onReady` on the wrappers) is a
|
|
251
|
+
thin skin over the kernel: `get(Token)` returns each plugin's **public
|
|
252
|
+
capability lens** verbatim — the same documented API the chrome's own buttons
|
|
253
|
+
use — plus ONE reactivity primitive and the command trio:
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
el.addEventListener('epdf:ready', () => {
|
|
257
|
+
const viewer = el.viewer;
|
|
258
|
+
|
|
259
|
+
viewer.execute('zoom:in'); // commands: UI verbs
|
|
260
|
+
const annotation = viewer.get(AnnotationToken); // capabilities: the API
|
|
261
|
+
await annotation.create(pon, draft);
|
|
262
|
+
|
|
263
|
+
viewer.watch(
|
|
264
|
+
// the one primitive
|
|
265
|
+
() => annotation.getSelectionProps(),
|
|
266
|
+
(props) => myPanel.render(props),
|
|
267
|
+
);
|
|
268
|
+
viewer.documents.list(); // the tab model
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Rule of thumb: **buttons speak commands; code speaks capabilities.** The
|
|
273
|
+
token re-export list in `index.ts` is the public-API act — internal lenses
|
|
274
|
+
(`/internal` entries) are structurally absent from delivery bundles. Coarse
|
|
275
|
+
DOM events (`epdf:ready`, `epdf:documentchange`) are sugar over `watch`.
|
|
276
|
+
|
|
277
|
+
### Theme — match your brand
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
theme={{
|
|
281
|
+
preference: 'system',
|
|
282
|
+
tokens: { accent: '#7c3aed', 'accent-hover': '#6d28d9' }, // both modes
|
|
283
|
+
dark: { accent: '#a78bfa' }, // dark overrides
|
|
284
|
+
}}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Token names are the `--ep-*` variables in `styles.css` without the prefix —
|
|
288
|
+
the prefix exists because custom properties inherit through shadow boundaries,
|
|
289
|
+
so unprefixed names could collide with the host page. The custom element
|
|
290
|
+
adopts the overrides into its shadow root; direct consumers of this package
|
|
291
|
+
just set the `--ep-*` variables in their own CSS.
|
|
292
|
+
|
|
293
|
+
### Restyle — reshape built-ins with page CSS
|
|
294
|
+
|
|
295
|
+
Key elements carry shadow `part` attributes, so plain page CSS reaches them:
|
|
296
|
+
|
|
297
|
+
```css
|
|
298
|
+
embedpdf-viewer::part(toolbar-button) {
|
|
299
|
+
border-radius: 2px;
|
|
300
|
+
}
|
|
301
|
+
embedpdf-viewer::part(tab-active) {
|
|
302
|
+
font-weight: 700;
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The v1 part vocabulary — public API, grown by demand, never speculatively:
|
|
307
|
+
`toolbar`, `toolbar-button(-active)`, `mode-tab(-active)`, `tab(-active)`,
|
|
308
|
+
`menu`, `menu-item(-active)`.
|
|
309
|
+
|
|
310
|
+
## What's deliberately NOT here (yet)
|
|
311
|
+
|
|
312
|
+
- **The element registry** (`elements: { button: 'tag' }` + exported base
|
|
313
|
+
classes) — the last move of the six-move model.
|
|
314
|
+
- **More regions & parts** — `header`/`tabs` sockets and the part list above
|
|
315
|
+
are the v1 vocabulary; grow by demand (names are public API).
|
|
316
|
+
- **Radius/density/font tokens** — the token set is the color vocabulary
|
|
317
|
+
today; spacing/shape tokens need a component sweep and land separately.
|