@sysce/estrogen 0.0.0-stage → 0.5.4

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.
Files changed (140) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +207 -2
  3. package/bin/estrogen.js +38 -0
  4. package/dist/cjs/astro.d.ts +31 -0
  5. package/dist/cjs/astro.js +45 -0
  6. package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
  7. package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
  8. package/dist/cjs/cloak/astro/HolyText.astro +31 -0
  9. package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
  10. package/dist/cjs/cloak/astro.d.ts +2 -0
  11. package/dist/cjs/cloak/astro.js +10 -0
  12. package/dist/cjs/cloak/base64.d.ts +2 -0
  13. package/dist/cjs/cloak/base64.js +20 -0
  14. package/dist/cjs/cloak/crypto.d.ts +16 -0
  15. package/dist/cjs/cloak/crypto.js +40 -0
  16. package/dist/cjs/cloak/decrypt.d.ts +23 -0
  17. package/dist/cjs/cloak/decrypt.js +144 -0
  18. package/dist/cjs/cloak/elements.d.ts +45 -0
  19. package/dist/cjs/cloak/elements.js +195 -0
  20. package/dist/cjs/cloak/index.d.ts +10 -0
  21. package/dist/cjs/cloak/index.js +41 -0
  22. package/dist/cjs/cloak/preact.d.ts +10 -0
  23. package/dist/cjs/cloak/preact.js +19 -0
  24. package/dist/cjs/cloak/props.d.ts +18 -0
  25. package/dist/cjs/cloak/props.js +27 -0
  26. package/dist/cjs/cloak/react-extra.d.ts +327 -0
  27. package/dist/cjs/cloak/react-extra.js +169 -0
  28. package/dist/cjs/cloak/react.d.ts +28 -0
  29. package/dist/cjs/cloak/react.js +159 -0
  30. package/dist/cjs/cloak/render.d.ts +37 -0
  31. package/dist/cjs/cloak/render.js +54 -0
  32. package/dist/cjs/cloak/server.d.ts +35 -0
  33. package/dist/cjs/cloak/server.js +87 -0
  34. package/dist/cjs/cloak/server.node.d.ts +15 -0
  35. package/dist/cjs/cloak/server.node.js +36 -0
  36. package/dist/cjs/cloak/solid.d.ts +13 -0
  37. package/dist/cjs/cloak/solid.js +55 -0
  38. package/dist/cjs/cloak/span.d.ts +8 -0
  39. package/dist/cjs/cloak/span.js +123 -0
  40. package/dist/cjs/cloak/strings.d.ts +18 -0
  41. package/dist/cjs/cloak/strings.js +53 -0
  42. package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
  43. package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  44. package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
  45. package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
  46. package/dist/cjs/cloak/svelte.d.ts +2 -0
  47. package/dist/cjs/cloak/svelte.js +10 -0
  48. package/dist/cjs/cloak/vue.d.ts +36 -0
  49. package/dist/cjs/cloak/vue.js +34 -0
  50. package/dist/cjs/esbuild.d.ts +33 -0
  51. package/dist/cjs/esbuild.js +79 -0
  52. package/dist/cjs/index.d.ts +24 -0
  53. package/dist/cjs/index.js +35 -0
  54. package/dist/cjs/node-require.js +7 -0
  55. package/dist/cjs/obfuscate.d.ts +23 -0
  56. package/dist/cjs/obfuscate.js +148 -0
  57. package/dist/cjs/options.d.ts +217 -0
  58. package/dist/cjs/options.js +89 -0
  59. package/dist/cjs/package.json +3 -0
  60. package/dist/cjs/report.d.ts +64 -0
  61. package/dist/cjs/report.js +55 -0
  62. package/dist/cjs/resolve-binary.d.ts +44 -0
  63. package/dist/cjs/resolve-binary.js +109 -0
  64. package/dist/cjs/rollup.d.ts +30 -0
  65. package/dist/cjs/rollup.js +57 -0
  66. package/dist/cjs/rsbuild.d.ts +29 -0
  67. package/dist/cjs/rsbuild.js +45 -0
  68. package/dist/cjs/vendor.d.ts +16 -0
  69. package/dist/cjs/vendor.js +95 -0
  70. package/dist/cjs/vite.d.ts +31 -0
  71. package/dist/cjs/vite.js +53 -0
  72. package/dist/esm/astro.d.ts +31 -0
  73. package/dist/esm/astro.js +42 -0
  74. package/dist/esm/cloak/astro/HolyLink.astro +36 -0
  75. package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
  76. package/dist/esm/cloak/astro/HolyText.astro +31 -0
  77. package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
  78. package/dist/esm/cloak/astro.d.ts +2 -0
  79. package/dist/esm/cloak/astro.js +2 -0
  80. package/dist/esm/cloak/base64.d.ts +2 -0
  81. package/dist/esm/cloak/base64.js +16 -0
  82. package/dist/esm/cloak/crypto.d.ts +16 -0
  83. package/dist/esm/cloak/crypto.js +36 -0
  84. package/dist/esm/cloak/decrypt.d.ts +23 -0
  85. package/dist/esm/cloak/decrypt.js +136 -0
  86. package/dist/esm/cloak/elements.d.ts +45 -0
  87. package/dist/esm/cloak/elements.js +189 -0
  88. package/dist/esm/cloak/index.d.ts +10 -0
  89. package/dist/esm/cloak/index.js +13 -0
  90. package/dist/esm/cloak/preact.d.ts +10 -0
  91. package/dist/esm/cloak/preact.js +15 -0
  92. package/dist/esm/cloak/props.d.ts +18 -0
  93. package/dist/esm/cloak/props.js +23 -0
  94. package/dist/esm/cloak/react-extra.d.ts +327 -0
  95. package/dist/esm/cloak/react-extra.js +161 -0
  96. package/dist/esm/cloak/react.d.ts +28 -0
  97. package/dist/esm/cloak/react.js +147 -0
  98. package/dist/esm/cloak/render.d.ts +37 -0
  99. package/dist/esm/cloak/render.js +48 -0
  100. package/dist/esm/cloak/server.d.ts +35 -0
  101. package/dist/esm/cloak/server.js +75 -0
  102. package/dist/esm/cloak/server.node.d.ts +15 -0
  103. package/dist/esm/cloak/server.node.js +22 -0
  104. package/dist/esm/cloak/solid.d.ts +13 -0
  105. package/dist/esm/cloak/solid.js +51 -0
  106. package/dist/esm/cloak/span.d.ts +8 -0
  107. package/dist/esm/cloak/span.js +117 -0
  108. package/dist/esm/cloak/strings.d.ts +18 -0
  109. package/dist/esm/cloak/strings.js +47 -0
  110. package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
  111. package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  112. package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
  113. package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
  114. package/dist/esm/cloak/svelte.d.ts +2 -0
  115. package/dist/esm/cloak/svelte.js +2 -0
  116. package/dist/esm/cloak/vue.d.ts +36 -0
  117. package/dist/esm/cloak/vue.js +31 -0
  118. package/dist/esm/esbuild.d.ts +33 -0
  119. package/dist/esm/esbuild.js +76 -0
  120. package/dist/esm/index.d.ts +24 -0
  121. package/dist/esm/index.js +22 -0
  122. package/dist/esm/node-require.js +8 -0
  123. package/dist/esm/obfuscate.d.ts +23 -0
  124. package/dist/esm/obfuscate.js +145 -0
  125. package/dist/esm/options.d.ts +217 -0
  126. package/dist/esm/options.js +85 -0
  127. package/dist/esm/package.json +3 -0
  128. package/dist/esm/report.d.ts +64 -0
  129. package/dist/esm/report.js +49 -0
  130. package/dist/esm/resolve-binary.d.ts +44 -0
  131. package/dist/esm/resolve-binary.js +101 -0
  132. package/dist/esm/rollup.d.ts +30 -0
  133. package/dist/esm/rollup.js +54 -0
  134. package/dist/esm/rsbuild.d.ts +29 -0
  135. package/dist/esm/rsbuild.js +42 -0
  136. package/dist/esm/vendor.d.ts +16 -0
  137. package/dist/esm/vendor.js +92 -0
  138. package/dist/esm/vite.d.ts +31 -0
  139. package/dist/esm/vite.js +50 -0
  140. package/package.json +282 -5
