@yaks/copy 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,110 @@
1
- # Temporary Holding Version
1
+ # @yaks/copy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An app's copy: the words its pages show, kept apart from the markup that shows
4
+ them. The copy lives in `copy.json` at the app's root as keyed snippets, and an
5
+ element names the snippet it shows by key. This package is pure logic and data:
6
+ it takes and returns strings and values, and reads no file and touches no page.
7
+
8
+ ## The file
9
+
10
+ `copy.json` is a JSON object of snippets. A nested object reads as dotted keys,
11
+ so `hero.title` is `{"hero": {"title": "…"}}`, and a key written with its dots,
12
+ `{"hero.title": "…"}`, reads the same. A snippet's value is plain text.
13
+
14
+ ```json
15
+ {
16
+ "cost": {
17
+ "note": "A space is your address, like %{yours}, with its apps, their data and the people you invite.",
18
+ "limits": "Tax is included. Going over a limit never deletes your apps or data. %{plans}.",
19
+ "plans": "Compare plans and limits"
20
+ }
21
+ }
22
+ ```
23
+
24
+ The file is written one snippet per line, so a text merge of two edits works by
25
+ key: two people changing different snippets change different lines.
26
+
27
+ ## Lists
28
+
29
+ A list is a JSON array of snippets, so its items can be added, removed and
30
+ moved: `"always": {"items": ["Members", "Visitors"]}`. The element holding the
31
+ items names it with `data-copy-list`, and each of its child elements is an item,
32
+ plain text with no slots. A page draws an item for each snippet, each as its
33
+ first item is written.
34
+
35
+ ```html
36
+ <ul data-copy-list="always.items">
37
+ <li class="Plan_Item"></li>
38
+ </ul>
39
+ ```
40
+
41
+ ## Slots
42
+
43
+ A link, a bold word or a part inside a sentence is a named slot in the value,
44
+ `%{name}`, as Rails interpolates. The element's own child marked
45
+ `data-copy-slot="name"` fills it, and that child can carry a snippet of its own:
46
+ above, `%{plans}` is filled by the link, whose text is `cost.plans`. `%%{name}`
47
+ is the text `%{name}`, and a lone `%` is just a percent sign.
48
+
49
+ ## An element's names
50
+
51
+ | attribute | names |
52
+ | -------------------------- | ------------------------------------------------------- |
53
+ | `data-copy="<key>"` | the snippet that is the element's text |
54
+ | `data-copy-<attr>="<key>"` | the snippet that is its attribute `<attr>`'s value |
55
+ | `data-copy-slot="<name>"` | the slot of its parent's snippet that the element fills |
56
+ | `data-copy-list="<key>"` | the list whose items are the element's children |
57
+
58
+ `<attr>` is any attribute whose value is words: `alt`, `placeholder`, `title`,
59
+ `aria-label`, a meta tag's `content`. `slot` and `list` are the names taken.
60
+
61
+ ```html
62
+ <p data-copy="cost.limits">
63
+ <a href="/pricing" data-copy-slot="plans" data-copy="cost.plans"></a>
64
+ </p>
65
+ <input data-copy-placeholder="search.hint">
66
+ ```
67
+
68
+ ## Calls
69
+
70
+ | call | what it does |
71
+ | ---------------------------- | ------------------------------------------------------------------ |
72
+ | `parse(text, file?)` | a file's text as its value; blank text is an empty file |
73
+ | `read(copy, key)` | the snippet at a key, or `undefined` |
74
+ | `items(copy, key)` | the list at a key, its snippets in order, or `undefined` |
75
+ | `valueAt(copy, key)` | what a key holds: a snippet or a list |
76
+ | `same(a, b)` | whether two values are the same snippet or the same list |
77
+ | `keys(copy)` | every snippet's and list's key, in the file's order |
78
+ | `fill(value, values)` | the snippet's parts in order: text, and each slot's given value |
79
+ | `slots(value)` | the slots a snippet names |
80
+ | `join(parts)` | a snippet from `fill`'s parts: text escaped, each slot by name |
81
+ | `set(text, changes)` | the file's text with keys set, a list whole, order and indent kept |
82
+ | `format(copy, indent?)` | a value as file text, one snippet per line |
83
+ | `merge(ours, theirs, base?)` | the file with each key `theirs` changed from `base` laid over it |
84
+ | `marks(attributes)` | the keys and slot an element's attributes name |
85
+ | `names` | the attribute names themselves |
86
+
87
+ ```ts
88
+ import { fill, parse, read, set } from '@yaks/copy'
89
+
90
+ let text = '{\n "cost": {\n "plans": "Compare plans and limits"\n }\n}\n'
91
+ let copy = parse(text)
92
+ read(copy, 'cost.plans') // 'Compare plans and limits'
93
+ fill('Tax is included. %{plans}.', { plans: 'LINK' }) // ['Tax is included. ', 'LINK', '.']
94
+ set(text, { 'cost.free': 'Your first space is free.' })
95
+ // cost.free joins the cost object, after plans
96
+ ```
97
+
98
+ `fill` takes any value for a slot, so a page passes its own child (a DOM node, a
99
+ JSX element) and places the parts it gets back. A slot given no value stays as
100
+ its `%{name}`, so a missing part shows by name rather than as a gap.
101
+
102
+ `merge` is how `yak admin push` keeps an edit made on an app's page: `ours` is
103
+ the checkout's file, `theirs` the live one, and `base` the newest version both
104
+ have held. A key `theirs` left as `base` had it keeps `ours`'s text; any other
105
+ key takes `theirs`'s. With no base, every key `theirs` holds is its own.
106
+
107
+ `set` keeps a key where it is. A new key goes at the end of the deepest object a
108
+ leading part of it names (`cost.free` into `cost`), or at the end of the file
109
+ when none does. A key that is a whole number (`"1"`) is read first in its
110
+ object, as JSON objects order them in JavaScript.
@@ -0,0 +1,50 @@
1
+ import { type Copy, type Value } from "./mod.js";
2
+ export declare let COPY: string;
3
+ export declare let LOCALES: string;
4
+ export declare let LANGUAGE: string;
5
+ export declare let LANGUAGES: string;
6
+ /** A language tag in the form used by HTML and by the locale file names. */ export declare let language: (tag: unknown) => string | undefined;
7
+ export declare let localeFile: (lang: string) => string;
8
+ export declare let copyLanguage: (path: string) => string | undefined;
9
+ export declare let isCopyFile: (path: string) => boolean;
10
+ export type Snippets = Record<string, Value>;
11
+ export type Origin = {
12
+ source: Value;
13
+ human?: boolean;
14
+ };
15
+ export type Locale = {
16
+ label?: string;
17
+ sources?: Record<string, Origin>;
18
+ preferences?: string[];
19
+ };
20
+ export type Locales = {
21
+ default: string;
22
+ languages: Record<string, Locale>;
23
+ suggestions?: boolean;
24
+ };
25
+ /** The app's language settings and the sources used by its translations. */ export declare let locales: (text: string) => Locales | null;
26
+ export declare let languagesOf: (config: Locales) => string[];
27
+ export type LanguageRequest = {
28
+ explicit?: string | null;
29
+ remembered?: string | null;
30
+ browser?: string;
31
+ };
32
+ /** Choose the address language, remembered choice, browser language, or default. */ export declare let chooseLanguage: (available: readonly [string, ...string[]] | readonly string[], _dts_1: never) => string;
33
+ /** An indexed language address on this page. */ export declare let languageAt: (address: string | URL, lang: string) => URL;
34
+ export declare let languageCookie: (mount: string) => string;
35
+ export declare let requestLanguage: (req: Request, mount: string) => LanguageRequest;
36
+ /** The additional variant needed when the held page uses another language. */ export declare let copyVariant: (req: Request, headers: Headers, mount: string) => string | undefined;
37
+ /** The default copy with the translated values it has, keeping the source
38
+ * where a translation is missing or has a different shape. */ export declare let localized: (source: Copy, translation: Copy) => Copy;
39
+ /** Copy slots stay in page order, and a list keeps one translation per item. */ export declare let compatible: (source: Value, translation: Value | undefined) => boolean;
40
+ export type Plan = {
41
+ current: Snippets;
42
+ pending: Snippets;
43
+ sources: Record<string, Origin>;
44
+ };
45
+ /** Keep translations of the current source, including human corrections.
46
+ * A translation with no recorded source is associated with the previous
47
+ * source when available, so an edit to that source still marks it stale. */ export declare let translationPlan: (source: Copy, translated: Copy, origins?: Record<string, Origin>, previous?: Copy) => Plan;
48
+ /** Apply a model answer only to the keys in the plan. */ export declare let translated: (plan: Plan, answer: Copy) => Omit<Plan, 'pending'>;
49
+ /** Snippets much longer than the source, for the editor's phone-width check. */ export declare let longTranslations: (source: Snippets, translation: Copy) => string[];
50
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.ts","sources":["../locales.ts"],"names":[],"mappings":"AACA,SACE,KAAK,IAAI,EAIT,KAAK,KAAK,mBAGK;AAEjB,OAAO,YAAI,aAAkB;AAC7B,OAAO,YAAI,gBAA4B;AACvC,OAAO,YAAI,iBAAiB;AAC5B,OAAO,YAAI,kBAAkC;AAE7C,0EAA0E,GAC1E,OAAO,YAAI,WAAY,KAAK,OAAO,KAAG,MAAM,GAAG,SAAS,CAOvD;AAED,OAAO,YAAI,aAAc,MAAM,MAAM,YAAwB;AAE7D,OAAO,YAAI,eAAgB,MAAM,MAAM,KAAG,MAAM,GAAG,SAAS,CAGL;AAEvD,OAAO,YAAI,aAAc,MAAM,MAAM,KAAG,OAAO,CACU;AAEzD,YAAY,WAAW,OAAO,MAAM,EAAE;AACtC,YAAY;EAAW,QAAQ;EAAO,QAAQ,OAAO;;AACrD,YAAY;EACV,QAAQ,MAAM;EACd,UAAU,OAAO,MAAM,EAAE;EACzB,cAAc,MAAM;;AAEtB,YAAY;EACV,SAAS,MAAM;EACf,WAAW,OAAO,MAAM,EAAE;EAC1B,cAAc,OAAO;;AASvB,0EAA0E,GAC1E,OAAO,YAAI,UAAW,MAAM,MAAM,KAAG,UAAU,IAAI,CA6ClD;AAED,OAAO,YAAI,cACT,QAAQ,YACP,MAAM,GAAwD;AAwBjE,YAAY;EACV,WAAW,MAAM,GAAG,IAAI;EACxB,aAAa,MAAM,GAAG,IAAI;EAC1B,UAAU,MAAM;;AAGlB,kFAAkF,GAClF,OAAO,YAAI,iBACT,qBAAqB,MAAM,KAAK,MAAM,eAAe,MAAM,IAC3D,kBACC,MAAM,CAYR;AAED,8CAA8C,GAC9C,OAAO,YAAI,aAAc,SAAS,MAAM,GAAG,KAAK,MAAM,MAAM,KAAG,IAI9D;AAED,OAAO,YAAI,iBAAkB,OAAO,MAAM,YACD;AAEzC,OAAO,YAAI,kBACT,KAAK,SACL,OAAO,MAAM,KACZ,gBAOD;AAEF,4EAA4E,GAC5E,OAAO,YAAI,cACT,KAAK,SACL,SAAS,SACT,OAAO,MAAM,KACZ,MAAM,GAAG,SAAS,CAKpB;AAED;4DAC4D,GAC5D,OAAO,YAAI,YAAa,QAAQ,MAAM,aAAa,SAAO,KAYvD;AAEH,8EAA8E,GAC9E,OAAO,YAAI,aACT,QAAQ,OACR,aAAa,QAAQ,SAAS,KAC7B,OAAO,CAOT;AAED,YAAY;EACV,SAAS;EACT,SAAS;EACT,SAAS,OAAO,MAAM,EAAE;;AAG1B;;0EAE0E,GAC1E,OAAO,YAAI,kBACT,QAAQ,MACR,YAAY,MACZ,UAAS,OAAO,MAAM,EAAE,SACxB,WAAU,SACT,KA0BF;AAED,uDAAuD,GACvD,OAAO,YAAI,aAAc,MAAM,MAAM,QAAQ,SAAO,KAAK,MAAM,WAe9D;AAED,8EAA8E,GAC9E,OAAO,YAAI,mBACT,QAAQ,UACR,aAAa,SACZ,MAAM,GAWR"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @yaks/copy — an app's copy: the words its pages show, kept in `copy.json` at
3
+ * the app's root as keyed snippets, apart from the markup that shows them.
4
+ *
5
+ * ```ts
6
+ * import { fill, parse, read, set } from '@yaks/copy'
7
+ *
8
+ * let copy = parse('{\n "hero": {\n "title": "Build, host and share web apps"\n }\n}\n')
9
+ * read(copy, 'hero.title') // 'Build, host and share web apps'
10
+ * fill('Your first space is %{price}.', { price: 'free' }) // ['Your first space is ', 'free', '.']
11
+ * set('{}', { 'hero.kicker': 'yaks.app' }) // '{\n "hero.kicker": "yaks.app"\n}\n'
12
+ * ```
13
+ *
14
+ * Pure logic and data: it takes and returns strings and values, and reads no
15
+ * file and touches no page.
16
+ *
17
+ * @module
18
+ */ /** A copy file's value: snippets and lists of them by key, and nested
19
+ * objects of more. */ export type Copy = {
20
+ [key: string]: string | string[] | Copy;
21
+ };
22
+ /** What a key holds: a snippet, or a list's snippets in order. */ export type Value = string | string[];
23
+ /** The attributes an element names its copy with. */ export declare let names: {
24
+ /** The key of the element's text. */ text: 'data-copy';
25
+ /** The slot of its parent's snippet this element fills. */ slot: 'data-copy-slot';
26
+ /** The key of the list whose items are the element's children. */ list: 'data-copy-list';
27
+ /** The attribute naming the key of the element's attribute `name`. */ attr: (name: string) => string;
28
+ };
29
+ /** What an element's attributes say about its copy. */ export type Marks = {
30
+ /** The key of its text. */ text?: string;
31
+ /** The slot it fills in its parent's snippet. */ slot?: string;
32
+ /** The key of the list its children are the items of. */ list?: string;
33
+ /** The key of each attribute's value, by attribute. */ attrs: Record<string, string>;
34
+ };
35
+ type Attributes = Iterable<{
36
+ name: string;
37
+ value: string;
38
+ }> | Record<string, string>;
39
+ /**
40
+ * The copy an element's attributes name, from a DOM element's `attributes` or
41
+ * a plain object of them.
42
+ *
43
+ * ```ts
44
+ * marks({ 'data-copy': 'cost.plans', 'data-copy-slot': 'plans', href: '/pricing' })
45
+ * // { text: 'cost.plans', slot: 'plans', attrs: {} }
46
+ * ```
47
+ */ export declare let marks: (attributes: Attributes) => Marks;
48
+ /**
49
+ * A copy file's text as its value; blank text is an empty file. `file` is the
50
+ * name an error uses.
51
+ */ export declare let parse: (text: string, file?: string) => Copy;
52
+ /** What `key`, a dotted path through nested objects, holds: a snippet or a
53
+ * list. */ export declare let valueAt: (copy: Copy, key: string) => Value | undefined;
54
+ /** The snippet at `key`; a list there is not one. */ export declare let read: (copy: Copy, key: string) => string | undefined;
55
+ /**
56
+ * The list at `key`: its items' snippets, in order. A list is a JSON array
57
+ * of snippets, so its items can be added, removed and moved.
58
+ *
59
+ * ```ts
60
+ * items({ always: { items: ['Members', 'Visitors'] } }, 'always.items')
61
+ * // ['Members', 'Visitors']
62
+ * ```
63
+ */ export declare let items: (copy: Copy, key: string) => string[] | undefined;
64
+ /** Whether two values are the same snippet, or the same list. */ export declare let same: (a: Value | undefined, b: Value | undefined) => boolean;
65
+ /** Every snippet's and list's key, in the file's order. */ export declare let keys: (copy: Copy) => string[];
66
+ /**
67
+ * A snippet's text with its slots filled: the parts in order, text between
68
+ * the values given. A slot given no value stays as its `%{name}`, so a missing
69
+ * part shows by name rather than as a gap.
70
+ *
71
+ * ```ts
72
+ * fill('Tax is included. %{plans}.', { plans: { a: '/pricing' } })
73
+ * // ['Tax is included. ', { a: '/pricing' }, '.']
74
+ * ```
75
+ */ export declare let fill: <T>(value: string, values?: Record<string, T>) => Array<string | T>;
76
+ /**
77
+ * A snippet from its parts in order, as `fill` gives them: text, which reads
78
+ * as itself (a `%{name}` in it is escaped), and each slot by its name. A page
79
+ * edited where it stands reads its snippet back this way.
80
+ *
81
+ * ```ts
82
+ * import { assertEquals } from '@std/assert'
83
+ * import { fill, join } from '@yaks/copy'
84
+ *
85
+ * let value = 'Tax is included. %{plans}.'
86
+ * assertEquals(join(['Tax is included. ', { slot: 'plans' }, '.']), value)
87
+ * assertEquals(fill(join(['100%{x}'])), ['100%{x}'])
88
+ * ```
89
+ */ export declare let join: (parts: Array<string | {
90
+ slot: string;
91
+ }>) => string;
92
+ /** The slots a snippet names, in order. */ export declare let slots: (value: string) => string[];
93
+ /**
94
+ * A copy file's text, one snippet per line, so a text merge of two edits works
95
+ * by key. `indent` is what a level is indented by.
96
+ */ export declare let format: (copy: Copy, indent?: string) => string;
97
+ /**
98
+ * A copy file's text with `changes` set by key, a snippet or a whole list. A
99
+ * key already there keeps its place; a new one is added at the end of the
100
+ * object its key leads into. The file's indentation is kept, and each snippet
101
+ * and list item stays on its own line.
102
+ */ export declare let set: (text: string, changes: Record<string, Value>, file?: string) => string;
103
+ /** A copy with changed values placed under their existing keys. */ export declare let withCopy: (copy: Copy, changes: Record<string, Value>) => Copy;
104
+ /**
105
+ * A copy file's text with each snippet another copy of it changed laid over
106
+ * it by key: `ours` is the file, `theirs` the other copy (an app's live
107
+ * file, edited on its page), and `base` what both last agreed on. A key
108
+ * `theirs` holds as `base` did is left as `ours` has it, so an edit or removal
109
+ * made only in `ours` stands; any other key `theirs` holds is set to its
110
+ * text, so an edit made in `theirs` wins, even where `ours` changed it too.
111
+ * With no base, every key `theirs` holds is its own.
112
+ *
113
+ * ```ts
114
+ * let base = '{\n "a": "one",\n "b": "two"\n}\n'
115
+ * let ours = '{\n "a": "uno",\n "b": "two",\n "c": "three"\n}\n'
116
+ * merge(ours, '{\n "a": "one",\n "b": "dos"\n}\n', base)
117
+ * // '{\n "a": "uno",\n "b": "dos",\n "c": "three"\n}\n'
118
+ * ```
119
+ */ export declare let merge: (ours: string, theirs: string, base?: string, file?: string) => string;
120
+ export * from "./locales.js";
121
+ export * from "./translation.js";
122
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GAED;oBACoB,GACpB,YAAY;GAAU,KAAK,MAAM,GAAG,MAAM,GAAG,MAAM,KAAK;;AAExD,gEAAgE,GAChE,YAAY,QAAQ,MAAM,GAAG,MAAM;AAEnC,mDAAmD,GACnD,OAAO,YAAI;EACT,mCAAmC,GACnC,MAAM;EACN,yDAAyD,GACzD,MAAM;EACN,gEAAgE,GAChE,MAAM;EACN,oEAAoE,GACpE,OAAO,MAAM,MAAM,KAAK,MAAM;EAM/B;AAED,qDAAqD,GACrD,YAAY;EACV,yBAAyB,GACzB,OAAO,MAAM;EACb,+CAA+C,GAC/C,OAAO,MAAM;EACb,uDAAuD,GACvD,OAAO,MAAM;EACb,qDAAqD,GACrD,OAAO,OAAO,MAAM,EAAE,MAAM;;KAGzB,aACD;EAAW,MAAM,MAAM;EAAE,OAAO,MAAM;KACtC,OAAO,MAAM,EAAE,MAAM;AAEzB;;;;;;;;CAQC,GACD,OAAO,YAAI,QAAS,YAAY,eAAa,MAmB5C;AA0BD;;;CAGC,GACD,OAAO,YAAI,QAAS,MAAM,MAAM,EAAE,kBAAqB,KAStD;AAyBD;SACS,GACT,OAAO,YAAI,UAAW,MAAM,MAAM,KAAK,MAAM,KAAG,QAAQ,SAAS,CAGhE;AAED,mDAAmD,GACnD,OAAO,YAAI,OAAQ,MAAM,MAAM,KAAK,MAAM,KAAG,MAAM,GAAG,SAAS,CAG9D;AAED;;;;;;;;CAQC,GACD,OAAO,YAAI,QAAS,MAAM,MAAM,KAAK,MAAM,KAAG,MAAM,KAAK,SAAS,CAGjE;AAED,+DAA+D,GAC/D,OAAO,YAAI,OAAQ,GAAG,QAAQ,SAAS,EAAE,GAAG,QAAQ,SAAS,KAAG,OAAO,CAC/B;AAExC,yDAAyD,GACzD,OAAO,YAAI,OAAQ,MAAM,SAAO,MAAM,GAGnC;AAKH;;;;;;;;;CASC,GACD,OAAO,YAAI,OAAQ,GACjB,OAAO,MAAM,EACb,SAAQ,OAAO,MAAM,EAAE,OACtB,MAAM,MAAM,GAAG,GAkBjB;AAED;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,OAAQ,OAAO,MAAM,MAAM;EAAK,MAAM,MAAM;OAAM,MAAM,CAKvD;AAEZ,yCAAyC,GACzC,OAAO,YAAI,QAAS,OAAO,MAAM,KAAG,MAAM,GAGvC;AAEH;;;CAGC,GACD,OAAO,YAAI,SAAU,MAAM,MAAM,oBAAgB,MAAM,CACZ;AAe3C;;;;;CAKC,GACD,OAAO,YAAI,MACT,MAAM,MAAM,EACZ,SAAS,OAAO,MAAM,EAAE,QACxB,kBACC,MAAM,CACmE;AAE5E,iEAAiE,GACjE,OAAO,YAAI,WAAY,MAAM,MAAM,SAAS,OAAO,MAAM,EAAE,WAAS,KAC3B;AAezC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,QACT,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,eACA,kBACC,MAAM,CAWR;AAED,6BAA4B;AAC5B,iCAAgC"}
@@ -0,0 +1,37 @@
1
+ import { type Copy, type Locales, type Snippets } from "./mod.js";
2
+ export type Translation = {
3
+ from: string;
4
+ to: string;
5
+ source: Snippets;
6
+ previous: Snippets;
7
+ preferences: string[];
8
+ feedback?: {
9
+ key: string;
10
+ note: string;
11
+ };
12
+ };
13
+ export type Translate = (job: Translation) => Promise<{
14
+ copy: Copy;
15
+ preference?: string;
16
+ }>;
17
+ export type Feedback = {
18
+ lang: string;
19
+ key: string;
20
+ note: string;
21
+ };
22
+ export type CopyFiles = Record<string, string>;
23
+ /** Locales registered by the app, including language files added by hand. */ export declare let copyLocales: (files: readonly string[], text: string, defaultLanguage?: string) => Locales;
24
+ /** Plan the work from authored files and the release they replace. Every
25
+ * returned file belongs in the same release. */ export declare let translateFiles: (before: CopyFiles, files: CopyFiles, translate: Translate, feedback?: Feedback) => Promise<CopyFiles>;
26
+ /** The one request for a language. App copy and feedback are quoted data. */ type TranslationRequest = {
27
+ messages: {
28
+ role: 'system' | 'user';
29
+ content: string;
30
+ }[];
31
+ response_format: {
32
+ type: 'json_object';
33
+ };
34
+ max_tokens: number;
35
+ };
36
+ /** Read a model reply and retry overly long copy once with the same source. */ export declare let translating: (run: (input: TranslationRequest) => Promise<string>) => Translate;
37
+ //# sourceMappingURL=translation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation.d.ts","sources":["../translation.ts"],"names":[],"mappings":"AACA,SAGE,KAAK,IAAI,EAOT,KAAK,OAAO,EAOZ,KAAK,QAAQ,mBAKE;AAEjB,YAAY;EACV,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,QAAQ;EACR,UAAU;EACV,aAAa,MAAM;EACnB;IAAa,KAAK,MAAM;IAAE,MAAM,MAAM;;;AAGxC,YAAY,aAAa,KAAK,gBAAgB;EAC5C,MAAM;EACN,aAAa,MAAM;;AAGrB,YAAY;EAAa,MAAM,MAAM;EAAE,KAAK,MAAM;EAAE,MAAM,MAAM;;AAChE,YAAY,YAAY,OAAO,MAAM,EAAE,MAAM;AAQ7C,2EAA2E,GAC3E,OAAO,YAAI,cACT,gBAAgB,MAAM,IACtB,MAAM,MAAM,EACZ,6BACC,QAWF;AAED;8CAC8C,GAC9C,OAAO,YAAI,iBACT,QAAQ,WACR,OAAO,WACP,WAAW,WACX,WAAW,aACV,QAAQ,WAsIV;AAED,2EAA2E,QACtE;EACH;IAAY,MAAM,WAAW;IAAQ,SAAS,MAAM;;EACpD;IAAmB,MAAM;;EACzB,YAAY,MAAM;;AAyBpB,6EAA6E,GAC7E,OAAO,YAAI,cACT,MAAM,OAAO,uBAAuB,QAAQ,MAAM,MACjD,UAmCF"}
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/copy","version":"0.2.36","license":"Apache-2.0","description":"An app's copy as a file of keyed snippets: read by key, filled by slot, set by key, one snippet per line.","exports":"./mod.ts","imports":{"@yaks/copy":"./mod.ts"}}