jj 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +29 -1
  2. package/SKILL.md +671 -0
  3. package/lib/bundle.cjs +2031 -0
  4. package/lib/bundle.cjs.map +1 -0
  5. package/lib/bundle.d.cts +1782 -0
  6. package/lib/bundle.d.ts +1782 -1
  7. package/lib/bundle.global.js +1953 -0
  8. package/lib/bundle.global.js.map +1 -0
  9. package/lib/bundle.js +232 -230
  10. package/lib/bundle.js.map +1 -7
  11. package/lib/bundle.min.cjs +2 -0
  12. package/lib/bundle.min.cjs.map +1 -0
  13. package/lib/bundle.min.d.cts +1782 -0
  14. package/lib/bundle.min.d.ts +1782 -1
  15. package/lib/bundle.min.global.js +2 -0
  16. package/lib/bundle.min.global.js.map +1 -0
  17. package/lib/bundle.min.js +2 -1
  18. package/lib/bundle.min.js.map +1 -0
  19. package/package.json +5 -5
  20. package/lib/JJD.d.ts +0 -87
  21. package/lib/JJD.js +0 -119
  22. package/lib/JJD.js.map +0 -1
  23. package/lib/JJDF.d.ts +0 -74
  24. package/lib/JJDF.js +0 -98
  25. package/lib/JJDF.js.map +0 -1
  26. package/lib/JJE.d.ts +0 -299
  27. package/lib/JJE.js +0 -401
  28. package/lib/JJE.js.map +0 -1
  29. package/lib/JJET.d.ts +0 -79
  30. package/lib/JJET.js +0 -114
  31. package/lib/JJET.js.map +0 -1
  32. package/lib/JJEx.d.ts +0 -63
  33. package/lib/JJEx.js +0 -83
  34. package/lib/JJEx.js.map +0 -1
  35. package/lib/JJHE.d.ts +0 -109
  36. package/lib/JJHE.js +0 -136
  37. package/lib/JJHE.js.map +0 -1
  38. package/lib/JJN-wrap.d.ts +0 -1
  39. package/lib/JJN-wrap.js +0 -46
  40. package/lib/JJN-wrap.js.map +0 -1
  41. package/lib/JJN.d.ts +0 -126
  42. package/lib/JJN.js +0 -166
  43. package/lib/JJN.js.map +0 -1
  44. package/lib/JJNx.d.ts +0 -126
  45. package/lib/JJNx.js +0 -157
  46. package/lib/JJNx.js.map +0 -1
  47. package/lib/JJSE.d.ts +0 -170
  48. package/lib/JJSE.js +0 -217
  49. package/lib/JJSE.js.map +0 -1
  50. package/lib/JJSR.d.ts +0 -71
  51. package/lib/JJSR.js +0 -90
  52. package/lib/JJSR.js.map +0 -1
  53. package/lib/JJT.d.ts +0 -92
  54. package/lib/JJT.js +0 -116
  55. package/lib/JJT.js.map +0 -1
  56. package/lib/case.d.ts +0 -60
  57. package/lib/case.js +0 -92
  58. package/lib/case.js.map +0 -1
  59. package/lib/components.d.ts +0 -147
  60. package/lib/components.js +0 -287
  61. package/lib/components.js.map +0 -1
  62. package/lib/helpers.d.ts +0 -159
  63. package/lib/helpers.js +0 -233
  64. package/lib/helpers.js.map +0 -1
  65. package/lib/index.d.ts +0 -33
  66. package/lib/index.js +0 -35
  67. package/lib/index.js.map +0 -1
  68. package/lib/internal.d.ts +0 -30
  69. package/lib/internal.js +0 -35
  70. package/lib/internal.js.map +0 -1
  71. package/lib/types.d.ts +0 -65
  72. package/lib/types.js +0 -2
  73. package/lib/types.js.map +0 -1
  74. package/lib/util.d.ts +0 -68
  75. package/lib/util.js +0 -90
  76. package/lib/util.js.map +0 -1
  77. package/llms.txt +0 -214
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,CAAC,CAAC,OAAe,EAAE,UAA0C,EAA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AC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAiB;IAC7C,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,GAAiB;IAC5C,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAiB;IAC9C,OAAO,MAAM,UAAU,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AAChD,CAAC"}
package/lib/index.d.ts DELETED
@@ -1,33 +0,0 @@
1
- export * from './types.js';
2
- export * from './util.js';
3
- export * from './case.js';
4
- export * from './JJET.js';
5
- export * from './JJN.js';
6
- import './JJN-wrap.js';
7
- export * from './JJT.js';
8
- export * from './JJE.js';
9
- export * from './JJHE.js';
10
- export * from './JJSE.js';
11
- export * from './JJD.js';
12
- export * from './JJDF.js';
13
- export * from './JJSR.js';
14
- export * from './helpers.js';
15
- export * from './components.js';
16
- import { JJD } from './JJD.js';
17
- /**
18
- * A wrapped document for convenience.
19
- * It can be used instead of document
20
- *
21
- * @example
22
- * ```ts
23
- * const el = doc.byId('my-element') // A JJHE instance
24
- * const body = doc.body // A JJHE instance
25
- * doc.append(JJHE.fromTag('script').setAttr('src', 'my-code.js'))
26
- * doc.head.append(JJHE.fromTag('link').setAttr({
27
- * rel: 'stylesheet',
28
- * href: 'code.css'
29
- * }))
30
- * ```
31
- */
32
- declare const doc: JJD<Document>;
33
- export default doc;
package/lib/index.js DELETED
@@ -1,35 +0,0 @@
1
- export * from './types.js';
2
- export * from './util.js';
3
- export * from './case.js';
4
- export * from './JJET.js';
5
- export * from './JJN.js';
6
- // Monkey patch the wrap() method which requires all the other JJ classes
7
- import './JJN-wrap.js';
8
- export * from './JJT.js';
9
- export * from './JJE.js';
10
- export * from './JJHE.js';
11
- export * from './JJSE.js';
12
- export * from './JJD.js';
13
- export * from './JJDF.js';
14
- export * from './JJSR.js';
15
- export * from './helpers.js';
16
- export * from './components.js';
17
- import { JJD } from './JJD.js';
18
- /**
19
- * A wrapped document for convenience.
20
- * It can be used instead of document
21
- *
22
- * @example
23
- * ```ts
24
- * const el = doc.byId('my-element') // A JJHE instance
25
- * const body = doc.body // A JJHE instance
26
- * doc.append(JJHE.fromTag('script').setAttr('src', 'my-code.js'))
27
- * doc.head.append(JJHE.fromTag('link').setAttr({
28
- * rel: 'stylesheet',
29
- * href: 'code.css'
30
- * }))
31
- * ```
32
- */
33
- const doc = JJD.from(document);
34
- export default doc;
35
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,yEAAyE;AACzE,OAAO,eAAe,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAC9B,eAAe,GAAG,CAAA"}
package/lib/internal.d.ts DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * Internal utilities for the JJ library.
3
- * These are not part of the public API.
4
- */
5
- /**
6
- * Creates a gzip-friendly error message by concatenating strings.
7
- * This avoids repeating common error message patterns that compress well.
8
- *
9
- * @remarks
10
- * Uses backtick strings to take advantage of gzip compression across the codebase.
11
- * Common patterns like `Expected 'x' to be ...` compress very efficiently.
12
- *
13
- * @internal
14
- * @param varName - The name of the variable
15
- * @param expected - Description of expected type
16
- * @param received - The actual value received
17
- * @returns Error message string
18
- */
19
- export declare function errMsg(varName: string, expected: string, received: unknown): string;
20
- /**
21
- * Creates a TypeError with a standardized error message.
22
- * Convenience wrapper around errMsg for type errors.
23
- *
24
- * @internal
25
- * @param varName - The name of the variable
26
- * @param expected - Description of expected type
27
- * @param received - The actual value received
28
- * @returns A TypeError ready to be thrown
29
- */
30
- export declare function typeErr(varName: string, expected: string, received: unknown): TypeError;
package/lib/internal.js DELETED
@@ -1,35 +0,0 @@
1
- /**
2
- * Internal utilities for the JJ library.
3
- * These are not part of the public API.
4
- */
5
- /**
6
- * Creates a gzip-friendly error message by concatenating strings.
7
- * This avoids repeating common error message patterns that compress well.
8
- *
9
- * @remarks
10
- * Uses backtick strings to take advantage of gzip compression across the codebase.
11
- * Common patterns like `Expected 'x' to be ...` compress very efficiently.
12
- *
13
- * @internal
14
- * @param varName - The name of the variable
15
- * @param expected - Description of expected type
16
- * @param received - The actual value received
17
- * @returns Error message string
18
- */
19
- export function errMsg(varName, expected, received) {
20
- return `Expected '${varName}' to be ${expected}. Got ${received} (${typeof received})`;
21
- }
22
- /**
23
- * Creates a TypeError with a standardized error message.
24
- * Convenience wrapper around errMsg for type errors.
25
- *
26
- * @internal
27
- * @param varName - The name of the variable
28
- * @param expected - Description of expected type
29
- * @param received - The actual value received
30
- * @returns A TypeError ready to be thrown
31
- */
32
- export function typeErr(varName, expected, received) {
33
- return new TypeError(errMsg(varName, expected, received));
34
- }
35
- //# sourceMappingURL=internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAiB;IACvE,OAAO,aAAa,OAAO,WAAW,QAAQ,SAAS,QAAQ,KAAK,OAAO,QAAQ,GAAG,CAAA;AAC1F,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAiB;IACxE,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;AAC7D,CAAC"}
package/lib/types.d.ts DELETED
@@ -1,65 +0,0 @@
1
- import type { JJD } from './JJD.js';
2
- import type { JJDF } from './JJDF.js';
3
- import type { JJE } from './JJE.js';
4
- import type { JJHE } from './JJHE.js';
5
- import type { JJN } from './JJN.js';
6
- import type { JJSE } from './JJSE.js';
7
- import type { JJSR } from './JJSR.js';
8
- import type { JJT } from './JJT.js';
9
- /**
10
- * Represents any value that can be wrapped by the library.
11
- * Can be a native Node, a string (which becomes a Text node), or an existing JJ wrapper.
12
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
13
- */
14
- export type Wrappable = string | Node | JJN;
15
- /**
16
- * Union type of all possible JJ wrapper classes.
17
- */
18
- export type Wrapped = JJN | JJT | JJE | JJHE | JJSE | JJD | JJDF | JJSR;
19
- /**
20
- * Union type of all native DOM nodes that correspond to JJ wrappers.
21
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
22
- */
23
- export type Unwrapped = Node | Text | Element | HTMLElement | SVGElement | Document | DocumentFragment | ShadowRoot;
24
- /**
25
- * Configuration for the component's template.
26
- * Can be an HTML string, a JJHE instance, a raw HTMLElement, or a
27
- * Promise / factory that yields one of those.
28
- *
29
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
30
- * @example
31
- * ```ts
32
- * const t1: tmplConf = '<div>Hello</div>'
33
- * const t2: tmplConf = fetchHtml('./template.html') // Lazy loading
34
- * const t3: tmplConf = () => fetchHtml('./template.html') // Lazy loading
35
- * const t4: tmplConf = new JJHE(document.createElement('div')) // JJHE instance
36
- * const t5: tmplConf = document.createElement('div') // Raw HTMLElement
37
- * const t6: tmplConf = await fetchHtml('./template.html') // Eager loading
38
- * ```
39
- */
40
- export type JJTemplateConfig = string | JJHE | HTMLElement | Promise<string | JJHE | HTMLElement> | (() => string | JJHE | HTMLElement | Promise<string | JJHE | HTMLElement>);
41
- /**
42
- * Configuration for the component's styles.
43
- * Can be a CSS string, a CSSStyleSheet, or a Promise / factory that yields one of those.
44
- *
45
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
46
- * @example
47
- * ```ts
48
- * const s1: JJStyleConfig = 'p { color: red; }' // simple string
49
- * const s2: JJStyleConfig = cssToSheet('p { color: red; }') // Parse string to CSSStyleSheet
50
- * const s3: JJStyleConfig = await fetchCss('./style.css') // Eager loading
51
- * const s4: JJStyleConfig = fetchCss('./style.css') // Lazy loading
52
- * const s5: JJStyleConfig = () => fetchCss('./style.css') // Lazy loading
53
- * ```
54
- */
55
- export type JJStyleConfig = string | CSSStyleSheet | Promise<string | CSSStyleSheet> | (() => string | CSSStyleSheet | Promise<string | CSSStyleSheet>);
56
- /**
57
- * Configuration for initializing a shadowRoot
58
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
59
- */
60
- export interface ShadowConfig {
61
- /** Optional HTML content to set in the shadow root */
62
- template?: string;
63
- /** Optional CSSStyleSheets to adopt in the shadow root */
64
- styles?: CSSStyleSheet[];
65
- }
package/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/lib/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/lib/util.d.ts DELETED
@@ -1,68 +0,0 @@
1
- /**
2
- * Returns the file extension
3
- *
4
- * @remarks
5
- * This convenience function is primarily used to guess the 'as' attribute of
6
- * a link preload/prefetch behind the scene.
7
- *
8
- * @example
9
- * ```ts
10
- * fileExt('file.txt') // => 'txt'
11
- * fileExt('https://www.alexewerlof.com/path/to/file.js') // => 'js'
12
- * ```
13
- *
14
- * @param path - absolute, relative, or URL path to a file
15
- * @returns the extension name in lowercase and without any dot prefix
16
- * @throws {TypeError} If path is not a string.
17
- */
18
- export declare function fileExt(path: string): string;
19
- /**
20
- * Returns a promise that resolves before the next repaint.
21
- *
22
- * @remarks
23
- * Used to give the UI a moment to update.
24
- *
25
- * @example
26
- * ```ts
27
- * await nextAnimationFrame()
28
- * ```
29
- *
30
- * @returns A promise that resolves with the timestamp.
31
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame | requestAnimationFrame}
32
- */
33
- export declare function nextAnimationFrame(): Promise<number>;
34
- /**
35
- * Returns a promise that resolves after the specified delay.
36
- *
37
- * @remarks
38
- * Uses `setTimeout` to delay execution. When used with 0ms, it defers
39
- * execution to the next macro-task, allowing the event loop to cycle.
40
- *
41
- * @example
42
- * ```ts
43
- * await sleep(100)
44
- * await sleep() // equivalent to setTimeout(..., 0)
45
- * ```
46
- *
47
- * @param ms - The delay in milliseconds. Defaults to 0.
48
- * @returns A promise that resolves after the delay.
49
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout | setTimeout}
50
- */
51
- export declare function sleep(ms?: number): Promise<void>;
52
- /**
53
- * Converts a CSS string to a CSSStyleSheet.
54
- *
55
- * @remarks
56
- * Suitable for attaching to ShadowRoot via `adoptedStyleSheets`.
57
- *
58
- * @example
59
- * ```ts
60
- * const sheet = await cssToStyle('p { color: red; }')
61
- * shadowRoot.adoptedStyleSheets = [sheet]
62
- * ```
63
- *
64
- * @param css - The CSS string.
65
- * @returns A promise resolving to the created CSSStyleSheet.
66
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace | CSSStyleSheet.replace}
67
- */
68
- export declare function cssToStyle(css: string): Promise<CSSStyleSheet>;
package/lib/util.js DELETED
@@ -1,90 +0,0 @@
1
- import { isStr } from 'jty';
2
- /**
3
- * Returns the file extension
4
- *
5
- * @remarks
6
- * This convenience function is primarily used to guess the 'as' attribute of
7
- * a link preload/prefetch behind the scene.
8
- *
9
- * @example
10
- * ```ts
11
- * fileExt('file.txt') // => 'txt'
12
- * fileExt('https://www.alexewerlof.com/path/to/file.js') // => 'js'
13
- * ```
14
- *
15
- * @param path - absolute, relative, or URL path to a file
16
- * @returns the extension name in lowercase and without any dot prefix
17
- * @throws {TypeError} If path is not a string.
18
- */
19
- export function fileExt(path) {
20
- if (!isStr(path)) {
21
- throw new TypeError(`Expected a string file path. Got ${path} (${typeof path})`);
22
- }
23
- const lastDotIndex = path.lastIndexOf('.');
24
- if (lastDotIndex === -1) {
25
- return '';
26
- }
27
- const ext = path.slice(lastDotIndex + 1);
28
- if (ext.indexOf('/') !== -1) {
29
- return '';
30
- }
31
- return ext.toLowerCase().trim();
32
- }
33
- /**
34
- * Returns a promise that resolves before the next repaint.
35
- *
36
- * @remarks
37
- * Used to give the UI a moment to update.
38
- *
39
- * @example
40
- * ```ts
41
- * await nextAnimationFrame()
42
- * ```
43
- *
44
- * @returns A promise that resolves with the timestamp.
45
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame | requestAnimationFrame}
46
- */
47
- export function nextAnimationFrame() {
48
- return new Promise((resolve) => requestAnimationFrame(resolve));
49
- }
50
- /**
51
- * Returns a promise that resolves after the specified delay.
52
- *
53
- * @remarks
54
- * Uses `setTimeout` to delay execution. When used with 0ms, it defers
55
- * execution to the next macro-task, allowing the event loop to cycle.
56
- *
57
- * @example
58
- * ```ts
59
- * await sleep(100)
60
- * await sleep() // equivalent to setTimeout(..., 0)
61
- * ```
62
- *
63
- * @param ms - The delay in milliseconds. Defaults to 0.
64
- * @returns A promise that resolves after the delay.
65
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout | setTimeout}
66
- */
67
- export function sleep(ms = 0) {
68
- return new Promise((resolve) => setTimeout(resolve, ms));
69
- }
70
- /**
71
- * Converts a CSS string to a CSSStyleSheet.
72
- *
73
- * @remarks
74
- * Suitable for attaching to ShadowRoot via `adoptedStyleSheets`.
75
- *
76
- * @example
77
- * ```ts
78
- * const sheet = await cssToStyle('p { color: red; }')
79
- * shadowRoot.adoptedStyleSheets = [sheet]
80
- * ```
81
- *
82
- * @param css - The CSS string.
83
- * @returns A promise resolving to the created CSSStyleSheet.
84
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace | CSSStyleSheet.replace}
85
- */
86
- export async function cssToStyle(css) {
87
- const sheet = new CSSStyleSheet();
88
- return await sheet.replace(css);
89
- }
90
- //# sourceMappingURL=util.js.map
package/lib/util.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IAChC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,oCAAoC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,CAAA;IACpF,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC1C,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAA;IACb,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAA;IACxC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAA;IACb,CAAC;IACD,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;AACnC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAA;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,CAAC;IAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW;IACxC,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAA;IACjC,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACnC,CAAC"}
package/llms.txt DELETED
@@ -1,214 +0,0 @@
1
- # JJ: The DOM Library for AI-Assisted Development
2
-
3
- ## What is JJ?
4
-
5
- JJ is a minimal, imperative DOM manipulation library designed for modern web development. It provides small wrapper classes around DOM interfaces with a fluent API for chaining operations. JJ is zero-dependency, TypeScript-first, and optimized for AI-assisted code generation.
6
-
7
- ## Core Principles
8
-
9
- 1. **Imperative by Design**: Direct DOM manipulation without virtual DOM overhead.
10
- 2. **Type-Safe**: Full TypeScript support with precise generic types for one-shot LLM correctness.
11
- 3. **Chainable**: All public methods support fluent chaining.
12
- 4. **Zero Build**: Works directly in browsers via ESM imports or bundled script tags.
13
- 5. **Self-Correcting Errors**: Error messages suggest the correct approach.
14
-
15
- ## Main Classes
16
-
17
- - **JJD**: Wraps `Document`. Entry point for querying and creating elements.
18
- - **JJN**: Wraps `Node`. Base for other wrappers.
19
- - **JJE**: Wraps `Element`. Generic element wrapper.
20
- - **JJHE**: Wraps `HTMLElement`. Extends JJE with HTML-specific methods.
21
- - **JJT**: Wraps `Text`. Text node operations.
22
- - **JJSR**: Wraps `ShadowRoot`. Shadow DOM operations.
23
- - **JJDF**: Wraps `DocumentFragment`. Fragment operations.
24
- - **JJSE**: Wraps `StyleSheet`. Style operations.
25
-
26
- ## Quick Start
27
-
28
- ```typescript
29
- import { JJD } from 'jj';
30
-
31
- // Query an element
32
- const btn = JJD.from(document).query('button#submit');
33
-
34
- // Set attributes and classes
35
- btn.attr('disabled', 'true').addClass('highlight');
36
-
37
- // Listen to events
38
- btn.on('click', () => console.log('Clicked!'));
39
-
40
- // Create and append elements
41
- const div = JJD.from(document).create('div').setText('Hello, World!');
42
- btn.parentNode?.appendChild(div.ref);
43
- ```
44
-
45
- ## Patterns and Examples
46
-
47
- ### Creating Elements
48
-
49
- ```typescript
50
- const el = JJD.from(document).create('div').addClass('container');
51
- ```
52
-
53
- ### Querying Elements
54
-
55
- ```typescript
56
- const btn = JJD.from(document).query('.btn');
57
- const buttons = JJD.from(document).queryAll('button');
58
- ```
59
-
60
- ### Manipulating Classes
61
-
62
- ```typescript
63
- el.addClass('active').removeClass('disabled').toggleClass('visible');
64
- ```
65
-
66
- ### Setting Attributes and Properties
67
-
68
- ```typescript
69
- el.attr('data-id', '42').prop('disabled', false);
70
- ```
71
-
72
- ### Listening to Events
73
-
74
- ```typescript
75
- el.on('click', (e) => { /* handle click */ });
76
- el.off('click');
77
- ```
78
-
79
- ### Styling
80
-
81
- ```typescript
82
- el.style('background-color', 'blue').style('padding', '10px');
83
- ```
84
-
85
- ### Accessing the Underlying Node
86
-
87
- Every JJ wrapper exposes `.ref` to access the underlying DOM node:
88
-
89
- ```typescript
90
- const nativeElement = el.ref; // HTMLElement
91
- ```
92
-
93
- ## For LLMs: Translation Patterns
94
-
95
- ### React to JJ
96
-
97
- **React**: State-driven component re-renders on state change.
98
- ```tsx
99
- const [count, setCount] = useState(0);
100
- return <button onClick={() => setCount(count + 1)}>{count}</button>;
101
- ```
102
-
103
- **JJ**: Direct DOM mutation and event binding.
104
- ```typescript
105
- let count = 0;
106
- const btn = JJD.from(document).create('button').setText('0');
107
- btn.on('click', () => {
108
- count++;
109
- btn.setText(String(count));
110
- });
111
- ```
112
-
113
- ### jQuery to JJ
114
-
115
- **jQuery**: Chainable DOM manipulation with `$()` selector.
116
- ```javascript
117
- $('.box').addClass('active').css('color', 'red');
118
- ```
119
-
120
- **JJ**: Similar chainable API with type safety.
121
- ```typescript
122
- JJD.from(document).query('.box').addClass('active').style('color', 'red');
123
- ```
124
-
125
- ### Vue to JJ
126
-
127
- **Vue**: Template-driven, two-way binding.
128
- ```vue
129
- <div>
130
- <input v-model="message" />
131
- <p>{{ message }}</p>
132
- </div>
133
- ```
134
-
135
- **JJ**: Imperative setup with manual event binding.
136
- ```typescript
137
- const input = JJD.from(document).create('input');
138
- const p = JJD.from(document).create('p');
139
- input.on('input', (e) => {
140
- p.setText((e.target as HTMLInputElement).value);
141
- });
142
- ```
143
-
144
- ### Svelte to JJ
145
-
146
- **Svelte**: Reactive variables and automatic re-renders.
147
- ```svelte
148
- <script>
149
- let count = 0;
150
- </script>
151
- <button on:click={() => count++}>{count}</button>
152
- ```
153
-
154
- **JJ**: Manual DOM updates on events.
155
- ```typescript
156
- let count = 0;
157
- const btn = JJD.from(document).create('button').setText('0');
158
- btn.on('click', () => {
159
- count++;
160
- btn.setText(String(count));
161
- });
162
- ```
163
-
164
- ## TypeScript Type Safety
165
-
166
- JJ leverages TypeScript generics to ensure type safety. For example:
167
-
168
- ```typescript
169
- const input = JJD.from(document).fromTag('input');
170
- // input is JJHE<HTMLInputElement>, so input.ref.value is known to exist
171
-
172
- const div = JJD.from(document).fromTag('div');
173
- // div is JJHE<HTMLDivElement>, so input.ref.value would be a type error
174
- ```
175
-
176
- This prevents LLM hallucinations about non-existent properties.
177
-
178
- ## Common Gotchas
179
-
180
- 1. **Accessing the Native Node**: Always use `.ref` to access the underlying DOM node for operations not exposed by JJ.
181
- 2. **Event Listeners**: Use `.on()` and `.off()` for proper cleanup.
182
- 3. **Fragments**: Use JJDF for batch operations before appending.
183
- 4. **Error Messages**: Read them carefully—they suggest the correct approach.
184
-
185
- ## Testing
186
-
187
- JJ uses Node's built-in test runner with `tsx`:
188
-
189
- ```bash
190
- npm test
191
- ```
192
-
193
- Tests are colocated with source files as `*.test.ts`.
194
-
195
- ## Building
196
-
197
- ```bash
198
- npm run build
199
- ```
200
-
201
- This runs TypeScript compilation, creates an ESM bundle and minified variant, and generates documentation.
202
-
203
- ## Resources
204
-
205
- - **GitHub**: https://github.com/alexewerlof/jj
206
- - **Documentation**: https://jj.rocks/doc/
207
- - **Examples**: https://jj.rocks/examples/
208
-
209
- ## For Best Results with LLMs
210
-
211
- 1. When asking an LLM to help with JJ code, provide a snippet of the desired DOM structure.
212
- 2. Reference the translation patterns above when converting from React, Vue, Svelte, or jQuery.
213
- 3. Ask the LLM to use `.ref` when accessing native properties not exposed by JJ.
214
- 4. Expect type errors to be self-documenting—they guide toward the correct API.