@sysce/estrogen 0.0.0-stage → 0.5.5

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