feat: a thesaurus, LibreOffice's own synonyms
Ctrl+F7, Review ▸ Thesaurus and the context menu open one dialog: the word at the caret, the sense groups it is in, click one to replace it, and a box to look up any other word. The data is MyThes re-packed to one group per line (de 3.0MB/37k groups, en 6.7MB/143k) — the format repeats every group once per member, ten times the bytes. Loaded on first use for the document's language and scanned, not indexed: ~4ms a lookup, where a word→group index measured ~100MB of memory against the text's ~8MB.
This commit is contained in:
1 parent
5b88de8c19
commit
44b351e865
21 files changed
+181348
-4
No files matched your search
+2
-1
@@ -148,6 +148,7 @@
|
||||
- Line numbering (Layout ▸ Line numbers, LibreOffice's Tools ▸ Line Numbering): numbers in the left margin, continuous or restarting each page, every nth line, with or without empty lines. Measured off the rendered lines, so the preview and the saved file agree; round-trips as ODF `text:linenumbering-configuration` and Word's `w:lnNumType`
|
||||
- Page design (Layout ▸ Page design): a page background colour, a border around the text area at a settable distance from it, and a text watermark with its own colour, angle and transparency — LibreOffice's Format ▸ Page Style ▸ Area/Borders and its Format ▸ Watermark. All three round-trip: ODF keeps them on the page layout and the master page's header, Word on `w:document` / `w:sectPr` / a VML shape in the header part
|
||||
- Captions (References ▸ Caption, LibreOffice's Insert ▸ Caption): a caption paragraph in the `Caption` style with a running number that counts itself — one counter per category (figure / table), in document order, renumbering as the document is edited. Round-trips as an ODF `<text:sequence>` (with LibreOffice's own `ooow:Illustration+1` formula) and a Word `SEQ Figure \* ARABIC` field
|
||||
- Thesaurus (Ctrl+F7, Review ▸ Thesaurus, the context menu): the word at the caret, the sense groups it appears in, click one to replace it — and a box to look up any other word. The synonyms are LibreOffice's own, its MyThes data re-packed to one group per line (`scripts/make-thesaurus.mjs`, de 3.0 MB / 37k groups, en 6.7 MB / 143k). It loads on first use for the document's language and is scanned, not indexed: ~4 ms per lookup against the ~100 MB an index would cost
|
||||
- Word (.docx) export and import — round-trips the editor's formatting (text, fonts, lists, tables, images, headers/footers, page geometry) and opens real Word documents
|
||||
- Document properties (title, subject, author, keywords, comments) in the File menu — LibreOffice's File ▸ Properties / Word's File ▸ Info. Round-trips through ODF `meta.xml` (one `meta:keyword` per keyword) and DOCX `docProps/core.xml`
|
||||
- File handlers: the installed app registers for `.odt` / `.ott` / `.docx` / `.dotx`, so the OS offers it for a double-clicked document and hands the file over through `launchQueue` — with its handle, so the first Save writes that same file. Word templates (`.dotx`) open like `.ott` does: read for their content, never bound as the file to save over
|
||||
@@ -169,7 +170,7 @@ The gap against Word/LibreOffice, most valuable first. Reviewed 2026-08-15.
|
||||
- A list level's own hanging indent: the marker sits at the 0.635 cm both exports write (`LIST_HANGING_CM`), so a wider *left*-set marker overflows where Word moves the text to the next list tab (a **right**-set one — `w:lvlJc`, which is what the built-in Roman numberings use — grows into the margin and is fine). Reading the value back naively also moves the markers of our own ODT exports — LibreOffice draws its own flat hanging at exactly the value odf-kit writes for level 2; see `tests/render-parity/README.md` before building on it
|
||||
- Linked / chained text frames: text overflowing one frame continues in the next, which is a layout engine's job — CSS Regions would do it and no engine implements them
|
||||
- Multi-document management: one document is open at a time, so there is no window list and no side-by-side compare
|
||||
- Thesaurus and grammar check
|
||||
- Grammar check: there is no offline engine small enough to bundle, and the ones that exist are servers
|
||||
- A vertical writing mode for the **page** (ODF `tb-rl` on the page layout): a text box can run its text top-to-bottom, the body cannot — pagination fills a page downwards. A ruby annotation's own alignment and position are not offered either; both products' defaults are what we write
|
||||
- Password-protected ODT/DOCX; digital signatures. ODF encrypts each zip entry (AES-256-CBC, PBKDF2, the manifest carrying salt, IV and checksum), which WebCrypto can do; Word's is an OLE compound file we would have to write from scratch, so the two legs are nowhere near the same size
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ npm test # Vitest suite once (tests/**/*.test.ts)
|
||||
npm run test:watch # Vitest in watch mode
|
||||
npm run test:lo # LibreOffice round-trip leg only (needs `soffice` on PATH)
|
||||
npm run test:parity # render parity vs LibreOffice (tests/render-parity/README.md)
|
||||
node scripts/make-thesaurus.mjs # re-vendor public/thesaurus/ from LibreOffice's MyThes data
|
||||
```
|
||||
|
||||
Tests live in `tests/` (outside `src/`, so `svelte-check` ignores them), jsdom via Vitest.
|
||||
|
||||
+21
-2
@@ -5,8 +5,10 @@ v3.0 (see [`LICENSE`](./LICENSE)), with a separate commercial license available
|
||||
(see [`LICENSE.commercial.md`](./LICENSE.commercial.md)).
|
||||
|
||||
It bundles and depends on third-party components that remain under **their own**
|
||||
licenses, listed below. All of these licenses are permissive and compatible with
|
||||
both the AGPL distribution and a commercial distribution of this project.
|
||||
licenses, listed below. The code dependencies and the fonts are permissive and
|
||||
compatible with both the AGPL distribution and a commercial distribution of this
|
||||
project; the bundled **language data** is a separate question — some of it is
|
||||
copyleft, see its section.
|
||||
|
||||
## Bundled fonts — retain their own license
|
||||
|
||||
@@ -24,6 +26,23 @@ licensed.
|
||||
> not sold by themselves. The fonts must not be redistributed under their Reserved
|
||||
> Font Names if modified.
|
||||
|
||||
## Bundled language data — retains its own license
|
||||
|
||||
Vendored under `public/`, each with its upstream license file beside it. None of
|
||||
it is part of this project's code: a distribution that cannot carry a copyleft
|
||||
data set may drop that folder, and the app then simply offers no dictionary or
|
||||
thesaurus for the language.
|
||||
|
||||
| Data | License |
|
||||
|------|---------|
|
||||
| `public/dictionaries/de` — Hunspell, igerman98 | GPL-2.0 or GPL-3.0 |
|
||||
| `public/dictionaries/en` — Hunspell, from SCOWL | permissive (BSD-style) |
|
||||
| `public/thesaurus/de` — OpenThesaurus | LGPL-2.1-or-later |
|
||||
| `public/thesaurus/en` — WordNet 2.1, Princeton University | WordNet license (permissive) |
|
||||
|
||||
Both thesaurus files are generated from LibreOffice's own MyThes data by
|
||||
`scripts/make-thesaurus.mjs`, which also fetches the license files above.
|
||||
|
||||
## Runtime / build dependencies
|
||||
|
||||
| Component | License |
|
||||
|
||||
@@ -0,0 +1,524 @@
|
||||
OpenThesaurus - Deutscher Thesaurus - Version für OpenOffice.org
|
||||
Copyright (C) 2003-2017 Daniel Naber (naber at danielnaber de)
|
||||
Snapshot, automatisch generiert 2017-01-06 23:22 (DE/AT)
|
||||
Homepage: http://www.openthesaurus.de
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Lizenz: ===================================================================
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
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 this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey 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 library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,31 @@
|
||||
WordNet Release 2.1
|
||||
|
||||
This software and database is being provided to you, the LICENSEE, by
|
||||
Princeton University under the following license. By obtaining, using
|
||||
and/or copying this software and database, you agree that you have
|
||||
read, understood, and will comply with these terms and conditions.:
|
||||
|
||||
Permission to use, copy, modify and distribute this software and
|
||||
database and its documentation for any purpose and without fee or
|
||||
royalty is hereby granted, provided that you agree to comply with
|
||||
the following copyright notice and statements, including the disclaimer,
|
||||
and that the same appear on ALL copies of the software, database and
|
||||
documentation, including modifications that you make for internal
|
||||
use or for distribution.
|
||||
|
||||
WordNet 2.1 Copyright 2005 by Princeton University. All rights reserved.
|
||||
|
||||
THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON
|
||||
UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
||||
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON
|
||||
UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT-
|
||||
ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE
|
||||
OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT
|
||||
INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR
|
||||
OTHER RIGHTS.
|
||||
|
||||
The name of Princeton University or Princeton may not be used in
|
||||
advertising or publicity pertaining to distribution of the software
|
||||
and/or database. Title to copyright in this software, database and
|
||||
any associated documentation shall at all times remain with
|
||||
Princeton University and LICENSEE agrees to preserve same.
|
||||
+143054
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,45 @@
|
||||
// Regenerates public/thesaurus/<code>/ from LibreOffice's own MyThes data: one
|
||||
// synonym group per line, ';'-separated, usage notes like "(ugs.)" dropped.
|
||||
// MyThes repeats every group once per member — 10x the bytes for the same content.
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
|
||||
const REPO = 'https://raw.githubusercontent.com/LibreOffice/dictionaries/master';
|
||||
const SOURCES = [
|
||||
{ code: 'de', dat: 'de/th_de_DE_v2.dat', license: 'de/README_thesaurus.txt' },
|
||||
{ code: 'en', dat: 'en/th_en_US_v2.dat', license: 'en/WordNet_license.txt' },
|
||||
];
|
||||
|
||||
// "(noun)", "(ugs.)", "(generic term)" — a label to read, not a word to insert.
|
||||
const clean = (word) => word.replace(/\([^)]*\)/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
|
||||
// MyThes: a "headword|senseCount" line, then that many "(pos)|syn|syn|…" lines.
|
||||
function groups(dat) {
|
||||
const lines = dat.split('\n');
|
||||
const out = new Set();
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
const head = lines[i].split('|');
|
||||
const senses = Number(head.at(-1));
|
||||
if (head.length < 2 || !Number.isInteger(senses) || senses < 1) continue;
|
||||
for (let s = 0; s < senses; s++) {
|
||||
const words = [...new Set((lines[++i] ?? '').split('|').slice(1).map(clean).filter(Boolean))];
|
||||
if (words.length > 1) out.add(words.join(';'));
|
||||
}
|
||||
}
|
||||
return [...out].sort();
|
||||
}
|
||||
|
||||
const text = async (path) => {
|
||||
const res = await fetch(`${REPO}/${path}`);
|
||||
if (!res.ok) throw new Error(`${res.status} for ${path}`);
|
||||
return res.text();
|
||||
};
|
||||
|
||||
for (const source of SOURCES) {
|
||||
const [dat, license] = await Promise.all([text(source.dat), text(source.license)]);
|
||||
const dir = new URL(`../public/thesaurus/${source.code}/`, import.meta.url);
|
||||
await mkdir(dir, { recursive: true });
|
||||
const lines = groups(dat);
|
||||
await writeFile(new URL(`${source.code}.txt`, dir), lines.join('\n') + '\n');
|
||||
await writeFile(new URL('LICENSE', dir), license);
|
||||
console.log(`${source.code}: ${lines.length} groups`);
|
||||
}
|
||||
@@ -57,6 +57,8 @@
|
||||
import { OPEN_COMMENT_EVENT } from './lib/editor/extensions/comment';
|
||||
import AutoCorrectDialog from './lib/components/AutoCorrectDialog.svelte';
|
||||
import AutoTextDialog from './lib/components/AutoTextDialog.svelte';
|
||||
import ThesaurusDialog from './lib/components/ThesaurusDialog.svelte';
|
||||
import { OPEN_THESAURUS_EVENT } from './lib/spell/thesaurus';
|
||||
import StyleManagerDialog from './lib/components/StyleManagerDialog.svelte';
|
||||
import NoteOptionsDialog from './lib/components/NoteOptionsDialog.svelte';
|
||||
import { t } from './lib/i18n/i18n.svelte';
|
||||
@@ -179,6 +181,7 @@
|
||||
let lineNumbering: LineNumbering = $state(loadLineNumbering());
|
||||
let autoCorrectOpen = $state(false);
|
||||
let autoTextOpen = $state(false);
|
||||
let thesaurusOpen = $state(false);
|
||||
let commentsOpen = $state(false);
|
||||
let revisionsOpen = $state(false);
|
||||
let navigatorOpen = $state(false);
|
||||
@@ -689,6 +692,13 @@
|
||||
return () => window.removeEventListener(OPEN_COMMENT_EVENT, open);
|
||||
});
|
||||
|
||||
// The context menu and both chromes' Thesaurus entries open the one dialog here.
|
||||
$effect(() => {
|
||||
const open = () => (thesaurusOpen = true);
|
||||
window.addEventListener(OPEN_THESAURUS_EVENT, open);
|
||||
return () => window.removeEventListener(OPEN_THESAURUS_EVENT, open);
|
||||
});
|
||||
|
||||
// A document double-clicked in the OS reaches the installed app through launchQueue
|
||||
// (the manifest's `file_handlers`). It fires once at startup, so it waits for the
|
||||
// editor; the handle comes with write permission, so a later Save writes that file.
|
||||
@@ -943,6 +953,7 @@
|
||||
[DEFAULT_SHORTCUTS.findPrevious, () => (findOpen ? editor?.commands.findPrevious() : openFind('find'))],
|
||||
[DEFAULT_SHORTCUTS.formattingMarks, () => (showFormattingMarks = !showFormattingMarks)],
|
||||
[DEFAULT_SHORTCUTS.navigator, () => (navigatorOpen = !navigatorOpen)],
|
||||
[DEFAULT_SHORTCUTS.thesaurus, () => (thesaurusOpen = true)],
|
||||
[DEFAULT_SHORTCUTS.splitView, () => (splitView = !splitView)],
|
||||
[DEFAULT_SHORTCUTS.zoomIn, () => setZoom(zoom + 10)],
|
||||
[DEFAULT_SHORTCUTS.zoomOut, () => setZoom(zoom - 10)],
|
||||
@@ -1271,6 +1282,10 @@
|
||||
<button class="theme-option" onclick={() => { themeOpen = false; autoTextOpen = true; }} role="menuitem">
|
||||
<span>{t().autoText.title}</span>
|
||||
</button>
|
||||
<button class="theme-option" onclick={() => { themeOpen = false; thesaurusOpen = true; }} role="menuitem">
|
||||
<span>{t().thesaurus.title}</span>
|
||||
<span class="theme-option-hint">{shortcutHint('thesaurus')}</span>
|
||||
</button>
|
||||
<div class="theme-heading">{t().ribbon.chrome.title}</div>
|
||||
<button
|
||||
class="theme-option"
|
||||
@@ -1468,6 +1483,7 @@
|
||||
<AboutDialog bind:open={aboutOpen} />
|
||||
<AutoCorrectDialog bind:open={autoCorrectOpen} />
|
||||
<AutoTextDialog bind:open={autoTextOpen} editor={activeEditor} />
|
||||
<ThesaurusDialog bind:open={thesaurusOpen} editor={activeEditor} />
|
||||
<DocPropertiesDialog bind:open={docPropsOpen} props={docProps} onApply={(p) => { docProps = p; saveDocProperties(p); }} />
|
||||
<!-- One instance for every entry point (styles gallery, insert-table menu): the
|
||||
callers only say which family to land on. -->
|
||||
|
||||
@@ -151,6 +151,25 @@ Text group, the classic chrome's Tools menu): the library, a click to insert, an
|
||||
from selection" — the selected slice serialized to HTML. `hasSelection` is derived off
|
||||
`open` because the dialog stays mounted and a modal freezes the selection it opened on.
|
||||
|
||||
## Thesaurus (`ThesaurusDialog.svelte`, `spell/thesaurus.ts`)
|
||||
|
||||
LibreOffice's Tools ▸ Thesaurus (Ctrl+F7), reachable where Word puts it too (the ribbon's
|
||||
Review ▸ Proofing) and from the context menu: the word at the caret (`wordRangeAt`), the
|
||||
groups it appears in, click one to replace it. The box above looks up any other word,
|
||||
which is how both dialogs follow a chain.
|
||||
|
||||
- The data is `public/thesaurus/<code>/<code>.txt`, one `;`-separated group per line,
|
||||
generated from LibreOffice's own MyThes files by `scripts/make-thesaurus.mjs` — de 3.0MB
|
||||
/ 37k groups, en 6.7MB / 143k groups. MyThes repeats every group once per member, ten
|
||||
times the bytes for the same content.
|
||||
- **Scanned, not indexed**: a regex over the whole file is ~4ms, which a lookup started by
|
||||
a menu click can spend, where a word→group index costs ~100MB of memory against the ~8MB
|
||||
the text itself holds (both measured).
|
||||
- Loaded on first use, for the document's spell language only, and kept by the service
|
||||
worker from then on — like a dictionary, and missing data disables the feature, not the app.
|
||||
- The groups come back ordered by where the word sits in each: a group leads with its main
|
||||
form, which is the sense LibreOffice lists first as well.
|
||||
|
||||
## Navigator (`NavigatorPane.svelte`, `editor/extensions/outline.ts`)
|
||||
|
||||
LibreOffice's Navigator and Word's Navigation pane: the outline, click to jump, and the
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
<script lang="ts">
|
||||
import type { Editor } from '@tiptap/core';
|
||||
import { synonyms } from '../spell/thesaurus';
|
||||
import { spellController } from '../spell/controller';
|
||||
import { wordRangeAt } from '../editor/extensions/spellCheck';
|
||||
import { NO_LANGUAGE } from '../storage/documentLanguage';
|
||||
import { t } from '../i18n/i18n.svelte';
|
||||
|
||||
// LibreOffice's Tools ▸ Thesaurus (Ctrl+F7) / Word's Review ▸ Thesaurus: the word at
|
||||
// the caret, the groups it appears in, click one to replace it. The box above looks
|
||||
// up any other word, which is how both dialogs let you follow a chain.
|
||||
let { open = $bindable(false), editor }: { open?: boolean; editor: Editor | null } = $props();
|
||||
|
||||
let dialogEl = $state<HTMLDialogElement | null>(null);
|
||||
let term = $state('');
|
||||
let groups = $state<string[][]>([]);
|
||||
let busy = $state(false);
|
||||
// The range the dialog opened on. A modal freezes the selection, and the term above
|
||||
// may wander off it while the replacement still belongs to this word.
|
||||
let target = $state<{ from: number; to: number } | null>(null);
|
||||
|
||||
const language = $derived(open ? spellController.getLanguage() : NO_LANGUAGE);
|
||||
|
||||
$effect(() => {
|
||||
const el = dialogEl;
|
||||
if (!el) return;
|
||||
if (open && !el.open) el.showModal();
|
||||
else if (!open && el.open) el.close();
|
||||
});
|
||||
|
||||
// Re-read on each open, as the dialog stays mounted.
|
||||
$effect(() => {
|
||||
if (!open) return;
|
||||
const view = editor?.view;
|
||||
const range = view ? wordRangeAt(view.state, view.state.selection.from) : null;
|
||||
target = range ? { from: range.from, to: range.to } : null;
|
||||
void lookUp(range?.word ?? '');
|
||||
});
|
||||
|
||||
async function lookUp(word: string) {
|
||||
term = word;
|
||||
groups = [];
|
||||
if (!word.trim()) return;
|
||||
busy = true;
|
||||
const found = await synonyms(spellController.getLanguage(), word);
|
||||
if (term !== word) return; // a newer lookup superseded this one
|
||||
groups = found;
|
||||
busy = false;
|
||||
}
|
||||
|
||||
// Replace the looked-up range, preserving the word's marks (font/bold/etc.).
|
||||
function replace(word: string) {
|
||||
const view = editor?.view;
|
||||
if (view && target) {
|
||||
const { state } = view;
|
||||
const from = state.doc.resolve(target.from);
|
||||
const marks = from.marksAcross(state.doc.resolve(target.to)) ?? from.marks();
|
||||
view.dispatch(state.tr.replaceWith(target.from, target.to, state.schema.text(word, marks)).scrollIntoView());
|
||||
view.focus();
|
||||
}
|
||||
open = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
bind:this={dialogEl}
|
||||
onclose={() => (open = false)}
|
||||
onclick={(e) => e.target === dialogEl && (open = false)}
|
||||
aria-label={t().thesaurus.title}
|
||||
>
|
||||
<div class="body">
|
||||
<h2>{t().thesaurus.title}</h2>
|
||||
|
||||
<div class="lookup">
|
||||
<input
|
||||
bind:value={term}
|
||||
placeholder={t().thesaurus.word}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') { e.preventDefault(); void lookUp(term); } }}
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<button class="small" onclick={() => void lookUp(term)}>{t().thesaurus.lookUp}</button>
|
||||
</div>
|
||||
|
||||
{#if language === NO_LANGUAGE}
|
||||
<p class="hint">{t().thesaurus.noLanguage}</p>
|
||||
{:else if busy}
|
||||
<p class="hint">{t().thesaurus.loading}</p>
|
||||
{:else if groups.length}
|
||||
<p class="hint">{t().thesaurus.replaceHint}</p>
|
||||
<ul>
|
||||
{#each groups as group, i (i)}
|
||||
<li>
|
||||
{#each group as word (word)}
|
||||
<button class="syn" onclick={() => replace(word)} disabled={!target}>{word}</button>
|
||||
{/each}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else if term.trim()}
|
||||
<p class="hint">{t().thesaurus.noSynonyms}</p>
|
||||
{/if}
|
||||
|
||||
<div class="actions">
|
||||
<span class="spacer"></span>
|
||||
<button class="primary" onclick={() => (open = false)}>{t().common.close}</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog {
|
||||
/* The global reset zeroes every margin, which also takes the auto centring a
|
||||
modal <dialog> gets by default. */
|
||||
margin: auto;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 0;
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: 420px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
padding: 18px 20px 16px;
|
||||
font-family: var(--font-sans);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
h2 { font-size: 1rem; }
|
||||
.hint { color: var(--color-text-muted); }
|
||||
|
||||
.lookup { display: flex; gap: 6px; }
|
||||
input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
padding: 4px 6px;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
ul { display: flex; flex-direction: column; gap: 8px; list-style: none; }
|
||||
li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
li:last-child { padding-bottom: 0; border-bottom: none; }
|
||||
|
||||
.syn { border-radius: 999px; padding: 2px 10px; }
|
||||
|
||||
.actions { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
|
||||
.spacer { flex: 1; }
|
||||
|
||||
button {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
padding: 4px 10px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover:not(:disabled) { background: var(--color-btn-hover); }
|
||||
button:disabled { opacity: 0.5; cursor: default; }
|
||||
.actions .primary {
|
||||
border-color: var(--color-primary);
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -87,6 +87,8 @@ export const STROKED = {
|
||||
close: ['M3.5 3.5 12.5 12.5M12.5 3.5 3.5 12.5'],
|
||||
lineNumbers: ['M6 3h8.5M6 6.5h8.5M6 10h8.5M6 13.5h8.5', 'M2 2.2h1.1v3.3M1.6 5.5h1.9', 'M1.5 9.6c.2-.4.6-.5 1-.4.5.1.6.6.3 1L1.6 11.6h1.9'],
|
||||
wordCount: ['M2.5 2.5h11v11h-11z', 'M5 6h6M5 9h4'],
|
||||
// An open book, the glyph both word processors give the thesaurus.
|
||||
thesaurus: ['M8 4.5C6.5 3.4 4.4 3.1 2.2 3.3v9c2.2-.2 4.3.1 5.8 1.2 1.5-1.1 3.6-1.4 5.8-1.2v-9c-2.2-.2-4.3.1-5.8 1.2z', 'M8 4.5v9'],
|
||||
// A speech bubble with its tail, the shape both word processors use for a comment.
|
||||
comment: ['M2 3.25h12v7.5H7.5L4.5 13.5v-2.75H2z', 'M4.75 6h6.5M4.75 8.25h4'],
|
||||
// A word broken at a hyphen: two stubs with the dash between them.
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
import type { DocumentLanguage } from '../../../storage/documentLanguage';
|
||||
import { recordChanges, setRecordChanges } from '../../../storage/trackChanges.svelte';
|
||||
import { revisions } from '../../../editor/extensions/trackChanges';
|
||||
import { OPEN_THESAURUS_EVENT } from '../../../spell/thesaurus';
|
||||
import { shortcutHint } from '../../../editor/shortcuts';
|
||||
import { t } from '../../../i18n/i18n.svelte';
|
||||
|
||||
let { editor, tick, documentLanguage, onLanguage, onAutoCorrect, onNewComment, commentsOpen = false, onToggleComments, revisionsOpen = false, onToggleRevisions }: {
|
||||
@@ -47,6 +49,13 @@
|
||||
</script>
|
||||
|
||||
<RibbonGroup label={t().ribbon.groups.proofing}>
|
||||
<RibbonButton
|
||||
variant="big"
|
||||
icon="thesaurus"
|
||||
label={t().thesaurus.title}
|
||||
title={`${t().thesaurus.title} (${shortcutHint('thesaurus')})`}
|
||||
onclick={() => window.dispatchEvent(new CustomEvent(OPEN_THESAURUS_EVENT))}
|
||||
/>
|
||||
<div class="rb-menu-wrap" use:clickOutside={'wordCount'}>
|
||||
<RibbonButton
|
||||
variant="big"
|
||||
|
||||
@@ -6,6 +6,7 @@ import { OPEN_LINK_DIALOG_EVENT } from './extensions/link';
|
||||
import { OPEN_COMMENT_EVENT } from './extensions/comment';
|
||||
import { OPEN_BOOKMARK_DIALOG_EVENT, bookmarkNames } from './extensions/bookmark';
|
||||
import { OPEN_CROSS_REF_DIALOG_EVENT } from './extensions/crossReference';
|
||||
import { OPEN_THESAURUS_EVENT } from '../spell/thesaurus';
|
||||
|
||||
// The right-click menu's contents, the usual text menu mapped onto this editor. Pure
|
||||
// data + closures — ContextMenu.svelte only renders it.
|
||||
@@ -114,6 +115,12 @@ export function buildContextMenu(editor: Editor, opts: { spell?: SpellSection }
|
||||
|
||||
entries.push(
|
||||
{ kind: 'sep' },
|
||||
{
|
||||
kind: 'item',
|
||||
label: t().thesaurus.menuItem,
|
||||
hint: shortcutHint('thesaurus'),
|
||||
run: () => window.dispatchEvent(new CustomEvent(OPEN_THESAURUS_EVENT)),
|
||||
},
|
||||
{
|
||||
kind: 'item',
|
||||
label: m.clearFormatting,
|
||||
|
||||
@@ -35,7 +35,7 @@ Five topics are large enough to have their own deep-dive — read the file befor
|
||||
- **`ruby.ts`** — a reading printed over its base (LibreOffice's Format ▸ Asian Phonetic Guide, Word's Phonetic Guide). An inline **atom** carrying both halves, because that is what both formats write: one element holding a base and a reading, edited as a unit (`RubyDialog.svelte`). Rendered as a real `<ruby>`, so the browser sets it. Alignment and position are both products' defaults and are not offered.
|
||||
- **`bookmark.ts`** / **`crossReference.ts`** — a named range of text (a mark) and the live references to it (`REF`/`PAGEREF`). `ToolbarExpanded.svelte` owns both dialogs, as it does the link one.
|
||||
- **`searchReplace.ts`** — Find & Replace: decorations highlight all matches, commands navigate/replace. Touches the document only for actual replacements. `useRegex` takes the term as a pattern instead of escaping it (a whole-word search then wraps it in a non-capturing group first, so the `\b` guards bound the alternation); each match keeps its captures so `expandGroups` can fill `$1`…`$9`/`$&` in the replacement. A `FormatSpec` (weight/slant/underline, font, size and colour — LibreOffice's Format… — plus a paragraph style, its Paragraph Styles box) narrows a text search to the runs carrying it, and **with no term is the search**: every such run, or every paragraph in the style, empty ones included. The same spec on the replacement applies it — and a replacement with **no text** keeps the text and only reformats, which is how both dialogs restyle a document without retyping it. A style also switches the node type, as `setParagraphStyle` does, so the extension takes the same `sheet` option. Font, size and colour live together on one **TextStyle** mark, and a mark of one type replaces that type whole, so each run's own attrs are the base of the new one — replacing the colour leaves the font alone. Sizes compare by value (12pt and 12.0pt are one size), colours and family names case-insensitively.
|
||||
- **`spellCheck.ts`** — decorations from `spell/controller.ts`; `spellErrorAt` feeds the context menu.
|
||||
- **`spellCheck.ts`** — decorations from `spell/controller.ts`; `spellErrorAt` feeds the context menu, `wordRangeAt` the thesaurus (the word at a position, misspelled or not). Both define a word the same way, so what is looked up is what is highlighted.
|
||||
- **`outline.ts`** — the document's chapters for `NavigatorPane.svelte`: every **top-level** heading owning the blocks up to the next heading of its level or above (one inside a cell or a text box is not a chapter — moving it would move it out of its container). The two operations are pure functions the commands only apply: `chapterMove` returns the range to lift and where to put it back — the insert position for a move down is already corrected for the delete — and `chapterLevels` the headings a promote/demote rewrites, null when any of the subtree would leave 1…`maxLevel`. A move swaps with the adjacent chapter at the **same** level and stops at a heading above it, so a subheading never reparents itself; the level shift rewrites `styleName` too, or the paragraph would keep the old heading's look.
|
||||
- **`indexEntry.ts`** — one place marked for the alphabetical index: an inline **atom**, not a mark, because that is what both formats write (a point `text:alphabetical-index-mark`, a Word `XE` field). It carries the term, so the marked text and the word the index lists can differ, plus `key1` for the heading it files under. `indexRows` merges the marks into the index's rows — one per term, its pages de-duplicated and sorted, the terms sorted case-insensitively by locale.
|
||||
- **`bibliographyEntry.ts`** — one citation, an inline **atom** carrying the whole source record (`identifier`, `type`, and every remaining ODF field in one `fields` record, so a file's fields we have no UI for still round-trip). ODF puts that record on the mark itself, which is what lets the document travel without a database; Word keeps it in a custom-XML part and cites it by tag, so the same attrs feed both. The **citation style** (`utils/citationStyle.ts` — LibreOffice's cite-by-key, numbered, APA, MLA, Chicago) rides the bibliography index's node, which is where both formats keep it: a row is a token list, exactly what an ODF entry template is, so LibreOffice regenerates the same rows (it fills the types the document does not cite with its own default, so the import takes the first template reading as anything but `key`). Word gets the style as `b:Sources StyleName`. Each citation's label is derived, kept true by an `appendTransaction` off the undo stack like the caption numbers. `bibliographyRows` is the list: one row per source, **in document order** — LibreOffice's own default is document position, not alphabetical — reading "key: author, title, year", the shape its entry templates produce. `DOCX_SOURCE_TYPE`/`DOCX_BIB_FIELD` map onto Word's smaller set, and the fields it has no slot for survive only the ODF leg.
|
||||
|
||||
@@ -43,6 +43,23 @@ export function spellErrorAt(state: EditorState, pos: number): { from: number; t
|
||||
return found.length ? { from: found[0].from, to: found[0].to } : null;
|
||||
}
|
||||
|
||||
// The word covering `pos`, right or wrong — what the thesaurus looks up. Leaf nodes
|
||||
// are one character wide here, so the text offsets stay the document's.
|
||||
export function wordRangeAt(state: EditorState, pos: number): { from: number; to: number; word: string } | null {
|
||||
const $pos = state.doc.resolve(pos);
|
||||
if (!$pos.parent.isTextblock) return null;
|
||||
const start = $pos.start();
|
||||
const text = $pos.parent.textBetween(0, $pos.parent.content.size, undefined, '');
|
||||
const offset = pos - start;
|
||||
WORD_RE.lastIndex = 0;
|
||||
let m: RegExpExecArray | null;
|
||||
while ((m = WORD_RE.exec(text)) !== null) {
|
||||
if (m.index > offset) break;
|
||||
if (offset <= m.index + m[0].length) return { from: start + m.index, to: start + m.index + m[0].length, word: m[0] };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const SpellCheck = Extension.create({
|
||||
name: 'spellCheck',
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ export const DEFAULT_SHORTCUTS = {
|
||||
formattingMarks: 'Mod-F10',
|
||||
// LibreOffice's Navigator key; Word has none for its Navigation pane.
|
||||
navigator: 'F5',
|
||||
// LibreOffice's Thesaurus key; Word's Shift+F7 is free but its own find-previous is F3's.
|
||||
thesaurus: 'Mod-F7',
|
||||
// Word's own key for View ▸ Split; LibreOffice's split has none.
|
||||
splitView: 'Mod-Alt-s',
|
||||
zoomIn: 'Mod-+',
|
||||
|
||||
@@ -484,6 +484,16 @@ const de: Messages = {
|
||||
addToDictionary: 'Zum Wörterbuch hinzufügen',
|
||||
ignoreAll: 'Alle ignorieren',
|
||||
},
|
||||
thesaurus: {
|
||||
title: 'Thesaurus',
|
||||
menuItem: 'Thesaurus…',
|
||||
lookUp: 'Nachschlagen',
|
||||
word: 'Wort',
|
||||
loading: 'Wird geladen…',
|
||||
replaceHint: 'Ein Wort anklicken, um es im Dokument zu ersetzen.',
|
||||
noSynonyms: 'Keine Synonyme gefunden',
|
||||
noLanguage: 'Für diese Sprache gibt es keinen Thesaurus',
|
||||
},
|
||||
contextMenu: {
|
||||
cut: 'Ausschneiden',
|
||||
copy: 'Kopieren',
|
||||
|
||||
@@ -488,6 +488,16 @@ const en = {
|
||||
addToDictionary: 'Add to Dictionary',
|
||||
ignoreAll: 'Ignore All',
|
||||
},
|
||||
thesaurus: {
|
||||
title: 'Thesaurus',
|
||||
menuItem: 'Thesaurus…',
|
||||
lookUp: 'Look up',
|
||||
word: 'Word',
|
||||
loading: 'Loading…',
|
||||
replaceHint: 'Click a word to replace the one in the document.',
|
||||
noSynonyms: 'No synonyms found',
|
||||
noLanguage: 'No thesaurus for this language',
|
||||
},
|
||||
contextMenu: {
|
||||
cut: 'Cut',
|
||||
copy: 'Copy',
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { NO_LANGUAGE, type DocumentLanguage } from '../storage/documentLanguage';
|
||||
|
||||
// Vendored assets: public/thesaurus/<code>/<code>.txt, one synonym group per
|
||||
// line, ';'-separated (scripts/make-thesaurus.mjs, from LibreOffice's MyThes data).
|
||||
const cache = new Map<string, Promise<string | null>>();
|
||||
|
||||
// Asks App.svelte for the dialog, as the other menu-opened dialogs do.
|
||||
export const OPEN_THESAURUS_EVENT = 'odf-open-thesaurus';
|
||||
|
||||
// More than a dialog can show without becoming a word list of its own.
|
||||
const MAX_GROUPS = 12;
|
||||
|
||||
function fetchThesaurus(code: string): Promise<string | null> {
|
||||
const url = `${import.meta.env.BASE_URL}thesaurus/${code}/${code}.txt`;
|
||||
return fetch(url)
|
||||
.then((res) => (res.ok ? res.text() : Promise.reject(new Error(`${res.status} for ${url}`))))
|
||||
.catch((err) => {
|
||||
cache.delete(code); // allow a retry after a transient failure
|
||||
console.error(`[thesaurus] failed to load "${code}":`, err);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
// Loads on first use (a few MB) and stays for the session, like the dictionary.
|
||||
export function loadThesaurus(code: DocumentLanguage): Promise<string | null> {
|
||||
if (!code || code === NO_LANGUAGE) return Promise.resolve(null);
|
||||
let pending = cache.get(code);
|
||||
if (!pending) cache.set(code, (pending = fetchThesaurus(code)));
|
||||
return pending;
|
||||
}
|
||||
|
||||
const escapeRe = (word: string) => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
// The groups `word` appears in, itself removed. Scanned, not indexed: a lookup is
|
||||
// a menu click (~4ms over 3MB), where a word→group index would cost ~100MB.
|
||||
// A group leads with its main form, so the earlier the word sits in one, the more
|
||||
// that group is about it — which is the order LibreOffice lists the senses in.
|
||||
export async function synonyms(code: DocumentLanguage, word: string): Promise<string[][]> {
|
||||
const text = await loadThesaurus(code);
|
||||
const term = word.trim();
|
||||
if (!text || !term) return [];
|
||||
const lower = term.toLowerCase();
|
||||
const re = new RegExp(`(^|;)${escapeRe(term)}(;|$)`, 'gim');
|
||||
const seen = new Set<string>();
|
||||
const found: { at: number; others: string[] }[] = [];
|
||||
for (const m of text.matchAll(re)) {
|
||||
const start = text.lastIndexOf('\n', m.index) + 1;
|
||||
const end = text.indexOf('\n', m.index);
|
||||
const line = text.slice(start, end < 0 ? undefined : end);
|
||||
if (seen.has(line)) continue;
|
||||
seen.add(line);
|
||||
const members = line.split(';');
|
||||
const others = members.filter((w) => w.toLowerCase() !== lower);
|
||||
if (others.length) found.push({ at: members.findIndex((w) => w.toLowerCase() === lower), others });
|
||||
}
|
||||
return found.sort((a, b) => a.at - b.at).slice(0, MAX_GROUPS).map((g) => g.others);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// The thesaurus lookup: a word is matched as a whole group member, never as a
|
||||
// substring of one, and the groups come back without the word itself.
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { synonyms, loadThesaurus } from '../../src/lib/spell/thesaurus';
|
||||
import { NO_LANGUAGE } from '../../src/lib/storage/documentLanguage';
|
||||
|
||||
const DATA = [
|
||||
'Ausgedingehaus;Stöckli;Haus',
|
||||
'Haus;Gebäude;Bauwerk',
|
||||
'Haus;Zuhause;Heim',
|
||||
'Hausboot;Boot',
|
||||
'schnell;rasch;flink',
|
||||
'C++;Programmiersprache',
|
||||
].join('\n');
|
||||
|
||||
// One language per test file run: the module caches a loaded thesaurus for the session.
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response(DATA, { status: 200 })));
|
||||
});
|
||||
|
||||
describe('synonyms', () => {
|
||||
it('returns every group the word is in, without the word', async () => {
|
||||
// The groups leading with it come first — its own senses before a compound's.
|
||||
expect(await synonyms('de', 'Haus')).toEqual([
|
||||
['Gebäude', 'Bauwerk'],
|
||||
['Zuhause', 'Heim'],
|
||||
['Ausgedingehaus', 'Stöckli'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('matches whole members only, and ignores case', async () => {
|
||||
expect(await synonyms('de', 'haus')).toHaveLength(3); // the groups holding Haus, not Hausboot's
|
||||
expect(await synonyms('de', 'boot')).toEqual([['Hausboot']]);
|
||||
});
|
||||
|
||||
it('takes a word with regex characters in it', async () => {
|
||||
expect(await synonyms('de', 'C++')).toEqual([['Programmiersprache']]);
|
||||
});
|
||||
|
||||
it('has nothing for an unknown word or no language', async () => {
|
||||
expect(await synonyms('de', 'Fahrrad')).toEqual([]);
|
||||
expect(await synonyms(NO_LANGUAGE, 'Haus')).toEqual([]);
|
||||
});
|
||||
|
||||
it('fetches the file once per language', async () => {
|
||||
await synonyms('en', 'Haus'); // 'en' is untouched above, so this is its first load
|
||||
await loadThesaurus('en');
|
||||
expect(vi.mocked(fetch)).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user