@orago/dodo 0.0.1

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 (78) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintrc.cjs +23 -0
  3. package/.gitattributes +2 -0
  4. package/dist/_virtual/_rolldown/runtime.cjs +1 -0
  5. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  6. package/dist/dodo-events.cjs +2 -0
  7. package/dist/dodo-events.cjs.map +1 -0
  8. package/dist/dodo-events.d.ts +44 -0
  9. package/dist/dodo-events.mjs +2 -0
  10. package/dist/dodo-events.mjs.map +1 -0
  11. package/dist/dodo.cjs +2 -0
  12. package/dist/dodo.cjs.map +1 -0
  13. package/dist/dodo.d.ts +304 -0
  14. package/dist/dodo.mjs +2 -0
  15. package/dist/dodo.mjs.map +1 -0
  16. package/dist/index.cjs +1 -0
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.mjs +1 -0
  19. package/dist/plugins/index.cjs +1 -0
  20. package/dist/plugins/index.d.ts +2 -0
  21. package/dist/plugins/index.mjs +1 -0
  22. package/dist/plugins/plugin-tracking.cjs +2 -0
  23. package/dist/plugins/plugin-tracking.cjs.map +1 -0
  24. package/dist/plugins/plugin-tracking.d.ts +40 -0
  25. package/dist/plugins/plugin-tracking.mjs +2 -0
  26. package/dist/plugins/plugin-tracking.mjs.map +1 -0
  27. package/dist/server/copydir.cjs +2 -0
  28. package/dist/server/copydir.cjs.map +1 -0
  29. package/dist/server/copydir.d.ts +12 -0
  30. package/dist/server/copydir.mjs +2 -0
  31. package/dist/server/copydir.mjs.map +1 -0
  32. package/dist/server/index.cjs +1 -0
  33. package/dist/server/index.d.ts +3 -0
  34. package/dist/server/index.mjs +1 -0
  35. package/dist/server/util.cjs +2 -0
  36. package/dist/server/util.cjs.map +1 -0
  37. package/dist/server/util.d.ts +31 -0
  38. package/dist/server/util.mjs +2 -0
  39. package/dist/server/util.mjs.map +1 -0
  40. package/dist/util/class.util.cjs +2 -0
  41. package/dist/util/class.util.cjs.map +1 -0
  42. package/dist/util/class.util.mjs +2 -0
  43. package/dist/util/class.util.mjs.map +1 -0
  44. package/dist/util/plugins-support.cjs +2 -0
  45. package/dist/util/plugins-support.cjs.map +1 -0
  46. package/dist/util/plugins-support.d.ts +19 -0
  47. package/dist/util/plugins-support.mjs +2 -0
  48. package/dist/util/plugins-support.mjs.map +1 -0
  49. package/dist/util/submap.cjs +2 -0
  50. package/dist/util/submap.cjs.map +1 -0
  51. package/dist/util/submap.d.ts +14 -0
  52. package/dist/util/submap.mjs +2 -0
  53. package/dist/util/submap.mjs.map +1 -0
  54. package/dist/util/utilities.cjs +2 -0
  55. package/dist/util/utilities.cjs.map +1 -0
  56. package/dist/util/utilities.d.ts +14 -0
  57. package/dist/util/utilities.mjs +2 -0
  58. package/dist/util/utilities.mjs.map +1 -0
  59. package/package.json +61 -0
  60. package/pnpm-workspace.yaml +4 -0
  61. package/readme.md +0 -0
  62. package/src/dodo-events.ts +245 -0
  63. package/src/dodo.ts +384 -0
  64. package/src/index.ts +2 -0
  65. package/src/plugins/index.ts +5 -0
  66. package/src/plugins/plugin-schema.ts +58 -0
  67. package/src/plugins/plugin-style.ts +11 -0
  68. package/src/plugins/plugin-tracking.ts +227 -0
  69. package/src/server/copydir.ts +119 -0
  70. package/src/server/index.ts +7 -0
  71. package/src/server/util.ts +82 -0
  72. package/src/util/class.util.ts +42 -0
  73. package/src/util/jsx-runtime.ts +53 -0
  74. package/src/util/plugins-support.ts +59 -0
  75. package/src/util/submap.ts +60 -0
  76. package/src/util/utilities.ts +51 -0
  77. package/tsconfig.json +31 -0
  78. package/tsdown.config.ts +22 -0
