fragtml 0.0.1 → 0.0.2

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.
@@ -5,10 +5,12 @@ export type RenderOptions = {
5
5
  export type CompiledTemplate = {
6
6
  strings: readonly string[];
7
7
  };
8
- export type HtmlTag = ((strings: TemplateStringsArray | readonly string[], ...substitutions: unknown[]) => HtmlResult) & ((options?: RenderOptions | string) => HtmlTag) & {
8
+ export type HtmlTag = ((strings: TemplateStrings, ...substitutions: HtmlSubstitution[]) => HtmlResult) & ((options?: RenderOptions | string) => HtmlTag) & {
9
9
  fragment: FragmentHelpers;
10
10
  raw: (value: unknown) => RawHtml;
11
11
  };
12
+ import type { TemplateStrings } from './html-types.js';
13
+ import type { HtmlSubstitution } from './html-types.js';
12
14
  import { HtmlResult } from './html-result.js';
13
15
  import type { FragmentHelpers } from './fragment.js';
14
16
  import type { RawHtml } from './raw.js';
@@ -1 +1 @@
1
- {"version":3,"file":"create-tag.d.ts","sourceRoot":"","sources":["create-tag.js"],"names":[],"mappings":"AA+EA,mBADW,OAAO,CACoB;;iBArExB,MAAM,GAAG,SAAS;;;aAKlB,SAAS,MAAM,EAAE;;sBAmElB,CAAC,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,MAAM,EAAE,EAAE,GAAG,aAAa,EAAE,OAAO,EAAE,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,KAAK,OAAO,CAAC,GAAG;IAAE,QAAQ,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE;2BA9EtM,kBAAkB;qCAJR,eAAe;6BACvB,UAAU"}
1
+ {"version":3,"file":"create-tag.d.ts","sourceRoot":"","sources":["create-tag.js"],"names":[],"mappings":"AAqFA,mBADW,OAAO,CACoB;;iBA1ExB,MAAM,GAAG,SAAS;;;aAKlB,SAAS,MAAM,EAAE;;sBAwElB,CAAC,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,aAAa,EAAE,gBAAgB,EAAE,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,KAAK,OAAO,CAAC,GAAG;IAAE,QAAQ,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE;qCAvF1J,iBAAiB;sCAAjB,iBAAiB;2BAI7C,kBAAkB;qCALR,eAAe;6BAEvB,UAAU"}
package/lib/create-tag.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /** @import { FragmentHelpers } from './fragment.js' */
2
+ /** @import { HtmlSubstitution, TemplateStrings } from './html-types.js' */
2
3
  /** @import { RawHtml } from './raw.js' */
3
4
 
4
5
  import { createFragmentHelpers } from './fragment.js'
@@ -56,8 +57,11 @@ function normalizeOptions (options) {
56
57
  * @returns {HtmlTag}
57
58
  */
58
59
  function createBoundTag (options) {
59
- // eslint-disable-next-line @stylistic/no-extra-parens
60
- const tag = /** @type {HtmlTag} */ (function tag (strings, ...substitutions) {
60
+ /**
61
+ * @param {TemplateStrings | RenderOptions | string | undefined} strings
62
+ * @param {...HtmlSubstitution} substitutions
63
+ */
64
+ function tag (strings, ...substitutions) {
61
65
  if (!isTemplateStrings(strings)) {
62
66
  return createBoundTag(normalizeOptions(/** @type {RenderOptions | string | undefined} */ strings))
63
67
  }
@@ -68,17 +72,19 @@ function createBoundTag (options) {
68
72
  options,
69
73
  renderResult
70
74
  )
71
- })
75
+ }
72
76
 
73
- tag.fragment = fragment
74
- tag.raw = raw
77
+ const htmlTag = /** @type {HtmlTag} */ (tag)
75
78
 
76
- return tag
79
+ htmlTag.fragment = fragment
80
+ htmlTag.raw = raw
81
+
82
+ return htmlTag
77
83
  }
78
84
 
79
85
  /** @type {HtmlTag} */
80
86
  export const html = createBoundTag({})
81
87
 
82
88
  /**
83
- * @typedef {((strings: TemplateStringsArray | readonly string[], ...substitutions: unknown[]) => HtmlResult) & ((options?: RenderOptions | string) => HtmlTag) & { fragment: FragmentHelpers, raw: (value: unknown) => RawHtml }} HtmlTag
89
+ * @typedef {((strings: TemplateStrings, ...substitutions: HtmlSubstitution[]) => HtmlResult) & ((options?: RenderOptions | string) => HtmlTag) & { fragment: FragmentHelpers, raw: (value: unknown) => RawHtml }} HtmlTag
84
90
  */
@@ -1,9 +1,9 @@
1
1
  export function isHtmlResult(value: unknown): value is HtmlResult;
2
2
  export const htmlResultSymbol: unique symbol;
3
3
  export class HtmlResult {
4
- constructor(compiled: CompiledTemplate, substitutions: unknown[], options: RenderOptions, render: (result: HtmlResult) => string);
4
+ constructor(compiled: CompiledTemplate, substitutions: HtmlSubstitution[], options: RenderOptions, render: (result: HtmlResult) => string);
5
5
  compiled: CompiledTemplate;
6
- substitutions: unknown[];
6
+ substitutions: HtmlSubstitution[];
7
7
  options: RenderOptions;
8
8
  render: (result: HtmlResult) => string;
9
9
  toString(): string;
@@ -12,5 +12,6 @@ export class HtmlResult {
12
12
  [htmlResultSymbol]: boolean;
13
13
  }
14
14
  import type { CompiledTemplate } from './create-tag.js';
15
+ import type { HtmlSubstitution } from './html-types.js';
15
16
  import type { RenderOptions } from './create-tag.js';
16
17
  //# sourceMappingURL=html-result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"html-result.d.ts","sourceRoot":"","sources":["html-result.js"],"names":[],"mappings":"AAoCA,oCAHW,OAAO,GACL,KAAK,IAAI,UAAU,CAQ/B;AAxCD,6CAA4D;AAE5D;IAOE,sBALW,gBAAgB,iBAChB,OAAO,EAAE,WACT,aAAa,UACb,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,EAQxC;IAJC,2BAAwB;IACxB,yBAAkC;IAClC,uBAAsB;IACtB,iBAPkB,UAAU,KAAK,MAAM,CAOnB;IAGtB,mBAEC;IAED,kBAEC;IAED,+BAEC;IAjBC,4BAA6B;CAkBhC;sCA9BoD,iBAAiB;mCAAjB,iBAAiB"}
1
+ {"version":3,"file":"html-result.d.ts","sourceRoot":"","sources":["html-result.js"],"names":[],"mappings":"AAqCA,oCAHW,OAAO,GACL,KAAK,IAAI,UAAU,CAQ/B;AAxCD,6CAA4D;AAE5D;IAOE,sBALW,gBAAgB,iBAChB,gBAAgB,EAAE,WAClB,aAAa,UACb,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,EAQxC;IAJC,2BAAwB;IACxB,kCAAkC;IAClC,uBAAsB;IACtB,iBAPkB,UAAU,KAAK,MAAM,CAOnB;IAGtB,mBAEC;IAED,kBAEC;IAED,+BAEC;IAjBC,4BAA6B;CAkBhC;sCA/BoD,iBAAiB;sCAChC,iBAAiB;mCADF,iBAAiB"}
@@ -1,11 +1,12 @@
1
1
  /** @import { CompiledTemplate, RenderOptions } from './create-tag.js' */
2
+ /** @import { HtmlSubstitution } from './html-types.js' */
2
3
 
3
4
  export const htmlResultSymbol = Symbol('fragtml.htmlResult')
4
5
 
5
6
  export class HtmlResult {
6
7
  /**
7
8
  * @param {CompiledTemplate} compiled
8
- * @param {unknown[]} substitutions
9
+ * @param {HtmlSubstitution[]} substitutions
9
10
  * @param {RenderOptions} options
10
11
  * @param {(result: HtmlResult) => string} render
11
12
  */
@@ -0,0 +1,9 @@
1
+ import type { FragmentBoundary } from './fragment.js';
2
+ import type { HtmlResult } from './html-result.js';
3
+ import type { RawHtml } from './raw.js';
4
+ export type HtmlPrimitiveSubstitution = string | number | bigint | boolean | null | undefined;
5
+ export type HtmlArrayScalarSubstitution = HtmlPrimitiveSubstitution | HtmlResult | RawHtml;
6
+ export type HtmlArraySubstitution = HtmlArrayScalarSubstitution | readonly HtmlArraySubstitution[];
7
+ export type HtmlSubstitution = HtmlArraySubstitution | FragmentBoundary;
8
+ export type TemplateStrings = TemplateStringsArray | readonly string[];
9
+ //# sourceMappingURL=html-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-types.d.ts","sourceRoot":"","sources":["html-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEvC,MAAM,MAAM,yBAAyB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AAC7F,MAAM,MAAM,2BAA2B,GAAG,yBAAyB,GAAG,UAAU,GAAG,OAAO,CAAA;AAC1F,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,GAAG,SAAS,qBAAqB,EAAE,CAAA;AAClG,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,gBAAgB,CAAA;AACvE,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,SAAS,MAAM,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ // Type exports only. Do not add runtime implementations to this module.
2
+ import type { FragmentBoundary } from './fragment.js'
3
+ import type { HtmlResult } from './html-result.js'
4
+ import type { RawHtml } from './raw.js'
5
+
6
+ export type HtmlPrimitiveSubstitution = string | number | bigint | boolean | null | undefined
7
+ export type HtmlArrayScalarSubstitution = HtmlPrimitiveSubstitution | HtmlResult | RawHtml
8
+ export type HtmlArraySubstitution = HtmlArrayScalarSubstitution | readonly HtmlArraySubstitution[]
9
+ export type HtmlSubstitution = HtmlArraySubstitution | FragmentBoundary
10
+ export type TemplateStrings = TemplateStringsArray | readonly string[]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fragtml",
3
3
  "description": "WIP - nothing to see here",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "author": "Bret Comnes <bcomnes@gmail.com> (https://bret.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/bcomnes/fragtml/issues"
@@ -48,7 +48,7 @@
48
48
  "build:declaration": "tsc -p declaration.tsconfig.json",
49
49
  "clean": "run-p clean:*",
50
50
  "clean:declarations-top": "rm -rf $(find . -maxdepth 1 -type f -name '*.d.ts*')",
51
- "clean:declarations-lib": "rm -rf $(find lib -type f -name '*.d.ts*' ! -name '*-types.d.ts')"
51
+ "clean:declarations-lib": "rm -rf $(find lib -type f -name '*.d.ts*')"
52
52
  },
53
53
  "funding": {
54
54
  "type": "individual",