@prosefly/astro-components 0.2.1 → 0.3.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.
@@ -0,0 +1,3 @@
1
+ import type { RemarkPlugin } from '@astrojs/markdown-remark';
2
+ export declare const remarkCalloutDirectives: RemarkPlugin;
3
+ //# sourceMappingURL=callout-directives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout-directives.d.ts","sourceRoot":"","sources":["../../src/markdown/callout-directives.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAoC7D,eAAO,MAAM,uBAAuB,EAAE,YA0BrC,CAAC"}
@@ -0,0 +1,130 @@
1
+ import remarkDirective from 'remark-directive';
2
+ const importStatement = "import { Callout as ProseflyDirectiveCallout } from '@prosefly/astro-components';";
3
+ const calloutTypes = new Map([
4
+ ['caution', 'warning'],
5
+ ['danger', 'danger'],
6
+ ['note', 'note'],
7
+ ['tip', 'tip'],
8
+ ['warning', 'warning'],
9
+ ]);
10
+ export const remarkCalloutDirectives = function () {
11
+ this.use(remarkDirective);
12
+ return (tree) => {
13
+ const root = tree;
14
+ let transformed = false;
15
+ visitChildren(root, (node, parent, index) => {
16
+ if (!parent?.children ||
17
+ index === undefined ||
18
+ !isCalloutDirective(node)) {
19
+ return;
20
+ }
21
+ parent.children[index] = createCalloutNode(node);
22
+ transformed = true;
23
+ });
24
+ if (transformed && !hasCalloutDirectiveImport(root)) {
25
+ root.children.unshift(createImportNode());
26
+ }
27
+ };
28
+ };
29
+ function visitChildren(node, visitor, parent, index) {
30
+ visitor(node, parent, index);
31
+ if (!node.children) {
32
+ return;
33
+ }
34
+ node.children.forEach((child, childIndex) => {
35
+ visitChildren(child, visitor, node, childIndex);
36
+ });
37
+ }
38
+ function isCalloutDirective(node) {
39
+ return ((node.type === 'containerDirective' || node.type === 'leafDirective') &&
40
+ typeof node.name === 'string' &&
41
+ calloutTypes.has(node.name) &&
42
+ Array.isArray(node.children));
43
+ }
44
+ function createCalloutNode(node) {
45
+ const { title, children } = getCalloutContent(node);
46
+ const type = calloutTypes.get(node.name) ?? 'note';
47
+ const attributes = [
48
+ {
49
+ type: 'mdxJsxAttribute',
50
+ name: 'type',
51
+ value: type,
52
+ },
53
+ ];
54
+ if (title) {
55
+ attributes.push({
56
+ type: 'mdxJsxAttribute',
57
+ name: 'title',
58
+ value: title,
59
+ });
60
+ }
61
+ return {
62
+ type: 'mdxJsxFlowElement',
63
+ name: 'ProseflyDirectiveCallout',
64
+ attributes,
65
+ children,
66
+ };
67
+ }
68
+ function getCalloutContent(node) {
69
+ const title = getAttributeTitle(node) ?? getDirectiveLabel(node);
70
+ const children = title
71
+ ? node.children.filter((child) => !isDirectiveLabel(child))
72
+ : node.children;
73
+ return { children, title };
74
+ }
75
+ function getAttributeTitle(node) {
76
+ const title = node.attributes?.title;
77
+ return typeof title === 'string' && title.trim() ? title : undefined;
78
+ }
79
+ function getDirectiveLabel(node) {
80
+ const label = node.children.find(isDirectiveLabel);
81
+ if (!label?.children) {
82
+ return undefined;
83
+ }
84
+ const text = label.children.map(getPlainText).join('').trim();
85
+ return text || undefined;
86
+ }
87
+ function isDirectiveLabel(node) {
88
+ return node.type === 'paragraph' && node.data?.directiveLabel === true;
89
+ }
90
+ function getPlainText(node) {
91
+ if (typeof node.value === 'string') {
92
+ return node.value;
93
+ }
94
+ return node.children?.map(getPlainText).join('') ?? '';
95
+ }
96
+ function createImportNode() {
97
+ return {
98
+ type: 'mdxjsEsm',
99
+ value: importStatement,
100
+ data: {
101
+ estree: {
102
+ type: 'Program',
103
+ sourceType: 'module',
104
+ body: [
105
+ {
106
+ type: 'ImportDeclaration',
107
+ specifiers: [
108
+ {
109
+ type: 'ImportSpecifier',
110
+ imported: { type: 'Identifier', name: 'Callout' },
111
+ local: { type: 'Identifier', name: 'ProseflyDirectiveCallout' },
112
+ },
113
+ ],
114
+ source: {
115
+ type: 'Literal',
116
+ value: '@prosefly/astro-components',
117
+ raw: "'@prosefly/astro-components'",
118
+ },
119
+ },
120
+ ],
121
+ },
122
+ },
123
+ };
124
+ }
125
+ function hasCalloutDirectiveImport(tree) {
126
+ return tree.children.some((node) => node.type === 'mdxjsEsm' &&
127
+ typeof node.value === 'string' &&
128
+ node.value.includes('ProseflyDirectiveCallout'));
129
+ }
130
+ //# sourceMappingURL=callout-directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout-directives.js","sourceRoot":"","sources":["../../src/markdown/callout-directives.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAE/C,MAAM,eAAe,GACnB,mFAAmF,CAAC;AAEtF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,CAAC,SAAS,EAAE,SAAS,CAAC;IACtB,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,SAAS,EAAE,SAAS,CAAC;CACvB,CAAC,CAAC;AAwBH,MAAM,CAAC,MAAM,uBAAuB,GAAiB;IAGnD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAE1B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,IAAI,GAAG,IAAgB,CAAC;QAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;QAExB,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YAC1C,IACE,CAAC,MAAM,EAAE,QAAQ;gBACjB,KAAK,KAAK,SAAS;gBACnB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EACzB,CAAC;gBACD,OAAO;YACT,CAAC;YAED,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACjD,WAAW,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,I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D,CAAC;AACJ,CAAC"}
@@ -1,3 +1,5 @@
1
+ export { unified } from '@astrojs/markdown-remark';
1
2
  export { rehypeImageGallery } from './image-gallery-plugin.js';
