@wdprlib/runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ interface RuntimeOptions {
2
+ /** Root element to bind event listeners (default: document.body) */
3
+ root?: HTMLElement;
4
+ /** Use fade animation for collapsible open/close (default: true) */
5
+ fade?: boolean;
6
+ /** MathJax or KaTeX CDN URL - auto-loads script when math elements are detected */
7
+ mathUrl?: string;
8
+ /** Callback when user votes on a page rate widget */
9
+ onRate?: (pageId: string, points: number) => Promise<RateResult>;
10
+ /** Callback when user clicks a join button */
11
+ onJoin?: () => Promise<void>;
12
+ }
13
+ interface RateResult {
14
+ points: number;
15
+ votes: number;
16
+ percent: number;
17
+ }
18
+ interface WdprRuntime {
19
+ /** Remove all event listeners and clean up */
20
+ destroy(): void;
21
+ }
22
+ /**
23
+ * Script to inject into htmlBlock iframe content.
24
+ * This should be included in the HTML served for htmlBlock iframes.
25
+ *
26
+ * Usage: Wrap htmlBlock content like this:
27
+ * ```html
28
+ * <!DOCTYPE html>
29
+ * <html>
30
+ * <head><script>${HTML_BLOCK_RESIZE_SCRIPT}<\/script></head>
31
+ * <body>${htmlBlockContent}</body>
32
+ * </html>
33
+ * ```
34
+ */
35
+ declare const HTML_BLOCK_RESIZE_SCRIPT = "(function(){\\n function notifyHeight() {\\n var height = (document.documentElement.scrollHeight || document.body.scrollHeight) + 2;\\n parent.postMessage({ type: 'wdpr-html-block-resize', height: height }, '*');\\n }\\n if (typeof ResizeObserver !== 'undefined') {\\n new ResizeObserver(notifyHeight).observe(document.body);\\n } else {\\n setInterval(notifyHeight, 250);\\n }\\n if (document.readyState === 'loading') {\\n document.addEventListener('DOMContentLoaded', notifyHeight);\\n } else {\\n notifyHeight();\\n }\\n window.addEventListener('load', notifyHeight);\\n})();";
36
+ /** Initialize the wdpr runtime, binding event listeners for interactive elements */
37
+ declare function initWdprRuntime(options?: RuntimeOptions): WdprRuntime;
38
+ export { initWdprRuntime, WdprRuntime, RuntimeOptions, RateResult, HTML_BLOCK_RESIZE_SCRIPT };
@@ -0,0 +1,38 @@
1
+ interface RuntimeOptions {
2
+ /** Root element to bind event listeners (default: document.body) */
3
+ root?: HTMLElement;
4
+ /** Use fade animation for collapsible open/close (default: true) */
5
+ fade?: boolean;
6
+ /** MathJax or KaTeX CDN URL - auto-loads script when math elements are detected */
7
+ mathUrl?: string;
8
+ /** Callback when user votes on a page rate widget */
9
+ onRate?: (pageId: string, points: number) => Promise<RateResult>;
10
+ /** Callback when user clicks a join button */
11
+ onJoin?: () => Promise<void>;
12
+ }
13
+ interface RateResult {
14
+ points: number;
15
+ votes: number;
16
+ percent: number;
17
+ }
18
+ interface WdprRuntime {
19
+ /** Remove all event listeners and clean up */
20
+ destroy(): void;
21
+ }
22
+ /**
23
+ * Script to inject into htmlBlock iframe content.
24
+ * This should be included in the HTML served for htmlBlock iframes.
25
+ *
26
+ * Usage: Wrap htmlBlock content like this:
27
+ * ```html
28
+ * <!DOCTYPE html>
29
+ * <html>
30
+ * <head><script>${HTML_BLOCK_RESIZE_SCRIPT}<\/script></head>
31
+ * <body>${htmlBlockContent}</body>
32
+ * </html>
33
+ * ```
34
+ */
35
+ declare const HTML_BLOCK_RESIZE_SCRIPT = "(function(){\\n function notifyHeight() {\\n var height = (document.documentElement.scrollHeight || document.body.scrollHeight) + 2;\\n parent.postMessage({ type: 'wdpr-html-block-resize', height: height }, '*');\\n }\\n if (typeof ResizeObserver !== 'undefined') {\\n new ResizeObserver(notifyHeight).observe(document.body);\\n } else {\\n setInterval(notifyHeight, 250);\\n }\\n if (document.readyState === 'loading') {\\n document.addEventListener('DOMContentLoaded', notifyHeight);\\n } else {\\n notifyHeight();\\n }\\n window.addEventListener('load', notifyHeight);\\n})();";
36
+ /** Initialize the wdpr runtime, binding event listeners for interactive elements */
37
+ declare function initWdprRuntime(options?: RuntimeOptions): WdprRuntime;
38
+ export { initWdprRuntime, WdprRuntime, RuntimeOptions, RateResult, HTML_BLOCK_RESIZE_SCRIPT };