@@ -0,0 +1,245 @@
1
+ import { Emitter } from "@orago/lib";
2
+ import { SubMap } from "./util/submap.js";
3
+ import { Dodo } from "./dodo.js";
4
+ import { Util as KiwiUtil } from "@orago/kiwi";
5
+ const VOID_EVENT: () => void = () => {};
6
+
7
+ export const ReservedEvents = {
8
+ // "dom-append": VOID_EVENT,
9
+ // "dom-remove": VOID_EVENT,
10
+ connected: VOID_EVENT,
11
+ disconnected: VOID_EVENT,
12
+ } satisfies Record<string, () => void>;
13
+
14
+ export type DodoEventsT = typeof ReservedEvents;
15
+ export type DodoEventKeys =
16
+ | (keyof HTMLElementEventMap | keyof DodoEventsT)
17
+ | (string & {});
18
+
19
+ class DodoEventCollection {
20
+ private static reserved_events: (keyof DodoEventsT | (string & {}))[] = [
21
+ ...Object.keys(ReservedEvents),
22
+ // "dom-append",
23
+ // "dom-remove",
24
+ ];
25
+
26
+ private static isReserved(event: DodoEventKeys) {
27
+ return this.reserved_events.includes(event);
28
+ }
29
+
30
+ // private static isReserved(event: string): event is typeof DodoEventCollection["reserved_events"][number] {
31
+ // return this.reserved_events.includes(event as any);
32
+ // }
33
+ public static on(
34
+ COLLECTION: DodoEventCollection,
35
+ event: DodoEventKeys,
36
+ callback: Function,
37
+ ) {
38
+ if (this.isReserved(event)) {
39
+ // if (event == "dom-append" || event == "dom-remove") {
40
+ // }
41
+ COLLECTION.events.on(event, callback);
42
+ } else {
43
+ if (event == "keypress" || event == "keydown" || event == "keyup") {
44
+ KiwiUtil.setAttributes(
45
+ { tabIndex: 0 },
46
+ (key, value) => COLLECTION.element.setAttribute(key, value),
47
+ (key) => COLLECTION.element.removeAttribute(key),
48
+ );
49
+ }
50
+ COLLECTION.listeners.add(event, callback);
51
+ COLLECTION.element.addEventListener(event, callback as any);
52
+ }
53
+ }
54
+
55
+ public static off(
56
+ COLLECTION: DodoEventCollection,
57
+ event: DodoEventKeys,
58
+ callback?: Function,
59
+ ) {
60
+ if (this.isReserved(event)) {
61
+ COLLECTION.events.off(event, callback);
62
+ } else {
63
+ const group = COLLECTION.listeners;
64
+
65
+ if (callback == undefined) {
66
+ for (const callback of group.get(event)) {
67
+ COLLECTION.element.removeEventListener(event, callback);
68
+ }
69
+ group.removeAll(event);
70
+ } else {
71
+ group.remove(event, callback);
72
+ COLLECTION.element.removeEventListener(event, callback as any);
73
+ }
74
+ }
75
+ }
76
+
77
+ public static once(
78
+ COLLECTION: DodoEventCollection,
79
+ event: DodoEventKeys,
80
+ callback: Function,
81
+ ): void {
82
+ const once_callback: any = (...args: any[]) => {
83
+ this.off(COLLECTION, event, once_callback);
84
+ callback(...args);
85
+ return void 0;
86
+ };
87
+
88
+ this.on(COLLECTION, event, (...args: any[]) => once_callback(...args));
89
+ }
90
+
91
+ public static emit(
92
+ COLLECTION: DodoEventCollection,
93
+ event: DodoEventKeys,
94
+ ...args: any[]
95
+ ): void {
96
+ if (this.isReserved(event)) {
97
+ COLLECTION.events.emit(event, ...args);
98
+ } else {
99
+ COLLECTION.listeners.add(event, ...args);
100
+ COLLECTION.element.dispatchEvent(
101
+ new CustomEvent(event, { detail: args }),
102
+ );
103
+ }
104
+ }
105
+
106
+ public static clear(COLLECTION: DodoEventCollection) {
107
+ for (const event of COLLECTION.listeners.all.keys()) {
108
+ // Delete off whole event instead of each individual callback
109
+ this.off(COLLECTION, event as any);
110
+ }
111
+
112
+ COLLECTION.events.all.clear();
113
+ }
114
+ readonly listeners: SubMap<Record<string, any>, true> = new SubMap();
115
+ events: Emitter<DodoEventsT> = new Emitter();
116
+
117
+ constructor(public readonly element: HTMLElement) {}
118
+ }
119
+ export class DodoEvents<T extends Dodo> {
120
+ private static c_events: WeakMap<HTMLElement, DodoEventCollection> =
121
+ new WeakMap();
122
+
123
+ public static getAlways(element: HTMLElement): DodoEventCollection {
124
+ const found = this.c_events.get(element);
125
+
126
+ if (found != undefined) {
127
+ return found;
128
+ }
129
+
130
+ const created = new DodoEventCollection(element);
131
+ this.c_events.set(element, created);
132
+ return created;
133
+ }
134
+
135
+ public static on(
136
+ element: HTMLElement,
137
+ event: DodoEventKeys,
138
+ callback: Function,
139
+ ): void {
140
+ DodoEventCollection.on(this.getAlways(element), event, callback);
141
+ }
142
+
143
+ public static off(
144
+ element: HTMLElement,
145
+ event: DodoEventKeys,
146
+ callback?: Function,
147
+ ) {
148
+ DodoEventCollection.off(this.getAlways(element), event, callback);
149
+ }
150
+
151
+ public static once(
152
+ element: HTMLElement,
153
+ event: DodoEventKeys,
154
+ callback: Function,
155
+ ): void {
156
+ DodoEventCollection.once(this.getAlways(element), event, callback);
157
+ }
158
+ public static emitTo(
159
+ element: HTMLElement,
160
+ event: DodoEventKeys,
161
+ ...args: any[]
162
+ ): void {
163
+ const COLLECTION = this.c_events.get(element);
164
+ if (COLLECTION == undefined) return;
165
+
166
+ DodoEventCollection.emit(COLLECTION, event, ...args);
167
+ }
168
+
169
+ public static clear(element: HTMLElement) {
170
+ const COLLECTION = this.c_events.get(element);
171
+ if (COLLECTION == undefined) return;
172
+
173
+ DodoEventCollection.clear(COLLECTION);
174
+ this.c_events.delete(COLLECTION.element);
175
+ }
176
+
177
+ constructor(public instance: T) {}
178
+
179
+ element(): HTMLElement {
180
+ return this.instance.element;
181
+ }
182
+
183
+ public nest(
184
+ run:
185
+ | ((arg0: this) => void)
186
+ | [event: DodoEventKeys, callback: Function][]
187
+ | {
188
+ [K in DodoEventKeys as `on:${K}` | K]?: (
189
+ ...ev: any[]
190
+ ) => any;
191
+ },
192
+ ): this["instance"] {
193
+ if (typeof run == "function") {
194
+ run(this);
195
+ } else if (Array.isArray(run)) {
196
+ for (const [event, callback] of run) {
197
+ this.on(event, callback);
198
+ }
199
+ } else if (typeof run == "object") {
200
+ const on_pre: string = "on:";
201
+ for (const key in run) {
202
+ const p = run[key as keyof typeof run];
203
+ if (key.startsWith(on_pre) && typeof p === "function") {
204
+ const event = key.slice(on_pre.length).toLowerCase();
205
+ this.on(event, p as any);
206
+ } else {
207
+ this.on(key, p as any);
208
+ }
209
+ }
210
+ }
211
+
212
+ return this.instance;
213
+ }
214
+
215
+ public call(...args: Parameters<DodoEvents<this["instance"]>["nest"]>) {
216
+ return this.nest(...args);
217
+ }
218
+
219
+ public on(event: DodoEventKeys, callback: Function) {
220
+ const plugin_events = Dodo.plugins.event_callbacks[event];
221
+
222
+ if (plugin_events != undefined) {
223
+ for (const cb of plugin_events) {
224
+ cb(this.instance);
225
+ }
226
+ }
227
+
228
+ DodoEvents.on(this.element(), event, callback);
229
+ return this;
230
+ }
231
+
232
+ public off(event: DodoEventKeys, callback?: Function) {
233
+ DodoEvents.off(this.element(), event, callback);
234
+ return this;
235
+ }
236
+
237
+ public once(event: DodoEventKeys, callback: Function) {
238
+ DodoEvents.once(this.element(), event, callback);
239
+ return this;
240
+ }
241
+
242
+ public clear() {
243
+ DodoEvents.clear(this.element());
244
+ }
245
+ }
package/src/dodo.ts ADDED
@@ -0,0 +1,384 @@
1
+ import {
2
+ type KiwiItem,
3
+ type KiwiUpdate,
4
+ Base_Kiwi,
5
+ Base_KiwiClasses,
6
+ Base_KiwiStyles,
7
+ ElementName,
8
+ Util as KiwiUtil,
9
+ StyleDeclaration,
10
+ StyleDeclarationPlus,
11
+ } from "@orago/kiwi";
12
+ import { Emitter } from "@orago/lib";
13
+ import { DodoEvents } from "./dodo-events.js";
14
+ import { makeCallableInstance } from "./util/class.util.js";
15
+ import { DodoGlobalPlugins } from "./util/plugins-support.js";
16
+
17
+ type Extractable = Dodo | KiwiItem | { element: HTMLElement } | Node;
18
+ type AppendableItem = Extractable | string | number;
19
+ type Appendable = AppendableItem | boolean | null | undefined;
20
+ export type ChildList = (Appendable | Appendable[])[];
21
+
22
+ export type ResolveElement<Input extends ElementName | Extractable> =
23
+ Input extends keyof HTMLElementTagNameMap
24
+ ? HTMLElementTagNameMap[Input]
25
+ : Input extends HTMLElement
26
+ ? Input
27
+ : Input extends Dodo
28
+ ? Input["element"]
29
+ : HTMLElement;
30
+
31
+ class DodoStyles<N extends Dodo> extends Base_KiwiStyles {
32
+ constructor(public instance: N) {
33
+ super();
34
+ }
35
+
36
+ public nest(run: (arg0: this) => void): this["instance"] {
37
+ run(this);
38
+ return this.instance;
39
+ }
40
+
41
+ public call(styles: StyleDeclarationPlus): N;
42
+ public call(value: (arg0: this) => void): N;
43
+ public call(value: StyleDeclarationPlus | ((arg0: this) => void) = {}): N {
44
+ if (typeof value == "object") {
45
+ return this.update(value).instance;
46
+ } else if (typeof value == "function") {
47
+ return this.nest(value);
48
+ }
49
+
50
+ return this.instance;
51
+ }
52
+
53
+ public get(): StyleDeclaration {
54
+ const style = this.instance.element.style;
55
+
56
+ return Object.fromEntries(
57
+ Array.from(style).map((name) => [
58
+ name,
59
+ style.getPropertyValue(name),
60
+ ]),
61
+ );
62
+ }
63
+
64
+ update(styles: StyleDeclarationPlus): this {
65
+ KiwiUtil.setStyles(styles, (key, value) => {
66
+ this.instance.element.style.setProperty(
67
+ KiwiUtil.formatAttributeName("kebab", key),
68
+ value,
69
+ );
70
+ });
71
+
72
+ return this;
73
+ }
74
+
75
+ remove(...styles: string[]): this {
76
+ for (const key of styles) {
77
+ this.instance.element.style.removeProperty(
78
+ KiwiUtil.formatAttributeName("kebab", key),
79
+ );
80
+ }
81
+
82
+ return this;
83
+ }
84
+ }
85
+
86
+ class DodoClasses<N extends Dodo> extends Base_KiwiClasses {
87
+ constructor(public instance: N) {
88
+ super();
89
+ }
90
+
91
+ public nest(run: (arg0: this) => void): this["instance"] {
92
+ run(this);
93
+ return this.instance;
94
+ }
95
+
96
+ public call(...classes: string[]): N;
97
+ public call(nest: (arg0: this) => void): N;
98
+ public call(...value: string[] | [(arg0: this) => void]): N {
99
+ let [first] = value;
100
+
101
+ if (typeof first == "string") {
102
+ return this.set(...(value as string[])).instance;
103
+ } else if (typeof first == "function") {
104
+ return this.nest(first);
105
+ }
106
+
107
+ return this.instance;
108
+ }
109
+
110
+ public get(): string[] {
111
+ return Array.from(this.instance.element.classList);
112
+ }
113
+
114
+ has(...classes: string[]): boolean {
115
+ return classes.every((classname) =>
116
+ this.instance.element.classList.contains(classname),
117
+ );
118
+ }
119
+
120
+ add(...classes: string[]): this {
121
+ this.instance.element.classList.add(...KiwiUtil.formatClasses(classes));
122
+ return this;
123
+ }
124
+
125
+ remove(...classes: string[]): this {
126
+ this.instance.element.classList.remove(
127
+ ...KiwiUtil.formatClasses(classes),
128
+ );
129
+
130
+ return this;
131
+ }
132
+
133
+ set(...classes: string[]): this {
134
+ this.instance.element.className =
135
+ KiwiUtil.formatClasses(classes).join(" ");
136
+ return this;
137
+ }
138
+
139
+ toggle(classes: string | string[], status: boolean): this {
140
+ const list = Array.isArray(classes) ? classes : [classes];
141
+ if (status) {
142
+ this.add(...list);
143
+ } else {
144
+ this.remove(...list);
145
+ }
146
+ return this;
147
+ }
148
+ }
149
+
150
+ class DodoUtil {
151
+ public static fromDataItem(
152
+ item: Omit<KiwiItem, "children"> & { children: ChildList },
153
+ ) {
154
+ const instance = new Dodo(item.tag).update(item.update);
155
+ instance.append(...DodoUtil.flattenElements(item.children));
156
+ return instance;
157
+ }
158
+
159
+ public static extractElement(a: Extractable): HTMLElement {
160
+ if ("element" in a) {
161
+ return a.element;
162
+ } else if (a instanceof Dodo) {
163
+ return a.element;
164
+ } else if ("tag" in a && "update" in a && "children" in a) {
165
+ return DodoUtil.fromDataItem(a).element;
166
+ } else {
167
+ return a as HTMLElement;
168
+ }
169
+ }
170
+
171
+ public static forceElement(a: AppendableItem) {
172
+ if (
173
+ typeof a == "number" ||
174
+ typeof a == "boolean" ||
175
+ typeof a == "string"
176
+ ) {
177
+ return document.createTextNode(String(a)) as unknown as HTMLElement;
178
+ } else {
179
+ return DodoUtil.extractElement(a);
180
+ }
181
+ }
182
+
183
+ public static flattenElements(contents: ChildList): HTMLElement[] {
184
+ return contents
185
+ .flat()
186
+ .filter((content) => content != undefined && content !== false)
187
+ .map((a) => {
188
+ if (a == true) a = "true";
189
+ return DodoUtil.forceElement(a);
190
+ });
191
+ }
192
+
193
+ public static injectItems<T extends HTMLElement>(
194
+ node: T,
195
+ direction: "append" | "prepend" = "append",
196
+ objs: ChildList,
197
+ ): void {
198
+ if (objs.length < 1) {
199
+ return;
200
+ }
201
+ const items = this.flattenElements(objs);
202
+
203
+ for (const item of items) {
204
+ const extracted =
205
+ typeof item === "string" ? item : DodoUtil.forceElement(item);
206
+
207
+ if (direction === "append") {
208
+ node.append(extracted);
209
+ } else {
210
+ node.prepend(extracted);
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ function oo<T extends ElementName>(
217
+ tag: T,
218
+ props?: KiwiUpdate | null,
219
+ ...children: ChildList
220
+ ): Dodo {
221
+ return DodoUtil.fromDataItem({
222
+ tag,
223
+ update: props ?? {},
224
+ children,
225
+ });
226
+ }
227
+
228
+ /**
229
+ * client sided mode for Orago's-Dom-Libary
230
+ */
231
+ class Dodo<H extends HTMLElement = HTMLElement> extends Base_Kiwi {
232
+ static oo = oo;
233
+ static plugins = new DodoGlobalPlugins();
234
+ public static events: Emitter<
235
+ {
236
+ init: (node: Dodo) => void;
237
+ },
238
+ true
239
+ > = new Emitter();
240
+
241
+ element!: H;
242
+
243
+ style = makeCallableInstance(DodoStyles, [this], "call");
244
+ class = makeCallableInstance(DodoClasses, [this], "call");
245
+ events = makeCallableInstance(DodoEvents, [this], "call");
246
+
247
+ constructor(element: ElementName | Extractable) {
248
+ super();
249
+
250
+ if (typeof element === "string") {
251
+ this.element = document.createElement(element) as any;
252
+ } else {
253
+ this.element = DodoUtil.extractElement(element) as any;
254
+ }
255
+ }
256
+
257
+ public update(update: KiwiUpdate): this {
258
+ if (update.id != undefined) {
259
+ this.id(update.id);
260
+ }
261
+ if (update.attributes != undefined) {
262
+ this.attr(update.attributes);
263
+ }
264
+ if (update.dataset != undefined) {
265
+ this.dataset(update.dataset);
266
+ }
267
+ if (update.styles != undefined) {
268
+ this.style(update.styles);
269
+ }
270
+ if (update.classes != undefined) {
271
+ this.class.add(...update.classes);
272
+ }
273
+ return this;
274
+ }
275
+
276
+ public use(plugins: ((node: this) => void)[]): this {
277
+ for (const plugin of plugins) {
278
+ plugin(this);
279
+ }
280
+
281
+ return this;
282
+ }
283
+
284
+ public attr(
285
+ attributes: Partial<Record<string & {}, string | number>> = {},
286
+ ): this {
287
+ KiwiUtil.setAttributes(
288
+ attributes,
289
+ (key, value) => this.element.setAttribute(key, value),
290
+ (key) => this.element.removeAttribute(key),
291
+ );
292
+ return this;
293
+ }
294
+
295
+ public dataset(): Partial<Record<string, string>>;
296
+ public dataset(record: "clear" | Partial<Record<string, string>>): this;
297
+ public dataset(record?: "clear" | Partial<Record<string, string>>): any {
298
+ if (record == undefined) {
299
+ return this.element.dataset;
300
+ }
301
+
302
+ if (record == "clear") {
303
+ return this.dataset(
304
+ Object.fromEntries(
305
+ Object.keys(this.element.dataset).map((key) => [
306
+ KiwiUtil.formatAttributeName("camel", key),
307
+ undefined,
308
+ ]),
309
+ ),
310
+ );
311
+ }
312
+
313
+ for (let [key, value] of Object.entries(record)) {
314
+ key = KiwiUtil.formatAttributeName("camel", key);
315
+ if (value == undefined) {
316
+ delete this.element.dataset[key];
317
+ } else {
318
+ this.element.dataset[key] = value;
319
+ }
320
+ }
321
+ return this;
322
+ }
323
+
324
+ public append(...input: ChildList): this {
325
+ DodoUtil.injectItems(this.element, "append", input);
326
+ return this;
327
+ }
328
+
329
+ public prepend(...input: ChildList): this {
330
+ DodoUtil.injectItems(this.element, "prepend", input);
331
+ return this;
332
+ }
333
+
334
+ protected $IdGet(): string {
335
+ return this.element.id;
336
+ }
337
+
338
+ protected $IdSet(value: string): void {
339
+ this.element.id = value;
340
+ }
341
+
342
+ protected $ValueGet(): string {
343
+ if (
344
+ this.element instanceof HTMLInputElement ||
345
+ this.element instanceof HTMLSelectElement
346
+ ) {
347
+ return this.element.value;
348
+ } else if (this.element instanceof HTMLImageElement) {
349
+ return this.element.src;
350
+ } else {
351
+ return this.element.textContent;
352
+ }
353
+ }
354
+
355
+ protected $ValueSet(value: string): this {
356
+ if (
357
+ this.element instanceof HTMLInputElement ||
358
+ this.element instanceof HTMLSelectElement
359
+ ) {
360
+ this.element.value = value.toString();
361
+ } else if (this.element instanceof HTMLImageElement) {
362
+ this.element.src = value.toString();
363
+ } else {
364
+ this.element.textContent = value.toString();
365
+ }
366
+ return this;
367
+ }
368
+
369
+ public clear(): this {
370
+ this.element.innerHTML = "";
371
+ return this;
372
+ }
373
+
374
+ public content(...input: ChildList): this {
375
+ this.clear().append(...input);
376
+ return this;
377
+ }
378
+
379
+ public getBounds() {
380
+ return this.element.getBoundingClientRect();
381
+ }
382
+ }
383
+
384
+ export { Dodo, DodoUtil, oo, type Appendable, type Extractable };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./dodo.js";
2
+ export * as Util from "./util/utilities.js";
@@ -0,0 +1,5 @@
1
+ export {
2
+ DodoRef,
3
+ SizeTrackingPlugin,
4
+ StateTrackingPlugin,
5
+ } from "./plugin-tracking.js";
@@ -0,0 +1,58 @@
1
+ import { Dodo, DodoUtil, Extractable } from "../dodo.js";
2
+ import { DodoGlobalPlugin } from "../util/plugins-support.js";
3
+ import { Query } from "../util/utilities.js";
4
+
5
+ type SchemaList = [name: string, schema: () => Dodo][];
6
+
7
+ export class SchemaPlugin {
8
+ public static plugin_id = "schema-plugin";
9
+
10
+ public schemas: Map<string, () => Dodo> = new Map();
11
+ constructor(
12
+ public id: string,
13
+ schemas: SchemaList = [],
14
+ ) {
15
+ this.addSchemas(schemas);
16
+ }
17
+
18
+ public addSchemas(schemas: SchemaList): this {
19
+ for (const [name, schema] of schemas) {
20
+ this.schemas.set(name, schema);
21
+ }
22
+ return this;
23
+ }
24
+
25
+ public ref(label: string) {
26
+ return new Dodo("schema").value(`${this.id}:${label}`);
27
+ }
28
+
29
+ public plugin(): DodoGlobalPlugin {
30
+ return {
31
+ id: SchemaPlugin.plugin_id,
32
+ };
33
+ }
34
+
35
+ public apply(parent: Extractable = document.body) {
36
+ const found = Query.where(
37
+ {
38
+ tag: "schema",
39
+ text: {
40
+ find: (value) => value.startsWith(`${this.id}:`),
41
+ },
42
+ },
43
+ DodoUtil.extractElement(parent),
44
+ );
45
+
46
+ for (const instance of found) {
47
+ const label = instance.element.textContent.replace(
48
+ `${this.id}:`,
49
+ "",
50
+ );
51
+ const schema = this.schemas.get(label);
52
+
53
+ if (schema != undefined) {
54
+ instance.element.replaceWith(schema().element);
55
+ }
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,11 @@
1
+ import { Builder, BuilderGroup } from "@orago/kiwi/finch/finch";
2
+ import { type Dodo, oo } from "../dodo.js";
3
+ // import { Builder, type BuilderGroup } from "../finch/finch.js";
4
+
5
+ export class FinchPlugin {
6
+ static sheet(group: BuilderGroup): Dodo {
7
+ return oo("style").value(
8
+ Builder.renderSheet(group, { indent: 0, gap: 1 }),
9
+ );
10
+ }
11
+ }