lism-css 0.9.0 → 0.9.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.
@@ -1,12 +1,12 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import s from "./getContent.js";
2
+ import g from "./getContent.js";
3
3
  import e from "../Lism/index.js";
4
- function d({ pre: i = "", length: a = "m", lang: o = "en", offset: r = 0, ...t }) {
5
- const m = t.as || t.tag || "p";
4
+ function d({ pre: i = "", length: o = "m", lang: r = "en", offset: s = 0, ...t }) {
5
+ const m = t.as || "p";
6
6
  if (m === "img")
7
7
  return /* @__PURE__ */ n(e, { as: "img", src: "https://cdn.lism-css.com/dummy-image.jpg", width: 600, height: 400, alt: "", ...t });
8
- const g = s({ tag: m, pre: i, lang: o, length: a, offset: r });
9
- return /* @__PURE__ */ n(e, { ...t, dangerouslySetInnerHTML: { __html: g } });
8
+ const a = g({ tag: m, pre: i, lang: r, length: o, offset: s });
9
+ return /* @__PURE__ */ n(e, { ...t, dangerouslySetInnerHTML: { __html: a } });
10
10
  }
11
11
  export {
12
12
  d as default
@@ -1,9 +1,9 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
- import e from "../Lism/index.js";
3
- function a({ children: t, ...r }) {
2
+ import s from "../Lism/index.js";
3
+ function n({ children: t, ...r }) {
4
4
  const o = !!r.href ? "a" : "div";
5
- return /* @__PURE__ */ i(e, { isLinkBox: !0, tag: o, ...r, children: t });
5
+ return /* @__PURE__ */ i(s, { isLinkBox: !0, as: o, ...r, children: t });
6
6
  }
7
7
  export {
8
- a as default
8
+ n as default
9
9
  };
@@ -1,12 +1,10 @@
1
- import { ComponentPropsWithoutRef, ElementType, ReactNode, JSX } from 'react';
1
+ import { ComponentPropsWithoutRef, ElementType, ReactNode } from 'react';
2
2
  import { LismProps } from '../../lib/getLismProps';
3
3
  import { LayoutSpecificProps } from '../../lib/types/LayoutProps';
4
4
  /** HTML 要素 Props と共通オプションの基底型 */
5
5
  type LismBaseProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, keyof LismProps> & {
6
6
  /** レンダリングするコンポーネントまたは要素 */
7
7
  as?: T;
8
- /** レンダリングするHTML要素のタグ名(文字列のみ)*/
9
- tag?: keyof JSX.IntrinsicElements;
10
8
  /** 子要素 */
11
9
  children?: ReactNode;
12
10
  /** getLismProps を経由せずに直接渡す追加の props */
@@ -27,5 +25,5 @@ export type LayoutComponentProps<T extends ElementType = 'div', L = object> = Om
27
25
  /**
28
26
  * Lism Propsを処理できるだけのコンポーネント
29
27
  */
30
- export default function Lism<T extends ElementType = 'div'>({ children, as, tag, exProps, ...props }: LismComponentProps<T>): JSX.Element;
28
+ export default function Lism<T extends ElementType = 'div'>({ children, as, exProps, ...props }: LismComponentProps<T>): import("react").JSX.Element;
31
29
  export {};
@@ -1,8 +1,8 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import i from "../../lib/getLismProps.js";
3
- function u({ children: o, as: t, tag: m, exProps: n, ...r }) {
4
- return /* @__PURE__ */ e(t || m || "div", { ...i(r), ...n, children: o });
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import e from "../../lib/getLismProps.js";
3
+ function f({ children: o, as: t, exProps: m, ...n }) {
4
+ return /* @__PURE__ */ r(t || "div", { ...e(n), ...m, children: o });
5
5
  }
6
6
  export {
7
- u as default
7
+ f as default
8
8
  };
@@ -12,7 +12,7 @@ type IconOwnProps = {
12
12
  exProps?: Record<string, unknown>;
13
13
  };
14
14
  export type IconProps = LismComponentProps & TransformStyleProps & IconOwnProps;
15
- export default function getProps({ lismClass, as, tag, icon, label, exProps, ..._props }: IconProps): {
15
+ export default function getProps({ lismClass, as, icon, label, exProps, ..._props }: IconProps): {
16
16
  Component: ElementType | "_SVG_";
17
17
  lismProps: {
18
18
  [key: string]: unknown;
@@ -1,56 +1,55 @@
1
- import C from "./presets.js";
2
- import y from "../../../lib/helper/atts.js";
3
- import b from "../../setMaybeTransformStyles.js";
4
- function d(u) {
5
- const a = {}, o = u.match(/<svg([^>]*?)>([\s\S]*?)<\/svg>/i);
6
- if (o) {
7
- const [, e, m] = o, t = /([\w-]+)=["']([^"']*)["']/g;
8
- let c;
9
- for (; (c = t.exec(e)) !== null; ) {
10
- const [, s, n] = c;
11
- if (s === "style") {
12
- const g = {};
13
- n.split(";").forEach((v) => {
14
- const [l, i] = v.split(":").map((f) => f.trim());
15
- l && i && (g[l] = i);
16
- }), a[s] = g;
1
+ import S from "./presets.js";
2
+ import h from "../../../lib/helper/atts.js";
3
+ import C from "../../setMaybeTransformStyles.js";
4
+ function b(g) {
5
+ const f = {}, s = g.match(/<svg([^>]*?)>([\s\S]*?)<\/svg>/i);
6
+ if (s) {
7
+ const [, o, t] = s, u = /([\w-]+)=["']([^"']*)["']/g;
8
+ let e;
9
+ for (; (e = u.exec(o)) !== null; ) {
10
+ const [, r, m] = e;
11
+ if (r === "style") {
12
+ const c = {};
13
+ m.split(";").forEach((l) => {
14
+ const [i, n] = l.split(":").map((a) => a.trim());
15
+ i && n && (c[i] = n);
16
+ }), f[r] = c;
17
17
  } else
18
- a[s] = n;
18
+ f[r] = m;
19
19
  }
20
- return { svgProps: a, svgContent: m };
20
+ return { svgProps: f, svgContent: t };
21
21
  }
22
22
  return {};
23
23
  }
24
- function j({ lismClass: u, as: a, tag: o, icon: e, label: m, exProps: t = {}, ...c }) {
25
- let s = o || "span", n = "";
24
+ function V({ lismClass: g, as: f, icon: s, label: o, exProps: t = {}, ...u }) {
25
+ let e = f || "span", r = "";
26
26
  const {
27
- style: g = {},
28
- className: v = "",
27
+ style: m = {},
28
+ className: c = "",
29
29
  ...l
30
- } = b(c);
31
- let i = g, f = v;
30
+ } = C(u);
31
+ let i = m, n = c;
32
32
  if (l.viewBox)
33
- s = "svg", l.width || (t.width = "1em"), l.height || (t.height = "1em");
33
+ e = "svg", l.width || (t.width = "1em"), l.height || (t.height = "1em");
34
34
  else if (l.src)
35
- s = "img";
36
- else if (e)
37
- if (typeof e == "string")
38
- if (e.startsWith("<svg")) {
39
- s = "_SVG_";
40
- const { svgProps: r = {}, svgContent: h = "" } = d(e), { class: p, style: _, ...S } = r;
41
- f = y(f, p), i = { ...i, ..._ }, t = { ...t, ...S, fill: "currentColor" }, n = h;
35
+ e = "img";
36
+ else if (s)
37
+ if (typeof s == "string")
38
+ if (s.startsWith("<svg")) {
39
+ e = "_SVG_";
40
+ const { svgProps: a = {}, svgContent: v = "" } = b(s), { class: y, style: p, ..._ } = a;
41
+ n = h(n, y), i = { ...i, ...p }, t = { ...t, ..._, fill: "currentColor" }, r = v;
42
42
  } else {
43
- const r = C[e] || null;
44
- r != null && (s = "_SVG_", t = { ...t, ...r });
43
+ const a = S[s] || null;
44
+ a != null && (e = "_SVG_", t = { ...t, ...a });
45
45
  }
46
- else if (typeof e == "object" && e.as) {
47
- const { as: r, ...h } = e;
48
- s = r, t = { ...t, ...h };
46
+ else if (typeof s == "object" && s.as) {
47
+ const { as: a, ...v } = s;
48
+ e = a, t = { ...t, ...v };
49
49
  } else
50
- s = e;
51
- else a && (s = a);
52
- return m ? (t["aria-label"] = m, t.role = "img") : t["aria-hidden"] = "true", l.lismClass = y(u, "a--icon", f), l.style = { ...i }, { Component: s, lismProps: l, exProps: t, content: n };
50
+ e = s;
51
+ return o ? (t["aria-label"] = o, t.role = "img") : t["aria-hidden"] = "true", l.lismClass = h(g, "a--icon", n), l.style = { ...i }, { Component: e, lismProps: l, exProps: t, content: r };
53
52
  }
54
53
  export {
55
- j as default
54
+ V as default
56
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lism-css",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "A layout-first CSS framework for websites.",
5
5
  "author": {
6
6
  "name": "ddryo",
@@ -5,9 +5,9 @@ import getContent from '../../../dist/components/Dummy/getContent';
5
5
 
6
6
  // Propsの定義
7
7
  interface Props extends LismProps {}
8
- const { tag = 'p', pre = '', length = 'm', lang = 'en', offset = 0, ...props } = Astro.props || {};
9
- const content = getContent({ tag, pre, lang, length, offset });
8
+ const { as: tagName = 'p', pre = '', length = 'm', lang = 'en', offset = 0, ...props } = Astro.props || {};
9
+ const content = getContent({ tag: tagName, pre, lang, length, offset });
10
10
  ---
11
11
 
12
- {tag === 'img' && <Lism tag='img' src='https://cdn.lism-css.com/dummy-image.jpg' width='600' height='400' alt='' {...props} />}
13
- {tag !== 'img' && <Lism tag={tag} {...props} set:html={content} />}
12
+ {tagName === 'img' && <Lism as='img' src='https://cdn.lism-css.com/dummy-image.jpg' width='600' height='400' alt='' {...props} />}
13
+ {tagName !== 'img' && <Lism as={tagName} {...props} set:html={content} />}
@@ -3,17 +3,17 @@
3
3
  import { createComponent, renderComponent } from 'astro/runtime/server/index.js';
4
4
  import Lism from '../Lism/Lism.astro';
5
5
 
6
- // <Lism tag="*"> の薄いラッパーを動的に生成するユーティリティ
6
+ // <Lism as="*"> の薄いラッパーを動的に生成するユーティリティ
7
7
  const createHTMLComponent = (tag, baseProps = {}) =>
8
8
  createComponent((result, props = {}, slots = {}) => {
9
- return renderComponent(result, 'Lism', Lism, { tag, ...baseProps, ...props }, slots);
9
+ return renderComponent(result, 'Lism', Lism, { as: tag, ...baseProps, ...props }, slots);
10
10
  });
11
11
 
12
12
  // 見出しだけ lv でタグ名を変える
13
13
  const createHeadingComponent = () =>
14
14
  createComponent((result, props = {}, slots = {}) => {
15
15
  const { lv = '1', ...rest } = props;
16
- return renderComponent(result, 'Lism', Lism, { tag: `h${lv}`, ...rest }, slots);
16
+ return renderComponent(result, 'Lism', Lism, { as: `h${lv}`, ...rest }, slots);
17
17
  });
18
18
 
19
19
  // よく使うタグをまとめてラップ
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='a' {...Astro.props}><slot /></Lism>
5
+ <Lism as='a' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='button' {...Astro.props}><slot /></Lism>
5
+ <Lism as='button' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='div' {...Astro.props}><slot /></Lism>
5
+ <Lism as='div' {...Astro.props}><slot /></Lism>
@@ -3,4 +3,4 @@ import Lism from '../Lism/Lism.astro';
3
3
  const { lv = '1', ...props } = Astro.props;
4
4
  ---
5
5
 
6
- <Lism tag={`h${lv}`} {...props}><slot /></Lism>
6
+ <Lism as={`h${lv}`} {...props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='img' {...Astro.props}><slot /></Lism>
5
+ <Lism as='img' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='li' {...Astro.props}><slot /></Lism>
5
+ <Lism as='li' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='ol' {...Astro.props}><slot /></Lism>
5
+ <Lism as='ol' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='p' {...Astro.props}><slot /></Lism>
5
+ <Lism as='p' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='span' {...Astro.props}><slot /></Lism>
5
+ <Lism as='span' {...Astro.props}><slot /></Lism>
@@ -2,4 +2,4 @@
2
2
  import Lism from '../Lism/Lism.astro';
3
3
  ---
4
4
 
5
- <Lism tag='ul' {...Astro.props}><slot /></Lism>
5
+ <Lism as='ul' {...Astro.props}><slot /></Lism>
@@ -10,6 +10,6 @@ const hasHref = !!props.href;
10
10
  const tag = hasHref ? 'a' : 'div';
11
11
  ---
12
12
 
13
- <Lism isLinkBox tag={tag} {...props}>
13
+ <Lism isLinkBox as={tag} {...props}>
14
14
  <slot />
15
15
  </Lism>
@@ -5,8 +5,8 @@ import getLismProps from '../../../dist/lib/getLismProps';
5
5
  // Propsの定義
6
6
  interface Props extends LismProps {}
7
7
 
8
- const { as, tag, exProps, ...props } = Astro.props || {};
9
- const JSX = as || tag || 'div';
8
+ const { as, exProps, ...props } = Astro.props || {};
9
+ const JSX = as || 'div';
10
10
  ---
11
11
 
12
12
  <JSX {...getLismProps(props)} {...exProps}>
@@ -3,9 +3,9 @@ import getLismProps from '../../../dist/lib/getLismProps';
3
3
  import getMediaProps from '../../../dist/components/atomic/Media/getProps';
4
4
  import { Image } from 'astro:assets';
5
5
 
6
- const { as, exProps, tag, ...props } = Astro.props || {};
6
+ const { as, exProps, ...props } = Astro.props || {};
7
7
 
8
- let JSX = as || tag || 'img';
8
+ let JSX = as || 'img';
9
9
  if (JSX === 'AstroImage') {
10
10
  JSX = Image;
11
11
  }