@ds-labs/prose-angular 0.0.0-stage → 0.1.1

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 [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,92 @@
1
- # Temporary Holding Version
1
+ # @ds-labs/prose-angular
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 Angular component that renders an [ODRL](https://www.w3.org/TR/odrl-model/)
4
+ policy, written as JSON-LD, as plain-language prose. It wraps the
5
+ `<OdrlProse>` Yew component of
6
+ [ds-prose-rs](https://github.com/ds-labs-org/ds-prose-rs), compiled to
7
+ WebAssembly (shipped in the `@ds-labs/prose-wasm` dependency). Read-only: no
8
+ edit mode.
9
+
10
+ ```
11
+ <ds-odrl-prose [json]> -> ProseHandle (@ds-labs/prose-wasm) -> <OdrlProse> (prose-yew)
12
+ ```
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm i @ds-labs/prose-angular
18
+ ```
19
+
20
+ Angular 19 or newer. Client-side only (see Notes).
21
+
22
+ ## Set up
23
+
24
+ The wasm file is a static asset your build must serve. Add one entry to the
25
+ `assets` of your application target in `angular.json`:
26
+
27
+ ```json
28
+ { "glob": "prose_wasm_bg.wasm", "input": "node_modules/@ds-labs/prose-wasm", "output": "/" }
29
+ ```
30
+
31
+ That is the whole setup. The wasm is fetched once, on first render.
32
+
33
+ ## Use
34
+
35
+ ```ts
36
+ import { Component } from '@angular/core';
37
+ import { OdrlProseComponent } from '@ds-labs/prose-angular';
38
+
39
+ @Component({
40
+ selector: 'app-policy',
41
+ imports: [OdrlProseComponent],
42
+ template: `<ds-odrl-prose [json]="policy" articleClass="my-prose" (loadFailed)="onFailed($event)" />`,
43
+ })
44
+ export class PolicyComponent {
45
+ policy = '{ "@type": "Set", "permission": [{ "action": "use", "target": "urn:asset:1" }] }';
46
+ onFailed(error: unknown) { /* report it */ }
47
+ }
48
+ ```
49
+
50
+ | | | |
51
+ |---|---|---|
52
+ | `json` | input, required | the ODRL policy as JSON-LD text |
53
+ | `articleClass` | input | extra class(es) for the rendered `<article class="ds-prose">` |
54
+ | `loadFailed` | output | emits the error when the wasm cannot be loaded |
55
+ | `PROSE_WASM_URL` | injection token | where the browser fetches the wasm from, relative to the page's base href (default `prose_wasm_bg.wasm`) |
56
+
57
+ Invalid JSON shows an error message in place of the prose; it recovers on the
58
+ next valid input. Style the result through the `prose-*` classes
59
+ (`.ds-prose`, `.prose-policy`, `.prose-rule`, `.prose-permission`,
60
+ `.prose-prohibition`, `.prose-obligation`, `.prose-error`, ...) or the
61
+ `articleClass` input.
62
+
63
+ If the wasm cannot be loaded (a wrong `PROSE_WASM_URL`, a 404, a network
64
+ failure) the element shows an error (`<p class="prose-error" role="alert">`),
65
+ logs it with `console.error`, and emits it from `loadFailed`. A failed load is
66
+ not remembered: the next change of an input tries again.
67
+
68
+ ## Notes
69
+
70
+ - The component owns its host element's children (Yew keeps its own virtual
71
+ DOM there). Use it as a leaf.
72
+ - It renders client-side only. If your app uses SSR, guard it with
73
+ `isPlatformBrowser` or `@defer`.
74
+ - The package version is independent of the Rust crates. The ds-prose-rs
75
+ version of the wasm is recorded in `@ds-labs/prose-wasm`'s `package.json`
76
+ under `dsProse.prose-yew`.
77
+
78
+ ## Replacing a vendored copy
79
+
80
+ If you copied this project into your repository and built it yourself, you can
81
+ delete the copy, the vendoring script, the `tsconfig` path to it and the lint
82
+ and formatter ignores for it, install the package above, and keep only the one
83
+ `angular.json` asset line.
84
+
85
+ Licence: Apache-2.0.
86
+
87
+ ## Developing this package
88
+
89
+ ```bash
90
+ scripts/build-npm-packages.sh # from the repository root: both packages, packed
91
+ cd prose-angular && npm test && npm run typecheck
92
+ ```
@@ -0,0 +1,125 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, input, output, inject, ElementRef, NgZone, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import init, { ProseHandle } from '@ds-labs/prose-wasm';
4
+
5
+ /**
6
+ * A loader that runs `init` at most once at a time and shares the result, so
7
+ * every component on a page waits on one fetch. A failed load is forgotten:
8
+ * the callers waiting on it all see the failure, and the next call tries again
9
+ * (the file may have been missing only for a moment).
10
+ */
11
+ function createWasmLoader(init) {
12
+ let ready;
13
+ return (url) => {
14
+ if (!ready) {
15
+ const attempt = init(url).catch((error) => {
16
+ if (ready === attempt)
17
+ ready = undefined;
18
+ throw error;
19
+ });
20
+ ready = attempt;
21
+ }
22
+ return ready;
23
+ };
24
+ }
25
+
26
+ /**
27
+ * Where the browser fetches `prose_wasm_bg.wasm` from, relative to the page's
28
+ * base href. The build does not emit the file for you: copy it into your
29
+ * assets (see README) or provide this token.
30
+ */
31
+ const PROSE_WASM_URL = new InjectionToken('PROSE_WASM_URL', {
32
+ providedIn: 'root',
33
+ factory: () => 'prose_wasm_bg.wasm',
34
+ });
35
+ // The wasm module is fetched and instantiated once per page. A failed load is
36
+ // not remembered, so the next input change retries it.
37
+ const loadWasm = createWasmLoader((url) => init({ module_or_path: new URL(url, document.baseURI) }));
38
+ /**
39
+ * `<ds-odrl-prose [json]="policy" />` renders ODRL JSON-LD as plain-language
40
+ * prose using the Yew component from `prose-yew`.
41
+ *
42
+ * The component owns the host element's children (Yew keeps its own virtual
43
+ * DOM there); style it through the `prose-*` classes or the `class` input.
44
+ *
45
+ * If the wasm cannot be loaded, the host shows an error (`role="alert"`,
46
+ * class `prose-error`), `loadFailed` emits the error, and the next change of
47
+ * an input tries again.
48
+ */
49
+ class OdrlProseComponent {
50
+ /** The ODRL policy as JSON-LD text. */
51
+ json = input.required();
52
+ /** Extra class(es) for the rendered `<article class="ds-prose">`. */
53
+ articleClass = input();
54
+ /** Emits when the wasm module could not be loaded. */
55
+ loadFailed = output();
56
+ host = inject(ElementRef).nativeElement;
57
+ zone = inject(NgZone);
58
+ wasmUrl = inject(PROSE_WASM_URL);
59
+ handle;
60
+ destroyed = false;
61
+ ngOnChanges() {
62
+ void this.sync();
63
+ }
64
+ ngOnDestroy() {
65
+ this.destroyed = true;
66
+ this.handle?.destroy();
67
+ this.handle?.free();
68
+ this.handle = undefined;
69
+ }
70
+ async sync() {
71
+ try {
72
+ await loadWasm(this.wasmUrl);
73
+ }
74
+ catch (error) {
75
+ if (!this.destroyed)
76
+ this.showLoadError(error);
77
+ return;
78
+ }
79
+ if (this.destroyed)
80
+ return;
81
+ // Only the error message can be in the host before the first mount.
82
+ if (!this.handle)
83
+ this.host.replaceChildren();
84
+ const json = this.json();
85
+ const cls = this.articleClass() ?? null;
86
+ // Yew schedules its own work; keep it out of Angular's change detection.
87
+ this.zone.runOutsideAngular(() => {
88
+ if (this.handle)
89
+ this.handle.update(json, cls);
90
+ else
91
+ this.handle = new ProseHandle(this.host, json, cls);
92
+ });
93
+ }
94
+ showLoadError(error) {
95
+ console.error('ds-odrl-prose: could not load the wasm module', error);
96
+ // A mounted Yew tree owns the host's children: leave it alone.
97
+ if (!this.handle) {
98
+ const message = document.createElement('p');
99
+ message.className = 'prose-error';
100
+ message.setAttribute('role', 'alert');
101
+ message.textContent =
102
+ `The ODRL prose renderer could not be loaded (${this.wasmUrl}). Check that the file is served; it is tried again when the input changes.`;
103
+ this.host.replaceChildren(message);
104
+ }
105
+ this.loadFailed.emit(error);
106
+ }
107
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: OdrlProseComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
108
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.25", type: OdrlProseComponent, isStandalone: true, selector: "ds-odrl-prose", inputs: { json: { classPropertyName: "json", publicName: "json", isSignal: true, isRequired: true, transformFunction: null }, articleClass: { classPropertyName: "articleClass", publicName: "articleClass", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { loadFailed: "loadFailed" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
109
+ }
110
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: OdrlProseComponent, decorators: [{
111
+ type: Component,
112
+ args: [{
113
+ selector: 'ds-odrl-prose',
114
+ standalone: true,
115
+ template: '',
116
+ changeDetection: ChangeDetectionStrategy.OnPush,
117
+ }]
118
+ }] });
119
+
120
+ /**
121
+ * Generated bundle index. Do not edit.
122
+ */
123
+
124
+ export { OdrlProseComponent, PROSE_WASM_URL };
125
+ //# sourceMappingURL=ds-labs-prose-angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ds-labs-prose-angular.mjs","sources":["../../../prose-angular/src/wasm-loader.ts","../../../prose-angular/src/odrl-prose.component.ts","../../../prose-angular/src/ds-labs-prose-angular.ts"],"sourcesContent":["/** Loads and instantiates the wasm module. Injected so it can be tested. */\nexport type WasmInit = (url: string) => Promise<unknown>;\n\n/**\n * A loader that runs `init` at most once at a time and shares the result, so\n * every component on a page waits on one fetch. A failed load is forgotten:\n * the callers waiting on it all see the failure, and the next call tries again\n * (the file may have been missing only for a moment).\n */\nexport function createWasmLoader(init: WasmInit): (url: string) => Promise<unknown> {\n let ready: Promise<unknown> | undefined;\n return (url) => {\n if (!ready) {\n const attempt: Promise<unknown> = init(url).catch((error: unknown) => {\n if (ready === attempt) ready = undefined;\n throw error;\n });\n ready = attempt;\n }\n return ready;\n };\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n NgZone,\n OnChanges,\n OnDestroy,\n InjectionToken,\n inject,\n input,\n output,\n} from '@angular/core';\nimport init, { ProseHandle } from '@ds-labs/prose-wasm';\nimport { createWasmLoader } from './wasm-loader';\n\n/**\n * Where the browser fetches `prose_wasm_bg.wasm` from, relative to the page's\n * base href. The build does not emit the file for you: copy it into your\n * assets (see README) or provide this token.\n */\nexport const PROSE_WASM_URL = new InjectionToken<string>('PROSE_WASM_URL', {\n providedIn: 'root',\n factory: () => 'prose_wasm_bg.wasm',\n});\n\n// The wasm module is fetched and instantiated once per page. A failed load is\n// not remembered, so the next input change retries it.\nconst loadWasm = createWasmLoader((url) => init({ module_or_path: new URL(url, document.baseURI) }));\n\n/**\n * `<ds-odrl-prose [json]=\"policy\" />` renders ODRL JSON-LD as plain-language\n * prose using the Yew component from `prose-yew`.\n *\n * The component owns the host element's children (Yew keeps its own virtual\n * DOM there); style it through the `prose-*` classes or the `class` input.\n *\n * If the wasm cannot be loaded, the host shows an error (`role=\"alert\"`,\n * class `prose-error`), `loadFailed` emits the error, and the next change of\n * an input tries again.\n */\n@Component({\n selector: 'ds-odrl-prose',\n standalone: true,\n template: '',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class OdrlProseComponent implements OnChanges, OnDestroy {\n /** The ODRL policy as JSON-LD text. */\n readonly json = input.required<string>();\n /** Extra class(es) for the rendered `<article class=\"ds-prose\">`. */\n readonly articleClass = input<string>();\n /** Emits when the wasm module could not be loaded. */\n readonly loadFailed = output<unknown>();\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly zone = inject(NgZone);\n private readonly wasmUrl = inject(PROSE_WASM_URL);\n private handle?: ProseHandle;\n private destroyed = false;\n\n ngOnChanges(): void {\n void this.sync();\n }\n\n ngOnDestroy(): void {\n this.destroyed = true;\n this.handle?.destroy();\n this.handle?.free();\n this.handle = undefined;\n }\n\n private async sync(): Promise<void> {\n try {\n await loadWasm(this.wasmUrl);\n } catch (error) {\n if (!this.destroyed) this.showLoadError(error);\n return;\n }\n if (this.destroyed) return;\n // Only the error message can be in the host before the first mount.\n if (!this.handle) this.host.replaceChildren();\n const json = this.json();\n const cls = this.articleClass() ?? null;\n // Yew schedules its own work; keep it out of Angular's change detection.\n this.zone.runOutsideAngular(() => {\n if (this.handle) this.handle.update(json, cls);\n else this.handle = new ProseHandle(this.host, json, cls);\n });\n }\n\n private showLoadError(error: unknown): void {\n console.error('ds-odrl-prose: could not load the wasm module', error);\n // A mounted Yew tree owns the host's children: leave it alone.\n if (!this.handle) {\n const message = document.createElement('p');\n message.className = 'prose-error';\n message.setAttribute('role', 'alert');\n message.textContent =\n `The ODRL prose renderer could not be loaded (${this.wasmUrl}). Check that the file is served; it is tried again when the input changes.`;\n this.host.replaceChildren(message);\n }\n this.loadFailed.emit(error);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAGA;;;;;AAKG;AACG,SAAU,gBAAgB,CAAC,IAAc,EAAA;AAC7C,IAAA,IAAI,KAAmC;IACvC,OAAO,CAAC,GAAG,KAAI;QACb,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,KAAI;gBACnE,IAAI,KAAK,KAAK,OAAO;oBAAE,KAAK,GAAG,SAAS;AACxC,gBAAA,MAAM,KAAK;AACb,YAAA,CAAC,CAAC;YACF,KAAK,GAAG,OAAO;QACjB;AACA,QAAA,OAAO,KAAK;AACd,IAAA,CAAC;AACH;;ACNA;;;;AAIG;MACU,cAAc,GAAG,IAAI,cAAc,CAAS,gBAAgB,EAAE;AACzE,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,oBAAoB;AACpC,CAAA;AAED;AACA;AACA,MAAM,QAAQ,GAAG,gBAAgB,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,cAAc,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAEpG;;;;;;;;;;AAUG;MAOU,kBAAkB,CAAA;;AAEpB,IAAA,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAU;;IAE/B,YAAY,GAAG,KAAK,EAAU;;IAE9B,UAAU,GAAG,MAAM,EAAW;AAEtB,IAAA,IA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ges, OnDestroy, InjectionToken } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Where the browser fetches `prose_wasm_bg.wasm` from, relative to the page's
5
+ * base href. The build does not emit the file for you: copy it into your
6
+ * assets (see README) or provide this token.
7
+ */
8
+ export declare const PROSE_WASM_URL: InjectionToken<string>;
9
+ /**
10
+ * `<ds-odrl-prose [json]="policy" />` renders ODRL JSON-LD as plain-language
11
+ * prose using the Yew component from `prose-yew`.
12
+ *
13
+ * The component owns the host element's children (Yew keeps its own virtual
14
+ * DOM there); style it through the `prose-*` classes or the `class` input.
15
+ *
16
+ * If the wasm cannot be loaded, the host shows an error (`role="alert"`,
17
+ * class `prose-error`), `loadFailed` emits the error, and the next change of
18
+ * an input tries again.
19
+ */
20
+ export declare class OdrlProseComponent implements OnChanges, OnDestroy {
21
+ /** The ODRL policy as JSON-LD text. */
22
+ readonly json: import("@angular/core").InputSignal<string>;
23
+ /** Extra class(es) for the rendered `<article class="ds-prose">`. */
24
+ readonly articleClass: import("@angular/core").InputSignal<string | undefined>;
25
+ /** Emits when the wasm module could not be loaded. */
26
+ readonly loadFailed: import("@angular/core").OutputEmitterRef<unknown>;
27
+ private readonly host;
28
+ private readonly zone;
29
+ private readonly wasmUrl;
30
+ private handle?;
31
+ private destroyed;
32
+ ngOnChanges(): void;
33
+ ngOnDestroy(): void;
34
+ private sync;
35
+ private showLoadError;
36
+ static ɵfac: i0.ɵɵFactoryDeclaration<OdrlProseComponent, never>;
37
+ static ɵcmp: i0.ɵɵComponentDeclaration<OdrlProseComponent, "ds-odrl-prose", never, { "json": { "alias": "json"; "required": true; "isSignal": true; }; "articleClass": { "alias": "articleClass"; "required": false; "isSignal": true; }; }, { "loadFailed": "loadFailed"; }, never, never, true, never>;
38
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@ds-labs/prose-angular",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Angular component that renders ODRL JSON-LD as plain-language prose (ds-prose-rs, compiled to WebAssembly)",
5
+ "keywords": [
6
+ "angular",
7
+ "odrl",
8
+ "policy",
9
+ "json-ld",
10
+ "wasm",
11
+ "dataspace"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "author": "Nicolas Karageuzian",
15
+ "homepage": "https://github.com/ds-labs-org/ds-prose-rs#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/ds-labs-org/ds-prose-rs.git",
19
+ "directory": "prose-angular"
20
+ },
21
+ "bugs": "https://github.com/ds-labs-org/ds-prose-rs/issues",
22
+ "type": "module",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "peerDependencies": {
27
+ "@angular/core": ">=19.0.0"
28
+ },
29
+ "dependencies": {
30
+ "@ds-labs/prose-wasm": "^0.1.0",
31
+ "tslib": "^2.3.0"
32
+ },
33
+ "module": "fesm2022/ds-labs-prose-angular.mjs",
34
+ "typings": "index.d.ts",
35
+ "exports": {
36
+ "./package.json": {
37
+ "default": "./package.json"
38
+ },
39
+ ".": {
40
+ "types": "./index.d.ts",
41
+ "default": "./fesm2022/ds-labs-prose-angular.mjs"
42
+ }
43
+ },
44
+ "sideEffects": false
6
45
  }
@@ -0,0 +1,9 @@
1
+ /** Loads and instantiates the wasm module. Injected so it can be tested. */
2
+ export type WasmInit = (url: string) => Promise<unknown>;
3
+ /**
4
+ * A loader that runs `init` at most once at a time and shares the result, so
5
+ * every component on a page waits on one fetch. A failed load is forgotten:
6
+ * the callers waiting on it all see the failure, and the next call tries again
7
+ * (the file may have been missing only for a moment).
8
+ */
9
+ export declare function createWasmLoader(init: WasmInit): (url: string) => Promise<unknown>;