/** * dsh-fa-rtl — Client half (browser). * * Format note: this file is a hand-written DSH client bundle. The Host * half of dsh-client-modules scans enabled Loader entries whose package * declares `dsh.client` (see package.json) and serves this file over * `/plugins//client.js`. The page's module loader facade * (`window.__ModuleLoader__`) registers the factory below; the browser * Cordis tree materializes it when it mounts this plugin's row and then * applies the exported plugin, exactly like the shipped UI bundles. * * The `id` passed to `load` MUST equal the package name in * package.json — it is how the module system, the style bookkeeping, * and HMR all identify this bundle. * * Plain JavaScript only: no JSX, no TypeScript, no imports. Anything * beyond the platform baseline must go through `require(...)` inside * the factory, but this plugin needs nothing beyond the DOM. */ window.__ModuleLoader__.load({ id: "dsh-fa-rtl", factory: (require) => { var module = { exports: {} }; var exports = module.exports; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); var PACKAGE = "dsh-fa-rtl"; var TAG = "fa-rtl-base"; /** * Per-block bidi auto-detection for the chat surfaces. * * `unicode-bidi: plaintext` (CSS Writing Modes 4) gives each block * its own direction, resolved from the block's first strong * character — the CSS equivalent of dir="auto": * * - a paragraph starting with Persian/Arabic/Hebrew → RTL, and * `text-align: start` aligns it to the right edge; * - a paragraph starting with Latin → LTR, visually unchanged. * * Code blocks (
) are deliberately NOT touched: code stays
		 * left-to-right even inside a Persian answer. List markers flip
		 * with their list because ul/ol are included. Table cells pick
		 * their direction per cell.
		 *
		 * The scope anchors are stable `data-*` attributes that
		 * dsh-client-ui-chat puts on its flow items (see the row props in
		 * that package: data-chat-flow-kind, data-chat-group-part,
		 * data-turn-process-answer). Build-time hashed class names are
		 * never referenced, so this stylesheet survives UI updates.
		 */
		var CSS = [
			"/* dsh-fa-rtl v1.0.0 — RTL rendering for Persian chat messages. */",
			":is(",
			"  [data-chat-flow-kind=\"user\"],",
			"  [data-chat-flow-kind=\"assistant-step\"],",
			"  [data-chat-group-part=\"response\"],",
			"  [data-chat-group-part=\"reasoning\"],",
			"  [data-turn-process-answer]",
			")",
			":is(h1, h2, h3, h4, h5, h6, p, li, ul, ol, blockquote, dd, dt, figcaption, td, th, div) {",
			"  unicode-bidi: plaintext;",
			"  text-align: start;",
			"}"
		].join("\n");

		/**
		 * Inject the stylesheet at materialization, guarded against double
		 * insertion. The tag carries `data-plugin` = package name, which
		 * is the ownership marker the client-module system uses: when this
		 * entry is disabled or its code is hot-swapped, the system removes
		 * exactly the tags it owns, and re-materialization re-inserts this
		 * one. This mirrors how the shipped UI bundles inject their CSS.
		 */
		if (typeof document !== "undefined"
			&& document.querySelector("style[data-plugin-css=" + JSON.stringify(TAG) + "]") === null) {
			var tag = document.createElement("style");
			tag.dataset.plugin = PACKAGE;
			tag.dataset.pluginCss = TAG;
			tag.textContent = CSS;
			document.head.appendChild(tag);
		}

		/**
		 * The Cordis plugin the browser tree mounts for this row. The
		 * stylesheet already lives for as long as the materialized module
		 * does, so the lifecycle hook has nothing to clean up itself.
		 */
		exports.apply = function apply(ctx) {
			try {
				console.log("[" + PACKAGE + "] active — Persian chat text now renders right-to-left");
			} catch {
				/* logging is best-effort */
			}
		};

		return module.exports;
	},
});