nizel-kit 0.1.5 → 0.1.6
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.
- package/dist/nizel-kit.iife.js +12 -4
- package/dist/nizel-kit.js +12 -4
- package/package.json +1 -1
package/dist/nizel-kit.iife.js
CHANGED
|
@@ -5036,7 +5036,9 @@ ${body}
|
|
|
5036
5036
|
|
|
5037
5037
|
// ../plugin-code-copy/dist/index.js
|
|
5038
5038
|
var codeCopyPlugin = (options = {}) => {
|
|
5039
|
+
const copiedLabel = options.copiedLabel ?? "Copied";
|
|
5039
5040
|
const label = options.label ?? "Copy";
|
|
5041
|
+
const mode = options.mode ?? "inline";
|
|
5040
5042
|
return defineNizelPlugin({
|
|
5041
5043
|
name: "code-copy",
|
|
5042
5044
|
blocks: {
|
|
@@ -5046,7 +5048,7 @@ ${body}
|
|
|
5046
5048
|
html(node, ctx) {
|
|
5047
5049
|
if (node.type !== "customBlock")
|
|
5048
5050
|
return "";
|
|
5049
|
-
return renderCodeCopyBlock(node, ctx, label);
|
|
5051
|
+
return renderCodeCopyBlock(node, ctx, { copiedLabel, label, mode });
|
|
5050
5052
|
}
|
|
5051
5053
|
}
|
|
5052
5054
|
}
|
|
@@ -5101,13 +5103,19 @@ ${body}
|
|
|
5101
5103
|
lang: value.lang
|
|
5102
5104
|
} : void 0;
|
|
5103
5105
|
};
|
|
5104
|
-
var renderCodeCopyBlock = (node, ctx,
|
|
5106
|
+
var renderCodeCopyBlock = (node, ctx, options) => {
|
|
5105
5107
|
const value = node.value;
|
|
5106
5108
|
const filename = value?.filename ? `<figcaption>${ctx.escape(value.filename)}</figcaption>` : "";
|
|
5107
|
-
const source = typeof value?.code === "string" ?
|
|
5109
|
+
const source = typeof value?.code === "string" ? `<textarea class="nizel-code-copy__source" data-nizel-copy-source hidden readonly tabindex="-1" aria-hidden="true" style="display: none">${ctx.escape(value.code)}</textarea>` : "";
|
|
5108
5110
|
const body = ctx.render(node.children ?? []);
|
|
5109
|
-
|
|
5111
|
+
const onclick = options.mode === "inline" ? ` onclick="${ctx.escape(createInlineCopyHandler(options.copiedLabel))}"` : "";
|
|
5112
|
+
return `<figure class="nizel-code-copy" data-nizel-code-copy>${filename}${source}<button type="button" class="nizel-code-copy__button" data-nizel-copy-button${onclick}>${ctx.escape(options.label)}</button>${body}</figure>`;
|
|
5110
5113
|
};
|
|
5114
|
+
var createInlineCopyHandler = (copiedLabel) => {
|
|
5115
|
+
const label = jsString(copiedLabel);
|
|
5116
|
+
return `var b=this,f=b.closest('[data-nizel-code-copy]'),s=f?f.querySelector('[data-nizel-copy-source]'):null,v=s?s.value:'',p=b.textContent,d=function(){b.textContent='${label}';setTimeout(function(){b.textContent=p;},1200)},c=function(){var t=document.createElement('textarea');t.value=v;t.setAttribute('readonly','');t.style.position='fixed';t.style.opacity='0';document.body.appendChild(t);t.select();document.execCommand('copy');document.body.removeChild(t);d()};if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(v).then(d,c)}else{c()}`;
|
|
5117
|
+
};
|
|
5118
|
+
var jsString = (value) => value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
5111
5119
|
|
|
5112
5120
|
// ../plugin-citations/dist/index.js
|
|
5113
5121
|
var citationsPlugin = (options = {}) => {
|
package/dist/nizel-kit.js
CHANGED
|
@@ -5004,7 +5004,9 @@ var autolinkPlugin = (options = {}) => {
|
|
|
5004
5004
|
|
|
5005
5005
|
// ../plugin-code-copy/dist/index.js
|
|
5006
5006
|
var codeCopyPlugin = (options = {}) => {
|
|
5007
|
+
const copiedLabel = options.copiedLabel ?? "Copied";
|
|
5007
5008
|
const label = options.label ?? "Copy";
|
|
5009
|
+
const mode = options.mode ?? "inline";
|
|
5008
5010
|
return defineNizelPlugin({
|
|
5009
5011
|
name: "code-copy",
|
|
5010
5012
|
blocks: {
|
|
@@ -5014,7 +5016,7 @@ var codeCopyPlugin = (options = {}) => {
|
|
|
5014
5016
|
html(node, ctx) {
|
|
5015
5017
|
if (node.type !== "customBlock")
|
|
5016
5018
|
return "";
|
|
5017
|
-
return renderCodeCopyBlock(node, ctx, label);
|
|
5019
|
+
return renderCodeCopyBlock(node, ctx, { copiedLabel, label, mode });
|
|
5018
5020
|
}
|
|
5019
5021
|
}
|
|
5020
5022
|
}
|
|
@@ -5069,13 +5071,19 @@ var sourceFromCustomBlock = (node) => {
|
|
|
5069
5071
|
lang: value.lang
|
|
5070
5072
|
} : void 0;
|
|
5071
5073
|
};
|
|
5072
|
-
var renderCodeCopyBlock = (node, ctx,
|
|
5074
|
+
var renderCodeCopyBlock = (node, ctx, options) => {
|
|
5073
5075
|
const value = node.value;
|
|
5074
5076
|
const filename = value?.filename ? `<figcaption>${ctx.escape(value.filename)}</figcaption>` : "";
|
|
5075
|
-
const source = typeof value?.code === "string" ?
|
|
5077
|
+
const source = typeof value?.code === "string" ? `<textarea class="nizel-code-copy__source" data-nizel-copy-source hidden readonly tabindex="-1" aria-hidden="true" style="display: none">${ctx.escape(value.code)}</textarea>` : "";
|
|
5076
5078
|
const body = ctx.render(node.children ?? []);
|
|
5077
|
-
|
|
5079
|
+
const onclick = options.mode === "inline" ? ` onclick="${ctx.escape(createInlineCopyHandler(options.copiedLabel))}"` : "";
|
|
5080
|
+
return `<figure class="nizel-code-copy" data-nizel-code-copy>${filename}${source}<button type="button" class="nizel-code-copy__button" data-nizel-copy-button${onclick}>${ctx.escape(options.label)}</button>${body}</figure>`;
|
|
5078
5081
|
};
|
|
5082
|
+
var createInlineCopyHandler = (copiedLabel) => {
|
|
5083
|
+
const label = jsString(copiedLabel);
|
|
5084
|
+
return `var b=this,f=b.closest('[data-nizel-code-copy]'),s=f?f.querySelector('[data-nizel-copy-source]'):null,v=s?s.value:'',p=b.textContent,d=function(){b.textContent='${label}';setTimeout(function(){b.textContent=p;},1200)},c=function(){var t=document.createElement('textarea');t.value=v;t.setAttribute('readonly','');t.style.position='fixed';t.style.opacity='0';document.body.appendChild(t);t.select();document.execCommand('copy');document.body.removeChild(t);d()};if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(v).then(d,c)}else{c()}`;
|
|
5085
|
+
};
|
|
5086
|
+
var jsString = (value) => value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
5079
5087
|
|
|
5080
5088
|
// ../plugin-citations/dist/index.js
|
|
5081
5089
|
var citationsPlugin = (options = {}) => {
|