3
+ export { remarkCalloutDirectives } from './callout-directives.js';
2
4
  export { remarkPackageManagerTabs } from './package-manager-tabs.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,3 +1,5 @@
1
+ export { unified } from '@astrojs/markdown-remark';
1
2
  export { rehypeImageGallery } from './image-gallery-plugin.js';
3
+ export { remarkCalloutDirectives } from './callout-directives.js';
2
4
  export { remarkPackageManagerTabs } from './package-manager-tabs.js';
3
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -16,7 +16,7 @@ const { title, type = 'note' } = Astro.props;
16
16
  const hasTitle = Boolean(title);
17
17
  ---
18
18
 
19
- <aside class="pl-callout" data-has-title={hasTitle ? 'true' : 'false'} data-type={type}>
19
+ <div class="pl-callout" data-has-title={hasTitle ? 'true' : 'false'} data-type={type} role="note">
20
20
  <span class="pl-callout__icon" aria-hidden="true">
21
21
  <Icon name={iconNames[type]} />
22
22
  </span>
@@ -26,7 +26,7 @@ const hasTitle = Boolean(title);
26
26
  <slot />
27
27
  </div>
28
28
  </div>
29
- </aside>
29
+ </div>
30
30
 
31
31
  <style>
32
32
  .pl-callout {
@@ -41,7 +41,7 @@ const linkAttrs = href
41
41
  )
42
42
  }
43
43
  <div class="pl-card__body">
44
- {title && <h3 class="pl-card__title">{title}</h3>}
44
+ {title && <p class="pl-card__title">{title}</p>}
45
45
  <div class="pl-card__content">
46
46
  <slot />
47
47
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosefly/astro-components",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "BSD-3-Clause",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "build": "node ./scripts/build.mjs",
9
9
  "check": "tsc -p ./tsconfig.build.json --noEmit",
10
10
  "prepack": "npm run build",
11
- "prepublishOnly": "npm run check && npm run build"
11
+ "prepublishOnly": "npm run check && npm run build",
12
+ "test": "pnpm run build && node --test test/*.test.mjs"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
@@ -46,7 +47,8 @@
46
47
  "@astrojs/markdown-remark": "^7.2.1",
47
48
  "@iconify/utils": "^3.1.4",
48
49
  "rehype": "^13.0.2",
49
- "rehype-format": "^5.0.1"
50
+ "rehype-format": "^5.0.1",
51
+ "remark-directive": "^4.0.0"
50
52
  },
51
53
  "devDependencies": {
52
54
  "astro": "7.1.0",