@htmlplus/element 2.9.8 → 2.11.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.
@@ -4,4 +4,5 @@ export declare const htmlplus: (...plugins: Array<TransformerPlugin>) => {
4
4
  buildStart(): Promise<void>;
5
5
  load(id: any): Promise<string | undefined>;
6
6
  buildEnd(): Promise<void>;
7
+ writeBundle(options: any, bundles: any): Promise<void>;
7
8
  };
package/bundlers/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import { transformer } from '../transformer/index.js';
3
3
  export const htmlplus = (...plugins) => {
4
- const { start, run, finish } = transformer(...plugins);
4
+ const { global, start, run, finish, write } = transformer(...plugins);
5
5
  return {
6
6
  name: 'htmlplus',
7
7
  async buildStart() {
@@ -20,6 +20,33 @@ export const htmlplus = (...plugins) => {
20
20
  },
21
21
  async buildEnd() {
22
22
  await finish();
23
+ },
24
+ async writeBundle(options, bundles) {
25
+ // TODO
26
+ try {
27
+ for (const context of global.contexts) {
28
+ for (const key in bundles) {
29
+ if (!Object.hasOwnProperty.call(bundles, key))
30
+ continue;
31
+ const bundle = bundles[key];
32
+ if (!bundle.facadeModuleId.startsWith(context.filePath))
33
+ continue;
34
+ const modules = bundle['modules'];
35
+ for (const key in modules) {
36
+ if (!Object.hasOwnProperty.call(modules, key))
37
+ continue;
38
+ const module = modules[key];
39
+ if (!key.startsWith(context.stylePath || ''))
40
+ continue;
41
+ context.styleContentTransformed = module.code;
42
+ break;
43
+ }
44
+ break;
45
+ }
46
+ }
47
+ }
48
+ catch { }
49
+ await write();
23
50
  }
24
51
  };
25
52
  };
@@ -214,7 +214,11 @@ var udomdiff = (parentNode, a, b, get, before) => {
214
214
  // need to be added are not at the end, and in such case
215
215
  // the node to `insertBefore`, if the index is more than 0
216
216
  // must be retrieved, otherwise it's gonna be the first item.
217
- const node = bEnd < bLength ? (bStart ? get(b[bStart - 1], -0).nextSibling : get(b[bEnd - bStart], 0)) : before;
217
+ const node = bEnd < bLength
218
+ ? bStart
219
+ ? get(b[bStart - 1], -0).nextSibling
220
+ : get(b[bEnd - bStart], 0)
221
+ : before;
218
222
  while (bStart < bEnd)
219
223
  parentNode.insertBefore(get(b[bStart++], 1), node);
220
224
  }
package/jsx-runtime.d.ts CHANGED
@@ -95,7 +95,7 @@ declare namespace JSX {
95
95
  s: WithPart<'s'>;
96
96
  samp: WithPart<'samp'>;
97
97
  search: WithPart<'search'>;
98
- slot: WithPart<'slot'>;
98
+ slot: WithPart<'slot'> & { onSlotChange?: (event: Event) => void };
99
99
  script: WithPart<'script'>;
100
100
  section: WithPart<'section'>;
101
101
  select: WithPart<'select'>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "2.9.8",
3
+ "version": "2.11.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -10,7 +10,7 @@ export const DOCUMENT_OPTIONS = {
10
10
  export const document = (options) => {
11
11
  const name = 'document';
12
12
  options = Object.assign({}, DOCUMENT_OPTIONS, options);
13
- const finish = (global) => {
13
+ const write = (global) => {
14
14
  const json = {
15
15
  elements: []
16
16
  };
@@ -164,7 +164,18 @@ export const document = (options) => {
164
164
  const [first, second] = section.split(/\n/);
165
165
  const description = first.replace('*/', '').trim();
166
166
  const name = second.split(':')[0].trim();
167
- const initializer = second.split(':').slice(1).join(':').replace(';', '').trim();
167
+ const initializerDefault = second.split(':').slice(1).join(':').replace(';', '').trim();
168
+ // TODO
169
+ const initializerTransformed = context.styleContentTransformed
170
+ ?.split(name)
171
+ ?.at(1)
172
+ ?.split(':')
173
+ ?.filter((section) => !!section)
174
+ ?.at(0)
175
+ ?.split(/;|}/)
176
+ ?.at(0)
177
+ ?.trim();
178
+ const initializer = initializerTransformed || initializerDefault;
168
179
  return {
169
180
  description,
170
181
  initializer,
@@ -191,5 +202,5 @@ export const document = (options) => {
191
202
  fs.ensureDirSync(dirname);
192
203
  fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
193
204
  };
194
- return { name, finish };
205
+ return { name, write };
195
206
  };
@@ -1,6 +1,8 @@
1
- import { TransformerPlugin, TransformerPluginContext } from './transformer.types.js';
1
+ import { TransformerPlugin, TransformerPluginContext, TransformerPluginGlobal } from './transformer.types.js';
2
2
  export declare const transformer: (...plugins: TransformerPlugin[]) => {
3
+ global: TransformerPluginGlobal;
3
4
  start: () => Promise<void>;
4
5
  run: (filePath: string) => Promise<TransformerPluginContext>;
5
6
  finish: () => Promise<void>;
7
+ write: () => Promise<void>;
6
8
  };
@@ -67,5 +67,12 @@ export const transformer = (...plugins) => {
67
67
  log(`Plugins finished successfully.`, true);
68
68
  log(`Finished.`, true);
69
69
  };
70
- return { start, run, finish };
70
+ const write = async () => {
71
+ for (const plugin of plugins) {
72
+ if (!plugin.write)
73
+ continue;
74
+ global = (await plugin.write(global)) || global;
75
+ }
76
+ };
77
+ return { global, start, run, finish, write };
71
78
  };
@@ -30,6 +30,7 @@ export interface TransformerPluginContext {
30
30
  readmeName?: string;
31
31
  readmePath?: string;
32
32
  styleContent?: string;
33
+ styleContentTransformed?: string;
33
34
  styleExtension?: string;
34
35
  styleName?: string;
35
36
  stylePath?: string;
@@ -46,5 +47,6 @@ export interface TransformerPlugin {
46
47
  start?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
47
48
  run?: (context: TransformerPluginContext, global: TransformerPluginGlobal) => Return<TransformerPluginContext>;
48
49
  finish?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
50
+ write?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
49
51
  }
50
52
  export {};