@@ -0,0 +1,147 @@
1
+ import { createElement, useRef, } from 'react';
2
+ import './elements.js';
3
+ import { holyDecrypt } from './decrypt.js';
4
+ import { linkElementProps, textElementProps, } from './props.js';
5
+ import { HolyDomText } from './react-extra.js';
6
+ import { cipherFor } from './render.js';
7
+ export { HolyDomText, HolyDynamic, HolyInput, HolyProse, HolyRich, useHolyAttr, } from './react-extra.js';
8
+ export function HolyText({ text, ciphertext, encrypted, as, ellipsis, revealForBots, children, ...attributes }) {
9
+ const content = text ?? (typeof children === 'string' ? children : '');
10
+ const cipher = ciphertext ?? encrypted;
11
+ if (as) {
12
+ return createElement(HolyDomText, {
13
+ ...attributes,
14
+ as,
15
+ text: content,
16
+ ciphertext: cipher,
17
+ ellipsis,
18
+ revealForBots,
19
+ });
20
+ }
21
+ const { attributes: cloak, placeholder } = textElementProps({
22
+ text: content,
23
+ ciphertext: cipher,
24
+ ellipsis,
25
+ revealForBots,
26
+ });
27
+ return createElement('holy-text', { ...attributes, ...cloak }, placeholder);
28
+ }
29
+ export function HolyLink({ as, href, hrefCipher, encryptedHref, target, children, text, encryptedText, onNavigate, onClick, ...attributes }) {
30
+ if (as === 'a') {
31
+ return createElement(HolyNativeLink, {
32
+ ...attributes,
33
+ href,
34
+ hrefCipher,
35
+ encryptedHref,
36
+ target,
37
+ children,
38
+ text,
39
+ encryptedText,
40
+ onNavigate,
41
+ onClick,
42
+ });
43
+ }
44
+ const label = typeof text === 'string'
45
+ ? createElement(HolyText, { text, ciphertext: encryptedText })
46
+ : children;
47
+ const handleClick = (event) => {
48
+ onClick?.(event);
49
+ if (event.defaultPrevented ||
50
+ !onNavigate ||
51
+ event.button !== 0 ||
52
+ event.ctrlKey ||
53
+ event.metaKey ||
54
+ event.shiftKey ||
55
+ event.altKey ||
56
+ (target && target !== '_self'))
57
+ return;
58
+ const destination = href ?? holyDecrypt(hrefCipher ?? encryptedHref ?? '');
59
+ // Keep external links and explicit protocols on the browser's native path.
60
+ if (!destination || /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(destination))
61
+ return;
62
+ event.preventDefault();
63
+ onNavigate(destination);
64
+ };
65
+ return createElement('holy-link', {
66
+ ...attributes,
67
+ ...linkElementProps({
68
+ href,
69
+ hrefCipher: hrefCipher ?? encryptedHref,
70
+ target,
71
+ }),
72
+ onClick: handleClick,
73
+ }, label);
74
+ }
75
+ /**
76
+ * A native anchor with ciphertext in data-eclink and href="#" at rest.
77
+ * Use this for sites whose link CSS and browser semantics depend on <a>.
78
+ * The real URL is set only during interaction, then hidden on blur or leave.
79
+ */
80
+ export function HolyNativeLink({ href, hrefCipher, encryptedHref, target, text, encryptedText, children, onNavigate, onClick, onAuxClick, onPointerDown, onPointerLeave, onFocus, onBlur, onContextMenu, className = '', as: _as, ...attributes }) {
81
+ const host = useRef(null);
82
+ const cipher = cipherFor(href ?? '', hrefCipher ?? encryptedHref);
83
+ const destination = () => (cipher ? holyDecrypt(cipher) : href) || '#';
84
+ const reveal = () => {
85
+ const next = destination();
86
+ if (host.current)
87
+ host.current.setAttribute('href', next);
88
+ };
89
+ const hide = () => {
90
+ host.current?.setAttribute('href', '#');
91
+ };
92
+ const handleClick = (event) => {
93
+ onClick?.(event);
94
+ if (event.defaultPrevented)
95
+ return;
96
+ reveal();
97
+ const next = host.current?.getAttribute('href') ?? '#';
98
+ if (!onNavigate ||
99
+ event.button !== 0 ||
100
+ event.ctrlKey ||
101
+ event.metaKey ||
102
+ event.shiftKey ||
103
+ event.altKey ||
104
+ (target && target !== '_self') ||
105
+ /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(next))
106
+ return;
107
+ event.preventDefault();
108
+ onNavigate(next);
109
+ };
110
+ const label = typeof text === 'string'
111
+ ? createElement(HolyText, { as: 'span', text, ciphertext: encryptedText })
112
+ : children;
113
+ return createElement('a', {
114
+ ...attributes,
115
+ ref: host,
116
+ href: '#',
117
+ 'data-eclink': cipher,
118
+ target,
119
+ className: `holy-link ${className}`.trim(),
120
+ onClick: handleClick,
121
+ onAuxClick: (event) => {
122
+ onAuxClick?.(event);
123
+ if (!event.defaultPrevented && event.button === 1)
124
+ reveal();
125
+ },
126
+ onPointerDown: (event) => {
127
+ reveal();
128
+ onPointerDown?.(event);
129
+ },
130
+ onPointerLeave: (event) => {
131
+ hide();
132
+ onPointerLeave?.(event);
133
+ },
134
+ onFocus: (event) => {
135
+ reveal();
136
+ onFocus?.(event);
137
+ },
138
+ onBlur: (event) => {
139
+ hide();
140
+ onBlur?.(event);
141
+ },
142
+ onContextMenu: (event) => {
143
+ reveal();
144
+ onContextMenu?.(event);
145
+ },
146
+ }, label);
147
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Build the dash placeholder shown before JS reveals the real text (and the
3
+ * value a naive scraper of the shipped HTML sees). Whitespace is preserved
4
+ * verbatim so the placeholder keeps the word shape and wrapping of the real
5
+ * string; every other code point becomes a dash.
6
+ */
7
+ export declare function makeDashPlaceholder(text: string): string;
8
+ /**
9
+ * Resolve the ciphertext for a string: an explicit ciphertext wins, otherwise
10
+ * the build-time registry. Returns undefined when the string is not registered,
11
+ * so callers fall back to rendering the plaintext.
12
+ */
13
+ export declare function cipherFor(content: string, ciphertext?: string): string | undefined;
14
+ export type HolyResolution = {
15
+ kind: 'reveal';
16
+ plaintext: string;
17
+ } | {
18
+ kind: 'keep';
19
+ };
20
+ export interface ResolveOptions {
21
+ /** Reveal even when the bot tripwire fires. Default false (bots keep dashes). */
22
+ revealForBots?: boolean;
23
+ }
24
+ /**
25
+ * Decide what a cloak host should display:
26
+ * 1. likely bot -> keep the dash placeholder (never reveal).
27
+ * 2. registered but the decrypt fails (no key / error) -> keep dashes.
28
+ * 3. otherwise reveal: the decrypted plaintext, or the raw content when the
29
+ * string was never registered (unobfuscated fallback).
30
+ */
31
+ export declare function resolveHoly(content: string, cipher: string | undefined, opts?: ResolveOptions): HolyResolution;
32
+ /**
33
+ * CSS for a cloak host in ellipsis mode. text-overflow / white-space / overflow
34
+ * are non-inherited, so they never cross the shadow boundary from the host;
35
+ * this styles the shadow-internal container directly.
36
+ */
37
+ export declare const ELLIPSIS_SHADOW_CSS = ".holy-ellipsis{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
@@ -0,0 +1,48 @@
1
+ // DOM-free primitives shared by every cloak component (web component and each
2
+ // framework wrapper). Keeping the placeholder, registry lookup and reveal gate
3
+ // in one pure module means all of them treat decrypt failures and the bot
4
+ // tripwire identically, and the logic is unit-testable without a DOM.
5
+ import { holyDecrypt, isLikelyBot } from './decrypt.js';
6
+ import { getObfuscatedCiphertext } from './strings.js';
7
+ /**
8
+ * Build the dash placeholder shown before JS reveals the real text (and the
9
+ * value a naive scraper of the shipped HTML sees). Whitespace is preserved
10
+ * verbatim so the placeholder keeps the word shape and wrapping of the real
11
+ * string; every other code point becomes a dash.
12
+ */
13
+ export function makeDashPlaceholder(text) {
14
+ if (!text)
15
+ return '---';
16
+ return Array.from(text)
17
+ .map((c) => (/\s/.test(c) ? c : '-'))
18
+ .join('');
19
+ }
20
+ /**
21
+ * Resolve the ciphertext for a string: an explicit ciphertext wins, otherwise
22
+ * the build-time registry. Returns undefined when the string is not registered,
23
+ * so callers fall back to rendering the plaintext.
24
+ */
25
+ export function cipherFor(content, ciphertext) {
26
+ return ciphertext || getObfuscatedCiphertext(content);
27
+ }
28
+ /**
29
+ * Decide what a cloak host should display:
30
+ * 1. likely bot -> keep the dash placeholder (never reveal).
31
+ * 2. registered but the decrypt fails (no key / error) -> keep dashes.
32
+ * 3. otherwise reveal: the decrypted plaintext, or the raw content when the
33
+ * string was never registered (unobfuscated fallback).
34
+ */
35
+ export function resolveHoly(content, cipher, opts) {
36
+ if (isLikelyBot() && !opts?.revealForBots)
37
+ return { kind: 'keep' };
38
+ const plaintext = cipher ? holyDecrypt(cipher) : content;
39
+ if (cipher && !plaintext)
40
+ return { kind: 'keep' };
41
+ return { kind: 'reveal', plaintext };
42
+ }
43
+ /**
44
+ * CSS for a cloak host in ellipsis mode. text-overflow / white-space / overflow
45
+ * are non-inherited, so they never cross the shadow boundary from the host;
46
+ * this styles the shadow-internal container directly.
47
+ */
48
+ export const ELLIPSIS_SHADOW_CSS = '.holy-ellipsis{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}';
@@ -0,0 +1,35 @@
1
+ import { createEncryptionSession, encryptText, type EncryptionSession } from './crypto.js';
2
+ import { makeDashPlaceholder } from './render.js';
3
+ export { createEncryptionSession, encryptText, type EncryptionSession };
4
+ export { makeDashPlaceholder };
5
+ /** Encrypt a JSON value using the same per-request session as visible text. */
6
+ export declare function encryptJson(value: unknown, session: EncryptionSession): string;
7
+ /**
8
+ * Request-local helpers for Astro middleware and other SSR stacks.
9
+ * `clientKey` and async `encryptText` match website2's existing locals types.
10
+ */
11
+ export declare function makeCloakContext(session: EncryptionSession): {
12
+ session: EncryptionSession;
13
+ clientKey: string;
14
+ encryptText: (text: string) => Promise<string>;
15
+ encryptJson: (value: unknown) => Promise<string>;
16
+ keyMarkup: () => string;
17
+ };
18
+ /** Create a fresh context for one request, never for a process lifetime. */
19
+ export declare function createRequestCloak(): {
20
+ session: EncryptionSession;
21
+ clientKey: string;
22
+ encryptText: (text: string) => Promise<string>;
23
+ encryptJson: (value: unknown) => Promise<string>;
24
+ keyMarkup: () => string;
25
+ };
26
+ /** Encrypt a fixed set of strings once, for the page-level registry map. */
27
+ export declare function buildEncryptedStringMap(session: EncryptionSession, strings: string[]): Record<string, string>;
28
+ /** The hidden element that carries the combined key to the client. */
29
+ export declare function cloakKeyMarkup(session: EncryptionSession): string;
30
+ /** A script that publishes the plaintext -> ciphertext map for the registry. */
31
+ export declare function cloakStringsMarkup(map: Record<string, string>): string;
32
+ /** A <holy-text> element: dash placeholder in the light DOM, real text as ciphertext. */
33
+ export declare function cloakText(text: string, session: EncryptionSession): string;
34
+ /** A <holy-link> element: the href and label ship only as ciphertext. */
35
+ export declare function cloakLink(href: string, label: string, session: EncryptionSession, target?: string): string;
@@ -0,0 +1,75 @@
1
+ // @sysce/estrogen/cloak/server: server/build cloak helpers.
2
+ //
3
+ // Make a per-request session, encrypt text and config, and emit the markup the
4
+ // client core needs: the #eckey element, the string-map script, and cloaked
5
+ // <holy-text>/<holy-link> tags that ship a dash placeholder plus ciphertext.
6
+ // The estrogen framework adapters (astro, vite, ...) build on these.
7
+ import { createEncryptionSession, encryptText, } from './crypto.js';
8
+ import { makeDashPlaceholder } from './render.js';
9
+ export { createEncryptionSession, encryptText };
10
+ export { makeDashPlaceholder };
11
+ /** Encrypt a JSON value using the same per-request session as visible text. */
12
+ export function encryptJson(value, session) {
13
+ const json = JSON.stringify(value);
14
+ if (json === undefined)
15
+ throw new TypeError('cloak: value cannot be represented as JSON');
16
+ return encryptText(json, session);
17
+ }
18
+ /**
19
+ * Request-local helpers for Astro middleware and other SSR stacks.
20
+ * `clientKey` and async `encryptText` match website2's existing locals types.
21
+ */
22
+ export function makeCloakContext(session) {
23
+ return {
24
+ session,
25
+ clientKey: session.combinedKeyBase64,
26
+ encryptText: async (text) => encryptText(text, session),
27
+ encryptJson: async (value) => encryptJson(value, session),
28
+ keyMarkup: () => cloakKeyMarkup(session),
29
+ };
30
+ }
31
+ /** Create a fresh context for one request, never for a process lifetime. */
32
+ export function createRequestCloak() {
33
+ return makeCloakContext(createEncryptionSession());
34
+ }
35
+ /** Encrypt a fixed set of strings once, for the page-level registry map. */
36
+ export function buildEncryptedStringMap(session, strings) {
37
+ const map = Object.create(null);
38
+ for (const str of Array.from(new Set(strings)))
39
+ map[str] = encryptText(str, session);
40
+ return map;
41
+ }
42
+ function escapeHtml(s) {
43
+ return s
44
+ .replace(/&/g, '&amp;')
45
+ .replace(/</g, '&lt;')
46
+ .replace(/>/g, '&gt;')
47
+ .replace(/"/g, '&quot;');
48
+ }
49
+ /** The hidden element that carries the combined key to the client. */
50
+ export function cloakKeyMarkup(session) {
51
+ return `<div id="eckey" style="display:none">${session.combinedKeyBase64}</div>`;
52
+ }
53
+ /** A script that publishes the plaintext -> ciphertext map for the registry. */
54
+ export function cloakStringsMarkup(map) {
55
+ // A registry key can contain a closing script tag. Escape it before writing
56
+ // executable HTML so user content cannot terminate the script element.
57
+ const json = JSON.stringify(map)
58
+ .replace(/</g, '\\u003c')
59
+ .replace(/>/g, '\\u003e')
60
+ .replace(/&/g, '\\u0026')
61
+ .replace(/\u2028/g, '\\u2028')
62
+ .replace(/\u2029/g, '\\u2029');
63
+ return `<script>window.__ESTROGEN_CLOAK_STRINGS__=${json}</script>`;
64
+ }
65
+ /** A <holy-text> element: dash placeholder in the light DOM, real text as ciphertext. */
66
+ export function cloakText(text, session) {
67
+ const ciphertext = encryptText(text, session);
68
+ return `<holy-text ciphertext="${ciphertext}">${escapeHtml(makeDashPlaceholder(text))}</holy-text>`;
69
+ }
70
+ /** A <holy-link> element: the href and label ship only as ciphertext. */
71
+ export function cloakLink(href, label, session, target) {
72
+ const hrefCipher = encryptText(href, session);
73
+ const targetAttr = target ? ` target="${escapeHtml(target)}"` : '';
74
+ return `<holy-link href-cipher="${hrefCipher}"${targetAttr}>${cloakText(label, session)}</holy-link>`;
75
+ }
@@ -0,0 +1,15 @@
1
+ export { encryptText, type EncryptionSession } from './crypto.js';
2
+ export { buildEncryptedStringMap, cloakKeyMarkup, cloakLink, cloakStringsMarkup, cloakText, encryptJson, makeCloakContext, makeDashPlaceholder, } from './server.js';
3
+ export declare function createEncryptionSession(): {
4
+ clientKey: Buffer<ArrayBuffer>;
5
+ iv: Buffer<ArrayBuffer>;
6
+ key: Uint8Array;
7
+ combinedKeyBase64: string;
8
+ };
9
+ export declare function createRequestCloak(): {
10
+ session: import("./crypto.js").EncryptionSession;
11
+ clientKey: string;
12
+ encryptText: (text: string) => Promise<string>;
13
+ encryptJson: (value: unknown) => Promise<string>;
14
+ keyMarkup: () => string;
15
+ };
@@ -0,0 +1,22 @@
1
+ // Node-specific entry. Node 18 does not always expose globalThis.crypto, so
2
+ // use node:crypto for random key material without requiring an experimental
3
+ // global WebCrypto flag. Edge runtimes load the standard server.ts entry.
4
+ import { randomFillSync } from 'node:crypto';
5
+ import { createEncryptionSession as createSession } from './crypto.js';
6
+ import { makeCloakContext } from './server.js';
7
+ export { encryptText } from './crypto.js';
8
+ export { buildEncryptedStringMap, cloakKeyMarkup, cloakLink, cloakStringsMarkup, cloakText, encryptJson, makeCloakContext, makeDashPlaceholder, } from './server.js';
9
+ export function createEncryptionSession() {
10
+ const session = createSession(randomFillSync);
11
+ return {
12
+ ...session,
13
+ // Preserve Buffer-valued fields for the Node crypto helper that the
14
+ // original Fracital site uses. The portable server entry stays typed
15
+ // as Uint8Array for edge runtimes.
16
+ clientKey: Buffer.from(session.key),
17
+ iv: Buffer.from(session.iv),
18
+ };
19
+ }
20
+ export function createRequestCloak() {
21
+ return makeCloakContext(createEncryptionSession());
22
+ }
@@ -0,0 +1,13 @@
1
+ import './elements.js';
2
+ import { type CloakLinkProps, type CloakTextProps } from './props.js';
3
+ export interface HolyTextProps extends CloakTextProps {
4
+ class?: string;
5
+ id?: string;
6
+ }
7
+ export interface HolyLinkProps extends CloakLinkProps {
8
+ children?: unknown;
9
+ class?: string;
10
+ id?: string;
11
+ }
12
+ export declare function HolyText(props: HolyTextProps): import("solid-js").JSX.Element;
13
+ export declare function HolyLink(props: HolyLinkProps): import("solid-js").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { createComponent } from 'solid-js';
2
+ import { Dynamic } from 'solid-js/web';
3
+ import './elements.js';
4
+ import { linkElementProps, textElementProps, } from './props.js';
5
+ export function HolyText(props) {
6
+ const get = () => textElementProps(props);
7
+ return createComponent(Dynamic, {
8
+ component: 'holy-text',
9
+ get id() {
10
+ return props.id;
11
+ },
12
+ get class() {
13
+ return props.class;
14
+ },
15
+ get 'attr:ciphertext'() {
16
+ return get().attributes.ciphertext;
17
+ },
18
+ get 'attr:ellipsis'() {
19
+ return get().attributes.ellipsis;
20
+ },
21
+ get 'attr:reveal-for-bots'() {
22
+ return get().attributes['reveal-for-bots'];
23
+ },
24
+ get children() {
25
+ return get().placeholder;
26
+ },
27
+ });
28
+ }
29
+ export function HolyLink(props) {
30
+ return createComponent(Dynamic, {
31
+ component: 'holy-link',
32
+ get id() {
33
+ return props.id;
34
+ },
35
+ get class() {
36
+ return props.class;
37
+ },
38
+ get 'attr:href'() {
39
+ return linkElementProps(props).href;
40
+ },
41
+ get 'attr:href-cipher'() {
42
+ return linkElementProps(props)['href-cipher'];
43
+ },
44
+ get 'attr:target'() {
45
+ return props.target;
46
+ },
47
+ get children() {
48
+ return props.children;
49
+ },
50
+ });
51
+ }
@@ -0,0 +1,8 @@
1
+ export type SpanNavigate = (href: string) => void | Promise<void>;
2
+ /** Reveal encrypted website2-style text into closed roots on native spans. */
3
+ export declare function revealSpanText(root?: ParentNode): void;
4
+ /** Bind website2-style span links once, without writing URLs into the DOM. */
5
+ export declare function bindSpanLinks(root?: ParentNode): void;
6
+ /** Re-run the two span passes after each Astro view transition. */
7
+ export declare function setupSpanCloak(onNavigate?: SpanNavigate): void;
8
+ export declare function refreshSpanCloak(): void;
@@ -0,0 +1,117 @@
1
+ // Optional Astro span-host compatibility. website2 uses native span elements
2
+ // as encrypted text and link hosts. Keep that DOM contract for site migrations
3
+ // without changing the default <holy-text> and <holy-link> components.
4
+ import { holyDecrypt, isLikelyBot } from './decrypt.js';
5
+ let installed = false;
6
+ let navigate;
7
+ const textRoots = new WeakMap();
8
+ const linkStates = new WeakMap();
9
+ /** Reveal encrypted website2-style text into closed roots on native spans. */
10
+ export function revealSpanText(root = document) {
11
+ if (isLikelyBot())
12
+ return;
13
+ for (const host of root.querySelectorAll('span[data-ectext]')) {
14
+ const cipher = host.getAttribute('data-ectext');
15
+ if (!cipher)
16
+ continue;
17
+ const plaintext = holyDecrypt(cipher);
18
+ if (!plaintext) {
19
+ // A failed decryption on a reused host must not keep showing the
20
+ // previous route's plaintext. Retain ciphertext so it can retry.
21
+ textRoots
22
+ .get(host)
23
+ ?.replaceChildren(document.createTextNode(host.textContent || '---'));
24
+ continue;
25
+ }
26
+ try {
27
+ let shadow = textRoots.get(host);
28
+ if (!shadow) {
29
+ shadow = host.attachShadow({ mode: 'closed' });
30
+ textRoots.set(host, shadow);
31
+ }
32
+ shadow.replaceChildren(document.createTextNode(plaintext));
33
+ host.removeAttribute('data-ectext');
34
+ }
35
+ catch {
36
+ // Leave the dash placeholder and ciphertext for a later hydration pass.
37
+ }
38
+ }
39
+ }
40
+ /** Bind website2-style span links once, without writing URLs into the DOM. */
41
+ export function bindSpanLinks(root = document) {
42
+ // Unlike text reveal, website2's link binding is not gated by webdriver.
43
+ // Keep navigation active while the bot tripwire holds the text placeholder.
44
+ for (const host of root.querySelectorAll('span[data-eclink]')) {
45
+ const cipher = host.getAttribute('data-eclink');
46
+ if (!cipher)
47
+ continue;
48
+ const href = holyDecrypt(cipher);
49
+ if (!href) {
50
+ const previous = linkStates.get(host);
51
+ if (previous)
52
+ previous.href = '';
53
+ continue;
54
+ }
55
+ const target = host.getAttribute('data-target');
56
+ const existing = linkStates.get(host);
57
+ if (existing) {
58
+ // Astro's DOM morph can reuse a span for a new route. Update the
59
+ // existing listeners instead of retaining a stale captured href.
60
+ existing.href = href;
61
+ existing.target = target;
62
+ host.removeAttribute('data-eclink');
63
+ host.removeAttribute('data-target');
64
+ continue;
65
+ }
66
+ const current = { href, target };
67
+ linkStates.set(host, current);
68
+ host.removeAttribute('data-eclink');
69
+ host.removeAttribute('data-target');
70
+ host.addEventListener('mouseup', (event) => {
71
+ if (event.button === 1 && current.href) {
72
+ event.preventDefault();
73
+ window.open(current.href, '_blank');
74
+ }
75
+ });
76
+ host.addEventListener('click', (event) => {
77
+ if (event.defaultPrevented)
78
+ return;
79
+ event.preventDefault();
80
+ if (!current.href)
81
+ return;
82
+ if (event.ctrlKey ||
83
+ event.metaKey ||
84
+ event.shiftKey ||
85
+ event.button === 1) {
86
+ window.open(current.href, '_blank');
87
+ }
88
+ else if (current.target) {
89
+ window.open(current.href, current.target);
90
+ }
91
+ else if (navigate) {
92
+ void navigate(current.href);
93
+ }
94
+ else {
95
+ window.location.assign(current.href);
96
+ }
97
+ });
98
+ }
99
+ }
100
+ /** Re-run the two span passes after each Astro view transition. */
101
+ export function setupSpanCloak(onNavigate) {
102
+ if (typeof document === 'undefined')
103
+ return;
104
+ if (onNavigate)
105
+ navigate = onNavigate;
106
+ if (!installed) {
107
+ installed = true;
108
+ document.addEventListener('astro:page-load', refreshSpanCloak);
109
+ }
110
+ refreshSpanCloak();
111
+ }
112
+ export function refreshSpanCloak() {
113
+ if (typeof document === 'undefined')
114
+ return;
115
+ revealSpanText(document);
116
+ bindSpanLinks(document);
117
+ }
@@ -0,0 +1,18 @@
1
+ declare global {
2
+ interface Window {
3
+ __ESTROGEN_CLOAK_STRINGS__?: Record<string, string>;
4
+ }
5
+ }
6
+ /** Read an existing application's registry without renaming its page global. */
7
+ export declare function setCloakStringMapProvider(provider: (() => Record<string, string> | null | undefined) | undefined): void;
8
+ /** Register one plaintext -> ciphertext pair (e.g. from a dynamic build step). */
9
+ export declare function registerObfuscatedString(text: string, ciphertext: string): void;
10
+ /** Register a whole plaintext -> ciphertext map at once. */
11
+ export declare function registerObfuscatedStrings(map: Record<string, string>): void;
12
+ /**
13
+ * Look up the ciphertext for a plaintext string: the page-level global map
14
+ * wins, then the local registry. Returns undefined when the string was never
15
+ * registered, which tells callers to render the plaintext directly.
16
+ */
17
+ export declare function getObfuscatedCiphertext(text: string): string | undefined;
18
+ export {};
@@ -0,0 +1,47 @@
1
+ // The build-time string registry. A build step encrypts a fixed set of strings
2
+ // (brand, nav, auth copy) once and ships the plaintext -> ciphertext map on the
3
+ // page as window.__ESTROGEN_CLOAK_STRINGS__. Components look a string up here
4
+ // instead of carrying an explicit ciphertext prop.
5
+ const GLOBAL = '__ESTROGEN_CLOAK_STRINGS__';
6
+ const localRegistry = Object.create(null);
7
+ let stringMapProvider;
8
+ /** Read an existing application's registry without renaming its page global. */
9
+ export function setCloakStringMapProvider(provider) {
10
+ stringMapProvider = provider;
11
+ }
12
+ /** Register one plaintext -> ciphertext pair (e.g. from a dynamic build step). */
13
+ export function registerObfuscatedString(text, ciphertext) {
14
+ localRegistry[text] = ciphertext;
15
+ }
16
+ /** Register a whole plaintext -> ciphertext map at once. */
17
+ export function registerObfuscatedStrings(map) {
18
+ for (const [plain, ciphertext] of Object.entries(map)) {
19
+ if (typeof ciphertext === 'string')
20
+ localRegistry[plain] = ciphertext;
21
+ }
22
+ }
23
+ /**
24
+ * Look up the ciphertext for a plaintext string: the page-level global map
25
+ * wins, then the local registry. Returns undefined when the string was never
26
+ * registered, which tells callers to render the plaintext directly.
27
+ */
28
+ export function getObfuscatedCiphertext(text) {
29
+ if (typeof window !== 'undefined') {
30
+ const map = window[GLOBAL];
31
+ const fromGlobal = map && Object.hasOwn(map, text) ? map[text] : undefined;
32
+ if (fromGlobal)
33
+ return fromGlobal;
34
+ }
35
+ if (stringMapProvider) {
36
+ try {
37
+ const map = stringMapProvider();
38
+ const fromProvider = map && Object.hasOwn(map, text) ? map[text] : undefined;
39
+ if (typeof fromProvider === 'string' && fromProvider)
40
+ return fromProvider;
41
+ }
42
+ catch {
43
+ // An unavailable host registry must not break fallback rendering.
44
+ }
45
+ }
46
+ return localRegistry[text];
47
+ }
@@ -0,0 +1,12 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import '../elements.js';
4
+ import { linkElementProps, type CloakLinkProps } from '../props.js';
5
+
6
+ let { href, hrefCipher, target, children }: CloakLinkProps & { children?: Snippet } = $props();
7
+ const attrs = $derived(linkElementProps({ href, hrefCipher, target }));
8
+ </script>
9
+
10
+ <holy-link href={attrs.href} href-cipher={attrs['href-cipher']} {target}>
11
+ {#if children}{@render children()}{/if}
12
+ </holy-link>
@@ -0,0 +1,5 @@
1
+ import type { Component, Snippet } from 'svelte';
2
+ import type { CloakLinkProps } from '../props.js';
3
+
4
+ declare const HolyLink: Component<CloakLinkProps & { children?: Snippet }>;
5
+ export default HolyLink;