@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.
- package/LICENSE +15 -0
- package/README.md +207 -2
- package/bin/estrogen.js +38 -0
- package/dist/cjs/astro.d.ts +31 -0
- package/dist/cjs/astro.js +45 -0
- package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
- package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/cjs/cloak/astro/HolyText.astro +31 -0
- package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/cjs/cloak/astro.d.ts +2 -0
- package/dist/cjs/cloak/astro.js +10 -0
- package/dist/cjs/cloak/base64.d.ts +2 -0
- package/dist/cjs/cloak/base64.js +20 -0
- package/dist/cjs/cloak/crypto.d.ts +16 -0
- package/dist/cjs/cloak/crypto.js +40 -0
- package/dist/cjs/cloak/decrypt.d.ts +23 -0
- package/dist/cjs/cloak/decrypt.js +144 -0
- package/dist/cjs/cloak/elements.d.ts +45 -0
- package/dist/cjs/cloak/elements.js +195 -0
- package/dist/cjs/cloak/index.d.ts +10 -0
- package/dist/cjs/cloak/index.js +41 -0
- package/dist/cjs/cloak/preact.d.ts +10 -0
- package/dist/cjs/cloak/preact.js +19 -0
- package/dist/cjs/cloak/props.d.ts +18 -0
- package/dist/cjs/cloak/props.js +27 -0
- package/dist/cjs/cloak/react-extra.d.ts +327 -0
- package/dist/cjs/cloak/react-extra.js +169 -0
- package/dist/cjs/cloak/react.d.ts +28 -0
- package/dist/cjs/cloak/react.js +159 -0
- package/dist/cjs/cloak/render.d.ts +37 -0
- package/dist/cjs/cloak/render.js +54 -0
- package/dist/cjs/cloak/server.d.ts +35 -0
- package/dist/cjs/cloak/server.js +87 -0
- package/dist/cjs/cloak/server.node.d.ts +15 -0
- package/dist/cjs/cloak/server.node.js +36 -0
- package/dist/cjs/cloak/solid.d.ts +13 -0
- package/dist/cjs/cloak/solid.js +55 -0
- package/dist/cjs/cloak/span.d.ts +8 -0
- package/dist/cjs/cloak/span.js +123 -0
- package/dist/cjs/cloak/strings.d.ts +18 -0
- package/dist/cjs/cloak/strings.js +53 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte.d.ts +2 -0
- package/dist/cjs/cloak/svelte.js +10 -0
- package/dist/cjs/cloak/vue.d.ts +36 -0
- package/dist/cjs/cloak/vue.js +34 -0
- package/dist/cjs/esbuild.d.ts +33 -0
- package/dist/cjs/esbuild.js +79 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/node-require.js +7 -0
- package/dist/cjs/obfuscate.d.ts +23 -0
- package/dist/cjs/obfuscate.js +148 -0
- package/dist/cjs/options.d.ts +217 -0
- package/dist/cjs/options.js +89 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/report.d.ts +64 -0
- package/dist/cjs/report.js +55 -0
- package/dist/cjs/resolve-binary.d.ts +44 -0
- package/dist/cjs/resolve-binary.js +109 -0
- package/dist/cjs/rollup.d.ts +30 -0
- package/dist/cjs/rollup.js +57 -0
- package/dist/cjs/rsbuild.d.ts +29 -0
- package/dist/cjs/rsbuild.js +45 -0
- package/dist/cjs/vendor.d.ts +16 -0
- package/dist/cjs/vendor.js +95 -0
- package/dist/cjs/vite.d.ts +31 -0
- package/dist/cjs/vite.js +53 -0
- package/dist/esm/astro.d.ts +31 -0
- package/dist/esm/astro.js +42 -0
- package/dist/esm/cloak/astro/HolyLink.astro +36 -0
- package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/esm/cloak/astro/HolyText.astro +31 -0
- package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/esm/cloak/astro.d.ts +2 -0
- package/dist/esm/cloak/astro.js +2 -0
- package/dist/esm/cloak/base64.d.ts +2 -0
- package/dist/esm/cloak/base64.js +16 -0
- package/dist/esm/cloak/crypto.d.ts +16 -0
- package/dist/esm/cloak/crypto.js +36 -0
- package/dist/esm/cloak/decrypt.d.ts +23 -0
- package/dist/esm/cloak/decrypt.js +136 -0
- package/dist/esm/cloak/elements.d.ts +45 -0
- package/dist/esm/cloak/elements.js +189 -0
- package/dist/esm/cloak/index.d.ts +10 -0
- package/dist/esm/cloak/index.js +13 -0
- package/dist/esm/cloak/preact.d.ts +10 -0
- package/dist/esm/cloak/preact.js +15 -0
- package/dist/esm/cloak/props.d.ts +18 -0
- package/dist/esm/cloak/props.js +23 -0
- package/dist/esm/cloak/react-extra.d.ts +327 -0
- package/dist/esm/cloak/react-extra.js +161 -0
- package/dist/esm/cloak/react.d.ts +28 -0
- package/dist/esm/cloak/react.js +147 -0
- package/dist/esm/cloak/render.d.ts +37 -0
- package/dist/esm/cloak/render.js +48 -0
- package/dist/esm/cloak/server.d.ts +35 -0
- package/dist/esm/cloak/server.js +75 -0
- package/dist/esm/cloak/server.node.d.ts +15 -0
- package/dist/esm/cloak/server.node.js +22 -0
- package/dist/esm/cloak/solid.d.ts +13 -0
- package/dist/esm/cloak/solid.js +51 -0
- package/dist/esm/cloak/span.d.ts +8 -0
- package/dist/esm/cloak/span.js +117 -0
- package/dist/esm/cloak/strings.d.ts +18 -0
- package/dist/esm/cloak/strings.js +47 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
- package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte.d.ts +2 -0
- package/dist/esm/cloak/svelte.js +2 -0
- package/dist/esm/cloak/vue.d.ts +36 -0
- package/dist/esm/cloak/vue.js +31 -0
- package/dist/esm/esbuild.d.ts +33 -0
- package/dist/esm/esbuild.js +76 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/node-require.js +8 -0
- package/dist/esm/obfuscate.d.ts +23 -0
- package/dist/esm/obfuscate.js +145 -0
- package/dist/esm/options.d.ts +217 -0
- package/dist/esm/options.js +85 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/report.d.ts +64 -0
- package/dist/esm/report.js +49 -0
- package/dist/esm/resolve-binary.d.ts +44 -0
- package/dist/esm/resolve-binary.js +101 -0
- package/dist/esm/rollup.d.ts +30 -0
- package/dist/esm/rollup.js +54 -0
- package/dist/esm/rsbuild.d.ts +29 -0
- package/dist/esm/rsbuild.js +42 -0
- package/dist/esm/vendor.d.ts +16 -0
- package/dist/esm/vendor.js +92 -0
- package/dist/esm/vite.d.ts +31 -0
- package/dist/esm/vite.js +50 -0
- package/package.json +282 -5
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Client side of the cloak: read the per-request key from the page and turn
|
|
3
|
+
// ciphertext back into plaintext. Ported from the holyDecrypt implementations
|
|
4
|
+
// that shipped in website2 and Fracital, generalized so it has no app-specific
|
|
5
|
+
// names and can read its key from a decoy overlay's shadow root.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.setCloakKeyProvider = setCloakKeyProvider;
|
|
8
|
+
exports.setCloakRoot = setCloakRoot;
|
|
9
|
+
exports.loadDecryptionKey = loadDecryptionKey;
|
|
10
|
+
exports.holyDecrypt = holyDecrypt;
|
|
11
|
+
exports.holyDecryptJson = holyDecryptJson;
|
|
12
|
+
exports.isLikelyBot = isLikelyBot;
|
|
13
|
+
const aes_js_1 = require("@noble/ciphers/aes.js");
|
|
14
|
+
const base64_js_1 = require("./base64.js");
|
|
15
|
+
/** The element id that carries base64(iv ++ key). Kept stable for drop-in use. */
|
|
16
|
+
const KEY_ELEMENT_ID = 'eckey';
|
|
17
|
+
/** Optional window global fallback for the combined key. */
|
|
18
|
+
const KEY_GLOBAL = '__ESTROGEN_CLOAK_KEY__';
|
|
19
|
+
let cachedKey;
|
|
20
|
+
let rootResolver;
|
|
21
|
+
let keyProvider;
|
|
22
|
+
/** Read the key from a host application's existing runtime, without copying globals. */
|
|
23
|
+
function setCloakKeyProvider(provider) {
|
|
24
|
+
keyProvider = provider;
|
|
25
|
+
cachedKey = undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tell the decryptor where to look for the #eckey element first, e.g. a decoy
|
|
29
|
+
* overlay's shadow root. The document is always checked as a fallback.
|
|
30
|
+
*/
|
|
31
|
+
function setCloakRoot(resolver) {
|
|
32
|
+
rootResolver = resolver;
|
|
33
|
+
cachedKey = undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Load the combined key from the DOM (or the window global). Safe to re-call. */
|
|
36
|
+
function loadDecryptionKey() {
|
|
37
|
+
if (typeof document !== 'undefined') {
|
|
38
|
+
const root = rootResolver?.();
|
|
39
|
+
// Document and ShadowRoot (via DocumentFragment) both expose getElementById.
|
|
40
|
+
const el = root?.getElementById(KEY_ELEMENT_ID) ??
|
|
41
|
+
document.getElementById(KEY_ELEMENT_ID);
|
|
42
|
+
if (el?.textContent) {
|
|
43
|
+
try {
|
|
44
|
+
const key = (0, base64_js_1.fromBase64)(el.textContent);
|
|
45
|
+
if (key.length !== 48)
|
|
46
|
+
throw new Error('invalid cloak key length');
|
|
47
|
+
cachedKey = key;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// fall through to the global
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Existing applications may already publish a page-scoped encryption key
|
|
56
|
+
// under a different name. Let them supply it without changing their markup.
|
|
57
|
+
if (keyProvider) {
|
|
58
|
+
try {
|
|
59
|
+
const provided = keyProvider();
|
|
60
|
+
if (typeof provided === 'string') {
|
|
61
|
+
const key = (0, base64_js_1.fromBase64)(provided);
|
|
62
|
+
if (key.length !== 48)
|
|
63
|
+
throw new Error('invalid cloak key length');
|
|
64
|
+
cachedKey = key;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Fall through to the normal page global or cached key.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const winKey = globalThis[KEY_GLOBAL];
|
|
73
|
+
if (typeof winKey === 'string') {
|
|
74
|
+
try {
|
|
75
|
+
const key = (0, base64_js_1.fromBase64)(winKey);
|
|
76
|
+
if (key.length !== 48)
|
|
77
|
+
throw new Error('invalid cloak key length');
|
|
78
|
+
cachedKey = key;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// fall through
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return cachedKey !== undefined;
|
|
86
|
+
}
|
|
87
|
+
if (typeof document !== 'undefined') {
|
|
88
|
+
loadDecryptionKey();
|
|
89
|
+
// Astro view transitions and late-injected keys: re-read on these events.
|
|
90
|
+
document.addEventListener('DOMContentLoaded', loadDecryptionKey);
|
|
91
|
+
document.addEventListener('astro:page-load', loadDecryptionKey);
|
|
92
|
+
}
|
|
93
|
+
const decoder = new TextDecoder();
|
|
94
|
+
let warnedMissingKey = false;
|
|
95
|
+
let warnedDecryptError = false;
|
|
96
|
+
/**
|
|
97
|
+
* Decrypt one base64 ciphertext string to plaintext. Returns "" on a missing
|
|
98
|
+
* key or a decrypt error, so a caller can keep its dash placeholder rather than
|
|
99
|
+
* blanking the text.
|
|
100
|
+
*/
|
|
101
|
+
function holyDecrypt(ciphertextB64) {
|
|
102
|
+
if (!ciphertextB64)
|
|
103
|
+
return '';
|
|
104
|
+
if (!loadDecryptionKey() && cachedKey === undefined) {
|
|
105
|
+
if (!warnedMissingKey) {
|
|
106
|
+
warnedMissingKey = true;
|
|
107
|
+
console.error('cloak: key unavailable; keeping placeholder');
|
|
108
|
+
}
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const cipherBytes = (0, base64_js_1.fromBase64)(ciphertextB64);
|
|
113
|
+
const iv = cachedKey.slice(0, 16);
|
|
114
|
+
const key = cachedKey.slice(16);
|
|
115
|
+
return decoder.decode((0, aes_js_1.cbc)(key, iv).decrypt(cipherBytes));
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
if (!warnedDecryptError) {
|
|
119
|
+
warnedDecryptError = true;
|
|
120
|
+
console.error('cloak: decrypt error', err);
|
|
121
|
+
}
|
|
122
|
+
return '';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Parse a JSON payload encrypted with `encryptJson` on the server. */
|
|
126
|
+
function holyDecryptJson(ciphertextB64) {
|
|
127
|
+
const plaintext = holyDecrypt(ciphertextB64);
|
|
128
|
+
if (!plaintext)
|
|
129
|
+
return undefined;
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(plaintext);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A tripwire, not a security control: flags a likely headless/automated browser
|
|
139
|
+
* so the reveal step can stay on the dash placeholder. Must never block a real
|
|
140
|
+
* user, so it only reads navigator.webdriver.
|
|
141
|
+
*/
|
|
142
|
+
function isLikelyBot() {
|
|
143
|
+
return typeof navigator !== 'undefined' && Boolean(navigator.webdriver);
|
|
144
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { makeDashPlaceholder } from './render.js';
|
|
2
|
+
declare const ElementBase: typeof HTMLElement;
|
|
3
|
+
/**
|
|
4
|
+
* <holy-text ciphertext="..." [text="..."] [ellipsis] [reveal-for-bots]>----</holy-text>
|
|
5
|
+
*
|
|
6
|
+
* Ships with a dash placeholder as its light-DOM text. On connect it resolves
|
|
7
|
+
* the real text and, unless kept (bot / decrypt failure), attaches a closed
|
|
8
|
+
* shadow root holding the plaintext. A shadow root suppresses the light dash
|
|
9
|
+
* text, so the host shows the real string without it ever being in innerHTML.
|
|
10
|
+
*/
|
|
11
|
+
export declare class HolyTextElement extends ElementBase {
|
|
12
|
+
static get observedAttributes(): string[];
|
|
13
|
+
private shadow?;
|
|
14
|
+
private observer?;
|
|
15
|
+
connectedCallback(): void;
|
|
16
|
+
disconnectedCallback(): void;
|
|
17
|
+
attributeChangedCallback(): void;
|
|
18
|
+
private get sourceText();
|
|
19
|
+
private reveal;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* <holy-link href-cipher="..." [target="_blank"]>Label</holy-link>
|
|
23
|
+
*
|
|
24
|
+
* Renders an anchor whose href is "#" at rest; the real href is decrypted and
|
|
25
|
+
* applied only on pointer/focus interaction, and restored to "#" on leave, so
|
|
26
|
+
* the URL is never sitting in the shipped markup. Click decrypts and navigates.
|
|
27
|
+
*/
|
|
28
|
+
export declare class HolyLinkElement extends ElementBase {
|
|
29
|
+
static get observedAttributes(): string[];
|
|
30
|
+
private shadow?;
|
|
31
|
+
private anchor?;
|
|
32
|
+
connectedCallback(): void;
|
|
33
|
+
attributeChangedCallback(): void;
|
|
34
|
+
private realHref;
|
|
35
|
+
private build;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register the cloak custom elements. Idempotent and safe to call more than
|
|
39
|
+
* once; a name already defined is left as-is.
|
|
40
|
+
*/
|
|
41
|
+
export declare function defineCloakElements(tags?: {
|
|
42
|
+
text?: string;
|
|
43
|
+
link?: string;
|
|
44
|
+
}): void;
|
|
45
|
+
export { makeDashPlaceholder };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The framework-agnostic layer: <holy-text> and <holy-link> custom elements.
|
|
3
|
+
// These are the primitive every framework wrapper renders, and they work on
|
|
4
|
+
// their own in plain HTML, with htm, or in any framework that can emit a custom
|
|
5
|
+
// element. The real text lives only as ciphertext until the element reveals it
|
|
6
|
+
// into a closed shadow root, which keeps it out of the light DOM / innerHTML.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.makeDashPlaceholder = exports.HolyLinkElement = exports.HolyTextElement = void 0;
|
|
9
|
+
exports.defineCloakElements = defineCloakElements;
|
|
10
|
+
const decrypt_js_1 = require("./decrypt.js");
|
|
11
|
+
const render_js_1 = require("./render.js");
|
|
12
|
+
Object.defineProperty(exports, "makeDashPlaceholder", { enumerable: true, get: function () { return render_js_1.makeDashPlaceholder; } });
|
|
13
|
+
// Importing the core must not throw in a non-DOM runtime (SSR, a build step, a
|
|
14
|
+
// test). HTMLElement is only a real base in the browser; elsewhere a stub keeps
|
|
15
|
+
// the class declarations evaluable. The elements are never constructed without
|
|
16
|
+
// customElements, so the stub is never used at runtime.
|
|
17
|
+
const ElementBase = typeof HTMLElement !== 'undefined'
|
|
18
|
+
? HTMLElement
|
|
19
|
+
: class {
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* <holy-text ciphertext="..." [text="..."] [ellipsis] [reveal-for-bots]>----</holy-text>
|
|
23
|
+
*
|
|
24
|
+
* Ships with a dash placeholder as its light-DOM text. On connect it resolves
|
|
25
|
+
* the real text and, unless kept (bot / decrypt failure), attaches a closed
|
|
26
|
+
* shadow root holding the plaintext. A shadow root suppresses the light dash
|
|
27
|
+
* text, so the host shows the real string without it ever being in innerHTML.
|
|
28
|
+
*/
|
|
29
|
+
class HolyTextElement extends ElementBase {
|
|
30
|
+
static get observedAttributes() {
|
|
31
|
+
return [
|
|
32
|
+
'ciphertext',
|
|
33
|
+
'data-ectext',
|
|
34
|
+
'text',
|
|
35
|
+
'data-text',
|
|
36
|
+
'ellipsis',
|
|
37
|
+
'reveal-for-bots',
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
shadow;
|
|
41
|
+
observer;
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
this.reveal();
|
|
44
|
+
// Framework hydration can replace a text child without changing an
|
|
45
|
+
// attribute. Observe only the light DOM, never the closed shadow root.
|
|
46
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
47
|
+
this.observer ??= new MutationObserver(() => this.reveal());
|
|
48
|
+
this.observer.observe(this, {
|
|
49
|
+
childList: true,
|
|
50
|
+
characterData: true,
|
|
51
|
+
subtree: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
disconnectedCallback() {
|
|
56
|
+
this.observer?.disconnect();
|
|
57
|
+
}
|
|
58
|
+
attributeChangedCallback() {
|
|
59
|
+
if (this.isConnected)
|
|
60
|
+
this.reveal();
|
|
61
|
+
}
|
|
62
|
+
get sourceText() {
|
|
63
|
+
return (this.getAttribute('text') ??
|
|
64
|
+
this.getAttribute('data-text') ??
|
|
65
|
+
this.textContent ??
|
|
66
|
+
'');
|
|
67
|
+
}
|
|
68
|
+
reveal() {
|
|
69
|
+
const text = this.sourceText;
|
|
70
|
+
const cipher = this.getAttribute('ciphertext') ??
|
|
71
|
+
this.getAttribute('data-ectext') ??
|
|
72
|
+
(0, render_js_1.cipherFor)(text) ??
|
|
73
|
+
undefined;
|
|
74
|
+
const res = (0, render_js_1.resolveHoly)(text, cipher, {
|
|
75
|
+
revealForBots: this.hasAttribute('reveal-for-bots'),
|
|
76
|
+
});
|
|
77
|
+
if (res.kind === 'keep') {
|
|
78
|
+
// Once a closed shadow root exists, the browser no longer displays the
|
|
79
|
+
// light DOM. Keep the placeholder visible after a failed re-decrypt.
|
|
80
|
+
if (this.shadow) {
|
|
81
|
+
this.shadow.replaceChildren(document.createTextNode((0, render_js_1.makeDashPlaceholder)(text)));
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!this.shadow)
|
|
86
|
+
this.shadow = this.attachShadow({ mode: 'closed' });
|
|
87
|
+
if (this.hasAttribute('ellipsis')) {
|
|
88
|
+
const style = document.createElement('style');
|
|
89
|
+
style.textContent = render_js_1.ELLIPSIS_SHADOW_CSS;
|
|
90
|
+
const span = document.createElement('span');
|
|
91
|
+
span.className = 'holy-ellipsis';
|
|
92
|
+
span.textContent = res.plaintext;
|
|
93
|
+
this.shadow.replaceChildren(style, span);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.shadow.replaceChildren(document.createTextNode(res.plaintext));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.HolyTextElement = HolyTextElement;
|
|
101
|
+
/**
|
|
102
|
+
* <holy-link href-cipher="..." [target="_blank"]>Label</holy-link>
|
|
103
|
+
*
|
|
104
|
+
* Renders an anchor whose href is "#" at rest; the real href is decrypted and
|
|
105
|
+
* applied only on pointer/focus interaction, and restored to "#" on leave, so
|
|
106
|
+
* the URL is never sitting in the shipped markup. Click decrypts and navigates.
|
|
107
|
+
*/
|
|
108
|
+
class HolyLinkElement extends ElementBase {
|
|
109
|
+
static get observedAttributes() {
|
|
110
|
+
return ['href-cipher', 'data-eclink', 'href', 'target', 'rel', 'download'];
|
|
111
|
+
}
|
|
112
|
+
shadow;
|
|
113
|
+
anchor;
|
|
114
|
+
connectedCallback() {
|
|
115
|
+
this.build();
|
|
116
|
+
}
|
|
117
|
+
attributeChangedCallback() {
|
|
118
|
+
if (this.isConnected)
|
|
119
|
+
this.build();
|
|
120
|
+
}
|
|
121
|
+
realHref() {
|
|
122
|
+
const cipher = this.getAttribute('href-cipher') ?? this.getAttribute('data-eclink');
|
|
123
|
+
if (!cipher)
|
|
124
|
+
return this.getAttribute('href') ?? '#';
|
|
125
|
+
return (0, decrypt_js_1.holyDecrypt)(cipher) || '#';
|
|
126
|
+
}
|
|
127
|
+
build() {
|
|
128
|
+
if (!this.shadow)
|
|
129
|
+
this.shadow = this.attachShadow({ mode: 'closed' });
|
|
130
|
+
if (!this.anchor) {
|
|
131
|
+
const a = document.createElement('a');
|
|
132
|
+
a.setAttribute('href', '#');
|
|
133
|
+
a.appendChild(document.createElement('slot'));
|
|
134
|
+
this.shadow.replaceChildren(a);
|
|
135
|
+
this.anchor = a;
|
|
136
|
+
const reveal = () => {
|
|
137
|
+
if (!(0, decrypt_js_1.isLikelyBot)())
|
|
138
|
+
a.setAttribute('href', this.realHref());
|
|
139
|
+
};
|
|
140
|
+
const hide = () => {
|
|
141
|
+
if (!this.matches(':focus-within'))
|
|
142
|
+
a.setAttribute('href', '#');
|
|
143
|
+
};
|
|
144
|
+
a.addEventListener('pointerenter', reveal);
|
|
145
|
+
a.addEventListener('pointerdown', reveal);
|
|
146
|
+
a.addEventListener('focus', reveal);
|
|
147
|
+
a.addEventListener('pointerleave', hide);
|
|
148
|
+
a.addEventListener('blur', () => a.setAttribute('href', '#'));
|
|
149
|
+
// Preserve the browser's native behavior for middle click,
|
|
150
|
+
// Ctrl/Meta/Shift click, download, target and keyboard activation.
|
|
151
|
+
// Do not call window.open or preventDefault for a valid href.
|
|
152
|
+
a.addEventListener('click', (event) => {
|
|
153
|
+
reveal();
|
|
154
|
+
if (a.getAttribute('href') === '#')
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
});
|
|
157
|
+
a.addEventListener('auxclick', reveal);
|
|
158
|
+
}
|
|
159
|
+
for (const attr of ['target', 'rel', 'download']) {
|
|
160
|
+
const value = this.getAttribute(attr);
|
|
161
|
+
if (value === null)
|
|
162
|
+
this.anchor.removeAttribute(attr);
|
|
163
|
+
else
|
|
164
|
+
this.anchor.setAttribute(attr, value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.HolyLinkElement = HolyLinkElement;
|
|
169
|
+
/**
|
|
170
|
+
* Register the cloak custom elements. Idempotent and safe to call more than
|
|
171
|
+
* once; a name already defined is left as-is.
|
|
172
|
+
*/
|
|
173
|
+
function defineCloakElements(tags) {
|
|
174
|
+
if (typeof customElements === 'undefined')
|
|
175
|
+
return;
|
|
176
|
+
const textTag = tags?.text ?? 'holy-text';
|
|
177
|
+
const linkTag = tags?.link ?? 'holy-link';
|
|
178
|
+
if (textTag === linkTag)
|
|
179
|
+
throw new Error('cloak: text and link tags must differ');
|
|
180
|
+
// The registry permits a given constructor under only one tag. An alias
|
|
181
|
+
// needs its own subclass, including when the default tag already exists.
|
|
182
|
+
if (!customElements.get(textTag))
|
|
183
|
+
customElements.define(textTag, textTag === 'holy-text'
|
|
184
|
+
? HolyTextElement
|
|
185
|
+
: class extends HolyTextElement {
|
|
186
|
+
});
|
|
187
|
+
if (!customElements.get(linkTag))
|
|
188
|
+
customElements.define(linkTag, linkTag === 'holy-link'
|
|
189
|
+
? HolyLinkElement
|
|
190
|
+
: class extends HolyLinkElement {
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// Auto-define with the default tag names when a DOM is present, so importing
|
|
194
|
+
// the core is enough to use <holy-text>/<holy-link> in plain HTML.
|
|
195
|
+
defineCloakElements();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { fromBase64, toBase64 } from './base64.js';
|
|
2
|
+
export { holyDecrypt, holyDecryptJson, isLikelyBot, loadDecryptionKey, setCloakRoot, setCloakKeyProvider, } from './decrypt.js';
|
|
3
|
+
export { cipherFor, ELLIPSIS_SHADOW_CSS, makeDashPlaceholder, resolveHoly, } from './render.js';
|
|
4
|
+
export type { HolyResolution, ResolveOptions } from './render.js';
|
|
5
|
+
export { getObfuscatedCiphertext, registerObfuscatedString, registerObfuscatedStrings, setCloakStringMapProvider, } from './strings.js';
|
|
6
|
+
export { defineCloakElements, HolyLinkElement, HolyTextElement, } from './elements.js';
|
|
7
|
+
export { linkElementProps, textElementProps } from './props.js';
|
|
8
|
+
export type { CloakLinkProps, CloakTextProps } from './props.js';
|
|
9
|
+
export { bindSpanLinks, refreshSpanCloak, revealSpanText, setupSpanCloak, } from './span.js';
|
|
10
|
+
export type { SpanNavigate } from './span.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @sysce/estrogen/cloak: framework-agnostic cloak core.
|
|
3
|
+
//
|
|
4
|
+
// Importing this registers <holy-text> and <holy-link>, so it is enough for
|
|
5
|
+
// plain HTML and htm. Framework wrappers live at @sysce/estrogen/cloak/<react |
|
|
6
|
+
// preact | vue | svelte | solid | astro> and the server/build helpers at
|
|
7
|
+
// @sysce/estrogen/cloak/server.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.setupSpanCloak = exports.revealSpanText = exports.refreshSpanCloak = exports.bindSpanLinks = exports.textElementProps = exports.linkElementProps = exports.HolyTextElement = exports.HolyLinkElement = exports.defineCloakElements = exports.setCloakStringMapProvider = exports.registerObfuscatedStrings = exports.registerObfuscatedString = exports.getObfuscatedCiphertext = exports.resolveHoly = exports.makeDashPlaceholder = exports.ELLIPSIS_SHADOW_CSS = exports.cipherFor = exports.setCloakKeyProvider = exports.setCloakRoot = exports.loadDecryptionKey = exports.isLikelyBot = exports.holyDecryptJson = exports.holyDecrypt = exports.toBase64 = exports.fromBase64 = void 0;
|
|
10
|
+
var base64_js_1 = require("./base64.js");
|
|
11
|
+
Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_js_1.fromBase64; } });
|
|
12
|
+
Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_js_1.toBase64; } });
|
|
13
|
+
var decrypt_js_1 = require("./decrypt.js");
|
|
14
|
+
Object.defineProperty(exports, "holyDecrypt", { enumerable: true, get: function () { return decrypt_js_1.holyDecrypt; } });
|
|
15
|
+
Object.defineProperty(exports, "holyDecryptJson", { enumerable: true, get: function () { return decrypt_js_1.holyDecryptJson; } });
|
|
16
|
+
Object.defineProperty(exports, "isLikelyBot", { enumerable: true, get: function () { return decrypt_js_1.isLikelyBot; } });
|
|
17
|
+
Object.defineProperty(exports, "loadDecryptionKey", { enumerable: true, get: function () { return decrypt_js_1.loadDecryptionKey; } });
|
|
18
|
+
Object.defineProperty(exports, "setCloakRoot", { enumerable: true, get: function () { return decrypt_js_1.setCloakRoot; } });
|
|
19
|
+
Object.defineProperty(exports, "setCloakKeyProvider", { enumerable: true, get: function () { return decrypt_js_1.setCloakKeyProvider; } });
|
|
20
|
+
var render_js_1 = require("./render.js");
|
|
21
|
+
Object.defineProperty(exports, "cipherFor", { enumerable: true, get: function () { return render_js_1.cipherFor; } });
|
|
22
|
+
Object.defineProperty(exports, "ELLIPSIS_SHADOW_CSS", { enumerable: true, get: function () { return render_js_1.ELLIPSIS_SHADOW_CSS; } });
|
|
23
|
+
Object.defineProperty(exports, "makeDashPlaceholder", { enumerable: true, get: function () { return render_js_1.makeDashPlaceholder; } });
|
|
24
|
+
Object.defineProperty(exports, "resolveHoly", { enumerable: true, get: function () { return render_js_1.resolveHoly; } });
|
|
25
|
+
var strings_js_1 = require("./strings.js");
|
|
26
|
+
Object.defineProperty(exports, "getObfuscatedCiphertext", { enumerable: true, get: function () { return strings_js_1.getObfuscatedCiphertext; } });
|
|
27
|
+
Object.defineProperty(exports, "registerObfuscatedString", { enumerable: true, get: function () { return strings_js_1.registerObfuscatedString; } });
|
|
28
|
+
Object.defineProperty(exports, "registerObfuscatedStrings", { enumerable: true, get: function () { return strings_js_1.registerObfuscatedStrings; } });
|
|
29
|
+
Object.defineProperty(exports, "setCloakStringMapProvider", { enumerable: true, get: function () { return strings_js_1.setCloakStringMapProvider; } });
|
|
30
|
+
var elements_js_1 = require("./elements.js");
|
|
31
|
+
Object.defineProperty(exports, "defineCloakElements", { enumerable: true, get: function () { return elements_js_1.defineCloakElements; } });
|
|
32
|
+
Object.defineProperty(exports, "HolyLinkElement", { enumerable: true, get: function () { return elements_js_1.HolyLinkElement; } });
|
|
33
|
+
Object.defineProperty(exports, "HolyTextElement", { enumerable: true, get: function () { return elements_js_1.HolyTextElement; } });
|
|
34
|
+
var props_js_1 = require("./props.js");
|
|
35
|
+
Object.defineProperty(exports, "linkElementProps", { enumerable: true, get: function () { return props_js_1.linkElementProps; } });
|
|
36
|
+
Object.defineProperty(exports, "textElementProps", { enumerable: true, get: function () { return props_js_1.textElementProps; } });
|
|
37
|
+
var span_js_1 = require("./span.js");
|
|
38
|
+
Object.defineProperty(exports, "bindSpanLinks", { enumerable: true, get: function () { return span_js_1.bindSpanLinks; } });
|
|
39
|
+
Object.defineProperty(exports, "refreshSpanCloak", { enumerable: true, get: function () { return span_js_1.refreshSpanCloak; } });
|
|
40
|
+
Object.defineProperty(exports, "revealSpanText", { enumerable: true, get: function () { return span_js_1.revealSpanText; } });
|
|
41
|
+
Object.defineProperty(exports, "setupSpanCloak", { enumerable: true, get: function () { return span_js_1.setupSpanCloak; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentChildren, type HTMLAttributes, type JSX } from 'preact';
|
|
2
|
+
import './elements.js';
|
|
3
|
+
import { type CloakLinkProps, type CloakTextProps } from './props.js';
|
|
4
|
+
export interface HolyTextProps extends CloakTextProps, Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
5
|
+
}
|
|
6
|
+
export interface HolyLinkProps extends CloakLinkProps, Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
7
|
+
children?: ComponentChildren;
|
|
8
|
+
}
|
|
9
|
+
export declare function HolyText({ text, ciphertext, ellipsis, revealForBots, ...attributes }: HolyTextProps): JSX.Element;
|
|
10
|
+
export declare function HolyLink({ href, hrefCipher, target, children, ...attributes }: HolyLinkProps): JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HolyText = HolyText;
|
|
4
|
+
exports.HolyLink = HolyLink;
|
|
5
|
+
const preact_1 = require("preact");
|
|
6
|
+
require("./elements.js");
|
|
7
|
+
const props_js_1 = require("./props.js");
|
|
8
|
+
function HolyText({ text, ciphertext, ellipsis, revealForBots, ...attributes }) {
|
|
9
|
+
const { attributes: cloak, placeholder } = (0, props_js_1.textElementProps)({
|
|
10
|
+
text,
|
|
11
|
+
ciphertext,
|
|
12
|
+
ellipsis,
|
|
13
|
+
revealForBots,
|
|
14
|
+
});
|
|
15
|
+
return (0, preact_1.h)('holy-text', { ...attributes, ...cloak }, placeholder);
|
|
16
|
+
}
|
|
17
|
+
function HolyLink({ href, hrefCipher, target, children, ...attributes }) {
|
|
18
|
+
return (0, preact_1.h)('holy-link', { ...attributes, ...(0, props_js_1.linkElementProps)({ href, hrefCipher, target }) }, children);
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface CloakTextProps {
|
|
2
|
+
text?: string;
|
|
3
|
+
ciphertext?: string;
|
|
4
|
+
ellipsis?: boolean;
|
|
5
|
+
revealForBots?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface CloakLinkProps {
|
|
8
|
+
href?: string;
|
|
9
|
+
hrefCipher?: string;
|
|
10
|
+
target?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Attributes and light DOM text shared by framework bindings. */
|
|
13
|
+
export declare function textElementProps(input: CloakTextProps): {
|
|
14
|
+
attributes: Record<string, string | undefined>;
|
|
15
|
+
placeholder: string;
|
|
16
|
+
};
|
|
17
|
+
/** A ciphertext replaces the plain href attribute in shipped markup. */
|
|
18
|
+
export declare function linkElementProps(input: CloakLinkProps): Record<string, string | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.textElementProps = textElementProps;
|
|
4
|
+
exports.linkElementProps = linkElementProps;
|
|
5
|
+
const render_js_1 = require("./render.js");
|
|
6
|
+
/** Attributes and light DOM text shared by framework bindings. */
|
|
7
|
+
function textElementProps(input) {
|
|
8
|
+
const text = input.text ?? '';
|
|
9
|
+
const ciphertext = (0, render_js_1.cipherFor)(text, input.ciphertext);
|
|
10
|
+
return {
|
|
11
|
+
attributes: {
|
|
12
|
+
ciphertext,
|
|
13
|
+
ellipsis: input.ellipsis ? '' : undefined,
|
|
14
|
+
'reveal-for-bots': input.revealForBots ? '' : undefined,
|
|
15
|
+
},
|
|
16
|
+
placeholder: ciphertext ? (0, render_js_1.makeDashPlaceholder)(text) : text,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** A ciphertext replaces the plain href attribute in shipped markup. */
|
|
20
|
+
function linkElementProps(input) {
|
|
21
|
+
const cipher = (0, render_js_1.cipherFor)(input.href ?? '', input.hrefCipher);
|
|
22
|
+
return {
|
|
23
|
+
'href-cipher': cipher,
|
|
24
|
+
href: cipher ? undefined : input.href,
|
|
25
|
+
target: input.target,
|
|
26
|
+
};
|
|
27
|
+
}
|