feat: release Office Tools 0.1.0
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
release/*.zip
|
||||||
|
release/*.zip.sha256
|
||||||
|
coverage/
|
||||||
|
playwright-report/
|
||||||
|
test-results/
|
||||||
|
*.tsbuildinfo
|
||||||
|
.DS_Store
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@add-ideas:registry=https://git.add-ideas.de/api/packages/lotobo/npm/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Verbatim upstream legal notice; keep its original formatting.
|
||||||
|
LICENSES/silurus-ooxml-THIRD_PARTY_NOTICES.md
|
||||||
|
public/LICENSES/silurus-ooxml-THIRD_PARTY_NOTICES.md
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to Office Tools are documented here. Versions follow
|
||||||
|
Semantic Versioning.
|
||||||
|
|
||||||
|
## 0.1.0 - 2026-08-31
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Initial local-first Office Tools application and Toolbox 0.2.3 integration.
|
||||||
|
- High-fidelity local DOCX/XLSX/PPTX canvas viewing with search, zoom and
|
||||||
|
document-aware navigation.
|
||||||
|
- Project-owned bounded ODT/ODS/ODP package reader and semantic views for text,
|
||||||
|
tables, spreadsheets, slides, images, notes and safe styling.
|
||||||
|
- Package-integrity, traversal, XML, expansion, repeat, cell, text and asset
|
||||||
|
protections with inert external/active content and visible diagnostics.
|
||||||
|
- Responsive light, dark and system-mode shell with accessible file selection.
|
||||||
|
- Relocatable installable build, strict release identity and deterministic ZIP
|
||||||
|
packaging with corresponding-source and licence material.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Contributions are welcome when they preserve the application's local-first,
|
||||||
|
inspection-oriented boundary.
|
||||||
|
|
||||||
|
## Development workflow
|
||||||
|
|
||||||
|
1. Use Node.js 22 or newer.
|
||||||
|
2. Install the locked dependencies with `npm ci`.
|
||||||
|
3. Keep parsing, package traversal and expensive work away from the React render
|
||||||
|
path; use bounded worker operations where appropriate.
|
||||||
|
4. Add focused unit tests and malformed-input cases for every parser change.
|
||||||
|
5. Run `npm run check` and `npm run test:browser` before proposing a change.
|
||||||
|
|
||||||
|
Do not add telemetry, remote document conversion, runtime CDN dependencies or
|
||||||
|
automatic external-resource fetching. Never execute macros, embedded scripts or
|
||||||
|
active document content. New dependencies need a licence and maintenance review
|
||||||
|
and must be reflected in `THIRD_PARTY_NOTICES.md` where required.
|
||||||
|
|
||||||
|
Format support must be described conservatively. A partial reader should expose
|
||||||
|
what it preserved, approximated, omitted or rejected rather than claiming Office
|
||||||
|
suite fidelity.
|
||||||
|
|
||||||
|
By contributing, you agree that your contribution is licensed under
|
||||||
|
GPL-3.0-or-later.
|
||||||
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Runtime licence inventory
|
||||||
|
|
||||||
|
`npm run release:prepare` generates `npm-runtime-licenses.txt` from the exact
|
||||||
|
runtime packages in `package-lock.json`. The generated inventory is included in
|
||||||
|
the static build and release ZIP together with the project licence and
|
||||||
|
third-party notices.
|
||||||
|
|
||||||
|
The reviewed Silurus OOXML licence and its bundled-code/data notices are also
|
||||||
|
kept as stable files because the npm package contains Rust/WebAssembly and data
|
||||||
|
whose complete provenance is broader than its top-level MIT licence.
|
||||||
|
|
||||||
|
Review dependency licence changes whenever the lockfile changes. Generation is
|
||||||
|
an inventory aid, not a substitute for legal review.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Yuki Yokotani
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,369 @@
|
|||||||
|
# Third-Party Notices
|
||||||
|
|
||||||
|
`@silurus/ooxml` is MIT-licensed (see [LICENSE](./LICENSE)). It bundles the
|
||||||
|
third-party components listed below, none of which are copyleft. This file
|
||||||
|
is included in the npm tarball so it travels with every install.
|
||||||
|
|
||||||
|
## JavaScript / bundled asset
|
||||||
|
|
||||||
|
### Natural Earth Admin 0 Countries, 1:110m
|
||||||
|
|
||||||
|
The optional Region Map renderer contains a coordinate-quantized derivative of
|
||||||
|
Natural Earth's Admin 0 Countries 1:110m vector dataset. Natural Earth states
|
||||||
|
that all versions of its raster and vector data are in the public domain. The
|
||||||
|
generated source records the exact upstream SHA-256 and fixed feature/vertex
|
||||||
|
bounds. The boundaries are illustrative, show Natural Earth's default de-facto
|
||||||
|
point of view, and do not imply this project's endorsement of any territorial
|
||||||
|
claim.
|
||||||
|
|
||||||
|
- Source: <https://github.com/nvkelso/natural-earth-vector/blob/master/geojson/ne_110m_admin_0_countries.geojson>
|
||||||
|
- Terms: <https://www.naturalearthdata.com/about/terms-of-use/>
|
||||||
|
|
||||||
|
### MathJax + STIX Two Math (`mathjax-stix2.js`)
|
||||||
|
|
||||||
|
The optional equation-rendering engine (`@silurus/ooxml/math`, opt-in —
|
||||||
|
see the [README's "Rendering equations" section](./README.md#rendering-equations))
|
||||||
|
pre-bundles two Apache-2.0 packages into a single ~3 MB asset
|
||||||
|
(`packages/core/assets/mathjax-stix2.js`, built by
|
||||||
|
[`packages/core/build/build-mathjax.mjs`](./packages/core/build/build-mathjax.mjs)).
|
||||||
|
It ships in the npm tarball but is only fetched by a consuming app at
|
||||||
|
runtime if that app imports `@silurus/ooxml/math` **and** the loaded
|
||||||
|
document actually contains an equation.
|
||||||
|
|
||||||
|
- **[MathJax](https://www.mathjax.org/)** (`@mathjax/src`, v4.1.2) —
|
||||||
|
Copyright © MathJax Consortium. Licensed under the
|
||||||
|
[Apache License, Version 2.0](#apache-license-20-full-text).
|
||||||
|
<https://github.com/mathjax/MathJax-src>
|
||||||
|
- **STIX Two Math font, as packaged for MathJax v4**
|
||||||
|
(`@mathjax/mathjax-stix2-font`, v4.1.2) — Copyright © MathJax Consortium.
|
||||||
|
The npm package declares `"license": "Apache-2.0"` in its `package.json`
|
||||||
|
(verified by reading `node_modules/@mathjax/mathjax-stix2-font/package.json`
|
||||||
|
directly; the package does not bundle its own `LICENSE` file, so this is
|
||||||
|
the authoritative declaration). Licensed under the
|
||||||
|
[Apache License, Version 2.0](#apache-license-20-full-text).
|
||||||
|
<https://github.com/mathjax/MathJax-fonts>
|
||||||
|
|
||||||
|
Note: the STIX Two Math font is also separately distributed upstream
|
||||||
|
(<https://github.com/stipub/stixfonts>) under the SIL Open Font License
|
||||||
|
1.1. The build in this repository consumes the Apache-2.0-licensed
|
||||||
|
`@mathjax/mathjax-stix2-font` npm package specifically, not the upstream
|
||||||
|
OFL font files directly, so Apache-2.0 is the governing license for the
|
||||||
|
bytes actually shipped here.
|
||||||
|
|
||||||
|
Neither package includes a Apache-2.0 §4(d) `NOTICE` file (checked in
|
||||||
|
the installed `node_modules` tree), so there is no additional NOTICE
|
||||||
|
content to reproduce beyond the attribution above.
|
||||||
|
|
||||||
|
### Build-time only (not shipped)
|
||||||
|
|
||||||
|
The library also declares `esbuild` (MIT) as a build-time dependency
|
||||||
|
(bundles `mathjax-stix2.js` above) and TypeScript (Apache-2.0) as a
|
||||||
|
dev/type-check dependency. Neither's code is included in the published
|
||||||
|
package — noted here for completeness only.
|
||||||
|
|
||||||
|
## Rust / WebAssembly
|
||||||
|
|
||||||
|
The three parser crates (`docx-parser`, `pptx-parser`, `xlsx-parser`) and
|
||||||
|
their shared `ooxml-common` crate compile to the `*_parser_bg.wasm` binaries
|
||||||
|
shipped in `dist/`. Their `wasm32-unknown-unknown` dependency graph is
|
||||||
|
identical across all three crates (verified with `cargo license
|
||||||
|
--filter-platform wasm32-unknown-unknown`) and consists entirely of
|
||||||
|
permissively-licensed crates — no copyleft (GPL/LGPL/AGPL) dependencies:
|
||||||
|
|
||||||
|
| License | Crates |
|
||||||
|
|---|---|
|
||||||
|
| MIT OR Apache-2.0 | bumpalo, cfg-if, console_error_panic_hook, crc32fast, displaydoc, equivalent, flate2, hashbrown, indexmap, itoa, log, once_cell, proc-macro2, quote, roxmltree, rustversion, serde, serde_core, serde_derive, serde_json, syn, thiserror, thiserror-impl, wasm-bindgen, wasm-bindgen-macro, wasm-bindgen-macro-support, wasm-bindgen-shared |
|
||||||
|
| (Apache-2.0 OR MIT) AND Unicode-3.0 | unicode-ident |
|
||||||
|
| 0BSD OR Apache-2.0 OR MIT | adler2 |
|
||||||
|
| Apache-2.0 | zopfli |
|
||||||
|
| Apache-2.0 OR MIT OR Zlib | miniz_oxide |
|
||||||
|
| MIT | simd-adler32, zip, zmij |
|
||||||
|
| MIT OR Unlicense | memchr |
|
||||||
|
|
||||||
|
Full license texts for each crate are available from
|
||||||
|
[crates.io](https://crates.io/) or the crate's own repository; SPDX
|
||||||
|
identifiers above match each crate's `Cargo.toml` `license` field. This
|
||||||
|
list was generated with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install cargo-license
|
||||||
|
cargo license --manifest-path packages/pptx/parser/Cargo.toml \
|
||||||
|
--avoid-dev-deps --filter-platform wasm32-unknown-unknown
|
||||||
|
# docx-parser / xlsx-parser produce an identical dependency set
|
||||||
|
```
|
||||||
|
|
||||||
|
### MCP server (`ooxml-mcp-server`, separate distribution)
|
||||||
|
|
||||||
|
`packages/mcp-server` is not part of the `@silurus/ooxml` npm package — it
|
||||||
|
is a standalone binary distributed independently (see the repository's MCP
|
||||||
|
server documentation). Its dependency graph is a superset of the table
|
||||||
|
above (adds `tokio`, `rmcp`, `anyhow`, `schemars`, `tracing`, and their
|
||||||
|
transitive deps for the async runtime and MCP protocol implementation) and
|
||||||
|
remains entirely MIT / Apache-2.0, with no copyleft licenses:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo license --manifest-path packages/mcp-server/Cargo.toml --avoid-dev-deps
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unicode Character Database data
|
||||||
|
|
||||||
|
The line-breaking, vertical-orientation and Arabic-shaping logic is driven
|
||||||
|
by tables generated from the Unicode Character Database (UCD), © Unicode,
|
||||||
|
Inc., licensed under the [Unicode License v3](#unicode-license-v3-full-text)
|
||||||
|
(SPDX: `Unicode-3.0`), which expressly permits copying, modification and
|
||||||
|
redistribution of the data files with this notice.
|
||||||
|
|
||||||
|
Checked into this repository (generator inputs, each retaining its original
|
||||||
|
Unicode copyright header; not part of the npm tarball):
|
||||||
|
|
||||||
|
- `packages/core/scripts/VerticalOrientation.txt` (UAX #50
|
||||||
|
Vertical_Orientation, UCD 17.0.0)
|
||||||
|
- `packages/docx/scripts/ArabicShaping.txt` (Joining_Type / Joining_Group,
|
||||||
|
UCD 17.0.0)
|
||||||
|
- `packages/docx/scripts/DerivedJoiningType.txt` (UCD 17.0.0)
|
||||||
|
|
||||||
|
Shipped in `dist/` as UCD-derived data compiled from the above and from
|
||||||
|
`LineBreak.txt` / `DerivedGeneralCategory.txt` / `EastAsianWidth.txt`
|
||||||
|
(fetched at generation time, not checked in): the `*.generated.ts` tables
|
||||||
|
under `packages/core/src/text/` and `packages/docx/src/` (line-break
|
||||||
|
classes, East Asian width, vertical orientation, bidi character data,
|
||||||
|
Arabic joining classes).
|
||||||
|
|
||||||
|
The `unicode-ident` Rust crate listed above also carries `Unicode-3.0` in
|
||||||
|
its SPDX expression for the same reason (embedded UCD-derived tables).
|
||||||
|
|
||||||
|
## License texts
|
||||||
|
|
||||||
|
- **MIT** — see [LICENSE](./LICENSE) (this repository's own license; the
|
||||||
|
MIT-licensed dependencies above use the same standard text with their own
|
||||||
|
copyright holder).
|
||||||
|
- **Unicode License v3** — canonical text at
|
||||||
|
<https://www.unicode.org/license.txt>, reproduced below.
|
||||||
|
- **Apache License, Version 2.0** — full text at
|
||||||
|
<https://www.apache.org/licenses/LICENSE-2.0>, reproduced below for
|
||||||
|
convenience.
|
||||||
|
|
||||||
|
### Unicode License v3 (full text)
|
||||||
|
|
||||||
|
```
|
||||||
|
UNICODE LICENSE V3
|
||||||
|
|
||||||
|
COPYRIGHT AND PERMISSION NOTICE
|
||||||
|
|
||||||
|
Copyright © 1991-2026 Unicode, Inc.
|
||||||
|
|
||||||
|
NOTICE TO USER: Carefully read the following legal agreement. BY
|
||||||
|
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
|
||||||
|
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
|
||||||
|
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
|
||||||
|
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of data files and any associated documentation (the "Data Files") or
|
||||||
|
software and any associated documentation (the "Software") to deal in the
|
||||||
|
Data Files or Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
||||||
|
copies of the Data Files or Software, and to permit persons to whom the
|
||||||
|
Data Files or Software are furnished to do so, provided that either (a)
|
||||||
|
this copyright and permission notice appear with all copies of the Data
|
||||||
|
Files or Software, or (b) this copyright and permission notice appear in
|
||||||
|
associated Documentation.
|
||||||
|
|
||||||
|
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
THIRD PARTY RIGHTS.
|
||||||
|
|
||||||
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
|
||||||
|
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
|
||||||
|
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
|
||||||
|
FILES OR SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of a copyright holder shall
|
||||||
|
not be used in advertising or otherwise to promote the sale, use or other
|
||||||
|
dealings in these Data Files or Software without prior written
|
||||||
|
authorization of the copyright holder.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Apache License 2.0 (full text)
|
||||||
|
|
||||||
|
```
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
```
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# Office Tools
|
||||||
|
|
||||||
|
Office Tools is a local-first browser application for opening and inspecting
|
||||||
|
office documents without sending them to a server. The initial release focuses
|
||||||
|
on safe, useful viewing of documents, spreadsheets and presentations in both
|
||||||
|
Office Open XML and OpenDocument packages.
|
||||||
|
|
||||||
|
The application is part of the
|
||||||
|
[add·ideas Toolbox](https://git.add-ideas.de/lotobo/toolbox-portal), but remains
|
||||||
|
fully usable as a standalone static site at any URL depth.
|
||||||
|
|
||||||
|
## Initial format scope
|
||||||
|
|
||||||
|
| Kind | Office Open XML | OpenDocument | Legacy binary |
|
||||||
|
| ------------- | --------------- | ------------ | ------------------------------------- |
|
||||||
|
| Documents | `.docx` | `.odt` | `.doc` is a later compatibility track |
|
||||||
|
| Spreadsheets | `.xlsx` | `.ods` | `.xls` is a later compatibility track |
|
||||||
|
| Presentations | `.pptx` | `.odp` | `.ppt` is a later compatibility track |
|
||||||
|
|
||||||
|
The viewer is deliberately read-only. It aims to preserve readable content,
|
||||||
|
structure and useful styling while clearly reporting features it cannot render.
|
||||||
|
It does not claim pixel-perfect fidelity with Microsoft Office or LibreOffice.
|
||||||
|
Macros, scripts, external resources and embedded active content are never run.
|
||||||
|
|
||||||
|
Office Open XML files use local Rust/WebAssembly parsers and canvas renderers.
|
||||||
|
OpenDocument files use the project's bounded ZIP/XML reader and semantic React
|
||||||
|
views. Both paths run locally, keep the interface responsive, support search and
|
||||||
|
navigation, and accept source files up to 100 MiB.
|
||||||
|
|
||||||
|
See [docs/FORMAT-SUPPORT.md](docs/FORMAT-SUPPORT.md) for the feature matrix and
|
||||||
|
known limits.
|
||||||
|
|
||||||
|
## Privacy and security
|
||||||
|
|
||||||
|
- File bytes are read locally and are never uploaded.
|
||||||
|
- There is no telemetry, analytics or CDN runtime dependency.
|
||||||
|
- Imported markup is converted to application-owned React output; it is not
|
||||||
|
inserted as trusted HTML.
|
||||||
|
- Document links remain inert in this release, and no macros, scripts or
|
||||||
|
embedded active objects are executed.
|
||||||
|
- Parsing uses explicit file, package and rendering limits. A malformed file
|
||||||
|
fails as data rather than taking over the application.
|
||||||
|
|
||||||
|
See [docs/PRIVACY-SECURITY.md](docs/PRIVACY-SECURITY.md) for the threat model.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Requirements: Node.js 22 or newer and npm 11 or newer. The committed `.npmrc`
|
||||||
|
points the `@add-ideas` scope at the ADD Ideas package registry; credentials stay
|
||||||
|
in the caller's npm configuration.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm ci
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The complete local verification gate is:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run check
|
||||||
|
npm run test:browser
|
||||||
|
```
|
||||||
|
|
||||||
|
`vite.config.ts` uses `base: './'`. All application URLs, WASM and worker assets
|
||||||
|
must remain relative so a production build works at `/apps/office/`, in a deeper
|
||||||
|
test path, or standalone.
|
||||||
|
|
||||||
|
## Release artifact
|
||||||
|
|
||||||
|
Create the deterministic application ZIP and checksum with:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run release:artifact
|
||||||
|
```
|
||||||
|
|
||||||
|
The result is written to:
|
||||||
|
|
||||||
|
```text
|
||||||
|
release/office-tools-0.1.0.zip
|
||||||
|
release/office-tools-0.1.0.zip.sha256
|
||||||
|
```
|
||||||
|
|
||||||
|
The archive contains `toolbox-app.json`, built assets, the full GPL licence,
|
||||||
|
third-party notices, a generated runtime licence inventory, documentation and
|
||||||
|
`SOURCE.md`. File order, timestamps and modes are normalized for reproducible
|
||||||
|
output.
|
||||||
|
|
||||||
|
## Toolbox identity
|
||||||
|
|
||||||
|
- Manifest id: `de.add-ideas.office-tools`
|
||||||
|
- Portal target: `office`
|
||||||
|
- Source: <https://git.add-ideas.de/lotobo/office-tools>
|
||||||
|
- Licence: `GPL-3.0-or-later`
|
||||||
|
|
||||||
|
The application uses `@add-ideas/toolbox-shell-react` 0.2.3 and validates its
|
||||||
|
production tree with `@add-ideas/toolbox-testkit`.
|
||||||
|
|
||||||
|
## Licence
|
||||||
|
|
||||||
|
Office Tools is free software licensed under GPL-3.0-or-later. See
|
||||||
|
[LICENSE](LICENSE). Bundled dependencies retain their own licences; see
|
||||||
|
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and [LICENSES](LICENSES/README.md).
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
# Security policy
|
||||||
|
|
||||||
|
Office files are untrusted structured packages. Reports about package traversal,
|
||||||
|
resource exhaustion, unsafe markup, external-resource loading, active-content
|
||||||
|
execution or privacy leakage are particularly welcome.
|
||||||
|
|
||||||
|
## Reporting
|
||||||
|
|
||||||
|
Please report a vulnerability privately to the repository owner through the
|
||||||
|
private contact mechanism on <https://git.add-ideas.de/lotobo/office-tools>.
|
||||||
|
Include the affected version, browser, a minimal reproducer when safe, and the
|
||||||
|
expected security boundary. Do not attach confidential source documents; reduce
|
||||||
|
them to synthetic fixtures first.
|
||||||
|
|
||||||
|
## Supported versions
|
||||||
|
|
||||||
|
Only the latest tagged release receives security fixes before version 1.0.
|
||||||
|
|
||||||
|
## Security boundary
|
||||||
|
|
||||||
|
Office Tools promises local processing and no intentional telemetry or upload.
|
||||||
|
It does not promise that every malformed package can be recovered or that every
|
||||||
|
browser is immune to memory pressure. The implementation must:
|
||||||
|
|
||||||
|
- reject traversal, absolute and ambiguous package paths;
|
||||||
|
- bound compressed size, expanded size, entry count, XML depth and rendered
|
||||||
|
output;
|
||||||
|
- render parsed data through application-owned components rather than trusting
|
||||||
|
imported HTML;
|
||||||
|
- never execute macros, scripts, OLE objects or embedded executables;
|
||||||
|
- avoid automatic network access for document relationships and links; and
|
||||||
|
- release object URLs, workers and large buffers when a document closes.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Corresponding source
|
||||||
|
|
||||||
|
The corresponding source for Office Tools 0.1.0 is available at:
|
||||||
|
|
||||||
|
https://git.add-ideas.de/lotobo/office-tools/src/tag/v0.1.0
|
||||||
|
|
||||||
|
Build that tag with Node.js 22 and the exact `package-lock.json`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm ci
|
||||||
|
npm run release:artifact
|
||||||
|
```
|
||||||
|
|
||||||
|
No generated bundle is the preferred source form. No runtime code or document
|
||||||
|
content is loaded from a CDN. The production archive contains this source
|
||||||
|
identity, the licence, dependency inventory and third-party notices beside the
|
||||||
|
executable application.
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Third-party notices
|
||||||
|
|
||||||
|
Office Tools is licensed under GPL-3.0-or-later. It incorporates separately
|
||||||
|
licensed runtime libraries. Their copyright and licence terms remain with their
|
||||||
|
respective authors.
|
||||||
|
|
||||||
|
## add·ideas Toolbox packages
|
||||||
|
|
||||||
|
`@add-ideas/toolbox-contract` and `@add-ideas/toolbox-shell-react` 0.2.3 are
|
||||||
|
licensed under Apache-2.0.
|
||||||
|
|
||||||
|
## Office Open XML viewer
|
||||||
|
|
||||||
|
`@silurus/ooxml` 0.84.1 is MIT-licensed. Office Tools uses its browser-local
|
||||||
|
Rust/WebAssembly parsers and Canvas renderer for DOCX, XLSX and PPTX viewing.
|
||||||
|
The reviewed upstream licence is reproduced in
|
||||||
|
`LICENSES/silurus-ooxml-MIT.txt`; its notices for bundled Rust crates, Unicode
|
||||||
|
data and optional packaged assets are reproduced in
|
||||||
|
`LICENSES/silurus-ooxml-THIRD_PARTY_NOTICES.md`.
|
||||||
|
|
||||||
|
`@xmldom/xmldom` 0.9.12 and `fflate` 0.8.3 are MIT-licensed. They support the
|
||||||
|
project-owned bounded OpenDocument reader. Their exact package-local licence
|
||||||
|
texts, and those of all other runtime packages, are generated into
|
||||||
|
`LICENSES/npm-runtime-licenses.txt` from the committed lockfile during every
|
||||||
|
production build.
|
||||||
|
|
||||||
|
Development-only tooling is not included in the browser application. Test
|
||||||
|
fixtures and the Office Tools icon are project-authored unless a fixture states
|
||||||
|
otherwise.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Accessibility
|
||||||
|
|
||||||
|
Office Tools uses semantic controls, visible focus, keyboard-operable file
|
||||||
|
selection and the shared Toolbox light/dark/system preference. The main content
|
||||||
|
width is `min(100%, 90rem)` and layouts collapse without horizontal page
|
||||||
|
overflow on narrow screens.
|
||||||
|
|
||||||
|
Viewer adapters should preserve meaningful headings, paragraphs, lists and table
|
||||||
|
semantics where the source exposes them. Spreadsheet grids need labelled row and
|
||||||
|
column headers plus a non-visual cell description. Presentation navigation needs
|
||||||
|
an announced slide position and a linear text alternative for each slide.
|
||||||
|
|
||||||
|
Colour alone must not communicate selection, errors or diagnostics. Animations
|
||||||
|
respect `prefers-reduced-motion`. Imported images use source alternative text
|
||||||
|
when available and an explicit fallback when it is absent.
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Architecture
|
||||||
|
|
||||||
|
Office Tools is a static React application with four deliberately separated
|
||||||
|
layers:
|
||||||
|
|
||||||
|
1. The Toolbox shell owns navigation, application identity, theme preferences,
|
||||||
|
help and source links.
|
||||||
|
2. The ingestion boundary checks extension and source size; each parser then
|
||||||
|
validates package identity from its contents and enforces resource limits.
|
||||||
|
3. Format adapters convert office packages into one application-owned,
|
||||||
|
read-only document model.
|
||||||
|
4. Viewer components render that model as document pages, spreadsheet sheets or
|
||||||
|
presentation slides without trusting imported markup.
|
||||||
|
|
||||||
|
The original file is immutable. Opening a new file cancels obsolete work and
|
||||||
|
releases prior buffers and object URLs. Expensive parsing belongs in a module
|
||||||
|
worker so the shell stays responsive and cancellation has a clear boundary.
|
||||||
|
|
||||||
|
Office Open XML input uses the pinned `@silurus/ooxml` Rust/WebAssembly parser
|
||||||
|
and Canvas renderer. OpenDocument input uses project-owned TypeScript adapters
|
||||||
|
over `fflate` and `@xmldom/xmldom`; it is not routed through an online converter.
|
||||||
|
The adapters share detection, size-policy and diagnostics contracts while
|
||||||
|
retaining their intentionally different rendering paths.
|
||||||
|
|
||||||
|
The OpenDocument module worker verifies central and local ZIP declarations,
|
||||||
|
normalized paths, CRC and expansion limits before namespace-aware XML parsing.
|
||||||
|
It rejects DTDs, entities, external resources and active XML, and returns only a
|
||||||
|
typed, serializable model plus transferable packaged image buffers.
|
||||||
|
|
||||||
|
## Deployment contract
|
||||||
|
|
||||||
|
Vite emits relative URLs (`base: './'`). `toolbox-app.json` sits beside
|
||||||
|
`index.html`, and the application works with or without a same-origin Toolbox
|
||||||
|
catalogue. `toolbox-check dist` verifies manifest identity, files and nested-path
|
||||||
|
operation. The service worker handles requests only inside its own scope.
|
||||||
|
|
||||||
|
## Rendering contract
|
||||||
|
|
||||||
|
The OpenDocument model records source kind, ordered blocks/sheets/slides, text
|
||||||
|
runs, whitelisted style data, tables, local images, notes and diagnostics. ODS
|
||||||
|
keeps source repeats compressed, trims office-suite full-grid tails and renders
|
||||||
|
at most 200 rows per page and 256 columns. Adapters emit warnings for omitted
|
||||||
|
embedded objects and other approximations. Source markup is never inserted as
|
||||||
|
HTML, formulas are never evaluated, and document URLs are never fetched.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Format support
|
||||||
|
|
||||||
|
Office Tools 0.1.0 targets read-only browser viewing, not editing or
|
||||||
|
pixel-identical reproduction.
|
||||||
|
|
||||||
|
| Family | Extensions | 0.1 viewing coverage |
|
||||||
|
| ---------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Office Open XML document | `.docx` | Paginated sections, text, lists, tables, images, shapes, charts, headers/footers, comments, selection and find |
|
||||||
|
| Office Open XML spreadsheet | `.xlsx` | Sheets, cached values/formulas, styles, merges, frozen panes, images, charts, comments, navigation and find |
|
||||||
|
| Office Open XML presentation | `.pptx` | Slides/masters, text, shapes, images, tables, charts, notes, selection, navigation and find |
|
||||||
|
| OpenDocument text | `.odt` | Semantic headings, paragraphs/runs, lists, tables, packaged images, metadata and foot/endnotes |
|
||||||
|
| OpenDocument spreadsheet | `.ods` | Sheets, typed/cached values, formulas, repeats, merges, annotations, basic safe styling and paged rows |
|
||||||
|
| OpenDocument presentation | `.odp` | Slide order, positioned text/shapes, groups, tables, packaged images, notes and basic safe styling |
|
||||||
|
|
||||||
|
Legacy compound-binary `.doc`, `.xls` and `.ppt` formats are explicitly outside
|
||||||
|
the first package-reader slice. They require a distinct, bounded parser and must
|
||||||
|
not be misidentified as their XML successors.
|
||||||
|
|
||||||
|
## Never executed
|
||||||
|
|
||||||
|
Macros, VBA projects, embedded executables, OLE objects, scripts, remote
|
||||||
|
templates and automatic external relationships remain inert. Unsupported
|
||||||
|
content is reported in diagnostics where it can be identified.
|
||||||
|
|
||||||
|
## Known boundaries
|
||||||
|
|
||||||
|
- Spreadsheet formulas display their saved cached result; Office Tools does not
|
||||||
|
recalculate them or refresh pivots and external data.
|
||||||
|
- Presentation animations and transitions are not reproduced. Embedded media
|
||||||
|
playback is disabled in the first release.
|
||||||
|
- OLE, ActiveX, VBA and OpenDocument embedded objects remain inert. The ODF
|
||||||
|
semantic view reports and omits embedded objects such as chart subdocuments.
|
||||||
|
- OpenDocument slide masters/layouts are identified but not fully reproduced;
|
||||||
|
uncommon drawing transforms and office-suite-specific layout can be
|
||||||
|
approximated.
|
||||||
|
- Fonts are substituted locally. Remote fonts, templates, images and links are
|
||||||
|
never fetched.
|
||||||
|
- ODS renders 200 rows at a time and up to 256 columns. Empty full-grid tails
|
||||||
|
emitted by office suites are deliberately trimmed.
|
||||||
|
|
||||||
|
## Safety limits
|
||||||
|
|
||||||
|
The source-file limit is 100 MiB. OOXML and ODF packages also enforce expanded
|
||||||
|
entry, total expanded byte, entry-count and image limits. ODF additionally
|
||||||
|
bounds compression ratio, XML depth/nodes, text, repeats, cells and assets.
|
||||||
|
Files that exceed a boundary fail with a visible diagnostic instead of being
|
||||||
|
partially trusted.
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Privacy and security model
|
||||||
|
|
||||||
|
## Local processing
|
||||||
|
|
||||||
|
Selecting a file grants the current browser tab access to that file's bytes.
|
||||||
|
Office Tools does not upload them, send telemetry or fetch a remote conversion
|
||||||
|
service. Data remains in memory unless a future feature explicitly offers a
|
||||||
|
user-triggered local download or browser-local save.
|
||||||
|
|
||||||
|
## Threat model
|
||||||
|
|
||||||
|
The input may be hostile: a ZIP bomb, path traversal, deeply nested XML,
|
||||||
|
oversized text, misleading MIME information, malformed relationships or active
|
||||||
|
content disguised as media. Readers therefore need limits for compressed and
|
||||||
|
expanded bytes, entry count, XML depth, node count, repeated elements, image
|
||||||
|
dimensions and rendered output.
|
||||||
|
|
||||||
|
Package paths are normalized as OPC/ODF paths and may never escape the logical
|
||||||
|
package root. External relationships and document links are not fetched or made
|
||||||
|
active. Imported HTML is never trusted. Macros, scripts, OLE objects and
|
||||||
|
embedded executables are never run. OpenDocument embedded objects are retained
|
||||||
|
only as inert package bytes and reported as omitted from the semantic view.
|
||||||
|
|
||||||
|
The ODF reader rejects ambiguous or traversing names, unsupported/encrypted ZIP
|
||||||
|
features, inconsistent headers, overlap, CRC errors, unsafe expansion, DTDs,
|
||||||
|
entities and active XML. It applies byte, entry, ratio, node, depth, repeat,
|
||||||
|
text, cell and image limits inside a disposable worker. OOXML readers likewise
|
||||||
|
run with explicit package/resource limits and external links and Google Fonts
|
||||||
|
disabled.
|
||||||
|
|
||||||
|
## Browser limits
|
||||||
|
|
||||||
|
Local processing is not the same as zero risk: a large document can still cause
|
||||||
|
memory pressure, and rendering depends on the browser's image and font engines.
|
||||||
|
The application should remain cancellable, keep the previous stable UI until a
|
||||||
|
new parse succeeds, and release resources promptly when a file closes.
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import reactHooks from "eslint-plugin-react-hooks";
|
||||||
|
import reactRefresh from "eslint-plugin-react-refresh";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
{
|
||||||
|
ignores: [
|
||||||
|
"dist",
|
||||||
|
"release",
|
||||||
|
"coverage",
|
||||||
|
"test-results",
|
||||||
|
"playwright-report",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||||
|
files: ["**/*.{ts,tsx}"],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2023,
|
||||||
|
globals: { ...globals.browser, ...globals.worker },
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
"react-hooks": reactHooks,
|
||||||
|
"react-refresh": reactRefresh,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...reactHooks.configs.recommended.rules,
|
||||||
|
"react-refresh/only-export-components": [
|
||||||
|
"warn",
|
||||||
|
{ allowConstantExport: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["scripts/**/*.mjs", "playwright.config.ts"],
|
||||||
|
languageOptions: { globals: globals.node },
|
||||||
|
},
|
||||||
|
);
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Open and inspect office documents locally in your browser."
|
||||||
|
/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
|
||||||
|
<link rel="manifest" href="./manifest.webmanifest" />
|
||||||
|
<meta name="theme-color" content="#24465f" />
|
||||||
|
<title>Office Tools</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="./src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Generated
+3995
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"name": "office-tools",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"predev": "npm run manifest:generate",
|
||||||
|
"dev": "vite",
|
||||||
|
"prebuild": "npm run release:prepare && npm run manifest:generate",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"typecheck": "tsc -b --pretty false",
|
||||||
|
"lint": "eslint . --max-warnings=0",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"format:check": "prettier --check .",
|
||||||
|
"test": "vitest run",
|
||||||
|
"test:watch": "vitest",
|
||||||
|
"test:browser": "playwright test",
|
||||||
|
"manifest:generate": "node scripts/generate-toolbox-manifest.mjs",
|
||||||
|
"manifest:check": "node scripts/generate-toolbox-manifest.mjs --check",
|
||||||
|
"release:prepare": "node scripts/prepare-release-files.mjs",
|
||||||
|
"toolbox:check": "toolbox-check dist",
|
||||||
|
"package:release": "node scripts/package-release.mjs",
|
||||||
|
"check": "npm run manifest:check && npm run typecheck && npm run lint && npm run format:check && npm run test && npm run build && npm run toolbox:check",
|
||||||
|
"release:artifact": "npm run check && npm run test:browser && npm run package:release -- --force"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@add-ideas/toolbox-contract": "0.2.3",
|
||||||
|
"@add-ideas/toolbox-shell-react": "0.2.3",
|
||||||
|
"@silurus/ooxml": "0.84.1",
|
||||||
|
"@xmldom/xmldom": "0.9.12",
|
||||||
|
"fflate": "0.8.3",
|
||||||
|
"react": "19.2.8",
|
||||||
|
"react-dom": "19.2.8"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@add-ideas/toolbox-testkit": "0.2.3",
|
||||||
|
"@eslint/js": "10.0.1",
|
||||||
|
"@playwright/test": "1.62.1",
|
||||||
|
"@testing-library/jest-dom": "6.9.1",
|
||||||
|
"@testing-library/react": "16.3.2",
|
||||||
|
"@testing-library/user-event": "14.6.1",
|
||||||
|
"@types/node": "25.9.5",
|
||||||
|
"@types/react": "19.2.17",
|
||||||
|
"@types/react-dom": "19.2.5",
|
||||||
|
"@vitejs/plugin-react": "6.0.3",
|
||||||
|
"eslint": "10.7.0",
|
||||||
|
"eslint-plugin-react-hooks": "7.1.1",
|
||||||
|
"eslint-plugin-react-refresh": "0.5.2",
|
||||||
|
"globals": "17.7.0",
|
||||||
|
"jsdom": "29.1.1",
|
||||||
|
"prettier": "3.9.5",
|
||||||
|
"typescript": "6.0.3",
|
||||||
|
"typescript-eslint": "8.64.0",
|
||||||
|
"vite": "8.2.2",
|
||||||
|
"vitest": "4.1.11"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { defineConfig, devices } from "@playwright/test";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: "./tests/browser",
|
||||||
|
fullyParallel: false,
|
||||||
|
workers: 1,
|
||||||
|
timeout: 120_000,
|
||||||
|
expect: { timeout: 10_000 },
|
||||||
|
reporter: [["list"]],
|
||||||
|
use: {
|
||||||
|
baseURL: "http://127.0.0.1:4173",
|
||||||
|
trace: "retain-on-failure",
|
||||||
|
},
|
||||||
|
webServer: {
|
||||||
|
command: "npm run build && node scripts/serve-test.mjs",
|
||||||
|
url: "http://127.0.0.1:4173/deep/nested/office/",
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
timeout: 180_000,
|
||||||
|
},
|
||||||
|
projects: [
|
||||||
|
{ name: "chromium", use: { ...devices["Desktop Chrome"] } },
|
||||||
|
{ name: "firefox", use: { ...devices["Desktop Firefox"] } },
|
||||||
|
],
|
||||||
|
});
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to Office Tools are documented here. Versions follow
|
||||||
|
Semantic Versioning.
|
||||||
|
|
||||||
|
## 0.1.0 - 2026-08-31
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Initial local-first Office Tools application and Toolbox 0.2.3 integration.
|
||||||
|
- High-fidelity local DOCX/XLSX/PPTX canvas viewing with search, zoom and
|
||||||
|
document-aware navigation.
|
||||||
|
- Project-owned bounded ODT/ODS/ODP package reader and semantic views for text,
|
||||||
|
tables, spreadsheets, slides, images, notes and safe styling.
|
||||||
|
- Package-integrity, traversal, XML, expansion, repeat, cell, text and asset
|
||||||
|
protections with inert external/active content and visible diagnostics.
|
||||||
|
- Responsive light, dark and system-mode shell with accessible file selection.
|
||||||
|
- Relocatable installable build, strict release identity and deterministic ZIP
|
||||||
|
packaging with corresponding-source and licence material.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Contributions are welcome when they preserve the application's local-first,
|
||||||
|
inspection-oriented boundary.
|
||||||
|
|
||||||
|
## Development workflow
|
||||||
|
|
||||||
|
1. Use Node.js 22 or newer.
|
||||||
|
2. Install the locked dependencies with `npm ci`.
|
||||||
|
3. Keep parsing, package traversal and expensive work away from the React render
|
||||||
|
path; use bounded worker operations where appropriate.
|
||||||
|
4. Add focused unit tests and malformed-input cases for every parser change.
|
||||||
|
5. Run `npm run check` and `npm run test:browser` before proposing a change.
|
||||||
|
|
||||||
|
Do not add telemetry, remote document conversion, runtime CDN dependencies or
|
||||||
|
automatic external-resource fetching. Never execute macros, embedded scripts or
|
||||||
|
active document content. New dependencies need a licence and maintenance review
|
||||||
|
and must be reflected in `THIRD_PARTY_NOTICES.md` where required.
|
||||||
|
|
||||||
|
Format support must be described conservatively. A partial reader should expose
|
||||||
|
what it preserved, approximated, omitted or rejected rather than claiming Office
|
||||||
|
suite fidelity.
|
||||||
|
|
||||||
|
By contributing, you agree that your contribution is licensed under
|
||||||
|
GPL-3.0-or-later.
|
||||||
+674
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Runtime licence inventory
|
||||||
|
|
||||||
|
`npm run release:prepare` generates `npm-runtime-licenses.txt` from the exact
|
||||||
|
runtime packages in `package-lock.json`. The generated inventory is included in
|
||||||
|
the static build and release ZIP together with the project licence and
|
||||||
|
third-party notices.
|
||||||
|
|
||||||
|
The reviewed Silurus OOXML licence and its bundled-code/data notices are also
|
||||||
|
kept as stable files because the npm package contains Rust/WebAssembly and data
|
||||||
|
whose complete provenance is broader than its top-level MIT licence.
|
||||||
|
|
||||||
|
Review dependency licence changes whenever the lockfile changes. Generation is
|
||||||
|
an inventory aid, not a substitute for legal review.
|
||||||
@@ -0,0 +1,552 @@
|
|||||||
|
==============================================================================
|
||||||
|
@add-ideas/toolbox-contract@0.2.3
|
||||||
|
Declared licence: Apache-2.0
|
||||||
|
Installed from: node_modules/@add-ideas/toolbox-contract
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
Copyright 2026 ADD Ideas
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
@add-ideas/toolbox-shell-react@0.2.3
|
||||||
|
Declared licence: Apache-2.0
|
||||||
|
Installed from: node_modules/@add-ideas/toolbox-shell-react
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
Copyright 2026 ADD Ideas
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
@silurus/ooxml@0.84.1
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/@silurus/ooxml
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Yuki Yokotani
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
@xmldom/xmldom@0.9.12
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/@xmldom/xmldom
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
Copyright 2019 - present Christopher J. Brody and other contributors, as listed in: https://github.com/xmldom/xmldom/graphs/contributors
|
||||||
|
Copyright 2012 - 2017 @jindw <jindw@xidea.org> and other contributors, as listed in: https://github.com/jindw/xmldom/graphs/contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
fflate@0.8.3
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/fflate
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Arjun Barrett
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
react@19.2.8
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/react
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
react-dom@19.2.8
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/react-dom
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
scheduler@0.27.0
|
||||||
|
Declared licence: MIT
|
||||||
|
Installed from: node_modules/scheduler
|
||||||
|
==============================================================================
|
||||||
|
--- LICENSE ---
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Yuki Yokotani
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,369 @@
|
|||||||
|
# Third-Party Notices
|
||||||
|
|
||||||
|
`@silurus/ooxml` is MIT-licensed (see [LICENSE](./LICENSE)). It bundles the
|
||||||
|
third-party components listed below, none of which are copyleft. This file
|
||||||
|
is included in the npm tarball so it travels with every install.
|
||||||
|
|
||||||
|
## JavaScript / bundled asset
|
||||||
|
|
||||||
|
### Natural Earth Admin 0 Countries, 1:110m
|
||||||
|
|
||||||
|
The optional Region Map renderer contains a coordinate-quantized derivative of
|
||||||
|
Natural Earth's Admin 0 Countries 1:110m vector dataset. Natural Earth states
|
||||||
|
that all versions of its raster and vector data are in the public domain. The
|
||||||
|
generated source records the exact upstream SHA-256 and fixed feature/vertex
|
||||||
|
bounds. The boundaries are illustrative, show Natural Earth's default de-facto
|
||||||
|
point of view, and do not imply this project's endorsement of any territorial
|
||||||
|
claim.
|
||||||
|
|
||||||
|
- Source: <https://github.com/nvkelso/natural-earth-vector/blob/master/geojson/ne_110m_admin_0_countries.geojson>
|
||||||
|
- Terms: <https://www.naturalearthdata.com/about/terms-of-use/>
|
||||||
|
|
||||||
|
### MathJax + STIX Two Math (`mathjax-stix2.js`)
|
||||||
|
|
||||||
|
The optional equation-rendering engine (`@silurus/ooxml/math`, opt-in —
|
||||||
|
see the [README's "Rendering equations" section](./README.md#rendering-equations))
|
||||||
|
pre-bundles two Apache-2.0 packages into a single ~3 MB asset
|
||||||
|
(`packages/core/assets/mathjax-stix2.js`, built by
|
||||||
|
[`packages/core/build/build-mathjax.mjs`](./packages/core/build/build-mathjax.mjs)).
|
||||||
|
It ships in the npm tarball but is only fetched by a consuming app at
|
||||||
|
runtime if that app imports `@silurus/ooxml/math` **and** the loaded
|
||||||
|
document actually contains an equation.
|
||||||
|
|
||||||
|
- **[MathJax](https://www.mathjax.org/)** (`@mathjax/src`, v4.1.2) —
|
||||||
|
Copyright © MathJax Consortium. Licensed under the
|
||||||
|
[Apache License, Version 2.0](#apache-license-20-full-text).
|
||||||
|
<https://github.com/mathjax/MathJax-src>
|
||||||
|
- **STIX Two Math font, as packaged for MathJax v4**
|
||||||
|
(`@mathjax/mathjax-stix2-font`, v4.1.2) — Copyright © MathJax Consortium.
|
||||||
|
The npm package declares `"license": "Apache-2.0"` in its `package.json`
|
||||||
|
(verified by reading `node_modules/@mathjax/mathjax-stix2-font/package.json`
|
||||||
|
directly; the package does not bundle its own `LICENSE` file, so this is
|
||||||
|
the authoritative declaration). Licensed under the
|
||||||
|
[Apache License, Version 2.0](#apache-license-20-full-text).
|
||||||
|
<https://github.com/mathjax/MathJax-fonts>
|
||||||
|
|
||||||
|
Note: the STIX Two Math font is also separately distributed upstream
|
||||||
|
(<https://github.com/stipub/stixfonts>) under the SIL Open Font License
|
||||||
|
1.1. The build in this repository consumes the Apache-2.0-licensed
|
||||||
|
`@mathjax/mathjax-stix2-font` npm package specifically, not the upstream
|
||||||
|
OFL font files directly, so Apache-2.0 is the governing license for the
|
||||||
|
bytes actually shipped here.
|
||||||
|
|
||||||
|
Neither package includes a Apache-2.0 §4(d) `NOTICE` file (checked in
|
||||||
|
the installed `node_modules` tree), so there is no additional NOTICE
|
||||||
|
content to reproduce beyond the attribution above.
|
||||||
|
|
||||||
|
### Build-time only (not shipped)
|
||||||
|
|
||||||
|
The library also declares `esbuild` (MIT) as a build-time dependency
|
||||||
|
(bundles `mathjax-stix2.js` above) and TypeScript (Apache-2.0) as a
|
||||||
|
dev/type-check dependency. Neither's code is included in the published
|
||||||
|
package — noted here for completeness only.
|
||||||
|
|
||||||
|
## Rust / WebAssembly
|
||||||
|
|
||||||
|
The three parser crates (`docx-parser`, `pptx-parser`, `xlsx-parser`) and
|
||||||
|
their shared `ooxml-common` crate compile to the `*_parser_bg.wasm` binaries
|
||||||
|
shipped in `dist/`. Their `wasm32-unknown-unknown` dependency graph is
|
||||||
|
identical across all three crates (verified with `cargo license
|
||||||
|
--filter-platform wasm32-unknown-unknown`) and consists entirely of
|
||||||
|
permissively-licensed crates — no copyleft (GPL/LGPL/AGPL) dependencies:
|
||||||
|
|
||||||
|
| License | Crates |
|
||||||
|
|---|---|
|
||||||
|
| MIT OR Apache-2.0 | bumpalo, cfg-if, console_error_panic_hook, crc32fast, displaydoc, equivalent, flate2, hashbrown, indexmap, itoa, log, once_cell, proc-macro2, quote, roxmltree, rustversion, serde, serde_core, serde_derive, serde_json, syn, thiserror, thiserror-impl, wasm-bindgen, wasm-bindgen-macro, wasm-bindgen-macro-support, wasm-bindgen-shared |
|
||||||
|
| (Apache-2.0 OR MIT) AND Unicode-3.0 | unicode-ident |
|
||||||
|
| 0BSD OR Apache-2.0 OR MIT | adler2 |
|
||||||
|
| Apache-2.0 | zopfli |
|
||||||
|
| Apache-2.0 OR MIT OR Zlib | miniz_oxide |
|
||||||
|
| MIT | simd-adler32, zip, zmij |
|
||||||
|
| MIT OR Unlicense | memchr |
|
||||||
|
|
||||||
|
Full license texts for each crate are available from
|
||||||
|
[crates.io](https://crates.io/) or the crate's own repository; SPDX
|
||||||
|
identifiers above match each crate's `Cargo.toml` `license` field. This
|
||||||
|
list was generated with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install cargo-license
|
||||||
|
cargo license --manifest-path packages/pptx/parser/Cargo.toml \
|
||||||
|
--avoid-dev-deps --filter-platform wasm32-unknown-unknown
|
||||||
|
# docx-parser / xlsx-parser produce an identical dependency set
|
||||||
|
```
|
||||||
|
|
||||||
|
### MCP server (`ooxml-mcp-server`, separate distribution)
|
||||||
|
|
||||||
|
`packages/mcp-server` is not part of the `@silurus/ooxml` npm package — it
|
||||||
|
is a standalone binary distributed independently (see the repository's MCP
|
||||||
|
server documentation). Its dependency graph is a superset of the table
|
||||||
|
above (adds `tokio`, `rmcp`, `anyhow`, `schemars`, `tracing`, and their
|
||||||
|
transitive deps for the async runtime and MCP protocol implementation) and
|
||||||
|
remains entirely MIT / Apache-2.0, with no copyleft licenses:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo license --manifest-path packages/mcp-server/Cargo.toml --avoid-dev-deps
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unicode Character Database data
|
||||||
|
|
||||||
|
The line-breaking, vertical-orientation and Arabic-shaping logic is driven
|
||||||
|
by tables generated from the Unicode Character Database (UCD), © Unicode,
|
||||||
|
Inc., licensed under the [Unicode License v3](#unicode-license-v3-full-text)
|
||||||
|
(SPDX: `Unicode-3.0`), which expressly permits copying, modification and
|
||||||
|
redistribution of the data files with this notice.
|
||||||
|
|
||||||
|
Checked into this repository (generator inputs, each retaining its original
|
||||||
|
Unicode copyright header; not part of the npm tarball):
|
||||||
|
|
||||||
|
- `packages/core/scripts/VerticalOrientation.txt` (UAX #50
|
||||||
|
Vertical_Orientation, UCD 17.0.0)
|
||||||
|
- `packages/docx/scripts/ArabicShaping.txt` (Joining_Type / Joining_Group,
|
||||||
|
UCD 17.0.0)
|
||||||
|
- `packages/docx/scripts/DerivedJoiningType.txt` (UCD 17.0.0)
|
||||||
|
|
||||||
|
Shipped in `dist/` as UCD-derived data compiled from the above and from
|
||||||
|
`LineBreak.txt` / `DerivedGeneralCategory.txt` / `EastAsianWidth.txt`
|
||||||
|
(fetched at generation time, not checked in): the `*.generated.ts` tables
|
||||||
|
under `packages/core/src/text/` and `packages/docx/src/` (line-break
|
||||||
|
classes, East Asian width, vertical orientation, bidi character data,
|
||||||
|
Arabic joining classes).
|
||||||
|
|
||||||
|
The `unicode-ident` Rust crate listed above also carries `Unicode-3.0` in
|
||||||
|
its SPDX expression for the same reason (embedded UCD-derived tables).
|
||||||
|
|
||||||
|
## License texts
|
||||||
|
|
||||||
|
- **MIT** — see [LICENSE](./LICENSE) (this repository's own license; the
|
||||||
|
MIT-licensed dependencies above use the same standard text with their own
|
||||||
|
copyright holder).
|
||||||
|
- **Unicode License v3** — canonical text at
|
||||||
|
<https://www.unicode.org/license.txt>, reproduced below.
|
||||||
|
- **Apache License, Version 2.0** — full text at
|
||||||
|
<https://www.apache.org/licenses/LICENSE-2.0>, reproduced below for
|
||||||
|
convenience.
|
||||||
|
|
||||||
|
### Unicode License v3 (full text)
|
||||||
|
|
||||||
|
```
|
||||||
|
UNICODE LICENSE V3
|
||||||
|
|
||||||
|
COPYRIGHT AND PERMISSION NOTICE
|
||||||
|
|
||||||
|
Copyright © 1991-2026 Unicode, Inc.
|
||||||
|
|
||||||
|
NOTICE TO USER: Carefully read the following legal agreement. BY
|
||||||
|
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
|
||||||
|
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
|
||||||
|
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
|
||||||
|
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of data files and any associated documentation (the "Data Files") or
|
||||||
|
software and any associated documentation (the "Software") to deal in the
|
||||||
|
Data Files or Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
||||||
|
copies of the Data Files or Software, and to permit persons to whom the
|
||||||
|
Data Files or Software are furnished to do so, provided that either (a)
|
||||||
|
this copyright and permission notice appear with all copies of the Data
|
||||||
|
Files or Software, or (b) this copyright and permission notice appear in
|
||||||
|
associated Documentation.
|
||||||
|
|
||||||
|
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
THIRD PARTY RIGHTS.
|
||||||
|
|
||||||
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
|
||||||
|
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
|
||||||
|
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
|
||||||
|
FILES OR SOFTWARE.
|
||||||
|
|
||||||
|
Except as contained in this notice, the name of a copyright holder shall
|
||||||
|
not be used in advertising or otherwise to promote the sale, use or other
|
||||||
|
dealings in these Data Files or Software without prior written
|
||||||
|
authorization of the copyright holder.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Apache License 2.0 (full text)
|
||||||
|
|
||||||
|
```
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
```
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# Office Tools
|
||||||
|
|
||||||
|
Office Tools is a local-first browser application for opening and inspecting
|
||||||
|
office documents without sending them to a server. The initial release focuses
|
||||||
|
on safe, useful viewing of documents, spreadsheets and presentations in both
|
||||||
|
Office Open XML and OpenDocument packages.
|
||||||
|
|
||||||
|
The application is part of the
|
||||||
|
[add·ideas Toolbox](https://git.add-ideas.de/lotobo/toolbox-portal), but remains
|
||||||
|
fully usable as a standalone static site at any URL depth.
|
||||||
|
|
||||||
|
## Initial format scope
|
||||||
|
|
||||||
|
| Kind | Office Open XML | OpenDocument | Legacy binary |
|
||||||
|
| ------------- | --------------- | ------------ | ------------------------------------- |
|
||||||
|
| Documents | `.docx` | `.odt` | `.doc` is a later compatibility track |
|
||||||
|
| Spreadsheets | `.xlsx` | `.ods` | `.xls` is a later compatibility track |
|
||||||
|
| Presentations | `.pptx` | `.odp` | `.ppt` is a later compatibility track |
|
||||||
|
|
||||||
|
The viewer is deliberately read-only. It aims to preserve readable content,
|
||||||
|
structure and useful styling while clearly reporting features it cannot render.
|
||||||
|
It does not claim pixel-perfect fidelity with Microsoft Office or LibreOffice.
|
||||||
|
Macros, scripts, external resources and embedded active content are never run.
|
||||||
|
|
||||||
|
Office Open XML files use local Rust/WebAssembly parsers and canvas renderers.
|
||||||
|
OpenDocument files use the project's bounded ZIP/XML reader and semantic React
|
||||||
|
views. Both paths run locally, keep the interface responsive, support search and
|
||||||
|
navigation, and accept source files up to 100 MiB.
|
||||||
|
|
||||||
|
See [docs/FORMAT-SUPPORT.md](docs/FORMAT-SUPPORT.md) for the feature matrix and
|
||||||
|
known limits.
|
||||||
|
|
||||||
|
## Privacy and security
|
||||||
|
|
||||||
|
- File bytes are read locally and are never uploaded.
|
||||||
|
- There is no telemetry, analytics or CDN runtime dependency.
|
||||||
|
- Imported markup is converted to application-owned React output; it is not
|
||||||
|
inserted as trusted HTML.
|
||||||
|
- Document links remain inert in this release, and no macros, scripts or
|
||||||
|
embedded active objects are executed.
|
||||||
|
- Parsing uses explicit file, package and rendering limits. A malformed file
|
||||||
|
fails as data rather than taking over the application.
|
||||||
|
|
||||||
|
See [docs/PRIVACY-SECURITY.md](docs/PRIVACY-SECURITY.md) for the threat model.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Requirements: Node.js 22 or newer and npm 11 or newer. The committed `.npmrc`
|
||||||
|
points the `@add-ideas` scope at the ADD Ideas package registry; credentials stay
|
||||||
|
in the caller's npm configuration.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm ci
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The complete local verification gate is:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run check
|
||||||
|
npm run test:browser
|
||||||
|
```
|
||||||
|
|
||||||
|
`vite.config.ts` uses `base: './'`. All application URLs, WASM and worker assets
|
||||||
|
must remain relative so a production build works at `/apps/office/`, in a deeper
|
||||||
|
test path, or standalone.
|
||||||
|
|
||||||
|
## Release artifact
|
||||||
|
|
||||||
|
Create the deterministic application ZIP and checksum with:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run release:artifact
|
||||||
|
```
|
||||||
|
|
||||||
|
The result is written to:
|
||||||
|
|
||||||
|
```text
|
||||||
|
release/office-tools-0.1.0.zip
|
||||||
|
release/office-tools-0.1.0.zip.sha256
|
||||||
|
```
|
||||||
|
|
||||||
|
The archive contains `toolbox-app.json`, built assets, the full GPL licence,
|
||||||
|
third-party notices, a generated runtime licence inventory, documentation and
|
||||||
|
`SOURCE.md`. File order, timestamps and modes are normalized for reproducible
|
||||||
|
output.
|
||||||
|
|
||||||
|
## Toolbox identity
|
||||||
|
|
||||||
|
- Manifest id: `de.add-ideas.office-tools`
|
||||||
|
- Portal target: `office`
|
||||||
|
- Source: <https://git.add-ideas.de/lotobo/office-tools>
|
||||||
|
- Licence: `GPL-3.0-or-later`
|
||||||
|
|
||||||
|
The application uses `@add-ideas/toolbox-shell-react` 0.2.3 and validates its
|
||||||
|
production tree with `@add-ideas/toolbox-testkit`.
|
||||||
|
|
||||||
|
## Licence
|
||||||
|
|
||||||
|
Office Tools is free software licensed under GPL-3.0-or-later. See
|
||||||
|
[LICENSE](LICENSE). Bundled dependencies retain their own licences; see
|
||||||
|
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and [LICENSES](LICENSES/README.md).
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Security policy
|
||||||
|
|
||||||
|
Office files are untrusted structured packages. Reports about package traversal,
|
||||||
|
resource exhaustion, unsafe markup, external-resource loading, active-content
|
||||||
|
execution or privacy leakage are particularly welcome.
|
||||||
|
|
||||||
|
## Reporting
|
||||||
|
|
||||||
|
Please report a vulnerability privately to the repository owner through the
|
||||||
|
private contact mechanism on <https://git.add-ideas.de/lotobo/office-tools>.
|
||||||
|
Include the affected version, browser, a minimal reproducer when safe, and the
|
||||||
|
expected security boundary. Do not attach confidential source documents; reduce
|
||||||
|
them to synthetic fixtures first.
|
||||||
|
|
||||||
|
## Supported versions
|
||||||
|
|
||||||
|
Only the latest tagged release receives security fixes before version 1.0.
|
||||||
|
|
||||||
|
## Security boundary
|
||||||
|
|
||||||
|
Office Tools promises local processing and no intentional telemetry or upload.
|
||||||
|
It does not promise that every malformed package can be recovered or that every
|
||||||
|
browser is immune to memory pressure. The implementation must:
|
||||||
|
|
||||||
|
- reject traversal, absolute and ambiguous package paths;
|
||||||
|
- bound compressed size, expanded size, entry count, XML depth and rendered
|
||||||
|
output;
|
||||||
|
- render parsed data through application-owned components rather than trusting
|
||||||
|
imported HTML;
|
||||||
|
- never execute macros, scripts, OLE objects or embedded executables;
|
||||||
|
- avoid automatic network access for document relationships and links; and
|
||||||
|
- release object URLs, workers and large buffers when a document closes.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Corresponding source
|
||||||
|
|
||||||
|
The corresponding source for Office Tools 0.1.0 is available at:
|
||||||
|
|
||||||
|
https://git.add-ideas.de/lotobo/office-tools/src/tag/v0.1.0
|
||||||
|
|
||||||
|
Build that tag with Node.js 22 and the exact `package-lock.json`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm ci
|
||||||
|
npm run release:artifact
|
||||||
|
```
|
||||||
|
|
||||||
|
No generated bundle is the preferred source form. No runtime code or document
|
||||||
|
content is loaded from a CDN. The production archive contains this source
|
||||||
|
identity, the licence, dependency inventory and third-party notices beside the
|
||||||
|
executable application.
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Third-party notices
|
||||||
|
|
||||||
|
Office Tools is licensed under GPL-3.0-or-later. It incorporates separately
|
||||||
|
licensed runtime libraries. Their copyright and licence terms remain with their
|
||||||
|
respective authors.
|
||||||
|
|
||||||
|
## add·ideas Toolbox packages
|
||||||
|
|
||||||
|
`@add-ideas/toolbox-contract` and `@add-ideas/toolbox-shell-react` 0.2.3 are
|
||||||
|
licensed under Apache-2.0.
|
||||||
|
|
||||||
|
## Office Open XML viewer
|
||||||
|
|
||||||
|
`@silurus/ooxml` 0.84.1 is MIT-licensed. Office Tools uses its browser-local
|
||||||
|
Rust/WebAssembly parsers and Canvas renderer for DOCX, XLSX and PPTX viewing.
|
||||||
|
The reviewed upstream licence is reproduced in
|
||||||
|
`LICENSES/silurus-ooxml-MIT.txt`; its notices for bundled Rust crates, Unicode
|
||||||
|
data and optional packaged assets are reproduced in
|
||||||
|
`LICENSES/silurus-ooxml-THIRD_PARTY_NOTICES.md`.
|
||||||
|
|
||||||
|
`@xmldom/xmldom` 0.9.12 and `fflate` 0.8.3 are MIT-licensed. They support the
|
||||||
|
project-owned bounded OpenDocument reader. Their exact package-local licence
|
||||||
|
texts, and those of all other runtime packages, are generated into
|
||||||
|
`LICENSES/npm-runtime-licenses.txt` from the committed lockfile during every
|
||||||
|
production build.
|
||||||
|
|
||||||
|
Development-only tooling is not included in the browser application. Test
|
||||||
|
fixtures and the Office Tools icon are project-authored unless a fixture states
|
||||||
|
otherwise.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Accessibility
|
||||||
|
|
||||||
|
Office Tools uses semantic controls, visible focus, keyboard-operable file
|
||||||
|
selection and the shared Toolbox light/dark/system preference. The main content
|
||||||
|
width is `min(100%, 90rem)` and layouts collapse without horizontal page
|
||||||
|
overflow on narrow screens.
|
||||||
|
|
||||||
|
Viewer adapters should preserve meaningful headings, paragraphs, lists and table
|
||||||
|
semantics where the source exposes them. Spreadsheet grids need labelled row and
|
||||||
|
column headers plus a non-visual cell description. Presentation navigation needs
|
||||||
|
an announced slide position and a linear text alternative for each slide.
|
||||||
|
|
||||||
|
Colour alone must not communicate selection, errors or diagnostics. Animations
|
||||||
|
respect `prefers-reduced-motion`. Imported images use source alternative text
|
||||||
|
when available and an explicit fallback when it is absent.
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Architecture
|
||||||
|
|
||||||
|
Office Tools is a static React application with four deliberately separated
|
||||||
|
layers:
|
||||||
|
|
||||||
|
1. The Toolbox shell owns navigation, application identity, theme preferences,
|
||||||
|
help and source links.
|
||||||
|
2. The ingestion boundary checks extension and source size; each parser then
|
||||||
|
validates package identity from its contents and enforces resource limits.
|
||||||
|
3. Format adapters convert office packages into one application-owned,
|
||||||
|
read-only document model.
|
||||||
|
4. Viewer components render that model as document pages, spreadsheet sheets or
|
||||||
|
presentation slides without trusting imported markup.
|
||||||
|
|
||||||
|
The original file is immutable. Opening a new file cancels obsolete work and
|
||||||
|
releases prior buffers and object URLs. Expensive parsing belongs in a module
|
||||||
|
worker so the shell stays responsive and cancellation has a clear boundary.
|
||||||
|
|
||||||
|
Office Open XML input uses the pinned `@silurus/ooxml` Rust/WebAssembly parser
|
||||||
|
and Canvas renderer. OpenDocument input uses project-owned TypeScript adapters
|
||||||
|
over `fflate` and `@xmldom/xmldom`; it is not routed through an online converter.
|
||||||
|
The adapters share detection, size-policy and diagnostics contracts while
|
||||||
|
retaining their intentionally different rendering paths.
|
||||||
|
|
||||||
|
The OpenDocument module worker verifies central and local ZIP declarations,
|
||||||
|
normalized paths, CRC and expansion limits before namespace-aware XML parsing.
|
||||||
|
It rejects DTDs, entities, external resources and active XML, and returns only a
|
||||||
|
typed, serializable model plus transferable packaged image buffers.
|
||||||
|
|
||||||
|
## Deployment contract
|
||||||
|
|
||||||
|
Vite emits relative URLs (`base: './'`). `toolbox-app.json` sits beside
|
||||||
|
`index.html`, and the application works with or without a same-origin Toolbox
|
||||||
|
catalogue. `toolbox-check dist` verifies manifest identity, files and nested-path
|
||||||
|
operation. The service worker handles requests only inside its own scope.
|
||||||
|
|
||||||
|
## Rendering contract
|
||||||
|
|
||||||
|
The OpenDocument model records source kind, ordered blocks/sheets/slides, text
|
||||||
|
runs, whitelisted style data, tables, local images, notes and diagnostics. ODS
|
||||||
|
keeps source repeats compressed, trims office-suite full-grid tails and renders
|
||||||
|
at most 200 rows per page and 256 columns. Adapters emit warnings for omitted
|
||||||
|
embedded objects and other approximations. Source markup is never inserted as
|
||||||
|
HTML, formulas are never evaluated, and document URLs are never fetched.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Format support
|
||||||
|
|
||||||
|
Office Tools 0.1.0 targets read-only browser viewing, not editing or
|
||||||
|
pixel-identical reproduction.
|
||||||
|
|
||||||
|
| Family | Extensions | 0.1 viewing coverage |
|
||||||
|
| ---------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Office Open XML document | `.docx` | Paginated sections, text, lists, tables, images, shapes, charts, headers/footers, comments, selection and find |
|
||||||
|
| Office Open XML spreadsheet | `.xlsx` | Sheets, cached values/formulas, styles, merges, frozen panes, images, charts, comments, navigation and find |
|
||||||
|
| Office Open XML presentation | `.pptx` | Slides/masters, text, shapes, images, tables, charts, notes, selection, navigation and find |
|
||||||
|
| OpenDocument text | `.odt` | Semantic headings, paragraphs/runs, lists, tables, packaged images, metadata and foot/endnotes |
|
||||||
|
| OpenDocument spreadsheet | `.ods` | Sheets, typed/cached values, formulas, repeats, merges, annotations, basic safe styling and paged rows |
|
||||||
|
| OpenDocument presentation | `.odp` | Slide order, positioned text/shapes, groups, tables, packaged images, notes and basic safe styling |
|
||||||
|
|
||||||
|
Legacy compound-binary `.doc`, `.xls` and `.ppt` formats are explicitly outside
|
||||||
|
the first package-reader slice. They require a distinct, bounded parser and must
|
||||||
|
not be misidentified as their XML successors.
|
||||||
|
|
||||||
|
## Never executed
|
||||||
|
|
||||||
|
Macros, VBA projects, embedded executables, OLE objects, scripts, remote
|
||||||
|
templates and automatic external relationships remain inert. Unsupported
|
||||||
|
content is reported in diagnostics where it can be identified.
|
||||||
|
|
||||||
|
## Known boundaries
|
||||||
|
|
||||||
|
- Spreadsheet formulas display their saved cached result; Office Tools does not
|
||||||
|
recalculate them or refresh pivots and external data.
|
||||||
|
- Presentation animations and transitions are not reproduced. Embedded media
|
||||||
|
playback is disabled in the first release.
|
||||||
|
- OLE, ActiveX, VBA and OpenDocument embedded objects remain inert. The ODF
|
||||||
|
semantic view reports and omits embedded objects such as chart subdocuments.
|
||||||
|
- OpenDocument slide masters/layouts are identified but not fully reproduced;
|
||||||
|
uncommon drawing transforms and office-suite-specific layout can be
|
||||||
|
approximated.
|
||||||
|
- Fonts are substituted locally. Remote fonts, templates, images and links are
|
||||||
|
never fetched.
|
||||||
|
- ODS renders 200 rows at a time and up to 256 columns. Empty full-grid tails
|
||||||
|
emitted by office suites are deliberately trimmed.
|
||||||
|
|
||||||
|
## Safety limits
|
||||||
|
|
||||||
|
The source-file limit is 100 MiB. OOXML and ODF packages also enforce expanded
|
||||||
|
entry, total expanded byte, entry-count and image limits. ODF additionally
|
||||||
|
bounds compression ratio, XML depth/nodes, text, repeats, cells and assets.
|
||||||
|
Files that exceed a boundary fail with a visible diagnostic instead of being
|
||||||
|
partially trusted.
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Privacy and security model
|
||||||
|
|
||||||
|
## Local processing
|
||||||
|
|
||||||
|
Selecting a file grants the current browser tab access to that file's bytes.
|
||||||
|
Office Tools does not upload them, send telemetry or fetch a remote conversion
|
||||||
|
service. Data remains in memory unless a future feature explicitly offers a
|
||||||
|
user-triggered local download or browser-local save.
|
||||||
|
|
||||||
|
## Threat model
|
||||||
|
|
||||||
|
The input may be hostile: a ZIP bomb, path traversal, deeply nested XML,
|
||||||
|
oversized text, misleading MIME information, malformed relationships or active
|
||||||
|
content disguised as media. Readers therefore need limits for compressed and
|
||||||
|
expanded bytes, entry count, XML depth, node count, repeated elements, image
|
||||||
|
dimensions and rendered output.
|
||||||
|
|
||||||
|
Package paths are normalized as OPC/ODF paths and may never escape the logical
|
||||||
|
package root. External relationships and document links are not fetched or made
|
||||||
|
active. Imported HTML is never trusted. Macros, scripts, OLE objects and
|
||||||
|
embedded executables are never run. OpenDocument embedded objects are retained
|
||||||
|
only as inert package bytes and reported as omitted from the semantic view.
|
||||||
|
|
||||||
|
The ODF reader rejects ambiguous or traversing names, unsupported/encrypted ZIP
|
||||||
|
features, inconsistent headers, overlap, CRC errors, unsafe expansion, DTDs,
|
||||||
|
entities and active XML. It applies byte, entry, ratio, node, depth, repeat,
|
||||||
|
text, cell and image limits inside a disposable worker. OOXML readers likewise
|
||||||
|
run with explicit package/resource limits and external links and Google Fonts
|
||||||
|
disabled.
|
||||||
|
|
||||||
|
## Browser limits
|
||||||
|
|
||||||
|
Local processing is not the same as zero risk: a large document can still cause
|
||||||
|
memory pressure, and rendering depends on the browser's image and font engines.
|
||||||
|
The application should remain cancellable, keep the previous stable UI until a
|
||||||
|
new parse succeeds, and release resources promptly when a file closes.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-labelledby="title desc">
|
||||||
|
<title id="title">Office Tools</title>
|
||||||
|
<desc id="desc">Three overlapping document sheets with text, table and presentation symbols.</desc>
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="page" x1="0" y1="0" x2="1" y2="1">
|
||||||
|
<stop offset="0" stop-color="#edf8ff"/>
|
||||||
|
<stop offset="1" stop-color="#d8eefa"/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<rect width="64" height="64" rx="15" fill="#24465f"/>
|
||||||
|
<path d="M17 13h23l9 9v31H17z" fill="#85c8e8" opacity=".45"/>
|
||||||
|
<path d="M13 9h25l9 9v33H13z" fill="url(#page)" stroke="#16384f" stroke-width="2"/>
|
||||||
|
<path d="M38 9v10h9" fill="#b4dff3" stroke="#16384f" stroke-width="2" stroke-linejoin="round"/>
|
||||||
|
<path d="M20 25h20M20 30h20" stroke="#397b9d" stroke-width="3" stroke-linecap="round"/>
|
||||||
|
<rect x="20" y="36" width="20" height="9" rx="1.5" fill="#fff" stroke="#397b9d" stroke-width="2"/>
|
||||||
|
<path d="M27 36v9m6-9v9m-13-4.5h20" stroke="#397b9d" stroke-width="1.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1014 B |
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "Office Tools",
|
||||||
|
"short_name": "Office",
|
||||||
|
"description": "Open and inspect office files locally in the browser.",
|
||||||
|
"start_url": "./",
|
||||||
|
"scope": "./",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#f7f8fa",
|
||||||
|
"theme_color": "#24465f",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "./favicon.svg",
|
||||||
|
"sizes": "any",
|
||||||
|
"type": "image/svg+xml",
|
||||||
|
"purpose": "any maskable"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
const CACHE_PREFIX = "office-tools-shell-";
|
||||||
|
const CACHE_NAME = `${CACHE_PREFIX}0.1.0`;
|
||||||
|
const CORE = ["./", "./manifest.webmanifest", "./favicon.svg"];
|
||||||
|
|
||||||
|
self.addEventListener("install", (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.open(CACHE_NAME).then(async (cache) => {
|
||||||
|
await cache.addAll(CORE);
|
||||||
|
const response = await fetch("./");
|
||||||
|
const html = await response.text();
|
||||||
|
const assets = [...html.matchAll(/(?:src|href)="(\.\/assets\/[^"]+)"/g)]
|
||||||
|
.map((match) => match[1])
|
||||||
|
.filter(Boolean);
|
||||||
|
await cache.addAll(assets);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
self.skipWaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("activate", (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches
|
||||||
|
.keys()
|
||||||
|
.then((keys) =>
|
||||||
|
Promise.all(
|
||||||
|
keys
|
||||||
|
.filter((key) => key.startsWith(CACHE_PREFIX) && key !== CACHE_NAME)
|
||||||
|
.map((key) => caches.delete(key)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.then(() => self.clients.claim()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("fetch", (event) => {
|
||||||
|
if (event.request.method !== "GET") return;
|
||||||
|
const url = new URL(event.request.url);
|
||||||
|
if (url.origin !== self.location.origin) return;
|
||||||
|
const scope = new URL(self.registration.scope);
|
||||||
|
if (!url.pathname.startsWith(scope.pathname)) return;
|
||||||
|
|
||||||
|
if (event.request.mode === "navigate") {
|
||||||
|
event.respondWith(
|
||||||
|
fetch(event.request)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
const copy = response.clone();
|
||||||
|
void caches
|
||||||
|
.open(CACHE_NAME)
|
||||||
|
.then((cache) => cache.put(event.request, copy));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.catch(async () => {
|
||||||
|
const cached = await caches.match(event.request);
|
||||||
|
if (cached) return cached;
|
||||||
|
const shellUrl = new URL("./", self.registration.scope).href;
|
||||||
|
return (await caches.match(shellUrl)) ?? Response.error();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.respondWith(
|
||||||
|
caches.match(event.request).then(
|
||||||
|
(cached) =>
|
||||||
|
cached ??
|
||||||
|
fetch(event.request).then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
const copy = response.clone();
|
||||||
|
void caches
|
||||||
|
.open(CACHE_NAME)
|
||||||
|
.then((cache) => cache.put(event.request, copy));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://git.add-ideas.de/lotobo/toolbox-sdk/raw/branch/main/schemas/toolbox-app.v1.schema.json",
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "de.add-ideas.office-tools",
|
||||||
|
"name": "Office Tools",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Open and inspect documents, spreadsheets and presentations locally in the browser.",
|
||||||
|
"entry": "./",
|
||||||
|
"icon": "./favicon.svg",
|
||||||
|
"categories": ["documents", "office", "productivity"],
|
||||||
|
"tags": [
|
||||||
|
"document",
|
||||||
|
"spreadsheet",
|
||||||
|
"presentation",
|
||||||
|
"docx",
|
||||||
|
"xlsx",
|
||||||
|
"pptx",
|
||||||
|
"odt",
|
||||||
|
"ods",
|
||||||
|
"odp",
|
||||||
|
"viewer"
|
||||||
|
],
|
||||||
|
"integration": {
|
||||||
|
"contextVersion": 1,
|
||||||
|
"launchModes": ["navigate", "new-tab"],
|
||||||
|
"embedding": "unsupported"
|
||||||
|
},
|
||||||
|
"requirements": {
|
||||||
|
"secureContext": false,
|
||||||
|
"workers": true,
|
||||||
|
"indexedDb": false,
|
||||||
|
"crossOriginIsolated": false,
|
||||||
|
"topLevelContext": false
|
||||||
|
},
|
||||||
|
"privacy": {
|
||||||
|
"processing": "local",
|
||||||
|
"fileUploads": false,
|
||||||
|
"telemetry": false,
|
||||||
|
"label": "Office files stay in this browser; nothing is uploaded."
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"repository": "https://git.add-ideas.de/lotobo/office-tools",
|
||||||
|
"license": "GPL-3.0-or-later"
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"id": "source",
|
||||||
|
"label": "Source",
|
||||||
|
"url": "https://git.add-ideas.de/lotobo/office-tools"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { lstat, readFile, writeFile } from "node:fs/promises";
|
||||||
|
import { dirname, join, relative } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { format } from "prettier";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const sourcePath = join(root, "src", "toolbox", "manifest.source.json");
|
||||||
|
const outputPath = join(root, "public", "toolbox-app.json");
|
||||||
|
const source = JSON.parse(await readFile(sourcePath, "utf8"));
|
||||||
|
const packageJson = JSON.parse(
|
||||||
|
await readFile(join(root, "package.json"), "utf8"),
|
||||||
|
);
|
||||||
|
const versionSource = await readFile(join(root, "src", "version.ts"), "utf8");
|
||||||
|
const applicationVersion =
|
||||||
|
/^export const (?:APPLICATION|APP)_VERSION = "([^"]+)";$/mu.exec(
|
||||||
|
versionSource,
|
||||||
|
)?.[1];
|
||||||
|
|
||||||
|
if (
|
||||||
|
source.version !== packageJson.version ||
|
||||||
|
applicationVersion !== packageJson.version
|
||||||
|
)
|
||||||
|
throw new Error(
|
||||||
|
`Version drift: manifest ${source.version}, application ${String(applicationVersion)}, package ${packageJson.version}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
source.id !== "de.add-ideas.office-tools" ||
|
||||||
|
source.source?.repository !==
|
||||||
|
"https://git.add-ideas.de/lotobo/office-tools" ||
|
||||||
|
source.source?.license !== "GPL-3.0-or-later"
|
||||||
|
)
|
||||||
|
throw new Error("Manifest source identity is incomplete or inconsistent");
|
||||||
|
|
||||||
|
for (const asset of source.assets ?? []) {
|
||||||
|
if (
|
||||||
|
typeof asset !== "string" ||
|
||||||
|
!asset.startsWith("./") ||
|
||||||
|
asset.includes("\\") ||
|
||||||
|
asset.split("/").includes("..")
|
||||||
|
)
|
||||||
|
throw new Error(`Unsafe manifest asset path: ${JSON.stringify(asset)}`);
|
||||||
|
const details = await lstat(join(root, "public", asset.slice(2))).catch(
|
||||||
|
() => null,
|
||||||
|
);
|
||||||
|
if (!details?.isFile() || details.isSymbolicLink())
|
||||||
|
throw new Error(`Manifest asset is missing or unsafe: ${asset}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const serialized = await format(JSON.stringify(source), {
|
||||||
|
filepath: outputPath,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (process.argv.includes("--check")) {
|
||||||
|
if ((await readFile(outputPath, "utf8").catch(() => "")) !== serialized)
|
||||||
|
throw new Error(
|
||||||
|
`${relative(root, outputPath)} is stale; run npm run manifest:generate`,
|
||||||
|
);
|
||||||
|
console.log("Toolbox manifest is synchronized");
|
||||||
|
} else {
|
||||||
|
await writeFile(outputPath, serialized);
|
||||||
|
console.log(`Generated ${relative(root, outputPath)}`);
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
|
import { execFile } from "node:child_process";
|
||||||
|
import {
|
||||||
|
access,
|
||||||
|
chmod,
|
||||||
|
copyFile,
|
||||||
|
cp,
|
||||||
|
lstat,
|
||||||
|
mkdir,
|
||||||
|
mkdtemp,
|
||||||
|
readFile,
|
||||||
|
readdir,
|
||||||
|
rename,
|
||||||
|
rm,
|
||||||
|
utimes,
|
||||||
|
writeFile,
|
||||||
|
} from "node:fs/promises";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import { promisify } from "node:util";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const execute = promisify(execFile);
|
||||||
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const packageJson = JSON.parse(
|
||||||
|
await readFile(path.join(root, "package.json"), "utf8"),
|
||||||
|
);
|
||||||
|
const argument = (name, fallback) => {
|
||||||
|
const index = process.argv.indexOf(name);
|
||||||
|
return index >= 0 ? process.argv[index + 1] : fallback;
|
||||||
|
};
|
||||||
|
const output = path.resolve(
|
||||||
|
root,
|
||||||
|
argument("--output", `release/office-tools-${packageJson.version}.zip`),
|
||||||
|
);
|
||||||
|
const checksumOutput = `${output}.sha256`;
|
||||||
|
const force = process.argv.includes("--force");
|
||||||
|
|
||||||
|
if (
|
||||||
|
path.extname(output).toLowerCase() !== ".zip" ||
|
||||||
|
output === root ||
|
||||||
|
output === path.parse(output).root
|
||||||
|
)
|
||||||
|
throw new Error("Release output is not a safe ZIP target");
|
||||||
|
|
||||||
|
const exists = (file) =>
|
||||||
|
access(file).then(
|
||||||
|
() => true,
|
||||||
|
() => false,
|
||||||
|
);
|
||||||
|
if (!force && ((await exists(output)) || (await exists(checksumOutput))))
|
||||||
|
throw new Error("Release output already exists; use --force to replace it");
|
||||||
|
|
||||||
|
const input = path.join(root, "dist");
|
||||||
|
for (const name of [
|
||||||
|
"index.html",
|
||||||
|
"manifest.webmanifest",
|
||||||
|
"sw.js",
|
||||||
|
"toolbox-app.json",
|
||||||
|
"favicon.svg",
|
||||||
|
"README.md",
|
||||||
|
"CHANGELOG.md",
|
||||||
|
"CONTRIBUTING.md",
|
||||||
|
"LICENSE",
|
||||||
|
"SECURITY.md",
|
||||||
|
"SOURCE.md",
|
||||||
|
"THIRD_PARTY_NOTICES.md",
|
||||||
|
"LICENSES/README.md",
|
||||||
|
"LICENSES/silurus-ooxml-MIT.txt",
|
||||||
|
"LICENSES/silurus-ooxml-THIRD_PARTY_NOTICES.md",
|
||||||
|
"LICENSES/npm-runtime-licenses.txt",
|
||||||
|
"docs/ACCESSIBILITY.md",
|
||||||
|
"docs/ARCHITECTURE.md",
|
||||||
|
"docs/FORMAT-SUPPORT.md",
|
||||||
|
"docs/PRIVACY-SECURITY.md",
|
||||||
|
]) {
|
||||||
|
const details = await lstat(path.join(input, name)).catch(() => null);
|
||||||
|
if (!details?.isFile() || details.isSymbolicLink())
|
||||||
|
throw new Error(`Release is missing a regular file: ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifest = JSON.parse(
|
||||||
|
await readFile(path.join(input, "toolbox-app.json"), "utf8"),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
manifest.id !== "de.add-ideas.office-tools" ||
|
||||||
|
manifest.version !== packageJson.version ||
|
||||||
|
manifest.entry !== "./" ||
|
||||||
|
manifest.icon !== "./favicon.svg" ||
|
||||||
|
manifest.source?.repository !==
|
||||||
|
"https://git.add-ideas.de/lotobo/office-tools" ||
|
||||||
|
manifest.source?.license !== "GPL-3.0-or-later"
|
||||||
|
)
|
||||||
|
throw new Error("Packaged Toolbox manifest identity is invalid");
|
||||||
|
|
||||||
|
const html = await readFile(path.join(input, "index.html"), "utf8");
|
||||||
|
if (/\b(?:src|href)=["']\//iu.test(html))
|
||||||
|
throw new Error("index.html contains a root-absolute asset reference");
|
||||||
|
|
||||||
|
async function collect(directory, prefix = "") {
|
||||||
|
const files = [];
|
||||||
|
for (const entry of (await readdir(directory, { withFileTypes: true })).sort(
|
||||||
|
(left, right) =>
|
||||||
|
left.name === right.name ? 0 : left.name < right.name ? -1 : 1,
|
||||||
|
)) {
|
||||||
|
const absolute = path.join(directory, entry.name);
|
||||||
|
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
||||||
|
if (entry.isSymbolicLink())
|
||||||
|
throw new Error(`Release contains a symbolic link: ${relative}`);
|
||||||
|
if (entry.isDirectory()) files.push(...(await collect(absolute, relative)));
|
||||||
|
else if (entry.isFile()) files.push({ absolute, relative });
|
||||||
|
else throw new Error(`Unsupported release entry: ${relative}`);
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceFiles = await collect(input);
|
||||||
|
for (const file of sourceFiles)
|
||||||
|
if (
|
||||||
|
file.relative.endsWith(".map") ||
|
||||||
|
/(?:^|\/)(?:\.env(?:\.|$)|id_rsa|id_ed25519|.*\.pem$|.*\.key$)/iu.test(
|
||||||
|
file.relative,
|
||||||
|
) ||
|
||||||
|
file.relative.startsWith("/") ||
|
||||||
|
file.relative.split("/").includes("..")
|
||||||
|
)
|
||||||
|
throw new Error(`Forbidden release entry: ${file.relative}`);
|
||||||
|
|
||||||
|
await mkdir(path.dirname(output), { recursive: true });
|
||||||
|
const stagingRoot = await mkdtemp(path.join(os.tmpdir(), "office-release-"));
|
||||||
|
const publicationRoot = await mkdtemp(
|
||||||
|
path.join(path.dirname(output), ".office-publish-"),
|
||||||
|
);
|
||||||
|
const stagedTree = path.join(stagingRoot, "tree");
|
||||||
|
const stagedArchive = path.join(stagingRoot, path.basename(output));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await cp(input, stagedTree, { recursive: true });
|
||||||
|
const timestamp = new Date("1980-01-01T00:00:00.000Z");
|
||||||
|
for (const file of await collect(stagedTree)) {
|
||||||
|
await chmod(file.absolute, 0o644);
|
||||||
|
await utimes(file.absolute, timestamp, timestamp);
|
||||||
|
}
|
||||||
|
await execute(
|
||||||
|
"zip",
|
||||||
|
[
|
||||||
|
"-X",
|
||||||
|
"-q",
|
||||||
|
"-9",
|
||||||
|
stagedArchive,
|
||||||
|
...sourceFiles.map((file) => file.relative),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
cwd: stagedTree,
|
||||||
|
env: { ...process.env, TZ: "UTC" },
|
||||||
|
maxBuffer: 1024 * 1024,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const archive = await readFile(stagedArchive);
|
||||||
|
const digest = createHash("sha256").update(archive).digest("hex");
|
||||||
|
const stagedChecksum = `${stagedArchive}.sha256`;
|
||||||
|
await writeFile(stagedChecksum, `${digest} ${path.basename(output)}\n`, {
|
||||||
|
mode: 0o644,
|
||||||
|
});
|
||||||
|
const publicationArchive = path.join(publicationRoot, path.basename(output));
|
||||||
|
const publicationChecksum = `${publicationArchive}.sha256`;
|
||||||
|
await copyFile(stagedArchive, publicationArchive);
|
||||||
|
await copyFile(stagedChecksum, publicationChecksum);
|
||||||
|
if (force) {
|
||||||
|
await rm(output, { force: true });
|
||||||
|
await rm(checksumOutput, { force: true });
|
||||||
|
}
|
||||||
|
await rename(publicationArchive, output);
|
||||||
|
await rename(publicationChecksum, checksumOutput);
|
||||||
|
console.log(
|
||||||
|
`Created ${path.relative(root, output)} (${archive.byteLength} bytes, ${sourceFiles.length} files)\nSHA-256 ${digest}`,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await rm(stagingRoot, { recursive: true, force: true });
|
||||||
|
await rm(publicationRoot, { recursive: true, force: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { cp, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const destination = path.join(root, "public");
|
||||||
|
const required = [
|
||||||
|
"LICENSE",
|
||||||
|
"README.md",
|
||||||
|
"CHANGELOG.md",
|
||||||
|
"CONTRIBUTING.md",
|
||||||
|
"SECURITY.md",
|
||||||
|
"SOURCE.md",
|
||||||
|
"THIRD_PARTY_NOTICES.md",
|
||||||
|
];
|
||||||
|
|
||||||
|
await mkdir(destination, { recursive: true });
|
||||||
|
for (const name of required) {
|
||||||
|
await readFile(path.join(root, name));
|
||||||
|
await cp(path.join(root, name), path.join(destination, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const directory of ["LICENSES", "docs"]) {
|
||||||
|
const output = path.join(destination, directory);
|
||||||
|
await rm(output, { recursive: true, force: true });
|
||||||
|
await cp(path.join(root, directory), output, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const lock = JSON.parse(
|
||||||
|
await readFile(path.join(root, "package-lock.json"), "utf8"),
|
||||||
|
);
|
||||||
|
const sections = [];
|
||||||
|
|
||||||
|
for (const [location, locked] of Object.entries(lock.packages ?? {}).sort(
|
||||||
|
([left], [right]) => (left === right ? 0 : left < right ? -1 : 1),
|
||||||
|
)) {
|
||||||
|
if (!location.includes("node_modules/") || locked.dev === true) continue;
|
||||||
|
const packageDirectory = path.join(root, location);
|
||||||
|
const details = JSON.parse(
|
||||||
|
await readFile(path.join(packageDirectory, "package.json"), "utf8"),
|
||||||
|
);
|
||||||
|
const candidates = (await readdir(packageDirectory))
|
||||||
|
.filter((name) => /^(?:licen[cs]e|copying|notice)(?:\.|$)/iu.test(name))
|
||||||
|
.sort();
|
||||||
|
const texts = [];
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
try {
|
||||||
|
texts.push(
|
||||||
|
`--- ${candidate} ---\n${(
|
||||||
|
await readFile(path.join(packageDirectory, candidate), "utf8")
|
||||||
|
).trimEnd()}`,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
/* Ignore directories and non-text aliases. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sections.push(
|
||||||
|
[
|
||||||
|
"=".repeat(78),
|
||||||
|
`${details.name}@${details.version}`,
|
||||||
|
`Declared licence: ${details.license ?? locked.license ?? "See upstream"}`,
|
||||||
|
`Installed from: ${location}`,
|
||||||
|
"=".repeat(78),
|
||||||
|
texts.join("\n\n") ||
|
||||||
|
"No package-local licence file was present; see THIRD_PARTY_NOTICES.md.",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await writeFile(
|
||||||
|
path.join(destination, "LICENSES", "npm-runtime-licenses.txt"),
|
||||||
|
`${sections.join("\n\n").trimEnd()}\n`,
|
||||||
|
);
|
||||||
|
console.log("Prepared static release documentation and notices");
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import { createServer } from "node:http";
|
||||||
|
import { readFile, stat } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"..",
|
||||||
|
"dist",
|
||||||
|
);
|
||||||
|
const nestedPrefix = "/deep/nested/office/";
|
||||||
|
const mediaTypes = new Map([
|
||||||
|
[".css", "text/css; charset=utf-8"],
|
||||||
|
[".html", "text/html; charset=utf-8"],
|
||||||
|
[".js", "text/javascript; charset=utf-8"],
|
||||||
|
[".mjs", "text/javascript; charset=utf-8"],
|
||||||
|
[".json", "application/json; charset=utf-8"],
|
||||||
|
[".webmanifest", "application/manifest+json; charset=utf-8"],
|
||||||
|
[".svg", "image/svg+xml"],
|
||||||
|
[".md", "text/markdown; charset=utf-8"],
|
||||||
|
[".txt", "text/plain; charset=utf-8"],
|
||||||
|
[".wasm", "application/wasm"],
|
||||||
|
[".png", "image/png"],
|
||||||
|
[".jpg", "image/jpeg"],
|
||||||
|
[".jpeg", "image/jpeg"],
|
||||||
|
[".webp", "image/webp"],
|
||||||
|
]);
|
||||||
|
const headers = {
|
||||||
|
"Content-Security-Policy":
|
||||||
|
"default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; form-action 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; media-src 'self' blob:; font-src 'self' data:; connect-src 'self'; worker-src 'self' blob:; manifest-src 'self'",
|
||||||
|
"Cross-Origin-Opener-Policy": "same-origin",
|
||||||
|
"Cross-Origin-Resource-Policy": "same-origin",
|
||||||
|
"Permissions-Policy":
|
||||||
|
"camera=(), microphone=(), geolocation=(), usb=(), payment=()",
|
||||||
|
"Referrer-Policy": "no-referrer",
|
||||||
|
"X-Content-Type-Options": "nosniff",
|
||||||
|
};
|
||||||
|
|
||||||
|
function safeFile(requestPath) {
|
||||||
|
const decoded = decodeURIComponent(requestPath);
|
||||||
|
const relative = decoded.startsWith(nestedPrefix)
|
||||||
|
? decoded.slice(nestedPrefix.length)
|
||||||
|
: decoded.replace(/^\/+/, "");
|
||||||
|
const normalized = path.posix.normalize(relative || "index.html");
|
||||||
|
if (
|
||||||
|
normalized === ".." ||
|
||||||
|
normalized.startsWith("../") ||
|
||||||
|
path.isAbsolute(normalized)
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
return path.join(root, normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = createServer(async (request, response) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
||||||
|
let file = safeFile(url.pathname);
|
||||||
|
if (!file) {
|
||||||
|
response.writeHead(400).end("Bad request");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((await stat(file).catch(() => null))?.isDirectory())
|
||||||
|
file = path.join(file, "index.html");
|
||||||
|
const content = await readFile(file);
|
||||||
|
const relative = path.relative(root, file).split(path.sep).join("/");
|
||||||
|
const immutable = relative.startsWith("assets/");
|
||||||
|
response.writeHead(200, {
|
||||||
|
"Content-Type":
|
||||||
|
mediaTypes.get(path.extname(file)) ?? "application/octet-stream",
|
||||||
|
"Cache-Control": immutable
|
||||||
|
? "public, max-age=31536000, immutable"
|
||||||
|
: "no-cache",
|
||||||
|
...headers,
|
||||||
|
});
|
||||||
|
response.end(content);
|
||||||
|
} catch {
|
||||||
|
response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
response.end("Not found");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(4173, "127.0.0.1", () =>
|
||||||
|
console.log(
|
||||||
|
"Office Tools test server listening on http://127.0.0.1:4173/deep/nested/office/",
|
||||||
|
),
|
||||||
|
);
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
import { lazy, Suspense, useState } from "react";
|
||||||
|
import { AppShell } from "@add-ideas/toolbox-shell-react";
|
||||||
|
import "@add-ideas/toolbox-shell-react/styles.css";
|
||||||
|
import "./styles.css";
|
||||||
|
import { AppErrorBoundary } from "./components/AppErrorBoundary";
|
||||||
|
import { HelpDialog } from "./components/HelpDialog";
|
||||||
|
import { manifest } from "./toolbox/manifest";
|
||||||
|
|
||||||
|
const UploadWorkbench = lazy(async () => ({
|
||||||
|
default: (await import("./components/UploadWorkbench")).UploadWorkbench,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
const [helpOpen, setHelpOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppErrorBoundary>
|
||||||
|
<AppShell
|
||||||
|
app={manifest}
|
||||||
|
manifestUrl="./toolbox-app.json"
|
||||||
|
helpAction={{ onClick: () => setHelpOpen(true) }}
|
||||||
|
onContextError={(error) =>
|
||||||
|
console.warn(
|
||||||
|
"Toolbox context unavailable; continuing standalone.",
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<p className="workbench-loading" role="status">
|
||||||
|
Preparing the local office viewer…
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<UploadWorkbench />
|
||||||
|
</Suspense>
|
||||||
|
</AppShell>
|
||||||
|
<HelpDialog open={helpOpen} onClose={() => setHelpOpen(false)} />
|
||||||
|
</AppErrorBoundary>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { Component, type ErrorInfo, type ReactNode } from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
error: Error | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AppErrorBoundary extends Component<Props, State> {
|
||||||
|
state: State = { error: null };
|
||||||
|
|
||||||
|
static getDerivedStateFromError(error: Error): State {
|
||||||
|
return { error };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, info: ErrorInfo): void {
|
||||||
|
console.error("Office Tools encountered an interface error", error, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
render(): ReactNode {
|
||||||
|
if (!this.state.error) return this.props.children;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="fatal-error" role="alert">
|
||||||
|
<h1>Office Tools could not continue</h1>
|
||||||
|
<p>{this.state.error.message}</p>
|
||||||
|
<button type="button" onClick={() => globalThis.location.reload()}>
|
||||||
|
Reload application
|
||||||
|
</button>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
|
interface HelpDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HelpDialog({ open, onClose }: HelpDialogProps) {
|
||||||
|
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const dialog = dialogRef.current;
|
||||||
|
if (!dialog) return;
|
||||||
|
if (open && !dialog.open) dialog.showModal();
|
||||||
|
if (!open && dialog.open) dialog.close();
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<dialog
|
||||||
|
ref={dialogRef}
|
||||||
|
className="office-dialog"
|
||||||
|
aria-labelledby="help-title"
|
||||||
|
onClose={onClose}
|
||||||
|
onCancel={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
onClick={(event) => {
|
||||||
|
if (event.target === event.currentTarget) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<article className="dialog-card">
|
||||||
|
<header className="dialog-heading">
|
||||||
|
<div>
|
||||||
|
<p className="eyebrow">Private document viewer</p>
|
||||||
|
<h2 id="help-title">Office Tools help</h2>
|
||||||
|
</div>
|
||||||
|
<button type="button" className="icon-button" onClick={onClose}>
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
<span className="sr-only">Close help</span>
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<div className="help-grid">
|
||||||
|
<section>
|
||||||
|
<h3>Open a file</h3>
|
||||||
|
<p>
|
||||||
|
Choose a supported document, spreadsheet or presentation, or drop
|
||||||
|
it onto the opening panel. The original file is not changed.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h3>Local by design</h3>
|
||||||
|
<p>
|
||||||
|
Parsing and viewing happen in this browser. Files are not sent to
|
||||||
|
a server, and Office Tools has no telemetry.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h3>Rendering scope</h3>
|
||||||
|
<p>
|
||||||
|
DOCX, XLSX and PPTX use a high-fidelity canvas renderer. ODT, ODS
|
||||||
|
and ODP use a semantic compatibility view. Unsupported or
|
||||||
|
approximated features are reported.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h3>Untrusted content</h3>
|
||||||
|
<p>
|
||||||
|
Imported links are disabled, and embedded active objects are
|
||||||
|
omitted. Office Tools never runs macros or document scripts.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,519 @@
|
|||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useId,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
type FormEvent,
|
||||||
|
} from "react";
|
||||||
|
import type { OdfDocument, OdfFormat } from "../office/odf";
|
||||||
|
import type {
|
||||||
|
OdfWorkerError,
|
||||||
|
OdfWorkerParseRequest,
|
||||||
|
OdfWorkerResponse,
|
||||||
|
} from "../workers/odf.worker";
|
||||||
|
import {
|
||||||
|
OdpPresentationView,
|
||||||
|
OdsWorkbookView,
|
||||||
|
OdtDocumentView,
|
||||||
|
} from "./odf-renderers";
|
||||||
|
import {
|
||||||
|
ODS_PAGE_ROWS,
|
||||||
|
buildSearchResult,
|
||||||
|
createStyleResolver,
|
||||||
|
type OdfSearchMatch,
|
||||||
|
} from "./odf-viewer-model";
|
||||||
|
|
||||||
|
type OpenState = {
|
||||||
|
status: "loading" | "ready" | "error";
|
||||||
|
detail: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface OdfViewerProps {
|
||||||
|
file: File;
|
||||||
|
format: OdfFormat;
|
||||||
|
onOpenStateChange?: (state: OpenState) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ReadyDocument {
|
||||||
|
model: OdfDocument;
|
||||||
|
assetUrls: Map<string, string>;
|
||||||
|
elapsedMs: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WORKER_TIMEOUT_MS = 90_000;
|
||||||
|
const MIN_ZOOM = 0.5;
|
||||||
|
const MAX_ZOOM = 2.5;
|
||||||
|
|
||||||
|
function describeWorkerError(error: OdfWorkerError): string {
|
||||||
|
switch (error.code) {
|
||||||
|
case "encrypted":
|
||||||
|
return "Encrypted OpenDocument files are not supported in this viewer.";
|
||||||
|
case "limit-exceeded":
|
||||||
|
return `Opening stopped because this package exceeds a local safety limit: ${error.message}`;
|
||||||
|
case "type-mismatch":
|
||||||
|
return "The file extension and OpenDocument package contents do not match.";
|
||||||
|
case "external-resource":
|
||||||
|
return "Opening stopped because the document contains an unsafe external or active resource.";
|
||||||
|
case "invalid-path":
|
||||||
|
case "invalid-zip":
|
||||||
|
case "invalid-xml":
|
||||||
|
case "invalid-document":
|
||||||
|
case "missing-part":
|
||||||
|
case "unsupported-zip":
|
||||||
|
return error.message;
|
||||||
|
default:
|
||||||
|
return error.message || "The OpenDocument file could not be opened.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function revokeUrls(urls: ReadonlyMap<string, string> | undefined): void {
|
||||||
|
if (!urls) return;
|
||||||
|
for (const url of urls.values()) URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeAssetUrls(model: OdfDocument): Map<string, string> {
|
||||||
|
const urls = new Map<string, string>();
|
||||||
|
try {
|
||||||
|
for (const asset of model.assets) {
|
||||||
|
const blob = new Blob([asset.data], { type: asset.mediaType });
|
||||||
|
urls.set(asset.id, URL.createObjectURL(blob));
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
} catch (error) {
|
||||||
|
revokeUrls(urls);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OdfViewer({ file, format, onOpenStateChange }: OdfViewerProps) {
|
||||||
|
const searchId = useId();
|
||||||
|
const stageRef = useRef<HTMLDivElement>(null);
|
||||||
|
const onOpenStateChangeRef = useRef(onOpenStateChange);
|
||||||
|
const urlsRef = useRef<Map<string, string> | undefined>(undefined);
|
||||||
|
const requestRef = useRef(0);
|
||||||
|
const [ready, setReady] = useState<ReadyDocument | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [zoom, setZoom] = useState(1);
|
||||||
|
const [activeSheet, setActiveSheet] = useState(0);
|
||||||
|
const [sheetPage, setSheetPage] = useState(0);
|
||||||
|
const [activeSlide, setActiveSlide] = useState(0);
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [matches, setMatches] = useState<OdfSearchMatch[]>([]);
|
||||||
|
const [matchIndex, setMatchIndex] = useState(-1);
|
||||||
|
const [searchTruncated, setSearchTruncated] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onOpenStateChangeRef.current = onOpenStateChange;
|
||||||
|
}, [onOpenStateChange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const requestId = requestRef.current + 1;
|
||||||
|
requestRef.current = requestId;
|
||||||
|
let active = true;
|
||||||
|
let worker: Worker | undefined;
|
||||||
|
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
|
const fail = (message: string) => {
|
||||||
|
if (!active || requestRef.current !== requestId) return;
|
||||||
|
setLoading(false);
|
||||||
|
setError(message);
|
||||||
|
onOpenStateChangeRef.current?.({ status: "error", detail: message });
|
||||||
|
};
|
||||||
|
|
||||||
|
async function open() {
|
||||||
|
await Promise.resolve();
|
||||||
|
if (!active) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
setReady(null);
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "loading",
|
||||||
|
detail: "Reading locally",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof Worker === "undefined") {
|
||||||
|
fail("This browser cannot start the isolated OpenDocument reader.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const buffer = await file.arrayBuffer();
|
||||||
|
if (!active || requestRef.current !== requestId) return;
|
||||||
|
worker = new Worker(
|
||||||
|
new URL("../workers/odf.worker.ts", import.meta.url),
|
||||||
|
{
|
||||||
|
type: "module",
|
||||||
|
name: "office-tools-odf-reader",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
worker.addEventListener(
|
||||||
|
"message",
|
||||||
|
(event: MessageEvent<OdfWorkerResponse>) => {
|
||||||
|
if (
|
||||||
|
!active ||
|
||||||
|
requestRef.current !== requestId ||
|
||||||
|
event.data.requestId !== requestId
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (timeout !== undefined) clearTimeout(timeout);
|
||||||
|
if (event.data.type === "error") {
|
||||||
|
fail(describeWorkerError(event.data.error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const assetUrls = makeAssetUrls(event.data.document);
|
||||||
|
revokeUrls(urlsRef.current);
|
||||||
|
urlsRef.current = assetUrls;
|
||||||
|
setReady({
|
||||||
|
model: event.data.document,
|
||||||
|
assetUrls,
|
||||||
|
elapsedMs: event.data.elapsedMs,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "ready",
|
||||||
|
detail: "Opened locally",
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
fail("Embedded document images could not be prepared safely.");
|
||||||
|
} finally {
|
||||||
|
worker?.terminate();
|
||||||
|
worker = undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
worker.addEventListener("error", () => {
|
||||||
|
if (timeout !== undefined) clearTimeout(timeout);
|
||||||
|
fail("The isolated OpenDocument reader stopped unexpectedly.");
|
||||||
|
worker?.terminate();
|
||||||
|
worker = undefined;
|
||||||
|
});
|
||||||
|
const request: OdfWorkerParseRequest = {
|
||||||
|
type: "parse",
|
||||||
|
requestId,
|
||||||
|
buffer,
|
||||||
|
format,
|
||||||
|
fileName: file.name,
|
||||||
|
};
|
||||||
|
worker.postMessage(request, [buffer]);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
fail("OpenDocument parsing exceeded its 90-second safety limit.");
|
||||||
|
worker?.terminate();
|
||||||
|
worker = undefined;
|
||||||
|
}, WORKER_TIMEOUT_MS);
|
||||||
|
} catch (openError) {
|
||||||
|
fail(
|
||||||
|
openError instanceof Error
|
||||||
|
? openError.message
|
||||||
|
: "The OpenDocument file could not be read.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void open();
|
||||||
|
return () => {
|
||||||
|
active = false;
|
||||||
|
if (timeout !== undefined) clearTimeout(timeout);
|
||||||
|
worker?.terminate();
|
||||||
|
revokeUrls(urlsRef.current);
|
||||||
|
urlsRef.current = undefined;
|
||||||
|
};
|
||||||
|
}, [file, format]);
|
||||||
|
|
||||||
|
const resolveStyle = useMemo(
|
||||||
|
() => createStyleResolver(ready?.model.styles ?? []),
|
||||||
|
[ready],
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeMatch = matchIndex >= 0 ? matches[matchIndex] : undefined;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!activeMatch) return;
|
||||||
|
const animation = requestAnimationFrame(() => {
|
||||||
|
const units =
|
||||||
|
stageRef.current?.querySelectorAll<HTMLElement>("[data-odf-unit]");
|
||||||
|
const target = [...(units ?? [])].find(
|
||||||
|
(element) => element.dataset.odfUnit === activeMatch.unitId,
|
||||||
|
);
|
||||||
|
target?.scrollIntoView({ block: "center", inline: "center" });
|
||||||
|
});
|
||||||
|
return () => cancelAnimationFrame(animation);
|
||||||
|
}, [activeMatch, activeSheet, activeSlide, sheetPage]);
|
||||||
|
|
||||||
|
const moveToMatch = useCallback(
|
||||||
|
(nextIndex: number, nextMatches = matches) => {
|
||||||
|
if (nextMatches.length === 0) {
|
||||||
|
setMatchIndex(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const normalized =
|
||||||
|
((nextIndex % nextMatches.length) + nextMatches.length) %
|
||||||
|
nextMatches.length;
|
||||||
|
const match = nextMatches[normalized];
|
||||||
|
if (!match) return;
|
||||||
|
setMatchIndex(normalized);
|
||||||
|
if (ready?.model.format === "ods") {
|
||||||
|
setActiveSheet(match.scopeIndex);
|
||||||
|
setSheetPage(Math.floor((match.rowIndex ?? 0) / ODS_PAGE_ROWS));
|
||||||
|
} else if (ready?.model.format === "odp") {
|
||||||
|
setActiveSlide(match.scopeIndex);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[matches, ready],
|
||||||
|
);
|
||||||
|
|
||||||
|
const find = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!ready) return;
|
||||||
|
const result = buildSearchResult(ready.model, query);
|
||||||
|
setMatches(result.matches);
|
||||||
|
setSearchTruncated(result.truncated);
|
||||||
|
moveToMatch(0, result.matches);
|
||||||
|
};
|
||||||
|
|
||||||
|
const model = ready?.model;
|
||||||
|
const noun =
|
||||||
|
model?.format === "ods"
|
||||||
|
? "sheet"
|
||||||
|
: model?.format === "odp"
|
||||||
|
? "slide"
|
||||||
|
: "document";
|
||||||
|
const index =
|
||||||
|
model?.format === "ods"
|
||||||
|
? activeSheet
|
||||||
|
: model?.format === "odp"
|
||||||
|
? activeSlide
|
||||||
|
: 0;
|
||||||
|
const total =
|
||||||
|
model?.format === "ods"
|
||||||
|
? model.sheets.length
|
||||||
|
: model?.format === "odp"
|
||||||
|
? model.slides.length
|
||||||
|
: model
|
||||||
|
? 1
|
||||||
|
: 0;
|
||||||
|
const goTo = (next: number) => {
|
||||||
|
const target = Math.max(0, Math.min(Math.max(0, total - 1), next));
|
||||||
|
if (model?.format === "ods") {
|
||||||
|
setActiveSheet(target);
|
||||||
|
setSheetPage(0);
|
||||||
|
} else if (model?.format === "odp") {
|
||||||
|
setActiveSlide(target);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const zoomPercent = Math.round(zoom * 100);
|
||||||
|
const elapsed = ready
|
||||||
|
? ready.elapsedMs < 1_000
|
||||||
|
? `${Math.round(ready.elapsedMs)} ms`
|
||||||
|
: `${(ready.elapsedMs / 1_000).toFixed(1)} s`
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
className="office-viewer"
|
||||||
|
aria-label={`${format.toUpperCase()} viewer`}
|
||||||
|
>
|
||||||
|
<div className="office-viewer-toolbar" aria-label="Viewer controls">
|
||||||
|
<div className="office-viewer-toolbar__group">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || index <= 0}
|
||||||
|
onClick={() => goTo(index - 1)}
|
||||||
|
aria-label={`Previous ${noun}`}
|
||||||
|
title={`Previous ${noun}`}
|
||||||
|
>
|
||||||
|
‹
|
||||||
|
</button>
|
||||||
|
<span className="office-position" aria-live="polite">
|
||||||
|
{total > 0 ? `${noun} ${index + 1} of ${total}` : `${noun} —`}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || index + 1 >= total}
|
||||||
|
onClick={() => goTo(index + 1)}
|
||||||
|
aria-label={`Next ${noun}`}
|
||||||
|
title={`Next ${noun}`}
|
||||||
|
>
|
||||||
|
›
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="office-viewer-toolbar__group">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || zoom <= MIN_ZOOM}
|
||||||
|
onClick={() => setZoom((value) => Math.max(MIN_ZOOM, value - 0.1))}
|
||||||
|
aria-label="Zoom out"
|
||||||
|
title="Zoom out"
|
||||||
|
>
|
||||||
|
−
|
||||||
|
</button>
|
||||||
|
<span className="office-zoom" aria-live="polite">
|
||||||
|
{zoomPercent}%
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || zoom >= MAX_ZOOM}
|
||||||
|
onClick={() => setZoom((value) => Math.min(MAX_ZOOM, value + 0.1))}
|
||||||
|
aria-label="Zoom in"
|
||||||
|
title="Zoom in"
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</button>
|
||||||
|
<button type="button" disabled={loading} onClick={() => setZoom(1)}>
|
||||||
|
Actual size
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form className="office-find" role="search" onSubmit={find}>
|
||||||
|
<label className="sr-only" htmlFor={searchId}>
|
||||||
|
Find in file
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id={searchId}
|
||||||
|
type="search"
|
||||||
|
value={query}
|
||||||
|
onChange={(event) => setQuery(event.currentTarget.value)}
|
||||||
|
placeholder="Find in file"
|
||||||
|
disabled={loading || !model}
|
||||||
|
/>
|
||||||
|
<button type="submit" disabled={loading || !model}>
|
||||||
|
Find
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={matches.length === 0}
|
||||||
|
onClick={() => moveToMatch(matchIndex - 1)}
|
||||||
|
aria-label="Previous match"
|
||||||
|
title="Previous match"
|
||||||
|
>
|
||||||
|
↑
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={matches.length === 0}
|
||||||
|
onClick={() => moveToMatch(matchIndex + 1)}
|
||||||
|
aria-label="Next match"
|
||||||
|
title="Next match"
|
||||||
|
>
|
||||||
|
↓
|
||||||
|
</button>
|
||||||
|
{matchIndex >= 0 && (
|
||||||
|
<span className="office-find__count" aria-live="polite">
|
||||||
|
{matchIndex + 1} of {matches.length}
|
||||||
|
{searchTruncated ? "+" : ""}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="office-viewer-status" aria-live="polite">
|
||||||
|
<span>
|
||||||
|
{loading
|
||||||
|
? "Parsing locally…"
|
||||||
|
: error || !model
|
||||||
|
? "Rendering stopped"
|
||||||
|
: "Rendered locally"}
|
||||||
|
</span>
|
||||||
|
{model && (
|
||||||
|
<span>
|
||||||
|
{model.assets.length} embedded{" "}
|
||||||
|
{model.assets.length === 1 ? "image" : "images"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{elapsed && <span>{elapsed}</span>}
|
||||||
|
<span>Isolated OpenDocument reader</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="office-inline-alert" role="alert">
|
||||||
|
<span>{error}</span>
|
||||||
|
<button type="button" onClick={() => setError(null)}>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{model && model.warnings.length > 0 && (
|
||||||
|
<details className="odf-warnings">
|
||||||
|
<summary>
|
||||||
|
{model.warnings.length} document{" "}
|
||||||
|
{model.warnings.length === 1 ? "notice" : "notices"}
|
||||||
|
</summary>
|
||||||
|
<ul>
|
||||||
|
{model.warnings.map((warning, warningIndex) => (
|
||||||
|
<li key={`${warning}-${warningIndex}`}>{warning}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
ref={stageRef}
|
||||||
|
className={`office-render-stage office-render-stage--${format} odf-render-stage`}
|
||||||
|
aria-busy={loading}
|
||||||
|
>
|
||||||
|
{ready && (
|
||||||
|
<div
|
||||||
|
className="odf-scaled-content"
|
||||||
|
style={{
|
||||||
|
transform: `scale(${zoom})`,
|
||||||
|
transformOrigin: "top center",
|
||||||
|
width: `${100 / zoom}%`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{ready.model.format === "odt" ? (
|
||||||
|
<OdtDocumentView
|
||||||
|
document={ready.model}
|
||||||
|
assetUrls={ready.assetUrls}
|
||||||
|
resolveStyle={resolveStyle}
|
||||||
|
activeUnitId={activeMatch?.unitId}
|
||||||
|
/>
|
||||||
|
) : ready.model.format === "ods" ? (
|
||||||
|
<OdsWorkbookView
|
||||||
|
document={ready.model}
|
||||||
|
activeSheetIndex={activeSheet}
|
||||||
|
page={sheetPage}
|
||||||
|
onSheetChange={(next) => {
|
||||||
|
setActiveSheet(next);
|
||||||
|
setSheetPage(0);
|
||||||
|
}}
|
||||||
|
onPageChange={setSheetPage}
|
||||||
|
assetUrls={ready.assetUrls}
|
||||||
|
resolveStyle={resolveStyle}
|
||||||
|
activeUnitId={activeMatch?.unitId}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<OdpPresentationView
|
||||||
|
document={ready.model}
|
||||||
|
activeSlideIndex={activeSlide}
|
||||||
|
assetUrls={ready.assetUrls}
|
||||||
|
resolveStyle={resolveStyle}
|
||||||
|
activeUnitId={activeMatch?.unitId}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{loading && (
|
||||||
|
<div className="office-loading-overlay" role="status">
|
||||||
|
<span className="office-spinner" aria-hidden="true" />
|
||||||
|
<strong>Parsing {file.name} locally…</strong>
|
||||||
|
<span>
|
||||||
|
The isolated reader enforces package and content limits.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,561 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import type { FormEvent } from "react";
|
||||||
|
import type { OfficeFormat } from "../office/formats";
|
||||||
|
import { describeOoxmlError } from "../office/ooxml-errors";
|
||||||
|
|
||||||
|
type OoxmlFormat = Extract<OfficeFormat, "docx" | "xlsx" | "pptx">;
|
||||||
|
|
||||||
|
interface OoxmlViewerProps {
|
||||||
|
file: File;
|
||||||
|
format: OoxmlFormat;
|
||||||
|
onOpenStateChange?: (state: {
|
||||||
|
status: "loading" | "ready" | "error";
|
||||||
|
detail: string;
|
||||||
|
}) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ViewerController {
|
||||||
|
destroy(): void;
|
||||||
|
fitPage(): void | Promise<void>;
|
||||||
|
fitWidth(): void | Promise<void>;
|
||||||
|
getScale(): number;
|
||||||
|
setScale(scale: number): void | Promise<void>;
|
||||||
|
zoomIn(): void | Promise<void>;
|
||||||
|
zoomOut(): void | Promise<void>;
|
||||||
|
findText(
|
||||||
|
query: string,
|
||||||
|
options?: { caseSensitive?: boolean },
|
||||||
|
): Promise<unknown[]>;
|
||||||
|
findNext(): Promise<unknown | null>;
|
||||||
|
findPrev(): Promise<unknown | null>;
|
||||||
|
clearFind(): void;
|
||||||
|
getResourceMetrics(): Promise<{
|
||||||
|
elapsedMs: number;
|
||||||
|
sourceBytes?: number;
|
||||||
|
usage?: {
|
||||||
|
archiveEntryCount?: number;
|
||||||
|
distinctInflatedBytes?: number;
|
||||||
|
largestInflatedEntryBytes?: number;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NavigationController {
|
||||||
|
previous(): void | Promise<void>;
|
||||||
|
next(): void | Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RESOURCE_LIMITS = {
|
||||||
|
maxArchiveEntryBytes: 64 * 1024 * 1024,
|
||||||
|
maxTotalInflatedBytes: 256 * 1024 * 1024,
|
||||||
|
maxArchiveEntries: 4096,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const ZOOM_MIN = 0.25;
|
||||||
|
const ZOOM_MAX = 4;
|
||||||
|
|
||||||
|
function supportsWorkerRendering(): boolean {
|
||||||
|
return (
|
||||||
|
typeof Worker !== "undefined" && typeof OffscreenCanvas !== "undefined"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OoxmlViewer({
|
||||||
|
file,
|
||||||
|
format,
|
||||||
|
onOpenStateChange,
|
||||||
|
}: OoxmlViewerProps) {
|
||||||
|
const stageRef = useRef<HTMLDivElement>(null);
|
||||||
|
const viewerMountRef = useRef<HTMLDivElement>(null);
|
||||||
|
const viewerRef = useRef<ViewerController | null>(null);
|
||||||
|
const navigationRef = useRef<NavigationController | null>(null);
|
||||||
|
const onOpenStateChangeRef = useRef(onOpenStateChange);
|
||||||
|
const [passwordInput, setPasswordInput] = useState("");
|
||||||
|
const [password, setPassword] = useState<string | undefined>();
|
||||||
|
const [passwordRequired, setPasswordRequired] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [failed, setFailed] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [progress, setProgress] = useState("Preparing the local viewer…");
|
||||||
|
const [position, setPosition] = useState({ index: 0, total: 0 });
|
||||||
|
const [positionNoun, setPositionNoun] = useState(
|
||||||
|
format === "docx" ? "page" : format === "xlsx" ? "sheet" : "slide",
|
||||||
|
);
|
||||||
|
const [scale, setScale] = useState(1);
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [matchCount, setMatchCount] = useState<number | null>(null);
|
||||||
|
const [metrics, setMetrics] = useState<string | null>(null);
|
||||||
|
const generationRef = useRef(0);
|
||||||
|
|
||||||
|
const mode = useMemo<"worker" | "main">(
|
||||||
|
() => (supportsWorkerRendering() ? "worker" : "main"),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onOpenStateChangeRef.current = onOpenStateChange;
|
||||||
|
}, [onOpenStateChange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const generation = generationRef.current + 1;
|
||||||
|
generationRef.current = generation;
|
||||||
|
let active = true;
|
||||||
|
let createdViewer: ViewerController | null = null;
|
||||||
|
let reportedError = false;
|
||||||
|
const viewerMount = viewerMountRef.current;
|
||||||
|
|
||||||
|
const isCurrent = () => active && generationRef.current === generation;
|
||||||
|
const commonOptions = {
|
||||||
|
mode,
|
||||||
|
password,
|
||||||
|
useGoogleFonts: false,
|
||||||
|
workerTimeoutMs: 90_000,
|
||||||
|
resourceLimits: RESOURCE_LIMITS,
|
||||||
|
zoomMin: ZOOM_MIN,
|
||||||
|
zoomMax: ZOOM_MAX,
|
||||||
|
enableHyperlinks: false,
|
||||||
|
onScaleChange: (nextScale: number) => {
|
||||||
|
if (isCurrent()) setScale(nextScale);
|
||||||
|
},
|
||||||
|
onError: (viewerError: Error) => {
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
reportedError = true;
|
||||||
|
const description = describeOoxmlError(viewerError);
|
||||||
|
setLoading(false);
|
||||||
|
setFailed(true);
|
||||||
|
setError(description.message);
|
||||||
|
setPasswordRequired(description.passwordRequired);
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "error",
|
||||||
|
detail: description.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async function open() {
|
||||||
|
await Promise.resolve();
|
||||||
|
if (!isCurrent() || !viewerMount) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
setFailed(false);
|
||||||
|
setPasswordRequired(false);
|
||||||
|
setPosition({ index: 0, total: 0 });
|
||||||
|
setMatchCount(null);
|
||||||
|
setMetrics(null);
|
||||||
|
setProgress(`Reading ${file.name} locally…`);
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "loading",
|
||||||
|
detail: "Reading locally",
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const bufferPromise = file.arrayBuffer();
|
||||||
|
|
||||||
|
if (format === "docx") {
|
||||||
|
const [{ DocxScrollViewer }, buffer] = await Promise.all([
|
||||||
|
import("@silurus/ooxml/docx"),
|
||||||
|
bufferPromise,
|
||||||
|
]);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
const viewer = new DocxScrollViewer(viewerMount, {
|
||||||
|
...commonOptions,
|
||||||
|
enableTextSelection: true,
|
||||||
|
comments: true,
|
||||||
|
enableElementSelection: true,
|
||||||
|
refitOnResize: true,
|
||||||
|
progressiveLayout: true,
|
||||||
|
sliceLayout: true,
|
||||||
|
onLayoutPartial: ({ availableUnits, totalUnits }) => {
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
setProgress(
|
||||||
|
totalUnits
|
||||||
|
? `Laying out page ${availableUnits} of ${totalUnits}…`
|
||||||
|
: `Laying out page ${availableUnits}…`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onVisiblePageChange: (index, total) => {
|
||||||
|
if (isCurrent()) setPosition({ index, total });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
createdViewer = viewer;
|
||||||
|
viewerRef.current = viewer;
|
||||||
|
const scrollToPage = (target: number) => {
|
||||||
|
setPosition((current) => ({ index: target, total: current.total }));
|
||||||
|
void viewer.scrollToPage(target, { behavior: "auto" });
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (isCurrent())
|
||||||
|
void viewer.scrollToPage(target, { behavior: "auto" });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
navigationRef.current = {
|
||||||
|
previous: () =>
|
||||||
|
scrollToPage(Math.max(0, viewer.topVisiblePage - 1)),
|
||||||
|
next: () =>
|
||||||
|
scrollToPage(
|
||||||
|
Math.min(viewer.pageCount - 1, viewer.topVisiblePage + 1),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
setPositionNoun("page");
|
||||||
|
await viewer.load(buffer);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
setPosition({
|
||||||
|
index: viewer.topVisiblePage,
|
||||||
|
total: viewer.pageCount,
|
||||||
|
});
|
||||||
|
viewer.fitWidth();
|
||||||
|
} else if (format === "xlsx") {
|
||||||
|
const [{ XlsxViewer }, buffer] = await Promise.all([
|
||||||
|
import("@silurus/ooxml/xlsx"),
|
||||||
|
bufferPromise,
|
||||||
|
]);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
const viewer = new XlsxViewer(viewerMount, {
|
||||||
|
...commonOptions,
|
||||||
|
resizable: true,
|
||||||
|
showScrollbars: true,
|
||||||
|
showZoomSlider: false,
|
||||||
|
enableElementSelection: true,
|
||||||
|
hiddenSheetMode: "dim",
|
||||||
|
onReady: (sheetNames) => {
|
||||||
|
if (isCurrent())
|
||||||
|
setPosition((current) => ({
|
||||||
|
index: current.index,
|
||||||
|
total: sheetNames.length,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
onSheetChange: (index, total) => {
|
||||||
|
if (isCurrent()) setPosition({ index, total });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
createdViewer = viewer;
|
||||||
|
viewerRef.current = viewer;
|
||||||
|
navigationRef.current = {
|
||||||
|
previous: () => viewer.prevSheet(),
|
||||||
|
next: () => viewer.nextSheet(),
|
||||||
|
};
|
||||||
|
setPositionNoun("sheet");
|
||||||
|
await viewer.load(buffer);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
setPosition({ index: viewer.sheetIndex, total: viewer.sheetCount });
|
||||||
|
viewer.fitPage();
|
||||||
|
} else {
|
||||||
|
const [{ PptxScrollViewer }, buffer] = await Promise.all([
|
||||||
|
import("@silurus/ooxml/pptx"),
|
||||||
|
bufferPromise,
|
||||||
|
]);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
const viewer = new PptxScrollViewer(viewerMount, {
|
||||||
|
...commonOptions,
|
||||||
|
enableTextSelection: true,
|
||||||
|
enableElementSelection: true,
|
||||||
|
comments: true,
|
||||||
|
refitOnResize: true,
|
||||||
|
enableMediaPlayback: false,
|
||||||
|
progressiveLayout: true,
|
||||||
|
onLayoutPartial: ({ availableUnits, totalUnits }) => {
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
setProgress(
|
||||||
|
totalUnits
|
||||||
|
? `Preparing slide ${availableUnits} of ${totalUnits}…`
|
||||||
|
: `Preparing slide ${availableUnits}…`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onVisibleSlideChange: (index, total) => {
|
||||||
|
if (isCurrent()) setPosition({ index, total });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
createdViewer = viewer;
|
||||||
|
viewerRef.current = viewer;
|
||||||
|
navigationRef.current = {
|
||||||
|
previous: () =>
|
||||||
|
viewer.scrollToSlide(Math.max(0, viewer.topVisibleSlide - 1), {
|
||||||
|
behavior: "auto",
|
||||||
|
}),
|
||||||
|
next: () =>
|
||||||
|
viewer.scrollToSlide(
|
||||||
|
Math.min(viewer.slideCount - 1, viewer.topVisibleSlide + 1),
|
||||||
|
{ behavior: "auto" },
|
||||||
|
),
|
||||||
|
};
|
||||||
|
setPositionNoun("slide");
|
||||||
|
await viewer.load(buffer);
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
setPosition({
|
||||||
|
index: viewer.topVisibleSlide,
|
||||||
|
total: viewer.slideCount,
|
||||||
|
});
|
||||||
|
viewer.fitPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isCurrent() || !createdViewer || reportedError) return;
|
||||||
|
setScale(createdViewer.getScale());
|
||||||
|
setLoading(false);
|
||||||
|
setProgress("Opened locally");
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "ready",
|
||||||
|
detail: "Opened locally",
|
||||||
|
});
|
||||||
|
|
||||||
|
createdViewer
|
||||||
|
.getResourceMetrics()
|
||||||
|
.then((report) => {
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
const time =
|
||||||
|
report.elapsedMs < 1000
|
||||||
|
? `${Math.round(report.elapsedMs)} ms`
|
||||||
|
: `${(report.elapsedMs / 1000).toFixed(1)} s`;
|
||||||
|
const entries = report.usage?.archiveEntryCount;
|
||||||
|
setMetrics(entries ? `${entries} package parts · ${time}` : time);
|
||||||
|
})
|
||||||
|
.catch(() => undefined);
|
||||||
|
} catch (openError) {
|
||||||
|
if (!isCurrent()) return;
|
||||||
|
const description = describeOoxmlError(openError);
|
||||||
|
setLoading(false);
|
||||||
|
setFailed(true);
|
||||||
|
setError(description.message);
|
||||||
|
setPasswordRequired(description.passwordRequired);
|
||||||
|
onOpenStateChangeRef.current?.({
|
||||||
|
status: "error",
|
||||||
|
detail: description.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void open();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
active = false;
|
||||||
|
navigationRef.current = null;
|
||||||
|
if (viewerRef.current === createdViewer) viewerRef.current = null;
|
||||||
|
createdViewer?.destroy();
|
||||||
|
viewerMount?.replaceChildren();
|
||||||
|
};
|
||||||
|
}, [file, format, mode, password]);
|
||||||
|
|
||||||
|
const run = useCallback(
|
||||||
|
async (operation: (viewer: ViewerController) => void | Promise<void>) => {
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
if (!viewer) return;
|
||||||
|
try {
|
||||||
|
await operation(viewer);
|
||||||
|
setScale(viewer.getScale());
|
||||||
|
} catch (operationError) {
|
||||||
|
setError(describeOoxmlError(operationError).message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const find = useCallback(
|
||||||
|
async (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
const term = query.trim();
|
||||||
|
if (!viewer) return;
|
||||||
|
if (!term) {
|
||||||
|
viewer.clearFind();
|
||||||
|
setMatchCount(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const matches = await viewer.findText(term, { caseSensitive: false });
|
||||||
|
setMatchCount(matches.length);
|
||||||
|
} catch (findError) {
|
||||||
|
setError(describeOoxmlError(findError).message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[query],
|
||||||
|
);
|
||||||
|
|
||||||
|
const retryWithPassword = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!passwordInput) return;
|
||||||
|
setPassword(passwordInput);
|
||||||
|
};
|
||||||
|
|
||||||
|
const percent = Math.round(scale * 100);
|
||||||
|
const canGoBack = position.total > 0 && position.index > 0;
|
||||||
|
const canGoForward =
|
||||||
|
position.total > 0 && position.index + 1 < position.total;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
className="office-viewer"
|
||||||
|
aria-label={`${format.toUpperCase()} viewer`}
|
||||||
|
>
|
||||||
|
<div className="office-viewer-toolbar" aria-label="Viewer controls">
|
||||||
|
<div className="office-viewer-toolbar__group">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={!canGoBack || loading}
|
||||||
|
onClick={() => void navigationRef.current?.previous()}
|
||||||
|
aria-label={`Previous ${positionNoun}`}
|
||||||
|
title={`Previous ${positionNoun}`}
|
||||||
|
>
|
||||||
|
‹
|
||||||
|
</button>
|
||||||
|
<span className="office-position" aria-live="polite">
|
||||||
|
{position.total > 0
|
||||||
|
? `${positionNoun} ${position.index + 1} of ${position.total}`
|
||||||
|
: `${positionNoun} —`}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={!canGoForward || loading}
|
||||||
|
onClick={() => void navigationRef.current?.next()}
|
||||||
|
aria-label={`Next ${positionNoun}`}
|
||||||
|
title={`Next ${positionNoun}`}
|
||||||
|
>
|
||||||
|
›
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="office-viewer-toolbar__group">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => void run((viewer) => viewer.zoomOut())}
|
||||||
|
aria-label="Zoom out"
|
||||||
|
title="Zoom out"
|
||||||
|
>
|
||||||
|
−
|
||||||
|
</button>
|
||||||
|
<span className="office-zoom" aria-live="polite">
|
||||||
|
{percent}%
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => void run((viewer) => viewer.zoomIn())}
|
||||||
|
aria-label="Zoom in"
|
||||||
|
title="Zoom in"
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => void run((viewer) => viewer.fitWidth())}
|
||||||
|
>
|
||||||
|
Fit width
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => void run((viewer) => viewer.fitPage())}
|
||||||
|
>
|
||||||
|
Fit page
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form className="office-find" role="search" onSubmit={find}>
|
||||||
|
<label className="sr-only" htmlFor="office-find-input">
|
||||||
|
Find in file
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="office-find-input"
|
||||||
|
type="search"
|
||||||
|
value={query}
|
||||||
|
onChange={(event) => setQuery(event.currentTarget.value)}
|
||||||
|
placeholder="Find in file"
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
<button type="submit" disabled={loading}>
|
||||||
|
Find
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || !query.trim()}
|
||||||
|
onClick={() => void viewerRef.current?.findPrev()}
|
||||||
|
aria-label="Previous match"
|
||||||
|
title="Previous match"
|
||||||
|
>
|
||||||
|
↑
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="office-icon-button"
|
||||||
|
disabled={loading || !query.trim()}
|
||||||
|
onClick={() => void viewerRef.current?.findNext()}
|
||||||
|
aria-label="Next match"
|
||||||
|
title="Next match"
|
||||||
|
>
|
||||||
|
↓
|
||||||
|
</button>
|
||||||
|
{matchCount !== null && (
|
||||||
|
<span className="office-find__count" aria-live="polite">
|
||||||
|
{matchCount} {matchCount === 1 ? "match" : "matches"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="office-viewer-status" aria-live="polite">
|
||||||
|
<span>
|
||||||
|
{loading
|
||||||
|
? progress
|
||||||
|
: failed
|
||||||
|
? "Rendering stopped"
|
||||||
|
: "Rendered locally"}
|
||||||
|
</span>
|
||||||
|
{metrics && <span>{metrics}</span>}
|
||||||
|
<span>
|
||||||
|
{mode === "worker"
|
||||||
|
? "Isolated worker rendering"
|
||||||
|
: "Compatible rendering"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="office-inline-alert" role="alert">
|
||||||
|
<span>{error}</span>
|
||||||
|
{!passwordRequired && (
|
||||||
|
<button type="button" onClick={() => setError(null)}>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{passwordRequired && (
|
||||||
|
<form className="office-password" onSubmit={retryWithPassword}>
|
||||||
|
<label htmlFor="office-password-input">Document password</label>
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
id="office-password-input"
|
||||||
|
type="password"
|
||||||
|
value={passwordInput}
|
||||||
|
onChange={(event) => setPasswordInput(event.currentTarget.value)}
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<button type="submit" disabled={!passwordInput}>
|
||||||
|
Unlock locally
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p>The password remains in memory only for this open attempt.</p>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
ref={stageRef}
|
||||||
|
className={`office-render-stage office-render-stage--${format}`}
|
||||||
|
aria-busy={loading}
|
||||||
|
>
|
||||||
|
<div ref={viewerMountRef} className="office-viewer-mount" />
|
||||||
|
{loading && (
|
||||||
|
<div className="office-loading-overlay" role="status">
|
||||||
|
<span className="office-spinner" aria-hidden="true" />
|
||||||
|
<strong>{progress}</strong>
|
||||||
|
<span>Nothing leaves this browser.</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useId,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
type ChangeEvent,
|
||||||
|
type DragEvent,
|
||||||
|
} from "react";
|
||||||
|
import {
|
||||||
|
OFFICE_ACCEPT,
|
||||||
|
detectOfficeFormat,
|
||||||
|
familyForFormat,
|
||||||
|
formatBytes,
|
||||||
|
formatLabel,
|
||||||
|
type OfficeFormat,
|
||||||
|
} from "../office/formats";
|
||||||
|
import { OoxmlViewer } from "./OoxmlViewer";
|
||||||
|
import { OdfViewer } from "./OdfViewer";
|
||||||
|
|
||||||
|
const ACCEPTED_FORMATS = [
|
||||||
|
{
|
||||||
|
group: "Documents",
|
||||||
|
formats: ["DOCX", "ODT"],
|
||||||
|
description: "Text, headings, lists, tables, images, comments and notes.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "Spreadsheets",
|
||||||
|
formats: ["XLSX", "ODS"],
|
||||||
|
description: "Sheets, values, formulas, merged ranges, styling and search.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "Presentations",
|
||||||
|
formats: ["PPTX", "ODP"],
|
||||||
|
description: "Slides, shapes, text, images, tables and speaker notes.",
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
interface SelectedOfficeFile {
|
||||||
|
file: File;
|
||||||
|
format: OfficeFormat;
|
||||||
|
identity: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OpenState {
|
||||||
|
status: "loading" | "ready" | "error";
|
||||||
|
detail: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UploadWorkbench() {
|
||||||
|
const inputId = useId();
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const identityRef = useRef(0);
|
||||||
|
const [dragging, setDragging] = useState(false);
|
||||||
|
const [selected, setSelected] = useState<SelectedOfficeFile | null>(null);
|
||||||
|
const [selectionError, setSelectionError] = useState<string | null>(null);
|
||||||
|
const [openState, setOpenState] = useState<OpenState | null>(null);
|
||||||
|
|
||||||
|
const select = useCallback((file: File | undefined) => {
|
||||||
|
if (!file) return;
|
||||||
|
try {
|
||||||
|
const format = detectOfficeFormat(file);
|
||||||
|
identityRef.current += 1;
|
||||||
|
setSelected({ file, format, identity: identityRef.current });
|
||||||
|
setSelectionError(null);
|
||||||
|
setOpenState({ status: "loading", detail: "Reading locally" });
|
||||||
|
} catch (error) {
|
||||||
|
setSelectionError(
|
||||||
|
error instanceof Error ? error.message : "This file cannot be opened.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onInput = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
select(event.currentTarget.files?.[0]);
|
||||||
|
event.currentTarget.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDrop = (event: DragEvent<HTMLElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setDragging(false);
|
||||||
|
select(event.dataTransfer.files[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dragHandlers = {
|
||||||
|
onDragEnter: (event: DragEvent<HTMLElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setDragging(true);
|
||||||
|
},
|
||||||
|
onDragOver: (event: DragEvent<HTMLElement>) => event.preventDefault(),
|
||||||
|
onDragLeave: (event: DragEvent<HTMLElement>) => {
|
||||||
|
if (!event.currentTarget.contains(event.relatedTarget as Node | null))
|
||||||
|
setDragging(false);
|
||||||
|
},
|
||||||
|
onDrop,
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
setSelected(null);
|
||||||
|
setOpenState(null);
|
||||||
|
setSelectionError(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileInput = (
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
id={inputId}
|
||||||
|
data-testid="office-file-input"
|
||||||
|
className="visually-hidden-input"
|
||||||
|
type="file"
|
||||||
|
accept={OFFICE_ACCEPT}
|
||||||
|
onChange={onInput}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
const { file, format, identity } = selected;
|
||||||
|
const family = familyForFormat(format);
|
||||||
|
const isOoxml = format === "docx" || format === "xlsx" || format === "pptx";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main
|
||||||
|
className={`office-workbench office-workbench--open${dragging ? " is-dragging" : ""}`}
|
||||||
|
data-testid="opened-file"
|
||||||
|
{...dragHandlers}
|
||||||
|
>
|
||||||
|
{fileInput}
|
||||||
|
<section className="file-heading" aria-labelledby="opened-file-name">
|
||||||
|
<div className={`file-kind file-kind--${family}`} aria-hidden="true">
|
||||||
|
{format.toUpperCase()}
|
||||||
|
</div>
|
||||||
|
<div className="file-heading__identity">
|
||||||
|
<p className="eyebrow">{formatLabel(format)}</p>
|
||||||
|
<h1 id="opened-file-name">{file.name}</h1>
|
||||||
|
<p>
|
||||||
|
{formatBytes(file.size)} · Read-only · Processed inside this
|
||||||
|
browser
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="file-heading__state" aria-live="polite">
|
||||||
|
<span
|
||||||
|
className={`state-dot state-dot--${openState?.status ?? "loading"}`}
|
||||||
|
/>
|
||||||
|
{openState?.detail ?? "Preparing viewer"}
|
||||||
|
</div>
|
||||||
|
<div className="file-heading__actions">
|
||||||
|
<button type="button" onClick={() => inputRef.current?.click()}>
|
||||||
|
Open another file
|
||||||
|
</button>
|
||||||
|
<button type="button" className="button-secondary" onClick={close}>
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{selectionError && (
|
||||||
|
<div className="office-inline-alert" role="alert">
|
||||||
|
<span>{selectionError}</span>
|
||||||
|
<button type="button" onClick={() => setSelectionError(null)}>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isOoxml ? (
|
||||||
|
<OoxmlViewer
|
||||||
|
key={identity}
|
||||||
|
file={file}
|
||||||
|
format={format}
|
||||||
|
onOpenStateChange={setOpenState}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<OdfViewer
|
||||||
|
key={identity}
|
||||||
|
file={file}
|
||||||
|
format={format}
|
||||||
|
onOpenStateChange={setOpenState}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{dragging && (
|
||||||
|
<div className="drop-replacement" aria-hidden="true">
|
||||||
|
Drop to open this file instead
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="office-workbench">
|
||||||
|
<section className="intro-panel" aria-labelledby="workspace-title">
|
||||||
|
<div>
|
||||||
|
<p className="eyebrow">Local-first office viewer</p>
|
||||||
|
<h1 id="workspace-title">Open an office file</h1>
|
||||||
|
<p className="intro-copy">
|
||||||
|
Read documents, spreadsheets and presentations without uploading
|
||||||
|
them. Processing stays inside this browser.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<span className="privacy-badge">
|
||||||
|
<span aria-hidden="true">●</span> No upload
|
||||||
|
</span>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{selectionError && (
|
||||||
|
<div className="office-inline-alert" role="alert">
|
||||||
|
<span>{selectionError}</span>
|
||||||
|
<button type="button" onClick={() => setSelectionError(null)}>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<section
|
||||||
|
className={`drop-panel${dragging ? " is-dragging" : ""}`}
|
||||||
|
{...dragHandlers}
|
||||||
|
>
|
||||||
|
<div className="document-mark" aria-hidden="true">
|
||||||
|
<span />
|
||||||
|
<span />
|
||||||
|
<span />
|
||||||
|
</div>
|
||||||
|
<h2>Choose or drop a file</h2>
|
||||||
|
<p>
|
||||||
|
The viewer opens a temporary, read-only representation and keeps the
|
||||||
|
original bytes in memory only.
|
||||||
|
</p>
|
||||||
|
<label className="primary-button" htmlFor={inputId}>
|
||||||
|
Open office file
|
||||||
|
</label>
|
||||||
|
{fileInput}
|
||||||
|
<p className="drop-panel__limit">
|
||||||
|
DOCX · ODT · XLSX · ODS · PPTX · ODP · up to 100 MiB
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="format-panel" aria-labelledby="formats-title">
|
||||||
|
<div>
|
||||||
|
<p className="eyebrow">Initial viewing slice</p>
|
||||||
|
<h2 id="formats-title">Open formats and Office Open XML</h2>
|
||||||
|
</div>
|
||||||
|
<div className="format-groups">
|
||||||
|
{ACCEPTED_FORMATS.map(({ group, formats, description }) => (
|
||||||
|
<article key={group}>
|
||||||
|
<h3>{group}</h3>
|
||||||
|
<div className="format-list">
|
||||||
|
{formats.map((format) => (
|
||||||
|
<span key={format}>{format}</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<p>{description}</p>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<p className="scope-note">
|
||||||
|
Legacy binary DOC, XLS and PPT files are a separate compatibility
|
||||||
|
track. Macros, scripts and embedded active content are never run.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,675 @@
|
|||||||
|
import { Fragment, useMemo } from "react";
|
||||||
|
import type { CSSProperties, ElementType, ReactNode } from "react";
|
||||||
|
import type {
|
||||||
|
OdfImage,
|
||||||
|
OdfPresentationDocument,
|
||||||
|
OdfPresentationShape,
|
||||||
|
OdfSpreadsheetCell,
|
||||||
|
OdfSpreadsheetDocument,
|
||||||
|
OdfTextBlock,
|
||||||
|
OdfTextDocument,
|
||||||
|
OdfTextRun,
|
||||||
|
} from "../office/odf";
|
||||||
|
import {
|
||||||
|
MAX_RENDERED_COLUMNS,
|
||||||
|
ODS_PAGE_ROWS,
|
||||||
|
columnLabel,
|
||||||
|
lengthToPixels,
|
||||||
|
sheetRowsForPage,
|
||||||
|
textTableView,
|
||||||
|
toCssLength,
|
||||||
|
type StyleResolver,
|
||||||
|
} from "./odf-viewer-model";
|
||||||
|
|
||||||
|
interface RenderContext {
|
||||||
|
assetUrls: ReadonlyMap<string, string>;
|
||||||
|
resolveStyle: StyleResolver;
|
||||||
|
activeUnitId?: string;
|
||||||
|
onAssetLoad?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TextBlocksProps extends RenderContext {
|
||||||
|
blocks: readonly OdfTextBlock[];
|
||||||
|
prefix: string;
|
||||||
|
searchable?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unitAttributes(
|
||||||
|
id: string,
|
||||||
|
activeUnitId: string | undefined,
|
||||||
|
searchable: boolean,
|
||||||
|
): { "data-odf-unit"?: string; className?: string } {
|
||||||
|
if (!searchable) return {};
|
||||||
|
return {
|
||||||
|
"data-odf-unit": id,
|
||||||
|
className:
|
||||||
|
activeUnitId === id ? "odf-find-unit is-active" : "odf-find-unit",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function TextRuns({
|
||||||
|
runs,
|
||||||
|
resolveStyle,
|
||||||
|
}: {
|
||||||
|
runs: readonly OdfTextRun[];
|
||||||
|
resolveStyle: StyleResolver;
|
||||||
|
}) {
|
||||||
|
return runs.map((run, index) => {
|
||||||
|
const content = <Fragment key={index}>{run.text}</Fragment>;
|
||||||
|
const style = resolveStyle(run.styleName, "text");
|
||||||
|
if (run.link) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
key={index}
|
||||||
|
className="odf-inert-link"
|
||||||
|
style={style}
|
||||||
|
title={`Link disabled in local viewer: ${run.link}`}
|
||||||
|
>
|
||||||
|
{run.text}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Object.keys(style).length > 0)
|
||||||
|
return (
|
||||||
|
<span key={index} style={style}>
|
||||||
|
{run.text}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
return content;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImageContent({
|
||||||
|
image,
|
||||||
|
assetUrls,
|
||||||
|
resolveStyle,
|
||||||
|
onAssetLoad,
|
||||||
|
standalone,
|
||||||
|
}: Pick<RenderContext, "assetUrls" | "resolveStyle" | "onAssetLoad"> & {
|
||||||
|
image: OdfImage;
|
||||||
|
standalone: boolean;
|
||||||
|
}) {
|
||||||
|
const source = assetUrls.get(image.assetId);
|
||||||
|
const imageStyle: CSSProperties = {
|
||||||
|
...resolveStyle(image.styleName, "graphic"),
|
||||||
|
width: toCssLength(image.width),
|
||||||
|
height: toCssLength(image.height),
|
||||||
|
maxWidth: "100%",
|
||||||
|
objectFit: "contain",
|
||||||
|
};
|
||||||
|
const content = source ? (
|
||||||
|
<img
|
||||||
|
src={source}
|
||||||
|
alt={image.alt ?? image.title ?? "Embedded image"}
|
||||||
|
title={image.title}
|
||||||
|
style={imageStyle}
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
draggable={false}
|
||||||
|
onLoad={onAssetLoad}
|
||||||
|
onError={onAssetLoad}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
className="odf-missing-image"
|
||||||
|
role="img"
|
||||||
|
aria-label="Embedded image unavailable"
|
||||||
|
>
|
||||||
|
Image unavailable
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
return standalone ? (
|
||||||
|
<figure className="odf-image">
|
||||||
|
{content}
|
||||||
|
{(image.title || image.alt) && (
|
||||||
|
<figcaption>{image.title ?? image.alt}</figcaption>
|
||||||
|
)}
|
||||||
|
</figure>
|
||||||
|
) : (
|
||||||
|
<span className="odf-inline-image">{content}</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TextTable({
|
||||||
|
block,
|
||||||
|
path,
|
||||||
|
searchable,
|
||||||
|
...context
|
||||||
|
}: RenderContext & {
|
||||||
|
block: Extract<OdfTextBlock, { kind: "table" }>;
|
||||||
|
path: string;
|
||||||
|
searchable: boolean;
|
||||||
|
}) {
|
||||||
|
const view = useMemo(() => textTableView(block), [block]);
|
||||||
|
return (
|
||||||
|
<div className="odf-table-wrap">
|
||||||
|
<table
|
||||||
|
className="odf-text-table"
|
||||||
|
style={context.resolveStyle(block.styleName, "table")}
|
||||||
|
>
|
||||||
|
{block.name && <caption>{block.name}</caption>}
|
||||||
|
<tbody>
|
||||||
|
{view.rows.map((row) => (
|
||||||
|
<tr key={row.rowIndex}>
|
||||||
|
{row.cells.map(({ cell, columnIndex }) => {
|
||||||
|
if (cell.covered) return null;
|
||||||
|
const cellPath = `${path}-r${row.rowIndex}-c${columnIndex}`;
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={columnIndex}
|
||||||
|
colSpan={Math.min(cell.columnSpan, MAX_RENDERED_COLUMNS)}
|
||||||
|
rowSpan={Math.min(cell.rowSpan, 1_000)}
|
||||||
|
style={context.resolveStyle(cell.styleName, "table-cell")}
|
||||||
|
{...unitAttributes(
|
||||||
|
cellPath,
|
||||||
|
context.activeUnitId,
|
||||||
|
searchable,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<TextBlocks
|
||||||
|
blocks={cell.blocks}
|
||||||
|
prefix={cellPath}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{view.truncated && (
|
||||||
|
<p className="odf-render-limit" role="note">
|
||||||
|
This table is larger than the safe display window. Its first 500 rows
|
||||||
|
and up to 256 columns are shown.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TextBlock({
|
||||||
|
block,
|
||||||
|
path,
|
||||||
|
searchable,
|
||||||
|
...context
|
||||||
|
}: RenderContext & {
|
||||||
|
block: OdfTextBlock;
|
||||||
|
path: string;
|
||||||
|
searchable: boolean;
|
||||||
|
}) {
|
||||||
|
const attributes = unitAttributes(path, context.activeUnitId, searchable);
|
||||||
|
if (block.kind === "paragraph") {
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
style={context.resolveStyle(block.styleName, "paragraph")}
|
||||||
|
{...attributes}
|
||||||
|
>
|
||||||
|
<TextRuns runs={block.runs} resolveStyle={context.resolveStyle} />
|
||||||
|
{block.images.map((image, index) => (
|
||||||
|
<ImageContent
|
||||||
|
key={`${image.assetId}-${index}`}
|
||||||
|
image={image}
|
||||||
|
standalone={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (block.kind === "heading") {
|
||||||
|
const Heading = `h${Math.max(1, Math.min(6, block.level))}` as ElementType;
|
||||||
|
return (
|
||||||
|
<Heading
|
||||||
|
style={context.resolveStyle(block.styleName, "paragraph")}
|
||||||
|
{...attributes}
|
||||||
|
>
|
||||||
|
<TextRuns runs={block.runs} resolveStyle={context.resolveStyle} />
|
||||||
|
{block.images.map((image, index) => (
|
||||||
|
<ImageContent
|
||||||
|
key={`${image.assetId}-${index}`}
|
||||||
|
image={image}
|
||||||
|
standalone={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Heading>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (block.kind === "image") {
|
||||||
|
return (
|
||||||
|
<div {...attributes}>
|
||||||
|
<ImageContent image={block} standalone {...context} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (block.kind === "list") {
|
||||||
|
return (
|
||||||
|
<ul
|
||||||
|
className="odf-list"
|
||||||
|
style={context.resolveStyle(block.styleName, "list")}
|
||||||
|
>
|
||||||
|
{block.items.map((item, itemIndex) => (
|
||||||
|
<li key={itemIndex}>
|
||||||
|
<TextBlocks
|
||||||
|
blocks={item.blocks}
|
||||||
|
prefix={`${path}-i${itemIndex}`}
|
||||||
|
searchable={searchable}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<TextTable block={block} path={path} searchable={searchable} {...context} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TextBlocks({
|
||||||
|
blocks,
|
||||||
|
prefix,
|
||||||
|
searchable = true,
|
||||||
|
...context
|
||||||
|
}: TextBlocksProps) {
|
||||||
|
if (blocks.length === 0) return null;
|
||||||
|
return blocks.map((block, index) => (
|
||||||
|
<TextBlock
|
||||||
|
key={`${prefix}-b${index}`}
|
||||||
|
block={block}
|
||||||
|
path={`${prefix}-b${index}`}
|
||||||
|
searchable={searchable}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OdtDocumentView({
|
||||||
|
document,
|
||||||
|
...context
|
||||||
|
}: RenderContext & { document: OdfTextDocument }) {
|
||||||
|
return (
|
||||||
|
<article className="odf-document" aria-label="OpenDocument text contents">
|
||||||
|
{document.metadata.title && (
|
||||||
|
<h1 className="odf-document-title">{document.metadata.title}</h1>
|
||||||
|
)}
|
||||||
|
<TextBlocks blocks={document.blocks} prefix="odt" {...context} />
|
||||||
|
{document.notes.length > 0 && (
|
||||||
|
<section className="odf-notes" aria-label="Document notes">
|
||||||
|
<h2>Notes</h2>
|
||||||
|
<ol>
|
||||||
|
{document.notes.map((note, index) => {
|
||||||
|
const id = `odt-note-${index}`;
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
key={`${note.id ?? "note"}-${index}`}
|
||||||
|
{...unitAttributes(id, context.activeUnitId, true)}
|
||||||
|
>
|
||||||
|
{note.citation && (
|
||||||
|
<span className="odf-note-citation">{note.citation}</span>
|
||||||
|
)}
|
||||||
|
<TextBlocks
|
||||||
|
blocks={note.blocks}
|
||||||
|
prefix={id}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cellDisplay(cell: OdfSpreadsheetCell): string {
|
||||||
|
if (cell.display) return cell.display;
|
||||||
|
return cell.value === undefined ? "" : String(cell.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cellTitle(cell: OdfSpreadsheetCell, address: string): string {
|
||||||
|
const details = [address];
|
||||||
|
if (cell.formula) details.push(`Formula: ${cell.formula}`);
|
||||||
|
if (cell.value !== undefined && String(cell.value) !== cell.display)
|
||||||
|
details.push(`Value: ${String(cell.value)}`);
|
||||||
|
if (cell.annotation?.length) details.push("Includes a comment");
|
||||||
|
return details.join(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OdsWorkbookView({
|
||||||
|
document,
|
||||||
|
activeSheetIndex,
|
||||||
|
page,
|
||||||
|
onSheetChange,
|
||||||
|
onPageChange,
|
||||||
|
...context
|
||||||
|
}: RenderContext & {
|
||||||
|
document: OdfSpreadsheetDocument;
|
||||||
|
activeSheetIndex: number;
|
||||||
|
page: number;
|
||||||
|
onSheetChange: (index: number) => void;
|
||||||
|
onPageChange: (page: number) => void;
|
||||||
|
}) {
|
||||||
|
const sheet = document.sheets[activeSheetIndex];
|
||||||
|
const pageCount = sheet
|
||||||
|
? Math.max(1, Math.ceil(sheet.expandedRowCount / ODS_PAGE_ROWS))
|
||||||
|
: 0;
|
||||||
|
const safePage = Math.min(Math.max(0, page), Math.max(0, pageCount - 1));
|
||||||
|
const rows = useMemo(
|
||||||
|
() => (sheet ? sheetRowsForPage(sheet, safePage) : []),
|
||||||
|
[safePage, sheet],
|
||||||
|
);
|
||||||
|
const lastColumn = Math.max(
|
||||||
|
0,
|
||||||
|
...rows.flatMap((row) => row.cells.map(({ column }) => column)),
|
||||||
|
);
|
||||||
|
const columnCount =
|
||||||
|
rows.length > 0 ? Math.min(MAX_RENDERED_COLUMNS, lastColumn + 1) : 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="odf-workbook">
|
||||||
|
<div
|
||||||
|
className="odf-sheet-tabs"
|
||||||
|
role="tablist"
|
||||||
|
aria-label="Workbook sheets"
|
||||||
|
>
|
||||||
|
{document.sheets.map((item, index) => (
|
||||||
|
<button
|
||||||
|
key={`${item.name}-${index}`}
|
||||||
|
type="button"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={index === activeSheetIndex}
|
||||||
|
className={index === activeSheetIndex ? "is-active" : undefined}
|
||||||
|
onClick={() => onSheetChange(index)}
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
{item.protected && (
|
||||||
|
<span aria-label="protected sheet"> · protected</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{sheet ? (
|
||||||
|
<div
|
||||||
|
className="odf-sheet"
|
||||||
|
role="tabpanel"
|
||||||
|
aria-label={`${sheet.name}, rows ${safePage * ODS_PAGE_ROWS + 1} to ${Math.min(sheet.expandedRowCount, (safePage + 1) * ODS_PAGE_ROWS)}`}
|
||||||
|
>
|
||||||
|
<div className="odf-sheet-page-controls">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={safePage === 0}
|
||||||
|
onClick={() => onPageChange(safePage - 1)}
|
||||||
|
>
|
||||||
|
Previous rows
|
||||||
|
</button>
|
||||||
|
<span>
|
||||||
|
Rows{" "}
|
||||||
|
{sheet.expandedRowCount === 0 ? 0 : safePage * ODS_PAGE_ROWS + 1}–
|
||||||
|
{Math.min(sheet.expandedRowCount, (safePage + 1) * ODS_PAGE_ROWS)}{" "}
|
||||||
|
of {sheet.expandedRowCount}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={safePage + 1 >= pageCount}
|
||||||
|
onClick={() => onPageChange(safePage + 1)}
|
||||||
|
>
|
||||||
|
Next rows
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{rows.length > 0 ? (
|
||||||
|
<div className="odf-sheet-grid-wrap">
|
||||||
|
<table
|
||||||
|
className="odf-sheet-grid"
|
||||||
|
role="grid"
|
||||||
|
aria-rowcount={sheet.expandedRowCount}
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th className="odf-sheet-corner" aria-hidden="true" />
|
||||||
|
{Array.from({ length: columnCount }, (_, column) => (
|
||||||
|
<th key={column} scope="col">
|
||||||
|
{columnLabel(column)}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rows.map((row) => (
|
||||||
|
<tr key={row.rowIndex} aria-rowindex={row.rowIndex + 1}>
|
||||||
|
<th scope="row">{row.rowIndex + 1}</th>
|
||||||
|
{row.cells.map(({ cell, column }) => {
|
||||||
|
if (cell.kind === "covered") return null;
|
||||||
|
const address = `${columnLabel(column)}${row.rowIndex + 1}`;
|
||||||
|
const unitId = `ods-s${activeSheetIndex}-r${row.rowIndex}-c${column}`;
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
key={column}
|
||||||
|
aria-colindex={column + 1}
|
||||||
|
colSpan={Math.min(
|
||||||
|
cell.columnSpan,
|
||||||
|
MAX_RENDERED_COLUMNS - column,
|
||||||
|
)}
|
||||||
|
rowSpan={Math.min(cell.rowSpan, ODS_PAGE_ROWS)}
|
||||||
|
title={cellTitle(cell, address)}
|
||||||
|
style={context.resolveStyle(
|
||||||
|
cell.styleName,
|
||||||
|
"table-cell",
|
||||||
|
)}
|
||||||
|
{...unitAttributes(
|
||||||
|
unitId,
|
||||||
|
context.activeUnitId,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{cell.paragraphs.length > 0 ? (
|
||||||
|
<TextBlocks
|
||||||
|
blocks={cell.paragraphs}
|
||||||
|
prefix={unitId}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
cellDisplay(cell)
|
||||||
|
)}
|
||||||
|
{cell.annotation && cell.annotation.length > 0 && (
|
||||||
|
<details className="odf-cell-annotation">
|
||||||
|
<summary
|
||||||
|
aria-label={`Show comment for ${address}`}
|
||||||
|
>
|
||||||
|
Comment
|
||||||
|
</summary>
|
||||||
|
<TextBlocks
|
||||||
|
blocks={cell.annotation}
|
||||||
|
prefix={`${unitId}-annotation`}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
</details>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{columnCount >= MAX_RENDERED_COLUMNS && (
|
||||||
|
<p className="odf-render-limit" role="note">
|
||||||
|
Columns after {columnLabel(MAX_RENDERED_COLUMNS - 1)} are
|
||||||
|
outside the safe display window.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="odf-empty-scope">This sheet has no populated rows.</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="odf-empty-scope">This workbook contains no sheets.</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_SLIDE_WIDTH = 960;
|
||||||
|
const DEFAULT_SLIDE_HEIGHT = 540;
|
||||||
|
|
||||||
|
function slideSize(shapes: readonly OdfPresentationShape[]): {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
} {
|
||||||
|
let width = DEFAULT_SLIDE_WIDTH;
|
||||||
|
let height = DEFAULT_SLIDE_HEIGHT;
|
||||||
|
const visit = (shape: OdfPresentationShape) => {
|
||||||
|
const x = lengthToPixels(shape.x, DEFAULT_SLIDE_WIDTH) ?? 0;
|
||||||
|
const y = lengthToPixels(shape.y, DEFAULT_SLIDE_HEIGHT) ?? 0;
|
||||||
|
const shapeWidth = lengthToPixels(shape.width, DEFAULT_SLIDE_WIDTH) ?? 0;
|
||||||
|
const shapeHeight = lengthToPixels(shape.height, DEFAULT_SLIDE_HEIGHT) ?? 0;
|
||||||
|
width = Math.max(width, Math.min(4_096, x + shapeWidth));
|
||||||
|
height = Math.max(height, Math.min(4_096, y + shapeHeight));
|
||||||
|
shape.children.forEach(visit);
|
||||||
|
};
|
||||||
|
shapes.forEach(visit);
|
||||||
|
return { width, height };
|
||||||
|
}
|
||||||
|
|
||||||
|
function Shape({
|
||||||
|
shape,
|
||||||
|
path,
|
||||||
|
slideWidth,
|
||||||
|
slideHeight,
|
||||||
|
...context
|
||||||
|
}: RenderContext & {
|
||||||
|
shape: OdfPresentationShape;
|
||||||
|
path: string;
|
||||||
|
slideWidth: number;
|
||||||
|
slideHeight: number;
|
||||||
|
}) {
|
||||||
|
const positionedStyle: CSSProperties = {
|
||||||
|
...context.resolveStyle(shape.styleName, "graphic"),
|
||||||
|
position: "absolute",
|
||||||
|
left: lengthToPixels(shape.x, slideWidth) ?? 0,
|
||||||
|
top: lengthToPixels(shape.y, slideHeight) ?? 0,
|
||||||
|
width: lengthToPixels(shape.width, slideWidth),
|
||||||
|
height: lengthToPixels(shape.height, slideHeight),
|
||||||
|
overflow: "hidden",
|
||||||
|
};
|
||||||
|
if (shape.type === "ellipse") positionedStyle.borderRadius = "50%";
|
||||||
|
if (shape.type === "line") {
|
||||||
|
positionedStyle.height = positionedStyle.height ?? 1;
|
||||||
|
positionedStyle.borderTop =
|
||||||
|
positionedStyle.borderTop ?? "1px solid currentColor";
|
||||||
|
}
|
||||||
|
const label = shape.name ?? `${shape.type} shape`;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`odf-shape odf-shape--${shape.type}`}
|
||||||
|
style={positionedStyle}
|
||||||
|
aria-label={label}
|
||||||
|
{...unitAttributes(path, context.activeUnitId, true)}
|
||||||
|
>
|
||||||
|
{shape.image && (
|
||||||
|
<ImageContent image={shape.image} standalone={false} {...context} />
|
||||||
|
)}
|
||||||
|
{shape.table && (
|
||||||
|
<TextTable
|
||||||
|
block={shape.table}
|
||||||
|
path={`${path}-table`}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<TextBlocks
|
||||||
|
blocks={shape.blocks}
|
||||||
|
prefix={path}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
{shape.children.map((child, index) => (
|
||||||
|
<Shape
|
||||||
|
key={`${child.id}-${index}`}
|
||||||
|
shape={child}
|
||||||
|
path={`${path}-s${index}`}
|
||||||
|
slideWidth={slideWidth}
|
||||||
|
slideHeight={slideHeight}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OdpPresentationView({
|
||||||
|
document,
|
||||||
|
activeSlideIndex,
|
||||||
|
...context
|
||||||
|
}: RenderContext & {
|
||||||
|
document: OdfPresentationDocument;
|
||||||
|
activeSlideIndex: number;
|
||||||
|
}) {
|
||||||
|
const slide = document.slides[activeSlideIndex];
|
||||||
|
const size = useMemo(() => slideSize(slide?.shapes ?? []), [slide]);
|
||||||
|
if (!slide)
|
||||||
|
return (
|
||||||
|
<p className="odf-empty-scope">This presentation contains no slides.</p>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article
|
||||||
|
className="odf-presentation"
|
||||||
|
aria-label={`Slide ${activeSlideIndex + 1}: ${slide.name}`}
|
||||||
|
>
|
||||||
|
<header className="odf-slide-heading">
|
||||||
|
<span>Slide {activeSlideIndex + 1}</span>
|
||||||
|
<strong>{slide.name}</strong>
|
||||||
|
</header>
|
||||||
|
<div
|
||||||
|
className="odf-slide"
|
||||||
|
style={{
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
aspectRatio: `${size.width} / ${size.height}`,
|
||||||
|
...context.resolveStyle(slide.styleName, "drawing-page"),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{slide.shapes.map((shape, index) => (
|
||||||
|
<Shape
|
||||||
|
key={`${shape.id}-${index}`}
|
||||||
|
shape={shape}
|
||||||
|
path={`odp-s${activeSlideIndex}-shape${index}`}
|
||||||
|
slideWidth={size.width}
|
||||||
|
slideHeight={size.height}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{slide.notes.length > 0 && (
|
||||||
|
<aside
|
||||||
|
className="odf-slide-notes"
|
||||||
|
aria-label="Speaker notes"
|
||||||
|
{...unitAttributes(
|
||||||
|
`odp-s${activeSlideIndex}-notes`,
|
||||||
|
context.activeUnitId,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<h2>Speaker notes</h2>
|
||||||
|
<TextBlocks
|
||||||
|
blocks={slide.notes}
|
||||||
|
prefix={`odp-s${activeSlideIndex}-notes`}
|
||||||
|
searchable={false}
|
||||||
|
{...context}
|
||||||
|
/>
|
||||||
|
</aside>
|
||||||
|
)}
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OdfRenderedContent = ReactNode;
|
||||||
@@ -0,0 +1,522 @@
|
|||||||
|
import type { CSSProperties } from "react";
|
||||||
|
import type {
|
||||||
|
OdfDocument,
|
||||||
|
OdfLength,
|
||||||
|
OdfPresentationShape,
|
||||||
|
OdfSpreadsheetCell,
|
||||||
|
OdfSpreadsheetSheet,
|
||||||
|
OdfStyle,
|
||||||
|
OdfTextBlock,
|
||||||
|
OdfTextTable,
|
||||||
|
} from "../office/odf";
|
||||||
|
|
||||||
|
export const ODS_PAGE_ROWS = 200;
|
||||||
|
export const MAX_RENDERED_COLUMNS = 256;
|
||||||
|
export const MAX_TEXT_TABLE_ROWS = 500;
|
||||||
|
export const MAX_TEXT_TABLE_CELLS = 20_000;
|
||||||
|
const MAX_SEARCH_MATCHES = 10_000;
|
||||||
|
|
||||||
|
export interface OdfSearchMatch {
|
||||||
|
scopeIndex: number;
|
||||||
|
unitId: string;
|
||||||
|
rowIndex?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfSearchResult {
|
||||||
|
matches: OdfSearchMatch[];
|
||||||
|
truncated: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExpandedSheetCell {
|
||||||
|
cell: OdfSpreadsheetCell;
|
||||||
|
column: number;
|
||||||
|
repeated: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExpandedSheetRow {
|
||||||
|
rowIndex: number;
|
||||||
|
cells: ExpandedSheetCell[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TextTableViewRow {
|
||||||
|
rowIndex: number;
|
||||||
|
cells: Array<{
|
||||||
|
cell: OdfTextTable["rows"][number]["cells"][number];
|
||||||
|
columnIndex: number;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TextTableView {
|
||||||
|
rows: TextTableViewRow[];
|
||||||
|
truncated: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StyleResolver = (
|
||||||
|
name: string | undefined,
|
||||||
|
family?: string,
|
||||||
|
) => CSSProperties;
|
||||||
|
|
||||||
|
function safeLength(value: string | undefined): string | undefined {
|
||||||
|
if (!value || value.length > 40) return undefined;
|
||||||
|
const trimmed = value.trim().toLowerCase();
|
||||||
|
if (trimmed === "auto") return "auto";
|
||||||
|
const match = /^(-?(?:\d+(?:\.\d+)?|\.\d+))(cm|mm|in|pt|pc|px|%)$/u.exec(
|
||||||
|
trimmed,
|
||||||
|
);
|
||||||
|
if (!match) return undefined;
|
||||||
|
const number = Number(match[1]);
|
||||||
|
const unit = match[2];
|
||||||
|
if (!Number.isFinite(number) || !unit) return undefined;
|
||||||
|
const bound = unit === "%" ? 1_000 : 10_000;
|
||||||
|
return `${Math.max(-bound, Math.min(bound, number))}${unit}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeColor(value: string | undefined): string | undefined {
|
||||||
|
if (!value || value.length > 80) return undefined;
|
||||||
|
const trimmed = value.trim().toLowerCase();
|
||||||
|
if (
|
||||||
|
trimmed === "transparent" ||
|
||||||
|
/^#[0-9a-f]{3,8}$/u.test(trimmed) ||
|
||||||
|
/^rgba?\(\s*[\d.%]+\s*,\s*[\d.%]+\s*,\s*[\d.%]+(?:\s*,\s*[\d.]+)?\s*\)$/u.test(
|
||||||
|
trimmed,
|
||||||
|
) ||
|
||||||
|
/^[a-z]{3,24}$/u.test(trimmed)
|
||||||
|
) {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeBorder(value: string | undefined): string | undefined {
|
||||||
|
if (!value || value.length > 120 || /url|var|calc|[;{}]/iu.test(value))
|
||||||
|
return undefined;
|
||||||
|
const tokens = value.trim().split(/\s+/u);
|
||||||
|
if (tokens.length < 2 || tokens.length > 3) return undefined;
|
||||||
|
const width = tokens.find((token) => safeLength(token) !== undefined);
|
||||||
|
const style = tokens.find((token) =>
|
||||||
|
/^(?:none|solid|dashed|dotted|double)$/u.test(token),
|
||||||
|
);
|
||||||
|
const color = tokens.find((token) => safeColor(token) !== undefined);
|
||||||
|
if (!style) return undefined;
|
||||||
|
return [
|
||||||
|
width ? safeLength(width) : undefined,
|
||||||
|
style,
|
||||||
|
color ? safeColor(color) : undefined,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeFontFamily(value: string | undefined): string | undefined {
|
||||||
|
if (!value || value.length > 160 || /[;{}]/u.test(value)) return undefined;
|
||||||
|
return /^[\p{L}\p{N}\s,'"._-]+$/u.test(value) ? value : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeOpacity(value: string | undefined): number | undefined {
|
||||||
|
if (!value) return undefined;
|
||||||
|
const percent = /^(\d+(?:\.\d+)?)%$/u.exec(value.trim());
|
||||||
|
const number = percent ? Number(percent[1]) / 100 : Number(value);
|
||||||
|
return Number.isFinite(number) ? Math.max(0, Math.min(1, number)) : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function propertiesToCss(
|
||||||
|
properties: Readonly<Record<string, string>>,
|
||||||
|
): CSSProperties {
|
||||||
|
const css: CSSProperties = {};
|
||||||
|
const valueFor = (suffix: string) => {
|
||||||
|
const entry = Object.entries(properties).find(([key]) =>
|
||||||
|
key.endsWith(suffix),
|
||||||
|
);
|
||||||
|
return entry?.[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
css.color = safeColor(valueFor(".fo:color"));
|
||||||
|
css.backgroundColor =
|
||||||
|
safeColor(valueFor(".fo:background-color")) ??
|
||||||
|
safeColor(valueFor(".draw:fill-color"));
|
||||||
|
css.fontSize = safeLength(valueFor(".fo:font-size"));
|
||||||
|
css.fontFamily = safeFontFamily(valueFor(".fo:font-family"));
|
||||||
|
|
||||||
|
const fontWeight = valueFor(".fo:font-weight");
|
||||||
|
if (fontWeight && /^(?:normal|bold|[1-9]00)$/u.test(fontWeight))
|
||||||
|
css.fontWeight = fontWeight as CSSProperties["fontWeight"];
|
||||||
|
const fontStyle = valueFor(".fo:font-style");
|
||||||
|
if (fontStyle && /^(?:normal|italic|oblique)$/u.test(fontStyle))
|
||||||
|
css.fontStyle = fontStyle as CSSProperties["fontStyle"];
|
||||||
|
const textAlign = valueFor(".fo:text-align");
|
||||||
|
if (textAlign && /^(?:start|end|left|right|center|justify)$/u.test(textAlign))
|
||||||
|
css.textAlign = textAlign as CSSProperties["textAlign"];
|
||||||
|
const textTransform = valueFor(".fo:text-transform");
|
||||||
|
if (
|
||||||
|
textTransform &&
|
||||||
|
/^(?:none|capitalize|uppercase|lowercase)$/u.test(textTransform)
|
||||||
|
)
|
||||||
|
css.textTransform = textTransform as CSSProperties["textTransform"];
|
||||||
|
|
||||||
|
const underline = valueFor(".style:text-underline-style");
|
||||||
|
const strike = valueFor(".style:text-line-through-style");
|
||||||
|
if (underline && underline !== "none") css.textDecorationLine = "underline";
|
||||||
|
if (strike && strike !== "none")
|
||||||
|
css.textDecorationLine = css.textDecorationLine
|
||||||
|
? `${css.textDecorationLine} line-through`
|
||||||
|
: "line-through";
|
||||||
|
|
||||||
|
css.marginTop = safeLength(valueFor(".fo:margin-top"));
|
||||||
|
css.marginRight = safeLength(valueFor(".fo:margin-right"));
|
||||||
|
css.marginBottom = safeLength(valueFor(".fo:margin-bottom"));
|
||||||
|
css.marginLeft = safeLength(valueFor(".fo:margin-left"));
|
||||||
|
css.paddingTop = safeLength(valueFor(".fo:padding-top"));
|
||||||
|
css.paddingRight = safeLength(valueFor(".fo:padding-right"));
|
||||||
|
css.paddingBottom = safeLength(valueFor(".fo:padding-bottom"));
|
||||||
|
css.paddingLeft = safeLength(valueFor(".fo:padding-left"));
|
||||||
|
css.letterSpacing = safeLength(valueFor(".fo:letter-spacing"));
|
||||||
|
|
||||||
|
const lineHeight = valueFor(".fo:line-height");
|
||||||
|
if (lineHeight) {
|
||||||
|
const length = safeLength(lineHeight);
|
||||||
|
const scalar = Number(lineHeight);
|
||||||
|
if (length) css.lineHeight = length;
|
||||||
|
else if (Number.isFinite(scalar) && scalar >= 0.5 && scalar <= 10)
|
||||||
|
css.lineHeight = scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
css.border = safeBorder(valueFor(".fo:border"));
|
||||||
|
css.borderTop = safeBorder(valueFor(".fo:border-top"));
|
||||||
|
css.borderRight = safeBorder(valueFor(".fo:border-right"));
|
||||||
|
css.borderBottom = safeBorder(valueFor(".fo:border-bottom"));
|
||||||
|
css.borderLeft = safeBorder(valueFor(".fo:border-left"));
|
||||||
|
css.borderColor = safeColor(valueFor(".svg:stroke-color"));
|
||||||
|
css.borderWidth = safeLength(valueFor(".svg:stroke-width"));
|
||||||
|
css.opacity = safeOpacity(
|
||||||
|
valueFor(".draw:opacity") ?? valueFor(".svg:stroke-opacity"),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const key of Object.keys(css) as Array<keyof CSSProperties>) {
|
||||||
|
if (css[key] === undefined) delete css[key];
|
||||||
|
}
|
||||||
|
return css;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createStyleResolver(
|
||||||
|
styles: readonly OdfStyle[],
|
||||||
|
): StyleResolver {
|
||||||
|
const exact = new Map<string, OdfStyle>();
|
||||||
|
const byName = new Map<string, OdfStyle>();
|
||||||
|
for (const style of styles) {
|
||||||
|
exact.set(`${style.family ?? ""}\0${style.name}`, style);
|
||||||
|
if (!byName.has(style.name)) byName.set(style.name, style);
|
||||||
|
}
|
||||||
|
const cache = new Map<string, CSSProperties>();
|
||||||
|
|
||||||
|
return (name, family) => {
|
||||||
|
if (!name) return {};
|
||||||
|
const cacheKey = `${family ?? ""}\0${name}`;
|
||||||
|
const cached = cache.get(cacheKey);
|
||||||
|
if (cached) return cached;
|
||||||
|
const visited = new Set<string>();
|
||||||
|
const chain: OdfStyle[] = [];
|
||||||
|
let current = exact.get(cacheKey) ?? byName.get(name);
|
||||||
|
while (current && chain.length < 32 && !visited.has(current.name)) {
|
||||||
|
visited.add(current.name);
|
||||||
|
chain.unshift(current);
|
||||||
|
current = current.parentName
|
||||||
|
? (exact.get(
|
||||||
|
`${current.family ?? family ?? ""}\0${current.parentName}`,
|
||||||
|
) ?? byName.get(current.parentName))
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
const result = Object.assign(
|
||||||
|
{},
|
||||||
|
...chain.map((style) => propertiesToCss(style.properties)),
|
||||||
|
);
|
||||||
|
cache.set(cacheKey, result);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toCssLength(length: OdfLength | undefined): string | undefined {
|
||||||
|
if (!length || !Number.isFinite(length.value)) return undefined;
|
||||||
|
const bound = length.unit === "%" ? 1_000 : 10_000;
|
||||||
|
const value = Math.max(-bound, Math.min(bound, length.value));
|
||||||
|
return length.unit === "unitless" ? `${value}px` : `${value}${length.unit}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function lengthToPixels(
|
||||||
|
length: OdfLength | undefined,
|
||||||
|
relativeTo: number,
|
||||||
|
): number | undefined {
|
||||||
|
if (!length || !Number.isFinite(length.value)) return undefined;
|
||||||
|
const factors: Record<
|
||||||
|
Exclude<OdfLength["unit"], "%" | "unitless">,
|
||||||
|
number
|
||||||
|
> = {
|
||||||
|
cm: 96 / 2.54,
|
||||||
|
mm: 96 / 25.4,
|
||||||
|
in: 96,
|
||||||
|
pt: 96 / 72,
|
||||||
|
pc: 16,
|
||||||
|
px: 1,
|
||||||
|
};
|
||||||
|
if (length.unit === "%") return (relativeTo * length.value) / 100;
|
||||||
|
if (length.unit === "unitless") return length.value;
|
||||||
|
return length.value * factors[length.unit];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function textTableView(table: OdfTextTable): TextTableView {
|
||||||
|
const rows: TextTableViewRow[] = [];
|
||||||
|
let renderedCells = 0;
|
||||||
|
let expandedRowIndex = 0;
|
||||||
|
let truncated = false;
|
||||||
|
outer: for (const sourceRow of table.rows) {
|
||||||
|
for (let repeat = 0; repeat < sourceRow.rowRepeat; repeat += 1) {
|
||||||
|
if (rows.length >= MAX_TEXT_TABLE_ROWS) {
|
||||||
|
truncated = true;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
const cells: TextTableViewRow["cells"] = [];
|
||||||
|
let columnIndex = 0;
|
||||||
|
for (const sourceCell of sourceRow.cells) {
|
||||||
|
for (
|
||||||
|
let cellRepeat = 0;
|
||||||
|
cellRepeat < sourceCell.columnRepeat;
|
||||||
|
cellRepeat += 1
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
columnIndex >= MAX_RENDERED_COLUMNS ||
|
||||||
|
renderedCells >= MAX_TEXT_TABLE_CELLS
|
||||||
|
) {
|
||||||
|
truncated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cells.push({ cell: sourceCell, columnIndex });
|
||||||
|
columnIndex += 1;
|
||||||
|
renderedCells += 1;
|
||||||
|
}
|
||||||
|
if (truncated && renderedCells >= MAX_TEXT_TABLE_CELLS) break;
|
||||||
|
}
|
||||||
|
rows.push({ rowIndex: expandedRowIndex, cells });
|
||||||
|
expandedRowIndex += 1;
|
||||||
|
if (renderedCells >= MAX_TEXT_TABLE_CELLS) break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { rows, truncated };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sheetRowsForPage(
|
||||||
|
sheet: OdfSpreadsheetSheet,
|
||||||
|
page: number,
|
||||||
|
): ExpandedSheetRow[] {
|
||||||
|
const start = Math.max(0, page) * ODS_PAGE_ROWS;
|
||||||
|
const end = Math.min(sheet.expandedRowCount, start + ODS_PAGE_ROWS);
|
||||||
|
const result: ExpandedSheetRow[] = [];
|
||||||
|
if (start >= end) return result;
|
||||||
|
|
||||||
|
for (const sourceRow of sheet.rows) {
|
||||||
|
const sourceStart = sourceRow.index;
|
||||||
|
const sourceEnd = sourceStart + sourceRow.rowRepeat;
|
||||||
|
const visibleStart = Math.max(start, sourceStart);
|
||||||
|
const visibleEnd = Math.min(end, sourceEnd);
|
||||||
|
for (let rowIndex = visibleStart; rowIndex < visibleEnd; rowIndex += 1) {
|
||||||
|
const cells: ExpandedSheetCell[] = [];
|
||||||
|
for (const sourceCell of sourceRow.cells) {
|
||||||
|
for (
|
||||||
|
let repeat = 0;
|
||||||
|
repeat < sourceCell.columnRepeat &&
|
||||||
|
sourceCell.column + repeat < MAX_RENDERED_COLUMNS;
|
||||||
|
repeat += 1
|
||||||
|
) {
|
||||||
|
cells.push({
|
||||||
|
cell: sourceCell,
|
||||||
|
column: sourceCell.column + repeat,
|
||||||
|
repeated: repeat > 0 || rowIndex !== sourceStart,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push({ rowIndex, cells });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function columnLabel(column: number): string {
|
||||||
|
let value = column + 1;
|
||||||
|
let result = "";
|
||||||
|
while (value > 0) {
|
||||||
|
value -= 1;
|
||||||
|
result = String.fromCharCode(65 + (value % 26)) + result;
|
||||||
|
value = Math.floor(value / 26);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function flattenBlocks(blocks: readonly OdfTextBlock[]): string {
|
||||||
|
const parts: string[] = [];
|
||||||
|
const visit = (block: OdfTextBlock) => {
|
||||||
|
if (block.kind === "paragraph" || block.kind === "heading") {
|
||||||
|
parts.push(block.text);
|
||||||
|
for (const image of block.images)
|
||||||
|
parts.push(image.alt ?? image.title ?? "");
|
||||||
|
} else if (block.kind === "image") {
|
||||||
|
parts.push(block.alt ?? block.title ?? "");
|
||||||
|
} else if (block.kind === "list") {
|
||||||
|
for (const item of block.items)
|
||||||
|
for (const child of item.blocks) visit(child);
|
||||||
|
} else {
|
||||||
|
for (const row of block.rows)
|
||||||
|
for (const cell of row.cells)
|
||||||
|
for (const child of cell.blocks) visit(child);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (const block of blocks) visit(block);
|
||||||
|
return parts.filter(Boolean).join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function textBlockMatches(
|
||||||
|
blocks: readonly OdfTextBlock[],
|
||||||
|
query: string,
|
||||||
|
scopeIndex: number,
|
||||||
|
prefix: string,
|
||||||
|
add: (text: string, match: OdfSearchMatch) => void,
|
||||||
|
): void {
|
||||||
|
const visit = (block: OdfTextBlock, path: string) => {
|
||||||
|
if (block.kind === "paragraph" || block.kind === "heading") {
|
||||||
|
add(block.text, { scopeIndex, unitId: path });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (block.kind === "image") {
|
||||||
|
add(block.alt ?? block.title ?? "", { scopeIndex, unitId: path });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (block.kind === "list") {
|
||||||
|
block.items.forEach((item, itemIndex) =>
|
||||||
|
item.blocks.forEach((child, childIndex) =>
|
||||||
|
visit(child, `${path}-i${itemIndex}-b${childIndex}`),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const table = textTableView(block);
|
||||||
|
for (const row of table.rows) {
|
||||||
|
for (const { cell, columnIndex } of row.cells) {
|
||||||
|
if (cell.covered) continue;
|
||||||
|
const cellPath = `${path}-r${row.rowIndex}-c${columnIndex}`;
|
||||||
|
add(flattenBlocks(cell.blocks), { scopeIndex, unitId: cellPath });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
blocks.forEach((block, index) => visit(block, `${prefix}-b${index}`));
|
||||||
|
void query;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shapeTextMatches(
|
||||||
|
shape: OdfPresentationShape,
|
||||||
|
scopeIndex: number,
|
||||||
|
path: string,
|
||||||
|
add: (text: string, match: OdfSearchMatch) => void,
|
||||||
|
): void {
|
||||||
|
const parts = [
|
||||||
|
flattenBlocks(shape.blocks),
|
||||||
|
shape.table ? flattenBlocks([shape.table]) : "",
|
||||||
|
shape.image?.alt ?? shape.image?.title ?? "",
|
||||||
|
];
|
||||||
|
add(parts.filter(Boolean).join("\n"), { scopeIndex, unitId: path });
|
||||||
|
shape.children.forEach((child, index) =>
|
||||||
|
shapeTextMatches(child, scopeIndex, `${path}-s${index}`, add),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildSearchResult(
|
||||||
|
document: OdfDocument,
|
||||||
|
rawQuery: string,
|
||||||
|
): OdfSearchResult {
|
||||||
|
const query = rawQuery.trim().toLocaleLowerCase();
|
||||||
|
if (!query) return { matches: [], truncated: false };
|
||||||
|
const matches: OdfSearchMatch[] = [];
|
||||||
|
let truncated = false;
|
||||||
|
const add = (text: string, match: OdfSearchMatch) => {
|
||||||
|
if (truncated || !text) return;
|
||||||
|
const haystack = text.toLocaleLowerCase();
|
||||||
|
let from = 0;
|
||||||
|
while (from <= haystack.length - query.length) {
|
||||||
|
const index = haystack.indexOf(query, from);
|
||||||
|
if (index < 0) break;
|
||||||
|
if (matches.length >= MAX_SEARCH_MATCHES) {
|
||||||
|
truncated = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
matches.push(match);
|
||||||
|
from = index + Math.max(1, query.length);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (document.format === "odt") {
|
||||||
|
textBlockMatches(document.blocks, query, 0, "odt", add);
|
||||||
|
document.notes.forEach((note, index) =>
|
||||||
|
add(flattenBlocks(note.blocks), {
|
||||||
|
scopeIndex: 0,
|
||||||
|
unitId: `odt-note-${index}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else if (document.format === "ods") {
|
||||||
|
outer: for (
|
||||||
|
let sheetIndex = 0;
|
||||||
|
sheetIndex < document.sheets.length;
|
||||||
|
sheetIndex += 1
|
||||||
|
) {
|
||||||
|
const sheet = document.sheets[sheetIndex];
|
||||||
|
if (!sheet) continue;
|
||||||
|
for (const sourceRow of sheet.rows) {
|
||||||
|
if (sourceRow.cells.length === 0) continue;
|
||||||
|
for (
|
||||||
|
let rowRepeat = 0;
|
||||||
|
rowRepeat < sourceRow.rowRepeat;
|
||||||
|
rowRepeat += 1
|
||||||
|
) {
|
||||||
|
const rowIndex = sourceRow.index + rowRepeat;
|
||||||
|
for (const cell of sourceRow.cells) {
|
||||||
|
const text = [
|
||||||
|
...new Set([
|
||||||
|
cell.display,
|
||||||
|
cell.formula ?? "",
|
||||||
|
cell.value === undefined ? "" : String(cell.value),
|
||||||
|
cell.annotation ? flattenBlocks(cell.annotation) : "",
|
||||||
|
]),
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join("\n");
|
||||||
|
for (
|
||||||
|
let repeat = 0;
|
||||||
|
repeat < cell.columnRepeat &&
|
||||||
|
cell.column + repeat < MAX_RENDERED_COLUMNS;
|
||||||
|
repeat += 1
|
||||||
|
) {
|
||||||
|
const column = cell.column + repeat;
|
||||||
|
add(text, {
|
||||||
|
scopeIndex: sheetIndex,
|
||||||
|
rowIndex,
|
||||||
|
unitId: `ods-s${sheetIndex}-r${rowIndex}-c${column}`,
|
||||||
|
});
|
||||||
|
if (truncated) break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
document.slides.forEach((slide, slideIndex) => {
|
||||||
|
slide.shapes.forEach((shape, shapeIndex) =>
|
||||||
|
shapeTextMatches(
|
||||||
|
shape,
|
||||||
|
slideIndex,
|
||||||
|
`odp-s${slideIndex}-shape${shapeIndex}`,
|
||||||
|
add,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
add(flattenBlocks(slide.notes), {
|
||||||
|
scopeIndex: slideIndex,
|
||||||
|
unitId: `odp-s${slideIndex}-notes`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { matches, truncated };
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { StrictMode } from "react";
|
||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { App } from "./App";
|
||||||
|
|
||||||
|
createRoot(document.getElementById("root")!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ("serviceWorker" in navigator && import.meta.env.PROD) {
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
const url = new URL("./sw.js", document.baseURI);
|
||||||
|
void navigator.serviceWorker
|
||||||
|
.register(url, { scope: new URL("./", document.baseURI).pathname })
|
||||||
|
.catch(() => {
|
||||||
|
// Offline installation is progressive enhancement.
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
export const MAX_SOURCE_BYTES = 100 * 1024 * 1024;
|
||||||
|
|
||||||
|
export const OFFICE_ACCEPT = [
|
||||||
|
".docx",
|
||||||
|
".odt",
|
||||||
|
".xlsx",
|
||||||
|
".ods",
|
||||||
|
".pptx",
|
||||||
|
".odp",
|
||||||
|
].join(",");
|
||||||
|
|
||||||
|
export type OfficeFormat = "docx" | "odt" | "xlsx" | "ods" | "pptx" | "odp";
|
||||||
|
export type OfficeFamily = "document" | "spreadsheet" | "presentation";
|
||||||
|
|
||||||
|
const FORMAT_BY_EXTENSION: Record<string, OfficeFormat> = {
|
||||||
|
docx: "docx",
|
||||||
|
odt: "odt",
|
||||||
|
xlsx: "xlsx",
|
||||||
|
ods: "ods",
|
||||||
|
pptx: "pptx",
|
||||||
|
odp: "odp",
|
||||||
|
};
|
||||||
|
|
||||||
|
const LEGACY_EXTENSIONS = new Set(["doc", "dot", "xls", "xlt", "ppt", "pps"]);
|
||||||
|
|
||||||
|
export class OfficeFileError extends Error {
|
||||||
|
readonly code:
|
||||||
|
"empty-file" | "file-too-large" | "legacy-format" | "unsupported-format";
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
code:
|
||||||
|
"empty-file" | "file-too-large" | "legacy-format" | "unsupported-format",
|
||||||
|
) {
|
||||||
|
super(message);
|
||||||
|
this.name = "OfficeFileError";
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extensionOf(name: string): string {
|
||||||
|
const lastDot = name.lastIndexOf(".");
|
||||||
|
return lastDot >= 0 ? name.slice(lastDot + 1).toLowerCase() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detectOfficeFormat(
|
||||||
|
file: Pick<File, "name" | "size">,
|
||||||
|
): OfficeFormat {
|
||||||
|
if (file.size === 0) {
|
||||||
|
throw new OfficeFileError("This file is empty.", "empty-file");
|
||||||
|
}
|
||||||
|
if (file.size > MAX_SOURCE_BYTES) {
|
||||||
|
throw new OfficeFileError(
|
||||||
|
`This first viewer slice accepts files up to ${formatBytes(MAX_SOURCE_BYTES)}.`,
|
||||||
|
"file-too-large",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = extensionOf(file.name);
|
||||||
|
if (LEGACY_EXTENSIONS.has(extension)) {
|
||||||
|
throw new OfficeFileError(
|
||||||
|
`.${extension} is a legacy binary Office format. Convert it to a modern OOXML or OpenDocument file before opening it here.`,
|
||||||
|
"legacy-format",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const format = FORMAT_BY_EXTENSION[extension];
|
||||||
|
if (!format) {
|
||||||
|
throw new OfficeFileError(
|
||||||
|
"Choose a DOCX, ODT, XLSX, ODS, PPTX, or ODP file.",
|
||||||
|
"unsupported-format",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function familyForFormat(format: OfficeFormat): OfficeFamily {
|
||||||
|
if (format === "docx" || format === "odt") return "document";
|
||||||
|
if (format === "xlsx" || format === "ods") return "spreadsheet";
|
||||||
|
return "presentation";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatLabel(format: OfficeFormat): string {
|
||||||
|
const labels: Record<OfficeFormat, string> = {
|
||||||
|
docx: "Word document",
|
||||||
|
odt: "OpenDocument text",
|
||||||
|
xlsx: "Excel workbook",
|
||||||
|
ods: "OpenDocument spreadsheet",
|
||||||
|
pptx: "PowerPoint presentation",
|
||||||
|
odp: "OpenDocument presentation",
|
||||||
|
};
|
||||||
|
return labels[format];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBytes(bytes: number): string {
|
||||||
|
if (bytes < 1024) return `${bytes} B`;
|
||||||
|
const units = ["KiB", "MiB", "GiB"];
|
||||||
|
let value = bytes / 1024;
|
||||||
|
let unit = units[0];
|
||||||
|
for (let index = 1; index < units.length && value >= 1024; index += 1) {
|
||||||
|
value /= 1024;
|
||||||
|
unit = units[index];
|
||||||
|
}
|
||||||
|
return `${value >= 10 ? value.toFixed(1) : value.toFixed(2)} ${unit}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
import type { SafeZipArchive } from "./zip";
|
||||||
|
import { canonicalPackagePath } from "./zip";
|
||||||
|
import type { OdfAsset, OdfParseLimits } from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
|
||||||
|
const MEDIA_TYPES: Readonly<Record<string, string>> = Object.freeze({
|
||||||
|
png: "image/png",
|
||||||
|
jpg: "image/jpeg",
|
||||||
|
jpeg: "image/jpeg",
|
||||||
|
gif: "image/gif",
|
||||||
|
webp: "image/webp",
|
||||||
|
svg: "image/svg+xml",
|
||||||
|
bmp: "image/bmp",
|
||||||
|
tif: "image/tiff",
|
||||||
|
tiff: "image/tiff",
|
||||||
|
});
|
||||||
|
|
||||||
|
export class OdfReadContext {
|
||||||
|
readonly assets: OdfAsset[] = [];
|
||||||
|
readonly warnings: string[] = [];
|
||||||
|
readonly archive: SafeZipArchive;
|
||||||
|
readonly limits: OdfParseLimits;
|
||||||
|
readonly mediaTypes: ReadonlyMap<string, string>;
|
||||||
|
private readonly assetByPath = new Map<string, OdfAsset>();
|
||||||
|
private textChars = 0;
|
||||||
|
private cellCount = 0;
|
||||||
|
private totalAssetBytes = 0;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
archive: SafeZipArchive,
|
||||||
|
limits: OdfParseLimits,
|
||||||
|
mediaTypes: ReadonlyMap<string, string>,
|
||||||
|
) {
|
||||||
|
this.archive = archive;
|
||||||
|
this.limits = limits;
|
||||||
|
this.mediaTypes = mediaTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
consumeText(text: string): string {
|
||||||
|
this.textChars += text.length;
|
||||||
|
if (this.textChars > this.limits.maxTextChars) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`Document text exceeds the ${this.limits.maxTextChars}-character limit`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
consumeCells(count: number): void {
|
||||||
|
if (!Number.isSafeInteger(count) || count < 0) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
"Invalid expanded cell count",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.cellCount += count;
|
||||||
|
if (
|
||||||
|
!Number.isSafeInteger(this.cellCount) ||
|
||||||
|
this.cellCount > this.limits.maxCells
|
||||||
|
) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`Document exceeds the ${this.limits.maxCells}-cell limit`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveAsset(href: string | undefined): OdfAsset {
|
||||||
|
const path = normalizeResourcePath(href);
|
||||||
|
const existing = this.assetByPath.get(path);
|
||||||
|
if (existing) return existing;
|
||||||
|
const storedPath = this.archive.pathLookup.get(path);
|
||||||
|
const bytes = storedPath ? this.archive.entries.get(storedPath) : undefined;
|
||||||
|
if (!bytes || !storedPath || storedPath.endsWith("/")) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
`Referenced package asset does not exist: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (this.assets.length >= this.limits.maxAssets) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`Document exceeds the ${this.limits.maxAssets}-asset limit`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (bytes.byteLength > this.limits.maxAssetBytes) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`Asset exceeds the per-asset size limit: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.totalAssetBytes += bytes.byteLength;
|
||||||
|
if (this.totalAssetBytes > this.limits.maxTotalAssetBytes) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
"Document assets exceed the total asset size limit",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const extension = storedPath.split(".").pop()?.toLowerCase() ?? "";
|
||||||
|
const mediaType =
|
||||||
|
this.mediaTypes.get(path) ||
|
||||||
|
this.mediaTypes.get(storedPath) ||
|
||||||
|
MEDIA_TYPES[extension] ||
|
||||||
|
"application/octet-stream";
|
||||||
|
if (!mediaType.startsWith("image/")) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"external-resource",
|
||||||
|
`Only local image assets may be rendered: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const data = bytes.buffer;
|
||||||
|
const asset: OdfAsset = {
|
||||||
|
id: `asset-${this.assets.length + 1}`,
|
||||||
|
path: storedPath,
|
||||||
|
mediaType,
|
||||||
|
byteLength: data.byteLength,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
this.assets.push(asset);
|
||||||
|
this.assetByPath.set(path, asset);
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeResourcePath(href: string | undefined): string {
|
||||||
|
if (!href)
|
||||||
|
throw new OdfParseError(
|
||||||
|
"external-resource",
|
||||||
|
"An image has no package path",
|
||||||
|
);
|
||||||
|
const trimmed = href.trim();
|
||||||
|
if (
|
||||||
|
!trimmed ||
|
||||||
|
trimmed.startsWith("#") ||
|
||||||
|
trimmed.startsWith("//") ||
|
||||||
|
/^[a-z][a-z0-9+.-]*:/iu.test(trimmed)
|
||||||
|
) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"external-resource",
|
||||||
|
`External or active resource is prohibited: ${href}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const path = trimmed.startsWith("./") ? trimmed.slice(2) : trimmed;
|
||||||
|
return canonicalPackagePath(path);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { parsePreparedOdp } from "./odp";
|
||||||
|
import { parsePreparedOds } from "./ods";
|
||||||
|
import { parsePreparedOdt } from "./odt";
|
||||||
|
import { prepareOdfPackage } from "./package";
|
||||||
|
import type { OdfDocument, OdfParseOptions } from "./types";
|
||||||
|
|
||||||
|
export { DEFAULT_ODF_LIMITS } from "./limits";
|
||||||
|
export { parseOdp } from "./odp";
|
||||||
|
export { parseOds } from "./ods";
|
||||||
|
export { parseOdt } from "./odt";
|
||||||
|
export { OdfParseError } from "./types";
|
||||||
|
export type * from "./types";
|
||||||
|
|
||||||
|
export function parseOpenDocument(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
options: OdfParseOptions = {},
|
||||||
|
): OdfDocument {
|
||||||
|
const prepared = prepareOdfPackage(input, options);
|
||||||
|
if (prepared.format === "odt") return parsePreparedOdt(prepared);
|
||||||
|
if (prepared.format === "ods") return parsePreparedOds(prepared);
|
||||||
|
return parsePreparedOdp(prepared);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function collectOdfTransferables(document: OdfDocument): ArrayBuffer[] {
|
||||||
|
return document.assets.map((asset) => asset.data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import type { OdfParseLimits } from "./types";
|
||||||
|
|
||||||
|
export const DEFAULT_ODF_LIMITS: Readonly<OdfParseLimits> = Object.freeze({
|
||||||
|
maxEntryBytes: 64 * 1024 * 1024,
|
||||||
|
maxTotalBytes: 256 * 1024 * 1024,
|
||||||
|
maxEntries: 4096,
|
||||||
|
maxCells: 250_000,
|
||||||
|
// LibreOffice commonly represents the unused tail of a sheet with repeats
|
||||||
|
// matching the application's full row or column capacity.
|
||||||
|
maxRepeat: 2_000_000,
|
||||||
|
maxXmlDepth: 128,
|
||||||
|
maxXmlNodes: 1_000_000,
|
||||||
|
maxTextChars: 10_000_000,
|
||||||
|
maxAssets: 1024,
|
||||||
|
maxAssetBytes: 64 * 1024 * 1024,
|
||||||
|
maxTotalAssetBytes: 128 * 1024 * 1024,
|
||||||
|
maxCompressionRatio: 1000,
|
||||||
|
});
|
||||||
|
|
||||||
|
export function resolveLimits(
|
||||||
|
overrides: Partial<OdfParseLimits> | undefined,
|
||||||
|
): OdfParseLimits {
|
||||||
|
const limits = { ...DEFAULT_ODF_LIMITS, ...overrides };
|
||||||
|
for (const [name, value] of Object.entries(limits)) {
|
||||||
|
if (!Number.isSafeInteger(value) || value <= 0) {
|
||||||
|
throw new TypeError(`${name} must be a positive safe integer`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return limits;
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import { prepareOdfPackage, type PreparedOdfPackage } from "./package";
|
||||||
|
import { parseFrameImage, parseTextBlocks, parseTextTable } from "./text";
|
||||||
|
import type {
|
||||||
|
OdfParseOptions,
|
||||||
|
OdfPresentationDocument,
|
||||||
|
OdfPresentationShape,
|
||||||
|
OdfPresentationShapeType,
|
||||||
|
OdfPresentationSlide,
|
||||||
|
} from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
import {
|
||||||
|
NS,
|
||||||
|
attribute,
|
||||||
|
childElements,
|
||||||
|
childrenNamed,
|
||||||
|
firstChildNamed,
|
||||||
|
parseLength,
|
||||||
|
type XmlElement,
|
||||||
|
} from "./xml";
|
||||||
|
|
||||||
|
export function parseOdp(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
options: Omit<OdfParseOptions, "expectedFormat"> = {},
|
||||||
|
): OdfPresentationDocument {
|
||||||
|
const prepared = prepareOdfPackage(input, {
|
||||||
|
...options,
|
||||||
|
expectedFormat: "odp",
|
||||||
|
});
|
||||||
|
return parsePreparedOdp(prepared);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePreparedOdp(
|
||||||
|
prepared: PreparedOdfPackage,
|
||||||
|
): OdfPresentationDocument {
|
||||||
|
if (prepared.format !== "odp") {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"Prepared package is not an ODP document",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const body = firstChildNamed(
|
||||||
|
prepared.content.documentElement!,
|
||||||
|
NS.office,
|
||||||
|
"body",
|
||||||
|
);
|
||||||
|
const presentation = body && firstChildNamed(body, NS.office, "presentation");
|
||||||
|
if (!presentation) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"ODP content.xml does not contain an office:presentation document body",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const slides = childrenNamed(presentation, NS.draw, "page").map(
|
||||||
|
(page, index) => parseSlide(page, index, prepared.context),
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
format: "odp",
|
||||||
|
mediaType: prepared.mediaType,
|
||||||
|
metadata: prepared.metadata,
|
||||||
|
styles: prepared.styles,
|
||||||
|
assets: prepared.context.assets,
|
||||||
|
warnings: prepared.context.warnings,
|
||||||
|
slides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseSlide(
|
||||||
|
page: XmlElement,
|
||||||
|
index: number,
|
||||||
|
context: ReturnType<typeof prepareOdfPackage>["context"],
|
||||||
|
): OdfPresentationSlide {
|
||||||
|
const notesElement = firstChildNamed(page, NS.presentation, "notes");
|
||||||
|
const shapes: OdfPresentationShape[] = [];
|
||||||
|
let shapeIndex = 0;
|
||||||
|
for (const element of childElements(page)) {
|
||||||
|
if (element === notesElement || element.namespaceURI !== NS.draw) continue;
|
||||||
|
shapes.push(
|
||||||
|
parseShape(element, `slide-${index + 1}-shape-${++shapeIndex}`, context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name: attribute(page, NS.draw, "name") ?? `Slide ${index + 1}`,
|
||||||
|
styleName: attribute(page, NS.draw, "style-name"),
|
||||||
|
masterPageName: attribute(page, NS.draw, "master-page-name"),
|
||||||
|
layoutName: attribute(
|
||||||
|
page,
|
||||||
|
NS.presentation,
|
||||||
|
"presentation-page-layout-name",
|
||||||
|
),
|
||||||
|
shapes,
|
||||||
|
notes: notesElement ? parseTextBlocks(notesElement, context) : [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseShape(
|
||||||
|
element: XmlElement,
|
||||||
|
fallbackId: string,
|
||||||
|
context: ReturnType<typeof prepareOdfPackage>["context"],
|
||||||
|
): OdfPresentationShape {
|
||||||
|
const image =
|
||||||
|
element.localName === "frame"
|
||||||
|
? parseFrameImage(element, context)
|
||||||
|
: undefined;
|
||||||
|
const textBox = firstChildNamed(element, NS.draw, "text-box");
|
||||||
|
const tableElement =
|
||||||
|
firstChildNamed(element, NS.table, "table") ??
|
||||||
|
(textBox ? firstChildNamed(textBox, NS.table, "table") : undefined);
|
||||||
|
const table = tableElement
|
||||||
|
? parseTextTable(tableElement, context)
|
||||||
|
: undefined;
|
||||||
|
const children: OdfPresentationShape[] = [];
|
||||||
|
if (element.localName === "g") {
|
||||||
|
let index = 0;
|
||||||
|
for (const child of childElements(element)) {
|
||||||
|
if (child.namespaceURI === NS.draw) {
|
||||||
|
children.push(parseShape(child, `${fallbackId}-${++index}`, context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const blocks = textBox
|
||||||
|
? parseTextBlocks(textBox, context).filter(
|
||||||
|
(block) => block.kind !== "table",
|
||||||
|
)
|
||||||
|
: parseTextBlocks(element, context);
|
||||||
|
return {
|
||||||
|
id: attribute(element, NS.draw, "id") ?? fallbackId,
|
||||||
|
type: shapeType(
|
||||||
|
element,
|
||||||
|
image !== undefined,
|
||||||
|
table !== undefined,
|
||||||
|
textBox !== undefined,
|
||||||
|
),
|
||||||
|
name: attribute(element, NS.draw, "name"),
|
||||||
|
styleName: attribute(element, NS.draw, "style-name"),
|
||||||
|
textStyleName: attribute(element, NS.draw, "text-style-name"),
|
||||||
|
layer: attribute(element, NS.draw, "layer"),
|
||||||
|
x: parseLength(attribute(element, NS.svg, "x")),
|
||||||
|
y: parseLength(attribute(element, NS.svg, "y")),
|
||||||
|
width: parseLength(attribute(element, NS.svg, "width")),
|
||||||
|
height: parseLength(attribute(element, NS.svg, "height")),
|
||||||
|
transform: attribute(element, NS.draw, "transform"),
|
||||||
|
blocks,
|
||||||
|
image,
|
||||||
|
table,
|
||||||
|
children,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function shapeType(
|
||||||
|
element: XmlElement,
|
||||||
|
hasImage: boolean,
|
||||||
|
hasTable: boolean,
|
||||||
|
hasTextBox: boolean,
|
||||||
|
): OdfPresentationShapeType {
|
||||||
|
if (hasImage) return "image";
|
||||||
|
if (hasTable) return "table";
|
||||||
|
if (hasTextBox) return "text-box";
|
||||||
|
if (element.localName === "rect") return "rectangle";
|
||||||
|
if (element.localName === "ellipse" || element.localName === "circle")
|
||||||
|
return "ellipse";
|
||||||
|
if (element.localName === "line") return "line";
|
||||||
|
if (element.localName === "custom-shape") return "custom";
|
||||||
|
if (element.localName === "g") return "group";
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
import { prepareOdfPackage, type PreparedOdfPackage } from "./package";
|
||||||
|
import { parseParagraph, parseTextBlocks } from "./text";
|
||||||
|
import type {
|
||||||
|
OdfParseOptions,
|
||||||
|
OdfSpreadsheetCell,
|
||||||
|
OdfSpreadsheetDocument,
|
||||||
|
OdfSpreadsheetRow,
|
||||||
|
OdfSpreadsheetSheet,
|
||||||
|
} from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
import {
|
||||||
|
NS,
|
||||||
|
attribute,
|
||||||
|
boundedRepeat,
|
||||||
|
childElements,
|
||||||
|
childrenNamed,
|
||||||
|
firstChildNamed,
|
||||||
|
positiveSpan,
|
||||||
|
type XmlElement,
|
||||||
|
} from "./xml";
|
||||||
|
|
||||||
|
export function parseOds(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
options: Omit<OdfParseOptions, "expectedFormat"> = {},
|
||||||
|
): OdfSpreadsheetDocument {
|
||||||
|
const prepared = prepareOdfPackage(input, {
|
||||||
|
...options,
|
||||||
|
expectedFormat: "ods",
|
||||||
|
});
|
||||||
|
return parsePreparedOds(prepared);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePreparedOds(
|
||||||
|
prepared: PreparedOdfPackage,
|
||||||
|
): OdfSpreadsheetDocument {
|
||||||
|
if (prepared.format !== "ods") {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"Prepared package is not an ODS document",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const body = firstChildNamed(
|
||||||
|
prepared.content.documentElement!,
|
||||||
|
NS.office,
|
||||||
|
"body",
|
||||||
|
);
|
||||||
|
const spreadsheet = body && firstChildNamed(body, NS.office, "spreadsheet");
|
||||||
|
if (!spreadsheet) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"ODS content.xml does not contain an office:spreadsheet document body",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const sheets = childrenNamed(spreadsheet, NS.table, "table").map(
|
||||||
|
(table, index) => parseSheet(table, index, prepared.context),
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
format: "ods",
|
||||||
|
mediaType: prepared.mediaType,
|
||||||
|
metadata: prepared.metadata,
|
||||||
|
styles: prepared.styles,
|
||||||
|
assets: prepared.context.assets,
|
||||||
|
warnings: prepared.context.warnings,
|
||||||
|
sheets,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseSheet(
|
||||||
|
table: XmlElement,
|
||||||
|
sheetIndex: number,
|
||||||
|
context: ReturnType<typeof prepareOdfPackage>["context"],
|
||||||
|
): OdfSpreadsheetSheet {
|
||||||
|
const rowElements: XmlElement[] = [];
|
||||||
|
collectSheetRows(table, rowElements);
|
||||||
|
let rows: OdfSpreadsheetRow[] = [];
|
||||||
|
let rowIndex = 0;
|
||||||
|
let expandedCellCount = 0;
|
||||||
|
for (const rowElement of rowElements) {
|
||||||
|
const rowRepeat = boundedRepeat(
|
||||||
|
attribute(rowElement, NS.table, "number-rows-repeated"),
|
||||||
|
context.limits,
|
||||||
|
"Repeated spreadsheet row count",
|
||||||
|
);
|
||||||
|
const cells: OdfSpreadsheetCell[] = [];
|
||||||
|
let column = 0;
|
||||||
|
for (const cellElement of childElements(rowElement)) {
|
||||||
|
if (
|
||||||
|
cellElement.namespaceURI !== NS.table ||
|
||||||
|
(cellElement.localName !== "table-cell" &&
|
||||||
|
cellElement.localName !== "covered-table-cell")
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const columnRepeat = boundedRepeat(
|
||||||
|
attribute(cellElement, NS.table, "number-columns-repeated"),
|
||||||
|
context.limits,
|
||||||
|
"Repeated spreadsheet column count",
|
||||||
|
);
|
||||||
|
const cell = parseCell(cellElement, column, columnRepeat, context);
|
||||||
|
cells.push(cell);
|
||||||
|
column += columnRepeat;
|
||||||
|
if (!Number.isSafeInteger(column)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
"Expanded spreadsheet width is too large",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const lastMeaningfulCell = cells.findLastIndex(isMeaningfulCell);
|
||||||
|
cells.splice(lastMeaningfulCell + 1);
|
||||||
|
rows.push({
|
||||||
|
index: rowIndex,
|
||||||
|
rowRepeat,
|
||||||
|
styleName: attribute(rowElement, NS.table, "style-name"),
|
||||||
|
cells,
|
||||||
|
});
|
||||||
|
rowIndex += rowRepeat;
|
||||||
|
if (!Number.isSafeInteger(rowIndex)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
"Expanded spreadsheet row count is too large",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const lastMeaningfulRow = rows.findLastIndex((row) => row.cells.length > 0);
|
||||||
|
rows = rows.slice(0, lastMeaningfulRow + 1);
|
||||||
|
for (const row of rows) {
|
||||||
|
const lastCell = row.cells.at(-1);
|
||||||
|
const representedColumns = lastCell
|
||||||
|
? lastCell.column + lastCell.columnRepeat
|
||||||
|
: 0;
|
||||||
|
const expandedForRow = representedColumns * row.rowRepeat;
|
||||||
|
if (!Number.isSafeInteger(expandedForRow)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
"Expanded spreadsheet cell count is too large",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
context.consumeCells(expandedForRow);
|
||||||
|
expandedCellCount += expandedForRow;
|
||||||
|
}
|
||||||
|
const expandedRowCount = rows.at(-1)
|
||||||
|
? rows.at(-1)!.index + rows.at(-1)!.rowRepeat
|
||||||
|
: 0;
|
||||||
|
return {
|
||||||
|
name: attribute(table, NS.table, "name") ?? `Sheet ${sheetIndex + 1}`,
|
||||||
|
styleName: attribute(table, NS.table, "style-name"),
|
||||||
|
protected: attribute(table, NS.table, "protected") === "true",
|
||||||
|
rows,
|
||||||
|
expandedRowCount,
|
||||||
|
expandedCellCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMeaningfulCell(cell: OdfSpreadsheetCell): boolean {
|
||||||
|
return (
|
||||||
|
cell.kind === "covered" ||
|
||||||
|
cell.columnSpan > 1 ||
|
||||||
|
cell.rowSpan > 1 ||
|
||||||
|
cell.formula !== undefined ||
|
||||||
|
cell.valueType !== undefined ||
|
||||||
|
cell.value !== undefined ||
|
||||||
|
cell.display !== "" ||
|
||||||
|
cell.paragraphs.length > 0 ||
|
||||||
|
(cell.annotation?.length ?? 0) > 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCell(
|
||||||
|
element: XmlElement,
|
||||||
|
column: number,
|
||||||
|
columnRepeat: number,
|
||||||
|
context: ReturnType<typeof prepareOdfPackage>["context"],
|
||||||
|
): OdfSpreadsheetCell {
|
||||||
|
const paragraphs = childrenNamed(element, NS.text, "p").map((paragraph) =>
|
||||||
|
parseParagraph(paragraph, context),
|
||||||
|
);
|
||||||
|
const annotation = firstChildNamed(element, NS.office, "annotation");
|
||||||
|
const display = paragraphs.map((paragraph) => paragraph.text).join("\n");
|
||||||
|
const valueType = attribute(element, NS.office, "value-type");
|
||||||
|
return {
|
||||||
|
kind: element.localName === "covered-table-cell" ? "covered" : "cell",
|
||||||
|
column,
|
||||||
|
columnRepeat,
|
||||||
|
columnSpan: positiveSpan(
|
||||||
|
attribute(element, NS.table, "number-columns-spanned"),
|
||||||
|
"Spreadsheet column span",
|
||||||
|
),
|
||||||
|
rowSpan: positiveSpan(
|
||||||
|
attribute(element, NS.table, "number-rows-spanned"),
|
||||||
|
"Spreadsheet row span",
|
||||||
|
),
|
||||||
|
styleName: attribute(element, NS.table, "style-name"),
|
||||||
|
formula: attribute(element, NS.table, "formula"),
|
||||||
|
valueType,
|
||||||
|
value: parseCellValue(element, valueType, display, context),
|
||||||
|
display,
|
||||||
|
paragraphs,
|
||||||
|
annotation: annotation ? parseTextBlocks(annotation, context) : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCellValue(
|
||||||
|
element: XmlElement,
|
||||||
|
valueType: string | undefined,
|
||||||
|
display: string,
|
||||||
|
context: ReturnType<typeof prepareOdfPackage>["context"],
|
||||||
|
): string | number | boolean | undefined {
|
||||||
|
if (
|
||||||
|
valueType === "float" ||
|
||||||
|
valueType === "percentage" ||
|
||||||
|
valueType === "currency"
|
||||||
|
) {
|
||||||
|
const raw = attribute(element, NS.office, "value");
|
||||||
|
if (raw === undefined) return undefined;
|
||||||
|
const number = Number(raw);
|
||||||
|
return Number.isFinite(number) ? number : raw;
|
||||||
|
}
|
||||||
|
if (valueType === "boolean") {
|
||||||
|
const raw = attribute(element, NS.office, "boolean-value");
|
||||||
|
if (raw === "true") return true;
|
||||||
|
if (raw === "false") return false;
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
if (valueType === "date") return attribute(element, NS.office, "date-value");
|
||||||
|
if (valueType === "time") return attribute(element, NS.office, "time-value");
|
||||||
|
if (valueType === "string") {
|
||||||
|
const value = attribute(element, NS.office, "string-value");
|
||||||
|
return value === undefined || value === display
|
||||||
|
? display
|
||||||
|
: context.consumeText(value);
|
||||||
|
}
|
||||||
|
return display || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectSheetRows(parent: XmlElement, result: XmlElement[]): void {
|
||||||
|
for (const child of childElements(parent)) {
|
||||||
|
if (child.namespaceURI !== NS.table) continue;
|
||||||
|
if (child.localName === "table-row") {
|
||||||
|
result.push(child);
|
||||||
|
} else if (
|
||||||
|
child.localName === "table-header-rows" ||
|
||||||
|
child.localName === "table-row-group" ||
|
||||||
|
child.localName === "table-rows"
|
||||||
|
) {
|
||||||
|
collectSheetRows(child, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { prepareOdfPackage, type PreparedOdfPackage } from "./package";
|
||||||
|
import { collectNotes, parseTextBlocks } from "./text";
|
||||||
|
import type { OdfParseOptions, OdfTextDocument } from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
import { NS, firstChildNamed } from "./xml";
|
||||||
|
|
||||||
|
export function parseOdt(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
options: Omit<OdfParseOptions, "expectedFormat"> = {},
|
||||||
|
): OdfTextDocument {
|
||||||
|
const prepared = prepareOdfPackage(input, {
|
||||||
|
...options,
|
||||||
|
expectedFormat: "odt",
|
||||||
|
});
|
||||||
|
return parsePreparedOdt(prepared);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePreparedOdt(
|
||||||
|
prepared: PreparedOdfPackage,
|
||||||
|
): OdfTextDocument {
|
||||||
|
if (prepared.format !== "odt") {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"Prepared package is not an ODT document",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const body = firstChildNamed(
|
||||||
|
prepared.content.documentElement!,
|
||||||
|
NS.office,
|
||||||
|
"body",
|
||||||
|
);
|
||||||
|
const text = body && firstChildNamed(body, NS.office, "text");
|
||||||
|
if (!text) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"ODT content.xml does not contain an office:text document body",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const blocks = parseTextBlocks(text, prepared.context);
|
||||||
|
return {
|
||||||
|
format: "odt",
|
||||||
|
mediaType: prepared.mediaType,
|
||||||
|
metadata: prepared.metadata,
|
||||||
|
styles: prepared.styles,
|
||||||
|
assets: prepared.context.assets,
|
||||||
|
warnings: prepared.context.warnings,
|
||||||
|
blocks,
|
||||||
|
notes: collectNotes(blocks),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
import { OdfReadContext } from "./context";
|
||||||
|
import { resolveLimits } from "./limits";
|
||||||
|
import type {
|
||||||
|
OdfFormat,
|
||||||
|
OdfMetadata,
|
||||||
|
OdfParseOptions,
|
||||||
|
OdfStyle,
|
||||||
|
} from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
import {
|
||||||
|
NS,
|
||||||
|
attribute,
|
||||||
|
childElements,
|
||||||
|
descendantsNamed,
|
||||||
|
parseXmlPart,
|
||||||
|
type XmlDocument,
|
||||||
|
type XmlElement,
|
||||||
|
} from "./xml";
|
||||||
|
import { openSafeZip, type SafeZipArchive } from "./zip";
|
||||||
|
import { canonicalPackagePath } from "./zip";
|
||||||
|
|
||||||
|
const FORMAT_MEDIA_TYPES: Readonly<Record<OdfFormat, string>> = Object.freeze({
|
||||||
|
odt: "application/vnd.oasis.opendocument.text",
|
||||||
|
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
||||||
|
odp: "application/vnd.oasis.opendocument.presentation",
|
||||||
|
});
|
||||||
|
|
||||||
|
export interface PreparedOdfPackage {
|
||||||
|
format: OdfFormat;
|
||||||
|
mediaType: string;
|
||||||
|
content: XmlDocument;
|
||||||
|
context: OdfReadContext;
|
||||||
|
metadata: OdfMetadata;
|
||||||
|
styles: OdfStyle[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prepareOdfPackage(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
options: OdfParseOptions = {},
|
||||||
|
): PreparedOdfPackage {
|
||||||
|
const limits = resolveLimits(options.limits);
|
||||||
|
const archive = openSafeZip(input, limits);
|
||||||
|
const mimeBytes = requireEntry(archive, "mimetype");
|
||||||
|
let mediaType: string;
|
||||||
|
try {
|
||||||
|
mediaType = new TextDecoder("utf-8", { fatal: true }).decode(mimeBytes);
|
||||||
|
} catch {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
"The ODF mimetype entry is not valid UTF-8",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const format = formatForMediaType(mediaType);
|
||||||
|
const expectedFromName = inferFormatFromName(options.fileName);
|
||||||
|
const expected = options.expectedFormat ?? expectedFromName;
|
||||||
|
if (expected && expected !== format) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
`Package is ${format.toUpperCase()}, but ${expected.toUpperCase()} was expected`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifestBytes = archive.entries.get("META-INF/manifest.xml");
|
||||||
|
const mediaTypes = manifestBytes
|
||||||
|
? parseManifest(manifestBytes, limits, archive)
|
||||||
|
: new Map<string, string>();
|
||||||
|
const declaredRootType = mediaTypes.get("/");
|
||||||
|
if (declaredRootType && declaredRootType !== mediaType) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
`Manifest media type ${declaredRootType} disagrees with ${mediaType}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const context = new OdfReadContext(archive, limits, mediaTypes);
|
||||||
|
if (!manifestBytes)
|
||||||
|
context.warnings.push("Package has no META-INF/manifest.xml");
|
||||||
|
|
||||||
|
const content = parseXmlPart(
|
||||||
|
requireEntry(archive, "content.xml"),
|
||||||
|
"content.xml",
|
||||||
|
limits,
|
||||||
|
);
|
||||||
|
const omittedObjects =
|
||||||
|
descendantsNamed(content.documentElement!, NS.draw, "object").length +
|
||||||
|
descendantsNamed(content.documentElement!, NS.draw, "object-ole").length;
|
||||||
|
if (omittedObjects > 0) {
|
||||||
|
context.warnings.push(
|
||||||
|
`${omittedObjects} embedded ${omittedObjects === 1 ? "object was" : "objects were"} kept inert and omitted`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const metaBytes = archive.entries.get("meta.xml");
|
||||||
|
const metadata = metaBytes
|
||||||
|
? parseMetadata(parseXmlPart(metaBytes, "meta.xml", limits), context)
|
||||||
|
: emptyMetadata();
|
||||||
|
const styleDocuments: XmlDocument[] = [content];
|
||||||
|
const stylesBytes = archive.entries.get("styles.xml");
|
||||||
|
if (stylesBytes)
|
||||||
|
styleDocuments.unshift(parseXmlPart(stylesBytes, "styles.xml", limits));
|
||||||
|
const styles = parseStyles(styleDocuments);
|
||||||
|
return { format, mediaType, content, context, metadata, styles };
|
||||||
|
}
|
||||||
|
|
||||||
|
function requireEntry(
|
||||||
|
archive: SafeZipArchive,
|
||||||
|
path: string,
|
||||||
|
): Uint8Array<ArrayBuffer> {
|
||||||
|
const entry = archive.entries.get(path);
|
||||||
|
if (!entry)
|
||||||
|
throw new OdfParseError(
|
||||||
|
"missing-part",
|
||||||
|
`Required ODF package part is missing: ${path}`,
|
||||||
|
);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatForMediaType(mediaType: string): OdfFormat {
|
||||||
|
for (const [format, expected] of Object.entries(FORMAT_MEDIA_TYPES)) {
|
||||||
|
if (mediaType === expected) return format as OdfFormat;
|
||||||
|
}
|
||||||
|
throw new OdfParseError(
|
||||||
|
"type-mismatch",
|
||||||
|
`Unsupported OpenDocument media type: ${mediaType || "(empty)"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function inferFormatFromName(name: string | undefined): OdfFormat | undefined {
|
||||||
|
if (!name) return undefined;
|
||||||
|
const match = /\.([^.]+)$/u.exec(name.trim().toLowerCase());
|
||||||
|
const extension = match?.[1];
|
||||||
|
return extension === "odt" || extension === "ods" || extension === "odp"
|
||||||
|
? extension
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseManifest(
|
||||||
|
bytes: Uint8Array<ArrayBuffer>,
|
||||||
|
limits: ReturnType<typeof resolveLimits>,
|
||||||
|
archive: SafeZipArchive,
|
||||||
|
): Map<string, string> {
|
||||||
|
const document = parseXmlPart(bytes, "META-INF/manifest.xml", limits);
|
||||||
|
if (
|
||||||
|
descendantsNamed(document.documentElement!, NS.manifest, "encryption-data")
|
||||||
|
.length > 0
|
||||||
|
) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"encrypted",
|
||||||
|
"Encrypted OpenDocument package entries are not supported",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const result = new Map<string, string>();
|
||||||
|
for (const entry of descendantsNamed(
|
||||||
|
document.documentElement!,
|
||||||
|
NS.manifest,
|
||||||
|
"file-entry",
|
||||||
|
)) {
|
||||||
|
const path = attribute(entry, NS.manifest, "full-path");
|
||||||
|
const mediaType = attribute(entry, NS.manifest, "media-type") ?? "";
|
||||||
|
if (!path) continue;
|
||||||
|
const canonicalPath = path === "/" ? "/" : canonicalPackagePath(path);
|
||||||
|
const implicitDirectory =
|
||||||
|
canonicalPath.endsWith("/") &&
|
||||||
|
[...archive.pathLookup.keys()].some((entryPath) =>
|
||||||
|
entryPath.startsWith(canonicalPath),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
path !== "/" &&
|
||||||
|
!archive.pathLookup.has(canonicalPath) &&
|
||||||
|
!implicitDirectory
|
||||||
|
) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
`Manifest references a missing package entry: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
result.set(canonicalPath, mediaType);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function emptyMetadata(): OdfMetadata {
|
||||||
|
return { keywords: [], statistics: {} };
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseMetadata(
|
||||||
|
document: XmlDocument,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfMetadata {
|
||||||
|
const metadata = emptyMetadata();
|
||||||
|
const firstText = (
|
||||||
|
namespace: string,
|
||||||
|
localName: string,
|
||||||
|
): string | undefined => {
|
||||||
|
const element = descendantsNamed(
|
||||||
|
document.documentElement!,
|
||||||
|
namespace,
|
||||||
|
localName,
|
||||||
|
)[0];
|
||||||
|
const value = element?.textContent?.trim();
|
||||||
|
return value ? context.consumeText(value) : undefined;
|
||||||
|
};
|
||||||
|
metadata.title = firstText(NS.dc, "title");
|
||||||
|
metadata.subject = firstText(NS.dc, "subject");
|
||||||
|
metadata.description = firstText(NS.dc, "description");
|
||||||
|
metadata.creator = firstText(NS.dc, "creator");
|
||||||
|
metadata.initialCreator = firstText(NS.meta, "initial-creator");
|
||||||
|
metadata.language = firstText(NS.dc, "language");
|
||||||
|
metadata.createdAt = firstText(NS.meta, "creation-date");
|
||||||
|
metadata.modifiedAt = firstText(NS.dc, "date");
|
||||||
|
metadata.generator = firstText(NS.meta, "generator");
|
||||||
|
metadata.keywords = descendantsNamed(
|
||||||
|
document.documentElement!,
|
||||||
|
NS.meta,
|
||||||
|
"keyword",
|
||||||
|
)
|
||||||
|
.map((element) => element.textContent?.trim() ?? "")
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((value) => context.consumeText(value));
|
||||||
|
const statistic = descendantsNamed(
|
||||||
|
document.documentElement!,
|
||||||
|
NS.meta,
|
||||||
|
"document-statistic",
|
||||||
|
)[0];
|
||||||
|
if (statistic) {
|
||||||
|
for (let index = 0; index < statistic.attributes.length; index += 1) {
|
||||||
|
const item = statistic.attributes.item(index);
|
||||||
|
if (!item || item.namespaceURI !== NS.meta || !/^\d+$/u.test(item.value))
|
||||||
|
continue;
|
||||||
|
const value = Number(item.value);
|
||||||
|
if (Number.isSafeInteger(value) && item.localName) {
|
||||||
|
const key = item.localName.replace(
|
||||||
|
/-([a-z])/gu,
|
||||||
|
(_match, letter: string) => letter.toUpperCase(),
|
||||||
|
);
|
||||||
|
metadata.statistics[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStyles(documents: readonly XmlDocument[]): OdfStyle[] {
|
||||||
|
const styles = new Map<string, OdfStyle>();
|
||||||
|
for (const document of documents) {
|
||||||
|
for (const element of descendantsNamed(
|
||||||
|
document.documentElement!,
|
||||||
|
NS.style,
|
||||||
|
"style",
|
||||||
|
)) {
|
||||||
|
const family = attribute(element, NS.style, "family");
|
||||||
|
const name = attribute(element, NS.style, "name");
|
||||||
|
if (!name) continue;
|
||||||
|
const style: OdfStyle = {
|
||||||
|
name,
|
||||||
|
family,
|
||||||
|
displayName: attribute(element, NS.style, "display-name"),
|
||||||
|
parentName: attribute(element, NS.style, "parent-style-name"),
|
||||||
|
nextName: attribute(element, NS.style, "next-style-name"),
|
||||||
|
listStyleName: attribute(element, NS.style, "list-style-name"),
|
||||||
|
masterPageName: attribute(element, NS.style, "master-page-name"),
|
||||||
|
properties: readStyleProperties(element),
|
||||||
|
};
|
||||||
|
styles.set(`${family ?? ""}\0${name}`, style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [...styles.values()];
|
||||||
|
}
|
||||||
|
|
||||||
|
function readStyleProperties(style: XmlElement): Record<string, string> {
|
||||||
|
const properties: Record<string, string> = {};
|
||||||
|
for (const child of childElements(style)) {
|
||||||
|
if (!child.localName?.endsWith("properties")) continue;
|
||||||
|
for (let index = 0; index < child.attributes.length; index += 1) {
|
||||||
|
const item = child.attributes.item(index);
|
||||||
|
if (!item || item.namespaceURI === "http://www.w3.org/2000/xmlns/")
|
||||||
|
continue;
|
||||||
|
properties[`${child.localName}.${item.nodeName}`] = item.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
import { normalizeResourcePath, OdfReadContext } from "./context";
|
||||||
|
import type {
|
||||||
|
OdfHeading,
|
||||||
|
OdfImage,
|
||||||
|
OdfList,
|
||||||
|
OdfNote,
|
||||||
|
OdfParagraph,
|
||||||
|
OdfTextBlock,
|
||||||
|
OdfTextRun,
|
||||||
|
OdfTextTable,
|
||||||
|
OdfTextTableCell,
|
||||||
|
} from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
import {
|
||||||
|
NS,
|
||||||
|
attribute,
|
||||||
|
boundedRepeat,
|
||||||
|
childElements,
|
||||||
|
childrenNamed,
|
||||||
|
directText,
|
||||||
|
firstChildNamed,
|
||||||
|
parseLength,
|
||||||
|
positiveSpan,
|
||||||
|
type XmlElement,
|
||||||
|
type XmlNode,
|
||||||
|
} from "./xml";
|
||||||
|
|
||||||
|
interface InlineResult {
|
||||||
|
runs: OdfTextRun[];
|
||||||
|
images: OdfImage[];
|
||||||
|
notes: OdfNote[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseTextBlocks(
|
||||||
|
parent: XmlNode,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfTextBlock[] {
|
||||||
|
const blocks: OdfTextBlock[] = [];
|
||||||
|
for (const element of childElements(parent)) {
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "p") {
|
||||||
|
blocks.push(parseParagraph(element, context));
|
||||||
|
} else if (element.namespaceURI === NS.text && element.localName === "h") {
|
||||||
|
blocks.push(parseHeading(element, context));
|
||||||
|
} else if (
|
||||||
|
element.namespaceURI === NS.text &&
|
||||||
|
element.localName === "list"
|
||||||
|
) {
|
||||||
|
blocks.push(parseList(element, context));
|
||||||
|
} else if (
|
||||||
|
element.namespaceURI === NS.table &&
|
||||||
|
element.localName === "table"
|
||||||
|
) {
|
||||||
|
blocks.push(parseTextTable(element, context));
|
||||||
|
} else if (
|
||||||
|
element.namespaceURI === NS.draw &&
|
||||||
|
element.localName === "frame"
|
||||||
|
) {
|
||||||
|
const image = parseFrameImage(element, context);
|
||||||
|
if (image) blocks.push(image);
|
||||||
|
const textBox = firstChildNamed(element, NS.draw, "text-box");
|
||||||
|
if (textBox) blocks.push(...parseTextBlocks(textBox, context));
|
||||||
|
} else if (
|
||||||
|
(element.namespaceURI === NS.text &&
|
||||||
|
(element.localName === "section" ||
|
||||||
|
element.localName === "list-header")) ||
|
||||||
|
(element.namespaceURI === NS.table &&
|
||||||
|
(element.localName === "table-header-rows" ||
|
||||||
|
element.localName === "table-row-group" ||
|
||||||
|
element.localName === "table-rows"))
|
||||||
|
) {
|
||||||
|
blocks.push(...parseTextBlocks(element, context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseParagraph(
|
||||||
|
element: XmlElement,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfParagraph {
|
||||||
|
const inline = parseInline(element, context);
|
||||||
|
return {
|
||||||
|
kind: "paragraph",
|
||||||
|
styleName: attribute(element, NS.text, "style-name"),
|
||||||
|
text: inline.runs.map((run) => run.text).join(""),
|
||||||
|
...inline,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseHeading(
|
||||||
|
element: XmlElement,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfHeading {
|
||||||
|
const inline = parseInline(element, context);
|
||||||
|
const levelValue = attribute(element, NS.text, "outline-level");
|
||||||
|
const level =
|
||||||
|
levelValue && /^\d+$/u.test(levelValue) ? Number(levelValue) : 1;
|
||||||
|
return {
|
||||||
|
kind: "heading",
|
||||||
|
level: Number.isSafeInteger(level) && level >= 1 ? Math.min(level, 10) : 1,
|
||||||
|
styleName: attribute(element, NS.text, "style-name"),
|
||||||
|
text: inline.runs.map((run) => run.text).join(""),
|
||||||
|
...inline,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseInline(
|
||||||
|
parent: XmlNode,
|
||||||
|
context: OdfReadContext,
|
||||||
|
inheritedStyle?: string,
|
||||||
|
inheritedLink?: string,
|
||||||
|
): InlineResult {
|
||||||
|
const result: InlineResult = { runs: [], images: [], notes: [] };
|
||||||
|
const append = (
|
||||||
|
text: string,
|
||||||
|
styleName = inheritedStyle,
|
||||||
|
link = inheritedLink,
|
||||||
|
) => {
|
||||||
|
if (!text) return;
|
||||||
|
context.consumeText(text);
|
||||||
|
const previous = result.runs[result.runs.length - 1];
|
||||||
|
if (
|
||||||
|
previous &&
|
||||||
|
previous.styleName === styleName &&
|
||||||
|
previous.link === link
|
||||||
|
) {
|
||||||
|
previous.text += text;
|
||||||
|
} else {
|
||||||
|
result.runs.push({ text, styleName, link });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (let node = parent.firstChild; node; node = node.nextSibling) {
|
||||||
|
if (node.nodeType === 3 || node.nodeType === 4) {
|
||||||
|
append(node.nodeValue ?? "");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (node.nodeType !== 1) continue;
|
||||||
|
const element = node as XmlElement;
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "s") {
|
||||||
|
const count = boundedRepeat(
|
||||||
|
attribute(element, NS.text, "c"),
|
||||||
|
context.limits,
|
||||||
|
"Repeated space count",
|
||||||
|
);
|
||||||
|
append(" ".repeat(count));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "tab") {
|
||||||
|
append("\t");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
element.namespaceURI === NS.text &&
|
||||||
|
element.localName === "line-break"
|
||||||
|
) {
|
||||||
|
append("\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "note") {
|
||||||
|
const note = parseNote(element, context);
|
||||||
|
result.notes.push(note);
|
||||||
|
if (note.citation) append(note.citation);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (element.namespaceURI === NS.draw && element.localName === "frame") {
|
||||||
|
const image = parseFrameImage(element, context);
|
||||||
|
if (image) result.images.push(image);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let childStyle = inheritedStyle;
|
||||||
|
let childLink = inheritedLink;
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "span") {
|
||||||
|
childStyle = attribute(element, NS.text, "style-name") ?? inheritedStyle;
|
||||||
|
}
|
||||||
|
if (element.namespaceURI === NS.text && element.localName === "a") {
|
||||||
|
childLink = safeHyperlink(attribute(element, NS.xlink, "href"));
|
||||||
|
}
|
||||||
|
const nested = parseInline(element, context, childStyle, childLink);
|
||||||
|
for (const run of nested.runs) {
|
||||||
|
const previous = result.runs[result.runs.length - 1];
|
||||||
|
if (
|
||||||
|
previous &&
|
||||||
|
previous.styleName === run.styleName &&
|
||||||
|
previous.link === run.link
|
||||||
|
) {
|
||||||
|
previous.text += run.text;
|
||||||
|
} else {
|
||||||
|
result.runs.push(run);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.images.push(...nested.images);
|
||||||
|
result.notes.push(...nested.notes);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeHyperlink(href: string | undefined): string | undefined {
|
||||||
|
if (!href) return undefined;
|
||||||
|
const value = href.trim();
|
||||||
|
if (value.startsWith("#") || /^(?:https?:|mailto:)/iu.test(value))
|
||||||
|
return value;
|
||||||
|
if (/^[a-z][a-z0-9+.-]*:/iu.test(value) || value.startsWith("//")) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"external-resource",
|
||||||
|
`Dangerous hyperlink scheme is prohibited: ${href}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return normalizeResourcePath(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNote(element: XmlElement, context: OdfReadContext): OdfNote {
|
||||||
|
const noteClassValue = attribute(element, NS.text, "note-class");
|
||||||
|
const citationElement = firstChildNamed(element, NS.text, "note-citation");
|
||||||
|
const bodyElement = firstChildNamed(element, NS.text, "note-body");
|
||||||
|
const citation = citationElement
|
||||||
|
? (citationElement.textContent ?? "")
|
||||||
|
: undefined;
|
||||||
|
return {
|
||||||
|
id: attribute(element, NS.text, "id"),
|
||||||
|
noteClass: noteClassValue === "endnote" ? "endnote" : "footnote",
|
||||||
|
citation,
|
||||||
|
blocks: bodyElement ? parseTextBlocks(bodyElement, context) : [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseList(element: XmlElement, context: OdfReadContext): OdfList {
|
||||||
|
const items = childrenNamed(element, NS.text, "list-item").map((item) => ({
|
||||||
|
blocks: parseTextBlocks(item, context),
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
kind: "list",
|
||||||
|
styleName: attribute(element, NS.text, "style-name"),
|
||||||
|
items,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseTextTable(
|
||||||
|
element: XmlElement,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfTextTable {
|
||||||
|
const rowElements: XmlElement[] = [];
|
||||||
|
collectRows(element, rowElements);
|
||||||
|
const rows = rowElements.map((row) => {
|
||||||
|
const rowRepeat = boundedRepeat(
|
||||||
|
attribute(row, NS.table, "number-rows-repeated"),
|
||||||
|
context.limits,
|
||||||
|
"Repeated table row count",
|
||||||
|
);
|
||||||
|
const cells: OdfTextTableCell[] = [];
|
||||||
|
let expandedColumns = 0;
|
||||||
|
for (const cell of childElements(row)) {
|
||||||
|
if (
|
||||||
|
cell.namespaceURI !== NS.table ||
|
||||||
|
(cell.localName !== "table-cell" &&
|
||||||
|
cell.localName !== "covered-table-cell")
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const columnRepeat = boundedRepeat(
|
||||||
|
attribute(cell, NS.table, "number-columns-repeated"),
|
||||||
|
context.limits,
|
||||||
|
"Repeated table column count",
|
||||||
|
);
|
||||||
|
expandedColumns += columnRepeat;
|
||||||
|
if (!Number.isSafeInteger(expandedColumns)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
"Expanded table width is too large",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
cells.push({
|
||||||
|
covered: cell.localName === "covered-table-cell",
|
||||||
|
styleName: attribute(cell, NS.table, "style-name"),
|
||||||
|
columnRepeat,
|
||||||
|
columnSpan: positiveSpan(
|
||||||
|
attribute(cell, NS.table, "number-columns-spanned"),
|
||||||
|
"Table column span",
|
||||||
|
),
|
||||||
|
rowSpan: positiveSpan(
|
||||||
|
attribute(cell, NS.table, "number-rows-spanned"),
|
||||||
|
"Table row span",
|
||||||
|
),
|
||||||
|
blocks: parseTextBlocks(cell, context),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
context.consumeCells(expandedColumns * rowRepeat);
|
||||||
|
return {
|
||||||
|
styleName: attribute(row, NS.table, "style-name"),
|
||||||
|
rowRepeat,
|
||||||
|
cells,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
kind: "table",
|
||||||
|
name: attribute(element, NS.table, "name"),
|
||||||
|
styleName: attribute(element, NS.table, "style-name"),
|
||||||
|
rows,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectRows(parent: XmlElement, result: XmlElement[]): void {
|
||||||
|
for (const child of childElements(parent)) {
|
||||||
|
if (child.namespaceURI !== NS.table) continue;
|
||||||
|
if (child.localName === "table-row") {
|
||||||
|
result.push(child);
|
||||||
|
} else if (
|
||||||
|
child.localName === "table-header-rows" ||
|
||||||
|
child.localName === "table-row-group" ||
|
||||||
|
child.localName === "table-rows"
|
||||||
|
) {
|
||||||
|
collectRows(child, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseFrameImage(
|
||||||
|
frame: XmlElement,
|
||||||
|
context: OdfReadContext,
|
||||||
|
): OdfImage | undefined {
|
||||||
|
const image =
|
||||||
|
frame.namespaceURI === NS.draw && frame.localName === "image"
|
||||||
|
? frame
|
||||||
|
: firstChildNamed(frame, NS.draw, "image");
|
||||||
|
if (!image) return undefined;
|
||||||
|
const asset = context.resolveAsset(attribute(image, NS.xlink, "href"));
|
||||||
|
const title =
|
||||||
|
firstChildNamed(frame, NS.svg, "title") ??
|
||||||
|
firstChildNamed(image, NS.svg, "title");
|
||||||
|
const description =
|
||||||
|
firstChildNamed(frame, NS.svg, "desc") ??
|
||||||
|
firstChildNamed(image, NS.svg, "desc");
|
||||||
|
const titleText = title ? directText(title).trim() || undefined : undefined;
|
||||||
|
const altText = description
|
||||||
|
? directText(description).trim() || undefined
|
||||||
|
: undefined;
|
||||||
|
if (titleText) context.consumeText(titleText);
|
||||||
|
if (altText) context.consumeText(altText);
|
||||||
|
return {
|
||||||
|
kind: "image",
|
||||||
|
assetId: asset.id,
|
||||||
|
path: asset.path,
|
||||||
|
mediaType: asset.mediaType,
|
||||||
|
title: titleText,
|
||||||
|
alt: altText,
|
||||||
|
width: parseLength(attribute(frame, NS.svg, "width")),
|
||||||
|
height: parseLength(attribute(frame, NS.svg, "height")),
|
||||||
|
x: parseLength(attribute(frame, NS.svg, "x")),
|
||||||
|
y: parseLength(attribute(frame, NS.svg, "y")),
|
||||||
|
styleName: attribute(frame, NS.draw, "style-name"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function collectNotes(blocks: readonly OdfTextBlock[]): OdfNote[] {
|
||||||
|
const result: OdfNote[] = [];
|
||||||
|
const visit = (block: OdfTextBlock) => {
|
||||||
|
if (block.kind === "paragraph" || block.kind === "heading") {
|
||||||
|
result.push(...block.notes);
|
||||||
|
for (const note of block.notes)
|
||||||
|
for (const child of note.blocks) visit(child);
|
||||||
|
} else if (block.kind === "list") {
|
||||||
|
for (const item of block.items)
|
||||||
|
for (const child of item.blocks) visit(child);
|
||||||
|
} else if (block.kind === "table") {
|
||||||
|
for (const row of block.rows) {
|
||||||
|
for (const cell of row.cells)
|
||||||
|
for (const child of cell.blocks) visit(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (const block of blocks) visit(block);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
export type OdfFormat = "odt" | "ods" | "odp";
|
||||||
|
|
||||||
|
export type OdfErrorCode =
|
||||||
|
| "invalid-zip"
|
||||||
|
| "unsupported-zip"
|
||||||
|
| "limit-exceeded"
|
||||||
|
| "encrypted"
|
||||||
|
| "invalid-path"
|
||||||
|
| "invalid-xml"
|
||||||
|
| "type-mismatch"
|
||||||
|
| "missing-part"
|
||||||
|
| "external-resource"
|
||||||
|
| "invalid-document";
|
||||||
|
|
||||||
|
export class OdfParseError extends Error {
|
||||||
|
readonly code: OdfErrorCode;
|
||||||
|
|
||||||
|
constructor(code: OdfErrorCode, message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "OdfParseError";
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfParseLimits {
|
||||||
|
maxEntryBytes: number;
|
||||||
|
maxTotalBytes: number;
|
||||||
|
maxEntries: number;
|
||||||
|
maxCells: number;
|
||||||
|
maxRepeat: number;
|
||||||
|
maxXmlDepth: number;
|
||||||
|
maxXmlNodes: number;
|
||||||
|
maxTextChars: number;
|
||||||
|
maxAssets: number;
|
||||||
|
maxAssetBytes: number;
|
||||||
|
maxTotalAssetBytes: number;
|
||||||
|
maxCompressionRatio: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfParseOptions {
|
||||||
|
expectedFormat?: OdfFormat;
|
||||||
|
fileName?: string;
|
||||||
|
limits?: Partial<OdfParseLimits>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfMetadata {
|
||||||
|
title?: string;
|
||||||
|
subject?: string;
|
||||||
|
description?: string;
|
||||||
|
creator?: string;
|
||||||
|
initialCreator?: string;
|
||||||
|
language?: string;
|
||||||
|
createdAt?: string;
|
||||||
|
modifiedAt?: string;
|
||||||
|
generator?: string;
|
||||||
|
keywords: string[];
|
||||||
|
statistics: Record<string, number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfStyle {
|
||||||
|
name: string;
|
||||||
|
family?: string;
|
||||||
|
displayName?: string;
|
||||||
|
parentName?: string;
|
||||||
|
nextName?: string;
|
||||||
|
listStyleName?: string;
|
||||||
|
masterPageName?: string;
|
||||||
|
properties: Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfAsset {
|
||||||
|
id: string;
|
||||||
|
path: string;
|
||||||
|
mediaType: string;
|
||||||
|
byteLength: number;
|
||||||
|
data: ArrayBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfLength {
|
||||||
|
value: number;
|
||||||
|
unit: "cm" | "mm" | "in" | "pt" | "pc" | "px" | "%" | "unitless";
|
||||||
|
raw: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfImage {
|
||||||
|
kind: "image";
|
||||||
|
assetId: string;
|
||||||
|
path: string;
|
||||||
|
mediaType: string;
|
||||||
|
alt?: string;
|
||||||
|
title?: string;
|
||||||
|
width?: OdfLength;
|
||||||
|
height?: OdfLength;
|
||||||
|
x?: OdfLength;
|
||||||
|
y?: OdfLength;
|
||||||
|
styleName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfTextRun {
|
||||||
|
text: string;
|
||||||
|
styleName?: string;
|
||||||
|
link?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfParagraph {
|
||||||
|
kind: "paragraph";
|
||||||
|
styleName?: string;
|
||||||
|
text: string;
|
||||||
|
runs: OdfTextRun[];
|
||||||
|
images: OdfImage[];
|
||||||
|
notes: OdfNote[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfHeading {
|
||||||
|
kind: "heading";
|
||||||
|
level: number;
|
||||||
|
styleName?: string;
|
||||||
|
text: string;
|
||||||
|
runs: OdfTextRun[];
|
||||||
|
images: OdfImage[];
|
||||||
|
notes: OdfNote[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfNote {
|
||||||
|
id?: string;
|
||||||
|
noteClass: "footnote" | "endnote";
|
||||||
|
citation?: string;
|
||||||
|
blocks: OdfTextBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfListItem {
|
||||||
|
blocks: OdfTextBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfList {
|
||||||
|
kind: "list";
|
||||||
|
styleName?: string;
|
||||||
|
items: OdfListItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfTextTableCell {
|
||||||
|
covered: boolean;
|
||||||
|
styleName?: string;
|
||||||
|
columnRepeat: number;
|
||||||
|
columnSpan: number;
|
||||||
|
rowSpan: number;
|
||||||
|
blocks: OdfTextBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfTextTableRow {
|
||||||
|
styleName?: string;
|
||||||
|
rowRepeat: number;
|
||||||
|
cells: OdfTextTableCell[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfTextTable {
|
||||||
|
kind: "table";
|
||||||
|
name?: string;
|
||||||
|
styleName?: string;
|
||||||
|
rows: OdfTextTableRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OdfTextBlock =
|
||||||
|
OdfParagraph | OdfHeading | OdfList | OdfTextTable | OdfImage;
|
||||||
|
|
||||||
|
export interface OdfSpreadsheetCell {
|
||||||
|
kind: "cell" | "covered";
|
||||||
|
column: number;
|
||||||
|
columnRepeat: number;
|
||||||
|
columnSpan: number;
|
||||||
|
rowSpan: number;
|
||||||
|
styleName?: string;
|
||||||
|
formula?: string;
|
||||||
|
valueType?: string;
|
||||||
|
value?: string | number | boolean;
|
||||||
|
display: string;
|
||||||
|
paragraphs: OdfParagraph[];
|
||||||
|
annotation?: OdfTextBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfSpreadsheetRow {
|
||||||
|
index: number;
|
||||||
|
rowRepeat: number;
|
||||||
|
styleName?: string;
|
||||||
|
cells: OdfSpreadsheetCell[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfSpreadsheetSheet {
|
||||||
|
name: string;
|
||||||
|
styleName?: string;
|
||||||
|
protected: boolean;
|
||||||
|
rows: OdfSpreadsheetRow[];
|
||||||
|
expandedRowCount: number;
|
||||||
|
expandedCellCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OdfPresentationShapeType =
|
||||||
|
| "text-box"
|
||||||
|
| "image"
|
||||||
|
| "table"
|
||||||
|
| "rectangle"
|
||||||
|
| "ellipse"
|
||||||
|
| "line"
|
||||||
|
| "custom"
|
||||||
|
| "group"
|
||||||
|
| "unknown";
|
||||||
|
|
||||||
|
export interface OdfPresentationShape {
|
||||||
|
id: string;
|
||||||
|
type: OdfPresentationShapeType;
|
||||||
|
name?: string;
|
||||||
|
styleName?: string;
|
||||||
|
textStyleName?: string;
|
||||||
|
layer?: string;
|
||||||
|
x?: OdfLength;
|
||||||
|
y?: OdfLength;
|
||||||
|
width?: OdfLength;
|
||||||
|
height?: OdfLength;
|
||||||
|
transform?: string;
|
||||||
|
blocks: OdfTextBlock[];
|
||||||
|
image?: OdfImage;
|
||||||
|
table?: OdfTextTable;
|
||||||
|
children: OdfPresentationShape[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfPresentationSlide {
|
||||||
|
name: string;
|
||||||
|
styleName?: string;
|
||||||
|
masterPageName?: string;
|
||||||
|
layoutName?: string;
|
||||||
|
shapes: OdfPresentationShape[];
|
||||||
|
notes: OdfTextBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OdfBaseModel {
|
||||||
|
format: OdfFormat;
|
||||||
|
mediaType: string;
|
||||||
|
metadata: OdfMetadata;
|
||||||
|
styles: OdfStyle[];
|
||||||
|
assets: OdfAsset[];
|
||||||
|
warnings: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfTextDocument extends OdfBaseModel {
|
||||||
|
format: "odt";
|
||||||
|
blocks: OdfTextBlock[];
|
||||||
|
notes: OdfNote[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfSpreadsheetDocument extends OdfBaseModel {
|
||||||
|
format: "ods";
|
||||||
|
sheets: OdfSpreadsheetSheet[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfPresentationDocument extends OdfBaseModel {
|
||||||
|
format: "odp";
|
||||||
|
slides: OdfPresentationSlide[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OdfDocument =
|
||||||
|
OdfTextDocument | OdfSpreadsheetDocument | OdfPresentationDocument;
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
import {
|
||||||
|
DOMParser,
|
||||||
|
type Document as XmlDocument,
|
||||||
|
type Element as XmlElement,
|
||||||
|
type Node as XmlNode,
|
||||||
|
} from "@xmldom/xmldom";
|
||||||
|
|
||||||
|
import type { OdfLength, OdfParseLimits } from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
|
||||||
|
export type { XmlDocument, XmlElement, XmlNode };
|
||||||
|
|
||||||
|
export const NS = Object.freeze({
|
||||||
|
office: "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
|
||||||
|
text: "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
|
||||||
|
table: "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
|
||||||
|
draw: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
|
||||||
|
presentation: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0",
|
||||||
|
style: "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
|
||||||
|
fo: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
|
||||||
|
xlink: "http://www.w3.org/1999/xlink",
|
||||||
|
dc: "http://purl.org/dc/elements/1.1/",
|
||||||
|
meta: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
|
||||||
|
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",
|
||||||
|
svg: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",
|
||||||
|
} as const);
|
||||||
|
|
||||||
|
const XML_DECLARATION_ATTACK = /<!\s*(?:DOCTYPE|ENTITY)|<\?xml-stylesheet/iu;
|
||||||
|
|
||||||
|
export function parseXmlPart(
|
||||||
|
bytes: Uint8Array,
|
||||||
|
path: string,
|
||||||
|
limits: OdfParseLimits,
|
||||||
|
): XmlDocument {
|
||||||
|
let source: string;
|
||||||
|
try {
|
||||||
|
source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
||||||
|
} catch {
|
||||||
|
throw new OdfParseError("invalid-xml", `${path} is not valid UTF-8 XML`);
|
||||||
|
}
|
||||||
|
if (XML_DECLARATION_ATTACK.test(source)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-xml",
|
||||||
|
`${path} contains a prohibited DTD, entity, or XML stylesheet`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let document: XmlDocument;
|
||||||
|
try {
|
||||||
|
document = new DOMParser({
|
||||||
|
locator: false,
|
||||||
|
onError(level, message) {
|
||||||
|
throw new Error(`${level}: ${message}`);
|
||||||
|
},
|
||||||
|
}).parseFromString(source, "application/xml");
|
||||||
|
} catch (error) {
|
||||||
|
const detail = error instanceof Error ? `: ${error.message}` : "";
|
||||||
|
throw new OdfParseError("invalid-xml", `Malformed XML in ${path}${detail}`);
|
||||||
|
}
|
||||||
|
if (!document.documentElement) {
|
||||||
|
throw new OdfParseError("invalid-xml", `${path} has no document element`);
|
||||||
|
}
|
||||||
|
validateStructure(
|
||||||
|
document.documentElement,
|
||||||
|
limits.maxXmlDepth,
|
||||||
|
limits.maxXmlNodes,
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
rejectActiveXml(document.documentElement, path);
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStructure(
|
||||||
|
root: XmlElement,
|
||||||
|
maximumDepth: number,
|
||||||
|
maximumNodes: number,
|
||||||
|
path: string,
|
||||||
|
): void {
|
||||||
|
const stack: Array<{ node: XmlNode; depth: number }> = [
|
||||||
|
{ node: root, depth: 1 },
|
||||||
|
];
|
||||||
|
let nodes = 0;
|
||||||
|
while (stack.length > 0) {
|
||||||
|
const current = stack.pop();
|
||||||
|
if (!current) break;
|
||||||
|
nodes += 1;
|
||||||
|
if (nodes > maximumNodes) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`${path} exceeds the XML node limit of ${maximumNodes}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (current.depth > maximumDepth) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`${path} exceeds the XML depth limit of ${maximumDepth}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (
|
||||||
|
let child = current.node.firstChild;
|
||||||
|
child;
|
||||||
|
child = child.nextSibling
|
||||||
|
) {
|
||||||
|
stack.push({
|
||||||
|
node: child,
|
||||||
|
depth: current.depth + (child.nodeType === 1 ? 1 : 0),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rejectActiveXml(root: XmlElement, path: string): void {
|
||||||
|
const prohibited = new Set(["script", "applet", "plugin", "floating-frame"]);
|
||||||
|
const stack = [root];
|
||||||
|
while (stack.length > 0) {
|
||||||
|
const element = stack.pop();
|
||||||
|
if (!element) break;
|
||||||
|
if (prohibited.has(element.localName ?? element.nodeName)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
`${path} contains prohibited active content: ${element.nodeName}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const child of childElements(element)) stack.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function childElements(parent: XmlNode): XmlElement[] {
|
||||||
|
const result: XmlElement[] = [];
|
||||||
|
for (let node = parent.firstChild; node; node = node.nextSibling) {
|
||||||
|
if (node.nodeType === 1) result.push(node as XmlElement);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function childrenNamed(
|
||||||
|
parent: XmlNode,
|
||||||
|
namespace: string,
|
||||||
|
localName: string,
|
||||||
|
): XmlElement[] {
|
||||||
|
return childElements(parent).filter(
|
||||||
|
(element) =>
|
||||||
|
element.namespaceURI === namespace && element.localName === localName,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function firstChildNamed(
|
||||||
|
parent: XmlNode,
|
||||||
|
namespace: string,
|
||||||
|
localName: string,
|
||||||
|
): XmlElement | undefined {
|
||||||
|
return childElements(parent).find(
|
||||||
|
(element) =>
|
||||||
|
element.namespaceURI === namespace && element.localName === localName,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function descendantsNamed(
|
||||||
|
parent: XmlNode,
|
||||||
|
namespace: string,
|
||||||
|
localName: string,
|
||||||
|
): XmlElement[] {
|
||||||
|
const result: XmlElement[] = [];
|
||||||
|
const stack = childElements(parent).reverse();
|
||||||
|
while (stack.length > 0) {
|
||||||
|
const element = stack.pop();
|
||||||
|
if (!element) break;
|
||||||
|
if (element.namespaceURI === namespace && element.localName === localName)
|
||||||
|
result.push(element);
|
||||||
|
const children = childElements(element);
|
||||||
|
for (let index = children.length - 1; index >= 0; index -= 1) {
|
||||||
|
const child = children[index];
|
||||||
|
if (child) stack.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function attribute(
|
||||||
|
element: XmlElement,
|
||||||
|
namespace: string,
|
||||||
|
localName: string,
|
||||||
|
): string | undefined {
|
||||||
|
const value = element.getAttributeNS(namespace, localName);
|
||||||
|
return value === null || value === "" ? undefined : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function attributeAnyNamespace(
|
||||||
|
element: XmlElement,
|
||||||
|
localName: string,
|
||||||
|
): string | undefined {
|
||||||
|
for (let index = 0; index < element.attributes.length; index += 1) {
|
||||||
|
const item = element.attributes.item(index);
|
||||||
|
if (item?.localName === localName && item.value !== "") return item.value;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function boundedRepeat(
|
||||||
|
value: string | undefined,
|
||||||
|
limits: OdfParseLimits,
|
||||||
|
label: string,
|
||||||
|
): number {
|
||||||
|
if (value === undefined) return 1;
|
||||||
|
if (!/^[1-9]\d*$/u.test(value)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
`${label} must be a positive integer`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const repeat = Number(value);
|
||||||
|
if (!Number.isSafeInteger(repeat) || repeat > limits.maxRepeat) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"limit-exceeded",
|
||||||
|
`${label} exceeds the repeat limit of ${limits.maxRepeat}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function positiveSpan(value: string | undefined, label: string): number {
|
||||||
|
if (value === undefined) return 1;
|
||||||
|
if (!/^[1-9]\d*$/u.test(value)) {
|
||||||
|
throw new OdfParseError(
|
||||||
|
"invalid-document",
|
||||||
|
`${label} must be a positive integer`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const span = Number(value);
|
||||||
|
if (!Number.isSafeInteger(span) || span > 1_000_000) {
|
||||||
|
throw new OdfParseError("limit-exceeded", `${label} is unreasonably large`);
|
||||||
|
}
|
||||||
|
return span;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseLength(value: string | undefined): OdfLength | undefined {
|
||||||
|
if (!value) return undefined;
|
||||||
|
const match = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))(cm|mm|in|pt|pc|px|%)?$/iu.exec(
|
||||||
|
value.trim(),
|
||||||
|
);
|
||||||
|
if (!match?.[1]) return undefined;
|
||||||
|
const numeric = Number(match[1]);
|
||||||
|
if (!Number.isFinite(numeric)) return undefined;
|
||||||
|
const rawUnit = match[2]?.toLowerCase();
|
||||||
|
const unit = (rawUnit ?? "unitless") as OdfLength["unit"];
|
||||||
|
return { value: numeric, unit, raw: value };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function directText(element: XmlElement): string {
|
||||||
|
let result = "";
|
||||||
|
for (let node = element.firstChild; node; node = node.nextSibling) {
|
||||||
|
if (node.nodeType === 3 || node.nodeType === 4)
|
||||||
|
result += node.nodeValue ?? "";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,431 @@
|
|||||||
|
import { unzipSync } from "fflate";
|
||||||
|
|
||||||
|
import type { OdfParseLimits } from "./types";
|
||||||
|
import { OdfParseError } from "./types";
|
||||||
|
|
||||||
|
const LOCAL_FILE_SIGNATURE = 0x04034b50;
|
||||||
|
const CENTRAL_FILE_SIGNATURE = 0x02014b50;
|
||||||
|
const END_SIGNATURE = 0x06054b50;
|
||||||
|
const ZIP64_END_SIGNATURE = 0x06064b50;
|
||||||
|
|
||||||
|
interface ZipEntryDescriptor {
|
||||||
|
path: string;
|
||||||
|
canonicalPath: string;
|
||||||
|
compressedSize: number;
|
||||||
|
uncompressedSize: number;
|
||||||
|
crc32: number;
|
||||||
|
method: number;
|
||||||
|
flags: number;
|
||||||
|
localOffset: number;
|
||||||
|
directory: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SafeZipArchive {
|
||||||
|
entries: ReadonlyMap<string, Uint8Array<ArrayBuffer>>;
|
||||||
|
pathLookup: ReadonlyMap<string, string>;
|
||||||
|
descriptors: readonly ZipEntryDescriptor[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function fail(
|
||||||
|
code:
|
||||||
|
| "invalid-zip"
|
||||||
|
| "unsupported-zip"
|
||||||
|
| "limit-exceeded"
|
||||||
|
| "encrypted"
|
||||||
|
| "invalid-path",
|
||||||
|
message: string,
|
||||||
|
): never {
|
||||||
|
throw new OdfParseError(code, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureRange(
|
||||||
|
bytes: Uint8Array,
|
||||||
|
offset: number,
|
||||||
|
length: number,
|
||||||
|
label: string,
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
!Number.isSafeInteger(offset) ||
|
||||||
|
!Number.isSafeInteger(length) ||
|
||||||
|
offset < 0 ||
|
||||||
|
length < 0 ||
|
||||||
|
offset + length > bytes.length
|
||||||
|
) {
|
||||||
|
fail("invalid-zip", `${label} lies outside the ZIP file`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readU16(view: DataView, offset: number): number {
|
||||||
|
if (offset + 2 > view.byteLength)
|
||||||
|
fail("invalid-zip", "Truncated ZIP structure");
|
||||||
|
return view.getUint16(offset, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function readU32(view: DataView, offset: number): number {
|
||||||
|
if (offset + 4 > view.byteLength)
|
||||||
|
fail("invalid-zip", "Truncated ZIP structure");
|
||||||
|
return view.getUint32(offset, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodePath(bytes: Uint8Array): string {
|
||||||
|
if (bytes.length === 0 || bytes.length > 4096) {
|
||||||
|
fail("invalid-path", "A ZIP entry has an empty or excessively long path");
|
||||||
|
}
|
||||||
|
let path: string;
|
||||||
|
try {
|
||||||
|
path = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
||||||
|
} catch {
|
||||||
|
fail("invalid-path", "A ZIP entry path is not valid UTF-8");
|
||||||
|
}
|
||||||
|
validatePackagePath(path);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validatePackagePath(path: string): void {
|
||||||
|
const directoryPath = path.endsWith("/") ? path.slice(0, -1) : path;
|
||||||
|
if (
|
||||||
|
!directoryPath ||
|
||||||
|
path.startsWith("/") ||
|
||||||
|
path.startsWith("\\") ||
|
||||||
|
path.includes("\\") ||
|
||||||
|
hasControlCharacter(path) ||
|
||||||
|
/^[a-z][a-z0-9+.-]*:/iu.test(path)
|
||||||
|
) {
|
||||||
|
fail("invalid-path", `Unsafe package path: ${JSON.stringify(path)}`);
|
||||||
|
}
|
||||||
|
const segments = directoryPath.split("/");
|
||||||
|
if (
|
||||||
|
segments.some(
|
||||||
|
(segment) => segment === "" || segment === "." || segment === "..",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
fail("invalid-path", `Unsafe package path: ${JSON.stringify(path)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalPackagePath(path: string): string {
|
||||||
|
let decoded: string;
|
||||||
|
try {
|
||||||
|
decoded = decodeURIComponent(path);
|
||||||
|
} catch {
|
||||||
|
fail(
|
||||||
|
"invalid-path",
|
||||||
|
`Malformed percent-encoding in package path: ${JSON.stringify(path)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
decoded = decoded.normalize("NFC");
|
||||||
|
validatePackagePath(decoded);
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasControlCharacter(value: string): boolean {
|
||||||
|
return Array.from(value).some((character) => {
|
||||||
|
const codePoint = character.codePointAt(0);
|
||||||
|
return codePoint !== undefined && (codePoint <= 0x1f || codePoint === 0x7f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function locateEnd(bytes: Uint8Array, view: DataView): number {
|
||||||
|
if (bytes.length < 22)
|
||||||
|
fail("invalid-zip", "The file is too short to be a ZIP package");
|
||||||
|
const earliest = Math.max(0, bytes.length - 65_557);
|
||||||
|
for (let offset = bytes.length - 22; offset >= earliest; offset -= 1) {
|
||||||
|
if (readU32(view, offset) !== END_SIGNATURE) continue;
|
||||||
|
const commentLength = readU16(view, offset + 20);
|
||||||
|
if (offset + 22 + commentLength === bytes.length) return offset;
|
||||||
|
}
|
||||||
|
fail("invalid-zip", "ZIP end-of-central-directory record was not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
function inspectCentralDirectory(
|
||||||
|
bytes: Uint8Array,
|
||||||
|
limits: OdfParseLimits,
|
||||||
|
): ZipEntryDescriptor[] {
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
if (readU32(view, 0) !== LOCAL_FILE_SIGNATURE) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
"OpenDocument input must begin with a ZIP local-file header",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const endOffset = locateEnd(bytes, view);
|
||||||
|
if (
|
||||||
|
endOffset >= 20 &&
|
||||||
|
readU32(view, endOffset - 20) === ZIP64_END_SIGNATURE
|
||||||
|
) {
|
||||||
|
fail("unsupported-zip", "ZIP64 OpenDocument packages are not supported");
|
||||||
|
}
|
||||||
|
const disk = readU16(view, endOffset + 4);
|
||||||
|
const centralDisk = readU16(view, endOffset + 6);
|
||||||
|
const entriesOnDisk = readU16(view, endOffset + 8);
|
||||||
|
const entryCount = readU16(view, endOffset + 10);
|
||||||
|
const centralSize = readU32(view, endOffset + 12);
|
||||||
|
const centralOffset = readU32(view, endOffset + 16);
|
||||||
|
if (disk !== 0 || centralDisk !== 0 || entriesOnDisk !== entryCount) {
|
||||||
|
fail("unsupported-zip", "Multi-disk ZIP packages are not supported");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
entryCount === 0xffff ||
|
||||||
|
centralSize === 0xffffffff ||
|
||||||
|
centralOffset === 0xffffffff
|
||||||
|
) {
|
||||||
|
fail("unsupported-zip", "ZIP64 OpenDocument packages are not supported");
|
||||||
|
}
|
||||||
|
if (entryCount === 0) fail("invalid-zip", "The ZIP package is empty");
|
||||||
|
if (entryCount > limits.maxEntries) {
|
||||||
|
fail(
|
||||||
|
"limit-exceeded",
|
||||||
|
`ZIP package contains ${entryCount} entries; the limit is ${limits.maxEntries}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ensureRange(bytes, centralOffset, centralSize, "ZIP central directory");
|
||||||
|
if (centralOffset + centralSize !== endOffset) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
"ZIP central directory has an inconsistent size or offset",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const descriptors: ZipEntryDescriptor[] = [];
|
||||||
|
const paths = new Set<string>();
|
||||||
|
const canonicalPaths = new Set<string>();
|
||||||
|
const intervals: Array<[number, number]> = [];
|
||||||
|
let offset = centralOffset;
|
||||||
|
let totalSize = 0;
|
||||||
|
for (let index = 0; index < entryCount; index += 1) {
|
||||||
|
ensureRange(bytes, offset, 46, "ZIP central-directory entry");
|
||||||
|
if (readU32(view, offset) !== CENTRAL_FILE_SIGNATURE) {
|
||||||
|
fail("invalid-zip", `Invalid central-directory entry ${index + 1}`);
|
||||||
|
}
|
||||||
|
const madeBy = readU16(view, offset + 4);
|
||||||
|
const flags = readU16(view, offset + 8);
|
||||||
|
const method = readU16(view, offset + 10);
|
||||||
|
const crc32 = readU32(view, offset + 16);
|
||||||
|
const compressedSize = readU32(view, offset + 20);
|
||||||
|
const uncompressedSize = readU32(view, offset + 24);
|
||||||
|
const nameLength = readU16(view, offset + 28);
|
||||||
|
const extraLength = readU16(view, offset + 30);
|
||||||
|
const commentLength = readU16(view, offset + 32);
|
||||||
|
const startDisk = readU16(view, offset + 34);
|
||||||
|
const externalAttributes = readU32(view, offset + 38);
|
||||||
|
const localOffset = readU32(view, offset + 42);
|
||||||
|
const recordLength = 46 + nameLength + extraLength + commentLength;
|
||||||
|
ensureRange(bytes, offset, recordLength, "ZIP central-directory entry");
|
||||||
|
const path = decodePath(
|
||||||
|
bytes.subarray(offset + 46, offset + 46 + nameLength),
|
||||||
|
);
|
||||||
|
const canonicalPath = canonicalPackagePath(path);
|
||||||
|
if (paths.has(path))
|
||||||
|
fail("invalid-path", `Duplicate ZIP entry path: ${path}`);
|
||||||
|
if (canonicalPaths.has(canonicalPath)) {
|
||||||
|
fail(
|
||||||
|
"invalid-path",
|
||||||
|
`ZIP entry path collides after URI/Unicode normalization: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
paths.add(path);
|
||||||
|
canonicalPaths.add(canonicalPath);
|
||||||
|
if (flags & 0x0001 || flags & 0x0040 || flags & 0x2000) {
|
||||||
|
fail("encrypted", `Encrypted ZIP entry is not supported: ${path}`);
|
||||||
|
}
|
||||||
|
if (flags & 0x0020)
|
||||||
|
fail("unsupported-zip", `Patched ZIP data is not supported: ${path}`);
|
||||||
|
if (method !== 0 && method !== 8) {
|
||||||
|
fail(
|
||||||
|
"unsupported-zip",
|
||||||
|
`ZIP compression method ${method} is not supported: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (startDisk !== 0)
|
||||||
|
fail("unsupported-zip", "Multi-disk ZIP entries are not supported");
|
||||||
|
const directory = path.endsWith("/");
|
||||||
|
if (directory && (compressedSize !== 0 || uncompressedSize !== 0)) {
|
||||||
|
fail("invalid-zip", `Directory entry contains data: ${path}`);
|
||||||
|
}
|
||||||
|
const host = madeBy >>> 8;
|
||||||
|
if (host === 3) {
|
||||||
|
const fileType = (externalAttributes >>> 16) & 0xf000;
|
||||||
|
if (fileType !== 0 && fileType !== 0x4000 && fileType !== 0x8000) {
|
||||||
|
fail(
|
||||||
|
"unsupported-zip",
|
||||||
|
`Special or symbolic-link ZIP entry is not supported: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uncompressedSize > limits.maxEntryBytes) {
|
||||||
|
fail(
|
||||||
|
"limit-exceeded",
|
||||||
|
`ZIP entry exceeds the ${limits.maxEntryBytes}-byte limit: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
totalSize += uncompressedSize;
|
||||||
|
if (!Number.isSafeInteger(totalSize) || totalSize > limits.maxTotalBytes) {
|
||||||
|
fail(
|
||||||
|
"limit-exceeded",
|
||||||
|
`ZIP expanded size exceeds the ${limits.maxTotalBytes}-byte limit`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
uncompressedSize > 1024 &&
|
||||||
|
uncompressedSize / Math.max(1, compressedSize) >
|
||||||
|
limits.maxCompressionRatio
|
||||||
|
) {
|
||||||
|
fail(
|
||||||
|
"limit-exceeded",
|
||||||
|
`ZIP entry has an unsafe compression ratio: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureRange(bytes, localOffset, 30, `Local header for ${path}`);
|
||||||
|
if (readU32(view, localOffset) !== LOCAL_FILE_SIGNATURE) {
|
||||||
|
fail("invalid-zip", `Missing local-file header for ${path}`);
|
||||||
|
}
|
||||||
|
const localFlags = readU16(view, localOffset + 6);
|
||||||
|
const localMethod = readU16(view, localOffset + 8);
|
||||||
|
const localCrc32 = readU32(view, localOffset + 14);
|
||||||
|
const localCompressedSize = readU32(view, localOffset + 18);
|
||||||
|
const localUncompressedSize = readU32(view, localOffset + 22);
|
||||||
|
const localNameLength = readU16(view, localOffset + 26);
|
||||||
|
const localExtraLength = readU16(view, localOffset + 28);
|
||||||
|
const dataOffset = localOffset + 30 + localNameLength + localExtraLength;
|
||||||
|
ensureRange(
|
||||||
|
bytes,
|
||||||
|
localOffset + 30,
|
||||||
|
localNameLength + localExtraLength,
|
||||||
|
`Local metadata for ${path}`,
|
||||||
|
);
|
||||||
|
const localPath = decodePath(
|
||||||
|
bytes.subarray(localOffset + 30, localOffset + 30 + localNameLength),
|
||||||
|
);
|
||||||
|
if (localPath !== path || localMethod !== method || localFlags !== flags) {
|
||||||
|
fail("invalid-zip", `Local and central metadata disagree for ${path}`);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!(flags & 0x0008) &&
|
||||||
|
(localCrc32 !== crc32 ||
|
||||||
|
localCompressedSize !== compressedSize ||
|
||||||
|
localUncompressedSize !== uncompressedSize)
|
||||||
|
) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
`Local and central size/CRC declarations disagree for ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ensureRange(
|
||||||
|
bytes,
|
||||||
|
dataOffset,
|
||||||
|
compressedSize,
|
||||||
|
`Compressed data for ${path}`,
|
||||||
|
);
|
||||||
|
if (dataOffset + compressedSize > centralOffset) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
`Compressed data overlaps the ZIP central directory: ${path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
intervals.push([localOffset, dataOffset + compressedSize]);
|
||||||
|
descriptors.push({
|
||||||
|
path,
|
||||||
|
canonicalPath,
|
||||||
|
compressedSize,
|
||||||
|
uncompressedSize,
|
||||||
|
crc32,
|
||||||
|
method,
|
||||||
|
flags,
|
||||||
|
localOffset,
|
||||||
|
directory,
|
||||||
|
});
|
||||||
|
offset += recordLength;
|
||||||
|
}
|
||||||
|
if (offset !== endOffset)
|
||||||
|
fail("invalid-zip", "ZIP central directory entry count is inconsistent");
|
||||||
|
|
||||||
|
intervals.sort((left, right) => left[0] - right[0]);
|
||||||
|
for (let index = 1; index < intervals.length; index += 1) {
|
||||||
|
const previous = intervals[index - 1];
|
||||||
|
const current = intervals[index];
|
||||||
|
if (previous && current && current[0] < previous[1]) {
|
||||||
|
fail("invalid-zip", "ZIP entries have overlapping local data ranges");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const first = descriptors[0];
|
||||||
|
if (
|
||||||
|
!first ||
|
||||||
|
first.path !== "mimetype" ||
|
||||||
|
first.localOffset !== 0 ||
|
||||||
|
first.method !== 0
|
||||||
|
) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
"ODF requires an uncompressed mimetype entry first in the package",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return descriptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CRC_TABLE = (() => {
|
||||||
|
const table = new Uint32Array(256);
|
||||||
|
for (let index = 0; index < 256; index += 1) {
|
||||||
|
let value = index;
|
||||||
|
for (let bit = 0; bit < 8; bit += 1) {
|
||||||
|
value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
|
||||||
|
}
|
||||||
|
table[index] = value >>> 0;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
})();
|
||||||
|
|
||||||
|
function calculateCrc32(bytes: Uint8Array): number {
|
||||||
|
let crc = 0xffffffff;
|
||||||
|
for (const byte of bytes) {
|
||||||
|
const lookup = CRC_TABLE[(crc ^ byte) & 0xff];
|
||||||
|
if (lookup === undefined) fail("invalid-zip", "CRC lookup failed");
|
||||||
|
crc = lookup ^ (crc >>> 8);
|
||||||
|
}
|
||||||
|
return (crc ^ 0xffffffff) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openSafeZip(
|
||||||
|
input: ArrayBuffer,
|
||||||
|
limits: OdfParseLimits,
|
||||||
|
): SafeZipArchive {
|
||||||
|
const bytes = new Uint8Array(input);
|
||||||
|
const descriptors = inspectCentralDirectory(bytes, limits);
|
||||||
|
let inflated: Record<string, Uint8Array<ArrayBufferLike>>;
|
||||||
|
try {
|
||||||
|
inflated = unzipSync(bytes);
|
||||||
|
} catch (error) {
|
||||||
|
const detail = error instanceof Error ? `: ${error.message}` : "";
|
||||||
|
fail("invalid-zip", `ZIP decompression failed${detail}`);
|
||||||
|
}
|
||||||
|
const entries = new Map<string, Uint8Array<ArrayBuffer>>();
|
||||||
|
const pathLookup = new Map<string, string>();
|
||||||
|
for (const descriptor of descriptors) {
|
||||||
|
const value = inflated[descriptor.path];
|
||||||
|
if (!value)
|
||||||
|
fail("invalid-zip", `ZIP entry could not be read: ${descriptor.path}`);
|
||||||
|
if (value.byteLength !== descriptor.uncompressedSize) {
|
||||||
|
fail(
|
||||||
|
"invalid-zip",
|
||||||
|
`Expanded size does not match the ZIP declaration: ${descriptor.path}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (calculateCrc32(value) !== descriptor.crc32) {
|
||||||
|
fail("invalid-zip", `CRC check failed for ZIP entry: ${descriptor.path}`);
|
||||||
|
}
|
||||||
|
let owned: Uint8Array<ArrayBuffer>;
|
||||||
|
if (
|
||||||
|
value.buffer instanceof ArrayBuffer &&
|
||||||
|
value.byteOffset === 0 &&
|
||||||
|
value.byteLength === value.buffer.byteLength
|
||||||
|
) {
|
||||||
|
owned = value as Uint8Array<ArrayBuffer>;
|
||||||
|
} else {
|
||||||
|
owned = new Uint8Array(value.byteLength);
|
||||||
|
owned.set(value);
|
||||||
|
}
|
||||||
|
entries.set(descriptor.path, owned);
|
||||||
|
pathLookup.set(descriptor.canonicalPath, descriptor.path);
|
||||||
|
}
|
||||||
|
return { entries, pathLookup, descriptors };
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
type ErrorWithCode = Error & {
|
||||||
|
code?: string;
|
||||||
|
officeIssue?: { code?: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface ViewerErrorDescription {
|
||||||
|
code: string;
|
||||||
|
message: string;
|
||||||
|
passwordRequired: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function describeOoxmlError(value: unknown): ViewerErrorDescription {
|
||||||
|
const error = value instanceof Error ? (value as ErrorWithCode) : undefined;
|
||||||
|
const code = error?.code ?? error?.officeIssue?.code ?? "open-failed";
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case "encrypted":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"This file is password protected. Enter its password to open it locally.",
|
||||||
|
passwordRequired: true,
|
||||||
|
};
|
||||||
|
case "invalid-password":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message: "That password did not unlock the file. Please try again.",
|
||||||
|
passwordRequired: true,
|
||||||
|
};
|
||||||
|
case "unsupported-encryption":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"This file uses an older encryption scheme that the local viewer cannot safely open.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
case "legacy-binary-format":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message: "This is a legacy binary Office file, not an OOXML document.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
case "not-ooxml":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"The file extension says OOXML, but the package contents do not match that format.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
case "ooxml-resource-limit":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"Opening stopped because the package exceeds the viewer’s decompression safety limits.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
case "ooxml-decoded-image-limit":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"Opening stopped because an embedded image exceeds the safe decoded-image limit.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
case "parser-crashed":
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message:
|
||||||
|
"The isolated document parser stopped while reading this file.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
message: error?.message?.trim() || "The document could not be opened.",
|
||||||
|
passwordRequired: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+1232
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
|||||||
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
import { cleanup } from "@testing-library/react";
|
||||||
|
import { afterEach } from "vitest";
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
if (!HTMLDialogElement.prototype.showModal) {
|
||||||
|
HTMLDialogElement.prototype.showModal = function showModal() {
|
||||||
|
this.setAttribute("open", "");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!HTMLDialogElement.prototype.close) {
|
||||||
|
HTMLDialogElement.prototype.close = function close() {
|
||||||
|
this.removeAttribute("open");
|
||||||
|
this.dispatchEvent(new Event("close"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Element.prototype.scrollIntoView) {
|
||||||
|
Element.prototype.scrollIntoView = () => undefined;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://git.add-ideas.de/lotobo/toolbox-sdk/raw/branch/main/schemas/toolbox-app.v1.schema.json",
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "de.add-ideas.office-tools",
|
||||||
|
"name": "Office Tools",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Open and inspect documents, spreadsheets and presentations locally in the browser.",
|
||||||
|
"entry": "./",
|
||||||
|
"icon": "./favicon.svg",
|
||||||
|
"categories": ["documents", "office", "productivity"],
|
||||||
|
"tags": [
|
||||||
|
"document",
|
||||||
|
"spreadsheet",
|
||||||
|
"presentation",
|
||||||
|
"docx",
|
||||||
|
"xlsx",
|
||||||
|
"pptx",
|
||||||
|
"odt",
|
||||||
|
"ods",
|
||||||
|
"odp",
|
||||||
|
"viewer"
|
||||||
|
],
|
||||||
|
"integration": {
|
||||||
|
"contextVersion": 1,
|
||||||
|
"launchModes": ["navigate", "new-tab"],
|
||||||
|
"embedding": "unsupported"
|
||||||
|
},
|
||||||
|
"requirements": {
|
||||||
|
"secureContext": false,
|
||||||
|
"workers": true,
|
||||||
|
"indexedDb": false,
|
||||||
|
"crossOriginIsolated": false,
|
||||||
|
"topLevelContext": false
|
||||||
|
},
|
||||||
|
"privacy": {
|
||||||
|
"processing": "local",
|
||||||
|
"fileUploads": false,
|
||||||
|
"telemetry": false,
|
||||||
|
"label": "Office files stay in this browser; nothing is uploaded."
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"repository": "https://git.add-ideas.de/lotobo/office-tools",
|
||||||
|
"license": "GPL-3.0-or-later"
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"id": "source",
|
||||||
|
"label": "Source",
|
||||||
|
"url": "https://git.add-ideas.de/lotobo/office-tools"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { defineToolboxApp, parseToolboxApp } from "@add-ideas/toolbox-contract";
|
||||||
|
import source from "./manifest.source.json";
|
||||||
|
|
||||||
|
export const manifest = defineToolboxApp(parseToolboxApp(source));
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const APP_VERSION = "0.1.0";
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/// <reference lib="webworker" />
|
||||||
|
|
||||||
|
import {
|
||||||
|
collectOdfTransferables,
|
||||||
|
OdfParseError,
|
||||||
|
parseOpenDocument,
|
||||||
|
} from "../office/odf";
|
||||||
|
import type {
|
||||||
|
OdfDocument,
|
||||||
|
OdfErrorCode,
|
||||||
|
OdfFormat,
|
||||||
|
OdfParseLimits,
|
||||||
|
} from "../office/odf";
|
||||||
|
|
||||||
|
export interface OdfWorkerParseRequest {
|
||||||
|
type: "parse";
|
||||||
|
requestId: number;
|
||||||
|
buffer: ArrayBuffer;
|
||||||
|
format: OdfFormat;
|
||||||
|
fileName: string;
|
||||||
|
limits?: Partial<OdfParseLimits>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OdfWorkerError {
|
||||||
|
name: string;
|
||||||
|
message: string;
|
||||||
|
code?: OdfErrorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OdfWorkerResponse =
|
||||||
|
| {
|
||||||
|
type: "parsed";
|
||||||
|
requestId: number;
|
||||||
|
document: OdfDocument;
|
||||||
|
elapsedMs: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "error";
|
||||||
|
requestId: number;
|
||||||
|
error: OdfWorkerError;
|
||||||
|
};
|
||||||
|
|
||||||
|
const workerScope = self as unknown as DedicatedWorkerGlobalScope;
|
||||||
|
|
||||||
|
function isRequest(value: unknown): value is OdfWorkerParseRequest {
|
||||||
|
if (typeof value !== "object" || value === null) return false;
|
||||||
|
const candidate = value as Partial<OdfWorkerParseRequest>;
|
||||||
|
return (
|
||||||
|
candidate.type === "parse" &&
|
||||||
|
Number.isSafeInteger(candidate.requestId) &&
|
||||||
|
candidate.buffer instanceof ArrayBuffer &&
|
||||||
|
(candidate.format === "odt" ||
|
||||||
|
candidate.format === "ods" ||
|
||||||
|
candidate.format === "odp") &&
|
||||||
|
typeof candidate.fileName === "string"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function serializeError(error: unknown): OdfWorkerError {
|
||||||
|
if (error instanceof OdfParseError) {
|
||||||
|
return { name: error.name, message: error.message, code: error.code };
|
||||||
|
}
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return { name: error.name || "Error", message: error.message };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name: "Error",
|
||||||
|
message: "The OpenDocument package could not be parsed.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
workerScope.addEventListener("message", (event: MessageEvent<unknown>) => {
|
||||||
|
if (!isRequest(event.data)) return;
|
||||||
|
|
||||||
|
const { requestId, buffer, format, fileName, limits } = event.data;
|
||||||
|
const startedAt = performance.now();
|
||||||
|
try {
|
||||||
|
const document = parseOpenDocument(buffer, {
|
||||||
|
expectedFormat: format,
|
||||||
|
fileName,
|
||||||
|
limits,
|
||||||
|
});
|
||||||
|
const response: OdfWorkerResponse = {
|
||||||
|
type: "parsed",
|
||||||
|
requestId,
|
||||||
|
document,
|
||||||
|
elapsedMs: performance.now() - startedAt,
|
||||||
|
};
|
||||||
|
workerScope.postMessage(response, collectOdfTransferables(document));
|
||||||
|
} catch (error) {
|
||||||
|
const response: OdfWorkerResponse = {
|
||||||
|
type: "error",
|
||||||
|
requestId,
|
||||||
|
error: serializeError(error),
|
||||||
|
};
|
||||||
|
workerScope.postMessage(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export {};
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { expect, test, type Page } from "@playwright/test";
|
||||||
|
import {
|
||||||
|
createMinimalOdp,
|
||||||
|
createMinimalOds,
|
||||||
|
createMinimalOdt,
|
||||||
|
type OdfFixture,
|
||||||
|
} from "../fixtures/odf";
|
||||||
|
|
||||||
|
const entry = "/deep/nested/office/";
|
||||||
|
|
||||||
|
async function openFixture(page: Page, fixture: OdfFixture) {
|
||||||
|
await page.goto(entry);
|
||||||
|
await page.getByTestId("office-file-input").setInputFiles(fixture);
|
||||||
|
await expect(page.getByText("Rendered locally", { exact: true })).toBeVisible(
|
||||||
|
{
|
||||||
|
timeout: 30_000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function find(page: Page, value: string) {
|
||||||
|
const search = page.getByRole("search");
|
||||||
|
await search.getByPlaceholder("Find in file").fill(value);
|
||||||
|
await search.getByRole("button", { name: "Find" }).click();
|
||||||
|
await expect(search.getByText("1 of 1", { exact: true })).toBeVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
test("renders and searches a project-authored ODT in an isolated worker", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const externalHosts = new Set<string>();
|
||||||
|
const errors: string[] = [];
|
||||||
|
const workerScripts: URL[] = [];
|
||||||
|
page.on("request", (request) => {
|
||||||
|
const url = new URL(request.url());
|
||||||
|
if (
|
||||||
|
(url.protocol === "http:" || url.protocol === "https:") &&
|
||||||
|
url.hostname !== "127.0.0.1"
|
||||||
|
)
|
||||||
|
externalHosts.add(url.hostname);
|
||||||
|
if (url.pathname.includes("odf.worker")) workerScripts.push(url);
|
||||||
|
});
|
||||||
|
page.on("console", (message) => {
|
||||||
|
if (message.type() === "error") errors.push(message.text());
|
||||||
|
});
|
||||||
|
page.on("pageerror", (error) => errors.push(error.message));
|
||||||
|
|
||||||
|
await openFixture(page, createMinimalOdt());
|
||||||
|
await expect(
|
||||||
|
page.getByRole("heading", { name: "OpenDocument Text Fixture" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("table", { name: "Fixture table" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("img", { name: "Project-authored fixture image" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await find(page, "ODT Search Marker");
|
||||||
|
await page.getByRole("button", { name: "Zoom in" }).click();
|
||||||
|
await expect(page.getByText("110%", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
expect(externalHosts).toEqual(new Set());
|
||||||
|
expect(errors).toEqual([]);
|
||||||
|
expect(workerScripts.length).toBeGreaterThan(0);
|
||||||
|
expect(
|
||||||
|
workerScripts.every(
|
||||||
|
(url) =>
|
||||||
|
url.origin === "http://127.0.0.1:4173" &&
|
||||||
|
url.pathname.startsWith("/deep/nested/office/assets/"),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renders, searches and switches sheets in a project-authored ODS", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await openFixture(page, createMinimalOds());
|
||||||
|
await expect(page.getByText("sheet 1 of 2", { exact: true })).toBeVisible();
|
||||||
|
await expect(page.getByRole("grid")).toContainText("Office Tools Workbook");
|
||||||
|
await find(page, "ODS Search Marker");
|
||||||
|
await page.getByRole("button", { name: "Next sheet" }).click();
|
||||||
|
await expect(page.getByText("sheet 2 of 2", { exact: true })).toBeVisible();
|
||||||
|
await expect(page.getByRole("grid")).toContainText("Second sheet content");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renders, searches and navigates a project-authored ODP", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await openFixture(page, createMinimalOdp());
|
||||||
|
await expect(page.getByText("slide 1 of 2", { exact: true })).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("heading", { name: "OpenDocument Presentation Fixture" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await find(page, "ODP Search Marker");
|
||||||
|
await expect(page.getByText("slide 2 of 2", { exact: true })).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("heading", { name: "ODP Search Marker" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("complementary", { name: "Speaker notes" }),
|
||||||
|
).toContainText("Second speaker note");
|
||||||
|
});
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { expect, test } from "@playwright/test";
|
||||||
|
|
||||||
|
const entry = "/deep/nested/office/";
|
||||||
|
|
||||||
|
test("loads from a nested path without external requests", async ({ page }) => {
|
||||||
|
const external: string[] = [];
|
||||||
|
page.on("request", (request) => {
|
||||||
|
const url = new URL(request.url());
|
||||||
|
if (url.hostname !== "127.0.0.1") external.push(request.url());
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(entry);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
page.getByRole("heading", { name: "Open an office file" }),
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(page.getByText("No upload")).toBeVisible();
|
||||||
|
expect(external).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("publishes valid relocatable metadata", async ({ request }) => {
|
||||||
|
const manifestResponse = await request.get(`${entry}toolbox-app.json`);
|
||||||
|
expect(manifestResponse.ok()).toBe(true);
|
||||||
|
await expect(manifestResponse.json()).resolves.toMatchObject({
|
||||||
|
schemaVersion: 1,
|
||||||
|
id: "de.add-ideas.office-tools",
|
||||||
|
version: "0.1.0",
|
||||||
|
entry: "./",
|
||||||
|
icon: "./favicon.svg",
|
||||||
|
privacy: { processing: "local", fileUploads: false, telemetry: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const webManifest = await request.get(`${entry}manifest.webmanifest`);
|
||||||
|
expect(webManifest.ok()).toBe(true);
|
||||||
|
expect(webManifest.headers()["content-type"]).toContain(
|
||||||
|
"application/manifest+json",
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import { expect, test, type Locator, type Page } from "@playwright/test";
|
||||||
|
import {
|
||||||
|
createMalformedDocx,
|
||||||
|
createMinimalDocx,
|
||||||
|
createMinimalPptx,
|
||||||
|
createMinimalXlsx,
|
||||||
|
type OoxmlFixture,
|
||||||
|
} from "../fixtures/ooxml";
|
||||||
|
|
||||||
|
const entry = "/deep/nested/office/";
|
||||||
|
|
||||||
|
async function openFixture(page: Page, fixture: OoxmlFixture) {
|
||||||
|
await page.goto(entry);
|
||||||
|
await page
|
||||||
|
.getByTestId("office-file-input")
|
||||||
|
.setInputFiles(
|
||||||
|
fixture as unknown as Parameters<Locator["setInputFiles"]>[0],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function expectRenderedPackage(
|
||||||
|
page: Page,
|
||||||
|
format: "docx" | "xlsx" | "pptx",
|
||||||
|
) {
|
||||||
|
await expect(page.getByTestId("opened-file")).toBeVisible();
|
||||||
|
await expect(page.getByText("Rendered locally", { exact: true })).toBeVisible(
|
||||||
|
{
|
||||||
|
timeout: 90_000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await expect(
|
||||||
|
page.locator(`.office-render-stage--${format} canvas`).first(),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
|
const canvas = page.locator(`.office-render-stage--${format} canvas`).first();
|
||||||
|
const dimensions = await canvas.evaluate((element) => {
|
||||||
|
const rendered = element as HTMLCanvasElement;
|
||||||
|
const bounds = rendered.getBoundingClientRect();
|
||||||
|
return {
|
||||||
|
bitmapHeight: rendered.height,
|
||||||
|
bitmapWidth: rendered.width,
|
||||||
|
cssHeight: bounds.height,
|
||||||
|
cssWidth: bounds.width,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(dimensions.bitmapWidth).toBeGreaterThan(1);
|
||||||
|
expect(dimensions.bitmapHeight).toBeGreaterThan(1);
|
||||||
|
expect(dimensions.cssWidth).toBeGreaterThan(1);
|
||||||
|
expect(dimensions.cssHeight).toBeGreaterThan(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function expectOneSearchMatch(page: Page, text: string) {
|
||||||
|
await page.getByRole("search").getByPlaceholder("Find in file").fill(text);
|
||||||
|
await page.getByRole("search").getByRole("button", { name: "Find" }).click();
|
||||||
|
await expect(page.getByText("1 match", { exact: true })).toBeVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
test("opens, renders, searches and navigates a project-authored DOCX", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const externalHosts = new Set<string>();
|
||||||
|
const runtimeErrors: string[] = [];
|
||||||
|
const wasmResponses: Array<{
|
||||||
|
cacheControl: string;
|
||||||
|
contentType: string;
|
||||||
|
url: URL;
|
||||||
|
}> = [];
|
||||||
|
page.on("request", (request) => {
|
||||||
|
const url = new URL(request.url());
|
||||||
|
if (url.hostname !== "127.0.0.1") externalHosts.add(url.hostname);
|
||||||
|
});
|
||||||
|
page.on("response", (response) => {
|
||||||
|
const url = new URL(response.url());
|
||||||
|
if (url.pathname.endsWith(".wasm")) {
|
||||||
|
wasmResponses.push({
|
||||||
|
cacheControl: response.headers()["cache-control"] ?? "",
|
||||||
|
contentType: response.headers()["content-type"] ?? "",
|
||||||
|
url,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
page.on("console", (message) => {
|
||||||
|
if (message.type() === "error") runtimeErrors.push(message.text());
|
||||||
|
});
|
||||||
|
page.on("pageerror", (error) => runtimeErrors.push(error.message));
|
||||||
|
|
||||||
|
await openFixture(page, createMinimalDocx());
|
||||||
|
await expectRenderedPackage(page, "docx");
|
||||||
|
await expect(page.getByText(/page 1 of [2-9]\d*/i)).toBeVisible();
|
||||||
|
|
||||||
|
await expectOneSearchMatch(page, "Second Page Search Marker");
|
||||||
|
await page.getByRole("button", { name: "Next page" }).click();
|
||||||
|
await expect(page.getByText(/page 2 of [2-9]\d*/i)).toBeVisible();
|
||||||
|
|
||||||
|
expect(externalHosts).toEqual(new Set());
|
||||||
|
expect(wasmResponses.length).toBeGreaterThan(0);
|
||||||
|
expect(
|
||||||
|
wasmResponses.every(
|
||||||
|
({ cacheControl, contentType, url }) =>
|
||||||
|
url.origin === "http://127.0.0.1:4173" &&
|
||||||
|
url.pathname.startsWith("/deep/nested/office/assets/") &&
|
||||||
|
contentType.startsWith("application/wasm") &&
|
||||||
|
cacheControl.includes("max-age=31536000") &&
|
||||||
|
cacheControl.includes("immutable"),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
expect(runtimeErrors).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("opens, renders, searches and switches sheets in a project-authored XLSX", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await openFixture(page, createMinimalXlsx());
|
||||||
|
await expectRenderedPackage(page, "xlsx");
|
||||||
|
await expect(page.getByText("sheet 1 of 2", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
await expectOneSearchMatch(page, "Office Tools Workbook Fixture");
|
||||||
|
await page.getByRole("button", { name: "Next sheet" }).click();
|
||||||
|
await expect(page.getByText("sheet 2 of 2", { exact: true })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("opens, renders, searches and navigates a project-authored PPTX", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await openFixture(page, createMinimalPptx());
|
||||||
|
await expectRenderedPackage(page, "pptx");
|
||||||
|
await expect(page.getByText("slide 1 of 2", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
await expectOneSearchMatch(page, "Second Slide Search Marker");
|
||||||
|
await page.getByRole("button", { name: "Next slide" }).click();
|
||||||
|
await expect(page.getByText("slide 2 of 2", { exact: true })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("fails closed with an inline error for a malformed OOXML package", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await openFixture(page, createMalformedDocx());
|
||||||
|
|
||||||
|
const alert = page.getByRole("alert");
|
||||||
|
await expect(alert).toBeVisible({ timeout: 90_000 });
|
||||||
|
await expect(alert).not.toBeEmpty();
|
||||||
|
await expect(
|
||||||
|
page.locator(".file-heading__state .state-dot--error"),
|
||||||
|
).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("rejects a valid package whose contents do not match its extension", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const workbook = createMinimalXlsx();
|
||||||
|
await openFixture(page, {
|
||||||
|
...workbook,
|
||||||
|
mimeType:
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
name: "workbook-disguised-as-document.docx",
|
||||||
|
});
|
||||||
|
|
||||||
|
const alert = page.getByRole("alert");
|
||||||
|
await expect(alert).toBeVisible({ timeout: 90_000 });
|
||||||
|
await expect(alert).not.toBeEmpty();
|
||||||
|
await expect(
|
||||||
|
page.locator(".file-heading__state .state-dot--error"),
|
||||||
|
).toBeVisible();
|
||||||
|
});
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { UploadWorkbench } from "../../src/components/UploadWorkbench";
|
||||||
|
|
||||||
|
vi.mock("../../src/components/OoxmlViewer", () => ({
|
||||||
|
OoxmlViewer: () => <section aria-label="Test OOXML viewer" />,
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("UploadWorkbench", () => {
|
||||||
|
it("exposes the initial local format families", () => {
|
||||||
|
render(<UploadWorkbench />);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", { name: "Open an office file" }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
for (const format of ["DOCX", "XLSX", "PPTX", "ODT", "ODS", "ODP"])
|
||||||
|
expect(screen.getByText(format)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("No upload")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows the identity of a locally selected file", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(<UploadWorkbench />);
|
||||||
|
const input = screen.getByLabelText("Open office file");
|
||||||
|
const file = new File(["local fixture"], "report.docx", {
|
||||||
|
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.upload(input, file);
|
||||||
|
|
||||||
|
const heading = screen.getByRole("region", { name: "report.docx" });
|
||||||
|
expect(heading).toHaveTextContent("report.docx");
|
||||||
|
expect(heading).toHaveTextContent("13 B");
|
||||||
|
expect(screen.getByLabelText("Test OOXML viewer")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
Vendored
+95
@@ -0,0 +1,95 @@
|
|||||||
|
import {
|
||||||
|
makeOdf,
|
||||||
|
odpContent,
|
||||||
|
odsContent,
|
||||||
|
odtContent,
|
||||||
|
XMLNS,
|
||||||
|
} from "../office/odf/fixtures";
|
||||||
|
|
||||||
|
export interface OdfFixture {
|
||||||
|
name: string;
|
||||||
|
mimeType: string;
|
||||||
|
buffer: NodeBufferLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NodeBufferLike extends Uint8Array {
|
||||||
|
toString(encoding?: string): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodeBuffer = (
|
||||||
|
globalThis as unknown as {
|
||||||
|
Buffer: { from(value: Uint8Array): NodeBufferLike };
|
||||||
|
}
|
||||||
|
).Buffer;
|
||||||
|
|
||||||
|
function fixture(
|
||||||
|
name: string,
|
||||||
|
mimeType: string,
|
||||||
|
buffer: ArrayBuffer,
|
||||||
|
): OdfFixture {
|
||||||
|
return { name, mimeType, buffer: nodeBuffer.from(new Uint8Array(buffer)) };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalOdt(): OdfFixture {
|
||||||
|
const svg = new TextEncoder().encode(
|
||||||
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 50"><rect width="80" height="50" rx="6" fill="#24465f"/><circle cx="25" cy="25" r="13" fill="#85c8e8"/></svg>',
|
||||||
|
);
|
||||||
|
const metadata = `<?xml version="1.0"?><office:document-meta ${XMLNS}>
|
||||||
|
<office:meta><dc:title>Project-authored ODT fixture</dc:title><dc:creator>Office Tools</dc:creator></office:meta>
|
||||||
|
</office:document-meta>`;
|
||||||
|
const data = makeOdf(
|
||||||
|
"odt",
|
||||||
|
odtContent(`
|
||||||
|
<text:h text:outline-level="1">OpenDocument Text Fixture</text:h>
|
||||||
|
<text:p>This document is rendered entirely in the browser.</text:p>
|
||||||
|
<text:p>Find the <text:span text:style-name="InlineBold">ODT Search Marker</text:span>.</text:p>
|
||||||
|
<text:list><text:list-item><text:p>First local item</text:p></text:list-item><text:list-item><text:p>Second local item</text:p></text:list-item></text:list>
|
||||||
|
<table:table table:name="Fixture table"><table:table-row><table:table-cell><text:p>Cell A</text:p></table:table-cell><table:table-cell><text:p>Cell B</text:p></table:table-cell></table:table-row></table:table>
|
||||||
|
<draw:frame svg:width="4cm" svg:height="2.5cm"><draw:image xlink:href="Pictures/fixture.svg"/><svg:desc>Project-authored fixture image</svg:desc></draw:frame>`),
|
||||||
|
{ extra: { "Pictures/fixture.svg": svg }, meta: metadata },
|
||||||
|
);
|
||||||
|
return fixture(
|
||||||
|
"project-authored.odt",
|
||||||
|
"application/vnd.oasis.opendocument.text",
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalOds(): OdfFixture {
|
||||||
|
const data = makeOdf(
|
||||||
|
"ods",
|
||||||
|
odsContent(`
|
||||||
|
<table:table table:name="Overview">
|
||||||
|
<table:table-row><table:table-cell office:value-type="string"><text:p>Office Tools Workbook</text:p></table:table-cell><table:table-cell office:value-type="float" office:value="42"><text:p>42</text:p></table:table-cell></table:table-row>
|
||||||
|
<table:table-row><table:table-cell office:value-type="string"><text:p>ODS Search Marker</text:p></table:table-cell><table:table-cell office:value-type="float" office:value="84" table:formula="of:=[.B1]*2"><text:p>84</text:p></table:table-cell></table:table-row>
|
||||||
|
</table:table>
|
||||||
|
<table:table table:name="Details"><table:table-row><table:table-cell office:value-type="string"><text:p>Second sheet content</text:p></table:table-cell></table:table-row></table:table>`),
|
||||||
|
);
|
||||||
|
return fixture(
|
||||||
|
"project-authored.ods",
|
||||||
|
"application/vnd.oasis.opendocument.spreadsheet",
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalOdp(): OdfFixture {
|
||||||
|
const data = makeOdf(
|
||||||
|
"odp",
|
||||||
|
odpContent(`
|
||||||
|
<draw:page draw:name="Opening">
|
||||||
|
<draw:frame draw:id="title-1" svg:x="1cm" svg:y="1cm" svg:width="20cm" svg:height="3cm"><draw:text-box><text:h text:outline-level="1">OpenDocument Presentation Fixture</text:h></draw:text-box></draw:frame>
|
||||||
|
<draw:rect draw:id="body-1" svg:x="2cm" svg:y="6cm" svg:width="15cm" svg:height="4cm"><text:p>First slide body</text:p></draw:rect>
|
||||||
|
<presentation:notes><text:p>Opening speaker note</text:p></presentation:notes>
|
||||||
|
</draw:page>
|
||||||
|
<draw:page draw:name="Search slide">
|
||||||
|
<draw:frame draw:id="title-2" svg:x="1cm" svg:y="1cm" svg:width="20cm" svg:height="3cm"><draw:text-box><text:h text:outline-level="1">ODP Search Marker</text:h></draw:text-box></draw:frame>
|
||||||
|
<draw:ellipse draw:id="circle-2" svg:x="4cm" svg:y="6cm" svg:width="5cm" svg:height="5cm"><text:p>Second slide shape</text:p></draw:ellipse>
|
||||||
|
<presentation:notes><text:p>Second speaker note</text:p></presentation:notes>
|
||||||
|
</draw:page>`),
|
||||||
|
);
|
||||||
|
return fixture(
|
||||||
|
"project-authored.odp",
|
||||||
|
"application/vnd.oasis.opendocument.presentation",
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
Vendored
+329
@@ -0,0 +1,329 @@
|
|||||||
|
import { strToU8, zipSync } from "fflate";
|
||||||
|
|
||||||
|
type XmlParts = Record<string, string>;
|
||||||
|
|
||||||
|
interface NodeBufferLike extends Uint8Array {
|
||||||
|
toString(encoding?: string): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodeBuffer = (
|
||||||
|
globalThis as unknown as {
|
||||||
|
Buffer: {
|
||||||
|
from(value: string | Uint8Array): NodeBufferLike;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
).Buffer;
|
||||||
|
|
||||||
|
export interface OoxmlFixture {
|
||||||
|
buffer: NodeBufferLike;
|
||||||
|
mimeType: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const XML_DECLARATION =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
||||||
|
|
||||||
|
function packageFixture(
|
||||||
|
name: string,
|
||||||
|
mimeType: string,
|
||||||
|
parts: XmlParts,
|
||||||
|
): OoxmlFixture {
|
||||||
|
const archive = Object.fromEntries(
|
||||||
|
Object.entries(parts)
|
||||||
|
.sort(([left], [right]) => left.localeCompare(right))
|
||||||
|
.map(([path, xml]) => [path, strToU8(xml)]),
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
buffer: nodeBuffer.from(zipSync(archive, { level: 6 })),
|
||||||
|
mimeType,
|
||||||
|
name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function contentTypes(overrides: string): string {
|
||||||
|
return `${XML_DECLARATION}
|
||||||
|
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||||
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
||||||
|
<Default Extension="xml" ContentType="application/xml"/>
|
||||||
|
${overrides}
|
||||||
|
</Types>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rootRelationships(target: string): string {
|
||||||
|
return `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="${target}"/>
|
||||||
|
</Relationships>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalDocx(): OoxmlFixture {
|
||||||
|
return packageFixture(
|
||||||
|
"three-page-document.docx",
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
{
|
||||||
|
"[Content_Types].xml": contentTypes(`
|
||||||
|
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
|
||||||
|
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>`),
|
||||||
|
"_rels/.rels": rootRelationships("word/document.xml"),
|
||||||
|
"word/_rels/document.xml.rels": `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
||||||
|
</Relationships>`,
|
||||||
|
"word/styles.xml": `${XML_DECLARATION}
|
||||||
|
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||||
|
<w:docDefaults>
|
||||||
|
<w:rPrDefault><w:rPr><w:sz w:val="24"/><w:szCs w:val="24"/></w:rPr></w:rPrDefault>
|
||||||
|
<w:pPrDefault><w:pPr/></w:pPrDefault>
|
||||||
|
</w:docDefaults>
|
||||||
|
<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
|
||||||
|
<w:name w:val="Normal"/><w:qFormat/>
|
||||||
|
</w:style>
|
||||||
|
<w:style w:type="paragraph" w:styleId="Title">
|
||||||
|
<w:name w:val="Title"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/>
|
||||||
|
<w:rPr><w:b/><w:sz w:val="36"/></w:rPr>
|
||||||
|
</w:style>
|
||||||
|
</w:styles>`,
|
||||||
|
"word/document.xml": `${XML_DECLARATION}
|
||||||
|
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||||
|
<w:body>
|
||||||
|
<w:p>
|
||||||
|
<w:pPr><w:pStyle w:val="Title"/></w:pPr>
|
||||||
|
<w:r><w:t>Office Tools Document Fixture</w:t></w:r>
|
||||||
|
</w:p>
|
||||||
|
<w:p><w:r><w:t>This text is rendered from a project-authored DOCX package.</w:t></w:r></w:p>
|
||||||
|
<w:tbl>
|
||||||
|
<w:tblPr><w:tblW w:w="0" w:type="auto"/></w:tblPr>
|
||||||
|
<w:tblGrid><w:gridCol w:w="3600"/><w:gridCol w:w="3600"/></w:tblGrid>
|
||||||
|
<w:tr>
|
||||||
|
<w:tc><w:p><w:r><w:t>Feature</w:t></w:r></w:p></w:tc>
|
||||||
|
<w:tc><w:p><w:r><w:t>Status</w:t></w:r></w:p></w:tc>
|
||||||
|
</w:tr>
|
||||||
|
<w:tr>
|
||||||
|
<w:tc><w:p><w:r><w:t>Local viewing</w:t></w:r></w:p></w:tc>
|
||||||
|
<w:tc><w:p><w:r><w:t>Ready</w:t></w:r></w:p></w:tc>
|
||||||
|
</w:tr>
|
||||||
|
</w:tbl>
|
||||||
|
<w:p><w:r><w:br w:type="page"/></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t>Second Page Search Marker</w:t></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t>Navigation reaches this independently laid-out page.</w:t></w:r></w:p>
|
||||||
|
<w:p><w:r><w:br w:type="page"/></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t>Third page trailing marker</w:t></w:r></w:p>
|
||||||
|
<w:p><w:r><w:t>This trailing page makes the middle page a stable scroll target.</w:t></w:r></w:p>
|
||||||
|
<w:sectPr>
|
||||||
|
<w:pgSz w:w="12240" w:h="15840"/>
|
||||||
|
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
|
||||||
|
</w:sectPr>
|
||||||
|
</w:body>
|
||||||
|
</w:document>`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalXlsx(): OoxmlFixture {
|
||||||
|
return packageFixture(
|
||||||
|
"two-sheet-workbook.xlsx",
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
{
|
||||||
|
"[Content_Types].xml": contentTypes(`
|
||||||
|
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
|
||||||
|
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
|
||||||
|
<Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
|
||||||
|
<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>
|
||||||
|
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>`),
|
||||||
|
"_rels/.rels": rootRelationships("xl/workbook.xml"),
|
||||||
|
"xl/workbook.xml": `${XML_DECLARATION}
|
||||||
|
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||||
|
<bookViews><workbookView xWindow="0" yWindow="0" windowWidth="18000" windowHeight="10000"/></bookViews>
|
||||||
|
<sheets>
|
||||||
|
<sheet name="Summary" sheetId="1" state="visible" r:id="rId1"/>
|
||||||
|
<sheet name="Details" sheetId="2" state="visible" r:id="rId2"/>
|
||||||
|
</sheets>
|
||||||
|
<calcPr calcId="191029"/>
|
||||||
|
</workbook>`,
|
||||||
|
"xl/_rels/workbook.xml.rels": `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
|
||||||
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/>
|
||||||
|
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
||||||
|
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>
|
||||||
|
</Relationships>`,
|
||||||
|
"xl/sharedStrings.xml": `${XML_DECLARATION}
|
||||||
|
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="6">
|
||||||
|
<si><t>Office Tools Workbook Fixture</t></si>
|
||||||
|
<si><t>Amount</t></si>
|
||||||
|
<si><t>Total</t></si>
|
||||||
|
<si><t>Details Sheet Search Marker</t></si>
|
||||||
|
<si><t>Item</t></si>
|
||||||
|
<si><t>Quantity</t></si>
|
||||||
|
</sst>`,
|
||||||
|
"xl/styles.xml": `${XML_DECLARATION}
|
||||||
|
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||||
|
<fonts count="2">
|
||||||
|
<font><sz val="11"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font>
|
||||||
|
<font><b/><sz val="11"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font>
|
||||||
|
</fonts>
|
||||||
|
<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>
|
||||||
|
<borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders>
|
||||||
|
<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>
|
||||||
|
<cellXfs count="2">
|
||||||
|
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
|
||||||
|
<xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1"/>
|
||||||
|
</cellXfs>
|
||||||
|
<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>
|
||||||
|
</styleSheet>`,
|
||||||
|
"xl/worksheets/sheet1.xml": `${XML_DECLARATION}
|
||||||
|
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||||
|
<dimension ref="A1:B4"/>
|
||||||
|
<sheetViews><sheetView workbookViewId="0"><selection activeCell="A1" sqref="A1"/></sheetView></sheetViews>
|
||||||
|
<sheetFormatPr defaultRowHeight="15"/>
|
||||||
|
<cols><col min="1" max="1" width="34" customWidth="1"/><col min="2" max="2" width="14" customWidth="1"/></cols>
|
||||||
|
<sheetData>
|
||||||
|
<row r="1"><c r="A1" s="1" t="s"><v>0</v></c></row>
|
||||||
|
<row r="2"><c r="A2" s="1" t="s"><v>1</v></c></row>
|
||||||
|
<row r="3"><c r="A3" t="n"><v>19</v></c><c r="B3" t="n"><v>23</v></c></row>
|
||||||
|
<row r="4"><c r="A4" s="1" t="s"><v>2</v></c><c r="B4"><f>SUM(A3:B3)</f><v>42</v></c></row>
|
||||||
|
</sheetData>
|
||||||
|
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
|
||||||
|
</worksheet>`,
|
||||||
|
"xl/worksheets/sheet2.xml": `${XML_DECLARATION}
|
||||||
|
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||||
|
<dimension ref="A1:B3"/>
|
||||||
|
<sheetViews><sheetView workbookViewId="0"><selection activeCell="A1" sqref="A1"/></sheetView></sheetViews>
|
||||||
|
<sheetFormatPr defaultRowHeight="15"/>
|
||||||
|
<cols><col min="1" max="1" width="34" customWidth="1"/><col min="2" max="2" width="14" customWidth="1"/></cols>
|
||||||
|
<sheetData>
|
||||||
|
<row r="1"><c r="A1" s="1" t="s"><v>3</v></c></row>
|
||||||
|
<row r="2"><c r="A2" s="1" t="s"><v>4</v></c><c r="B2" s="1" t="s"><v>5</v></c></row>
|
||||||
|
<row r="3"><c r="A3" t="inlineStr"><is><t>Local parser</t></is></c><c r="B3" t="n"><v>2</v></c></row>
|
||||||
|
</sheetData>
|
||||||
|
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
|
||||||
|
</worksheet>`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRESENTATION_NS =
|
||||||
|
'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"';
|
||||||
|
|
||||||
|
function slideXml(title: string, body: string): string {
|
||||||
|
return `${XML_DECLARATION}
|
||||||
|
<p:sld ${PRESENTATION_NS}>
|
||||||
|
<p:cSld>
|
||||||
|
<p:spTree>
|
||||||
|
<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>
|
||||||
|
<p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>
|
||||||
|
<p:sp>
|
||||||
|
<p:nvSpPr><p:cNvPr id="2" name="Fixture title"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>
|
||||||
|
<p:spPr>
|
||||||
|
<a:xfrm><a:off x="685800" y="685800"/><a:ext cx="7772400" cy="914400"/></a:xfrm>
|
||||||
|
<a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln>
|
||||||
|
</p:spPr>
|
||||||
|
<p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="2800" b="1"/><a:t>${title}</a:t></a:r><a:endParaRPr lang="en-US"/></a:p></p:txBody>
|
||||||
|
</p:sp>
|
||||||
|
<p:sp>
|
||||||
|
<p:nvSpPr><p:cNvPr id="3" name="Fixture body"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>
|
||||||
|
<p:spPr>
|
||||||
|
<a:xfrm><a:off x="914400" y="2057400"/><a:ext cx="7315200" cy="2286000"/></a:xfrm>
|
||||||
|
<a:prstGeom prst="roundRect"><a:avLst/></a:prstGeom>
|
||||||
|
<a:solidFill><a:srgbClr val="E8F0FE"/></a:solidFill><a:ln><a:solidFill><a:srgbClr val="356AC3"/></a:solidFill></a:ln>
|
||||||
|
</p:spPr>
|
||||||
|
<p:txBody><a:bodyPr lIns="228600" rIns="228600" tIns="228600" bIns="228600"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1800"/><a:t>${body}</a:t></a:r><a:endParaRPr lang="en-US"/></a:p></p:txBody>
|
||||||
|
</p:sp>
|
||||||
|
</p:spTree>
|
||||||
|
</p:cSld>
|
||||||
|
<p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>
|
||||||
|
</p:sld>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function slideRelationships(): string {
|
||||||
|
return `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>
|
||||||
|
</Relationships>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMinimalPptx(): OoxmlFixture {
|
||||||
|
return packageFixture(
|
||||||
|
"two-slide-presentation.pptx",
|
||||||
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||||
|
{
|
||||||
|
"[Content_Types].xml": contentTypes(`
|
||||||
|
<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>
|
||||||
|
<Override PartName="/ppt/slides/slide1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>
|
||||||
|
<Override PartName="/ppt/slides/slide2.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>
|
||||||
|
<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>
|
||||||
|
<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>
|
||||||
|
<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>`),
|
||||||
|
"_rels/.rels": rootRelationships("ppt/presentation.xml"),
|
||||||
|
"ppt/presentation.xml": `${XML_DECLARATION}
|
||||||
|
<p:presentation ${PRESENTATION_NS}>
|
||||||
|
<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>
|
||||||
|
<p:sldIdLst><p:sldId id="256" r:id="rId2"/><p:sldId id="257" r:id="rId3"/></p:sldIdLst>
|
||||||
|
<p:sldSz cx="9144000" cy="5143500" type="screen16x9"/>
|
||||||
|
<p:notesSz cx="6858000" cy="9144000"/>
|
||||||
|
</p:presentation>`,
|
||||||
|
"ppt/_rels/presentation.xml.rels": `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>
|
||||||
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/>
|
||||||
|
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide2.xml"/>
|
||||||
|
</Relationships>`,
|
||||||
|
"ppt/slides/slide1.xml": slideXml(
|
||||||
|
"Office Tools Presentation Fixture",
|
||||||
|
"This first slide is rendered entirely in the browser.",
|
||||||
|
),
|
||||||
|
"ppt/slides/slide2.xml": slideXml(
|
||||||
|
"Second Slide Search Marker",
|
||||||
|
"Navigation reaches the second project-authored slide.",
|
||||||
|
),
|
||||||
|
"ppt/slides/_rels/slide1.xml.rels": slideRelationships(),
|
||||||
|
"ppt/slides/_rels/slide2.xml.rels": slideRelationships(),
|
||||||
|
"ppt/slideLayouts/slideLayout1.xml": `${XML_DECLARATION}
|
||||||
|
<p:sldLayout ${PRESENTATION_NS} type="blank" preserve="1">
|
||||||
|
<p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree></p:cSld>
|
||||||
|
<p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>
|
||||||
|
</p:sldLayout>`,
|
||||||
|
"ppt/slideLayouts/_rels/slideLayout1.xml.rels": `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="../slideMasters/slideMaster1.xml"/>
|
||||||
|
</Relationships>`,
|
||||||
|
"ppt/slideMasters/slideMaster1.xml": `${XML_DECLARATION}
|
||||||
|
<p:sldMaster ${PRESENTATION_NS}>
|
||||||
|
<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree></p:cSld>
|
||||||
|
<p:clrMap accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" bg1="lt1" bg2="lt2" folHlink="folHlink" hlink="hlink" tx1="dk1" tx2="dk2"/>
|
||||||
|
<p:sldLayoutIdLst><p:sldLayoutId id="1" r:id="rId1"/></p:sldLayoutIdLst>
|
||||||
|
<p:txStyles><p:titleStyle/><p:bodyStyle/><p:otherStyle/></p:txStyles>
|
||||||
|
</p:sldMaster>`,
|
||||||
|
"ppt/slideMasters/_rels/slideMaster1.xml.rels": `${XML_DECLARATION}
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>
|
||||||
|
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>
|
||||||
|
</Relationships>`,
|
||||||
|
"ppt/theme/theme1.xml": `${XML_DECLARATION}
|
||||||
|
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Tools Fixture">
|
||||||
|
<a:themeElements>
|
||||||
|
<a:clrScheme name="Fixture">
|
||||||
|
<a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>
|
||||||
|
<a:dk2><a:srgbClr val="1F2937"/></a:dk2><a:lt2><a:srgbClr val="F8FAFC"/></a:lt2>
|
||||||
|
<a:accent1><a:srgbClr val="356AC3"/></a:accent1><a:accent2><a:srgbClr val="D97706"/></a:accent2>
|
||||||
|
<a:accent3><a:srgbClr val="059669"/></a:accent3><a:accent4><a:srgbClr val="7C3AED"/></a:accent4>
|
||||||
|
<a:accent5><a:srgbClr val="0891B2"/></a:accent5><a:accent6><a:srgbClr val="DB2777"/></a:accent6>
|
||||||
|
<a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink>
|
||||||
|
</a:clrScheme>
|
||||||
|
<a:fontScheme name="Fixture"><a:majorFont><a:latin typeface="Arial"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Arial"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme>
|
||||||
|
<a:fmtScheme name="Fixture"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme>
|
||||||
|
</a:themeElements>
|
||||||
|
</a:theme>`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createMalformedDocx(): OoxmlFixture {
|
||||||
|
return {
|
||||||
|
buffer: nodeBuffer.from("This is deliberately not an OOXML ZIP package."),
|
||||||
|
mimeType:
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
name: "malformed-document.docx",
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import {
|
||||||
|
MAX_SOURCE_BYTES,
|
||||||
|
OfficeFileError,
|
||||||
|
detectOfficeFormat,
|
||||||
|
extensionOf,
|
||||||
|
familyForFormat,
|
||||||
|
formatBytes,
|
||||||
|
formatLabel,
|
||||||
|
} from "../../src/office/formats";
|
||||||
|
|
||||||
|
describe("office format handling", () => {
|
||||||
|
it.each([
|
||||||
|
["REPORT.DOCX", "docx"],
|
||||||
|
["notes.odt", "odt"],
|
||||||
|
["budget.xlsx", "xlsx"],
|
||||||
|
["budget.ODS", "ods"],
|
||||||
|
["deck.pptx", "pptx"],
|
||||||
|
["deck.odp", "odp"],
|
||||||
|
] as const)("detects %s", (name, expected) => {
|
||||||
|
expect(detectOfficeFormat({ name, size: 42 })).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects empty, oversized, unsupported and legacy inputs explicitly", () => {
|
||||||
|
const cases = [
|
||||||
|
[{ name: "empty.docx", size: 0 }, "empty-file"],
|
||||||
|
[{ name: "huge.docx", size: MAX_SOURCE_BYTES + 1 }, "file-too-large"],
|
||||||
|
[{ name: "old.doc", size: 42 }, "legacy-format"],
|
||||||
|
[{ name: "notes.txt", size: 42 }, "unsupported-format"],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
for (const [file, code] of cases) {
|
||||||
|
try {
|
||||||
|
detectOfficeFormat(file);
|
||||||
|
throw new Error("Expected detection to fail");
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeInstanceOf(OfficeFileError);
|
||||||
|
expect((error as OfficeFileError).code).toBe(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maps family, labels and display values", () => {
|
||||||
|
expect(extensionOf("archive.name.PPTX")).toBe("pptx");
|
||||||
|
expect(familyForFormat("docx")).toBe("document");
|
||||||
|
expect(familyForFormat("ods")).toBe("spreadsheet");
|
||||||
|
expect(familyForFormat("odp")).toBe("presentation");
|
||||||
|
expect(formatLabel("xlsx")).toBe("Excel workbook");
|
||||||
|
expect(formatBytes(1536)).toBe("1.50 KiB");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import { strToU8, zipSync, type Zippable } from "fflate";
|
||||||
|
|
||||||
|
import type { OdfFormat } from "../../../src/office/odf";
|
||||||
|
|
||||||
|
export const MEDIA_TYPES: Readonly<Record<OdfFormat, string>> = Object.freeze({
|
||||||
|
odt: "application/vnd.oasis.opendocument.text",
|
||||||
|
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
||||||
|
odp: "application/vnd.oasis.opendocument.presentation",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const XMLNS = [
|
||||||
|
'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"',
|
||||||
|
'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"',
|
||||||
|
'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"',
|
||||||
|
'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"',
|
||||||
|
'xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"',
|
||||||
|
'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"',
|
||||||
|
'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"',
|
||||||
|
'xmlns:xlink="http://www.w3.org/1999/xlink"',
|
||||||
|
'xmlns:dc="http://purl.org/dc/elements/1.1/"',
|
||||||
|
'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"',
|
||||||
|
'xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"',
|
||||||
|
'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"',
|
||||||
|
].join(" ");
|
||||||
|
|
||||||
|
interface FixtureOptions {
|
||||||
|
extra?: Record<string, Uint8Array>;
|
||||||
|
manifest?: string | false;
|
||||||
|
meta?: string;
|
||||||
|
styles?: string;
|
||||||
|
mediaType?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeOdf(
|
||||||
|
format: OdfFormat,
|
||||||
|
content: string,
|
||||||
|
options: FixtureOptions = {},
|
||||||
|
): ArrayBuffer {
|
||||||
|
const mediaType = options.mediaType ?? MEDIA_TYPES[format];
|
||||||
|
const extra = options.extra ?? {};
|
||||||
|
const manifest =
|
||||||
|
options.manifest === false
|
||||||
|
? undefined
|
||||||
|
: (options.manifest ?? makeManifest(mediaType, Object.keys(extra)));
|
||||||
|
const files: Zippable = {
|
||||||
|
mimetype: [strToU8(mediaType), { level: 0 }],
|
||||||
|
"content.xml": strToU8(content),
|
||||||
|
};
|
||||||
|
if (manifest) files["META-INF/manifest.xml"] = strToU8(manifest);
|
||||||
|
if (options.meta) files["meta.xml"] = strToU8(options.meta);
|
||||||
|
if (options.styles) files["styles.xml"] = strToU8(options.styles);
|
||||||
|
for (const [path, value] of Object.entries(extra)) files[path] = value;
|
||||||
|
return ownedBuffer(zipSync(files, { level: 6 }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeManifest(
|
||||||
|
mediaType: string,
|
||||||
|
extraPaths: readonly string[] = [],
|
||||||
|
): string {
|
||||||
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
|
||||||
|
<manifest:file-entry manifest:full-path="/" manifest:media-type="${mediaType}"/>
|
||||||
|
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
|
||||||
|
${extraPaths
|
||||||
|
.map(
|
||||||
|
(path) =>
|
||||||
|
`<manifest:file-entry manifest:full-path="${path}" manifest:media-type="${mediaFor(path)}"/>`,
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
</manifest:manifest>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function odtContent(body: string): string {
|
||||||
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<office:document-content ${XMLNS} office:version="1.3">
|
||||||
|
<office:automatic-styles>
|
||||||
|
<style:style style:name="InlineBold" style:family="text">
|
||||||
|
<style:text-properties fo:font-weight="bold"/>
|
||||||
|
</style:style>
|
||||||
|
</office:automatic-styles>
|
||||||
|
<office:body><office:text>${body}</office:text></office:body>
|
||||||
|
</office:document-content>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function odsContent(body: string): string {
|
||||||
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<office:document-content ${XMLNS} office:version="1.3">
|
||||||
|
<office:body><office:spreadsheet>${body}</office:spreadsheet></office:body>
|
||||||
|
</office:document-content>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function odpContent(body: string): string {
|
||||||
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<office:document-content ${XMLNS} office:version="1.3">
|
||||||
|
<office:body><office:presentation>${body}</office:presentation></office:body>
|
||||||
|
</office:document-content>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function zipWithTraversal(content: string): ArrayBuffer {
|
||||||
|
const files: Zippable = {
|
||||||
|
mimetype: [strToU8(MEDIA_TYPES.odt), { level: 0 }],
|
||||||
|
"content.xml": strToU8(content),
|
||||||
|
"../escape.txt": strToU8("no"),
|
||||||
|
};
|
||||||
|
return ownedBuffer(zipSync(files));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function zipWithEncodedCollision(content: string): ArrayBuffer {
|
||||||
|
const files: Zippable = {
|
||||||
|
mimetype: [strToU8(MEDIA_TYPES.odt), { level: 0 }],
|
||||||
|
"content.xml": strToU8(content),
|
||||||
|
"Pictures/a.png": new Uint8Array([1]),
|
||||||
|
"Pictures/%61.png": new Uint8Array([2]),
|
||||||
|
};
|
||||||
|
return ownedBuffer(zipSync(files));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function corruptFirstCentralCrc(input: ArrayBuffer): ArrayBuffer {
|
||||||
|
const bytes = new Uint8Array(input.slice(0));
|
||||||
|
const view = new DataView(bytes.buffer);
|
||||||
|
const end = findSignature(bytes, 0x06054b50);
|
||||||
|
const centralOffset = view.getUint32(end + 16, true);
|
||||||
|
view.setUint32(
|
||||||
|
centralOffset + 16,
|
||||||
|
view.getUint32(centralOffset + 16, true) ^ 1,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
return bytes.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findSignature(bytes: Uint8Array, signature: number): number {
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
for (let offset = bytes.byteLength - 4; offset >= 0; offset -= 1) {
|
||||||
|
if (view.getUint32(offset, true) === signature) return offset;
|
||||||
|
}
|
||||||
|
throw new Error("Signature not found in test ZIP");
|
||||||
|
}
|
||||||
|
|
||||||
|
function mediaFor(path: string): string {
|
||||||
|
if (path.endsWith(".png")) return "image/png";
|
||||||
|
if (path.endsWith(".svg")) return "image/svg+xml";
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
|
||||||
|
function ownedBuffer(bytes: Uint8Array): ArrayBuffer {
|
||||||
|
const copy = new Uint8Array(bytes.byteLength);
|
||||||
|
copy.set(bytes);
|
||||||
|
return copy.buffer;
|
||||||
|
}
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import {
|
||||||
|
collectOdfTransferables,
|
||||||
|
parseOdp,
|
||||||
|
parseOds,
|
||||||
|
parseOdt,
|
||||||
|
parseOpenDocument,
|
||||||
|
} from "../../../src/office/odf";
|
||||||
|
import { makeOdf, odpContent, odsContent, odtContent, XMLNS } from "./fixtures";
|
||||||
|
|
||||||
|
const PIXEL = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||||
|
|
||||||
|
describe("OpenDocument normalized models", () => {
|
||||||
|
it("parses ODT metadata, styles, rich text, lists, tables, images, and notes", () => {
|
||||||
|
const content = odtContent(`
|
||||||
|
<text:h text:outline-level="2">A heading</text:h>
|
||||||
|
<text:p text:style-name="Body">Hello<text:s text:c="2"/><text:span text:style-name="InlineBold">world</text:span><text:tab/>!
|
||||||
|
<text:note text:id="note-1" text:note-class="footnote">
|
||||||
|
<text:note-citation>1</text:note-citation>
|
||||||
|
<text:note-body><text:p>Footnote body</text:p></text:note-body>
|
||||||
|
</text:note>
|
||||||
|
</text:p>
|
||||||
|
<text:list text:style-name="Bullets">
|
||||||
|
<text:list-item><text:p>First</text:p></text:list-item>
|
||||||
|
<text:list-item><text:p>Second</text:p></text:list-item>
|
||||||
|
</text:list>
|
||||||
|
<table:table table:name="Data"><table:table-row table:number-rows-repeated="2">
|
||||||
|
<table:table-cell table:number-columns-spanned="2"><text:p>Cell</text:p></table:table-cell>
|
||||||
|
<table:covered-table-cell/>
|
||||||
|
</table:table-row></table:table>
|
||||||
|
<draw:frame draw:style-name="Graphic" svg:x="1cm" svg:y="2cm" svg:width="3cm" svg:height="4cm">
|
||||||
|
<draw:image xlink:href="Pictures/pixel.png"/>
|
||||||
|
<svg:title>Pixel</svg:title><svg:desc>A tiny pixel</svg:desc>
|
||||||
|
</draw:frame>`);
|
||||||
|
const meta = `<?xml version="1.0"?><office:document-meta ${XMLNS}>
|
||||||
|
<office:meta><dc:title>Test document</dc:title><dc:creator>Ada</dc:creator>
|
||||||
|
<meta:keyword>local</meta:keyword><meta:keyword>office</meta:keyword>
|
||||||
|
<meta:document-statistic meta:word-count="8" meta:page-count="1"/>
|
||||||
|
</office:meta></office:document-meta>`;
|
||||||
|
const styles = `<?xml version="1.0"?><office:document-styles ${XMLNS}><office:styles>
|
||||||
|
<style:style style:name="Body" style:family="paragraph" style:display-name="Body text">
|
||||||
|
<style:paragraph-properties fo:text-align="start"/>
|
||||||
|
</style:style></office:styles></office:document-styles>`;
|
||||||
|
const result = parseOdt(
|
||||||
|
makeOdf("odt", content, {
|
||||||
|
extra: { "Pictures/pixel.png": PIXEL },
|
||||||
|
meta,
|
||||||
|
styles,
|
||||||
|
}),
|
||||||
|
{ fileName: "example.odt" },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.format).toBe("odt");
|
||||||
|
expect(result.metadata).toMatchObject({
|
||||||
|
title: "Test document",
|
||||||
|
creator: "Ada",
|
||||||
|
keywords: ["local", "office"],
|
||||||
|
statistics: { wordCount: 8, pageCount: 1 },
|
||||||
|
});
|
||||||
|
expect(result.styles).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "Body",
|
||||||
|
family: "paragraph",
|
||||||
|
properties: { "paragraph-properties.fo:text-align": "start" },
|
||||||
|
}),
|
||||||
|
expect.objectContaining({ name: "InlineBold", family: "text" }),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
expect(result.blocks[0]).toMatchObject({
|
||||||
|
kind: "heading",
|
||||||
|
level: 2,
|
||||||
|
text: "A heading",
|
||||||
|
});
|
||||||
|
expect(result.blocks[1]).toMatchObject({
|
||||||
|
kind: "paragraph",
|
||||||
|
text: expect.stringContaining("Hello world\t!"),
|
||||||
|
runs: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ text: "world", styleName: "InlineBold" }),
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
expect(result.blocks[2]).toMatchObject({ kind: "list", items: [{}, {}] });
|
||||||
|
expect(result.blocks[3]).toMatchObject({
|
||||||
|
kind: "table",
|
||||||
|
name: "Data",
|
||||||
|
rows: [{ rowRepeat: 2, cells: [{ columnSpan: 2 }, { covered: true }] }],
|
||||||
|
});
|
||||||
|
expect(result.blocks[4]).toMatchObject({
|
||||||
|
kind: "image",
|
||||||
|
assetId: "asset-1",
|
||||||
|
alt: "A tiny pixel",
|
||||||
|
title: "Pixel",
|
||||||
|
width: { value: 3, unit: "cm" },
|
||||||
|
});
|
||||||
|
expect(result.notes).toHaveLength(1);
|
||||||
|
expect(result.notes[0]).toMatchObject({ id: "note-1", citation: "1" });
|
||||||
|
expect(result.assets[0]).toMatchObject({
|
||||||
|
id: "asset-1",
|
||||||
|
path: "Pictures/pixel.png",
|
||||||
|
mediaType: "image/png",
|
||||||
|
byteLength: PIXEL.byteLength,
|
||||||
|
});
|
||||||
|
expect(new Uint8Array(result.assets[0]!.data)).toEqual(PIXEL);
|
||||||
|
expect(collectOdfTransferables(result)).toEqual([result.assets[0]!.data]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses ODS sheets, typed values, formulas, repeats, merges, and annotations", () => {
|
||||||
|
const content = odsContent(`
|
||||||
|
<table:table table:name="Budget" table:style-name="SheetStyle" table:protected="true">
|
||||||
|
<table:table-row table:number-rows-repeated="2" table:style-name="RowStyle">
|
||||||
|
<table:table-cell office:value-type="string" office:string-value="Name"><text:p>Name</text:p></table:table-cell>
|
||||||
|
<table:table-cell table:number-columns-repeated="2" office:value-type="float" office:value="42.5"
|
||||||
|
table:formula="of:=SUM([.B1:.C1])"><text:p>42.50</text:p>
|
||||||
|
<office:annotation><text:p>Cached value only</text:p></office:annotation>
|
||||||
|
</table:table-cell>
|
||||||
|
<table:table-cell table:number-columns-spanned="2" table:number-rows-spanned="2" office:value-type="boolean" office:boolean-value="true"><text:p>TRUE</text:p></table:table-cell>
|
||||||
|
<table:covered-table-cell/>
|
||||||
|
</table:table-row>
|
||||||
|
</table:table>`);
|
||||||
|
const result = parseOds(makeOdf("ods", content));
|
||||||
|
const sheet = result.sheets[0]!;
|
||||||
|
|
||||||
|
expect(sheet).toMatchObject({
|
||||||
|
name: "Budget",
|
||||||
|
styleName: "SheetStyle",
|
||||||
|
protected: true,
|
||||||
|
expandedRowCount: 2,
|
||||||
|
expandedCellCount: 10,
|
||||||
|
});
|
||||||
|
expect(sheet.rows[0]).toMatchObject({
|
||||||
|
index: 0,
|
||||||
|
rowRepeat: 2,
|
||||||
|
styleName: "RowStyle",
|
||||||
|
});
|
||||||
|
expect(sheet.rows[0]!.cells).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({ column: 0, value: "Name", display: "Name" }),
|
||||||
|
expect.objectContaining({
|
||||||
|
column: 1,
|
||||||
|
columnRepeat: 2,
|
||||||
|
value: 42.5,
|
||||||
|
formula: "of:=SUM([.B1:.C1])",
|
||||||
|
display: "42.50",
|
||||||
|
annotation: [
|
||||||
|
expect.objectContaining({
|
||||||
|
kind: "paragraph",
|
||||||
|
text: "Cached value only",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
column: 3,
|
||||||
|
columnSpan: 2,
|
||||||
|
rowSpan: 2,
|
||||||
|
value: true,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({ column: 4, kind: "covered" }),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("trims office-suite full-grid tail repeats without expanding them", () => {
|
||||||
|
const content = odsContent(`
|
||||||
|
<table:table table:name="Used range">
|
||||||
|
<table:table-row>
|
||||||
|
<table:table-cell office:value-type="string"><text:p>Only value</text:p></table:table-cell>
|
||||||
|
<table:table-cell table:number-columns-repeated="16383"/>
|
||||||
|
</table:table-row>
|
||||||
|
<table:table-row table:number-rows-repeated="1048575">
|
||||||
|
<table:table-cell table:number-columns-repeated="16384"/>
|
||||||
|
</table:table-row>
|
||||||
|
</table:table>`);
|
||||||
|
const sheet = parseOds(makeOdf("ods", content)).sheets[0]!;
|
||||||
|
|
||||||
|
expect(sheet.expandedRowCount).toBe(1);
|
||||||
|
expect(sheet.expandedCellCount).toBe(1);
|
||||||
|
expect(sheet.rows).toHaveLength(1);
|
||||||
|
expect(sheet.rows[0]!.cells).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses ODP slides, coordinates, text, shapes, images, tables, groups, and notes", () => {
|
||||||
|
const content = odpContent(`
|
||||||
|
<draw:page draw:name="Opening" draw:style-name="SlideStyle" draw:master-page-name="Master"
|
||||||
|
presentation:presentation-page-layout-name="TitleLayout">
|
||||||
|
<draw:frame draw:id="title" draw:name="Title" svg:x="1cm" svg:y="2cm" svg:width="20cm" svg:height="3cm">
|
||||||
|
<draw:text-box><text:p>Local Office</text:p></draw:text-box>
|
||||||
|
</draw:frame>
|
||||||
|
<draw:rect draw:name="Accent" svg:x="2cm" svg:y="6cm" svg:width="5cm" svg:height="2cm"><text:p>Box</text:p></draw:rect>
|
||||||
|
<draw:frame draw:id="picture" svg:x="8cm" svg:y="6cm" svg:width="4cm" svg:height="4cm">
|
||||||
|
<draw:image xlink:href="Pictures/pixel.png"/>
|
||||||
|
</draw:frame>
|
||||||
|
<draw:frame draw:id="grid" svg:x="1cm" svg:y="11cm" svg:width="10cm" svg:height="4cm">
|
||||||
|
<table:table table:name="Slide table"><table:table-row><table:table-cell><text:p>A1</text:p></table:table-cell></table:table-row></table:table>
|
||||||
|
</draw:frame>
|
||||||
|
<draw:g draw:id="group"><draw:ellipse draw:id="circle" svg:x="1cm" svg:y="1cm" svg:width="1cm" svg:height="1cm"/></draw:g>
|
||||||
|
<presentation:notes><text:p>Speaker note</text:p></presentation:notes>
|
||||||
|
</draw:page>`);
|
||||||
|
const result = parseOdp(
|
||||||
|
makeOdf("odp", content, { extra: { "Pictures/pixel.png": PIXEL } }),
|
||||||
|
);
|
||||||
|
const slide = result.slides[0]!;
|
||||||
|
|
||||||
|
expect(slide).toMatchObject({
|
||||||
|
name: "Opening",
|
||||||
|
styleName: "SlideStyle",
|
||||||
|
masterPageName: "Master",
|
||||||
|
layoutName: "TitleLayout",
|
||||||
|
notes: [
|
||||||
|
expect.objectContaining({ kind: "paragraph", text: "Speaker note" }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(slide.shapes).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "title",
|
||||||
|
type: "text-box",
|
||||||
|
x: { value: 1, unit: "cm", raw: "1cm" },
|
||||||
|
blocks: [
|
||||||
|
expect.objectContaining({
|
||||||
|
kind: "paragraph",
|
||||||
|
text: "Local Office",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
expect.objectContaining({ type: "rectangle", name: "Accent" }),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "picture",
|
||||||
|
type: "image",
|
||||||
|
image: expect.objectContaining({ assetId: "asset-1" }),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "grid",
|
||||||
|
type: "table",
|
||||||
|
table: expect.objectContaining({ name: "Slide table" }),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "group",
|
||||||
|
type: "group",
|
||||||
|
children: [
|
||||||
|
expect.objectContaining({ id: "circle", type: "ellipse" }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("auto-detects formats without parsing the package twice and warns on a missing manifest", () => {
|
||||||
|
const document = parseOpenDocument(
|
||||||
|
makeOdf("odt", odtContent("<text:p>Minimal</text:p>"), {
|
||||||
|
manifest: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(document.format).toBe("odt");
|
||||||
|
expect(document.warnings).toContain("Package has no META-INF/manifest.xml");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import {
|
||||||
|
OdfParseError,
|
||||||
|
parseOdt,
|
||||||
|
parseOpenDocument,
|
||||||
|
} from "../../../src/office/odf";
|
||||||
|
import {
|
||||||
|
corruptFirstCentralCrc,
|
||||||
|
makeManifest,
|
||||||
|
makeOdf,
|
||||||
|
MEDIA_TYPES,
|
||||||
|
odtContent,
|
||||||
|
odsContent,
|
||||||
|
XMLNS,
|
||||||
|
zipWithEncodedCollision,
|
||||||
|
zipWithTraversal,
|
||||||
|
} from "./fixtures";
|
||||||
|
|
||||||
|
function expectOdfError(
|
||||||
|
action: () => unknown,
|
||||||
|
code: OdfParseError["code"],
|
||||||
|
): void {
|
||||||
|
try {
|
||||||
|
action();
|
||||||
|
throw new Error("Expected ODF parser to reject the fixture");
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeInstanceOf(OdfParseError);
|
||||||
|
expect((error as OdfParseError).code).toBe(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("OpenDocument package and XML security boundaries", () => {
|
||||||
|
it("rejects non-ZIP input and unsafe traversal paths", () => {
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(new Uint8Array([1, 2, 3]).buffer),
|
||||||
|
"invalid-zip",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
zipWithTraversal(odtContent("<text:p>Safe</text:p>")),
|
||||||
|
),
|
||||||
|
"invalid-path",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
zipWithEncodedCollision(odtContent("<text:p>Safe</text:p>")),
|
||||||
|
),
|
||||||
|
"invalid-path",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects CRC corruption", () => {
|
||||||
|
const fixture = makeOdf("odt", odtContent("<text:p>Integrity</text:p>"));
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(corruptFirstCentralCrc(fixture)),
|
||||||
|
"invalid-zip",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects expected-format, filename, manifest, and body type mismatches", () => {
|
||||||
|
const ods = makeOdf("ods", odsContent('<table:table table:name="S"/>'));
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(ods, { expectedFormat: "odt" }),
|
||||||
|
"type-mismatch",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(ods, { fileName: "wrong.odt" }),
|
||||||
|
"type-mismatch",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
makeOdf("odt", odtContent("<text:p>x</text:p>"), {
|
||||||
|
manifest: makeManifest(MEDIA_TYPES.ods),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
"type-mismatch",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOdt(makeOdf("odt", odsContent('<table:table table:name="S"/>'))),
|
||||||
|
"type-mismatch",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects encrypted package declarations", () => {
|
||||||
|
const manifest = `<?xml version="1.0"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
|
||||||
|
<manifest:file-entry manifest:full-path="/" manifest:media-type="${MEDIA_TYPES.odt}"/>
|
||||||
|
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml">
|
||||||
|
<manifest:encryption-data/>
|
||||||
|
</manifest:file-entry></manifest:manifest>`;
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
makeOdf("odt", odtContent("<text:p>x</text:p>"), { manifest }),
|
||||||
|
),
|
||||||
|
"encrypted",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts manifest directories represented implicitly by child entries", () => {
|
||||||
|
const manifest = `<?xml version="1.0"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
|
||||||
|
<manifest:file-entry manifest:full-path="/" manifest:media-type="${MEDIA_TYPES.odt}"/>
|
||||||
|
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
|
||||||
|
<manifest:file-entry manifest:full-path="Object 1/" manifest:media-type="application/vnd.oasis.opendocument.text"/>
|
||||||
|
</manifest:manifest>`;
|
||||||
|
const document = parseOpenDocument(
|
||||||
|
makeOdf("odt", odtContent("<text:p>Safe</text:p>"), {
|
||||||
|
manifest,
|
||||||
|
extra: {
|
||||||
|
"Object 1/content.xml": new TextEncoder().encode("unused"),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(document.format).toBe("odt");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects malformed XML, DTDs/entities, and excessive XML depth", () => {
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(makeOdf("odt", "<office:document-content>")),
|
||||||
|
"invalid-xml",
|
||||||
|
);
|
||||||
|
const entity = `<?xml version="1.0"?><!DOCTYPE x [<!ENTITY local "bad">]>
|
||||||
|
<office:document-content ${XMLNS}><office:body><office:text><text:p>&local;</text:p></office:text></office:body></office:document-content>`;
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(makeOdf("odt", entity)),
|
||||||
|
"invalid-xml",
|
||||||
|
);
|
||||||
|
const nested =
|
||||||
|
`<text:section>`.repeat(8) +
|
||||||
|
`<text:p>x</text:p>` +
|
||||||
|
`</text:section>`.repeat(8);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(makeOdf("odt", odtContent(nested)), {
|
||||||
|
limits: { maxXmlDepth: 6 },
|
||||||
|
}),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
const compact = `<?xml version="1.0"?><office:document-content ${XMLNS}><office:body><office:text><text:p>x</text:p></office:text></office:body></office:document-content>`;
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(makeOdf("odt", compact, { manifest: false }), {
|
||||||
|
limits: { maxXmlNodes: 4 },
|
||||||
|
}),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects dangerous external images and active links", () => {
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
makeOdf(
|
||||||
|
"odt",
|
||||||
|
odtContent(
|
||||||
|
'<draw:frame><draw:image xlink:href="https://tracker.example/image.png"/></draw:frame>',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"external-resource",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() =>
|
||||||
|
parseOpenDocument(
|
||||||
|
makeOdf(
|
||||||
|
"odt",
|
||||||
|
odtContent(
|
||||||
|
'<text:p><text:a xlink:href="javascript:alert(1)">bad</text:a></text:p>',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"external-resource",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps embedded objects inert and reports their omission", () => {
|
||||||
|
const document = parseOpenDocument(
|
||||||
|
makeOdf("odt", odtContent('<draw:object xlink:href="Object 1"/>')),
|
||||||
|
);
|
||||||
|
if (document.format !== "odt") throw new Error("Expected an ODT model");
|
||||||
|
expect(document.blocks).toEqual([]);
|
||||||
|
expect(document.warnings).toContain(
|
||||||
|
"1 embedded object was kept inert and omitted",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("enforces entry, total, text, asset, repeat, and expanded-cell limits", () => {
|
||||||
|
const basic = makeOdf("odt", odtContent("<text:p>123456789</text:p>"));
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(basic, { limits: { maxEntryBytes: 32 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(basic, { limits: { maxTotalBytes: 50 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(basic, { limits: { maxEntries: 2 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(basic, { limits: { maxTextChars: 5 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
|
||||||
|
const repeated = makeOdf(
|
||||||
|
"ods",
|
||||||
|
odsContent(
|
||||||
|
'<table:table table:name="Huge"><table:table-row table:number-rows-repeated="4"><table:table-cell table:number-columns-repeated="4" office:value-type="string"><text:p>x</text:p></table:table-cell></table:table-row></table:table>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(repeated, { limits: { maxRepeat: 3 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(repeated, { limits: { maxCells: 15 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
|
||||||
|
const image = new Uint8Array([137, 80, 78, 71, 1, 2, 3, 4]);
|
||||||
|
const imageDocument = makeOdf(
|
||||||
|
"odt",
|
||||||
|
odtContent(
|
||||||
|
'<draw:frame><draw:image xlink:href="Pictures/a.png"/></draw:frame>',
|
||||||
|
),
|
||||||
|
{ extra: { "Pictures/a.png": image } },
|
||||||
|
);
|
||||||
|
expectOdfError(
|
||||||
|
() => parseOpenDocument(imageDocument, { limits: { maxAssetBytes: 4 } }),
|
||||||
|
"limit-exceeded",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("validates option limits before reading untrusted input", () => {
|
||||||
|
expect(() =>
|
||||||
|
parseOpenDocument(new ArrayBuffer(0), { limits: { maxEntries: 0 } }),
|
||||||
|
).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { describeOoxmlError } from "../../src/office/ooxml-errors";
|
||||||
|
|
||||||
|
describe("OOXML error descriptions", () => {
|
||||||
|
it("offers an in-memory password retry for supported encryption", () => {
|
||||||
|
const description = describeOoxmlError(
|
||||||
|
Object.assign(new Error("encrypted"), { code: "encrypted" }),
|
||||||
|
);
|
||||||
|
expect(description.passwordRequired).toBe(true);
|
||||||
|
expect(description.message).toContain("password protected");
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
"unsupported-encryption",
|
||||||
|
"legacy-binary-format",
|
||||||
|
"not-ooxml",
|
||||||
|
"ooxml-resource-limit",
|
||||||
|
"ooxml-decoded-image-limit",
|
||||||
|
"parser-crashed",
|
||||||
|
])("provides a stable safe message for %s", (code) => {
|
||||||
|
const description = describeOoxmlError(
|
||||||
|
Object.assign(new Error("internal diagnostic"), { code }),
|
||||||
|
);
|
||||||
|
expect(description.code).toBe(code);
|
||||||
|
expect(description.passwordRequired).toBe(false);
|
||||||
|
expect(description.message).not.toBe("internal diagnostic");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("retains an ordinary parser message as the fallback", () => {
|
||||||
|
expect(describeOoxmlError(new Error("Malformed package")).message).toBe(
|
||||||
|
"Malformed package",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { manifest } from "../../src/toolbox/manifest";
|
||||||
|
import { APP_VERSION } from "../../src/version";
|
||||||
|
|
||||||
|
describe("Toolbox manifest", () => {
|
||||||
|
it("keeps the release and source identity pinned", () => {
|
||||||
|
expect(manifest.id).toBe("de.add-ideas.office-tools");
|
||||||
|
expect(manifest.version).toBe(APP_VERSION);
|
||||||
|
expect(manifest.entry).toBe("./");
|
||||||
|
expect(manifest.source).toEqual({
|
||||||
|
repository: "https://git.add-ideas.de/lotobo/office-tools",
|
||||||
|
license: "GPL-3.0-or-later",
|
||||||
|
});
|
||||||
|
expect(manifest.privacy).toMatchObject({
|
||||||
|
processing: "local",
|
||||||
|
fileUploads: false,
|
||||||
|
telemetry: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "ES2023",
|
||||||
|
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"allowArbitraryExtensions": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"strict": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
},
|
||||||
|
"include": ["src", "tests"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "ES2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"vite.config.ts",
|
||||||
|
"playwright.config.ts",
|
||||||
|
"eslint.config.mjs",
|
||||||
|
"scripts/**/*.mjs"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/// <reference types="vitest/config" />
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
base: "./",
|
||||||
|
plugins: [react()],
|
||||||
|
test: {
|
||||||
|
environment: "jsdom",
|
||||||
|
setupFiles: "./src/test/setup.ts",
|
||||||
|
css: true,
|
||||||
|
maxWorkers: 2,
|
||||||
|
restoreMocks: true,
|
||||||
|
exclude: ["tests/browser/**", "node_modules/**", "dist/**"],
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user